From 2681f771ceafe79d12db01bf8a4ae55f4eb1d22e Mon Sep 17 00:00:00 2001 From: Michal Pristas Date: Thu, 14 May 2020 09:29:43 +0200 Subject: [PATCH 1/2] initial --- .../plugin/app/monitoring/beats/beats_monitor.go | 12 +++++++++++- x-pack/elastic-agent/pkg/core/plugin/app/start.go | 12 +++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/x-pack/elastic-agent/pkg/core/plugin/app/monitoring/beats/beats_monitor.go b/x-pack/elastic-agent/pkg/core/plugin/app/monitoring/beats/beats_monitor.go index f1fb92d3a71..c8d25c733aa 100644 --- a/x-pack/elastic-agent/pkg/core/plugin/app/monitoring/beats/beats_monitor.go +++ b/x-pack/elastic-agent/pkg/core/plugin/app/monitoring/beats/beats_monitor.go @@ -8,6 +8,7 @@ import ( "net/url" "os" "path/filepath" + "runtime" "strings" "unicode" @@ -139,7 +140,7 @@ func (b *Monitor) Prepare(process, pipelineID string, uid, gid int) error { } } - if err := os.Chown(drop, uid, gid); err != nil { + if err := changeOwner(drop, uid, gid); err != nil { return err } } @@ -229,3 +230,12 @@ func isWindowsPath(path string) bool { } return unicode.IsLetter(rune(path[0])) && path[1] == ':' } + +func changeOwner(path string, uid, gid int) error { + if runtime.GOOS == "windows" { + // on windows it always returns the syscall.EWINDOWS error, wrapped in *PathError + return nil + } + + return os.Chown(path, uid, gid) +} diff --git a/x-pack/elastic-agent/pkg/core/plugin/app/start.go b/x-pack/elastic-agent/pkg/core/plugin/app/start.go index e13e137699e..41fb75ae8ef 100644 --- a/x-pack/elastic-agent/pkg/core/plugin/app/start.go +++ b/x-pack/elastic-agent/pkg/core/plugin/app/start.go @@ -9,6 +9,7 @@ import ( "fmt" "os" "path/filepath" + "runtime" "strings" "time" "unicode" @@ -319,7 +320,7 @@ func (a *Application) configureByFile(spec *ProcessSpec, config map[string]inter defer f.Close() // change owner - if err := os.Chown(filePath, a.uid, a.gid); err != nil { + if err := changeOwner(filePath, a.uid, a.gid); err != nil { return err } @@ -383,3 +384,12 @@ func isWindowsPath(path string) bool { } return unicode.IsLetter(rune(path[0])) && path[1] == ':' } + +func changeOwner(path string, uid, gid int) error { + if runtime.GOOS == "windows" { + // on windows it always returns the syscall.EWINDOWS error, wrapped in *PathError + return nil + } + + return os.Chown(path, uid, gid) +} From 2992388bc4dbe73b9bafc27248296932bc08b81f Mon Sep 17 00:00:00 2001 From: Michal Pristas Date: Thu, 14 May 2020 14:57:10 +0200 Subject: [PATCH 2/2] changelog --- x-pack/elastic-agent/CHANGELOG.asciidoc | 1 + 1 file changed, 1 insertion(+) diff --git a/x-pack/elastic-agent/CHANGELOG.asciidoc b/x-pack/elastic-agent/CHANGELOG.asciidoc index c0cb50bb6ae..98048c26022 100644 --- a/x-pack/elastic-agent/CHANGELOG.asciidoc +++ b/x-pack/elastic-agent/CHANGELOG.asciidoc @@ -34,6 +34,7 @@ - Fix make sure the collected logs or metrics include streams information. {pull}18261[18261] - Stop monitoring on config change {pull}18284[18284] - Fix jq: command not found {pull}18408[18408] +- Avoid Chown on windows {pull}18512[18512] ==== New features