Sessions from single sign-on end after a set time; command to end a person's sessions #78

Merged
calvin merged 3 commits from oidc-session-limit into master 2026-11-14 20:23:35 +00:00
Owner

A person disabled at the identity provider kept a valid Salt session for up to 14 days. This limits sessions that came from single sign-on and adds an operator command to end one person's sessions.

What changes

  • SALT_DNS_OIDC_SESSION_HOURS (default 12, whole number 1 to 336). A session that began with single sign-on is valid for that many hours. After that the next request is signed out and the normal sign-in follows. An invalid value stops the boot with a clear message (same check as the neighbouring settings). Password sessions keep 14 days.
  • Accounts.delete_all_user_session_tokens/1 deletes every session token of a user (password and single sign-on), disconnects their open pages, and returns how many tokens it removed.
  • SaltDns.Release.sign_out_user(email) for operators. Prints the count. An unknown address prints a clear message and changes nothing (returns {:error, :not_found}, no crash). Documented in docs/operations.md, "Ending a person's sessions".
  • Docs: docs/configuration.md (new row), docs/operations.md (session life and the provider case; there is no security page, so it sits next to the command), CHANGELOG.

Design: how single sign-on sessions are marked

A distinct token context, oidc_session, next to the existing session. Chosen over a nullable column because it needs no migration and no backfill, the verify query stays one indexed lookup, and the two lives are visibly separate rows. Existing code that deletes tokens by user (password change, magic link) already deletes every context. The OIDC callback passes method: :oidc through UserAuth.log_in_user/4 to generate_user_session_token/2.

Reissue: UserAuth makes a fresh token for a session older than 7 days. A new "session" token would have restarted the clock and defeated the limit (reachable when the setting is above 168 hours). Single sign-on sessions are therefore never reissued; the person signs in again at the limit.

Sockets that are already connected

Not enforced, and I did not build anything for it. on_mount checks the token once, at mount. There is no periodic check in the shared hooks (the existing timers are per-page refreshes), and a socket only re-checks when it reconnects or the page is loaded again. So an open page can outlive the limit until then. Reaching it cleanly would need a timer in every LiveView or a hook with attach_hook plus Process.send_after in every live_session. I judged that elaborate and left it for the maintainers to decide.

Related: sign_out_user runs in a separate Erlang VM under bin/salt_dns eval, where the application's PubSub is not running, so it cannot disconnect open pages. It deletes the tokens; open pages end at their next load or reconnect, and restarting the application cuts them at once. This is stated in the docs and the function doc. Inside the running application (tests, any in-app caller) the pages are disconnected.

Migration and existing tokens

No migration. After deploy, tokens already in users_tokens have context session and keep the 14 days they were given, including sessions that came from single sign-on before the upgrade. Only new single sign-on sign-ins get the short life. To remove an existing person now, run sign_out_user for them. It is safe on a running system: it only deletes rows.

Tests

Accounts (OIDC token accepted at 11 hours and refused at 13, by moving inserted_at; password token unaffected at 13 hours and refused at 15 days; delete all returns the count, disconnects and keeps other users and non-session tokens), release task (known and unknown address), runtime config validation (valid 1, 12, 336; invalid 0, 337, -1, 12h, text), and UserAuth (OIDC login makes an oidc_session token that is refused after the limit; password session unaffected). The UserAuth tests are tagged :integration, so CI runs them; they did not run locally.

Not merged. Not deployed.

🤖 Generated with Claude Code

https://claude.ai/code/session_01DnYzaTxC2GmdSpvCNyHNne

A person disabled at the identity provider kept a valid Salt session for up to 14 days. This limits sessions that came from single sign-on and adds an operator command to end one person's sessions. ## What changes - **`SALT_DNS_OIDC_SESSION_HOURS`** (default 12, whole number 1 to 336). A session that began with single sign-on is valid for that many hours. After that the next request is signed out and the normal sign-in follows. An invalid value stops the boot with a clear message (same check as the neighbouring settings). Password sessions keep 14 days. - **`Accounts.delete_all_user_session_tokens/1`** deletes every session token of a user (password and single sign-on), disconnects their open pages, and returns how many tokens it removed. - **`SaltDns.Release.sign_out_user(email)`** for operators. Prints the count. An unknown address prints a clear message and changes nothing (returns `{:error, :not_found}`, no crash). Documented in `docs/operations.md`, "Ending a person's sessions". - Docs: `docs/configuration.md` (new row), `docs/operations.md` (session life and the provider case; there is no security page, so it sits next to the command), CHANGELOG. ## Design: how single sign-on sessions are marked A distinct token context, `oidc_session`, next to the existing `session`. Chosen over a nullable column because it needs no migration and no backfill, the verify query stays one indexed lookup, and the two lives are visibly separate rows. Existing code that deletes tokens by user (password change, magic link) already deletes every context. The OIDC callback passes `method: :oidc` through `UserAuth.log_in_user/4` to `generate_user_session_token/2`. Reissue: `UserAuth` makes a fresh token for a session older than 7 days. A new "session" token would have restarted the clock and defeated the limit (reachable when the setting is above 168 hours). Single sign-on sessions are therefore never reissued; the person signs in again at the limit. ## Sockets that are already connected Not enforced, and I did not build anything for it. `on_mount` checks the token once, at mount. There is no periodic check in the shared hooks (the existing timers are per-page refreshes), and a socket only re-checks when it reconnects or the page is loaded again. So an open page can outlive the limit until then. Reaching it cleanly would need a timer in every LiveView or a hook with `attach_hook` plus `Process.send_after` in every live_session. I judged that elaborate and left it for the maintainers to decide. Related: `sign_out_user` runs in a separate Erlang VM under `bin/salt_dns eval`, where the application's PubSub is not running, so it cannot disconnect open pages. It deletes the tokens; open pages end at their next load or reconnect, and restarting the application cuts them at once. This is stated in the docs and the function doc. Inside the running application (tests, any in-app caller) the pages are disconnected. ## Migration and existing tokens No migration. After deploy, tokens already in `users_tokens` have context `session` and keep the 14 days they were given, including sessions that came from single sign-on before the upgrade. Only new single sign-on sign-ins get the short life. To remove an existing person now, run `sign_out_user` for them. It is safe on a running system: it only deletes rows. ## Tests Accounts (OIDC token accepted at 11 hours and refused at 13, by moving `inserted_at`; password token unaffected at 13 hours and refused at 15 days; delete all returns the count, disconnects and keeps other users and non-session tokens), release task (known and unknown address), runtime config validation (valid 1, 12, 336; invalid 0, 337, -1, 12h, text), and `UserAuth` (OIDC login makes an `oidc_session` token that is refused after the limit; password session unaffected). The `UserAuth` tests are tagged `:integration`, so CI runs them; they did not run locally. Not merged. Not deployed. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01DnYzaTxC2GmdSpvCNyHNne
End single sign-on sessions after a set time; command to end a person's sessions
Some checks failed
ci/woodpecker/pr/image Pipeline was successful
ci/woodpecker/pr/quality Pipeline failed
ci/woodpecker/pr/integration unknown status
54ae9233bd
Sessions that begin with the identity provider get their own token context
(oidc_session) and last SALT_DNS_OIDC_SESSION_HOURS (default 12, 1 to 336).
They are never reissued. Password sessions keep 14 days.
Accounts.delete_all_user_session_tokens/1 and SaltDns.Release.sign_out_user/1
end every session of one person.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DnYzaTxC2GmdSpvCNyHNne
Merge remote-tracking branch 'origin/master' into oidc-session-limit
Some checks failed
ci/woodpecker/pr/image Pipeline was successful
ci/woodpecker/pr/quality Pipeline was successful
ci/woodpecker/pr/integration Pipeline failed
30fe667d24
# Conflicts:
#	CHANGELOG.md
Test: a signed-out request has no scope at all
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
af733b172e
The expired single sign-on session leaves current_scope nil, as for any
signed-out request; the assertion looked for a user inside it.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DnYzaTxC2GmdSpvCNyHNne
calvin merged commit b747121842 into master 2026-11-14 20:23:35 +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!78
No description provided.