Skip to content

Commit 601fac0

Browse files
authored
fix(auth): admin dashboard sessions end with administrator rights, time out, and show in history (#439)
Revoking an administrator's rights left their dashboard sessions in place, so granting the rights again revived old cookies. Dashboard sessions lasted 30 days, and reads accepted a passkey sign-in of any age. Dashboard sign-ins appeared nowhere but the data export. Also, when a dashboard session ended, auth's handoff page signed the browser back in without asking for anything. So an unlocked laptop kept its dashboard. Now a dashboard session ends with the rights that opened it. It also ends after 30 minutes without a request, or 12 hours after sign-in. Every sign-in asks for the administrator's passkey. Sign-ins and sign-outs show in the administrator's own history, and their Devices page lists them. ## What changes - **Sign-in asks for a passkey every time.** Auth's handoff page always runs its passkey ceremony, and that proof confirms the dashboard for its first five minutes. The handoff no longer has a silent path, and `hand_off` takes an `AdminProof`, not an `Option`. The page checks rights and passkey sign-in first, so anyone else is still told they have no access before being asked. - **Timeouts.** Migration `0039` adds `last_used_at` and `expires_at` to `dashboard_sessions`. `DashboardRepository::use_session` refreshes `last_used_at` on each request, and refuses a session that has been idle for 30 minutes or is past `expires_at`. The cookie lasts 12 hours, and cleanup deletes expired rows. The limits are `DASHBOARD_IDLE_MINUTES` and `DASHBOARD_LIFETIME_HOURS` in `security/mod.rs`. - **Revocation ends the sessions.** `revoke_administrator` deletes the account's dashboard sessions and pending handoffs in the same transaction, and records a `dashboard_signed_out` for each one still in use. Creating and redeeming a handoff share-lock the rights, so a sign-in racing a revocation either commits first and is ended by it, or is refused. - **History.** New `DashboardSignedIn` and `DashboardSignedOut` events show as "Signed in to / Signed out of the admin dashboard", and can be reported as not yours. A session that times out records nothing, like an expired auth session. The dashboard's passkey proofs, on its own page and on auth's handoff page, now record `passkey_confirmed`. - **Every surface lists them.** Dashboard sessions nest under the auth session they rest on: - the Devices page ("Admin dashboard · Active 4 minutes ago") - the account API and `account sessions` at the terminal - the dashboard's user page, and `user show` - the data export, which moves to version 3: `dashboard_sessions` moves from the top level into each session, with when it was last used and when it ends. - **Docs:** `surfaces.md`, `sessions.md`, `administration.md` and `security/properties.md`, and the user guide's Devices and export pages. ## Deploying - The migration only adds columns with defaults, so the previous release keeps inserting sessions. - A handoff without a proof, as the previous release makes, never redeems. You chose to break the keep-the-previous-release-working rule here: during the deploy, a dashboard sign-in that reaches an old replica fails, and works when tried again. ## Overlap - The migration is `0041`, after main's `0039` and `0040`. - #417 and #423 both edit `web/admin/mod.rs` and `ui/admin/mod.rs`. The edits are in different places: the alerts and status bar there, the handoff here. - #258 (reasons) touches `admin/service/access.rs`. This PR adds only to the end of `revoke_administrator`. - #387 rewrites the dashboard's script in Rust. This PR doesn't touch the script. ## Proof - **Re-granting revives nothing:** `the_dashboard_ends_with_the_auth_session_and_the_rights`. - **An idle session expires:** `an_idle_dashboard_session_expires` checks that 29 minutes idle still works, that each request counts, and that 31 minutes doesn't. - **Sign-in is recorded:** `signing_in_asks_auth_for_a_passkey_once`. - **Races:** `a_sign_in_racing_a_revocation_never_outlives_it` covers both lock orders. Its sign-in-first case stands in for the redemption with the same lock and insert, since a real one can't be paused mid-transaction. - **Unit and database tests:** the dashboard, export, admin, passkey, history, settings, common, UI and repository tests pass, with clippy, fmt and the SQLx cache. - **On a preview:** - `tests/browser/admin.spec.ts` passed 6 of 8. The other 2 need `E2E_INVITE` or a mail catcher. - The announcement test moves the page's clock past the sign-in's confirmation, so the in-page passkey dialog keeps its coverage. - Checked by hand: the dashboard cookie lasts 12 hours, Devices shows "Admin dashboard · Active now" under the session, and history shows the sign-in and sign-out. - **Not tested:** an old-style handoff without a proof. The repository can no longer write one, so the `confirmed_at IS NOT NULL` filter and its typed `confirmed_at!` have no direct test. Reviewed by GPT 6.1 Sol, which found two problems, both now fixed and re-checked: - A sign-in redeemed during a revocation could survive it (reproduced on PostgreSQL). - Mixed replicas during a deploy could hand off without a passkey: such a handoff now never redeems. Closes #259 Reviewed with review-loop: 1 round with 2× GPT 6.1 Sol and Claude Opus 5.5. Verdict: approved > [!NOTE] > Written by Claude Opus 5.5 in Claude Code and reviewed by GPT 6.1 Sol (via T3 Code) 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary This change adds bounded, passkey-protected administrator dashboard sessions. It also ends those sessions when the administrator loses access and makes dashboard activity visible in account history and session views. ### Dashboard sign-in and session lifecycle - Require a passkey handoff for every dashboard sign-in. Bind the proof to the administrator’s active authentication session and require proof when redeeming the handoff. - Limit dashboard sessions to 12 hours after sign-in and end them after 30 minutes without a request. Requests update the last-used time. Dashboard access checks both limits and the status of the parent authentication session. - When administrator rights are revoked, delete the user’s dashboard sessions and pending handoffs in the same transaction. Coordinate handoff creation and redemption with rights changes so a racing sign-in cannot survive revocation. - Add database fields and indexes for dashboard session use and expiry. Extend maintenance cleanup to remove expired dashboard sessions. ### History and session views - Record dashboard sign-ins and explicit sign-outs in administrator security history. Timeouts do not create sign-out events. - Show dashboard sessions under their parent authentication sessions in the Devices page, account and user interfaces, and CLI output. - Change account export to version 3 and nest dashboard session details under each authentication session. ### Related updates - Update passkey confirmation handling, dashboard cookie lifetime, handoff and session documentation, and browser test flows. - Add tests for idle expiry, rights revocation and re-granting, sign-in races with revocation, passkey handoff requirements, and history events. ### Verification The supplied PR description reports that unit and database tests, clippy, formatting, and the SQLx cache passed. It reports that 6 of 8 admin browser tests passed on a preview; the other two require `E2E_INVITE` or a mail catcher. It also reports manual checks of cookie duration, Devices display, and history. Old-style handoffs without proof were not tested. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 2e47871 commit 601fac0

52 files changed

Lines changed: 1167 additions & 513 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/auth-service/src/admin/service/access.rs‎

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use super::AdminService;
55
use crate::{
66
account::AccountService,
7-
admin::{AdminError, InviteExpiry, Operator},
7+
admin::{AdminError, DashboardSignIn, InviteExpiry, Operator},
88
routes,
99
};
1010
use chrono::Utc;
@@ -124,9 +124,11 @@ impl AdminService {
124124
Self::finish(tx, operator, Some(user_id), vec![granted]).await
125125
}
126126

127-
/// Removes the administrator rights of `user_id`. Administrators cannot remove
128-
/// their own, and nobody can remove the last active administrator's: someone
129-
/// must be left to administer.
127+
/// Removes the administrator rights of `user_id`, and ends its dashboard
128+
/// sessions with them, and the handoffs that would start one: rights granted
129+
/// again later revive none. Administrators cannot remove their own, and
130+
/// nobody can remove the last active administrator's: someone must be left
131+
/// to administer.
130132
///
131133
/// # Errors
132134
/// Fails when the operator may not make changes, the account is not an
@@ -145,7 +147,16 @@ impl AdminService {
145147
if !tx.administrators().revoke(user_id).await? {
146148
return Err(AdminError::NotAnAdministrator);
147149
}
148-
let revoked = DomainEvent::AdministratorRevoked {};
149-
Self::finish(tx, operator, Some(user_id), vec![revoked]).await
150+
let ended = tx
151+
.dashboard()
152+
.end_of_user(user_id, DashboardSignIn::idle_since())
153+
.await?;
154+
let signed_out = ended
155+
.into_iter()
156+
.map(|session_id| DomainEvent::DashboardSignedOut { session_id });
157+
let events = std::iter::once(DomainEvent::AdministratorRevoked {})
158+
.chain(signed_out)
159+
.collect();
160+
Self::finish(tx, operator, Some(user_id), events).await
150161
}
151162
}

‎apps/auth-service/src/admin/service/accounts.rs‎

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@
33
44
use super::AdminService;
55
use crate::{
6-
admin::{AdminError, HandleProblem, Operator, Reason, UserRef},
6+
admin::{AdminError, DashboardSignIn, HandleProblem, Operator, Reason, UserRef},
77
deletion::Deletions,
88
handles::Handles,
99
security::Session,
1010
};
1111
use sourceorigin_common::{
1212
AccountStatus, Handle, HandleError, Personal, SessionId, UserId,
1313
admin::{
14-
Email, Paging, ReleasedHandle, ReservedHandle, ScheduledDeletion, UserDetail, UserPage,
14+
DashboardSession, Email, Paging, ReleasedHandle, ReservedHandle, ScheduledDeletion,
15+
UserDetail, UserPage,
1516
},
1617
email::NormalizedEmail,
1718
events::{DomainEvent, EventContext, RevocationReason},
@@ -125,13 +126,18 @@ impl AdminService {
125126
.collect(),
126127
passkeys: Self::views(tx.passkeys().list_active(user_id).await?),
127128
identities: Self::views(tx.federation().list_active(user_id).await?),
128-
sessions: tx
129-
.sessions()
130-
.list_active_for_user(user_id)
131-
.await?
132-
.into_iter()
133-
.map(Into::into)
134-
.collect(),
129+
sessions: {
130+
let dashboard = (tx.dashboard())
131+
.of_user(user_id, DashboardSignIn::idle_since())
132+
.await?;
133+
(tx.sessions().list_active_for_user(user_id).await?)
134+
.into_iter()
135+
.map(|session| sourceorigin_common::admin::Session {
136+
dashboard: DashboardSession::on(&dashboard, session.id),
137+
..session.into()
138+
})
139+
.collect()
140+
},
135141
consents: tx.oidc().list_consents(user_id).await?,
136142
deletion: match tx.deletions().find(user_id).await? {
137143
Some(deletion) => Some(ScheduledDeletion {

0 commit comments

Comments
 (0)