From 83b1d2310a28ef72a20f853fc5c57091cc06162e Mon Sep 17 00:00:00 2001 From: Erik Tate Date: Tue, 5 Nov 2024 11:12:19 -0500 Subject: [PATCH] adding missing GID value when fetching Hostuser (#48245) --- integration/hostuser_test.go | 22 ++++++++++++++++++++++ lib/srv/usermgmt.go | 1 + 2 files changed, 23 insertions(+) diff --git a/integration/hostuser_test.go b/integration/hostuser_test.go index 242908525cdf3..2f7a741e513f5 100644 --- a/integration/hostuser_test.go +++ b/integration/hostuser_test.go @@ -583,6 +583,28 @@ func TestRootHostUsers(t *testing.T) { require.NoError(t, err) require.False(t, hasExpirations) }) + + t.Run("Test migrate unmanaged user", func(t *testing.T) { + t.Cleanup(func() { cleanupUsersAndGroups([]string{testuser}, []string{types.TeleportKeepGroup}) }) + + users := srv.NewHostUsers(context.Background(), presence, "host_uuid") + _, err := host.UserAdd(testuser, nil, host.UserOpts{}) + require.NoError(t, err) + + closer, err := users.UpsertUser(testuser, services.HostUsersInfo{Mode: services.HostUserModeKeep, Groups: []string{types.TeleportKeepGroup}}) + require.NoError(t, err) + require.Nil(t, closer) + + u, err := user.Lookup(testuser) + require.NoError(t, err) + + gids, err := u.GroupIds() + require.NoError(t, err) + + keepGroup, err := user.LookupGroup(types.TeleportKeepGroup) + require.NoError(t, err) + require.Contains(t, gids, keepGroup.Gid) + }) } type hostUsersBackendWithExp struct { diff --git a/lib/srv/usermgmt.go b/lib/srv/usermgmt.go index 77dec5c37d0fd..c73e1db41390e 100644 --- a/lib/srv/usermgmt.go +++ b/lib/srv/usermgmt.go @@ -689,6 +689,7 @@ func (u *HostUserManagement) getHostUser(username string) (*HostUser, error) { return &HostUser{ Name: username, UID: usr.Uid, + GID: usr.Gid, Home: usr.HomeDir, Groups: groups, }, trace.NewAggregate(groupErrs...)