fix(auth): make DISABLE_REGISTRATION drive registration_mode too
DISABLE_REGISTRATION=true used to block /auth/register at the handler layer only, leaving /auth/config still reporting self_serve. The frontend therefore kept showing the Register entry even when the env var was set — clicking it just hit the 403. Two gates, out of sync. Wire DISABLE_REGISTRATION=true through applyAuthAndTenantDefaults so it coerces auth.registration_mode to invite_only (env wins over YAML, matching docs/rbac.md). The handler-side os.Getenv check is now redundant with IsInviteOnly() and is removed, leaving a single enforcement path. Add config tests pinning down the env/YAML matrix, including the explicit-self_serve override case that would otherwise be the easy regression to ship.
This commit is contained in:
@@ -713,12 +713,12 @@ func applyAgentEnvOverrides(cfg *Config) {
|
||||
// Unparseable / empty values are ignored so a stale shell variable
|
||||
// can't silently disable the quota for a future deployment.
|
||||
//
|
||||
// Note: auth.registration_mode is intentionally NOT env-overridable.
|
||||
// Operators who need to turn off public registration set the legacy
|
||||
// DISABLE_REGISTRATION=true env (handled at the /auth/register handler
|
||||
// layer) or flip auth.registration_mode in config.yaml; the env layer
|
||||
// keeps a single knob to avoid two redundant ways of saying the same
|
||||
// thing.
|
||||
// Note: auth.registration_mode has no dedicated env override. The
|
||||
// long-standing DISABLE_REGISTRATION=true env var is the single env-layer
|
||||
// knob and, when set, coerces registration_mode to invite_only here. That
|
||||
// way both the API gate (handler) and the /auth/config-driven UI gate
|
||||
// (frontend hides the register entry) stay consistent — without needing
|
||||
// two parallel env vars.
|
||||
func applyAuthAndTenantDefaults(cfg *Config) {
|
||||
if cfg.Auth == nil {
|
||||
cfg.Auth = &AuthConfig{}
|
||||
@@ -727,6 +727,17 @@ func applyAuthAndTenantDefaults(cfg *Config) {
|
||||
cfg.Tenant = &TenantConfig{}
|
||||
}
|
||||
|
||||
if legacy := strings.TrimSpace(os.Getenv("DISABLE_REGISTRATION")); strings.EqualFold(legacy, "true") {
|
||||
prev := strings.TrimSpace(cfg.Auth.RegistrationMode)
|
||||
cfg.Auth.RegistrationMode = AuthRegistrationModeInviteOnly
|
||||
if prev != "" && prev != AuthRegistrationModeInviteOnly {
|
||||
fmt.Printf(
|
||||
"[config] DISABLE_REGISTRATION=true overrides auth.registration_mode=%q -> %q\n",
|
||||
prev, AuthRegistrationModeInviteOnly,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
if strings.TrimSpace(cfg.Auth.RegistrationMode) == "" {
|
||||
cfg.Auth.RegistrationMode = AuthRegistrationModeSelfServe
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user