From 042d9c675597e4c7fcde3bbdd5e5f0ce5f5dda18 Mon Sep 17 00:00:00 2001 From: Michal Pristas Date: Tue, 24 Mar 2020 14:34:52 +0100 Subject: [PATCH 01/14] added steps --- go.sum | 1 + x-pack/agent/pkg/agent/transpiler/rules.go | 2 +- x-pack/agent/pkg/agent/transpiler/steps.go | 126 +++++++++++++++++++++ 3 files changed, 128 insertions(+), 1 deletion(-) create mode 100644 x-pack/agent/pkg/agent/transpiler/steps.go diff --git a/go.sum b/go.sum index 26dcb9910c1..557948b5fe1 100644 --- a/go.sum +++ b/go.sum @@ -215,6 +215,7 @@ github.com/eapache/queue v1.1.0 h1:YOEu7KNc61ntiQlcEeUIoDTJ2o8mQznoNvUhiigpIqc= github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I= github.com/eclipse/paho.mqtt.golang v1.2.1-0.20200121105743-0d940dd29fd2 h1:DW6WrARxK5J+o8uAKCiACi5wy9EK1UzrsCpGBPsKHAA= github.com/eclipse/paho.mqtt.golang v1.2.1-0.20200121105743-0d940dd29fd2/go.mod h1:H9keYFcgq3Qr5OUJm/JZI/i6U7joQ8SYLhZwfeOo6Ts= +github.com/elastic/beats v7.6.1+incompatible h1:4iPVpFr8BSJW2fUVi+/tYXQ4v/IYVx0k2PPLTg8cfks= github.com/elastic/dhcp v0.0.0-20200227161230-57ec251c7eb3 h1:lnDkqiRFKm0rxdljqrj3lotWinO9+jFmeDXIC4gvIQs= github.com/elastic/dhcp v0.0.0-20200227161230-57ec251c7eb3/go.mod h1:aPqzac6AYkipvp4hufTyMj5PDIphF3+At8zr7r51xjY= github.com/elastic/ecs v1.5.0 h1:/VEIBsRU4ecq2+U3RPfKNc6bFyomP6qnthYEcQZu8GU= diff --git a/x-pack/agent/pkg/agent/transpiler/rules.go b/x-pack/agent/pkg/agent/transpiler/rules.go index ebc1d5b2eb0..96f16d18b6d 100644 --- a/x-pack/agent/pkg/agent/transpiler/rules.go +++ b/x-pack/agent/pkg/agent/transpiler/rules.go @@ -85,7 +85,7 @@ func (r *RuleList) MarshalYAML() (interface{}, error) { return doc, nil } -// UnmarshalYAML unmashal a YAML document into a RuleList. +// UnmarshalYAML unmarshal a YAML document into a RuleList. func (r *RuleList) UnmarshalYAML(unmarshal func(interface{}) error) error { var unpackTo []map[string]interface{} diff --git a/x-pack/agent/pkg/agent/transpiler/steps.go b/x-pack/agent/pkg/agent/transpiler/steps.go new file mode 100644 index 00000000000..edd722c3514 --- /dev/null +++ b/x-pack/agent/pkg/agent/transpiler/steps.go @@ -0,0 +1,126 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License; +// you may not use this file except in compliance with the Elastic License. + +package transpiler + +import ( + "fmt" + + "gopkg.in/yaml.v2" +) + +// StepList is a container that allow the same tree to be executed on multiple defined Step. +type StepList struct { + Steps []Step +} + +type Step interface { + Apply() error +} + +// Apply applies a list of steps. +func (r *StepList) Apply() error { + var err error + for _, rule := range r.Steps { + err = rule.Apply() + if err != nil { + return err + } + } + + return nil +} + +// MarshalYAML marsharl a steps list to YAML. +func (r *StepList) MarshalYAML() (interface{}, error) { + doc := make([]map[string]Step, 0, len(r.Steps)) + + for _, step := range r.Steps { + var name string + switch step.(type) { + case *DeleteFileStep: + name = "delete_file" + + default: + return nil, fmt.Errorf("unknown rule of type %T", step) + } + + subdoc := map[string]Step{ + name: step, + } + + doc = append(doc, subdoc) + } + return doc, nil +} + +// UnmarshalYAML unmarshal a YAML document into a RuleList. +func (r *StepList) UnmarshalYAML(unmarshal func(interface{}) error) error { + var unpackTo []map[string]interface{} + + err := unmarshal(&unpackTo) + if err != nil { + return err + } + + // NOTE(ph): this is a bit of a hack because I want to make sure + // the unpack strategy stay in the struct implementation and yaml + // doesn't have a RawMessage similar to the JSON package, so partial unpack + // is not possible. + unpack := func(in interface{}, out interface{}) error { + b, err := yaml.Marshal(in) + if err != nil { + return err + } + return yaml.Unmarshal(b, out) + } + + var steps []Step + + for _, m := range unpackTo { + ks := keys(m) + if len(ks) > 1 { + return fmt.Errorf("unknown rule identifier, expecting one identifier and received %d", len(ks)) + } + + name := ks[0] + fields := m[name] + + var s Step + switch name { + case "delete_file": + s = &DeleteFileStep{} + default: + return fmt.Errorf("unknown rule of type %s", name) + } + + if err := unpack(fields, r); err != nil { + return err + } + + steps = append(steps, s) + } + r.Steps = steps + return nil +} + +// DeleteFileStep removes a file from disk. +type DeleteFileStep struct { + Path string + // FailOnMissing fails if file is already missing + FailOnMissing bool +} + +// Apply applies delete file step. +func (r *DeleteFileStep) Apply() error { + return nil +} + +// DeleteFile creates a DeleteFileStep +func DeleteFile(path string, failOnMissing bool) *DeleteFileStep { + return &DeleteFileStep{ + Path: path, + FailOnMissing: failOnMissing, + } +} From 0af63c87e3aad2fc545193dc43de28a7bd68a4cd Mon Sep 17 00:00:00 2001 From: Michal Pristas Date: Wed, 25 Mar 2020 14:37:41 +0100 Subject: [PATCH 02/14] post install hooks working --- x-pack/agent/pkg/agent/program/spec.go | 13 ++-- x-pack/agent/pkg/agent/program/supported.go | 2 +- x-pack/agent/pkg/agent/transpiler/steps.go | 72 +++++++++++++++++-- .../artifact/install/hooks/hooks_installer.go | 57 +++++++++++++++ .../agent/pkg/artifact/install/installer.go | 13 +++- x-pack/agent/spec/metricbeat.yml | 4 ++ 6 files changed, 145 insertions(+), 16 deletions(-) create mode 100644 x-pack/agent/pkg/artifact/install/hooks/hooks_installer.go diff --git a/x-pack/agent/pkg/agent/program/spec.go b/x-pack/agent/pkg/agent/program/spec.go index 831406bf995..c9cfe9a7d0b 100644 --- a/x-pack/agent/pkg/agent/program/spec.go +++ b/x-pack/agent/pkg/agent/program/spec.go @@ -27,12 +27,13 @@ var ErrMissingWhen = errors.New("program must define a 'When' expression") // NOTE: Current spec are build at compile time, we want to revisit that to allow other program // to register their spec in a secure way. type Spec struct { - Name string `yaml:"name"` - Cmd string `yaml:"cmd"` - Configurable string `yaml:"configurable"` - Args []string `yaml:"args"` - Rules *transpiler.RuleList `yaml:"rules"` - When string `yaml:"when"` + Name string `yaml:"name"` + Cmd string `yaml:"cmd"` + Configurable string `yaml:"configurable"` + Args []string `yaml:"args"` + Rules *transpiler.RuleList `yaml:"rules"` + PostInstallSteps *transpiler.StepList `yaml:"post_install"` + When string `yaml:"when"` } // ReadSpecs reads all the specs that match the provided globbing path. diff --git a/x-pack/agent/pkg/agent/program/supported.go b/x-pack/agent/pkg/agent/program/supported.go index 0640627860b..b6b8cbca19d 100644 --- a/x-pack/agent/pkg/agent/program/supported.go +++ b/x-pack/agent/pkg/agent/program/supported.go @@ -19,7 +19,7 @@ func init() { // Packed Files // spec/filebeat.yml // spec/metricbeat.yml - unpacked := packer.MustUnpack("eJykVltzq7oVfu/PyHOnBRF7Dp05D4ZTbnHINk4koTckOYAtGRqwMXT63zsCgy9J9u6ZPuzxjpDW9Vvft/79UJUb9vf3XGzoJqn/1krx8I8HKp2avBZpJEVFUCBivHqKgb57yS2ZoJOIJcz4osyY5N1LblE/1x0/b1J/HwruwWYpRUXXM0Glk1MX7n4gklEvFP2d+7v7SFBsVTGOxFLCQ4yCiqCVSaRTMfCWL+1FvnwbfilyDjHigiJ44PaspiASP3BaM9fZJq0uqQsFt/3Kt/06WqvfoI7RLCMA1gTNtGv73At0sg64LcMjlaQkBmz7b69FSoygiZuy5egkWFc8LddWSWUpYiN6T9BsR3A6t/NF6tuWtsGWeMmtigLe2WlR+y585F6QqbvUFR13zJK7sFZ2fHuR+p6VcTed+26UcdfpqPILYHe21999ya2S7i2de8/nN9HxchZ23AtEjPSzPz1jf9zbFgfmQY0ZocYkzCge7QQ6dWH3khap+nu5trbUsGbYiI4YnEpmrM55Df8SHAn6WqTcEw1ZFdP5OZ5LHMOb2nfDI/PEO3fNIfcxLvsmt4ZJc0tw2FEj6K79cfe3ue9dYrZzLSU405h0ttwxqwSHGgZCI0ifcmCuoyV/FGmCZg3HUceMqCXIqVlT3ORwf977GuvU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/oD3MWYy1myI7cxTvZDezM+5T5Nzy6mQ19QgAoMeS9O8fi7If+jMmVPIILYJsJpxHyQtBdoDloZa3eiNOsv6jxhd3Is8neqV0p9HnlIfTD3P3FxKto+XqSnWbuz+QdF39rwg6Gl2FvIzL7w48V8RuMnnMOqErlsvq7kMcttPcPim8mOG0rR1EQBL556tc6cXckGh23EotgzEGZNhEbSNiuEq/s58vwGu3IDf+//VJYwZUcZAun9ZFt+//fNP/woAAP//ypoPSg==") SupportedMap = make(map[string]bool) for f, v := range unpacked { diff --git a/x-pack/agent/pkg/agent/transpiler/steps.go b/x-pack/agent/pkg/agent/transpiler/steps.go index edd722c3514..a01275c68a9 100644 --- a/x-pack/agent/pkg/agent/transpiler/steps.go +++ b/x-pack/agent/pkg/agent/transpiler/steps.go @@ -6,7 +6,10 @@ package transpiler import ( "fmt" + "os" + "path/filepath" + "github.com/pkg/errors" "gopkg.in/yaml.v2" ) @@ -16,14 +19,14 @@ type StepList struct { } type Step interface { - Apply() error + Apply(rootDir string) error } // Apply applies a list of steps. -func (r *StepList) Apply() error { +func (r *StepList) Apply(rootDir string) error { var err error - for _, rule := range r.Steps { - err = rule.Apply() + for _, step := range r.Steps { + err = step.Apply(rootDir) if err != nil { return err } @@ -41,6 +44,8 @@ func (r *StepList) MarshalYAML() (interface{}, error) { switch step.(type) { case *DeleteFileStep: name = "delete_file" + case *MoveFileStep: + name = "move_file" default: return nil, fmt.Errorf("unknown rule of type %T", step) @@ -73,7 +78,8 @@ func (r *StepList) UnmarshalYAML(unmarshal func(interface{}) error) error { if err != nil { return err } - return yaml.Unmarshal(b, out) + fmt.Println(string(b)) + return errors.Wrap(yaml.Unmarshal(b, out), "ajaj") } var steps []Step @@ -91,11 +97,13 @@ func (r *StepList) UnmarshalYAML(unmarshal func(interface{}) error) error { switch name { case "delete_file": s = &DeleteFileStep{} + case "move_file": + s = &MoveFileStep{} default: return fmt.Errorf("unknown rule of type %s", name) } - if err := unpack(fields, r); err != nil { + if err := unpack(fields, s); err != nil { return err } @@ -113,7 +121,20 @@ type DeleteFileStep struct { } // Apply applies delete file step. -func (r *DeleteFileStep) Apply() error { +func (r *DeleteFileStep) Apply(rootDir string) error { + path := filepath.Join(rootDir, filepath.FromSlash(r.Path)) + err := os.Remove(path) + + if os.IsNotExist(err) && r.FailOnMissing { + // is not found and should be reported + return err + } + + if err != nil && !os.IsNotExist(err) { + // report others + return err + } + return nil } @@ -124,3 +145,40 @@ func DeleteFile(path string, failOnMissing bool) *DeleteFileStep { FailOnMissing: failOnMissing, } } + +// MoveFileStep removes a file from disk. +type MoveFileStep struct { + Path string + Target string + // FailOnMissing fails if file is already missing + FailOnMissing bool `yaml:"fail_on_missing" config:"fail_on_missing"` +} + +// Apply applies delete file step. +func (r *MoveFileStep) Apply(rootDir string) error { + path := filepath.Join(rootDir, filepath.FromSlash(r.Path)) + target := filepath.Join(rootDir, filepath.FromSlash(r.Target)) + + err := os.Rename(path, target) + + if os.IsNotExist(err) && r.FailOnMissing { + // is not found and should be reported + return err + } + + if err != nil && !os.IsNotExist(err) { + // report others + return err + } + + return nil +} + +// MoveFile creates a MoveFileStep +func MoveFile(path, target string, failOnMissing bool) *MoveFileStep { + return &MoveFileStep{ + Path: path, + Target: target, + FailOnMissing: failOnMissing, + } +} diff --git a/x-pack/agent/pkg/artifact/install/hooks/hooks_installer.go b/x-pack/agent/pkg/artifact/install/hooks/hooks_installer.go new file mode 100644 index 00000000000..df3e8c7933a --- /dev/null +++ b/x-pack/agent/pkg/artifact/install/hooks/hooks_installer.go @@ -0,0 +1,57 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License; +// you may not use this file except in compliance with the Elastic License. + +package hooks + +import ( + "strings" + + "github.com/elastic/beats/v7/x-pack/agent/pkg/agent/program" +) + +type embeddedInstaller interface { + Install(programName, version, installDir string) error +} + +// Installer or zip packages +type Installer struct { + installer embeddedInstaller +} + +// NewInstaller creates an installer able to install zip packages +func NewInstaller(i embeddedInstaller) (*Installer, error) { + return &Installer{ + installer: i, + }, nil +} + +// Install performs installation of program in a specific version. +// It expects package to be already downloaded. +func (i *Installer) Install(programName, version, installDir string) error { + if err := i.installer.Install(programName, version, installDir); err != nil { + return err + } + + // post install hooks + nameLower := strings.ToLower(programName) + _, isSupported := program.SupportedMap[nameLower] + if !isSupported { + return nil + } + + for _, spec := range program.Supported { + if strings.ToLower(spec.Name) != nameLower { + continue + } + + if spec.PostInstallSteps != nil { + return spec.PostInstallSteps.Apply(installDir) + } + + // only one spec for type + break + } + + return nil +} diff --git a/x-pack/agent/pkg/artifact/install/installer.go b/x-pack/agent/pkg/artifact/install/installer.go index b8860f6b003..0ba1a07aca6 100644 --- a/x-pack/agent/pkg/artifact/install/installer.go +++ b/x-pack/agent/pkg/artifact/install/installer.go @@ -9,6 +9,7 @@ import ( "runtime" "github.com/elastic/beats/v7/x-pack/agent/pkg/artifact" + "github.com/elastic/beats/v7/x-pack/agent/pkg/artifact/install/hooks" "github.com/elastic/beats/v7/x-pack/agent/pkg/artifact/install/tar" "github.com/elastic/beats/v7/x-pack/agent/pkg/artifact/install/zip" ) @@ -36,9 +37,17 @@ func NewInstaller(config *artifact.Config) (Installer, error) { return nil, ErrConfigNotProvided } + var installer Installer + var err error if runtime.GOOS == "windows" { - return zip.NewInstaller(config) + installer, err = zip.NewInstaller(config) + } else { + installer, err = tar.NewInstaller(config) } - return tar.NewInstaller(config) + if err != nil { + return nil, err + } + + return hooks.NewInstaller(installer) } diff --git a/x-pack/agent/spec/metricbeat.yml b/x-pack/agent/spec/metricbeat.yml index 178a797430f..390749a3327 100644 --- a/x-pack/agent/spec/metricbeat.yml +++ b/x-pack/agent/spec/metricbeat.yml @@ -2,6 +2,10 @@ name: Metricbeat cmd: metricbeat args: ["-E", "setup.ilm.enabled=false", "-E", "setup.template.enabled=false", "-E", "management.mode=x-pack-fleet", "-E", "management.enabled=true"] configurable: grpc +post_install: + - move_file: + path: "modules.d/system.yml" + target: "modules.d/system.yml.disabled" rules: - inject_index: type: metrics From 1fe0bf454b143e3840798635d7f56c3736badcf0 Mon Sep 17 00:00:00 2001 From: Michal Pristas Date: Wed, 25 Mar 2020 14:45:17 +0100 Subject: [PATCH 03/14] changelog --- x-pack/agent/CHANGELOG.asciidoc | 1 + 1 file changed, 1 insertion(+) diff --git a/x-pack/agent/CHANGELOG.asciidoc b/x-pack/agent/CHANGELOG.asciidoc index 1b19ceb6484..f65fae39803 100644 --- a/x-pack/agent/CHANGELOG.asciidoc +++ b/x-pack/agent/CHANGELOG.asciidoc @@ -19,3 +19,4 @@ - Generate index name in a format type-dataset-namespace {pull}16903[16903] - OS agnostic default configuration {pull}17016[17016] +- Introduced post install hooks {pull}17241[17241] From e73d37c731abdb3d908119be44245caefd717f46 Mon Sep 17 00:00:00 2001 From: Michal Pristas Date: Wed, 25 Mar 2020 15:20:27 +0100 Subject: [PATCH 04/14] apply to execute --- x-pack/agent/pkg/agent/transpiler/steps.go | 17 +++++++++-------- .../artifact/install/hooks/hooks_installer.go | 2 +- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/x-pack/agent/pkg/agent/transpiler/steps.go b/x-pack/agent/pkg/agent/transpiler/steps.go index a01275c68a9..fb940053e51 100644 --- a/x-pack/agent/pkg/agent/transpiler/steps.go +++ b/x-pack/agent/pkg/agent/transpiler/steps.go @@ -18,15 +18,16 @@ type StepList struct { Steps []Step } +// Step is an execution step which needs to be run. type Step interface { - Apply(rootDir string) error + Execute(rootDir string) error } -// Apply applies a list of steps. -func (r *StepList) Apply(rootDir string) error { +// Execute executes a list of steps. +func (r *StepList) Execute(rootDir string) error { var err error for _, step := range r.Steps { - err = step.Apply(rootDir) + err = step.Execute(rootDir) if err != nil { return err } @@ -120,8 +121,8 @@ type DeleteFileStep struct { FailOnMissing bool } -// Apply applies delete file step. -func (r *DeleteFileStep) Apply(rootDir string) error { +// Execute executes delete file step. +func (r *DeleteFileStep) Execute(rootDir string) error { path := filepath.Join(rootDir, filepath.FromSlash(r.Path)) err := os.Remove(path) @@ -154,8 +155,8 @@ type MoveFileStep struct { FailOnMissing bool `yaml:"fail_on_missing" config:"fail_on_missing"` } -// Apply applies delete file step. -func (r *MoveFileStep) Apply(rootDir string) error { +// Execute executes move file step. +func (r *MoveFileStep) Execute(rootDir string) error { path := filepath.Join(rootDir, filepath.FromSlash(r.Path)) target := filepath.Join(rootDir, filepath.FromSlash(r.Target)) diff --git a/x-pack/agent/pkg/artifact/install/hooks/hooks_installer.go b/x-pack/agent/pkg/artifact/install/hooks/hooks_installer.go index df3e8c7933a..8dd4c8c057f 100644 --- a/x-pack/agent/pkg/artifact/install/hooks/hooks_installer.go +++ b/x-pack/agent/pkg/artifact/install/hooks/hooks_installer.go @@ -46,7 +46,7 @@ func (i *Installer) Install(programName, version, installDir string) error { } if spec.PostInstallSteps != nil { - return spec.PostInstallSteps.Apply(installDir) + return spec.PostInstallSteps.Execute(installDir) } // only one spec for type From 453546e763b96b6db26b3939ec5494a19c837701 Mon Sep 17 00:00:00 2001 From: Michal Pristas Date: Wed, 25 Mar 2020 15:21:55 +0100 Subject: [PATCH 05/14] updated comments --- x-pack/agent/pkg/agent/transpiler/steps.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/agent/pkg/agent/transpiler/steps.go b/x-pack/agent/pkg/agent/transpiler/steps.go index fb940053e51..b2f38dcc05b 100644 --- a/x-pack/agent/pkg/agent/transpiler/steps.go +++ b/x-pack/agent/pkg/agent/transpiler/steps.go @@ -147,7 +147,7 @@ func DeleteFile(path string, failOnMissing bool) *DeleteFileStep { } } -// MoveFileStep removes a file from disk. +// MoveFileStep moves a file to a new location. type MoveFileStep struct { Path string Target string From 4f30025c05eb68f164449880d2614a0288c43151 Mon Sep 17 00:00:00 2001 From: Michal Pristas Date: Thu, 26 Mar 2020 10:52:05 +0100 Subject: [PATCH 06/14] more defensive steps --- x-pack/agent/pkg/agent/transpiler/steps.go | 41 ++++++++++++++++--- .../agent/pkg/agent/transpiler/steps_test.go | 37 +++++++++++++++++ 2 files changed, 72 insertions(+), 6 deletions(-) create mode 100644 x-pack/agent/pkg/agent/transpiler/steps_test.go diff --git a/x-pack/agent/pkg/agent/transpiler/steps.go b/x-pack/agent/pkg/agent/transpiler/steps.go index b2f38dcc05b..b48cf44c2f0 100644 --- a/x-pack/agent/pkg/agent/transpiler/steps.go +++ b/x-pack/agent/pkg/agent/transpiler/steps.go @@ -8,8 +8,9 @@ import ( "fmt" "os" "path/filepath" + "runtime" + "strings" - "github.com/pkg/errors" "gopkg.in/yaml.v2" ) @@ -79,8 +80,7 @@ func (r *StepList) UnmarshalYAML(unmarshal func(interface{}) error) error { if err != nil { return err } - fmt.Println(string(b)) - return errors.Wrap(yaml.Unmarshal(b, out), "ajaj") + return yaml.Unmarshal(b, out) } var steps []Step @@ -123,7 +123,11 @@ type DeleteFileStep struct { // Execute executes delete file step. func (r *DeleteFileStep) Execute(rootDir string) error { - path := filepath.Join(rootDir, filepath.FromSlash(r.Path)) + path, isSubpath := joinPaths(rootDir, r.Path) + if !isSubpath { + return fmt.Errorf("invalid path value for operation 'Delete': %s", path) + } + err := os.Remove(path) if os.IsNotExist(err) && r.FailOnMissing { @@ -157,8 +161,15 @@ type MoveFileStep struct { // Execute executes move file step. func (r *MoveFileStep) Execute(rootDir string) error { - path := filepath.Join(rootDir, filepath.FromSlash(r.Path)) - target := filepath.Join(rootDir, filepath.FromSlash(r.Target)) + path, isSubpath := joinPaths(rootDir, r.Path) + if !isSubpath { + return fmt.Errorf("invalid path value for operation 'Move': %s", path) + } + + target, isSubpath := joinPaths(rootDir, r.Target) + if !isSubpath { + return fmt.Errorf("invalid target value for operation 'Move': %s", target) + } err := os.Rename(path, target) @@ -183,3 +194,21 @@ func MoveFile(path, target string, failOnMissing bool) *MoveFileStep { FailOnMissing: failOnMissing, } } + +// joinPaths joins paths and returns true if path is subpath of rootDir +func joinPaths(rootDir, path string) (string, bool) { + if !filepath.IsAbs(path) { + path = filepath.Join(rootDir, path) + } + + absRoot := filepath.Clean(filepath.FromSlash(rootDir)) + absPath := filepath.Clean(filepath.FromSlash(path)) + + // path on windows are case insensitive + if runtime.GOOS == "windows" { + absRoot = strings.ToLower(absRoot) + absPath = strings.ToLower(absPath) + } + + return absPath, strings.HasPrefix(absPath, absRoot) +} diff --git a/x-pack/agent/pkg/agent/transpiler/steps_test.go b/x-pack/agent/pkg/agent/transpiler/steps_test.go new file mode 100644 index 00000000000..e0f106c538b --- /dev/null +++ b/x-pack/agent/pkg/agent/transpiler/steps_test.go @@ -0,0 +1,37 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License; +// you may not use this file except in compliance with the Elastic License. + +package transpiler + +import ( + "fmt" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestIsSubpath(t *testing.T) { + testCases := []struct { + root string + path string + resultPath string + isSubpath bool + }{ + {"/", "a", "/a", true}, + {"/a", "b", "/a/b", true}, + {"/a", "b/c", "/a/b/c", true}, + {"/a/b", "/a/c", "/a/c", false}, + {"/a/b", "/a/b/../c", "/a/c", false}, + {"/a/b", "../c", "/a/c", false}, + } + + for _, test := range testCases { + t.Run(fmt.Sprintf("'%s'-'%s'", test.root, test.path), func(t *testing.T) { + newPath, result := joinPaths(test.root, test.path) + assert.Equal(t, test.resultPath, newPath) + assert.Equal(t, test.isSubpath, result) + }) + } + +} From 069e43876b5ca28201e48b263b3e1876655e01b3 Mon Sep 17 00:00:00 2001 From: Michal Pristas Date: Thu, 26 Mar 2020 11:43:09 +0100 Subject: [PATCH 07/14] mage vendor --- go.sum | 1 - 1 file changed, 1 deletion(-) diff --git a/go.sum b/go.sum index 557948b5fe1..26dcb9910c1 100644 --- a/go.sum +++ b/go.sum @@ -215,7 +215,6 @@ github.com/eapache/queue v1.1.0 h1:YOEu7KNc61ntiQlcEeUIoDTJ2o8mQznoNvUhiigpIqc= github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I= github.com/eclipse/paho.mqtt.golang v1.2.1-0.20200121105743-0d940dd29fd2 h1:DW6WrARxK5J+o8uAKCiACi5wy9EK1UzrsCpGBPsKHAA= github.com/eclipse/paho.mqtt.golang v1.2.1-0.20200121105743-0d940dd29fd2/go.mod h1:H9keYFcgq3Qr5OUJm/JZI/i6U7joQ8SYLhZwfeOo6Ts= -github.com/elastic/beats v7.6.1+incompatible h1:4iPVpFr8BSJW2fUVi+/tYXQ4v/IYVx0k2PPLTg8cfks= github.com/elastic/dhcp v0.0.0-20200227161230-57ec251c7eb3 h1:lnDkqiRFKm0rxdljqrj3lotWinO9+jFmeDXIC4gvIQs= github.com/elastic/dhcp v0.0.0-20200227161230-57ec251c7eb3/go.mod h1:aPqzac6AYkipvp4hufTyMj5PDIphF3+At8zr7r51xjY= github.com/elastic/ecs v1.5.0 h1:/VEIBsRU4ecq2+U3RPfKNc6bFyomP6qnthYEcQZu8GU= From 98437b881ca1487147ae4c6e144f9e370359aa11 Mon Sep 17 00:00:00 2001 From: Michal Pristas Date: Thu, 26 Mar 2020 13:02:18 +0100 Subject: [PATCH 08/14] serialization tedst --- x-pack/agent/pkg/agent/program/spec_test.go | 12 ++++++++++++ x-pack/agent/pkg/agent/transpiler/steps.go | 7 ++++++- x-pack/agent/pkg/agent/transpiler/steps_test.go | 1 - 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/x-pack/agent/pkg/agent/program/spec_test.go b/x-pack/agent/pkg/agent/program/spec_test.go index 67fcb6ac759..fd3db0374b2 100644 --- a/x-pack/agent/pkg/agent/program/spec_test.go +++ b/x-pack/agent/pkg/agent/program/spec_test.go @@ -44,6 +44,10 @@ func TestSerialization(t *testing.T) { "log", ), ), + PostInstallSteps: transpiler.NewStepList( + transpiler.DeleteFile("d-1", true), + transpiler.MoveFile("m-1", "m-2", false), + ), When: "1 == 1", } yml := `name: hello @@ -85,6 +89,14 @@ rules: key: type values: - log +post_install: +- delete_file: + path: d-1 + fail_on_missing: true +- move_file: + path: m-1 + target: m-2 + fail_on_missing: false when: 1 == 1 ` t.Run("serialization", func(t *testing.T) { diff --git a/x-pack/agent/pkg/agent/transpiler/steps.go b/x-pack/agent/pkg/agent/transpiler/steps.go index b48cf44c2f0..56cc6c763f5 100644 --- a/x-pack/agent/pkg/agent/transpiler/steps.go +++ b/x-pack/agent/pkg/agent/transpiler/steps.go @@ -19,6 +19,11 @@ type StepList struct { Steps []Step } +// NewStepList returns a new list of rules to be executed. +func NewStepList(steps ...Step) *StepList { + return &StepList{Steps: steps} +} + // Step is an execution step which needs to be run. type Step interface { Execute(rootDir string) error @@ -118,7 +123,7 @@ func (r *StepList) UnmarshalYAML(unmarshal func(interface{}) error) error { type DeleteFileStep struct { Path string // FailOnMissing fails if file is already missing - FailOnMissing bool + FailOnMissing bool `yaml:"fail_on_missing" config:"fail_on_missing"` } // Execute executes delete file step. diff --git a/x-pack/agent/pkg/agent/transpiler/steps_test.go b/x-pack/agent/pkg/agent/transpiler/steps_test.go index e0f106c538b..7f597a501ee 100644 --- a/x-pack/agent/pkg/agent/transpiler/steps_test.go +++ b/x-pack/agent/pkg/agent/transpiler/steps_test.go @@ -33,5 +33,4 @@ func TestIsSubpath(t *testing.T) { assert.Equal(t, test.isSubpath, result) }) } - } From ca18a46c2d384014209df6c7c8a295520805dba7 Mon Sep 17 00:00:00 2001 From: Michal Pristas Date: Fri, 27 Mar 2020 13:41:12 +0100 Subject: [PATCH 09/14] run specific tests --- go.sum | 1 + .../agent/pkg/agent/transpiler/steps_test.go | 42 +++++++++++++++---- 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/go.sum b/go.sum index 26dcb9910c1..557948b5fe1 100644 --- a/go.sum +++ b/go.sum @@ -215,6 +215,7 @@ github.com/eapache/queue v1.1.0 h1:YOEu7KNc61ntiQlcEeUIoDTJ2o8mQznoNvUhiigpIqc= github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I= github.com/eclipse/paho.mqtt.golang v1.2.1-0.20200121105743-0d940dd29fd2 h1:DW6WrARxK5J+o8uAKCiACi5wy9EK1UzrsCpGBPsKHAA= github.com/eclipse/paho.mqtt.golang v1.2.1-0.20200121105743-0d940dd29fd2/go.mod h1:H9keYFcgq3Qr5OUJm/JZI/i6U7joQ8SYLhZwfeOo6Ts= +github.com/elastic/beats v7.6.1+incompatible h1:4iPVpFr8BSJW2fUVi+/tYXQ4v/IYVx0k2PPLTg8cfks= github.com/elastic/dhcp v0.0.0-20200227161230-57ec251c7eb3 h1:lnDkqiRFKm0rxdljqrj3lotWinO9+jFmeDXIC4gvIQs= github.com/elastic/dhcp v0.0.0-20200227161230-57ec251c7eb3/go.mod h1:aPqzac6AYkipvp4hufTyMj5PDIphF3+At8zr7r51xjY= github.com/elastic/ecs v1.5.0 h1:/VEIBsRU4ecq2+U3RPfKNc6bFyomP6qnthYEcQZu8GU= diff --git a/x-pack/agent/pkg/agent/transpiler/steps_test.go b/x-pack/agent/pkg/agent/transpiler/steps_test.go index 7f597a501ee..9185e36d544 100644 --- a/x-pack/agent/pkg/agent/transpiler/steps_test.go +++ b/x-pack/agent/pkg/agent/transpiler/steps_test.go @@ -6,28 +6,52 @@ package transpiler import ( "fmt" + "runtime" "testing" "github.com/stretchr/testify/assert" ) func TestIsSubpath(t *testing.T) { - testCases := []struct { + testCases := map[string][]struct { root string path string resultPath string isSubpath bool }{ - {"/", "a", "/a", true}, - {"/a", "b", "/a/b", true}, - {"/a", "b/c", "/a/b/c", true}, - {"/a/b", "/a/c", "/a/c", false}, - {"/a/b", "/a/b/../c", "/a/c", false}, - {"/a/b", "../c", "/a/c", false}, + "linux": { + {"/", "a", "/a", true}, + {"/a", "b", "/a/b", true}, + {"/a", "b/c", "/a/b/c", true}, + {"/a/b", "/a/c", "/a/c", false}, + {"/a/b", "/a/b/../c", "/a/c", false}, + {"/a/b", "../c", "/a/c", false}, + }, + "darwin": { + {"/", "a", "/a", true}, + {"/a", "b", "/a/b", true}, + {"/a", "b/c", "/a/b/c", true}, + {"/a/b", "/a/c", "/a/c", false}, + {"/a/b", "/a/b/../c", "/a/c", false}, + {"/a/b", "../c", "/a/c", false}, + }, + "windows": { + {"/", "a", "\\a", true}, + {"/a", "b", "\\a\\b", true}, + {"/a", "b/c", "\\a\\b\\c", true}, + {"/a/b", "/a/c", "\\a\\c", false}, + {"/a/b", "/a/b/../c", "\\a\\c", false}, + {"/a/b", "../c", "\\a\\c", false}, + }, } - for _, test := range testCases { - t.Run(fmt.Sprintf("'%s'-'%s'", test.root, test.path), func(t *testing.T) { + osSpecificTests, found := testCases[runtime.GOOS] + if !found { + return + } + + for _, test := range osSpecificTests { + t.Run(fmt.Sprintf("[%s]'%s-%s'", runtime.GOOS, test.root, test.path), func(t *testing.T) { newPath, result := joinPaths(test.root, test.path) assert.Equal(t, test.resultPath, newPath) assert.Equal(t, test.isSubpath, result) From cd80ffe70cc709302af69b1c53e6e63efb8cee8b Mon Sep 17 00:00:00 2001 From: Michal Pristas Date: Fri, 27 Mar 2020 14:13:13 +0100 Subject: [PATCH 10/14] mage vendor --- go.sum | 1 - 1 file changed, 1 deletion(-) diff --git a/go.sum b/go.sum index 557948b5fe1..26dcb9910c1 100644 --- a/go.sum +++ b/go.sum @@ -215,7 +215,6 @@ github.com/eapache/queue v1.1.0 h1:YOEu7KNc61ntiQlcEeUIoDTJ2o8mQznoNvUhiigpIqc= github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I= github.com/eclipse/paho.mqtt.golang v1.2.1-0.20200121105743-0d940dd29fd2 h1:DW6WrARxK5J+o8uAKCiACi5wy9EK1UzrsCpGBPsKHAA= github.com/eclipse/paho.mqtt.golang v1.2.1-0.20200121105743-0d940dd29fd2/go.mod h1:H9keYFcgq3Qr5OUJm/JZI/i6U7joQ8SYLhZwfeOo6Ts= -github.com/elastic/beats v7.6.1+incompatible h1:4iPVpFr8BSJW2fUVi+/tYXQ4v/IYVx0k2PPLTg8cfks= github.com/elastic/dhcp v0.0.0-20200227161230-57ec251c7eb3 h1:lnDkqiRFKm0rxdljqrj3lotWinO9+jFmeDXIC4gvIQs= github.com/elastic/dhcp v0.0.0-20200227161230-57ec251c7eb3/go.mod h1:aPqzac6AYkipvp4hufTyMj5PDIphF3+At8zr7r51xjY= github.com/elastic/ecs v1.5.0 h1:/VEIBsRU4ecq2+U3RPfKNc6bFyomP6qnthYEcQZu8GU= From 64a61d0abf03c503541f2dcab2865f5e0b307448 Mon Sep 17 00:00:00 2001 From: Michal Pristas Date: Tue, 31 Mar 2020 11:58:39 +0200 Subject: [PATCH 11/14] case sensitivity check --- go.sum | 1 + x-pack/agent/pkg/agent/transpiler/steps.go | 33 +++++++++++++++++-- .../agent/pkg/agent/transpiler/steps_test.go | 6 ++++ 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/go.sum b/go.sum index 26dcb9910c1..557948b5fe1 100644 --- a/go.sum +++ b/go.sum @@ -215,6 +215,7 @@ github.com/eapache/queue v1.1.0 h1:YOEu7KNc61ntiQlcEeUIoDTJ2o8mQznoNvUhiigpIqc= github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I= github.com/eclipse/paho.mqtt.golang v1.2.1-0.20200121105743-0d940dd29fd2 h1:DW6WrARxK5J+o8uAKCiACi5wy9EK1UzrsCpGBPsKHAA= github.com/eclipse/paho.mqtt.golang v1.2.1-0.20200121105743-0d940dd29fd2/go.mod h1:H9keYFcgq3Qr5OUJm/JZI/i6U7joQ8SYLhZwfeOo6Ts= +github.com/elastic/beats v7.6.1+incompatible h1:4iPVpFr8BSJW2fUVi+/tYXQ4v/IYVx0k2PPLTg8cfks= github.com/elastic/dhcp v0.0.0-20200227161230-57ec251c7eb3 h1:lnDkqiRFKm0rxdljqrj3lotWinO9+jFmeDXIC4gvIQs= github.com/elastic/dhcp v0.0.0-20200227161230-57ec251c7eb3/go.mod h1:aPqzac6AYkipvp4hufTyMj5PDIphF3+At8zr7r51xjY= github.com/elastic/ecs v1.5.0 h1:/VEIBsRU4ecq2+U3RPfKNc6bFyomP6qnthYEcQZu8GU= diff --git a/x-pack/agent/pkg/agent/transpiler/steps.go b/x-pack/agent/pkg/agent/transpiler/steps.go index 56cc6c763f5..d436999a432 100644 --- a/x-pack/agent/pkg/agent/transpiler/steps.go +++ b/x-pack/agent/pkg/agent/transpiler/steps.go @@ -76,7 +76,7 @@ func (r *StepList) UnmarshalYAML(unmarshal func(interface{}) error) error { return err } - // NOTE(ph): this is a bit of a hack because I want to make sure + // NOTE: this is a bit of a hack because I want to make sure // the unpack strategy stay in the struct implementation and yaml // doesn't have a RawMessage similar to the JSON package, so partial unpack // is not possible. @@ -210,10 +210,39 @@ func joinPaths(rootDir, path string) (string, bool) { absPath := filepath.Clean(filepath.FromSlash(path)) // path on windows are case insensitive - if runtime.GOOS == "windows" { + if !isFsCaseSensitive(rootDir) { absRoot = strings.ToLower(absRoot) absPath = strings.ToLower(absPath) } return absPath, strings.HasPrefix(absPath, absRoot) } + +func isFsCaseSensitive(rootDir string) bool { + defaultCaseSens := runtime.GOOS != "windows" && runtime.GOOS != "darwin" + + dir := filepath.Dir(rootDir) + base := filepath.Base(rootDir) + // if rootdir not exist create it + if _, err := os.Stat(rootDir); os.IsNotExist(err) { + os.MkdirAll(rootDir, 0775) + defer os.RemoveAll(rootDir) + } + + lowDir := filepath.Join(base, strings.ToLower(dir)) + upDir := filepath.Join(base, strings.ToUpper(dir)) + + if _, err := os.Stat(rootDir); err != nil { + return defaultCaseSens + } + + // check lower/upper dir + if _, lowErr := os.Stat(lowDir); os.IsNotExist(lowErr) { + return true + } + if _, upErr := os.Stat(upDir); os.IsNotExist(upErr) { + return true + } + + return defaultCaseSens +} diff --git a/x-pack/agent/pkg/agent/transpiler/steps_test.go b/x-pack/agent/pkg/agent/transpiler/steps_test.go index 9185e36d544..788e4a73931 100644 --- a/x-pack/agent/pkg/agent/transpiler/steps_test.go +++ b/x-pack/agent/pkg/agent/transpiler/steps_test.go @@ -26,6 +26,8 @@ func TestIsSubpath(t *testing.T) { {"/a/b", "/a/c", "/a/c", false}, {"/a/b", "/a/b/../c", "/a/c", false}, {"/a/b", "../c", "/a/c", false}, + {"/a", "/a/b/c", "/a/b/c", true}, + {"/a", "/A/b/c", "/a/b/c", false}, }, "darwin": { {"/", "a", "/a", true}, @@ -34,6 +36,8 @@ func TestIsSubpath(t *testing.T) { {"/a/b", "/a/c", "/a/c", false}, {"/a/b", "/a/b/../c", "/a/c", false}, {"/a/b", "../c", "/a/c", false}, + {"/a", "/a/b/c", "/a/b/c", true}, + {"/a", "/A/b/c", "/a/b/c", true}, }, "windows": { {"/", "a", "\\a", true}, @@ -42,6 +46,8 @@ func TestIsSubpath(t *testing.T) { {"/a/b", "/a/c", "\\a\\c", false}, {"/a/b", "/a/b/../c", "\\a\\c", false}, {"/a/b", "../c", "\\a\\c", false}, + {"/a", "/a/b/c", "\\a\\b\\c", true}, + {"/a", "/A/b/c", "\\a\\b\\c", true}, }, } From b7a06ea0218506a9209ccf17a56f8b2bfde97dfc Mon Sep 17 00:00:00 2001 From: Michal Pristas Date: Tue, 31 Mar 2020 13:58:30 +0200 Subject: [PATCH 12/14] mage vendor --- go.sum | 1 - 1 file changed, 1 deletion(-) diff --git a/go.sum b/go.sum index 557948b5fe1..26dcb9910c1 100644 --- a/go.sum +++ b/go.sum @@ -215,7 +215,6 @@ github.com/eapache/queue v1.1.0 h1:YOEu7KNc61ntiQlcEeUIoDTJ2o8mQznoNvUhiigpIqc= github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I= github.com/eclipse/paho.mqtt.golang v1.2.1-0.20200121105743-0d940dd29fd2 h1:DW6WrARxK5J+o8uAKCiACi5wy9EK1UzrsCpGBPsKHAA= github.com/eclipse/paho.mqtt.golang v1.2.1-0.20200121105743-0d940dd29fd2/go.mod h1:H9keYFcgq3Qr5OUJm/JZI/i6U7joQ8SYLhZwfeOo6Ts= -github.com/elastic/beats v7.6.1+incompatible h1:4iPVpFr8BSJW2fUVi+/tYXQ4v/IYVx0k2PPLTg8cfks= github.com/elastic/dhcp v0.0.0-20200227161230-57ec251c7eb3 h1:lnDkqiRFKm0rxdljqrj3lotWinO9+jFmeDXIC4gvIQs= github.com/elastic/dhcp v0.0.0-20200227161230-57ec251c7eb3/go.mod h1:aPqzac6AYkipvp4hufTyMj5PDIphF3+At8zr7r51xjY= github.com/elastic/ecs v1.5.0 h1:/VEIBsRU4ecq2+U3RPfKNc6bFyomP6qnthYEcQZu8GU= From 4584bddea8fc7edf48a2f7cb6cefd918b55eb387 Mon Sep 17 00:00:00 2001 From: Michal Pristas Date: Tue, 31 Mar 2020 17:58:04 +0200 Subject: [PATCH 13/14] tests: lowers resulting path in insensitive FSs --- go.sum | 1 + x-pack/agent/pkg/agent/transpiler/steps_test.go | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/go.sum b/go.sum index 26dcb9910c1..557948b5fe1 100644 --- a/go.sum +++ b/go.sum @@ -215,6 +215,7 @@ github.com/eapache/queue v1.1.0 h1:YOEu7KNc61ntiQlcEeUIoDTJ2o8mQznoNvUhiigpIqc= github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I= github.com/eclipse/paho.mqtt.golang v1.2.1-0.20200121105743-0d940dd29fd2 h1:DW6WrARxK5J+o8uAKCiACi5wy9EK1UzrsCpGBPsKHAA= github.com/eclipse/paho.mqtt.golang v1.2.1-0.20200121105743-0d940dd29fd2/go.mod h1:H9keYFcgq3Qr5OUJm/JZI/i6U7joQ8SYLhZwfeOo6Ts= +github.com/elastic/beats v7.6.1+incompatible h1:4iPVpFr8BSJW2fUVi+/tYXQ4v/IYVx0k2PPLTg8cfks= github.com/elastic/dhcp v0.0.0-20200227161230-57ec251c7eb3 h1:lnDkqiRFKm0rxdljqrj3lotWinO9+jFmeDXIC4gvIQs= github.com/elastic/dhcp v0.0.0-20200227161230-57ec251c7eb3/go.mod h1:aPqzac6AYkipvp4hufTyMj5PDIphF3+At8zr7r51xjY= github.com/elastic/ecs v1.5.0 h1:/VEIBsRU4ecq2+U3RPfKNc6bFyomP6qnthYEcQZu8GU= diff --git a/x-pack/agent/pkg/agent/transpiler/steps_test.go b/x-pack/agent/pkg/agent/transpiler/steps_test.go index 788e4a73931..eedff0a703c 100644 --- a/x-pack/agent/pkg/agent/transpiler/steps_test.go +++ b/x-pack/agent/pkg/agent/transpiler/steps_test.go @@ -27,7 +27,7 @@ func TestIsSubpath(t *testing.T) { {"/a/b", "/a/b/../c", "/a/c", false}, {"/a/b", "../c", "/a/c", false}, {"/a", "/a/b/c", "/a/b/c", true}, - {"/a", "/A/b/c", "/a/b/c", false}, + {"/a", "/A/b/c", "/A/b/c", false}, }, "darwin": { {"/", "a", "/a", true}, From aab3104bdc30fa302d35d5f277cc11a69aff888c Mon Sep 17 00:00:00 2001 From: Michal Pristas Date: Wed, 1 Apr 2020 10:05:11 +0200 Subject: [PATCH 14/14] mage vendor --- go.sum | 1 - 1 file changed, 1 deletion(-) diff --git a/go.sum b/go.sum index 5fc51460a8d..5c8338626cc 100644 --- a/go.sum +++ b/go.sum @@ -217,7 +217,6 @@ github.com/eapache/queue v1.1.0 h1:YOEu7KNc61ntiQlcEeUIoDTJ2o8mQznoNvUhiigpIqc= github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I= github.com/eclipse/paho.mqtt.golang v1.2.1-0.20200121105743-0d940dd29fd2 h1:DW6WrARxK5J+o8uAKCiACi5wy9EK1UzrsCpGBPsKHAA= github.com/eclipse/paho.mqtt.golang v1.2.1-0.20200121105743-0d940dd29fd2/go.mod h1:H9keYFcgq3Qr5OUJm/JZI/i6U7joQ8SYLhZwfeOo6Ts= -github.com/elastic/beats v7.6.1+incompatible h1:4iPVpFr8BSJW2fUVi+/tYXQ4v/IYVx0k2PPLTg8cfks= github.com/elastic/dhcp v0.0.0-20200227161230-57ec251c7eb3 h1:lnDkqiRFKm0rxdljqrj3lotWinO9+jFmeDXIC4gvIQs= github.com/elastic/dhcp v0.0.0-20200227161230-57ec251c7eb3/go.mod h1:aPqzac6AYkipvp4hufTyMj5PDIphF3+At8zr7r51xjY= github.com/elastic/ecs v1.5.0 h1:/VEIBsRU4ecq2+U3RPfKNc6bFyomP6qnthYEcQZu8GU=