Skip to content

Commit 0f4980c

Browse files
committed
utils/file: Create files as running user instead of effective user
1 parent 6c6d89a commit 0f4980c

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

utils/file.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"strings"
2525

2626
"github.com/steiler/acls"
27+
"golang.org/x/sys/unix"
2728

2829
log "github.com/sirupsen/logrus"
2930
)
@@ -196,6 +197,16 @@ func CreateFile(file, content string) (err error) {
196197
return err
197198
}
198199

200+
// Change file ownership to user running Containerlab instead of effective UID
201+
realUID, effUID, _ := unix.Getresuid()
202+
if realUID != effUID {
203+
realGID, _, _ := unix.Getresgid()
204+
err = os.Chown(file, realUID, realGID)
205+
if err != nil {
206+
return err
207+
}
208+
}
209+
199210
return f.Close()
200211
}
201212

0 commit comments

Comments
 (0)