feat(auth): sign in through Thermopylae only #11
No reviewers
Labels
No labels
Bug
Enhancement
Feature
Performance
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
exler/mado!11
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/thermopylae-sso"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Mado now signs everyone in through Thermopylae, and nothing else. The local login form, the password change and the local email editing are gone; Django Admin authenticates the same way, and the
rolesclaim Thermopylae issues for this application decides who gets in.Why
accountsshipped with Django's own username/password login, which meant a second credential store to maintain next to Thermopylae. Thermopylae already vouches for identity (email is its unique key) and, since the per-approlesscope landed, for per-application roles — so Mado can hand the whole problem over.What changed
accounts/auth.pyOIDCAuthenticationBackend: provisions users from the vouched identity, setsis_staff/is_superuserfrom theadminrole, and re-syncs email and roles at every sign-in. Usernames come frompreferred_username(the email), and provisioned users get an unusable password.accounts/admin.pyAdminSite.login, so/admin/login/starts the provider handshake; a signed-in non-staff visitor gets a 403 instead of a provider round-trip loop. Replaces Django'sUserAdminwith a read-only page, which removes the "set password" and permission surface, and the admin's password-change pages answer 404.accounts/urls.py,views.py, templates/login/renders Mado's sign-in screen, whose only option is the Sign in with Thermopylae button;/logged-out/replaces the signed-out redirect, and User Settings reports the identity read-only with a link to Thermopylae. The old password login template is gone, andaccounts/forms.pywith it.mado/settings.pyOIDC_ISSUER/OIDC_CLIENT_ID/OIDC_CLIENT_SECRET; the four endpoints are derived from the issuer; PKCES256;RS256; scopesopenid email profile roles; the provider backend is the onlyAUTHENTICATION_BACKENDSentry.AUTH_PASSWORD_VALIDATORSremoved.accounts/checks.pyaccounts.W001warns when the three settings are missing — Mado has no local sign-in, so nobody could get in.client.login(password=…)replaced withforce_login; 30 tests inaccounts/tests.py.mado/static/css/.thermopylae-markcomponent (see Sign-in button mark below) and the compiledmado.cssrebuilt with the pinned Tailwind 4.2.2.Configuration
Register the application in Thermopylae's
/adminwith redirect URIhttps://mado.marut.network/oidc/callback/, then set in the deployment.env:Give an account the
adminrole under the Mado client to grant Django Admin access.Hardening from review (
c5ed868)A review pass over the first commit found three further defects, all fixed, each with a regression test that fails when the fix is reverted:
email_verified.verify_claimsnow requires it. Thermopylae always sets it for the addresses its admins vouch for, so nothing legitimate is refused.error=, or a failed claim check, the library redirects toLOGIN_REDIRECT_URL_FAILURE— defaulting to/, which requires a sign-in, bounces to the provider, whose session is still open, and returns to the callback that just failed. It now lands on/logged-out/./admin/password_change/and/admin/password_change/done/are DjangoAdminSiteviews; they now answer 404. A password set there could never have authenticated anyone, but the requirement is that no password change exists at all.Reviewed and deliberately not taken:
emailandpreferred_usernamefrom the same field, so the claim shape that lookup defends against cannot occur, and it does nothing for the case that can. Measured, not assumed — see the probe under Verification.Login screen (
445a7f9)/login/no longer redirects straight to the provider: it renders Mado's own sign-in screen, and the only way in from it is a single Sign in with Thermopylae button.?next=is read from the query string, validated withurl_has_allowed_host_and_scheme(an off-site or missing destination falls back toLOGIN_REDIRECT_URL), carried into the provider request, and an already-signed-in visitor is redirected instead of shown the screen. Django Admin funnels into the same screen, so/admin/…→/admin/login/?next=…→/login/?next=…→ button → provider.The screen reuses
logged_out.html's layout and only classes already present in the committed stylesheet, so no CSS rebuild is involved.Sign-in button mark (
b01912e)The button now carries the Thermopylae hoplite, in the treatment the user chose: a single-colour silhouette in the button's own foreground colour, not the two-tone brand art.
Why not the brand art directly: the Thermopylae assets are orange
#f06204+ ivory#f7f5efand its README says to place them on a near-black surface. Measured against Mado's own themes, the two-tone mark loses its orange against the accent button (#ff5201) and loses its ivory on the light theme's paper — two variants of the same artwork were rendered and rejected for exactly that.Implementation: the SVG is copied into
static/img/unchanged, and the silhouette comes from a CSS mask filled withcurrentColor, so the mark follows the button's colour automatically, hover included:The compiled stylesheet was rebuilt, and that is worth a reviewer's attention:
mado.cssis generated, and the siblingnode_moduleson this machine had Tailwind 4.3.3 while the committed file was built with 4.2.2 (the versionbun.lockresolves). Building with 4.3.3 rewrote unrelated utilities, so the rebuild uses the pinned 4.2.2. That build's diff is the new rule plus the removal of the now-unused.hiddenutility — pre-existing drift, not this change: building untouched sources drops it too, and the only hidden utility any template uses ismax-sm:hidden, which is still present.Copy trimmed (
5fb884b,7fde5bd)The screens stopped explaining themselves on request. The line under the heading on the sign-in and signed-out screens is gone, with no replacement copy; the User Settings note about the account belonging to Thermopylae is gone too, because it repeated the account button sitting directly beneath it. That page keeps the button, which links to the provider's
/accountpage. Headings, the provider mark and the remaining buttons are unchanged, and the captures below are the final state.Verification
uv run python manage.py collectstatic --noinputthenDJANGO_SECRET_KEY=… uv run python manage.py test→ 97 tests, OK (67 pre-existing + 30 new)./login/returns 0<form>, 0<input>, 0type="password"and exactly one sign-in control, labelledSign in with Thermopylae; itshrefcarriesnextthrough and an off-sitenextfalls back to/projects/.302tohttps://thermopylae.marut.network/authorize?…withscope=openid email profile rolesandcode_challenge_method=S256.FAILED (failures=3)), so each guard bites.preferred_usernamemoved — what Thermopylae sendspreferred_usernameunchanged — impossible hereIntegrityErroruv run ruff check accounts→ clean. Repo-wide findings went 22 → 11; the remainder are pre-existing, and the removed login view accounted for the rest.uv run mypy accounts→ 5 findings, the same set as before the hardening commit (2type-arginadmin.py, 3 infactories.py) and the same kindevents/admin.pyandprojects/factories.pyalready carry. The repo'smypyinvocation already reports 155 findings onmain.uv run djlint accounts/templates --check→ 0 files would be updated.background-coloris the button's foreground (rgb(10, 7, 5)dark,rgb(251, 248, 244)light), and the browser fetched the mask asset (41 808 B) — so the silhouette paints rather than silently resolving to nothing. Clicking the mark itself still starts the provider handshake.S256,RS256and therolesscope are advertised there./→/projects/→/login/→/oidc/authenticate/→https://thermopylae.marut.network/authorize?…→ Thermopylae's sign-in page./settings/serves no password input and no editable field;/admin/as a staff account shows View user with no password field, no password link and no save row.Known gap: the authorization-code exchange itself is not exercised end to end, because it needs the client credentials that are still to be registered. Everything up to
/authorize, plus the RS256/JWKS setup the library applies on the way back, is verified.Continuous integration
This repository's only workflow publishes images on pushes to
mainand version tags, so a feature branch produces no CI run and this pull request has none. All the checks above were run locally.Migration note
Accounts are matched by email. A Mado user whose email differs from their Thermopylae email gets a second account on first sign-in, and changing an email in Thermopylae does the same — the stable
subclaim is not stored yet, which is the follow-up below. Set the email on the existing user (or move project ownership) before the first login after this deploys.Risk and rollback
Sign-in is now the only entry point, so a missing or wrong OIDC configuration locks everyone out; the
accounts.W001check warns about exactly that case. Reverting the commit restores the previous local login.Follow-ups, deliberately not here
subas the account key, so an email change keeps the account (needs a model and a migration).admintakes effect when the session ends rather than immediately.madostack are not in this PR.createsuperuser/changepasswordcommands still run from a shell; a password they set cannot authenticate anyone, because the provider backend is the only one.Visual verification
Captured against a local server pointed at the live provider, so the handshake in the first three is real.
Mado's sign-in screen — the only option is the provider, and the button carries the Thermopylae mark (dark desktop, light desktop, dark phone width):
Clicking that one button starts the provider handshake:
The signed-out screen (desktop, then phone width):
User Settings reports the identity and hands account changes to the provider:
Django Admin: identity only, no password field, no password link, no save row: