chore(auth): drop redundant WEKNORA_AUTH_REGISTRATION_MODE env override

DISABLE_REGISTRATION=true (handler layer) and
WEKNORA_AUTH_REGISTRATION_MODE=invite_only (config layer) were two
env-level ways of saying the same thing: block /auth/register.
Keeping both invites confusion about which wins and risks operators
setting one while expecting the other.

Remove the WEKNORA_AUTH_REGISTRATION_MODE env override so the env
layer exposes a single knob (DISABLE_REGISTRATION). The
auth.registration_mode config field stays — operators who want the
richer behaviour (frontend hides the registration entry via
/auth/config in addition to the server-side 403) flip it in
config.yaml.

No behaviour change for deployments that did not set the env var.
Update docs/rbac.md to document the deliberate split.
This commit is contained in:
wizardchen
2026-05-18 21:07:44 +08:00
committed by lyingbug
parent 4344765cf9
commit 2ab54f1542
2 changed files with 14 additions and 5 deletions
+7 -1
View File
@@ -130,9 +130,15 @@ Environment overrides (always win over YAML):
| Env var | YAML key | Values |
|--------------------------------------|--------------------------------|------------------------------|
| `WEKNORA_TENANT_ENABLE_RBAC` | `tenant.enable_rbac` | `true` / `false` |
| `WEKNORA_AUTH_REGISTRATION_MODE` | `auth.registration_mode` | `self_serve` / `invite_only` |
| `WEKNORA_AUDIT_RETENTION_DAYS` | `audit.retention_days` | non-negative integer |
`auth.registration_mode` is intentionally not env-overridable to avoid
duplicating the long-standing `DISABLE_REGISTRATION` env knob. Set
`auth.registration_mode: invite_only` in `config.yaml` when you want the
frontend to hide the registration entry in addition to the server-side
block; use `DISABLE_REGISTRATION=true` for a quick env-level kill switch
that only enforces server-side.
The startup logger emits one line summarising both effective values
plus their override sources, so you can confirm at boot which mode
the deployment is in.
+7 -4
View File
@@ -707,12 +707,18 @@ func applyAgentEnvOverrides(cfg *Config) {
// - tenant.enable_rbac -> false (rolled out in two steps; flip later)
//
// Env overrides (when set and non-empty):
// - WEKNORA_AUTH_REGISTRATION_MODE ("self_serve" or "invite_only")
// - WEKNORA_TENANT_ENABLE_RBAC ("true"/"false", case-insensitive)
// - WEKNORA_TENANT_MAX_OWNED_PER_USER (integer; <0 disables the cap,
// 0 falls back to the handler default, >0 enforces that exact cap).
// 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.
func applyAuthAndTenantDefaults(cfg *Config) {
if cfg.Auth == nil {
cfg.Auth = &AuthConfig{}
@@ -721,9 +727,6 @@ func applyAuthAndTenantDefaults(cfg *Config) {
cfg.Tenant = &TenantConfig{}
}
if value := strings.TrimSpace(os.Getenv("WEKNORA_AUTH_REGISTRATION_MODE")); value != "" {
cfg.Auth.RegistrationMode = value
}
if strings.TrimSpace(cfg.Auth.RegistrationMode) == "" {
cfg.Auth.RegistrationMode = AuthRegistrationModeSelfServe
}