Repository navigation
Commit 6fcabb0
authored
refactor(auth)!: one session-revocation service, and the duplicate session revoke commands are gone (#606)
Part of #544. Builds on #562, now merged.
Signing an account's sessions out was implemented twice. The admin
dashboard and `auth-service session revoke|revoke-all` went through
`AdminService::revoke_session` and `revoke_user_sessions`. The settings
and `auth-service account <user> sessions revoke|revoke-all` went
through `AccountService::revoke_session` and `revoke_other_sessions`.
The CLI offered both pairs of commands.
Now the account service is the only one. The dashboard's **Revoke** and
**Revoke all** pages call it with an operator `Subject`, as the CLI's
`account` commands already do. The removed code:
- `AdminService::revoke_session` and `revoke_user_sessions`.
- `AdminOperation::RevokeSession` and `RevokeUserSessions`. The
dashboard now mounts its two session pages directly, next to the other
settings pages it shares with owners.
- `AdminError::SessionNotFound`.
- `cli/session.rs` and its `session revoke` and `session revoke-all`
commands.
The owner decided this behaviour. The account path's behaviour is the
one kept.
### Visible changes
- **Removed commands:** `auth-service session revoke` and `auth-service
session revoke-all`. Use `auth-service account <user> sessions revoke
<session>` and `auth-service account <user> sessions revoke-all`. They
take the same `--reason`, and `revoke-all` the same `--yes`. On success
the account commands print their own messages: "Signed session … of …
out." and "Signed … out of N sessions.". The CLI reference is
regenerated and loses only the `session` sections.
- **Refusal for an unknown session:**
- Dashboard: the form said "no active session has this ID". It now says
"You have no such session; it may already be signed out.". The status is
still 404.
- CLI: `session revoke` printed "no active session has this ID".
`account … sessions revoke` prints "session not found".
- **Which error wins:** when a dashboard revocation of one session finds
no active session, the administrator's rights, session and passkey
confirmation are now checked first. If they lapsed, the page hands off
to sign-in instead of refusing with "not found". Before, "not found" won
without that check.
- **Expired sessions:** revoking one expired session from the dashboard
now commits its refresh grants as revoked (#562's intent), then refuses
with "not found". Before, the admin path rolled that back. Expired
grants no longer refresh either way, so only the stored `revoked_at`
differs.
- **Dropped log lines:** the dashboard no longer logs `admin dashboard
request refused` for these two refusals. The responses are the same.
- `admin.failure=session_not_found`, when **Revoke** names no active
session of the account.
- `admin.failure=database`, when the database fails while beginning,
revoking or committing during **Revoke** or **Revoke all**. A database
failure in the operator's own checks is still logged.
The dashboard's other shared settings pages already refuse
account-service errors without this line.
Unchanged: the domain events (`SessionRevoked` per session, with
`RevocationReason::Admin`, attributed to the operator with their
reason), the lock order (`Operator::lock`, then the revocation, then
`Operator::authorize`), one transaction per revocation, the dashboard's
pages, their markup and their paths.
### How I checked the rest is unchanged
- Read both paths side by side on #562. Revoke-all made the same calls
in the same order: `Operator::lock`, then
`revoke_sessions(operator.context(reason), user, All, Admin)`, then
`authorize`, then commit.
- Diffed `docs/dev/operations/cli-commands.md` before and after: it only
loses the `session` sections.
- `every_change_to_an_account_shows_its_reason_to_the_owner` now revokes
through `AccountService` with an operator `Subject`, and still checks
that the owner's history shows both reasons.
**Proof:** `just db test` passed with only `keys::` skipped. The 13
`keys::` tests passed alone; one had timed out under load, which is
#590. Then the dashboard, `cli::tests` and account-reason tests ran
against a scratch database, 50 of 50, including the new dashboard test.
CI is green.
### Tests
- Changed
`admin::tests::accounts::every_change_to_an_account_shows_its_reason_to_the_owner`:
it revokes through the account service, and its assertions are
unchanged.
- Added `web::admin::tests::sessions_are_revoked_from_the_dashboard`:
from an account's dashboard page, **Revoke** signs one session out and
**Revoke all** the rest. Each goes back to the account's page, and the
active sessions go from 2 to 1 to 0. Nothing covered the dashboard's
successful revocations before.
- Removed the `RevokeSession` and `RevokeUserSessions` arms from the
operation tables in `cli/tests.rs` and `admin/tests/reads.rs`, since
those operations no longer exist. `account … sessions revoke|revoke-all`
remain covered by the `AccountOperation` tables.
### Docs
- Updated `architecture/sessions.md`, `architecture/surfaces.md`,
`operations/administration.md` and `operations/incidents.md`. #553
already corrected the threat-model sentence on `main`, so this PR leaves
it alone.
- `surfaces.md` says the account page's **Revoke** and **Revoke all**
sign sessions out through the account service, from the dashboard's
reason page.
- The `just auth session` recipe is removed with the commands.
No files were edited outside the revocation paths.
## Council review
Rounds: 2
| Delegate | Round 1 | Round 2 |
| --- | --- | --- |
| GPT 6.1 Sol | 9/10 | 9/10 |
| Claude Opus 5.5 | 9/10 | 9.5/10 |
| Claude Fable 5.2 | 9/10 | 9/10 |
Round 1 found the unlisted `session_not_found` log line, `make` wrapping
admin errors in `AccountError`, and two docs sentences, all fixed. A
shared helper for the two `Subject::operator` lines was declined as out
of scope. Round 2's nits are fixed: the route comment and the database
log wording above. The threat-model sentence is left to #553's version.
> [!NOTE]
> Written by Claude Opus 5.5 in Claude Code, reviewed by GPT 6.1 Sol,
Claude Opus 5.5 and Claude Fable 5.2 (via T3 Code)
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->
**Admin service and error model (`apps/auth-service/src/admin/`)**
- Removes `AccountService`-adjacent admin methods `revoke_user_sessions`
and `revoke_session` from `service/accounts.rs`. Removes the `SessionId`
and `SessionScope` imports.
- Removes `AdminOperation::RevokeUserSessions` and
`AdminOperation::RevokeSession` from `operation.rs`.
- Removes `AdminError::SessionNotFound` from `error.rs`, including its
log-reason mapping and its not-found `ApiError` classification.
- Removes the two operations from `AdminOperation::read` in
`tests/reads.rs`.
**CLI (`apps/auth-service/src/cli/`)**
- Deletes `cli/session.rs`, which held the `session revoke` and `session
revoke-all` commands.
- Removes the `session` module and command from `cli/mod.rs`.
- Removes the matching invocation mappings from `cli/tests.rs`. The
`account <user> sessions` mappings remain.
**Web dashboard (`apps/auth-service/src/web/admin/`)**
- `mod.rs` registers `users::revoke_sessions` and
`users::revoke_session` as explicit routes. It removes both operations
from the generic account-action routing and the operation-to-page
mapping.
- `users.rs` changes `AccountChange::make` to return `Result<(),
Refusal>`. Session revocation now runs through `AccountService` with an
operator `Subject`. Other changes still use the admin service, and their
errors become refusals.
**Tests**
- `admin/tests/accounts.rs` builds an `AccountService` directly for
session-revocation cases. It passes an operator `Subject` that contains
the account ID, administrator, and reason.
- `web/admin/tests.rs` adds `sessions_are_revoked_from_the_dashboard`,
an ignored database-backed test. It revokes one session, then the rest,
and checks the redirects and the active-session count (2, 1, 0).
**Documentation (`docs/dev/`)**
- `architecture/sessions.md` removes the `revoke_session`,
`revoke_user_sessions`, and `session revoke*` callers. It adds
notification-email sign-out links to the `Session::end_all` cases.
- `architecture/surfaces.md` names the CLI command `account <user>
sessions revoke` for the cross-account not-found case. It states that
the dashboard's **Revoke** and **Revoke all** actions use the dashboard
reason page.
- `operations/administration.md` changes the documented commands to the
`account <handle> sessions` group.
- `operations/incidents.md` changes the runbook command to `auth-service
account <handle> sessions revoke-all`.
- `operations/cli-commands.md` removes the generated `auth-service
session` reference.
**Build recipes (`just/auth.just`)**
- Removes the `session *ARGS` recipe and its example comment.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->1 parent 915cff4 commit 6fcabb0
17 files changed
Lines changed: 86 additions & 251 deletions
File tree
- apps/auth-service/src
- admin
- service
- tests
- cli
- web/admin
- docs/dev
- architecture
- operations
- just
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | 34 | | |
38 | 35 | | |
39 | 36 | | |
| |||
233 | 230 | | |
234 | 231 | | |
235 | 232 | | |
236 | | - | |
237 | 233 | | |
238 | 234 | | |
239 | 235 | | |
| |||
329 | 325 | | |
330 | 326 | | |
331 | 327 | | |
332 | | - | |
333 | 328 | | |
334 | 329 | | |
335 | 330 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | 31 | | |
36 | 32 | | |
37 | 33 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
| 12 | + | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
| 20 | + | |
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| |||
319 | 319 | | |
320 | 320 | | |
321 | 321 | | |
322 | | - | |
323 | | - | |
324 | | - | |
325 | | - | |
326 | | - | |
327 | | - | |
328 | | - | |
329 | | - | |
330 | | - | |
331 | | - | |
332 | | - | |
333 | | - | |
334 | | - | |
335 | | - | |
336 | | - | |
337 | | - | |
338 | | - | |
339 | | - | |
340 | | - | |
341 | | - | |
342 | | - | |
343 | | - | |
344 | | - | |
345 | | - | |
346 | | - | |
347 | | - | |
348 | | - | |
349 | | - | |
350 | | - | |
351 | | - | |
352 | | - | |
353 | | - | |
354 | | - | |
355 | | - | |
356 | | - | |
357 | | - | |
358 | | - | |
359 | | - | |
360 | | - | |
361 | | - | |
362 | | - | |
363 | 322 | | |
364 | 323 | | |
365 | 324 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
| |||
136 | 137 | | |
137 | 138 | | |
138 | 139 | | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
146 | 144 | | |
147 | 145 | | |
148 | | - | |
149 | | - | |
| 146 | + | |
| 147 | + | |
150 | 148 | | |
151 | 149 | | |
152 | 150 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
116 | 116 | | |
117 | 117 | | |
118 | 118 | | |
119 | | - | |
120 | | - | |
121 | 119 | | |
122 | 120 | | |
123 | 121 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
39 | | - | |
40 | | - | |
41 | 39 | | |
42 | 40 | | |
43 | 41 | | |
| |||
60 | 58 | | |
61 | 59 | | |
62 | 60 | | |
63 | | - | |
64 | 61 | | |
65 | 62 | | |
66 | 63 | | |
| |||
116 | 113 | | |
117 | 114 | | |
118 | 115 | | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | 116 | | |
123 | 117 | | |
124 | 118 | | |
| |||
229 | 223 | | |
230 | 224 | | |
231 | 225 | | |
232 | | - | |
233 | | - | |
234 | | - | |
235 | | - | |
236 | 226 | | |
237 | 227 | | |
238 | 228 | | |
| |||
304 | 294 | | |
305 | 295 | | |
306 | 296 | | |
307 | | - | |
308 | 297 | | |
309 | 298 | | |
310 | 299 | | |
| |||
This file was deleted.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | 43 | | |
55 | 44 | | |
56 | 45 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
383 | 383 | | |
384 | 384 | | |
385 | 385 | | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
386 | 389 | | |
387 | 390 | | |
388 | 391 | | |
| |||
448 | 451 | | |
449 | 452 | | |
450 | 453 | | |
451 | | - | |
452 | | - | |
453 | 454 | | |
454 | 455 | | |
455 | 456 | | |
| |||
518 | 519 | | |
519 | 520 | | |
520 | 521 | | |
521 | | - | |
522 | | - | |
523 | 522 | | |
524 | 523 | | |
525 | 524 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2206 | 2206 | | |
2207 | 2207 | | |
2208 | 2208 | | |
| 2209 | + | |
| 2210 | + | |
| 2211 | + | |
| 2212 | + | |
| 2213 | + | |
| 2214 | + | |
| 2215 | + | |
| 2216 | + | |
| 2217 | + | |
| 2218 | + | |
| 2219 | + | |
| 2220 | + | |
| 2221 | + | |
| 2222 | + | |
| 2223 | + | |
| 2224 | + | |
| 2225 | + | |
| 2226 | + | |
| 2227 | + | |
| 2228 | + | |
| 2229 | + | |
| 2230 | + | |
| 2231 | + | |
| 2232 | + | |
| 2233 | + | |
| 2234 | + | |
| 2235 | + | |
| 2236 | + | |
| 2237 | + | |
| 2238 | + | |
| 2239 | + | |
| 2240 | + | |
| 2241 | + | |
| 2242 | + | |
| 2243 | + | |
2209 | 2244 | | |
2210 | 2245 | | |
2211 | 2246 | | |
| |||
0 commit comments