Repository navigation
Commit 601fac0
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
- apps/auth-service/src
- admin
- service
- cli
- deletion/export
- history
- passkey
- security
- sessions
- web
- admin
- auth
- settings
- crates
- common/src
- events
- notifications
- database
- .sqlx
- migrations
- src
- repositories
- ui/src
- admin
- settings
- docs
- dev
- architecture
- operations
- security
- user
- account
- your-data
- tests/browser
- screenshots
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| |||
124 | 124 | | |
125 | 125 | | |
126 | 126 | | |
127 | | - | |
128 | | - | |
129 | | - | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
130 | 132 | | |
131 | 133 | | |
132 | 134 | | |
| |||
145 | 147 | | |
146 | 148 | | |
147 | 149 | | |
148 | | - | |
149 | | - | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
150 | 161 | | |
151 | 162 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| |||
125 | 126 | | |
126 | 127 | | |
127 | 128 | | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
135 | 141 | | |
136 | 142 | | |
137 | 143 | | |
| |||
0 commit comments