Skip to content

Commit

Permalink
Merge branch 'main' into dsl-cfg-docs
Browse files Browse the repository at this point in the history
  • Loading branch information
fearful-symmetry authored Oct 4, 2023
2 parents 15251d8 + febe538 commit b88f432
Show file tree
Hide file tree
Showing 11 changed files with 1,011 additions and 43 deletions.
4 changes: 2 additions & 2 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ CHANGELOG*
/filebeat/module/mysql @elastic/security-external-integrations
/filebeat/module/nats @elastic/integrations
/filebeat/module/nginx @elastic/obs-infraobs-integrations
/filebeat/module/osquery @elastic/security-asset-management
/filebeat/module/osquery @elastic/security-external-integrations
/filebeat/module/pensando @elastic/security-external-integrations
/filebeat/module/postgresql @elastic/obs-infraobs-integrations
/filebeat/module/redis @elastic/obs-infraobs-integrations
Expand Down Expand Up @@ -196,7 +196,7 @@ CHANGELOG*
/x-pack/metricbeat/module/statsd @elastic/obs-infraobs-integrations
/x-pack/metricbeat/module/stan/ @elastic/obs-cloudnative-monitoring
/x-pack/metricbeat/module/tomcat @elastic/obs-infraobs-integrations
/x-pack/osquerybeat/ @elastic/security-asset-management
/x-pack/osquerybeat/ @elastic/security-external-integrations
/x-pack/packetbeat/ @elastic/security-external-integrations
/x-pack/winlogbeat/ @elastic/security-external-integrations
/x-pack/libbeat/reader/parquet/ @elastic/security-external-integrations
13 changes: 13 additions & 0 deletions .mergify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -276,3 +276,16 @@ pull_request_rules:
labels:
- "backport"
title: "[{{ destination_branch }}](backport #{{ number }}) {{ title }}"
- name: backport patches to 8.11 branch
conditions:
- merged
- label=backport-v8.11.0
actions:
backport:
assignees:
- "{{ author }}"
branches:
- "8.11"
labels:
- "backport"
title: "[{{ destination_branch }}](backport #{{ number }}) {{ title }}"
860 changes: 852 additions & 8 deletions NOTICE.txt

Large diffs are not rendered by default.

12 changes: 8 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ require (
github.com/mitchellh/hashstructure v1.1.0
github.com/mitchellh/mapstructure v1.5.0
github.com/olekukonko/tablewriter v0.0.5
github.com/osquery/osquery-go v0.0.0-20220706183148-4e1f83012b42
github.com/osquery/osquery-go v0.0.0-20230707154813-2e4891a0f444
github.com/pierrre/gotestcover v0.0.0-20160517101806-924dca7d15f0
github.com/pkg/errors v0.9.1
github.com/pmezard/go-difflib v1.0.0
Expand Down Expand Up @@ -158,7 +158,7 @@ require (
golang.org/x/net v0.10.0
golang.org/x/oauth2 v0.7.0
golang.org/x/sync v0.1.0
golang.org/x/sys v0.11.0
golang.org/x/sys v0.12.0
golang.org/x/text v0.12.0
golang.org/x/time v0.3.0
golang.org/x/tools v0.6.0
Expand Down Expand Up @@ -245,7 +245,7 @@ require (
github.com/JohnCGriffin/overflow v0.0.0-20211019200055-46fa312c352c // indirect
github.com/andybalholm/brotli v1.0.5 // indirect
github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20230305170008-8188dc5388df // indirect
github.com/apache/thrift v0.18.1 // indirect
github.com/apache/thrift v0.19.0 // indirect
github.com/armon/go-radix v1.0.0 // indirect
github.com/aws/aws-sdk-go v1.38.60 // indirect
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.4.8 // indirect
Expand Down Expand Up @@ -276,7 +276,8 @@ require (
github.com/felixge/httpsnoop v1.0.1 // indirect
github.com/form3tech-oss/jwt-go v3.2.5+incompatible // indirect
github.com/go-logfmt/logfmt v0.5.1 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/go-stack/stack v1.8.0 // indirect
github.com/gobuffalo/here v0.6.7 // indirect
Expand Down Expand Up @@ -357,6 +358,9 @@ require (
github.com/zeebo/xxh3 v1.0.2 // indirect
go.elastic.co/fastjson v1.1.0 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/otel v1.19.0 // indirect
go.opentelemetry.io/otel/metric v1.19.0 // indirect
go.opentelemetry.io/otel/trace v1.19.0 // indirect
golang.org/x/exp v0.0.0-20220921023135-46d9e7742f1e // indirect
golang.org/x/term v0.11.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
Expand Down
24 changes: 17 additions & 7 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,8 @@ github.com/apache/arrow/go/v12 v12.0.1-0.20230605094802-c153c6d36ccf/go.mod h1:w
github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ=
github.com/apache/thrift v0.13.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ=
github.com/apache/thrift v0.16.0/go.mod h1:PHK3hniurgQaNMZYaCLEqXKsYK8upmhPbmdP2FXSqgU=
github.com/apache/thrift v0.18.1 h1:lNhK/1nqjbwbiOPDBPFJVKxgDEGSepKuTh6OLiXW8kg=
github.com/apache/thrift v0.18.1/go.mod h1:rdQn/dCcDKEWjjylUeueum4vQEjG2v8v2PqriUnbr+I=
github.com/apache/thrift v0.19.0 h1:sOqkWPzMj7w6XaYbJQG7m4sGqVolaW/0D28Ln7yPzMk=
github.com/apache/thrift v0.19.0/go.mod h1:SUALL216IiaOw2Oy+5Vs9lboJ/t9g40C+G07Dc0QC1I=
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=
Expand Down Expand Up @@ -782,8 +782,12 @@ github.com/go-logr/logr v0.1.0/go.mod h1:ixOQHD9gLJUVQQ2ZOR7zLEifBX6tGkNJF4QyIY7
github.com/go-logr/logr v0.2.0/go.mod h1:z6/tIYblkpsD+a4lm/fGIIU9mZ+XfAiaFtq7xTgseGU=
github.com/go-logr/logr v0.4.0/go.mod h1:z6/tIYblkpsD+a4lm/fGIIU9mZ+XfAiaFtq7xTgseGU=
github.com/go-logr/logr v1.2.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.2.3 h1:2DntVwHkVopvECVRSlL5PSo9eG+cAkDCuckLubN+rq0=
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.2.3/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ=
github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
github.com/go-martini/martini v0.0.0-20170121215854-22fa46961aab h1:xveKWz2iaueeTaUgdetzel+U7exyigDYBryyVfV/rZk=
github.com/go-martini/martini v0.0.0-20170121215854-22fa46961aab/go.mod h1:/P9AEU963A2AYjv4d1V5eVL1CQbEJq6aCNHDDjibzu8=
github.com/go-ole/go-ole v1.2.5/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
Expand Down Expand Up @@ -1555,8 +1559,8 @@ github.com/openzipkin-contrib/zipkin-go-opentracing v0.4.5/go.mod h1:/wsWhb9smxS
github.com/openzipkin/zipkin-go v0.1.6/go.mod h1:QgAqvLzwWbR/WpD4A3cGpPtJrZXNIiJc5AZX7/PBEpw=
github.com/openzipkin/zipkin-go v0.2.1/go.mod h1:NaW6tEwdmWMaCDZzg8sh+IBNOxHMPnhQw8ySjnjRyN4=
github.com/openzipkin/zipkin-go v0.2.2/go.mod h1:NaW6tEwdmWMaCDZzg8sh+IBNOxHMPnhQw8ySjnjRyN4=
github.com/osquery/osquery-go v0.0.0-20220706183148-4e1f83012b42 h1:Epwxipb+y/e8ss/SJ7947F8J6dwjv3RHRCz2g0OkCII=
github.com/osquery/osquery-go v0.0.0-20220706183148-4e1f83012b42/go.mod h1:0KzmMhe0PL19cdYq6nd1cT9/5bMMJBTssAfuEgM2i34=
github.com/osquery/osquery-go v0.0.0-20230707154813-2e4891a0f444 h1:UO3MEdZ4hkmAfhf7kXfuKR+e44gsHlEEsdWGOwZNLyQ=
github.com/osquery/osquery-go v0.0.0-20230707154813-2e4891a0f444/go.mod h1:mLJRc1Go8uP32LRALGvWj2lVJ+hDYyIfxDzVa+C5Yo8=
github.com/otiai10/copy v1.12.0 h1:cLMgSQnXBs1eehF0Wy/FAGsgDTDmAqFR7rQylBb1nDY=
github.com/otiai10/copy v1.12.0/go.mod h1:rSaLseMUsZFFbsFGc7wCJnnkTAvdc5L6VWxPE4308Ww=
github.com/otiai10/mint v1.5.1 h1:XaPLeE+9vGbuyEHem1JNk3bYc7KKqyI/na0/mLd/Kks=
Expand Down Expand Up @@ -1938,6 +1942,12 @@ go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk=
go.opencensus.io v0.23.0/go.mod h1:XItmlyltB5F7CS4xOC1DcqMoFqwtC6OG2xF7mCv7P7E=
go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0=
go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo=
go.opentelemetry.io/otel v1.19.0 h1:MuS/TNf4/j4IXsZuJegVzI1cwut7Qc00344rgH7p8bs=
go.opentelemetry.io/otel v1.19.0/go.mod h1:i0QyjOq3UPoTzff0PJB2N66fb4S0+rSbSB15/oyH9fY=
go.opentelemetry.io/otel/metric v1.19.0 h1:aTzpGtV0ar9wlV4Sna9sdJyII5jTVJEvKETPiOKwvpE=
go.opentelemetry.io/otel/metric v1.19.0/go.mod h1:L5rUsV9kM1IxCj1MmSdS+JQAcVm319EUrDVLrt7jqt8=
go.opentelemetry.io/otel/trace v1.19.0 h1:DFVQmlVbfVeOuBRrwdtaehRrWiL1JoVs9CPIQ1Dzxpg=
go.opentelemetry.io/otel/trace v1.19.0/go.mod h1:mfaSyvGyEJEI0nyV2I4qhNQnbBOUUmYZpYojqMnX2vo=
go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI=
go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
Expand Down Expand Up @@ -2321,8 +2331,8 @@ golang.org/x/sys v0.0.0-20220829200755-d48e67d00261/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM=
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
Expand Down
2 changes: 1 addition & 1 deletion libbeat/version/version.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions x-pack/osquerybeat/beater/action_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type publisher interface {
}

type queryExecutor interface {
Query(ctx context.Context, sql string) ([]map[string]interface{}, error)
Query(ctx context.Context, sql string, timeout time.Duration) ([]map[string]interface{}, error)
}

type namespaceProvider interface {
Expand Down Expand Up @@ -68,7 +68,7 @@ func (a *actionHandler) Execute(ctx context.Context, req map[string]interface{})
func (a *actionHandler) execute(ctx context.Context, req map[string]interface{}) (int, error) {
ac, err := action.FromMap(req)
if err != nil {
return 0, fmt.Errorf("%v: %w", err, ErrQueryExecution)
return 0, fmt.Errorf("%w: %w", err, ErrQueryExecution)
}

var namespace string
Expand All @@ -95,7 +95,7 @@ func (a *actionHandler) executeQuery(ctx context.Context, index string, ac actio

start := time.Now()

hits, err := a.queryExec.Query(ctx, ac.Query)
hits, err := a.queryExec.Query(ctx, ac.Query, ac.Timeout)

if err != nil {
a.log.Errorf("Failed to execute query, err: %v", err)
Expand Down
3 changes: 2 additions & 1 deletion x-pack/osquerybeat/beater/action_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package beater
import (
"context"
"testing"
"time"

"github.com/gofrs/uuid"
"github.com/google/go-cmp/cmp"
Expand All @@ -23,7 +24,7 @@ type mockExecutor struct {
receivedSql string
}

func (e *mockExecutor) Query(ctx context.Context, sql string) ([]map[string]interface{}, error) {
func (e *mockExecutor) Query(ctx context.Context, sql string, to time.Duration) ([]map[string]interface{}, error) {
e.receivedSql = sql

return e.result, e.err
Expand Down
6 changes: 4 additions & 2 deletions x-pack/osquerybeat/beater/osquerybeat.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ const (
// osqueryd child process requests configuration from the configuration plugin implemented in osquerybeat
configurationRefreshIntervalSecs = 60

osqueryTimeout = 60 * time.Second
osqueryTimeout = 1 * time.Minute
osqueryMaxTimeout = 15 * time.Minute
)

const (
Expand Down Expand Up @@ -271,6 +272,7 @@ func (bt *osquerybeat) runOsquery(ctx context.Context, b *beat.Beat, osq *osqd.O
cli := osqdcli.New(socketPath,
osqdcli.WithLogger(bt.log),
osqdcli.WithTimeout(osqueryTimeout),
osqdcli.WithMaxTimeout(osqueryMaxTimeout),
osqdcli.WithCache(cache, adhocOsqueriesTypesCacheSize),
)

Expand Down Expand Up @@ -337,7 +339,7 @@ func runExtensionServer(ctx context.Context, socketPath string, configPlugin *Co
// Register config and logger extensions
extserver, err := osquery.NewExtensionManagerServer(extManagerServerName, socketPath, osquery.ServerTimeout(timeout))
if err != nil {
return
return err
}

// Register osquery configuration plugin
Expand Down
53 changes: 49 additions & 4 deletions x-pack/osquerybeat/internal/action/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ package action
import (
"errors"
"fmt"
"strconv"
"strings"
"time"

"github.com/elastic/beats/v7/x-pack/osquerybeat/internal/ecs"
)
Expand All @@ -17,8 +19,10 @@ var (
)

type Action struct {
Query string
ID string
Query string
ID string
// The optional action timeout
Timeout time.Duration
ECSMapping ecs.Mapping
}

Expand Down Expand Up @@ -72,11 +76,24 @@ func FromMap(m map[string]interface{}) (a Action, err error) {
return a, fmt.Errorf("missing query: %w", ErrActionRequest)
}

return Action{
a = Action{
Query: query,
ID: id,
ECSMapping: ecsm,
}, nil
}

if v, ok := m["timeout"]; ok {
timeout, err := convertToInt64(v)
if err != nil {
return a, fmt.Errorf("invalid timeout value %v: %w", v, err)
}
if timeout > 0 {
// Convert from seconds to duration
a.Timeout = time.Duration(timeout) * time.Second
}
}

return a, nil
}

func parseECSMapping(m map[string]interface{}) (ecsm ecs.Mapping, err error) {
Expand Down Expand Up @@ -121,3 +138,31 @@ func parseECSMapping(m map[string]interface{}) (ecsm ecs.Mapping, err error) {
}
return ecsm, err
}

func convertToInt64(i interface{}) (int64, error) {
switch v := i.(type) {
case int8:
return int64(v), nil
case int16:
return int64(v), nil
case int32:
return int64(v), nil
case int64:
return v, nil
case uint8:
return int64(v), nil
case uint16:
return int64(v), nil
case uint32:
return int64(v), nil
case uint64:
return int64(v), nil
case float32:
return int64(v), nil
case float64:
return int64(v), nil
case string:
return strconv.ParseInt(v, 10, 64)
}
return 0, fmt.Errorf("unexpected type: %T", i)
}
Loading

0 comments on commit b88f432

Please sign in to comment.