From 4919fe76fdb1c674bc180adf8db6a6228b9424a4 Mon Sep 17 00:00:00 2001 From: Erik Tate Date: Fri, 13 Sep 2024 10:24:02 -0400 Subject: [PATCH] adding better error message with reference to /etc/nsswitch.conf when looking up a user results in ENOENT (#46556) --- lib/srv/usermgmt_linux.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/srv/usermgmt_linux.go b/lib/srv/usermgmt_linux.go index 0fa1392829ec2..2c3fb0ef34b7a 100644 --- a/lib/srv/usermgmt_linux.go +++ b/lib/srv/usermgmt_linux.go @@ -18,6 +18,7 @@ package srv import ( "bufio" + "errors" "fmt" "os" "os/user" @@ -59,7 +60,16 @@ func newHostSudoersBackend(uuid string) (HostSudoersBackend, error) { // Lookup implements host user information lookup func (*HostUsersProvisioningBackend) Lookup(username string) (*user.User, error) { - return user.Lookup(username) + usr, err := user.Lookup(username) + if err != nil { + if !errors.Is(err, user.UnknownUserError(username)) && strings.Contains(err.Error(), "no such file or directory") { + return nil, trace.Wrap(err, "looking up user %q, sources configured for passwd in host's /etc/nsswitch.conf may be misconfigured", username) + } + + return nil, trace.Wrap(err) + } + + return usr, nil } // UserGIDs returns the list of group IDs for a user