Skip to content

Commit

Permalink
Fix Windows chown error (#28748)
Browse files Browse the repository at this point in the history
* noop for windows chown

* changelog
  • Loading branch information
miagilepner authored Oct 22, 2024
1 parent 9097689 commit 4439ee8
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
6 changes: 6 additions & 0 deletions changelog/28748.txt
Original file line number Diff line number Diff line change
@@ -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.
```
3 changes: 2 additions & 1 deletion command/agentproxyshared/sink/file/file_sink.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}

Expand Down
5 changes: 5 additions & 0 deletions helper/osutil/fileinfo_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package osutil
import (
"fmt"
"io/fs"
"os"
"os/user"
"strconv"
"syscall"
Expand Down Expand Up @@ -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)
}
5 changes: 5 additions & 0 deletions helper/osutil/fileinfo_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package osutil

import (
"io/fs"
"os"
)

func FileUidMatch(info fs.FileInfo, path string, uid int) error {
Expand All @@ -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
}

0 comments on commit 4439ee8

Please sign in to comment.