Skip to content

Commit

Permalink
utils/file: Create files as running user instead of effective user
Browse files Browse the repository at this point in the history
  • Loading branch information
vista- committed Jan 30, 2025
1 parent 6c6d89a commit 0f4980c
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions utils/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"strings"

"github.com/steiler/acls"
"golang.org/x/sys/unix"

log "github.com/sirupsen/logrus"
)
Expand Down Expand Up @@ -196,6 +197,16 @@ func CreateFile(file, content string) (err error) {
return err
}

// Change file ownership to user running Containerlab instead of effective UID
realUID, effUID, _ := unix.Getresuid()
if realUID != effUID {
realGID, _, _ := unix.Getresgid()
err = os.Chown(file, realUID, realGID)
if err != nil {
return err
}
}

return f.Close()
}

Expand Down

0 comments on commit 0f4980c

Please sign in to comment.