Skip to content

Commit a56f2b2

Browse files
Merge pull request #1755 from giuseppe/expose-get-rootless-gid
unshare: export rootless GID
2 parents abee549 + 023ae7e commit a56f2b2

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

pkg/unshare/unshare_darwin.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ func GetRootlessUID() int {
2525
return os.Getuid()
2626
}
2727

28+
// GetRootlessGID returns the GID of the user in the parent userNS
29+
func GetRootlessGID() int {
30+
return os.Getgid()
31+
}
32+
2833
// RootlessEnv returns the environment settings for the rootless containers
2934
func RootlessEnv() []string {
3035
return append(os.Environ(), UsernsEnvName+"=")

pkg/unshare/unshare_linux.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,16 @@ func GetRootlessUID() int {
441441
return os.Getuid()
442442
}
443443

444+
// GetRootlessGID returns the GID of the user in the parent userNS
445+
func GetRootlessGID() int {
446+
gidEnv := getenv("_CONTAINERS_ROOTLESS_GID")
447+
if gidEnv != "" {
448+
u, _ := strconv.Atoi(gidEnv)
449+
return u
450+
}
451+
return os.Getgid()
452+
}
453+
444454
// RootlessEnv returns the environment settings for the rootless containers
445455
func RootlessEnv() []string {
446456
return append(os.Environ(), UsernsEnvName+"=done")

pkg/unshare/unshare_unsupported.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ func GetRootlessUID() int {
2525
return os.Getuid()
2626
}
2727

28+
// GetRootlessGID returns the GID of the user in the parent userNS
29+
func GetRootlessGID() int {
30+
return os.Getgid()
31+
}
32+
2833
// RootlessEnv returns the environment settings for the rootless containers
2934
func RootlessEnv() []string {
3035
return append(os.Environ(), UsernsEnvName+"=")

0 commit comments

Comments
 (0)