Skip to content

Commit

Permalink
[Ingest Manager] Avoid Chown on windows (elastic#18512)
Browse files Browse the repository at this point in the history
* initial

* changelog
  • Loading branch information
michalpristas committed May 15, 2020
1 parent fb9a22e commit cf2a8ca
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
1 change: 1 addition & 0 deletions x-pack/elastic-agent/CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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

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

0 comments on commit cf2a8ca

Please sign in to comment.