From 1500f15ad19f7bf0c5584a20f43ab29d9c72c9e8 Mon Sep 17 00:00:00 2001 From: Michal Pristas Date: Thu, 14 May 2020 22:23:00 +0200 Subject: [PATCH] [Ingest Manager] Avoid Chown on windows (#18512) * initial * changelog --- x-pack/elastic-agent/CHANGELOG.asciidoc | 1 + .../plugin/app/monitoring/beats/beats_monitor.go | 12 +++++++++++- x-pack/elastic-agent/pkg/core/plugin/app/start.go | 12 +++++++++++- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/x-pack/elastic-agent/CHANGELOG.asciidoc b/x-pack/elastic-agent/CHANGELOG.asciidoc index a38beab5118..2fad284a06c 100644 --- a/x-pack/elastic-agent/CHANGELOG.asciidoc +++ b/x-pack/elastic-agent/CHANGELOG.asciidoc @@ -35,6 +35,7 @@ - Ensure that the beats uses the params prefer_v2_templates on bulk request. {pull}18318[18318] - 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 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) +}