feat(32.2-01): in-transaction BackendAccessRevokedEvent at every admin access change

- cabana: BackendAccessRevokedEvent with reasons deleted, deactivated,
  password_changed, password_set, password_reset and permissions, fired
  synchronously inside the save's transaction; a listener error rolls back
- fired on admin delete, deactivate, a password set by another admin, an own
  password change, admin:reset-password, a role/permissions/superuser change
  and a role's permission change (every holder); MCPSubjectChanged unchanged
- role delete fires nothing (refused while the role has holders); no sign
  out everywhere action exists
- smoke test TestBackendAccessRevokedSmoke (Postgres)
This commit is contained in:
Jakub Zych
2026-11-21 00:32:26 +01:00
parent 3f7ce6020d
commit fcc7bbde25
10 changed files with 270 additions and 8 deletions

View File

@@ -186,6 +186,10 @@ Administrators are deactivated, deleted and restored, never removed:
When a refused row is part of a bulk selection, the whole selection is rolled back and the refusal is shown.
#### What ends an administrator's OAuth grants
A plugin that issues OAuth grants acting as an administrator (an MCP connector the administrator signed in to, for example) listens for `cabana.BackendAccessRevokedEvent` and revokes those grants in the same transaction as the change. The event fires when the administrator is deleted or deactivated, when they change their own password on My account, when another administrator sets their password, when `admin:reset-password` resets it, and when their role, own permission overrides or superuser flag change, or the permissions of the role they hold change. A listener that fails rolls the save back, so the change never commits while the grants survive. Each connection can also be revoked one by one where the plugin lists it. The admin has no "sign out everywhere" action.
Setting the password of another administrator ends that administrator's sessions at once, as `admin:reset-password` does: tokens issued before the change are refused. Their personal API tokens keep working, exactly as after `admin:reset-password`; revoke them with `admin:token:revoke` when they should stop too.
### The Roles screen

View File

@@ -96,3 +96,13 @@ Here `acme.pages` listens at a higher priority, so it gets the first chance to c
## Events and transactions
Listeners run where the event is fired, inside any transaction the caller has open. A listener that writes to the database joins that transaction when it uses the transaction handle the event carries. A listener with a side effect outside the database, such as a mail or a broadcast, should defer it with `lagoon.AfterCommit`, so it does not announce a write that rolls back. See [Transactions](../database/transactions.md).
The framework fires these events of its own:
| Event | Fired by | When | Transaction |
|-------|----------|------|-------------|
| `cabana.BackendAccessRevokedEvent` | the admin | an administrator is deleted (`cabana.BackendAccessDeleted`) or deactivated (`cabana.BackendAccessDeactivated`), changes their own password on My account (`cabana.BackendAccessPasswordChanged`), gets a password set by another administrator (`cabana.BackendAccessPasswordSet`) or reset with `admin:reset-password` (`cabana.BackendAccessPasswordReset`), or their role, own permissions or superuser flag change, or the permissions of the role they hold (`cabana.BackendAccessPermissions`) | inside the save's transaction, before the commit, with `cabana.BackendAccessRevokedEvent.Tx` set; a listener's error rolls the save back |
| `pact.MCPSubjectChanged` | the admin, plugins | what a subject may do over MCP changed: permissions, a backend link, a revoked grant or token, a deleted or deactivated user | after the commit; a listener's error is logged and never fails the save |
| `pact.RecordSaved` | the admin | a record was created or updated on an admin screen | after the commit |
Listen for `cabana.BackendAccessRevokedEvent` to revoke what is keyed on an administrator, such as OAuth grants they consented to, atomically with the change: write through `cabana.BackendAccessRevokedEvent.Tx` and do not open a transaction of your own.