feat(proxy): add PROXY_CREATEHOME_CACHE_DISABLED env var
Allow operators to disable the in-memory CreateHome cache via PROXY_CREATEHOME_CACHE_DISABLED as a fallback if the cache causes unexpected behavior. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
a087a99da0
commit
e227983a9f
4 files changed
+21
-4
No files matched your search
@@ -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(
|
||||
|
||||
@@ -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:"-"`
|
||||
}
|
||||
|
||||
@@ -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{}{})
|
||||
}
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in new issue
Block a user