Skip to content

Commit

Permalink
unshare: export rootless GID
Browse files Browse the repository at this point in the history
Signed-off-by: Giuseppe Scrivano <[email protected]>
  • Loading branch information
giuseppe committed Nov 7, 2023
1 parent ddc5840 commit 023ae7e
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 023ae7e

Please sign in to comment.