From 2ab54f15424c5e9a6cfb28034eabe0210ce15dc0 Mon Sep 17 00:00:00 2001 From: wizardchen Date: Mon, 18 May 2026 21:07:44 +0800 Subject: [PATCH] chore(auth): drop redundant WEKNORA_AUTH_REGISTRATION_MODE env override MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- docs/rbac.md | 8 +++++++- internal/config/config.go | 11 +++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/docs/rbac.md b/docs/rbac.md index 85d976a4..77c03b46 100644 --- a/docs/rbac.md +++ b/docs/rbac.md @@ -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. diff --git a/internal/config/config.go b/internal/config/config.go index 07febc00..262d842f 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -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 }