Only invited people get an account; removing a member ends their access #82

Merged
calvin merged 2 commits from invited-sign-up into master 2026-11-15 06:14:14 +00:00
Owner

What this does

Two access changes, one branch.

1. Only invited people get an account

SALT_DNS_OIDC_AUTO_CREATE now takes true, false or invited. Anything else stops the boot (RuntimeConfig). true and false work as before.

With invited:

  • A first sign-in creates a user only if an owner or admin invited the verified address of the ID token (pending, not expired, not revoked). In one transaction Salt creates the user, adds the membership for every pending invitation for that address (several organisations are all accepted), and marks them accepted.
  • Without an invitation, the person gets a plain 403 page: no account here, ask an owner for an invitation. The page is identical for never invited, expired and revoked, so it tells nobody whether an address was invited. An unverified address is refused before any invitation is looked up.
  • An address match never attaches a provider account to an existing user. Users are still recognised by sub only; a clash is still email_taken and the invitation stays pending.
  • Members page: the existing "add a member" form invites an address that has no account (an address with an account is added as before). Pending invitations are listed with a Revoke button. Only owners and admins can do this, in the page and in the context functions.
  • New table invitations (migration 20261125090000): organisation, citext e-mail (same type as users.email), role, invited_by, expires_at (default 14 days), accepted_at, revoked_at, plus revoked_by and accepted_user for the record. A new table only, so the old code runs fine while it is applied.
  • Mail: none is sent. There is no mailer for member notices to reuse (UserNotifier only has the sign-in link and the address-change mail), and releases run with mail_delivery false. The page says the inviter tells the person, with the sign-in address.
  • REST API: there are no member calls in the REST API today, so invitations are console and operator command only.
  • Audit: membership changes are not audited today (the changes table is per zone). The invitation row records who invited, who revoked, who accepted and when, and each of the three writes one info log line with ids (never the address).

Who may create an organisation under invited

Only a user who is an owner of some organisation. Installations that are not invited are unchanged (anyone). Before this, any user with no membership was shown a form to create an organisation, and the provider was the only gate. Under invited, a person invited as admin, editor or viewer, or a person with no membership, cannot. This is the smallest rule that closes "anyone the provider lets in makes an organisation". Provisioning tokens and parent organisations are not involved: they create child organisations through the API, which is a different path. Enforced in Accounts.create_organisation/2 (so a forged event fails too) and hidden on the organisations page.

Operator commands

SaltDns.Release.create_organisation(name) and SaltDns.Release.invite(email, organisation_id, role), documented in docs/operations.md. A fresh invited installation has no organisation and no owner, so the operator makes the organisation and invites its first owner. (create_organisation/1 is one more than asked; without it a fresh installation has no way in.)

2. Removing a membership ends the person's access

  • No membership left: delete_all_user_session_tokens/1 (all sessions end, open pages disconnect).
  • Other memberships left: sessions stay and the person's open pages are disconnected (the broadcast the session code uses), so they load again with the rights they have now.
  • A role change (any direction) does the same disconnect and no session end. Saving the same role does nothing.

What LiveViews did before: Console.Hooks.load_org reads the organisation, role and admin? once, in on_mount. Actions (SaltDns.Access) read the memberships from the database on every call, so a removed or demoted person could not change anything. But the page kept showing the old role and organisation data, and kept receiving updates, until it was reloaded. Now the disconnect makes the browser remount, and load_org then sends them away or loads the lower rights. There is no organisation deletion in the code, so no path to cover there; there is no member API either.

A release task runs in its own VM without the PubSub, so the console is the path that disconnects pages (as with sign_out_user).

Switching it on

Set SALT_DNS_OIDC_AUTO_CREATE=invited and restart. Existing users keep their accounts and memberships. Nothing is changed for them. Run the migration first (the normal deploy does). Recommended for a public installation.

Tests

New: test/salt_dns/accounts_invitations_test.exs, test/salt_dns_web/live/console/invitations_test.exs, test/salt_dns_web/oidc_invited_test.exs; extended: release_test.exs, runtime_config_test.exs. All database tests are :integration. Run locally with --include integration on the workstation Postgres (partition invited): 245 passed (the new files plus the existing member, OIDC, accounts, release, docs and back-channel tests).

Format, compile --warnings-as-errors and credo --strict are clean.

Not verified: a real identity provider (the tests use the mock provider); the live installation.

🤖 Generated with Claude Code

https://claude.ai/code/session_01DnYzaTxC2GmdSpvCNyHNne

## What this does Two access changes, one branch. ### 1. Only invited people get an account `SALT_DNS_OIDC_AUTO_CREATE` now takes `true`, `false` or `invited`. Anything else stops the boot (`RuntimeConfig`). `true` and `false` work as before. With `invited`: - A first sign-in creates a user only if an owner or admin invited the verified address of the ID token (pending, not expired, not revoked). In one transaction Salt creates the user, adds the membership for every pending invitation for that address (several organisations are all accepted), and marks them accepted. - Without an invitation, the person gets a plain 403 page: no account here, ask an owner for an invitation. The page is identical for never invited, expired and revoked, so it tells nobody whether an address was invited. An unverified address is refused before any invitation is looked up. - An address match never attaches a provider account to an existing user. Users are still recognised by `sub` only; a clash is still `email_taken` and the invitation stays pending. - Members page: the existing "add a member" form invites an address that has no account (an address with an account is added as before). Pending invitations are listed with a Revoke button. Only owners and admins can do this, in the page and in the context functions. - New table `invitations` (migration `20261125090000`): organisation, citext e-mail (same type as `users.email`), role, invited_by, expires_at (default 14 days), accepted_at, revoked_at, plus revoked_by and accepted_user for the record. A new table only, so the old code runs fine while it is applied. - **Mail:** none is sent. There is no mailer for member notices to reuse (`UserNotifier` only has the sign-in link and the address-change mail), and releases run with `mail_delivery` false. The page says the inviter tells the person, with the sign-in address. - **REST API:** there are no member calls in the REST API today, so invitations are console and operator command only. - **Audit:** membership changes are not audited today (the `changes` table is per zone). The invitation row records who invited, who revoked, who accepted and when, and each of the three writes one info log line with ids (never the address). ### Who may create an organisation under `invited` Only a user who is an **owner of some organisation**. Installations that are not `invited` are unchanged (anyone). Before this, any user with no membership was shown a form to create an organisation, and the provider was the only gate. Under `invited`, a person invited as admin, editor or viewer, or a person with no membership, cannot. This is the smallest rule that closes "anyone the provider lets in makes an organisation". Provisioning tokens and parent organisations are not involved: they create child organisations through the API, which is a different path. Enforced in `Accounts.create_organisation/2` (so a forged event fails too) and hidden on the organisations page. ### Operator commands `SaltDns.Release.create_organisation(name)` and `SaltDns.Release.invite(email, organisation_id, role)`, documented in `docs/operations.md`. A fresh `invited` installation has no organisation and no owner, so the operator makes the organisation and invites its first owner. (`create_organisation/1` is one more than asked; without it a fresh installation has no way in.) ### 2. Removing a membership ends the person's access - No membership left: `delete_all_user_session_tokens/1` (all sessions end, open pages disconnect). - Other memberships left: sessions stay and the person's open pages are disconnected (the broadcast the session code uses), so they load again with the rights they have now. - A role change (any direction) does the same disconnect and no session end. Saving the same role does nothing. What LiveViews did before: `Console.Hooks.load_org` reads the organisation, role and `admin?` once, in `on_mount`. Actions (`SaltDns.Access`) read the memberships from the database on every call, so a removed or demoted person could not change anything. But the page kept showing the old role and organisation data, and kept receiving updates, until it was reloaded. Now the disconnect makes the browser remount, and `load_org` then sends them away or loads the lower rights. There is no organisation deletion in the code, so no path to cover there; there is no member API either. A release task runs in its own VM without the PubSub, so the console is the path that disconnects pages (as with `sign_out_user`). ## Switching it on Set `SALT_DNS_OIDC_AUTO_CREATE=invited` and restart. Existing users keep their accounts and memberships. Nothing is changed for them. Run the migration first (the normal deploy does). Recommended for a public installation. ## Tests New: `test/salt_dns/accounts_invitations_test.exs`, `test/salt_dns_web/live/console/invitations_test.exs`, `test/salt_dns_web/oidc_invited_test.exs`; extended: `release_test.exs`, `runtime_config_test.exs`. All database tests are `:integration`. Run locally with `--include integration` on the workstation Postgres (partition `invited`): 245 passed (the new files plus the existing member, OIDC, accounts, release, docs and back-channel tests). Format, `compile --warnings-as-errors` and `credo --strict` are clean. Not verified: a real identity provider (the tests use the mock provider); the live installation. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01DnYzaTxC2GmdSpvCNyHNne
Only invited people get an account; removing a member ends their access
Some checks failed
ci/woodpecker/pr/image Pipeline was successful
ci/woodpecker/pr/quality Pipeline was successful
ci/woodpecker/pr/integration Pipeline was canceled
3fb4682286
SALT_DNS_OIDC_AUTO_CREATE=invited: a first sign-in through the identity
provider creates a user only for a verified address with a pending
invitation (new table invitations, migration 20261125090000). Owners and
admins invite from the members page. Only owners may create organisations
on such an installation. SaltDns.Release.create_organisation/1 and invite/3
give a fresh installation its first owner.

Removing a member ends all their sessions when no membership is left, and
otherwise disconnects their open pages; a role change disconnects them too.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DnYzaTxC2GmdSpvCNyHNne
Invitations: ASCII-only addresses, owner role only from owners, ID token as the one source
All checks were successful
ci/woodpecker/pr/image Pipeline was successful
ci/woodpecker/pr/quality Pipeline was successful
ci/woodpecker/pr/integration Pipeline was successful
7a83069c74
- Invitation e-mail is a plain text column in ASCII lower case; non-ASCII
  addresses are refused at invite time and never match at sign-in (Kelvin
  sign, dotted I, full-width letters).
- Only an owner may grant the owner role (invite, add, change role) or
  revoke an owner invitation; enforced in Accounts and Invitations.
- The address and its verified flag come from the signed ID token only, in
  every auto_create mode.
- A second simultaneous first sign-in with the same sub succeeds.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DnYzaTxC2GmdSpvCNyHNne
calvin merged commit a7cae653a7 into master 2026-11-15 06:14:14 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
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
external/salt-dns!82
No description provided.