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:
wizardchen
2026-05-18 21:14:10 +08:00
committed by lyingbug
parent 2ab54f1542
commit 49f3ad185a
4 changed files with 69 additions and 21 deletions
+7 -6
View File
@@ -132,12 +132,13 @@ Environment overrides (always win over YAML):
| `WEKNORA_TENANT_ENABLE_RBAC` | `tenant.enable_rbac` | `true` / `false` |
| `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.
`auth.registration_mode` has no dedicated env override to avoid
duplicating the long-standing `DISABLE_REGISTRATION` env knob. When
`DISABLE_REGISTRATION=true` is set, startup coerces
`auth.registration_mode` to `invite_only` so both the API gate and the
`/auth/config`-driven UI gate (frontend hides the registration entry)
stay consistent. To pick a mode without the env var, set
`auth.registration_mode` in `config.yaml`.
The startup logger emits one line summarising both effective values
plus their override sources, so you can confirm at boot which mode