From 212c43f4a06fe17fdc70f1b9d7fa4dcb6f4d7874 Mon Sep 17 00:00:00 2001 From: Lukasz Raczylo Date: Wed, 2 Dec 2026 01:45:34 +0000 Subject: [PATCH] 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. --- oidc_registry.go | 18 ++++++++++++++---- oidc_registry_test.go | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 4 deletions(-) diff --git a/oidc_registry.go b/oidc_registry.go index cefae62..1044e84 100644 --- a/oidc_registry.go +++ b/oidc_registry.go @@ -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, diff --git a/oidc_registry_test.go b/oidc_registry_test.go index eec2e9b..546adb3 100644 --- a/oidc_registry_test.go +++ b/oidc_registry_test.go @@ -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", "alice@x.com") + put("oidc:bob@x.com", "bob@x.com") + put("bob-old", "bob@x.com") + if err := fx.gw.auth.replaceFileUsers([]*UserConfig{{Name: "alice-new", OIDCIdentity: "alice@x.com"}}); err != nil { + t.Fatal(err) + } + put("alice-new", "alice@x.com") + 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:bob@x.com": true, + "bob-old": false, + } { + if _, ok := findUserSummary(users, name); ok != want { + t.Errorf("%s listed = %v, want %v", name, ok, want) + } + } +}