Skip to content

Commit

Permalink
userns: skip the nobody user
Browse files Browse the repository at this point in the history
improve the heuristic to detect the user namespace size needed to run
an image.  Hardcode the nobody user value to 65534, which is the value
used by the kernel, and ignore this value when parsing /etc/passwd and
/etc/group.

Closes: #1472

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
(cherry picked from commit b876a48)
  • Loading branch information
giuseppe committed Jan 20, 2023
1 parent c747cbb commit 038679c
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions userns.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ func (s *store) getAvailableIDs() (*idSet, *idSet, error) {
return u, g, nil
}

// nobodyUser returns the UID and GID of the "nobody" user. Hardcode its value
// for simplicity.
const nobodyUser = 65534

// parseMountedFiles returns the maximum UID and GID found in the /etc/passwd and
// /etc/group files.
func parseMountedFiles(containerMount, passwdFile, groupFile string) uint32 {
Expand All @@ -98,10 +102,10 @@ func parseMountedFiles(containerMount, passwdFile, groupFile string) uint32 {
if u.Name == "nobody" {
continue
}
if u.Uid > size {
if u.Uid > size && u.Uid != nobodyUser {
size = u.Uid
}
if u.Gid > size {
if u.Gid > size && u.Gid != nobodyUser {
size = u.Gid
}
}
Expand All @@ -113,7 +117,7 @@ func parseMountedFiles(containerMount, passwdFile, groupFile string) uint32 {
if g.Name == "nobody" {
continue
}
if g.Gid > size {
if g.Gid > size && g.Gid != nobodyUser {
size = g.Gid
}
}
Expand Down

0 comments on commit 038679c

Please sign in to comment.