Migrate OIDC to ash_authentication identity_resource closes #557 #573

Merged
moritz merged 23 commits from issue/mitgliederverwaltung-557 into main 2026-10-08 13:03:51 +02:00
Owner

Description of the implemented changes

The changes were:

  • Bugfixing
  • New Feature
  • Breaking Change
  • Refactoring

Migrate OIDC to ash_authentication identity_resource (UserIdentity) and unpin to 4.15+. A disclosure of 18 advisories in ash_authentication / ash_authentication_phoenix made the 4.13 pin a security problem; 4.15 requires OIDC sign-ins to resolve through a user identity resource, so SSO links move from users.oidc_id into user_identities while existing members keep signing in to the same account.

What has been changed?

  • Close the ash_authentication advisories by upgrading to 4.15 with OIDC user identities
  • Carry existing SSO links over into OIDC identities on migration
  • Drop the sign_in_with_oidc read action no OIDC callback reaches
  • Decide OIDC account linking by identity and never link the system user
  • Register OIDC users by email while still applying provider email changes
  • Derive the SSO link status from OIDC identities
  • Drop users.oidc_id now that OIDC identities hold every SSO link
  • Prove unknown OIDC subjects never take over existing accounts
  • Guard session renewal and failed OIDC callbacks against regressions
  • Clear SSO links when the OIDC provider changes
  • Describe OIDC identities, the accepted linking risk and provider switches
  • Refuse to boot when the provider switch check fails
  • Enforce one OIDC identity per account in the database
  • Keep the OIDC strategy name, identity query and provider email in one place
  • Name the provider email in the password verification error
  • Let Mv.Config decide the base URL override for saved settings
  • Tell users whether their account or the OIDC identity is already linked
  • Cover the SSO notice in the user form
  • Roll back the real identity migrations in the rollback test
  • Drop OIDC linking tests that stricter siblings already cover
  • Accept only the email claim as the OIDC provider email
  • Accept re-linking a user to the OIDC identity they already have

Definition of Done

Code Quality

  • No new technical depths
  • Linting passed
  • Documentation is added were needed

Accessibility

  • New elements are properly defined with html-tags
  • Colour contrast follows WCAG criteria
  • Aria labels are added when needed
  • Everything is accessible by keyboard
  • Tab-Order is comprehensible
  • All interactive elements have a visible focus

Testing

  • Tests for new code are written
  • All tests pass
  • axe-core dev tools show no critical or major issues

Additional Notes

  • Rollout: the backfill keys identities on the existing users.oidc_id values, which assumes Authentik keeps sending the same sub (provider "subject mode" unchanged). The first boot after the migration only records the OIDC base URL and clears nothing; later changes of the base URL (settings or OIDC_BASE_URL) clear all SSO links, and every member links once again. If that check fails at boot, the application refuses to start.
  • Behavior change: only the email claim is used as the provider email; a sign-in without it no longer creates or links an account (Authentik and Rauthy send it).
  • Accepted residual risk (documented in docs/oidc-account-linking.md): passwordless, not-yet-linked accounts are auto-linked by matching provider email; trust_email_verified? true is set only because 4.15 refuses false without a confirmation add-on.
  • Verified manually end-to-end against a local Rauthy: new user, passwordless auto-link, password linking, provider email change, and a real backfill (rollback → re-migrate) with existing links.
  • Larger commits: the upgrade, the identity-based linking, the users.oidc_id drop, the provider-switch feature (includes resource snapshots) and the email-claim change touch more than 5 files each.
## Description of the implemented changes The changes were: - [x] Bugfixing - [x] New Feature - [ ] Breaking Change - [x] Refactoring Migrate OIDC to ash_authentication identity_resource (UserIdentity) and unpin to 4.15+. A disclosure of 18 advisories in `ash_authentication` / `ash_authentication_phoenix` made the 4.13 pin a security problem; 4.15 requires OIDC sign-ins to resolve through a user identity resource, so SSO links move from `users.oidc_id` into `user_identities` while existing members keep signing in to the same account. ## What has been changed? - Close the ash_authentication advisories by upgrading to 4.15 with OIDC user identities - Carry existing SSO links over into OIDC identities on migration - Drop the sign_in_with_oidc read action no OIDC callback reaches - Decide OIDC account linking by identity and never link the system user - Register OIDC users by email while still applying provider email changes - Derive the SSO link status from OIDC identities - Drop users.oidc_id now that OIDC identities hold every SSO link - Prove unknown OIDC subjects never take over existing accounts - Guard session renewal and failed OIDC callbacks against regressions - Clear SSO links when the OIDC provider changes - Describe OIDC identities, the accepted linking risk and provider switches - Refuse to boot when the provider switch check fails - Enforce one OIDC identity per account in the database - Keep the OIDC strategy name, identity query and provider email in one place - Name the provider email in the password verification error - Let Mv.Config decide the base URL override for saved settings - Tell users whether their account or the OIDC identity is already linked - Cover the SSO notice in the user form - Roll back the real identity migrations in the rollback test - Drop OIDC linking tests that stricter siblings already cover - Accept only the email claim as the OIDC provider email - Accept re-linking a user to the OIDC identity they already have ## Definition of Done ### Code Quality - [ ] No new technical depths - [x] Linting passed - [x] Documentation is added were needed ### Accessibility - [ ] New elements are properly defined with html-tags - [ ] Colour contrast follows WCAG criteria - [ ] Aria labels are added when needed - [ ] Everything is accessible by keyboard - [ ] Tab-Order is comprehensible - [ ] All interactive elements have a visible focus ### Testing - [x] Tests for new code are written - [x] All tests pass - [ ] axe-core dev tools show no critical or major issues ## Additional Notes - Rollout: the backfill keys identities on the existing `users.oidc_id` values, which assumes Authentik keeps sending the same `sub` (provider "subject mode" unchanged). The first boot after the migration only records the OIDC base URL and clears nothing; later changes of the base URL (settings or `OIDC_BASE_URL`) clear all SSO links, and every member links once again. If that check fails at boot, the application refuses to start. - Behavior change: only the `email` claim is used as the provider email; a sign-in without it no longer creates or links an account (Authentik and Rauthy send it). - Accepted residual risk (documented in `docs/oidc-account-linking.md`): passwordless, not-yet-linked accounts are auto-linked by matching provider email; `trust_email_verified? true` is set only because 4.15 refuses `false` without a confirmation add-on. - Verified manually end-to-end against a local Rauthy: new user, passwordless auto-link, password linking, provider email change, and a real backfill (rollback → re-migrate) with existing links. - Larger commits: the upgrade, the identity-based linking, the users.oidc_id drop, the provider-switch feature (includes resource snapshots) and the email-claim change touch more than 5 files each.
4.15 resolves OIDC sign-ins through a user identity resource and rejects known
users without one. Identities are written alongside users.oidc_id until a later
commit drops the column, so every commit keeps existing SSO users signed in.
Rolling the migration back restores users.oidc_id from the identities, so a
downgrade keeps every SSO link.
Identities are keyed on the provider's subject only, so subjects of a new
provider could collide with stale links. The check runs on settings save and at
boot; the first boot after the migration only records the URL and clears nothing.
preferred_username is often editable by the user at the identity provider, so it
must not decide which local account a sign-in links to.
docs(changelog): record the OIDC identity migration under Unreleased
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/promote/production Build is passing
6b4b025470
moritz merged commit 245b614744 into main 2026-10-08 13:03:51 +02:00
moritz deleted branch issue/mitgliederverwaltung-557 2026-10-08 13:03:51 +02:00
Sign in to join this conversation.
No description provided.