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 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) +}