Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Ingest Manager] Avoid Chown on windows #18512

Merged
merged 2 commits into from
May 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions x-pack/elastic-agent/CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"net/url"
"os"
"path/filepath"
"runtime"
"strings"
"unicode"

Expand Down Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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)
}
12 changes: 11 additions & 1 deletion x-pack/elastic-agent/pkg/core/plugin/app/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"fmt"
"os"
"path/filepath"
"runtime"
"strings"
"time"
"unicode"
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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)
}