Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions docs/SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -1667,30 +1667,32 @@ tuple: they act only on the caller's own account.
| `DELETE` | `/roles/custom/{role_id}` | `users:manage` | `require_step_up_action` (action `save_ends_own_sessions`) **only when the save would end the caller's own sessions**, else the session window (BACKLOG #3401) |
| `GET` | `/users` | `users:read` | `require`. Each account's record is checked against its integrity seal (BACKLOG #5520); one that fails is listed by its `id` alone, with `integrity_failed: true` (`IntegrityFailedUser`). What that reports: *What an admin user read reports* below this table |
| `GET` | `/users/{user_id}/permissions` | `users:read` | `require` — the effective-permission inspector. The account is read with its record checked against its integrity seal (BACKLOG #5520): 423 when the record fails it, with nothing of the row answered. What the 423 reports, and when a row read mid-write is not refused: *What an admin user read reports* below this table; 404 for an unknown user |
| `POST` | `/users` | `users:manage` | `require_step_up`. Refuses (422) a `username` the new-username rule refuses, before anything is generated or written (BACKLOG #5521). The rule, and what it admits, is stated once, in the docstring of `messagefoundry/auth/usernames.py`; the service refuses the same name 400 for a caller that skips the request model. `provision-admin`, `POST /users/directory` and an AD sign-in that creates its account do not apply this rule |
| `POST` | `/users` | `users:manage` | `require_step_up`. Refuses (422) a `username` the new-username rule refuses, before anything is generated or written (BACKLOG #5521). The rule, and what it admits, is stated once, in the docstring of `messagefoundry/auth/usernames.py`; the service refuses the same name 400 for a caller that skips the request model. Which other paths write a username without this rule is stated there too |
| `POST` | `/users/directory` | `users:manage` | `require_step_up`. Creates a directory (AD) account's mirror row by name, without a sign-in (BACKLOG #2021). The row's `objectGUID`, display name and `mail` come from a service-account directory lookup, never from the request: the body carries `username` and an optional `notify_email`, and an unknown key is refused 422. The row is never born without a notification address: the directory's `mail` is it when BACKLOG #2014's rule adopts it, and `notify_email` is then refused; otherwise `notify_email` is required and checked as `POST /users` checks `email` (400). 404 when the directory has no enabled account by that name, 400 when it returns no readable `objectGUID`, 409 when a row already holds the name or id, 503 when the directory cannot be reached. No roles: they come from the AD-group map at sign-in |
| `PATCH` | `/users/{user_id}` | `users:manage` | `require_step_up_action` (action `admin_user_update`). The account is read with its record checked against its integrity seal (BACKLOG #5520): 423 when the record fails it, with nothing of the row answered. What the 423 reports, and when a row read mid-write is not refused: *What an admin user read reports* below this table; 404 for an unknown user |
| `DELETE` | `/users/{user_id}` | `users:manage` | `require_step_up` |
| `DELETE` | `/users/{user_id}/sessions` | `users:manage` | `require_step_up`; **refuses (400) when `user_id` is the caller's own** (BACKLOG #1149) -- end your own from `DELETE /me/sessions` and sign-out instead |
| `DELETE` | `/sessions` | `users:manage` | `require_step_up_action` (action `revoke_all_sessions`). Ends the sessions it finds and keeps the caller's current session, except at least when that session's seal fails, when it is ended too, and when the revoke declines to re-stamp it, because an earlier revoke's sweep missed it or its account's record fails its seal, when the revoke ends it in the same transaction (BACKLOG #4975 and its follow-up). Whether it kept that session, in the reply and in the audit row's scope, is the store's answer from the revoke's own transaction, not a read made after it (BACKLOG #4975). Writes one `auth.session_revoked` row with the count, even a zero (BACKLOG #2614); the count includes the caller's own session wherever the call ended it. What it may miss: *Limits of the session sweep* under [Federated sign-in](#federated-sign-in-oidc-browser-only--adr-0142). `messagefoundry admin-revoke-sessions` is the same act from the host, for when the API is not trusted |
| `PUT` | `/users/{user_id}/roles` | `users:manage` | `require_step_up`; **refuses (400) when `user_id` is the caller's own** (BACKLOG #1149) |
| `POST` | `/users/{user_id}/reset-password` | `users:manage` | `require_step_up_action` (action `admin_reset_password`) |
| `PUT` | `/users/{user_id}/roles` | `users:manage` | `require_step_up`; **refuses (400) when `user_id` is the caller's own** (BACKLOG #1149). The account is read with its record checked against its integrity seal (BACKLOG #5520): 423 when the record fails it, with nothing of the row answered. What the 423 reports, and when a row read mid-write is not refused: *What an admin user read reports* below this table; 404 for an unknown user |
| `POST` | `/users/{user_id}/reset-password` | `users:manage` | `require_step_up_action` (action `admin_reset_password`). The account is read with its record checked against its integrity seal (BACKLOG #5520): 423 when the record fails it, with nothing of the row answered. What the 423 reports, and when a row read mid-write is not refused: *What an admin user read reports* below this table; 404 for an unknown user |
| `GET` | `/users/{user_id}/federated-identity` | `users:manage` | `require` (a read on the `users:manage` tier, like `GET /users/{user_id}/channel-scope`). The account's stored `issuer`/`subject`, the issuer a bind would use, and whether the account carries its directory id: the pair the console's federated-identity screen shows, for a JSON caller to send back as `expected_issuer`/`expected_subject` (BACKLOG #2331). No step-up, so it spends no grant. Audited as every satisfied route is, by its `auth.permission_granted` row, as the channel-scope read is. The console page of the same pair asks for the step-up window, because it also offers the link and unlink forms. 404 for an unknown user. The account is read with its record checked against its integrity seal (BACKLOG #5520): 423 when the record fails it, with nothing of the row answered. What the 423 reports, and when a row read mid-write is not refused: *What an admin user read reports* below this table |
| `PUT` | `/users/{user_id}/federated-identity` | `users:manage` | `require_step_up_action` (action `admin_federated_identity`). Binds the account to an IdP `sub` under the configured `[auth].oidc_issuer`, or rebinds it; either one revokes every live session of the account, in the same transaction as the write (vault BACKLOG #2609). **The only path that creates a federated binding** (ADR 0184, BACKLOG #1143): a federated login never binds, and an unbound one is refused. Directory (AD) accounts only, and only one that carries its immutable directory id (`users.directory_object_id`, the `objectGUID`): 400 `directory_object_id_missing` otherwise, audited as `auth.federated_bind_refused` (BACKLOG #1143 slice C). A local account is refused 400 too, audited with reason `not_a_directory_account` (BACKLOG #3174). 409 when another account holds the identity, audited with reason `federated_subject_held` (BACKLOG #3174), and 409 `federated_binding_changed` when the account no longer holds the body's required `expected_issuer`/`expected_subject`, the pair the caller saw (BACKLOG #2026), also audited as `auth.federated_bind_refused`, with reason `federated_binding_changed`, the expected pair (BACKLOG #2331), and the pair the row held as `held_issuer`/`held_subject` wherever the refusal read it (BACKLOG #3174). 404 for an unknown user, including one deleted while the bind ran (BACKLOG #2331). A rebind is still a clear then a separate set: if another bind lands between them the rebind is refused 409 without that code, and its clear has already removed the old binding, audited as `auth.federated_subject_unbound`. The refusal itself is audited as `auth.federated_bind_refused` with reason `account_bound_concurrently`; that row and the `federated_subject_held` one carry `previous_binding_removed`, which says whether this request's clear had removed a binding first (BACKLOG #3174). **A bound account is refused Windows SSO from then on**, whether or not `oidc_enabled` is on (vault BACKLOG #2609; [Federated sign-in](#federated-sign-in-oidc-browser-only--adr-0142) has the limits) |
| `DELETE` | `/users/{user_id}/federated-identity` | `users:manage` | `require_step_up_action` (action `admin_federated_identity`). Removes the binding and revokes the account's sessions (BACKLOG #1474's service method); its next federated login is refused until it is bound again. The body's required `expected_issuer`/`expected_subject` is the pair the caller saw: a stored pair that differs is refused 409 `federated_binding_changed` with nothing changed, compared under the clear's row lock (BACKLOG #2026). That refusal writes an `auth.federated_unbind_refused` audit row naming the actor, with reason `federated_binding_changed` and the expected pair (BACKLOG #2331) |
| `POST` | `/users/{user_id}/reset-mfa` | `users:manage` | `require_step_up_action` (action `admin_reset_mfa`); **refuses (400) when `user_id` is the caller's own** — use the self-service MFA settings instead. Targeting yourself here was a third route to zero factors that skipped the last-factor refusal both self-service paths make (BACKLOG #1022). Cross-user reset is untouched: it is the always-available recovery for a locked-out passkey user (ADR 0068 §2) |
| `POST` | `/users/{user_id}/enrolment-code` | `users:manage` | `require_step_up_action` (action `admin_enrolment_code_issue`). Issues a directory account's single-use enrolment code, returned once and `no-store` ([Directory-account enrolment codes](#directory-account-enrolment-codes-adr-0207), ADR 0207). **Refuses (400) the caller's own account**, a local account, an account holding a factor and a disabled account; 404 for an unknown one |
| `DELETE` | `/users/{user_id}/enrolment-code` | `users:manage` | `require_step_up_action` (action `admin_enrolment_code_revoke`). Clears an outstanding code; `revoked` says whether one was. Refuses (400) the caller's own account; 404 for an unknown one |
| `GET` | `/users/{user_id}/channel-scope` | `users:manage` | `require` (a read on the `users:manage` tier, not `users:read`). The account is read with its record checked against its integrity seal (BACKLOG #5520): 423 when the record fails it, with nothing of the row answered. What the 423 reports, and when a row read mid-write is not refused: *What an admin user read reports* below this table; 404 for an unknown user |
| `PUT` | `/users/{user_id}/channel-scope` | `users:manage` | `require_step_up`; **refuses (400) when `user_id` is the caller's own** (BACKLOG #1149) |
| `PUT` | `/users/{user_id}/channel-scope` | `users:manage` | `require_step_up`; **refuses (400) when `user_id` is the caller's own** (BACKLOG #1149). The account is read with its record checked against its integrity seal (BACKLOG #5520): 423 when the record fails it, with nothing of the row answered. What the 423 reports, and when a row read mid-write is not refused: *What an admin user read reports* below this table; 404 for an unknown user |
| `GET` | `/ad-group-map` | `users:manage` | `require` |
| `PUT` | `/ad-group-map` | `users:manage` | `require_step_up_action` (action `save_ends_own_sessions`) **only when the save would end the caller's own sessions**, else the session window (BACKLOG #3401) |
| `GET` | `/ad-group-scope-map` | `users:manage` | `require` |
| `PUT` | `/ad-group-scope-map` | `users:manage` | `require_step_up_action` (action `save_ends_own_sessions`) **only when the save would end the caller's own sessions**, else the session window (BACKLOG #3401) |

**What an admin user read reports (BACKLOG #5520).** At least these read each account with its whole
record checked against its integrity seal: `GET /users`, `GET /users/{user_id}/permissions`,
`PATCH /users/{user_id}`, `GET /users/{user_id}/federated-identity` and `GET /users/{user_id}/channel-scope`;
`PATCH /users/{user_id}`, `PUT /users/{user_id}/roles`, `POST /users/{user_id}/reset-password`,
`GET /users/{user_id}/federated-identity`, `GET /users/{user_id}/channel-scope` and
`PUT /users/{user_id}/channel-scope`;
and in the web console (BACKLOG #5559) at least these. `GET /ui/users` answers 200 and lists a
failing account by its id alone; to a caller holding `users:manage` it links that account's
delete to `GET /ui/users/{user_id}/delete-confirm`, which, for a record its checked read refuses
Expand Down Expand Up @@ -1730,12 +1732,19 @@ or federated pair cannot make it vanish from these reads. One that keeps changin
unreported. Honest writes that race all three checks the same way would be a false alarm
too. **Two honest role writes to the account that commit across both of those reads
are still answered as a failing record and reported**, a false alarm the reads cannot tell from
tampering, because the role rows are read apart from the account's row. Where
tampering, because the role rows are read apart from the account's row. Since BACKLOG #5520,
`PUT /users/{user_id}/roles`, and the console's `POST /ui/users/{user_id}/roles` that calls it,
read the account this way before they write, so that false alarm there refuses the role change
with the 423 (the console shows its text on a 400 page) and is reported as above. Before, a local
account's role write went ahead in that case, and a directory account's was refused 400: an
over-refusal, kept by decision d20261123T150929936-d70a0b. Where
`[auth].require_action_step_up` is on, the default, `PATCH /users/{user_id}` reads the account
after its gate has spent the single-use `admin_user_update` grant, so its 423 and its 404 cost that
proof, as the console's `POST /ui/users/{user_id}/update` does after its own gate. So does its 422
for a changed display name the name rule refuses (BACKLOG #5784), which the route checks against
the stored name after that read. Where it is
the stored name after that read. `POST /users/{user_id}/reset-password` reads the account after
its gate has spent the single-use `admin_reset_password` grant, so its 423, its 404 and the 503 its
checked read answers for a Vault transit outage cost that proof too. Where it is
off, the gate checks the step-up session window instead and spends nothing, so none of these
answers costs a proof. On a `vault_transit` store (ADR 0217), a record Vault transit cannot verify is
answered the same way as a failing record, but reported under
Expand Down
16 changes: 10 additions & 6 deletions messagefoundry/api/auth_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1807,28 +1807,26 @@ async def set_user_roles(
# the body model. A body that fails ``RolesUpdateRequest`` is answered first, with no audit
# row: FastAPI answers 422 on the JSON plane, and the console route that builds the model
# renders "invalid input" with a 400.
user = await service.store.get_user(user_id)
await _refuse_if_self(
request,
service,
identity,
user_id,
user,
op="set_roles",
detail="another administrator must change your own roles",
)
await _validate_roles(service, body.roles)
if user is None:
raise HTTPException(status.HTTP_404_NOT_FOUND, "no such user")
# BACKLOG #5520 items 2 and 13: the route decides on the record, so it reads it checked: a
# record that fails its seal answers the reads' 423, not the write's own 409.
user = await _checked_user(service, user_id)
if _externally_managed(user.auth_provider):
raise HTTPException(
status.HTTP_400_BAD_REQUEST, "AD users get roles from the AD-group map"
)
# BACKLOG #315: promotion mints an approver exactly as creation does, so it pages too. Only a
# GRANT pages: re-saving an existing Administrator's roles changes nothing.
granted = (
Role.ADMINISTRATOR.value in body.roles
and Role.ADMINISTRATOR.value not in await service.store.get_user_role_ids(user_id)
Role.ADMINISTRATOR.value in body.roles and Role.ADMINISTRATOR.value not in user.role_ids
)
try:
# The last-administrator guard is inside, in one store transaction with the role write
Expand Down Expand Up @@ -1877,6 +1875,9 @@ async def reset_user_password(
op="password_reset",
detail="use change-password for your own account",
)
# BACKLOG #5520 items 2 and 13: a record that fails its seal answers the reads' 423, not
# the service loader's 404. The service reads the account again before it writes.
await _checked_user(service, user_id)
try:
issued = await service.admin_reset_password(user_id, actor=identity.username)
except ValueError as exc:
Expand Down Expand Up @@ -2222,6 +2223,9 @@ async def set_channel_scope(
``ChannelScope`` is answered 422 by FastAPI before the guard runs, with no audit row; the
console route runs the guard before its own checks (BACKLOG #3393)."""
await _refuse_own_channel_scope(request, service, identity, user_id)
# BACKLOG #5520 items 2 and 13: as on the role write, a record that fails its seal answers
# the reads' 423, not the service loader's 404. The service reads it again to decide.
await _checked_user(service, user_id)
try:
await service.set_channel_scope(
user_id,
Expand Down
12 changes: 7 additions & 5 deletions messagefoundry/api/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,13 @@ def alert_sink_for(state: Any) -> AlertSink:
return sink if sink is not None else _FALLBACK_ALERT_SINK


#: ``granted_by`` on the ``administrator_granted`` alert a directory sign-in raises (vault BACKLOG
#: #2610): no administrator acted, the directory's group membership did. It is a fixed marker, styled
#: like the ``<kerberos>`` audit actor. ``POST /users`` refuses the name (``auth/usernames.py``), but
#: provision-admin and the directory create paths do not, so an account literally named
#: ``<directory>`` could read the same in this field; the alert's ``via`` names the route either way.
#: ``granted_by`` on the ``administrator_granted`` alert raised when the directory, not an
#: administrator, grants Administrator: a directory sign-in (vault BACKLOG #2610) and the directory
#: reconciler (``via=directory_reconcile``). It is a fixed marker, styled like the ``<kerberos>``
#: audit actor. The new-username rule's ``<...>`` form covers it; which paths apply that rule, and
#: what the rule still admits, ``auth/usernames.py`` states. An account named so by a path that skips
#: the rule, or spelled to render the same, could read the same in this field; the alert's ``via``
#: names the route either way.
DIRECTORY_GRANTED_BY = "<directory>"


Expand Down
Loading
Loading