users: eliminate nobody user memoization (#16904)

This PR eliminates code specific to looking up and caching the uid/gid/user.User
object associated with the nobody user in an init block. This code existed before
adding the generic users cache and was meant to optimize the one search path we
knew would happen often. Now that we have the cache, seems reasonable to eliminate
this init block and use the cache instead like for any other user.

Also fixes a constraint on the podman (and other) drivers, where building without
CGO became problematic on some OS like Fedora IoT where the nobody user cannot
be found with the pure-Go standard library.

Fixes github.com/hashicorp/nomad-driver-podman/issues/228
This commit is contained in:
Seth Hoenig
2023-04-17 12:30:30 -05:00
committed by GitHub
parent a46e8e62fe
commit ed0dfd2ffb
3 changed files with 9 additions and 65 deletions

View File

@@ -43,14 +43,17 @@ func dropDirPermissions(path string, desired os.FileMode) error {
return nil
}
nobody := users.Nobody()
u, err := users.Lookup("nobody")
if err != nil {
return fmt.Errorf("Unable to find nobody user: %w", err)
}
uid, err := getUid(&nobody)
uid, err := getUid(u)
if err != nil {
return err
}
gid, err := getGid(&nobody)
gid, err := getGid(u)
if err != nil {
return err
}