Skip to content

Commit

Permalink
Merge pull request #1755 from giuseppe/expose-get-rootless-gid
Browse files Browse the repository at this point in the history
unshare: export rootless GID
  • Loading branch information
openshift-merge-bot[bot] authored Nov 8, 2023
2 parents abee549 + 023ae7e commit a56f2b2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/unshare/unshare_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ func GetRootlessUID() int {
return os.Getuid()
}

// GetRootlessGID returns the GID of the user in the parent userNS
func GetRootlessGID() int {
return os.Getgid()
}

// RootlessEnv returns the environment settings for the rootless containers
func RootlessEnv() []string {
return append(os.Environ(), UsernsEnvName+"=")
Expand Down
10 changes: 10 additions & 0 deletions pkg/unshare/unshare_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,16 @@ func GetRootlessUID() int {
return os.Getuid()
}

// GetRootlessGID returns the GID of the user in the parent userNS
func GetRootlessGID() int {
gidEnv := getenv("_CONTAINERS_ROOTLESS_GID")
if gidEnv != "" {
u, _ := strconv.Atoi(gidEnv)
return u
}
return os.Getgid()
}

// RootlessEnv returns the environment settings for the rootless containers
func RootlessEnv() []string {
return append(os.Environ(), UsernsEnvName+"=done")
Expand Down
5 changes: 5 additions & 0 deletions pkg/unshare/unshare_unsupported.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ func GetRootlessUID() int {
return os.Getuid()
}

// GetRootlessGID returns the GID of the user in the parent userNS
func GetRootlessGID() int {
return os.Getgid()
}

// RootlessEnv returns the environment settings for the rootless containers
func RootlessEnv() []string {
return append(os.Environ(), UsernsEnvName+"=")
Expand Down

0 comments on commit a56f2b2

Please sign in to comment.