Audience: the operator who will actually turn MFA enforcement on. This is not a design doc; it is the order of operations, the preconditions that will lock you out if you skip them, and how to roll back.
Default posture today: enforcement is OFF on a cluster and nothing here changes
that. Seeding the mfa_required rules (below) is inert until you flip a flag.
STATUS, verified against
mainon 2026-08-06. This runbook was written on branchfeat/mfa-required-ruleswhile its companionfeat/gateway-mfa-envwas still open, and much of the text below was phrased for that moment. Both halves are now merged. The knob EXISTS: the shared chart carries anmfa:values block (specs/cluster/charts/hugmesh-gateway/values.yaml), its template rendersAPP_MFA_ENABLED/APP_MFA_FRESHNESS_WINDOW/APP_MFA_ENFORCE_PRIVILEGED_FLOORinto every gateway pod, compose defaultsAPP_MFA_ENABLED=true, andtests/stack/test-gateway-mfa-env.shpins both postures (101 passed / 0 failed, alongsidetest-mfa-required-rules.shat 99/0). Confirmed on a live kind cluster: a running fe-gateway pod carries all three env vars,APP_MFA_ENABLED=false.So §3 step 6 is actionable, not a no-op, and every "needs the companion / until it lands there is no knob" caveat below is HISTORICAL. What has NOT changed is the hard precondition: enrolling every privileged operator (§2) still gates the flip, and the cluster still ships
falsedeliberately.Re-measured 2026-10-14 on
main(c0c46601). Nothing code-side is left to land: the chart block, the rendered env, themfa_requiredrows (16 flipped + 1 deny row carrying the floor;mainat that commit had 10 + 1, the four per-service console rows of decision 80b take it to 14 + 1, and the two tube admin rows of 2026-10-15 to 16 + 1) and the posture gates are all present and green. What is left is the operator's live flip, and §9 is the checklist for it, with the exact commands. Two things in the older text were wrong and are corrected below rather than left to mislead: the flip changes three gate suites, not one (§3 steps 6 and 7), and "do the floor on one gateway first" cannot be done through the chart (§3 step 7).
The feature shipped as two halves in two commits, and this runbook was written with the first one. The table records which half contributed what.
| half | what it contains | where it is |
|---|---|---|
| rows (this change) | the mfa_required UPDATE in 20-schema.sql, this runbook, tests/scripts/test-mfa-required-rules.sh |
branch feat/mfa-required-rules |
| flag wiring (companion) | the shared chart's mfa: values block, the chart template that renders APP_MFA_ENABLED / APP_MFA_FRESHNESS_WINDOW / APP_MFA_ENFORCE_PRIVILEGED_FLOOR into every gateway pod, the compose-stack defaults, tests/stack/test-gateway-mfa-env.sh |
branch feat/gateway-mfa-env |
What that meant on the authoring branch, kept for provenance:
-
HISTORICAL (true only before the companion merged): nothing in the chart, the gateway Applications or the compose stack mentioned the gateway MFA env, so the rows were not merely default-off but unreachable — no supported knob could make the gateway consult them. The verification command below was documented as printing exit
1.On
maintoday it prints0, and that is the correct, expected result:$ grep -rn 'APP_MFA_ENABLED\|APP_MFA_ENFORCE_PRIVILEGED_FLOOR' \ specs/cluster/charts specs/cluster/apps tests/stack/ specs/cluster/charts/hugmesh-gateway/values.yaml:... # the mfa: values block specs/cluster/charts/hugmesh-gateway/templates/deployment.yaml:207: - name: APP_MFA_ENABLED tests/stack/test-gateway-mfa-env.sh:... # the posture pins $ echo $? 0
If you are reading this on a checkout where that command still exits
1, you are before the companion merge — treat the caveats below as live rather than historical. -
Do not work around that by hand-adding an
extraEnv: APP_MFA_ENABLEDto a gateway Application. That is exactly what the posture gate intests/scripts/test-mfa-required-rules.shfails the build on, structurally, in every ArgoCD input shape (helm.values,helm.valuesObject,helm.parameters, and ahelm.valueFilesreference it refuses to treat as auditable).
Merge order: either order is safe — each half is inert without the other — but
they should land in the same release, and the two references between them only
resolve once both are in. The companion's
specs/cluster/apps/22-gateway-superadmin.yaml comment points at "the step-by-step
rollout runbook [that] arrives with the route-access mfa_required change", i.e. at
this file; and §1.3/§3 below point back at the companion's chart values. Merging
only the companion leaves a live flag with no row to match on (a no-op); merging only
this one leaves rows with no flag that can reach them (also a no-op). Merging neither
is today's posture.
Wherever a claim below was only true after the companion landed, it says so explicitly. Nothing in this document is written as though the wiring were already here.
app.casdoor.mfa.enabled is already true in both deployment targets:
| Where | File | Value |
|---|---|---|
| Cluster | specs/cluster/manifests/admin-bff-api/deployment.yaml (APP_CASDOOR_MFA_ENABLED) |
"true" |
| Compose dev stack | tests/stack/compose.local.yaml (APP_CASDOOR_MFA_ENABLED) |
${APP_CASDOOR_MFA_ENABLED:-true} |
This is the leg that lets a fresh MFA stamp on the opaque bff_ session satisfy
a step-up gate (ImageGenStepUpGate, PhoneLockStepUpGate, GoLiveStepUpGate,
SshKeyIssueStepUpGate, …) as a co-equal alternative to the token-based step-up.
It is a pure additive OR — it does not gate ordinary login, and it does not gate any
route at the gateway. It also arms the enrollment/challenge API
(/bff/mfa/**); with the flag off, every /bff/mfa/** endpoint returns 503.
Prerequisite for that leg, already provisioned: APP_MFA_FACTOR_KEY — see §4.
specs/cluster/manifests/route-access/initdb/20-schema.sql now ends its seed with:
UPDATE gateway_route_access
SET mfa_required = true
WHERE allow = true
AND (url_pattern = '/bff/admin'
OR url_pattern LIKE '/bff/admin/%'
OR url_pattern LIKE '/bff/%/admin/%'
OR url_pattern = '/bff/superadmin'
OR url_pattern LIKE '/bff/superadmin/%'
OR url_pattern LIKE '/bff/%/superadmin/%'
OR (COALESCE(NULLIF(lower(trim(domain)), 'default'), '') <> ''
AND url_pattern IN ('')))
AND mfa_required IS DISTINCT FROM true;(That block is not retyped prose: the gate compares it byte-for-byte against the
statement in 20-schema.sql, so it cannot drift.)
The final OR is the per-domain arm (issue #47 × the casdoor-choice
schema): list a url_pattern in its IN (…) and every domain-scoped row
carrying it gets the same re-apply convergence the two blanket prefixes get.
It is empty today — the empty-string element matches no pattern, so the
flip set is exactly the 16 rows below — and §1.2a explains when (and when not)
to widen it.
The /bff/admin… and /bff/superadmin… arms are the two original prefixes; the
/bff/%/admin/% and /bff/%/superadmin/% arms are the per-service console
shape added by operator decision 80b = B (hugmesh-generator#329, 2026-09-23). %
spans any characters, / included, so a later /bff/<service>/admin/… row is
picked up with no edit to the UPDATE.
That flips 16 rows (as of this writing) across three gateways:
| gateway | url_pattern | role |
|---|---|---|
hugmesh-fe-gateway |
/bff/admin/** |
ROLE_ADMIN |
hugmesh-fe-gateway |
/bff/admin/phone-fleet/** |
ROLE_FLEET_ADMIN, ROLE_ADMIN, ROLE_SUPERADMIN |
hugmesh-fe-gateway |
/bff/superadmin/** |
ROLE_SUPERADMIN |
hugmesh-fe-gateway |
/bff/forum/admin/** |
ROLE_ADMIN |
hugmesh-fe-gateway |
/bff/wiki/admin/** |
ROLE_ADMIN |
hugmesh-fe-gateway |
/bff/wiki/superadmin/** |
ROLE_SUPERADMIN |
hugmesh-fe-gateway |
/bff/owncast/admin/** |
ROLE_ADMIN |
hugmesh-fe-gateway |
/bff/tube/admin/access/** |
ROLE_ADMIN |
hugmesh-fe-gateway |
/bff/tube/admin/storage-budget/** |
ROLE_ADMIN |
hugmesh-be-gateway |
/bff/admin/workloads/** |
ROLE_ADMIN |
hugmesh-be-gateway |
/bff/superadmin/** |
ROLE_SUPERADMIN |
hugmesh-be-gateway |
/bff/superadmin/games-services/** |
ROLE_SUPERADMIN |
hugmesh-be-gateway |
/bff/superadmin/workloads/** |
ROLE_SUPERADMIN |
hugmesh-superadmin-gateway |
/bff/superadmin/** |
ROLE_SUPERADMIN |
The two /bff/tube/admin/… rows are the tube ADMIN write surfaces (operator
decision 2026-10-15, hugmesh-tube-ui#19 / hugmesh-wiki-ui#25: the gateway sends
X-Step-Up-Required on an mfa_required deny). They need no statement of their own:
the per-service /bff/%/admin/% arm flips them like the forum, wiki and owncast
consoles. /** and not /*: the revoke is DELETE /access/{type}/{user}, two
segments down, and * is one segment in AntPathMatcher, so /access/* would leave
revoke on the ungated /bff/tube/** floor. /storage-budget/** also matches the
bare path. What they do and do not do: tube-bff admits only ADMIN and
SUPERADMIN on /bff/tube/admin/**, and GatewayRouteAccessFilter forwards both
before decide() runs, so for those callers the rows bite only through the
privileged floor (§3 step 7); app.mfa.enabled alone gates nothing for a tube
admin. Their one effect inside decide() is on a non-admin: a plain ROLE_TUBE
holder now gets 403 + X-Route-Denied at the gateway door for these paths instead
of a refusal one layer down in tube-bff. The rest of /bff/tube/** stays on the
ungated ROLE_TUBE floor.
A seventeenth row ends up at mfa_required = true without being flipped by this
UPDATE: the hugmesh-fe-gateway /bff/superadmin/games-services/** DENY row,
which the blanket flip cannot reach (WHERE allow = true) and which is seeded by its
own row-scoped UPDATE immediately before it. It is not in the table above because
this table is the flip's scope, not the floor's — see §5's deny-floor table for the
floor's full membership, and why a deny row carries one at all.
Read that table twice. /bff/superadmin/** is governed on three gateways —
hugmesh-fe-gateway joined the be and superadmin gateways when #244 was answered
ACCEPT — and /bff/admin/… on two; the write is prefix-based and gateway-blind on
purpose, because scoping it to one gateway name would leave the other as an
un-MFA'd second door to the same paths. Matching is longest-pattern-wins, so
flipping only the two /** floors would leave every longer sub-path row as the
deciding rule with mfa_required=false — a bypass on exactly the
highest-value surfaces (phone-fleet, workloads, games-services).
tests/scripts/test-mfa-required-rules.sh pins all of that, with negative controls.
Every behavioural verdict there is read back from a real SQL engine after
replaying the file's own statements in file order, never inferred from the text of
one statement — so a later statement that un-flips, deletes or partially reverts one
of these rows is caught by the result, in any spelling. (A handful of intent
checks are still textual — that the UPDATE is gateway-blind, allow-only, and says
IS DISTINCT FROM true — but nothing about the file's net effect is.) The default
engine is sqlite3, and a plain local run says so. Since leg 1c the seed is also
replayed verbatim on a real Postgres — twice, under ON_ERROR_STOP, nothing
translated or skipped — whenever POSTGRES_HOST is set, and .gitlab-ci.yml's
lint:mfa-required-rules always sets it (a postgres:16-alpine service container).
That leg replays the seed; the runbook's own SQL blocks (§3 step 4, §9) are still
executed on sqlite only, so their first contact with Postgres is the operator's.
(Whether that CI job is running at all is not something this file can tell you.)
The authorised scope is the two path prefixes /bff/admin… and
/bff/superadmin…, blanket within them, plus (operator decision 80b = B,
hugmesh-generator#329, answered 2026-09-23) the per-service console shape:
every allow row matching /bff/%/admin/% or /bff/%/superadmin/%, i.e. the admin
consoles that live behind a service-BFF's own prefix (today forum, wiki and
owncast: /bff/forum/admin/**, /bff/wiki/admin/**, /bff/wiki/superadmin/**,
/bff/owncast/admin/**; and since 2026-10-15 the two tube admin write surfaces
/bff/tube/admin/access/** and /bff/tube/admin/storage-budget/**). The operator
chose that deliberately over the narrower superadmin-only match, knowing it is the
larger-lockout-risk option: the §3 step-7 floor now also needs a fresh second factor
to reach those six consoles. It is
still not "every admin surface", and the difference matters if you are reasoning
about what an attacker can still reach with a stolen session and no second factor.
Three other admin-ish /bff/ rows are deliberately left mfa_required=false:
| gateway | url_pattern | role | why it is out of scope |
|---|---|---|---|
hugmesh-fe-gateway |
/bff/mod/** |
ROLE_ADMIN |
a moderation surface; ROLE_ADMIN is paired on it only as a superset of ROLE_MOD, so gating it would gate moderation, not administration |
hugmesh-be-gateway |
/bff/image-builds/arch/** |
ROLE_SUPERADMIN |
privileged by role, not by path — a prefix predicate cannot express it |
hugmesh-be-gateway |
/bff/games-services/instances/** |
ROLE_GAMES_SERVICES_ADMIN |
ditto (derived games-services ∩ (admin|mod) role) |
The first used to be one of seven: the four per-service console rows (forum,
wiki admin, wiki superadmin, owncast) were excluded until decision 80b widened the
predicate, and they are in the §1.2 table now. Each of the three that remain would
be a new scope decision, not a bug fix: widening enlarges the §3 step-7
lockout blast radius, so it is the operator's call. If you do widen, widen the
prose in the same commit — and note that the gate enumerates admin-ish surfaces
independently of the UPDATE's own predicate and cross-checks them against
exactly this list, so a fourth admin-ish /bff/ row appearing later that the
predicate does not reach fails the build until someone decides consciously (and a
stale entry in the list fails it too). A new /bff/<service>/admin/… row needs no
such decision: the shape already covers it, so it is gated from its first apply.
gateway_route_access rows carry a per-row domain, and the casdoor-choice
schema (PR #71, Domain.idp) makes multiple local domains behind one set of
gateways a first-class shape. What a domain-scoped row can and cannot express
for MFA is fixed by GatewayRouteAccessService.decide() in hugmesh-gateway
— verified against the source, not assumed: among the rows at the longest
matching url_pattern, decide() ORs mfa_required across every row that
grants the principal and domain-applies, and an unscoped row
(NULL/blank/default, case-insensitive, trimmed) domain-applies to every
domain. Hence this scope table:
| you want | expressible? | how / why not |
|---|---|---|
| the blanket (the two prefixes and the per-service console shape) on every domain, including rows someone scoped to one domain under them | yes — enforced | the seed UPDATE is domain-blind, deliberately, like it is gateway-blind. A scoped mfa_required=false row under the prefixes is a phantom exemption: the unscoped canonical row still applies to that domain and still pulls the MFA floor up, so the false row exempts nothing — the seed re-flips it to make the table say what the gateway does. And a scoped-only allow row (a per-domain admin surface with no unscoped twin) must not ship un-MFA'd inside the blanket |
| require a second factor on one domain only, on a surface outside the blanket (per-domain tightening) | yes | insert a domain-scoped sibling row — same gateway/url_pattern/role, its own domain, allow=true, mfa_required=true. domainApplies() keeps it off every other domain. To give it the same re-apply convergence the blanket has, also list its url_pattern in the UPDATE's per-domain arm (§1.2) and in the gate's PER_DOMAIN_SCOPE set — the gate cross-checks the two in both directions |
| exempt one domain from the blanket | no | not by a row (see the phantom-exemption note — decide() is a sticky OR), and not by the predicate (the blanket rows are unscoped, and unscoped rows apply to every domain). A real per-domain exemption means splitting the canonical rows per domain — a new scope decision with the full §3 step-7 blast-radius conversation attached |
an own-IdP domain (Domain.idp: own, PR #71) satisfying MFA |
no (today) — see the source chain below | its principals authenticate against the domain-local Casdoor and can never carry MFA_SATISFIED. On a shared-gateway mesh, treat that whole population like the §2.4 machine callers: enumerate own-IdP domains before §3 step 6, or their non-privileged holders (e.g. a pure ROLE_FLEET_ADMIN) are 403'd on every mfa_required surface with no way to enroll |
Re-verified 2026-08-20. §2.4 lists two carriers that CAN satisfy an mfa_required
route. An idp: own principal is closed out of both, and the two closures are
independent — fixing either one alone changes nothing:
- The opaque
bff_session leg is unreachable./bff/loginis bound to ONE Casdoor:CasdoorLoginConfig(hugmesh-user-bff-api) builds the singleCasdoorLoginClientfromapp.bff.oidc.login-base+app.bff.oidc.organization, with no per-domain routing anywhere on that path. A user who exists only in the domain-local Casdoor therefore never gets abff_sessionrow at all. - The raw-JWT leg never gets a stamp written.
mfa_satisfied_atis a user Property, andCasdoorAdminClient.writeMfaProperty(hugmesh-auth-core) writes it through the superdomain's admin client — never the domain-local Casdoor — so the claim cannot appear in a token minted by the domain's own issuer.
The tighter fact, and the reason raising the freshness window or pointing an admin
client at the tenant Casdoor would not be enough on its own: the bff_session row is
a hard precondition for the Property write too.
MfaChallengeService.onSessionStamped returns false and skips the advisory
Property leg entirely when the authoritative session stamp updates zero rows. So for
a principal with no bff_session, POST /bff/mfa/challenge cannot succeed and
mfa_satisfied_at is never written in any Casdoor. The blocker is the login
binding in (1), not only the Property's location in (2).
Cross-repo, and therefore NOT gate-pinned. Everything above lives in hugmesh-user-bff-api and hugmesh-auth-core; the generator's gates cannot see either, so nothing here fails the build when one of those classes changes. Re-read all three call sites named above before §3 step 6 on any mesh that hosts an
idp: owndomain.
The uniqueness key makes the sibling-row idiom safe: uq_route_access_row
keys its domain leg on the gateway's own scope equivalence
(COALESCE(NULLIF(lower(trim(domain)), 'default'), '')), so a 'Default' or
case/whitespace alias collides with the row it aliases instead of
duplicating it, while a genuinely scoped sibling keys differently and lands.
The tightening row shape, concretely — and this block is executed by the
gate against the replayed seed (inserted, then the whole seed re-applied over
it) to prove the row survives with mfa_required=true while its unscoped twin
stays false:
INSERT INTO gateway_route_access (gateway, url_pattern, role, allow, domain, mfa_required)
VALUES ('hugmesh-fe-gateway', '/bff/mod/**', 'ROLE_ADMIN', true, 'brand-x.example', true)
ON CONFLICT (gateway, url_pattern, role, COALESCE(casdoor_user, ''), COALESCE(NULLIF(lower(trim(domain)), 'default'), '')) DO NOTHING;Such rows are provisioning/CRUD data, not canonical seed rows — the
canonical seed stays domain-free because the reference mesh defines no extra
local domains. brand-x.example above is a placeholder; a real tightening row
carries the real domain and goes in through the admin-bff CRUD or a per-mesh
provisioning step, with the url_pattern listed in the per-domain arm in the
same change.
These rows do nothing until a gateway flag is on.
GatewayRouteAccessService.decide() consults mfa_required only when
app.mfa.enabled is true. And the converse is just as important: enabled: true
alone was a NO-OP before these rows existed — nothing else in the platform ever
wrote mfa_required=true, so the flag had nothing to match on. The flag and the
rules are two halves of one feature.
The hugmesh-gateway image reads three properties (its own
src/main/resources/application.yml), all default-off in the image itself. That is
the operator-facing contract, and it is true today:
| property | env | image default (today, cross-repo) |
|---|---|---|
app.mfa.enabled |
APP_MFA_ENABLED |
false (${APP_MFA_ENABLED:false}) |
app.mfa.freshness-window |
APP_MFA_FRESHNESS_WINDOW |
600000 (10 min) |
app.mfa.enforce-privileged-floor |
APP_MFA_ENFORCE_PRIVILEGED_FLOOR |
false |
✅ The knob now EXISTS (companion merged — see §0). The shared chart
specs/cluster/charts/hugmesh-gateway (used by all four gateway Applications:
specs/cluster/apps/20-gateway-{pki,be,fe}.yaml and
specs/cluster/apps/22-gateway-superadmin.yaml) carries an mfa: values block, and
its templates/deployment.yaml renders all three into every gateway pod. Verify that
yourself rather than trusting this sentence — the grep now EXITS 0, and a live pod
carries the env:
$ grep -rn 'APP_MFA_ENABLED\|APP_MFA_ENFORCE_PRIVILEGED_FLOOR' \
specs/cluster/charts specs/cluster/apps tests/stack/
$ echo $?
0
$ kubectl exec -n hugmesh-frontend deploy/hugmesh-fe-gateway -c gateway -- env | grep MFA
APP_MFA_ENABLED=false
APP_MFA_ENFORCE_PRIVILEGED_FLOOR=false
APP_MFA_FRESHNESS_WINDOW=600000An earlier revision of this section asserted the opposite and told you to expect exit
1. That was true on the authoring branch and is now wrong; it is corrected rather
than deleted because an operator who hit the contradiction would reasonably have gone
looking for an unmerged companion that is in fact already in.
Since the companion change (§0) landed, the three are chart values —
mfa.enabled / mfa.freshnessWindow / mfa.enforcePrivilegedFloor in
specs/cluster/charts/hugmesh-gateway/values.yaml, rendered into every gateway pod —
with a deliberate asymmetry: the cluster chart default stays false while the
compose dev stack (tests/stack/compose.local.yaml, the gateway-pki /
gateway-be / gateway-fe services) defaults APP_MFA_ENABLED=true, so the
enforcement leg is exercisable end-to-end locally while a cluster ships dark. The
privileged floor is false on both sides.
Never turn gateway MFA on from a
specs/cluster/apps/*.yaml. Turning it on is an explicit, deliberate operator action taken after §2. The privileged floor is not exempt for SUPERADMIN, so enabling enforcement before operators hold a second factor locks you out of the privileged plane — with no in-band way back in.tests/scripts/test-mfa-required-rules.shfails the build if any gateway Application sets it, and it checks that structurally rather than by grep: it parsesspec.source[s].helm.values(a YAML string, block or flow style, comments and all),helm.valuesObject, andhelm.parameters(including indexed names likeextraEnv[0].name), for both spellings — the chart'smfa.enabled/mfa.enforcePrivilegedFloorand a rawAPP_MFA_*container env injected throughextraEnv, the raw escape hatch that bypasses the chart'smfa:block (it was the only mechanism before the companion landed; it is audited because it still works). Ahelm.valueFiles/helm.fileParametersreference, or anAPP_MFA_*env sourced from a Secret, fails the gate as un-auditable rather than quietly reading as a pass. The chart's ownmfa:defaults are asserted too, the moment that block exists.That parse only covers
specs/cluster/apps/*.yaml, so a second, separate sweep covers everything else — every file underspecs/plustests/stack/compose.local.yaml— for a hardcodedAPP_MFA_ENABLED/APP_MFA_ENFORCE_PRIVILEGED_FLOOR. It is shape-aware rather than a grep, because the file that renders env into all four gateway pods is a Helm template and therefore not parseable as YAML: it understands the Kubernetes env-list form (- name:andvalue:on separate lines, in either order), plain mapping keys,[export] KEY=value, and flow mappings. AvalueFromreference, or a literaltrueinside an open Helm{{ if }}block, is reported as undecidable and fails — while a value that simply defers to a chart value ({{ .Values.mfa.enabled | quote }}, i.e. what the companion change will look like) is left to the chart-values check above. The predecessor of this sweep was a two-stage grep that looked for the variable name on a line and then tested that same line for a true value, which the k8s env-list form defeats by construction; it would have passed while the shared chart template turned the privileged floor on for every gateway.
Every operator who holds ROLE_SUPERADMIN, ROLE_ADMIN or
ROLE_GAME-MASTER must have a working second factor enrolled, and must have
verified they can produce a fresh stamp, BEFORE APP_MFA_ENFORCE_PRIVILEGED_FLOOR
is turned on anywhere.
Why this is not negotiable, from GatewayRouteAccessFilter:
- The privileged MFA floor runs above the
ROLE_SUPERADMINcross-domain bypass and theROLE_ADMIN/ROLE_GAME-MASTERown-domain bypass. Those bypassesreturn chain.filter(...)beforedecide()is ever consulted, so the floor has to sit above them or the very roles whose MFA matters would never be gated. SUPERADMIN is explicitly not exempt. - The floor fails CLOSED on cold start: before route-access has been primed from
the datastore the gateway cannot know whether a path is an
mfa_requiredsurface, so every privileged request is held with503+Retry-After: 5. On a gateway restart your admin plane is briefly 503 for privileged callers by design. - A privileged principal on an
mfa_requiredsurface without a fresh factor gets403with anX-Route-Deniedresponse header. - ⚠
enforce-privileged-flooris NOT a sub-flag ofenabled. The filter checks it without consultingapp.mfa.enabled, andisMfaRequiredSurface()has no enabled-guard either. SettingAPP_MFA_ENFORCE_PRIVILEGED_FLOOR=truemakes the floor live on its own, even withapp.mfa.enabled=false. Treat it as the single most dangerous flag in this runbook.
/bff/mfa/** (auth-core MfaEnrollmentController, MfaChallengeController):
| endpoint | purpose |
|---|---|
POST /bff/mfa/enroll/totp |
begin TOTP: returns the secret/QS to add to an authenticator |
POST /bff/mfa/enroll/totp/verify |
finish TOTP — returns the recovery-code set ONCE |
POST /bff/mfa/enroll/webauthn/options → POST /bff/mfa/enroll/webauthn/verify |
register a security key / platform authenticator |
GET /bff/mfa/factors |
list enrolled factors |
DELETE /bff/mfa/factors/{id} |
remove a factor (step-up gated) |
POST /bff/mfa/recovery/regenerate |
new recovery set (step-up gated) |
POST /bff/mfa/challenge |
produce the MFA stamp that satisfies the floor |
Enrollment is reachable while the floor is on: /bff/mfa/** has no
gateway_route_access row (neither in this seed nor in the gateway's baked
CanonicalSeed), and hugmesh-fe-gateway has no /bff/** floor row, so decide()
returns NO_RULE and the gateway forwards on the coarse authenticated() floor.
⚠ If anyone ever adds a /bff/** floor row to the seed, re-check this — a
/bff/** row would become the deciding rule for /bff/mfa/** and could make
enrollment unreachable exactly when it is needed.
Enroll TOTP first, or at least alongside WebAuthn. Do not enroll WebAuthn only.
Recovery codes are issued only on the TOTP path
(MfaEnrollmentService.verifyTotpEnroll → enableTotpAndIssueRecovery →
regenerateRecoveryCodesInternal). verifyWebAuthnEnroll → storeWebAuthnCredential
issues none. And POST /bff/mfa/recovery/regenerate is itself step-up gated —
it requires a fresh stamp, which requires the factor you just lost.
So: WebAuthn-only operator + lost/broken security key = no self-service recovery
path. Once the privileged floor is on, that operator is locked out of
/bff/admin/** and /bff/superadmin/** and the only way back is the out-of-band
break-glass in §6.
Also capture the recovery codes at enroll time. They are shown once (hashes only are stored) and a regenerate invalidates the previous set.
The rules use the operator-chosen blanket scope within the two prefixes and the
per-service console shape (§1.2a): every /bff/admin…, /bff/superadmin…,
/bff/<service>/admin/… and /bff/<service>/superadmin/… allow row, not just the
dangerous verbs. Combined with the freshness window that means:
- Gateway window:
app.mfa.freshness-window, default 600000 ms = 10 min. Amfa_satisfied_atstamp older than that (or in the future) yields noMFA_SATISFIEDmarker. - Native-login (opaque
bff_session) callers: admin-bff appliesapp.casdoor.mfa.freshness(defaultPT10M) before reportingmfaSatisfied, and the gateway'sBffSessionAuthFiltersimply mirrors that boolean into theMFA_SATISFIEDauthority.
Practical effect: all work under those prefixes and consoles — reading a dashboard,
listing announcements,
paging through audit rows — needs a stamp taken within the last 10 minutes, and a
long admin session will be interrupted roughly every 10 minutes. The operator
accepted this when choosing blanket scope. If it proves intolerable, the two
supported adjustments are (a) raise APP_MFA_FRESHNESS_WINDOW and
APP_CASDOOR_MFA_FRESHNESS together — they must agree, or the JWT and
opaque-session legs will disagree about who is fresh — or (b) narrow the WHERE
predicate in 20-schema.sql. Do not hand-edit individual rows: see §5.
§2.3 describes the freshness window without saying how each carrier actually obtains a stamp. The three carriers behave differently, and only one of them is genuinely stuck:
| carrier | how it obtains MFA_SATISFIED |
can it satisfy an mfa_required route? |
|---|---|---|
opaque bff_ session (native web login) |
BffSessionAuthFilter mirrors admin-bff's introspect mfaSatisfied; the session row is stamped synchronously by MfaChallengeService. |
Yes, immediately. |
raw Casdoor JWT for a human (desktop/PKCE hugmesh-desktop, or any password-grant client) |
CasdoorAuthorities -> Roles.isMfaSatisfied(jwt, now, 600000) against the mfa_satisfied_at claim. The claim is a Casdoor user Property, so it enters a token only at MINT time — but these clients can re-mint on demand (refresh_token, device_code, password). |
Yes — complete MFA through the BFF (which writes the Property), then re-mint/refresh within the 10-minute window. |
raw Casdoor JWT from client_credentials (pure machine, no human behind it) |
same path — but mfa_satisfied_at is a user Property and a client-credentials token has no user subject, so there is nothing to stamp. POST /bff/mfa/challenge also fails closed without an opaque session row and an enrolled factor. |
No. Not under any configuration — there is no second factor for a machine. |
⚠ Do not mistake "mint-time only" for "rarely". An earlier draft of this section claimed
no raw-JWT caller could ever be fresh, reasoning that the claim lands only at mint and the
seeded expireInHours is 168 (4 for user-bff) against a 10-minute window. That reasoning
was wrong: expireInHours bounds how long a stale token stays valid, not how soon a
client may request a new one. hugmesh-desktop is seeded as a public PKCE client with
refresh_token, and its own seed comment states the intent — "refresh_token so the device
can refresh after the BFF stamps the MFA Property". That flow works.
What IS broken. The seam that was supposed to make the stamp appear without the client
doing anything never runs: MfaChallengeService calls
RawJwtRefreshService.forceRefresh(subject, null) with a literal null refresh-token at
the only call site, so it always takes its no-op fallback branch. (app.bff.oidc.enabled is
true on the live pods, so the bean's presence is not the blocker — the argument is.) The
practical consequence is a usability trap, not a lockout: after completing MFA a raw-JWT
holder must actively re-mint inside the 10-minute window; nothing does it for them, and
a client that simply keeps using its existing token will keep being denied until it happens
to refresh. Note also a second re-mint path that bypasses RawJwtRefreshService entirely —
admin-bff InternalAccountController.exchangeSessionRow() calls oidcExchange.refresh(...)
directly when custody is near expiry.
RawJwtRefreshService's javadoc justified the no-op by claiming "GEN2 lowers the privileged-appexpireInHoursprecisely so this natural-lifetime gap stays SHORTER than the MFA freshness window". There is no such GEN2 change (git grep GEN2finds an unrelated CI comment and a disk-partitioning note), and no seeded expiry is anywhere near 10 minutes. Corrected in hugmesh-auth-core #43 — do not restore that reasoning.
What this means at the §3 step-6 / step-7 flip. Human operators are fine on both
carriers. The population to enumerate first is machine client_credentials traffic on
/bff/admin… and /bff/superadmin…: it has no supported path to a second factor, so once
APP_MFA_ENABLED=true it is denied there permanently, and the step-7 privileged floor denies
it outright (ROLE_SUPERADMIN is not exempt). If any exists, the options are to leave the
floor off, narrow the rows (§2.3 (b)), or move that caller to a service account driving an
opaque session. Raising APP_MFA_FRESHNESS_WINDOW does not help it at all — the claim is
absent, not stale.
That enumeration has been done once — 2026-08-06. The STATIC half came back CLEAN and stands; the empirical half was withdrawn (see below). Recorded here so the operator inherits the answer rather than the chore, with the commands to re-run it, because it is a point-in-time result and a new service could invalidate it.
Static, across all 38 repos. Seven code sites use the client_credentials grant
(admin-bff FederationOverrideClearClient / FederationResolvedFindingsClient /
UserBffCharacterModerationClient, mesh-bff UserBffMeshDeviceClient, actions
FederationUsernameClientConfig, user-bff ServiceTokenBroker, remote-fragment
CasdoorTokenClient). None targets /bff/admin… or /bff/superadmin…, and every one
dials its peer directly over cluster DNS (…svc.cluster.local:8080, or the Matrix /
Mastodon homeserver) rather than through a gateway — so gateway route-access, and therefore
the MFA floor, never applies to that hop at all.
Exactly one server-side caller anywhere touches a gated prefix: mod-bff's
AdminDomainLockClient (POST/DELETE /bff/admin/domain-lock/{platform}/{user}). It is
not machine traffic — AdminApiConfig builds it with
BearerForwardingFilter.forwardCallerToken(...), so it carries the human moderator's
token, and it also dials admin-bff directly. Both reasons independently put it outside the
floor. The only other two hits (auth-core GatewayRevocationClient, forum-bff
PhpbbAdminClient) are javadoc prose, not calls.
Empirical: WITHDRAWN as evidence (corrected 2026-10-14). An earlier revision of this
section recorded that, on the live kind cluster, Casdoor "has issued 80 tokens, 100 % of
them user-bound, zero machine tokens" (app-built-in 48, app-user-bff 32). That count
came from a query that classified a token as a machine token when its user column was
empty. A client_credentials token never has an empty user: at the cluster's pinned tag
(casbin/casdoor:3.80.0, specs/cluster/manifests/casdoor/deployment.yaml)
object/token_oauth.go GetClientCredentialsToken builds a placeholder user named after
the application (nullUser := &User{..., Name: application.Name, Type: "application"})
and stores User: nullUser.Name together with GrantType: "client_credentials". So the
query could not match a machine token and its "zero" was guaranteed, whatever was in the
table. app-user-bff is seeded with both password and client_credentials
(init-job.yaml reconcile_app), so some of those 32 may have been machine tokens. Do not
quote the 80 / 0 figure. The static half above is unaffected and stands on its own.
The empirical half is now the block below (executed by the gate against a fixture that
mirrors the 3.80.0 table shape, including both ways a machine token can look: the
grant_type column, and the user = application placeholder that rows from before the
column existed still carry):
SELECT application,
CASE WHEN grant_type = 'client_credentials' OR "user" = application
THEN 'machine' ELSE 'user-bound' END AS kind,
count(*) AS tokens,
max(created_time) AS newest
FROM token
GROUP BY 1, 2
ORDER BY 2, 1;$ scripts/mfa-runbook-sql.sh casdoor-machine-census | \
kubectl -n hugmesh-pki exec -i deploy/casdoor-pg -- \
sh -c 'PGPASSWORD="$POSTGRES_PASSWORD" psql -X -U "$POSTGRES_USER" -d casdoor'Reading it: machine rows are expected. client_credentials is seeded on every
confidential app and seven code sites use it (above), so a live cluster will show machine
rows for the Casdoor applications behind those sites (app-user-bff, app-admin-bff,
app-fragment-sync, plus whichever applications mesh-bff and actions are configured with;
read those from their config, they are not assumed here). The stop is a machine row for an
application that is not one of them: that is a caller the static census did not know
about. The table records the application, not the URL, so this block can never say
that a machine token reached /bff/admin… or /bff/superadmin…; that question is
answered by the static half and, after step 6, by X-Route-Denied in the gateway logs.
So step 6 is clear on this precondition only to the extent the static half is. The empirical half has not been run against a live cluster since this correction; re-run both if a new service is added, if an existing one starts calling those prefixes, or if any caller is moved behind a gateway instead of cluster-DNS.
One knob that moves a bff_ carrier onto the JWT path.
hugmesh.gateway.bff-exchange.enabled (default false, set in no manifest) makes
BffJwtExchangeWebFilter rewrite Authorization: bff_… into the custody Casdoor JWT
before Spring Security. With it on, an opaque carrier reaches the gateway as a Jwt
principal and takes the mint-time path in row 2 instead of the synchronous row 1. Turn it on
only together with a re-read of this section.
tests/scripts/test-mfa-raw-jwt-posture.sh pins this taxonomy to the seed: it derives each
seeded app's grant types, classifies which can re-mint, and fails if a caller that cannot
re-mint appears without this section naming that population — or if the debunked
bounded-gap reasoning is reintroduced anywhere.
Do these in order. Do not batch them. All seven steps are actionable on main
today — steps 6–7 were gated on the companion change from §0, which has merged.
-
Verify the factor key exists (§4). Without it TOTP enroll refuses, so nobody can enroll and step 3 would be a lockout.
-
Fix WebAuthn RP-ID / origins for your real domain (§4) — otherwise
navigator.credentials.create()fails in the browser and only TOTP works. -
Enroll every privileged operator (§2). TOTP at minimum. Record recovery codes. Have each operator prove they can complete
POST /bff/mfa/challengeand then reach an admin page. Do this while enforcement is still off — the enrollment API is already armed becauseAPP_CASDOOR_MFA_ENABLED=true. -
Seed the rules. They ship in
20-schema.sql. On a fresh cluster the route-access-db initdb applies them; on an existing cluster re-apply that file againstroute-access-db. TheUPDATEis idempotent (mfa_required IS DISTINCT FROM true) and converges for both cases — anINSERTwould not, becauseON CONFLICT DO NOTHINGskips rows that already exist and would leavemfa_required=false. Re-applying the file on an existing cluster also repairs the column shape:mfa_requiredwas first added by anALTER … ADD COLUMNthat was nullable while theCREATE TABLEdeclares itNOT NULL, so an upgraded cluster could holdmfa_required = NULL— a third state the gateway's boolean read path is not written for. The file now backfills the NULLs and re-assertsDEFAULT false/NOT NULL; all of that is a no-op on a cluster that is already correct. Verify with:SELECT gateway, url_pattern, role, mfa_required FROM gateway_route_access WHERE allow = true AND (url_pattern LIKE '/bff/admin%' OR url_pattern LIKE '/bff/superadmin%' OR url_pattern LIKE '/bff/%/admin/%' OR url_pattern LIKE '/bff/%/superadmin/%') ORDER BY 1, 2, 3;
Expect the 16 rows in §1.2 at
true— and read what this query does not show you before you act on it. Theallow = trueclause is not cosmetic: it is the same predicate the flipUPDATEuses, so this query and thatUPDATEagree on scope by construction rather than by coincidence. Since 2026-09-17 that scoping also hides one row. The seed now carries anallow = falserow under the superadmin prefix —hugmesh-fe-gateway/bff/superadmin/games-services/**, reinstated by operator decision 28 = D (hugmesh-generator#347) — and that row carries the floor too. Seventeen rows end up atmfa_required = true; this query returns sixteen of them. A deny row denies at the longest match regardless of MFA, which is why the flip leaves it alone, and why an operator reading an un-filtered result would see afalseunder a "fully flipped" prefix and think the rollout had failed. Do not now make the opposite mistake: the seventeenth row is not missing from the rollout, and the step-up floor is not off for the games app-store subtree. To audit the floor rather than the flip, use:SELECT gateway, url_pattern, role, allow, mfa_required FROM gateway_route_access WHERE mfa_required = true ORDER BY allow, 1, 2, 3;
Expect 17 rows: the 16 above at
allow = true, plus the oneallow = falserow in the table below. That row keeps the floor over its whole subtree rather than removing it, because the gateway computes the privileged step-up floor withGatewayRouteAccessService.isMfaRequiredSurface()— longest matchingurl_pattern, thenif (r.mfaRequired()) return true;, with noallowtest and no role test — and not withdecide(), whose MFA leg is raised only on the arms that GRANT the principal. The blanket flip (WHERE allow = true) can never reach a deny row, so this one is seeded by its own row-scopedUPDATEin20-schema.sql, placed immediately before the flip.gateway url_pattern role why it carries the floor while denying hugmesh-fe-gateway/bff/superadmin/games-services/**ROLE_SUPERADMIN#347 decision 28 = D — the games app-store control plane is walled at the public browser door and stays inside the privileged step-up floor. Any other
allow = falserow atmfa_required = trueis a defect, and the reverse is a lie:tests/scripts/test-mfa-required-rules.shfails on a deny row attruethat is not in this table (DENY_TRUE_UNDECLARED), on a table row the seed does not carry (DOC_DENY_MISSING/DENY_DECLARED_MISSING), and on this table disappearing.Settled, 2026-09-17 — operator decision 28 = D (hugmesh-generator#347), landed by hugmesh-generator#484. History, because this note has now said both things.
integrate/superadminadded theallow = trueclause and the deny row that motivated it (hugmesh-fe-gateway/bff/superadmin/games-services/**). On the 2026-09-16 merge the clause landed and the row did not: operator decision 8 (#244 ACCEPT) is SPECIFIC to that row and was answered "without the games-services deny row", while decision 20 ("land the whole branch") is the LATER, GENERAL one — recency argued for the row, specificity against it, the specific answer was applied and the choice was parked for the operator as decision 28. Decision 28 answers it: the row goes back in, withmfa_requiredseeded true on the row itself. That 2026-09-16 note also said the row "strips the floor". That was read off the wrong function —decide(), whose MFA leg is grant-scoped, rather thanisMfaRequiredSurface(), which the privileged floor actually calls — and it is why leaving the row out looked forced. See the paragraph above the table. Theintegrate/superadminbranch also wrote "every row" in place of "the 10 rows" here, predating the count becoming 10 under the same ACCEPT.To see the scope boundary instead — the 16 gated rows and the three §1.2a rows that are
falseby design — use this, which is the same admin-ish enumeration the gate itself performs (path segmentadmin/superadminor an*_ADMIN/SUPERADMINrole, which is how the three role-privileged exclusions get in at all):SELECT gateway, url_pattern, role, mfa_required FROM gateway_route_access WHERE allow = true AND url_pattern LIKE '/bff/%' AND (url_pattern LIKE '%admin%' OR role LIKE '%ADMIN%') ORDER BY mfa_required, 1, 2, 3;
Expect 19 rows: the 16 at
true, then the 3 §1.2a exclusions atfalse. ⚠ Do not useLIKE '/bff/%admin%'for this — an earlier revision of this runbook said that form "also returns the six §1.2a rows". It does not: it returns none of the three that remain (and returned only four of the then seven), because/bff/mod/**,/bff/image-builds/arch/**and/bff/games-services/instances/**have noadminsubstring inurl_patternat all and are excluded by role. An operator reading that output would conclude those three privileged surfaces were inside the gate. Both blocks above are now executed bytests/scripts/test-mfa-required-rules.shagainst the replayed seed and compared against the real row sets, so neither can drift back into prose that is merely plausible. Still no behaviour change at this point. -
Exercise it in the compose dev stack first. Compose mounts the same seed file (
tests/stack/compose.local.yamlmountsspecs/cluster/manifests/route-access/initdb/20-schema.sqlinto/docker-entrypoint-initdb.d/), so amake stack-upon a freshroute-access-pgvolume seeds the rows locally. ⚠ The enforcement leg is only exercisable once the companion change (§0) has landed — that is what setsAPP_MFA_ENABLED=trueon the compose gateways. Before then compose seeds the rows and ignores them, exactly like a cluster. After it lands you get the real enforcement leg for the non-privileged case (see §3.1) — and you can rehearse step 7's privileged floor itself, per run and lockout-free, withmake stack-up MFA_FLOOR=1(a Makefile variable; it threadsAPP_MFA_ENFORCE_PRIVILEGED_FLOOR=trueinto the compose gateways for that run only, and expands to nothing otherwise, so the committed compose default staysfalseand a plainmake stack-upis byte-identical).tests/e2e/specs/29-mfa-privileged-floor.spec.tsis the end-to-end proof for both modes. Run it twice:stack run as what it proves make stack-upnpx playwright test 29-mfa-privileged-floora pure ROLE_FLEET_ADMINis 403'd on/bff/admin/phone-fleet/**without a stamp, and — §3.1's small print — the same admin on the same blanket is not gatedmake stack-up MFA_FLOOR=1MFA_FLOOR=1 npx playwright test 29-mfa-privileged-floorthe floor: admin 403 without a fresh factor, a real TOTP enroll + step-up challenge driven through the shipped login-ui pages, the same route then passing, and a non- mfa_requiredsurface untouchedThe floor legs are the ONLY thing
MFA_FLOOR=1un-gates in that spec; every other precondition FAILS loudly rather than skipping. Two of those are worth knowing before you blame the code:- the seed rows land through initdb, which runs only on a fresh
route-access-pgvolume —make stack-cleanbeforemake stack-up, or an older volume will enforce nothing; - the enroll leg needs the admin-bff MFA surface live
(
APP_CASDOOR_MFA_ENABLED=trueandAPP_MFA_FACTOR_KEY, both already defaulted incompose.local.yaml), and thee2e-fleetpersona fromtests/stack/seed-e2e.sh— a deliberateROLE_FLEET_ADMIN+ROLE_USERaccount with noROLE_ADMIN, since an admin would bypassdecide()and the fleet leg would prove nothing.
Note compose has no superadmin gateway — only pki/be/fe.
- the seed rows land through initdb, which runs only on a fresh
-
Turn on
APP_MFA_ENABLEDfor the cluster gateways — the companion (§0) has landed, so this step is actionable today. Hand-adding anextraEnv: APP_MFA_ENABLEDto a gateway Application still fails the posture gate on purpose. Set the shared chart'smfa.enabledvalue: all four gateway Applications point at the one chart, so a chart-level default reaches all four; keep it out of the per-app manifests (the gate enforces that). Watch for 403s from non-privileged holders ofROLE_FLEET_ADMIN, and list them before the flip: they are the one population this step alone changes (§3.1), and §9'sC5privileged-operator census does not include them. §9C5b(runbook blockfleet-census) lists every pure fleet owner with their TOTP state and whether their phone-fleet entitlement is active. ⚠ This is the step that permanently denies machineclient_credentialstraffic. A client-credentials token has no user subject, andmfa_satisfied_atis a Casdoor user Property — so there is nothing to stamp and no second factor to enrol. Enumerate any such caller on/bff/admin…//bff/superadmin…before this flip. Human callers are fine on both carriers, but a raw-JWT human must re-mint after completing MFA (nothing does it for them). Read §2.4 before flipping.⚠ The flip commit changes THREE gate suites, not one. An earlier revision of this step named only
tests/stack/test-gateway-mfa-env.sh. Measured 2026-10-14 onmain(c0c46601) by settingmfa.enabled: truein the shared chart'svalues.yamland nothing else, then running every MFA suite (tests/scripts/test-mfa-required-rules.sh,tests/scripts/test-mfa-raw-jwt-posture.sh,tests/stack/test-gateway-mfa-env.sh,tests/stack/test-mfa-flip-wiring.sh): (A wider sweep of all 21tests/**/test-*.shfiles that mentionmfa, base versus step 6, found no other suite changing result. Two of the 21,test-cluster-manifest-integrity.shandtest-tor-flip-wiring.sh, hit that sweep's 300 s timeout and were re-measured separately with a 900 s one, on the merged tree, under each flip on its own (mfa.enabled: true, thenmfa.enforcePrivilegedFloor: true): both stayed green (manifest integrity PASS with 59/59 negative controls; tor flip wiring 74/0). The step 7 sweep otherwise covered only the four suites below, so "no other suite goes red at step 7" is established for those two and for the four, not for the other 15.)suite result what goes red what the flip commit has to do tests/stack/test-gateway-mfa-env.sh8 FAIL (2) chart value is not boolean false; (4) ×5 — each of the four rendered releases and the bare chart defaults emitAPP_MFA_ENABLED=trueagainst the pin; (6)ASYMMETRY LOST: compose='true' cluster='true'; (8a)MUTATOR DID NOT LANDset EXPECT_APP_MFA_ENABLED="true"(theEXPECT_*table near the top); then decide what (6) means once both sides aretrue(the script refuses to run whenEXPECT_APP_MFA_ENABLEDandCEXPECT_APP_MFA_ENABLEDagree — replace the asymmetry self-check with an explicit "cluster and compose are both ON" pin, do not delete it); and invert (8a)'s mutator, which today rewritesenabled: falsetotrueand therefore finds nothing to mutatetests/scripts/test-mfa-required-rules.sh1 FAIL the posture block: "the shared chart's mfa: block defaults BOTH enabled and enforcePrivilegedFloor off" this check has no EXPECT_*table — the OFF state is hard-coded in thecase "$(q CHART_MFA_BLOCK)"arm (CHART_MFA_ENABLEDmust benot-true). Change theenabledhalf totrue, keep the floor halfnot-true, and reword the messagetests/stack/test-mfa-flip-wiring.sh1 FAIL (5a) chart values mfa.enabled changed— the chart default is hard-codedfalsethere toochange the (5a) pin to trueand its messagetests/scripts/test-mfa-raw-jwt-posture.shgreen — nothing; it pins the §2.4 taxonomy, not the posture All three red suites are the posture pins the operator chose on purpose; red is the signal to move them deliberately in the same reviewed commit, not to delete a gate. Do not put the flip in a branch that only touches
values.yaml: CI will be red for three independent reasons and the reviewer has no list..github/workflows/shell-suites.ymland.gitlab-ci.ymlwire these suites by path, so none of those files needs an edit for the flip itself. -
Only then consider
APP_MFA_ENFORCE_PRIVILEGED_FLOOR— same chart value (mfa.enforcePrivilegedFloor), also available today. This is the step that actually gates admins and superadmins. Expect 503s during each gateway's cold-start priming window, and keep a second authenticated superadmin session open on another browser as a canary. Blast radius includes tube admins since 2026-10-15: everyADMIN/SUPERADMINwho grants, times out, bans or revokes Tube access or sets a Tube storage budget now needs a fresh second factor too (the two/bff/tube/admin/…rows in §1.2). They get 403 +X-Step-Up-Requiredand an inline challenge in hugmesh-tube-ui; a tube admin who has not enrolled is locked out of those two consoles, the same way as every other privileged surface.⚠ Pin rule, measured the same way (2026-10-14:
mfa.enforcePrivilegedFloor: truealone). Two suites go red;test-mfa-flip-wiring.shandtest-mfa-raw-jwt-posture.shstay green:suite result what goes red what the flip commit has to do tests/stack/test-gateway-mfa-env.sh6 FAIL (2) mfa.enforcePrivilegedFloor wrong; (4) ×5 — four releases + chart defaults emitAPP_MFA_ENFORCE_PRIVILEGED_FLOOR=trueEXPECT_APP_MFA_ENFORCE_PRIVILEGED_FLOOR="true"(cluster only —CEXPECT_APP_MFA_ENFORCE_PRIVILEGED_FLOORstays"false": the dev stack floor stays off in the committed file andmake stack-up MFA_FLOOR=1is the per-run override that does not touch the pin)tests/scripts/test-mfa-required-rules.sh1 FAIL the same posture-block check as step 6, floor half change the floor half of that arm to true; the no-app-manifest-turns-the-floor-on check stays as isRehearse it first on compose with
make stack-up MFA_FLOOR=1+tests/e2e/specs/29-mfa-privileged-floor.spec.ts— the only place the floor's behaviour is exercised end to end.⚠ "Do the floor on one gateway first" cannot be done through the chart, and an earlier revision of this step told you to. Verified from the manifests:
- all four gateway Applications render the one chart, so a chart value reaches all four at once;
- a per-Application override in
specs/cluster/apps/*.yamlis exactly what the posture gate fails the build on (§1.3), in every spelling; - each gateway Application (
syncPolicy.automated: {prune: true, selfHeal: true}) reverts a hand-patch of the Deployment env, sokubectl set envlasts until the next reconcile. A repo-recursing root Applicationhugmesh-root(specs/cluster/app-of-apps.yaml,automated: {prune: true, selfHeal: true}) would also revert a patch of the gateway Application, but that root is opt-in and absent from a default cluster:bootstrap.shapplies the baked Application set directly, createshugmesh-rootonly underHUGMESH_GITOPS_ROOT_RECURSE=1, and deletes a pre-existing one (specs/cluster/bootstrap/bootstrap.sh, "Retire a recursing root"). §9 phase B reads which case you are in; §9's bypass and rollback commands branch on it. (hugmesh-root-waved,00-app-of-apps-waved.yaml, is non-automated and pruned from the baked tree; it never reverts anything.) The honest options are: (a) flip all four from one reviewed commit and rely on the canary session plus §6's rollback (the default, and what §9 phase E gives commands for); (b) a deliberate, temporary GitOps bypass for a single gateway (§9 phase E-bypass — it works only while auto-sync is suspended and leaves drift that must be reverted); or (c) a gate change that lets a named gateway Application carry its own pin — a new scope decision for the operator, not something the runbook can assume exists. Note which paths each gateway owns before choosing:hugmesh-fe-gatewaycarries/bff/admin/**,phone-fleetand/bff/superadmin/**;hugmesh-be-gatewaycarries/bff/admin/workloads/**and/bff/superadmin/**;hugmesh-superadmin-gatewaycarries/bff/superadmin/**(§1.2). A floor onfealone leaves thebeandsuperadmindoors un-floored.
With enabled=true but enforce-privileged-floor=false — the recommended
intermediate state — ROLE_SUPERADMIN, ROLE_ADMIN and ROLE_GAME-MASTER
short-circuit in GatewayRouteAccessFilter before decide() runs. So of the 16
flipped rows, the only one that changes behaviour is
/bff/admin/phone-fleet/** → ROLE_FLEET_ADMIN: a pure fleet owner is not
privileged, so it reaches decide(), and without a fresh MFA_SATISFIED marker it
gets a 403.
That is the whole point of the two-flag design, but it means: do not read a quiet cluster after step 6 as evidence that admin MFA works. It does not gate admins until step 7.
A 256-bit AES-GCM data key. MfaSecretCipher uses it to encrypt every enrolled TOTP
secret at rest, and it keys the recovery-code HMAC.
- Cluster:
specs/cluster/manifests/admin-bff-api/deployment.yamlreads it from ESO Secretadmin-bff-mfa, keyfactor-key— the ref is REQUIRED (nooptional:). The ExternalSecret is inspecs/cluster/manifests/external-secrets/secretstore.yaml; the value is minted byscripts/gen-cluster-secrets.sh(openssl rand -base64 32) into Vault atsecret/<brand>/admin-bff-mfa.factor_key. - Compose:
tests/stack/compose.local.yamlAPP_MFA_FACTOR_KEYhas a dev default. It is a committed dev value — never reuse it outside compose. - An absent Secret now blocks pod start at the Kubernetes layer
(
CreateContainerConfigErrornamingadmin-bff-mfa), instead of booting a pod whose cipher is INERT and whose TOTP enroll / recovery generation silently refuse (no plaintext fallback). That silent-enrollment-failure mode was why the ref used to beoptional: true; withapp.casdoor.mfa.enabledarmed in-cluster the key is load-bearing, so a missing key is now a loud scheduling failure with a clear reason — still step 1, but you find out fromkubectl get pods, not from a user's failed enrollment.test-cluster-manifest-integrity.shpins both the required posture and that the ref'sname/keymatch what the ExternalSecret actually materializes. - Rotating this key orphans every enrolled TOTP secret and every recovery-code hash. Treat it as unrotatable without a re-enrollment campaign.
WebAuthn binds a credential to an RP-ID (a registrable domain) and an exact origin. The auth-core defaults are localhost-shaped and wrong for any real deploy.
specs/cluster/manifests/admin-bff-api/deployment.yaml sets them explicitly:
- name: APP_MFA_WEBAUTHN_RP_ID
value: "admin.hugmesh.net"
- name: APP_MFA_WEBAUTHN_ORIGINS
value: "https://admin.hugmesh.net"For your own domain these must be rewritten (the rebrand_sysroot path rewrites
admin.hugmesh.net → admin.<domain> per tenant — confirm it did). Rules:
- RP-ID must be the registrable suffix of every origin the admin UI is served from. A credential registered under one RP-ID cannot be asserted under another — changing RP-ID later invalidates every enrolled key.
- Origins must be the exact
https://host[:port]strings the browser sends, including every alias operators actually use. HTTPS is mandatory (excepthttp://localhost). - If operators reach the console over the tailnet on a different hostname than
admin.<domain>, that origin must be listed too, or WebAuthn silently fails there and only TOTP works.
role_mfa_policyenforces nothing. admin-bff carries a per-(domain, role)role_mfa_policytable with an admin write path (RoleMfaPolicyService,RoleMfaPolicyController; changelog150-mfa-substrate.xml). Its own javadoc is explicit that "nothing in the request pipeline consults it yet" —/bff/login,/bff/session, the introspect leg and the step-up gates behave as before, and the gateway's route-level enforcement stays behindapp.mfa.enabled. Editing a row there will not gate anyone and is not part of this rollout. (The service pinssuperadminandadmintorequired=trueregardless of any row, mirroring §2.) Cross-repo, so not gate-pinned.MfaPreconditionBootGuard(auth-core) only WARNs by default. It reports a missing factor key and a loopback WebAuthn RP-ID/origin allowlist (§4.1, §4.2) with a*** MFA MISCONFIGURED ***banner in the admin-bff log, and aborts the boot only ifAPP_MFA_PRECONDITIONS_FAIL_FAST=trueis set — which no manifest here sets. Absence of the banner is a useful signal (§9 phase C2 greps for it) but not a gate; whether the deployed admin-bff image carries the guard depends on its pinned version, which this repo cannot see.
The admin-bff is the CRUD writer for gateway_route_access, so you can flip an
individual row's mfa_required through the admin API. Don't use that to carve out
exemptions:
- The seed converges. Re-applying
20-schema.sqlre-flips anything under/bff/admin/…or/bff/superadmin/…back totrue— exactly as theINSERTabove it re-creates deleted seed rows. Your exemption disappears at the next in-place apply. - Exempt a surface by changing the
WHEREpredicate in20-schema.sql, so the exemption is reviewable, testable and survives a re-apply. Narrow the predicate — do not append a secondUPDATE … SET mfa_required = false. An appended un-flip leaves the file's net effect un-gated while every statement in it still looks right;tests/scripts/test-mfa-required-rules.shreplays the whole file on a real SQL engine and will fail on exactly that. It also fails if any statement other than that oneUPDATEwrites the column — the single exception being the in-place-upgradeWHERE mfa_required IS NULLrepair near the top of the file, which is matched as a whole statement, so a second predicate cannot be smuggled into it, and which must stay ahead of the flip. And it recognises the write in every spelling Postgres accepts — bare,public.-qualified,"double-quoted", or led by a CTE — plus it now refuses to run at all if the file contains a statement of a kind it cannot classify. That last part matters: while the matcher demanded a bare table name, an appendedDELETE FROM public.gateway_route_access WHERE url_pattern LIKE '/bff/superadmin%'wiped every superadmin row and this gate still reported a clean pass. And update §1.2 / §1.2a in the same commit: the gate cross-checks the documented exclusion list against the real rows in both directions, so prose and predicate cannot drift apart. - Adding a parallel row that differs only in
mfa_requireddoes nothing:mfa_requiredis not part ofuq_route_access_row(gateway, url_pattern, role, COALESCE(casdoor_user,''), COALESCE(NULLIF(lower(trim(domain)),'default'),'')), so the row collides andON CONFLICT DO NOTHINGsilently drops it. This is the single easiest way to think you have enabled MFA on a surface while enabling nothing. Note the domain leg is the gateway's scope equivalence, not the raw text — a'Default'or case/whitespace re-spelling of an existing row's domain collides too. A row that differs indomainfor real is the one legal sibling shape: per-domain tightening, §1.2a.
If both Postgres and the Cassandra mirror are unreachable, the gateway falls back to
its baked-in CanonicalSeed, whose every row is hard-coded mfaRequired=false
— a deliberate choice in hugmesh-gateway so a datastore outage cannot lock the
privileged plane out on the bare floor. Role gating still applies (and the seed is
closed-by-default for an unknown gateway name), but the second-factor requirement
silently disappears for the duration of the outage. Accept it or change it in
hugmesh-gateway; it cannot be fixed from this repo.
The two tube ADMIN rows of §1.2 are not in that baked floor at all: CanonicalSeed
carries no tube row (a grep for tube over it on hugmesh-gateway main finds nothing,
the /bff/tube/** floor included), so during the same outage /bff/tube/** is
ungoverned at the gateway (NO_RULE, forwarded on the coarse authenticated floor), and
tube-bff's own role gates are the only wall. Closing that is a hugmesh-gateway change.
Roll back in the reverse of §3, and note that only the flags are hot — the rules are data.
-
Immediate relief for a privileged lockout: set
APP_MFA_ENFORCE_PRIVILEGED_FLOOR=falseon the affected gateway(s) and restart. The privileged bypasses come back and admins/superadmins reach the admin plane again without a factor. This is the first thing to try; it needs no DB access. ⚠ On a cluster that auto-syncs, "set it" means one of two things, and only the first is durable. (i) Revert the flip commit (setmfa.enforcePrivilegedFloorback tofalsein the shared chart) and let ArgoCD sync — every gateway Application runsautomated: {prune: true, selfHeal: true}(and so does the opt-inhugmesh-root, where the cluster has one: §3 step 7), so akubectl set envorkubectl patchis reverted by the next reconcile. (ii) For minutes-matter relief, suspend auto-sync first, then change the env — exact commands are §9 phase G, and they leave drift you must reconcile afterwards. -
Full disable: set
APP_MFA_ENABLED=falseas well.decide()then ignoresmfa_requiredentirely andMFA_SATISFIEDis no longer even derived, so every flipped row is inert again. The authority set returns to the legacy shape. -
Only if you want the data gone too:
UPDATE gateway_route_access SET mfa_required = false WHERE url_pattern LIKE '/bff/admin/%' OR url_pattern LIKE '/bff/superadmin/%' OR url_pattern LIKE '/bff/%/admin/%' OR url_pattern LIKE '/bff/%/superadmin/%' OR url_pattern IN ('/bff/admin', '/bff/superadmin');
(The gate runs this one too, against the replayed seed, and asserts that no row is left
mfa_required=trueafterwards — so a rollback that silently stopped covering one of the prefixes or the per-service console shape fails the build.) The gateways pick this up on their next route-access refresh (app.route-access.refresh-interval-ms, default 5 s) — no restart needed. Note this is undone the next time20-schema.sqlis applied; to make it permanent, revert theUPDATEblock in that file. -
If both flags are off and privileged callers still 503: that is the cold-start hold, and it only runs under
enforce-privileged-floor. If you are seeing it with the flag off, the flag did not actually reach the pod — check the rendered env, not the chart values. -
Break-glass for a locked-out operator with no factor: there is no in-band path (the recovery-regenerate endpoint is itself step-up gated). Use cluster access —
kubectl execto the admin-bff's Postgres (deploy/admin-bff-db, namespacehugmesh-backend, database/useradminbff) and delete that subject's rows from the MFA factor tablesmfa_factor,mfa_recovery_codeandwebauthn_credential(created by changelogs151-mfa-factors.xml;owner_subjectis the key — see §9 phase C for which value that is per carrier), or roll back per step 1 — then re-enroll. The exact commands are §9 phase G. If you have no cluster access either, you are relying on someone who does; make sure that person exists and is not the same single operator before step 7.
| path | present on main? |
what |
|---|---|---|
specs/cluster/manifests/route-access/initdb/20-schema.sql |
yes | the gateway_route_access table + canonical seed + the mfa_required UPDATE |
tests/scripts/test-mfa-required-rules.sh |
yes | the gate over the rules (net-effect replay) + the enablement posture (structured ArgoCD parse and the shape-aware APP_MFA_* sweep over all of specs/ + the compose stack) + the four SQL blocks in this runbook, which it executes against the replayed seed |
tests/scripts/test-cluster-manifest-integrity.sh |
yes | verifies every seeded gateway id is a deployed gateway |
specs/cluster/apps/20-gateway-{pki,be,fe}.yaml, specs/cluster/apps/22-gateway-superadmin.yaml |
yes | the four gateway Applications; instance.name here is the gateway column value each pod loads |
specs/cluster/manifests/admin-bff-api/deployment.yaml |
yes | APP_CASDOOR_MFA_ENABLED, APP_MFA_FACTOR_KEY, APP_MFA_WEBAUTHN_RP_ID, APP_MFA_WEBAUTHN_ORIGINS |
specs/cluster/manifests/external-secrets/secretstore.yaml |
yes | the admin-bff-mfa ExternalSecret |
scripts/gen-cluster-secrets.sh |
yes | mints the factor key into Vault |
tests/stack/compose.local.yaml |
yes | dev stack: gateway SPRING_APPLICATION_NAMEs, APP_CASDOOR_MFA_ENABLED, APP_MFA_FACTOR_KEY, the initdb mount of the seed, AND the gateway APP_MFA_* trio (APP_MFA_ENABLED=true — the deliberate dev-vs-cluster asymmetry) |
specs/cluster/charts/hugmesh-gateway/values.yaml |
yes | shared gateway chart; carries the mfa: block (enabled: false) reaching all four gateways, rendered by templates/deployment.yaml |
tests/stack/test-gateway-mfa-env.sh |
yes | pins BOTH postures (cluster false / compose true) and refuses to run if that asymmetry disappears |
specs/cluster/charts/hugmesh-gateway/templates/deployment.yaml |
yes | renders APP_MFA_ENABLED / APP_MFA_FRESHNESS_WINDOW / APP_MFA_ENFORCE_PRIVILEGED_FLOOR (from .Values.mfa.*) into every gateway pod; the sweep in §1.3 watches this file specifically — it is the one place a single edit reaches all four gateways |
tests/stack/gateway_mfa_env.py |
yes | the helper behind test-gateway-mfa-env.sh; its posture parser overlaps test-mfa-required-rules.sh's and the two have not been collapsed into one shared helper |
tests/stack/test-mfa-flip-wiring.sh |
yes | pins the MFA=1 switch per lane (§8) and the chart default mfa.enabled: false (its check (5a)) — one of the three posture suites a cluster flip must move (§3 step 6) |
scripts/kind-mfa-posture.sh |
yes | reads APP_MFA_ENABLED back off the kind fe-gateway pod (§8.1); §9 phase B generalises the same read to all four gateways and all three variables |
Cross-repo (not changeable from here):
hugmesh-gateway filter/GatewayRouteAccessFilter.java,
cache/GatewayRouteAccessService.java, cache/CanonicalSeed.java,
config/CasdoorAuthorities.java, filter/BffSessionAuthFilter.java;
hugmesh-auth-core mfa/MfaEnrollmentService.java, mfa/RecoveryCodeService.java,
casdoor/MfaChallengeController.java.
Everything above describes WHAT to flip; this section is the ONE switch that
performs the flip, per lane, following the PHPBB=1/AKKOMA=1 knob precedent.
It flips only app.mfa.enabled: the freshness window keeps its default
(600000) everywhere, and the privileged floor is not reachable from this
switch on any lane — MFA_FLOOR=1 (§3 step 5) stays its own deliberate,
compose-only rehearsal knob, and a cluster floor flip stays the hand-executed §3
step 7. Every precondition in §2 (enroll before you enforce, the machine-caller
census in §2.4) binds on every lane below. Nothing here changes a committed
default: the chart stays false, no specs/cluster/apps/*.yaml flips it, and
the posture gates (tests/stack/test-gateway-mfa-env.sh,
tests/scripts/test-mfa-required-rules.sh) keep enforcing that.
| lane | invocation | mechanism | scope |
|---|---|---|---|
| compose dev stack | make stack-up MFA=1 |
threads an EXPLICIT APP_MFA_ENABLED='true' into every compose invocation (STACK_MFA_ENV in the Makefile), overriding even an operator shell that exports APP_MFA_ENABLED=false. A plain make stack-up stays byte-identical (the dev default is already true, §1.3). |
the run |
| kind SSO slice | make kind-up MFA=1 |
bootstrap-kind.sh appends a mfa.enabled=true helm parameter to every gateway Application it applies (today: hugmesh-gateway-fe) — the same runtime-patch mechanism as its ingress.className override, so the committed chart/apps stay untouched. Fails loudly under KIND_PROFILE=core (no gateway is applied there) and on any unrecognised MFA spelling. With it on, spec 27's cluster carries live route-level enforcement for the non-privileged case, same as compose (§3.1). |
the kind cluster |
| per-domain / tenant | MFA=1 in brands/<brand>.conf, then ./generate-brand-repos.sh brands/<brand>.conf |
renders mfa: {enabled: true} into that brand's gateway Applications via the {{MFA_ENABLED}} token (both render engines; parity-proven). Conf-only by design: an ambient exported MFA=1 does NOT leak into a render whose profile never set it (root-cron reconcile safety). |
one CLUSTER_DOMAIN |
The reference cluster (specs/cluster) is deliberately NOT a lane. Its flip
remains §3 step 6 — a reviewed commit that sets the shared chart's mfa.enabled
and moves the EXPECT_* pins in the same change. MFA=1 gives you the
rehearsal (compose), the integration proof (kind), and the tenant rollout
(brands); it never silently changes the posture a cluster ships with.
Per-domain WITHIN one mesh (several local domains behind the same gateways)
is now expressible — the casdoor-choice schema landed (PR #71) and the join
point named here was implemented: uq_route_access_row's domain leg is keyed
on the gateway's own scope equivalence, the seed's UPDATE carries a
per-domain arm (empty today), and §1.2a's scope table says exactly what a
domain-scoped row can express (per-domain tightening), cannot express
(per-domain exemption — decide() is a sticky OR and the blanket rows are
unscoped), and what an own-IdP domain means for a MFA=1 flip (its
principals cannot enroll — enumerate them before §3 step 6).
Wiring proof: tests/stack/test-mfa-flip-wiring.sh (CI lint:mfa-flip-wiring)
re-derives every consumer of the trio per lane from the artifacts themselves and
fails if any consumer stops receiving the switch — the inert-toggle failure mode
(a flag wiring only half its consumers has shipped dark twice in this repo). All
of its checks are mutation-tested on staged copies.
$ make kind-mfa-posture # what the RUNNING gateway pod actually has
APP_MFA_ENABLED=false
$ make kind-e2e-mfa # spec 29 against the cluster, at that live posturekind-e2e runs spec 27 only, so before kind-e2e-mfa the kind lane could flip MFA
on and had no way to run the MFA spec against either posture. The target reads
APP_MFA_ENABLED back off the gateway Deployment (scripts/kind-mfa-posture.sh) and
hands it to spec 29, which selects between its two stack blocks on that value:
false runs the OFF-posture block (the seeded mfa_required rows are inert, the role
wall on the same rows is not, an un-enrolled admin is never challenged) and anything
else runs the per-row enforcement block.
Read live, never guessed, and never threaded from $(MFA) — deliberately. kind-up
is a separate invocation and the cluster outlives it, so the caller's shell describes
a cluster it may never have flipped; and the repo cannot answer either, because
kind-up MFA=1 flips through an ArgoCD helm parameter, leaving the committed
chart reading mfa.enabled: false on a cluster that is enforcing. The helper is
fail-closed: an unreachable cluster is an error, not an "assume off" that would report
a clean pass for the posture the cluster is not holding.
What the flip changes, concretely (verified on the kind SSO slice, 2026-08-20 —
9 mfa_required rows seeded, hugmesh-gateway-fe holding APP_MFA_ENABLED=false):
make kind-up MFA=1 appends {"name":"mfa.enabled","value":"true"} to the
hugmesh-gateway-fe Application's helm parameters, the chart re-renders
APP_MFA_ENABLED=true into the gateway container, and the pod rolls. Nothing else
moves — APP_MFA_FRESHNESS_WINDOW stays 600000 and
APP_MFA_ENFORCE_PRIVILEGED_FLOOR stays false (§3 step 7 is still a hand-executed
step). The observable difference is that a pure ROLE_FLEET_ADMIN on
/bff/admin/phone-fleet/** goes from "reaches admin-bff" to the gateway's 403 +
X-Route-Denied; privileged roles are unchanged until the floor is on (§3.1).
⚠ The equivalent one-shot kubectl patch must carry both parameters —
--type merge replaces spec.source.helm.parameters wholesale, so a patch that sets
only mfa.enabled drops the kind lane's ingress.className: nginx-internal override
and nothing routes.
Everything before this section says why; this is the order and the commands. It
exists because the only thing left on the MFA privileged floor is a live action on a
real cluster, and the earlier text spread its commands over eight sections. None of
this has been run against a live cluster by the person who wrote it — the commands
are derived from the committed manifests (every namespace, Deployment, container,
database and Secret name below is cited to one) and the SQL that is marked is
executed by tests/scripts/test-mfa-required-rules.sh, but a command that has
never met your cluster can still be wrong. Each phase says what it proves; stop at
the first phase that does not come back as stated.
Conventions: $KC is kubectl pointed at the operator's cluster context, checked
with kubectl config current-context first. Nothing below is for the kind lane
(§8.1 covers that). The runbook's own SQL blocks are fed to psql through
scripts/mfa-runbook-sql.sh <name>, which prints the block byte-for-byte as the
gate ran it (--list shows the names); never retype them.
The four gateways, from specs/cluster/apps/20-gateway-*.yaml and
22-gateway-superadmin.yaml (Deployment name = instance.name, container gateway):
| gateway Deployment | namespace | ArgoCD Application (ns devops) |
|---|---|---|
hugmesh-pki-gateway |
hugmesh-pki |
hugmesh-gateway-pki |
hugmesh-be-gateway |
hugmesh-backend |
hugmesh-gateway-be |
hugmesh-fe-gateway |
hugmesh-frontend |
hugmesh-gateway-fe |
hugmesh-superadmin-gateway |
hugmesh-pki |
hugmesh-gateway-superadmin |
$ git fetch origin && git status -sb # you are reviewing the commit you will deploy
$ for t in tests/scripts/test-mfa-required-rules.sh \
tests/scripts/test-mfa-raw-jwt-posture.sh \
tests/stack/test-gateway-mfa-env.sh \
tests/stack/test-mfa-flip-wiring.sh; do bash "$t" >/dev/null 2>&1; echo "$? $t"; done
0 tests/scripts/test-mfa-required-rules.sh
0 tests/scripts/test-mfa-raw-jwt-posture.sh
0 tests/stack/test-gateway-mfa-env.sh
0 tests/stack/test-mfa-flip-wiring.shAll four must print 0 before the flip commit (a gate that is already red proves
nothing about your change). The flip commit then turns three of them red until their
pins move (§3 steps 6 and 7) and must leave all four green again.
tests/stack/test-gateway-mfa-env.sh cross-checks its model against a real helm template when helm is on PATH and prints SKIP (9) when it is not — run it with
REQUIRE_HELM=1 so a missing helm is a failure, not a quieter green.
tests/scripts/test-mfa-required-rules.sh needs only python3 (it replays the seed on
the stdlib sqlite3 engine; set POSTGRES_HOST to replay it on a real Postgres too).
The committed chart says false; the pod is the truth (§6 item 4). Read the env the
process carries, on all four, all three variables:
$ for gw in hugmesh-pki-gateway:hugmesh-pki hugmesh-be-gateway:hugmesh-backend \
hugmesh-fe-gateway:hugmesh-frontend hugmesh-superadmin-gateway:hugmesh-pki; do
d=${gw%%:*}; ns=${gw##*:}; echo "== $d ($ns)"
$KC -n "$ns" exec "deploy/$d" -c gateway -- env | grep '^APP_MFA_' | sort
done
== hugmesh-pki-gateway (hugmesh-pki)
APP_MFA_ENABLED=false
APP_MFA_ENFORCE_PRIVILEGED_FLOOR=false
APP_MFA_FRESHNESS_WINDOW=600000
... (the same three lines for each of the other three)Expect false / false / 600000 four times. Anything else means somebody already
flipped something outside git — resolve that before going on. Also confirm what
ArgoCD thinks is deployed, and whether this cluster has a repo-recursing root at all
(phases E-bypass and G branch on it):
$ $KC -n devops get application hugmesh-root --ignore-not-found \
-o jsonpath='{.spec.source.path}{"\n"}'
$ $KC -n devops get app hugmesh-gateway-pki hugmesh-gateway-be \
hugmesh-gateway-fe hugmesh-gateway-superadmin \
-o custom-columns=NAME:.metadata.name,SYNC:.status.sync.status,HEALTH:.status.health.status,REV:.status.sync.revisionThe first command prints specs/cluster/apps if a recursing root exists (this is the
same test bootstrap.sh uses before it retires one) and nothing if not. Nothing is
the default: the root is opt-in (HUGMESH_GITOPS_ROOT_RECURSE=1, specs/cluster/app-of-apps.yaml)
and bootstrap.sh removes a leftover one, so on a default cluster there is no
hugmesh-root and every command below that names it is skipped (marked root only).
Note which case you are in; if the root exists add it to the second command and expect it
Synced / Healthy too. On the four gateway Applications expect Synced / Healthy,
and REV equal to the commit you reviewed in phase A.
All of C is read-only. Every command here can be run today, with enforcement off.
C1. The factor key exists and is non-empty (§4.1; Secret admin-bff-mfa, key
factor-key, from specs/cluster/manifests/admin-bff-api/deployment.yaml). The value
is not printed:
$ $KC -n hugmesh-backend get secret admin-bff-mfa -o jsonpath='{.data.factor-key}' | wc -cExpect a number well above 0 (a base64 256-bit key is 44). 0 or No resources
means step 1 of §3 is not done and nobody can enrol TOTP.
C2. WebAuthn RP-ID and origins are your real domain (§4.2):
$ for v in APP_MFA_WEBAUTHN_RP_ID APP_MFA_WEBAUTHN_ORIGINS APP_CASDOOR_MFA_ENABLED; do
printf '%s=' "$v"
$KC -n hugmesh-backend get deploy hugmesh-admin-bff-api \
-o jsonpath="{.spec.template.spec.containers[*].env[?(@.name==\"$v\")].value}"; echo
done
$ $KC -n hugmesh-backend logs deploy/hugmesh-admin-bff-api --since=24h | grep -c 'MFA MISCONFIGURED' || trueExpect your own domain on the first two (not admin.hugmesh.net unless that is your
domain, and never localhost), true on the third, and 0 from the grep (the boot
guard's banner, §4.3 — absence is only meaningful if that image carries the guard; the
trailing || true is there because grep -c exits 1 when the count is 0).
C3. The seeded rules are what §1.2 says — 16 flipped, 17 carrying the floor. Run
the two runbook blocks, unmodified, against the route-access database
(deploy/route-access-db, namespace hugmesh-pki, database and owner role
gateway, password from the pod's own POSTGRES_PASSWORD, per
specs/cluster/manifests/route-access/deployment.yaml):
$ for b in verify floor; do
echo "== $b"
scripts/mfa-runbook-sql.sh "$b" | $KC -n hugmesh-pki exec -i deploy/route-access-db -- \
sh -c 'PGPASSWORD="$POSTGRES_PASSWORD" psql -X -U gateway -d gateway'
doneExpect (16 rows) for verify, all mfa_required = t, and (17 rows) for floor
(the extra one is the allow = f games-services row, §3 step 4). If the cluster was
upgraded in place and these come back short, re-apply 20-schema.sql (§3 step 4);
do not hand-edit rows (§5).
C4. The machine-caller census (§2.4) — re-run it, it is a point-in-time answer.
The static half (a git grep per repo, in §2.4) is the part that answers "does a machine
caller reach /bff/admin… or /bff/superadmin…". The empirical half is the runbook block
casdoor-machine-census, which lists which Casdoor applications have minted
client_credentials tokens (a machine token carries grant_type = 'client_credentials'
and a placeholder user equal to its application name, not an empty user; §2.4
cites the pinned Casdoor source):
$ scripts/mfa-runbook-sql.sh casdoor-machine-census | \
$KC -n hugmesh-pki exec -i deploy/casdoor-pg -- \
sh -c 'PGPASSWORD="$POSTGRES_PASSWORD" psql -X -U "$POSTGRES_USER" -d casdoor'Do not expect zero machine rows: client_credentials is seeded on every
confidential app and the seven call sites in §2.4 use it, so machine rows for those
applications are normal. Compare the application column with that list. A machine row
for an application that is not on it is a §2.4 stop (a caller the census did not
know about); resolve it before step 6, because a machine token is denied permanently on
mfa_required routes the moment step 6 lands. The block cannot tell you which URL a token
reached, so a clean result here is not evidence that nothing machine-driven calls the
gated prefixes; only §2.4's static census and the gateway logs say that. (The Casdoor
Deployment is casdoor-pg in hugmesh-pki, database casdoor, user from the pod's
POSTGRES_USER, per specs/cluster/manifests/casdoor/pg.yaml; the token columns used
are those of casbin/casdoor:3.80.0, which the cluster pins.)
C5. Every privileged operator has an ENABLED TOTP factor — the census the runbook
had no command for. The query below lists every account whose cached roles include
superadmin, admin or game-master, with whether it holds an enabled TOTP and/or
WebAuthn factor. TOTP specifically, not "any factor", because only the TOTP path issues
recovery codes (§2.2). It is executed by the gate against a fixture schema that
mirrors changelogs 004-account.xml and 151-mfa-factors.xml.
SELECT a.id,
a.roles,
EXISTS (SELECT 1 FROM mfa_factor f
WHERE f.owner_subject = a.id AND f.enabled AND f.type = 'TOTP') AS totp,
EXISTS (SELECT 1 FROM mfa_factor f
WHERE f.owner_subject = a.id AND f.enabled AND f.type = 'WEBAUTHN') AS webauthn
FROM account a
WHERE ',' || replace(a.roles, ' ', '') || ',' LIKE '%,superadmin,%'
OR ',' || replace(a.roles, ' ', '') || ',' LIKE '%,admin,%'
OR ',' || replace(a.roles, ' ', '') || ',' LIKE '%,game-master,%'
ORDER BY 3, 1;$ scripts/mfa-runbook-sql.sh census | $KC -n hugmesh-backend exec -i deploy/admin-bff-db -- \
sh -c 'PGPASSWORD="$POSTGRES_PASSWORD" psql -X -U adminbff -d adminbff'(deploy/admin-bff-db, namespace hugmesh-backend, database and owner role
adminbff, from specs/cluster/manifests/admin-bff-db/deployment.yaml.) Rows are
sorted un-enrolled first. Every row must show totp = t. A row with totp = f and
webauthn = t is the §2.2 hazard (WebAuthn-only, no recovery codes) and is not
ready. The census is only as complete as what it can see, and three blind spots matter:
-
account.rolesis a cached copy that admin-bff re-syncs from the Casdoor id_token on every native login (changelog260-account-roles-check-relax.xml). A privileged Casdoor user who has never logged in through/bff/loginhas noaccountrow, therefore no opaque session, therefore cannot enrol at all, and is invisible here. Compare against Casdoor's own role membership (Casdoor admin UI → Roles →superadmin,admin,game-master) and have each missing person log in once. No SQL is given for the Casdoor side: itsroletable layout was not verified from this repo. -
owner_subjectis carrier-dependent (auth-coreMfaEnrollmentController.subjectOf): an opaquebff_session enrols underaccount.id(casdoor:<handle>), a raw JWT under the CasdoorsubUUID. The join above is correct for the native-login web console, which is the only carrier that can completePOST /bff/mfa/challenge(§2.4). Look at what is not matched:$ echo "SELECT owner_subject, type, enabled FROM mfa_factor ORDER BY 1,2;" | \ $KC -n hugmesh-backend exec -i deploy/admin-bff-db -- \ sh -c 'PGPASSWORD="$POSTGRES_PASSWORD" psql -X -U adminbff -d adminbff'
An
owner_subjectthat looks like a bare UUID is a raw-JWT enrolment keyed under thesub; it will not appear in the census and its holder must be checked by hand. -
An
idp: owndomain's principals cannot enrol at all (§1.2a); enumerate those domains separately.
C5b. The pure fleet owners — the one population step 6 (mfa.enabled alone) changes.
C5 lists superadmin, admin and game-master, and those three short-circuit in the
gateway before the mfa_required decision (§3.1), so until step 7 they are not gated at
all. The population that is gated at step 6 is an account with fleet_admin and none
of those three: it reaches /bff/admin/phone-fleet/** today and, once step 6 lands,
gets 403 + X-Route-Denied until it holds a fresh stamp. These are customer-facing
accounts (phone-fleet owners), not operators. The account.roles token is lowercase
fleet_admin (the gateway authority ROLE_FLEET_ADMIN, upper-cased by auth-core's
BffCookieAuthenticationWebFilter). entitled is the same test the admin-bff entitlement
wall applies (an active fleet_entitlement row, not expired; changelog
306-fleet-entitlement.xml), keyed on account.id as the opaque-session carrier does.
SELECT a.id,
a.roles,
EXISTS (SELECT 1 FROM mfa_factor f
WHERE f.owner_subject = a.id AND f.enabled AND f.type = 'TOTP') AS totp,
EXISTS (SELECT 1 FROM mfa_factor f
WHERE f.owner_subject = a.id AND f.enabled AND f.type = 'WEBAUTHN') AS webauthn,
EXISTS (SELECT 1 FROM fleet_entitlement e
WHERE e.subject = a.id AND e.active
AND (e.expires_at IS NULL OR e.expires_at > CURRENT_TIMESTAMP)) AS entitled
FROM account a
WHERE ',' || replace(a.roles, ' ', '') || ',' LIKE '%,fleet\_admin,%' ESCAPE '\'
AND NOT ( ',' || replace(a.roles, ' ', '') || ',' LIKE '%,superadmin,%'
OR ',' || replace(a.roles, ' ', '') || ',' LIKE '%,admin,%'
OR ',' || replace(a.roles, ' ', '') || ',' LIKE '%,game-master,%')
ORDER BY 3, 5 DESC, 1;$ scripts/mfa-runbook-sql.sh fleet-census | $KC -n hugmesh-backend exec -i deploy/admin-bff-db -- \
sh -c 'PGPASSWORD="$POSTGRES_PASSWORD" psql -X -U adminbff -d adminbff'Rows are sorted un-enrolled first, then entitled first. A row with totp = f and
entitled = t is someone who loses the phone console at step 6 until they enrol and
step up. That is a decision, not a stop: either have them enrol first (they can; /bff/mfa/**
has no route row, §2.1) or announce the loss. A row with entitled = f already gets
403 fleet entitlement required and is unaffected by step 6. Unlike C6 this is not a
person-by-person proof; nobody can make a customer enrol, and the census only tells you
whom to tell. It sees only accounts with a cached account row (the C5 first bullet),
carriers keyed on the Casdoor sub rather than account.id (the C5 second bullet; also
why entitled can read f for an owner whose entitlement is keyed on a sub), and not
the principals of an idp: own domain (§1.2a), who cannot enrol at all.
C6. Each privileged operator PROVES a fresh stamp — a human step, no command can do it
for them. For every row from C5: sign in at the real console, open the login-ui security
page, complete the TOTP challenge (POST /bff/mfa/challenge, body
{"factor":"totp","credential":"<code>"}, driven by the page), then reach an
/bff/admin… page within 10 minutes. Afterwards you can read the stamp back
(token column deliberately not selected):
$ echo "SELECT account_id, mfa_satisfied, mfa_satisfied_at, now() - mfa_satisfied_at AS age
FROM bff_session
WHERE mfa_satisfied AND expires_at > now()
ORDER BY mfa_satisfied_at DESC;" | \
$KC -n hugmesh-backend exec -i deploy/admin-bff-db -- \
sh -c 'PGPASSWORD="$POSTGRES_PASSWORD" psql -X -U adminbff -d adminbff'Every privileged account_id from C5 must appear at least once with mfa_satisfied = t. Record each operator's recovery codes at enrol time (shown once, §2.2). Do not
go on until C5 is fully totp = t and every row has appeared here.
C7. Two people hold cluster access. §6 item 5's break-glass needs kubectl on the
admin-bff database; if the only person who can do it is the one being locked out,
there is no way back. Name the second person now.
§3 step 7 cannot canary one gateway through git (§3 step 7's warning). Decide, in
writing, before phase E: (a) all four at once from one commit, (b) the
temporary bypass in phase E on hugmesh-fe-gateway first, or (c) extend the gate
to allow a per-gateway pin. This section implements (a) and (b).
E1. Step 6 (mfa.enabled). One commit that changes, together: the chart value
specs/cluster/charts/hugmesh-gateway/values.yaml mfa.enabled: true, and the three
suites' pins exactly as §3 step 6's table lists (test-gateway-mfa-env.sh,
test-mfa-required-rules.sh, test-mfa-flip-wiring.sh). Re-run phase A: all four
0. Merge, let ArgoCD sync, then re-run phase B: APP_MFA_ENABLED=true on all
four, floor still false, window still 600000. Wait for rollouts:
$ for gw in hugmesh-pki-gateway:hugmesh-pki hugmesh-be-gateway:hugmesh-backend \
hugmesh-fe-gateway:hugmesh-frontend hugmesh-superadmin-gateway:hugmesh-pki; do
$KC -n "${gw##*:}" rollout status "deploy/${gw%%:*}" --timeout=300s
doneWhat you should and should not see (§3.1): a pure ROLE_FLEET_ADMIN without a
stamp now gets 403 with X-Route-Denied on /bff/admin/phone-fleet/** (the C5b rows
with totp = f, entitled = t; re-run fleet-census and compare with who actually
complains); admins and superadmins are unchanged. A quiet cluster is not evidence that admin MFA works.
Soak here as long as you like; this state is the recommended resting point.
E2. Step 7 (mfa.enforcePrivilegedFloor) — option (a). Rehearse on compose first
(make stack-up MFA_FLOOR=1, then MFA_FLOOR=1 npx playwright test 29-mfa-privileged-floor from tests/e2e). Have two superadmin sessions open on
two browsers, each with a stamp taken in the last few minutes, and the C7 person on
call. One commit: mfa.enforcePrivilegedFloor: true plus the two suite pins from §3
step 7's table. Merge, sync, re-run phase B (APP_MFA_ENFORCE_PRIVILEGED_FLOOR=true
everywhere), and expect 503 + Retry-After: 5 for privileged callers during each
gateway's cold start (§2). Then, from a session whose stamp is older than 10
minutes, load an /bff/admin… page: expect 403 + X-Route-Denied; complete the
challenge on the security page and reload: expect it to pass. A page outside the floor
(for example /bff/mod/**, the moderation surface left out of scope in §1.2a)
must be untouched; the forum, wiki and owncast admin consoles are not such a
page, they carry the floor too.
E-bypass. Option (b): the floor on hugmesh-fe-gateway only, temporarily, outside
git. Auto-sync must be suspended or it reverts you within a reconcile (§3 step 7).
This is a drift you create on purpose and must undo:
$ $KC -n devops patch app hugmesh-root --type merge -p '{"spec":{"syncPolicy":{"automated":null}}}' # root only (phase B printed specs/cluster/apps)
$ $KC -n devops patch app hugmesh-gateway-fe --type merge -p '{"spec":{"syncPolicy":{"automated":null}}}'
$ $KC -n hugmesh-frontend set env deploy/hugmesh-fe-gateway -c gateway APP_MFA_ENFORCE_PRIVILEGED_FLOOR=true
$ $KC -n hugmesh-frontend rollout status deploy/hugmesh-fe-gateway --timeout=300sSkip the first line on a cluster without the root (the default, phase B). Undo it by
re-enabling auto-sync with
{"spec":{"syncPolicy":{"automated":{"prune":true,"selfHeal":true}}}}: on the root
(root only), which re-applies the Application specs from git, and on
hugmesh-gateway-fe itself (on a cluster without a root nothing else re-applies its
spec, so this patch is the whole undo), then confirming phase B shows the value git says.
Until you do, reconcile-driven fixes are frozen on hugmesh-fe-gateway (and, with a
root, on every Application). Not run against a live cluster; ArgoCD behaviour here is
read from the manifests only.
Re-run phase B, the C3 floor block (still (17 rows) — a flip must not move data),
and the C5/C5b/C6 queries. Watch the four gateways' logs for a burst of 403 /
X-Route-Denied from principals you did not expect; each is either an operator who
missed C6 or a caller the §2.4 census did not know about.
Order is §6: floor first, then enabled, data last. The durable rollback is a git
revert of the flip commit (its pins revert with it). The fast path, when minutes
matter, is to suspend auto-sync and change the env, then reconcile afterwards:
$ $KC -n devops patch app hugmesh-root --type merge -p '{"spec":{"syncPolicy":{"automated":null}}}' # root only (phase B printed specs/cluster/apps)
$ $KC -n devops patch app hugmesh-gateway-fe --type merge -p '{"spec":{"syncPolicy":{"automated":null}}}'
$ $KC -n hugmesh-frontend set env deploy/hugmesh-fe-gateway -c gateway APP_MFA_ENFORCE_PRIVILEGED_FLOOR=false
$ $KC -n hugmesh-frontend rollout status deploy/hugmesh-fe-gateway --timeout=300s(Skip the first line on a cluster without the root, the default. Repeat the second, third
and fourth lines for each affected gateway from the table above; for a full disable add
APP_MFA_ENABLED=false. Afterwards re-enable auto-sync as in E-bypass, on each patched
Application and, root only, on the root.) Break-glass for one operator with no usable
factor, in two separate commands, because a single piped heredoc cannot be read before
it commits (psql would run the SELECT, the DELETEs and the COMMIT in one go).
<owner_subject> is the value from the C5 id column, or the unmatched
owner_subject from the second list under C5 when the operator enrolled on a raw-JWT
carrier (it is a bare UUID there, not casdoor:<handle>).
G1. Look (read-only; nothing to commit):
$ $KC -n hugmesh-backend exec -i deploy/admin-bff-db -- \
sh -c 'PGPASSWORD="$POSTGRES_PASSWORD" psql -X -v ON_ERROR_STOP=1 -U adminbff -d adminbff' <<'SQL'
SELECT 'mfa_factor', count(*) FROM mfa_factor WHERE owner_subject = '<owner_subject>'
UNION ALL SELECT 'mfa_recovery_code', count(*) FROM mfa_recovery_code WHERE owner_subject = '<owner_subject>'
UNION ALL SELECT 'webauthn_credential', count(*) FROM webauthn_credential WHERE owner_subject = '<owner_subject>';
SQLRead the three counts. All zero means you have the wrong owner_subject: stop.
G2. Delete, as shipped a dry run. The block below ends in ROLLBACK;, so as written
it deletes nothing and prints each statement's DELETE n. Compare those n with the G1
counts; only if they match, run it again with the last line changed to COMMIT;:
$ $KC -n hugmesh-backend exec -i deploy/admin-bff-db -- \
sh -c 'PGPASSWORD="$POSTGRES_PASSWORD" psql -X -v ON_ERROR_STOP=1 -U adminbff -d adminbff' <<'SQL'
BEGIN;
DELETE FROM mfa_recovery_code WHERE owner_subject = '<owner_subject>';
DELETE FROM webauthn_credential WHERE owner_subject = '<owner_subject>';
DELETE FROM mfa_factor WHERE owner_subject = '<owner_subject>';
ROLLBACK;
SQL(None of the three tables has a foreign key to another, changelog 151-mfa-factors.xml,
so the order is not load-bearing.)
That operator can then sign in again and re-enrol TOTP first (§2.2) —
enrolment is reachable with the floor on (§2.1: /bff/mfa/** has no route row), and
only the removal of a factor and the recovery-code regeneration are step-up gated.
The data rollback (§6 step 3) is scripts/mfa-runbook-sql.sh rollback | …psql… against
route-access-db, exactly as in C3.
It does not prove that Postgres executes the runbook's SQL blocks (the gate runs
those on sqlite; only the seed has a Postgres leg, §1.2) — C3, C4, C5 and C5b are their
first contact with Postgres. The C4 fixture mirrors the token table as read from the
Casdoor 3.80.0 source, not a table dumped from a live Casdoor. It does not enumerate
privileged Casdoor users who never logged in (C5, first bullet). It does not prove the
suspended-auto-sync commands against your ArgoCD version. And it cannot make an
operator enrol: C6 is a person at a keyboard.