From cc134f85351bc19195819b580e1a2404573a790d Mon Sep 17 00:00:00 2001 From: Georg Pfuetzenreuter Date: Thu, 6 Aug 2026 15:53:45 +0200 Subject: [PATCH] internal: type switching for uidNumber/gidNumber When the uidNumber attribute was set as an integer without an explicit gidNumber, the system would generate a gidNumber instead of mapping the uidNumber. The mapping only worked if uidNumber was set as a string. As uidNumber/gidNumber are commonly integers, avoid the need for faking strings in the user attributes by matching the behavior. This also reduces implementation confusion, as the documentation states The gidNumber attribute of each virtual group is equal to the uidNumber of the user. without imposing any limitations on the data type. Signed-off-by: Georg Pfuetzenreuter --- internal/outpost/ldap/utils.go | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/internal/outpost/ldap/utils.go b/internal/outpost/ldap/utils.go index 9bf8ac340f67..f9f523abf50b 100644 --- a/internal/outpost/ldap/utils.go +++ b/internal/outpost/ldap/utils.go @@ -7,6 +7,22 @@ import ( api "goauthentik.io/packages/client-go" ) +func getAttributeString(attributes map[string]any, key string) (string, bool) { + val, ok := attributes[key] + if !ok || val == nil { + return "", false + } + + switch v := val.(type) { + case string: + return v, true + case float64: + return strconv.FormatFloat(v, 'f', -1, 64), true + default: + return "", false + } +} + func (pi *ProviderInstance) GroupsForUser(user api.User) []string { groups := make([]string, len(user.Groups)) for i, group := range user.GroupsObj { @@ -48,7 +64,7 @@ func (pi *ProviderInstance) GetVirtualGroupDN(group string) string { } func (pi *ProviderInstance) GetUserUidNumber(user api.User) string { - uidNumber, ok := user.GetAttributes()["uidNumber"].(string) + uidNumber, ok := getAttributeString(user.GetAttributes(), "uidNumber") if ok { return uidNumber @@ -58,7 +74,7 @@ func (pi *ProviderInstance) GetUserUidNumber(user api.User) string { } func (pi *ProviderInstance) GetUserGidNumber(user api.User) string { - gidNumber, ok := user.GetAttributes()["gidNumber"].(string) + gidNumber, ok := getAttributeString(user.GetAttributes(), "gidNumber") if ok { return gidNumber @@ -68,7 +84,7 @@ func (pi *ProviderInstance) GetUserGidNumber(user api.User) string { } func (pi *ProviderInstance) GetGroupGidNumber(group api.Group) string { - gidNumber, ok := group.GetAttributes()["gidNumber"].(string) + gidNumber, ok := getAttributeString(group.GetAttributes(), "gidNumber") if ok { return gidNumber