fix(auth): hide renamed oidc override names in the user list

A renamed users file override left its old name in the Redis registry.
The admin list showed that name for up to 32 days.

The list now shows a registry record only under the name its identity
resolves to now. This is the override name, or the default oidc name when
no override exists. Usage counters stay untouched.
This commit is contained in:
2026-12-02 02:02:44 +00:00
parent e94225a569
commit 212c43f4a0
2 changed files with 49 additions and 4 deletions
+14 -4
View File
@@ -156,8 +156,9 @@ func (r *oidcRegistry) logError(op string, err error) {
// oidcSummaries lists the OIDC virtual users for snapshot: the ones in
// memory, then registry records for users this replica has not seen.
// Registry users whose groups are all gone, or whose last request is older
// than oidcRegistryRetention, are hidden.
// Registry users whose groups are all gone, whose last request is older
// than oidcRegistryRetention, or whose stored name is not the name their
// identity resolves to now, are hidden.
func (a *authStore) oidcSummaries(skip map[string]bool) []userSummary {
if a.oidcAuth == nil {
return nil
@@ -182,7 +183,7 @@ func (a *authStore) oidcSummaries(skip map[string]bool) []userSummary {
a.mu.RUnlock()
cutoff := a.nowFn().Add(-oidcRegistryRetention).Unix()
for name, rec := range recs {
if skip[name] || rec.LastSeen < cutoff {
if skip[name] || rec.LastSeen < cutoff || name != resolvedOIDCName(overrides[rec.Identity], rec.Identity) {
continue
}
var members []*group
@@ -197,7 +198,7 @@ func (a *authStore) oidcSummaries(skip map[string]bool) []userSummary {
continue
}
var own *LimitsConfig
if ov := overrides[rec.Identity]; ov != nil && ov.name == name {
if ov := overrides[rec.Identity]; ov != nil {
own = ov.limits
}
limits, sources := effectiveUserLimits(own, members)
@@ -210,6 +211,15 @@ func (a *authStore) oidcSummaries(skip map[string]bool) []userSummary {
return out
}
// resolvedOIDCName is the accounting name an identity gets now: its
// override's name, else the default prefixed name.
func resolvedOIDCName(ov *oidcOverride, identity string) string {
if ov != nil {
return ov.name
}
return oidcNamePrefix + identity
}
func virtualSummary(u *user) userSummary {
return userSummary{
limits: u.limits,
+35
View File
@@ -179,3 +179,38 @@ func TestSnapshot_NoRedis(t *testing.T) {
}
func itoa(n int64) string { return strconv.FormatInt(n, 10) }
func TestSnapshot_RegistryHidesRenamedOverride(t *testing.T) {
ln := newBehavioralRedisServer(t)
fx := newOIDCGateway(t, func(cfg *Config) { cfg.Redis = &RedisConfig{Address: ln.Addr().String()} })
now := fx.gw.auth.nowFn().Unix()
put := func(name, identity string) {
t.Helper()
rec := `{"identity":"` + identity + `","groups":["default"],"lastSeen":` + itoa(now) + `}`
if _, err := fx.gw.redisClient.do("HSET", oidcRegistryKey, name, rec); err != nil {
t.Fatal(err)
}
}
put("alice-old", "[email protected]")
put("oidc:[email protected]", "[email protected]")
put("bob-old", "[email protected]")
if err := fx.gw.auth.replaceFileUsers([]*UserConfig{{Name: "alice-new", OIDCIdentity: "[email protected]"}}); err != nil {
t.Fatal(err)
}
put("alice-new", "[email protected]")
reg := fx.gw.auth.oidcRegistry
reg.mu.Lock()
reg.cached = nil
reg.mu.Unlock()
users, _ := fx.gw.auth.snapshot()
for name, want := range map[string]bool{
"alice-old": false,
"alice-new": true,
"oidc:[email protected]": true,
"bob-old": false,
} {
if _, ok := findUserSummary(users, name); ok != want {
t.Errorf("%s listed = %v, want %v", name, ok, want)
}
}
}