From 4439ee879808bd8e567dbd5e8e108fd6d376ae6a Mon Sep 17 00:00:00 2001 From: miagilepner Date: Tue, 22 Oct 2024 14:57:26 +0200 Subject: [PATCH] Fix Windows chown error (#28748) * noop for windows chown * changelog --- changelog/28748.txt | 6 ++++++ command/agentproxyshared/sink/file/file_sink.go | 3 ++- helper/osutil/fileinfo_unix.go | 5 +++++ helper/osutil/fileinfo_windows.go | 5 +++++ 4 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 changelog/28748.txt diff --git a/changelog/28748.txt b/changelog/28748.txt new file mode 100644 index 0000000000..fb486b7372 --- /dev/null +++ b/changelog/28748.txt @@ -0,0 +1,6 @@ +```release-note:bug +agent: Fix chown error running agent on Windows with an auto-auth file sinks. +``` +```release-note:bug +proxy: Fix chown error running proxy on Windows with an auto-auth file sink. +``` diff --git a/command/agentproxyshared/sink/file/file_sink.go b/command/agentproxyshared/sink/file/file_sink.go index 6e1b71aa2e..0d846e09d4 100644 --- a/command/agentproxyshared/sink/file/file_sink.go +++ b/command/agentproxyshared/sink/file/file_sink.go @@ -13,6 +13,7 @@ import ( hclog "github.com/hashicorp/go-hclog" uuid "github.com/hashicorp/go-uuid" "github.com/hashicorp/vault/command/agentproxyshared/sink" + "github.com/hashicorp/vault/helper/osutil" ) // fileSink is a Sink implementation that writes a token to a file @@ -117,7 +118,7 @@ func (f *fileSink) WriteToken(token string) error { return fmt.Errorf("error opening temp file in dir %s for writing: %w", targetDir, err) } - if err := tmpFile.Chown(f.owner, f.group); err != nil { + if err := osutil.Chown(tmpFile, f.owner, f.group); err != nil { return fmt.Errorf("error changing ownership of %s: %w", tmpFile.Name(), err) } diff --git a/helper/osutil/fileinfo_unix.go b/helper/osutil/fileinfo_unix.go index da7b58d61c..1ff1284a0e 100644 --- a/helper/osutil/fileinfo_unix.go +++ b/helper/osutil/fileinfo_unix.go @@ -8,6 +8,7 @@ package osutil import ( "fmt" "io/fs" + "os" "os/user" "strconv" "syscall" @@ -59,3 +60,7 @@ func FileUidMatch(info fs.FileInfo, path string, uid int) (err error) { func Umask(newmask int) int { return syscall.Umask(newmask) } + +func Chown(f *os.File, owner, group int) error { + return f.Chown(owner, group) +} diff --git a/helper/osutil/fileinfo_windows.go b/helper/osutil/fileinfo_windows.go index 9292b4613a..a2cc5d8570 100644 --- a/helper/osutil/fileinfo_windows.go +++ b/helper/osutil/fileinfo_windows.go @@ -7,6 +7,7 @@ package osutil import ( "io/fs" + "os" ) func FileUidMatch(info fs.FileInfo, path string, uid int) error { @@ -17,3 +18,7 @@ func FileUidMatch(info fs.FileInfo, path string, uid int) error { func Umask(newmask int) int { return 0 } + +func Chown(f *os.File, owner, group int) error { + return nil +}