diff --git a/services/proxy/pkg/command/server.go b/services/proxy/pkg/command/server.go index c0a08116358..7ce31a90ec9 100644 --- a/services/proxy/pkg/command/server.go +++ b/services/proxy/pkg/command/server.go @@ -373,6 +373,7 @@ func loadMiddlewares(logger log.Logger, cfg *config.Config, middleware.Logger(logger), middleware.WithRevaGatewaySelector(gatewaySelector), middleware.RoleQuotas(cfg.RoleQuotas), + middleware.CreateHomeCacheDisabled(cfg.CreateHomeCacheDisabled), ), // trigger space assignment when a user logs in middleware.SpaceManager( diff --git a/services/proxy/pkg/config/config.go b/services/proxy/pkg/config/config.go index 9ce6faf3f1d..bef3f4708ab 100644 --- a/services/proxy/pkg/config/config.go +++ b/services/proxy/pkg/config/config.go @@ -48,6 +48,7 @@ type Config struct { ClaimSpaceManagement ClaimSpaceManagement `yaml:"claim_space_management"` MultiFactorAuthentication MFAConfig `yaml:"mfa"` MultiInstance MultiInstanceConfig `yaml:"multi_instance"` + CreateHomeCacheDisabled bool `yaml:"create_home_cache_disabled" env:"PROXY_CREATEHOME_CACHE_DISABLED" desc:"Disable the in-memory cache that skips redundant CreateHome calls for users whose home has already been created. Set this to true as a fallback if the cache causes unexpected behavior." introductionVersion:"8.0.0"` Context context.Context `json:"-" yaml:"-"` } diff --git a/services/proxy/pkg/middleware/create_home.go b/services/proxy/pkg/middleware/create_home.go index eff88f8cf7d..b69f37d5517 100644 --- a/services/proxy/pkg/middleware/create_home.go +++ b/services/proxy/pkg/middleware/create_home.go @@ -26,12 +26,15 @@ func CreateHome(optionSetters ...Option) func(next http.Handler) http.Handler { options := newOptions(optionSetters...) logger := options.Logger + cacheDisabled := options.CreateHomeCacheDisabled + return func(next http.Handler) http.Handler { return &createHome{ next: next, logger: logger, revaGatewaySelector: options.RevaGatewaySelector, roleQuotas: options.RoleQuotas, + cacheDisabled: cacheDisabled, } } } @@ -41,6 +44,7 @@ type createHome struct { logger log.Logger revaGatewaySelector pool.Selectable[gateway.GatewayAPIClient] roleQuotas map[string]uint64 + cacheDisabled bool knownHomes sync.Map // map[userID]struct{} — users whose home is confirmed flight singleflight.Group // collapses concurrent CreateHome calls per user @@ -66,9 +70,11 @@ func (m *createHome) ServeHTTP(w http.ResponseWriter, req *http.Request) { userID := u.Id.OpaqueId // Fast path: home already known to exist for this user. - if _, ok := m.knownHomes.Load(userID); ok { - m.next.ServeHTTP(w, req) - return + if !m.cacheDisabled { + if _, ok := m.knownHomes.Load(userID); ok { + m.next.ServeHTTP(w, req) + return + } } createHomeReq := &provider.CreateHomeRequest{} @@ -106,7 +112,7 @@ func (m *createHome) ServeHTTP(w http.ResponseWriter, req *http.Request) { }) // Only cache on success — if CreateHome failed, retry on next request. - if err == nil { + if err == nil && !m.cacheDisabled { m.knownHomes.Store(userID, struct{}{}) } diff --git a/services/proxy/pkg/middleware/options.go b/services/proxy/pkg/middleware/options.go index 503273a564e..bd030839459 100644 --- a/services/proxy/pkg/middleware/options.go +++ b/services/proxy/pkg/middleware/options.go @@ -77,6 +77,8 @@ type Options struct { // Service Accounts ServiceAccountID string ServiceAccountSecret string + // CreateHomeCacheDisabled disables the knownHomes cache in the CreateHome middleware + CreateHomeCacheDisabled bool // Multi-Instance Options MultiInstanceEnabled bool InstanceID string @@ -236,6 +238,13 @@ func AccessTokenVerifyMethod(method string) Option { } } +// CreateHomeCacheDisabled provides a function to disable the CreateHome cache. +func CreateHomeCacheDisabled(val bool) Option { + return func(o *Options) { + o.CreateHomeCacheDisabled = val + } +} + // RoleQuotas sets the role quota mapping setting func RoleQuotas(roleQuotas map[string]uint64) Option { return func(o *Options) {