Authenticate exclusively through Thermopylae #7

Merged
exler merged 5 commits from feat/thermopylae-only into main 2026-10-16 20:14:03 +02:00
Collaborator

Summary

  • Removed the general-purpose account-linking command. Keep Django’s inherited password field, usable-password checks and session hashes unchanged; new accounts use standard set_unusable_password(). Legacy hashes cannot authenticate through the sole OIDC backend. Hide admin password navigation with a normal template override, not a model override.
  • Make Thermopylae the sole browser sign-in provider for Dome and Django Admin. Local password login and admin password-change surfaces are removed; bearer API tokens keep working.
  • Use mozilla-django-oidc 5.0.2 with RS256, PKCE S256 and openid email profile roles. Apply the per-client admin role on every sign-in. Require verified email, validate signed ID-token issuer/audience/authorized party/expiry and enforce UserInfo/ID-token subject consistency before provisioning or linking.
  • Reuse Mado's unchanged hoplite asset as a 20×20 foreground-colour CSS mask with the exact “Sign in with Thermopylae” action. Preserve safe next; logout is a CSRF-protected POST with a public signed-out screen. Failure screen stays public.

Existing accounts and migration

Dome has usernames but no email field; copying Mado's email matching would be unsafe. The additive users/0003_oidcidentity migration binds accounts to stable (issuer, sub) identities without changing usernames, tracking ownership, avatars or tokens.

Automatic migration for the confirmed existing account: users/0004_link_exler_thermopylae creates the pending pairing exler → kamil@marut.network at https://thermopylae.marut.network. Deploy and run the ordinary migrations; no manual account-linking command is needed. The first verified provider sign-in binds its stable subject to the existing user, keeping the same profile, tracking and API tokens. Migration is independent of environment configuration, does not create an absent user, and never overwrites an existing identity. A conflicting email pairing stops safely. Reverse is a no-op, retaining the identity.

This is an explicit owner-approved one-time data mapping, not a runtime username-matching exception. Subsequent email changes do not change ownership or profile URLs.

Verification

  • Simplification review passed; parent reran 127 tests after removing command-only tests and adding real legacy-password authentication/admin navigation regressions. No custom has_usable_password or session-hash overrides remain.
  • Follow-up migration review passed; real MigrationExecutor tests cover automatic linking, first verified login preserving PK/tokens/tracking, reruns, absent user, existing identity, and conflicts.
  • Independent security review passed after the token-validation follow-up; no outstanding security or logic findings.
  • Parent independently reran the full suite: 127 tests, OK (expected failures=1). One pre-existing expected failure remains.
  • New auth coverage includes stable identity linking, collisions, inactive accounts/sessions, role revocation, no local-password authentication, protected admin, safe redirects, POST logout and unchanged API access.
  • Real RS256-signed tokens exercise signature, nonce, issuer, audience, authorized-party, expiry and mismatched UserInfo-sub rejection; only network boundaries are mocked. Invalid tokens/subjects cannot create accounts, consume pending links or grant admin access.
  • Focused Ruff checks, uv lock --check, makemigrations --check --dry-run, and git diff --check pass. No OIDC config produces a documented users.W001 warning rather than breaking build/migration.
  • Browser QA: light/dark desktop and 390px mobile (no horizontal overflow). Mark measured 20×20, colour equals button foreground, SVG fetched with HTTP 200; clicking the mark starts the real provider redirect with PKCE S256. Login markup has zero forms and zero inputs.
  • Local fixture route-state matrix exercised anonymous/member/admin access to login, settings, API tokens, admin entry/login/password endpoints, failure/signed-out pages and logout. Admin password endpoints return 404 to staff; nonstaff admin login returns 403; no tested response contains a password input. Screenshots below are from the actual local application with throwaway configuration, not production.
  • Live provider discovery confirms the configured endpoint paths, RS256, S256 and requested scopes.

Rollout / limitations

Not deployed. Register the Dome client in Thermopylae with https://<dome-host>/oidc/callback/, configure OIDC_ISSUER, OIDC_CLIENT_ID, OIDC_CLIENT_SECRET, apply migrations (the existing exler account is paired automatically), and open sign-in. No real-client end-to-end callback has been exercised; browser QA used a placeholder client ID and stopped at the provider login.

Existing sessions are invalidated because their password backend is removed. Logout ends only the Dome session (Thermopylae advertises no end-session endpoint). Existing password hashes are retained but cannot authenticate. Rollback requires reverting application code; the additive identity table can remain without affecting old tables.

Visual verification

login-light.png

login-dark.png

login-mobile.png

## Summary - Removed the general-purpose account-linking command. Keep Django’s inherited password field, usable-password checks and session hashes unchanged; new accounts use standard `set_unusable_password()`. Legacy hashes cannot authenticate through the sole OIDC backend. Hide admin password navigation with a normal template override, not a model override. - Make Thermopylae the sole browser sign-in provider for Dome and Django Admin. Local password login and admin password-change surfaces are removed; bearer API tokens keep working. - Use `mozilla-django-oidc` 5.0.2 with RS256, PKCE S256 and `openid email profile roles`. Apply the per-client `admin` role on every sign-in. Require verified email, validate signed ID-token issuer/audience/authorized party/expiry and enforce UserInfo/ID-token subject consistency before provisioning or linking. - Reuse Mado's unchanged hoplite asset as a 20×20 foreground-colour CSS mask with the exact “Sign in with Thermopylae” action. Preserve safe `next`; logout is a CSRF-protected POST with a public signed-out screen. Failure screen stays public. ## Existing accounts and migration Dome has usernames but **no email field**; copying Mado's email matching would be unsafe. The additive `users/0003_oidcidentity` migration binds accounts to stable `(issuer, sub)` identities without changing usernames, tracking ownership, avatars or tokens. **Automatic migration for the confirmed existing account:** `users/0004_link_exler_thermopylae` creates the pending pairing **`exler` → `kamil@marut.network`** at `https://thermopylae.marut.network`. Deploy and run the ordinary migrations; **no manual account-linking command is needed**. The first verified provider sign-in binds its stable subject to the existing user, keeping the same profile, tracking and API tokens. Migration is independent of environment configuration, does not create an absent user, and never overwrites an existing identity. A conflicting email pairing stops safely. Reverse is a no-op, retaining the identity. This is an explicit owner-approved one-time data mapping, not a runtime username-matching exception. Subsequent email changes do not change ownership or profile URLs. ## Verification - Simplification review passed; parent reran 127 tests after removing command-only tests and adding real legacy-password authentication/admin navigation regressions. No custom `has_usable_password` or session-hash overrides remain. - Follow-up migration review passed; real MigrationExecutor tests cover automatic linking, first verified login preserving PK/tokens/tracking, reruns, absent user, existing identity, and conflicts. - Independent security review passed after the token-validation follow-up; no outstanding security or logic findings. - Parent independently reran the full suite: **127 tests, OK (expected failures=1)**. One pre-existing expected failure remains. - New auth coverage includes stable identity linking, collisions, inactive accounts/sessions, role revocation, no local-password authentication, protected admin, safe redirects, POST logout and unchanged API access. - Real RS256-signed tokens exercise signature, nonce, issuer, audience, authorized-party, expiry and mismatched UserInfo-sub rejection; only network boundaries are mocked. Invalid tokens/subjects cannot create accounts, consume pending links or grant admin access. - Focused Ruff checks, `uv lock --check`, `makemigrations --check --dry-run`, and `git diff --check` pass. No OIDC config produces a documented `users.W001` warning rather than breaking build/migration. - Browser QA: light/dark desktop and 390px mobile (no horizontal overflow). Mark measured 20×20, colour equals button foreground, SVG fetched with HTTP 200; clicking the mark starts the real provider redirect with PKCE S256. Login markup has zero forms and zero inputs. - Local fixture route-state matrix exercised anonymous/member/admin access to login, settings, API tokens, admin entry/login/password endpoints, failure/signed-out pages and logout. Admin password endpoints return 404 to staff; nonstaff admin login returns 403; no tested response contains a password input. Screenshots below are from the actual local application with throwaway configuration, not production. - Live provider discovery confirms the configured endpoint paths, RS256, S256 and requested scopes. ## Rollout / limitations **Not deployed.** Register the Dome client in Thermopylae with `https://<dome-host>/oidc/callback/`, configure `OIDC_ISSUER`, `OIDC_CLIENT_ID`, `OIDC_CLIENT_SECRET`, apply migrations (the existing `exler` account is paired automatically), and open sign-in. No real-client end-to-end callback has been exercised; browser QA used a placeholder client ID and stopped at the provider login. Existing sessions are invalidated because their password backend is removed. Logout ends only the Dome session (Thermopylae advertises no end-session endpoint). Existing password hashes are retained but cannot authenticate. Rollback requires reverting application code; the additive identity table can remain without affecting old tables. ## Visual verification ![login-light.png](https://git.marut.network/attachments/47d2f71d-f02a-46cf-8d5e-95efbf5fec09) ![login-dark.png](https://git.marut.network/attachments/09e4c9fc-71e0-404e-9a7e-40e25c970832) ![login-mobile.png](https://git.marut.network/attachments/1ee6219d-2a67-461a-991c-70480336c85b)
Browser sign-in (app and Django Admin) now goes through Thermopylae via
mozilla-django-oidc (RS256, PKCE S256, scopes openid email profile roles),
the sole authentication backend. Local password login, password validators
and admin password endpoints are gone; bearer API tokens are unchanged.

Accounts bind to the provider's (issuer, sub) through a new additive
OIDCIdentity model, never to username or email. New users get a unique,
valid username from the email local part. Existing accounts are linked
explicitly with `manage.py link_thermopylae <username> <email>`, consumed
once by the next verified sign-in. The `admin` role sets is_staff and
is_superuser on every sign-in.

/login/ renders a sign-in screen with a single "Sign in with Thermopylae"
action and carries a same-host `next` through; logout is a CSRF POST to a
public signed-out screen, and refused sign-ins land on a public retry page.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
mozilla-django-oidc 5.0.2 verifies only signature, alg, nonce and exp-if-present.
Require iss == OIDC_ISSUER, OIDC_RP_CLIENT_ID in aud, azp == client ID when
present (and required for multiple audiences), and exp. Refuse UserInfo whose
sub is empty or differs from the verified ID token's before any lookup, link
or provisioning. Wrap PyJWT errors (e.g. expired) as SuspiciousOperation
instead of letting them 500.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The only production account, exler, is owned by the Thermopylae account
kamil@marut.network (owner-confirmed). users.0004 leaves a pending
OIDCIdentity for that exact username at the fixed issuer
https://thermopylae.marut.network, so the first verified sign-in binds it
without running link_thermopylae. No settings or env are read, so migrate
may run before OIDC is configured.

No-op without exler or when exler already has an identity (never
overwritten); fails with an actionable error if the email is already
linked to another account at that issuer. Reverse is a no-op so a
subject-bound identity is never removed. link_thermopylae stays as the
optional generic path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Migration 0004 is the only way an existing account gets linked, so the
manual command goes. User inherits Django's password behaviour again; a
legacy hash still cannot authenticate because the OIDC backend is the only
one. The admin hides "Change password" via a userlinks template override.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
exler merged commit 16fba9f6ff into main 2026-10-16 20:14:03 +02:00
exler deleted branch feat/thermopylae-only 2026-10-16 20:14:03 +02:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
exler/dome!7
No description provided.