Skip to content

Commit 561fd68

Browse files
committed
docs: security pages and extending recipes match today's code
The recipes name Records, out.emit, SecretBytes::text, the channels' notified slice and Registered list, Google's endpoints and the provider credentials rule, and the migration example adds a column that doesn't exist yet. The security pages give the operator name's sources, every link the token digest key derives, where IPs live, the reasons every admin change needs, and the rate categories by link.
1 parent 71182aa commit 561fd68

11 files changed

Lines changed: 60 additions & 49 deletions

‎docs/dev/extending/account-setting.md‎

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ Then:
137137
`Picture::Remove { .. } => Op::RemovePicture`.
138138
2. Run it in `AccountCommand::run`: a change as `change.on(id, console)`, the
139139
operator's `Subject` with the `--reason` the `Change` flattens, and a read as
140-
`read()`, printed with `output.print`.
140+
`read()`, printed with `out.emit`.
141141
3. If it cuts off access, as removing a passkey does, flatten a `Confirm` into it.
142142

143143
## 6. Add it to the dashboard
@@ -159,18 +159,21 @@ let refused = App::submit(cx, form, App::here(cx), |posted| async move {
159159
Reads take `App::viewer(user, admin)`, and the page ends with
160160
`App::settings_page`. A new tab is mounted with `.route(settings::…)` in
161161
`AdminApplication::routes` (`web/admin/mod.rs`), and linked from
162-
`App::settings_tab` and from the account's page in `web/admin/users.rs`.
162+
the tab list in `App::settings_page` and from the account's page in
163+
`web/admin/users.rs`.
163164

164165
## 7. Add it to the data export
165166

166167
The owner downloads everything auth stores about their account, as
167168
`AccountExport` (`apps/auth-service/src/deletion/export/mod.rs`). If the setting
168169
stores something new:
169170

170-
1. Add a field to `AccountExport`, with a doc comment saying what it holds.
171-
2. Read it in `AccountExport::read`, from the export's transaction, so the export
172-
is one snapshot.
173-
3. Raise `VERSION`, and say what the version added in the struct's doc comment.
171+
1. Add a field to `Records`, the export's sections, with a doc comment saying
172+
what it holds.
173+
2. Read it where `AccountExport::read` builds `Records`, from the export's
174+
transaction, so the export is one snapshot.
175+
3. Raise `VERSION`, and say what the version added in `AccountExport`'s doc
176+
comment.
174177

175178
The export never holds a secret, a digest or key material.
176179

@@ -197,9 +200,9 @@ apart by its actor: see [adding a notification](notification.md).
197200
4. Test the settings page and the dashboard page, in
198201
`apps/auth-service/src/web/settings/tests.rs` and `web/admin/tests.rs`.
199202
5. If the export grew, add the new field to
200-
`serializes_every_category_in_its_documented_shape`
203+
`serializes_every_section_in_its_documented_shape`
201204
(`deletion/export/tests.rs`), which builds an export and checks each
202-
category's name and shape.
205+
section's name and shape.
203206

204207
```console
205208
just test -p auth-service

‎docs/dev/extending/configuration-variable.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ let budget: std::num::NonZeroU32 =
7878

7979
A secret is never set directly. Its variable holds a `SecretReference`, an
8080
`env://NAME` or `file:///path` that `resolve()` reads. Its bytes stay redacted;
81-
`utf8()` borrows them as text.
81+
`SecretBytes::text()` reads them as text, without one trailing line ending.
8282

8383
Reject a bad value with `variable.invalid(reason)`, or `variable.error(reason,
8484
source)` to keep the parser's error as its source. The reason says what the

‎docs/dev/extending/delivery-channel.md‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl Channel for BackchannelLogout {
5151
async fn deliveries(
5252
event: &DomainEvent,
5353
_: Option<UserId>,
54-
_: Option<&Notified>,
54+
_: &[Notified],
5555
tx: &mut DatabaseTransaction<'_>,
5656
) -> Result<Vec<NewDelivery<Self>>, DatabaseError> {
5757
let DomainEvent::SessionRevoked { session_id, .. } = event else {
@@ -66,8 +66,9 @@ impl Channel for BackchannelLogout {
6666
- `NAME` is stored in every row, so never rename a released channel.
6767
- `Recipient` holds the facts copied about the recipient, and `Payload` the
6868
message, both stored as JSON. Never store a plaintext secret in either.
69-
- `deliveries` receives the event, its subject, and the notification it just gave
70-
the subject, if any, which the `email` channel sends. It runs inside the
69+
- `deliveries` receives the event, its subject, and the notifications it just
70+
wrote, such as one per administrator for a raised alert, which the `email`
71+
channel sends. It runs inside the
7172
event's transaction, so it sees the rows as the change left them.
7273
- Each `NewDelivery` names its `destination`, an endpoint URL or an address.
7374

@@ -81,7 +82,7 @@ Add the channel to `Registered` in `deliveries/mod.rs`, a nested list that
8182
`DatabaseTransaction::record` fans every event out to:
8283

8384
```rust
84-
pub(crate) type Registered = (BackchannelLogout, (Email, (Announcement, (Witness, ()))));
85+
pub(crate) type Registered = (BackchannelLogout, (Email, (Announcement, (Invitation, ()))));
8586
```
8687

8788
A delivery that no event causes, such as a witness's checkpoint, is inserted

‎docs/dev/extending/federation-providers.md‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ Provider::GitLab => (GITLAB_CLIENT_ID, GITLAB_CLIENT_SECRET),
9494
```
9595

9696
`ProviderConfig::from_environment` already reads every provider's pair: an empty
97-
or unset client ID leaves the provider off, and a client ID requires the secret.
97+
client ID, or neither variable set, leaves the provider off, and setting either
98+
requires both.
9899
The doc comments are the variables' entries in the configuration reference, so
99100
write them for operators. See
100101
[adding a configuration variable](configuration-variable.md).
@@ -109,8 +110,8 @@ specific to the provider:
109110
- **`impl ProviderEndpoints`:** `pub(super) fn gitlab() -> Self`, with the issuer
110111
stored beside each subject, the authorization and token URLs, the scopes and
111112
the identity strategy. A provider whose facts need a request, such as Google's
112-
key cache, takes the client and may fail:
113-
`fn google(client: &reqwest::Client) -> Result<Self, FederationConfigError>`.
113+
key cache, builds its client with `FederationApplication::http_client()` and
114+
may fail: `fn google() -> Result<Self, FederationConfigError>`.
114115
- **`GitLabProtocol`:** the back-channel URLs the identity step calls, such as
115116
the key set or the profile endpoint. They are `String`s, so tests can point
116117
them at a local fixture.

‎docs/dev/extending/migration.md‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ Open the file with SQL comments that say what the migration changes, why, and
4040
why the previous release keeps working:
4141

4242
```sql
43-
-- The profile picture URL a provider reported with its evidence, so a social
44-
-- signup can import it once the account exists. Nullable: the previous release
45-
-- inserts evidence without one, and its signups import nothing.
46-
ALTER TABLE pending_federation
47-
ADD COLUMN picture_url TEXT CHECK (char_length(picture_url) <= 2048);
43+
-- The language an account's emails are written in, as a BCP 47 tag the owner
44+
-- picks in their settings. Nullable: the previous release creates accounts
45+
-- without one, and their emails stay in English.
46+
ALTER TABLE users
47+
ADD COLUMN locale TEXT CHECK (char_length(locale) <= 35);
4848
```
4949

5050
The comments are the migration's documentation; nothing else describes it.

‎docs/dev/extending/notification.md‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ emails. So adding one changes no page, route or job.
2323

2424
- Find the event the notification comes from. If the change records none yet,
2525
add one first: see [recording its event](admin-operation.md#3-record-its-event).
26-
- Decide who is told. Every notification is emailed, and none can be turned off,
27-
so notify only what the owner needs to know about their account. A change the
26+
- Decide who is told. A notification about the account is always emailed, and
27+
nobody can turn its email off, so notify only what the owner needs to know
28+
about their account. A change the
2829
owner made themselves usually tells them nothing new.
2930

3031
## 1. Add the kind
@@ -154,14 +155,13 @@ surface needs a change.
154155
offers more names it in `Notification::action`, which its page and its email
155156
both read: a recovery's undo page or the dashboard's Alerts tab. A new kind of
156157
action needs a `NotificationAction` variant, and each surface must say where
157-
it links: the notification page (`src/web/settings/notifications.rs`) and the
158-
email (`EmailSender::content`).
159-
- **During a deploy or a rollback.** The previous release's email workers may
160-
claim the email of a kind they don't know. They can't decode it, so they leave
161-
it pending for the new release, which sends it at the latest 30 seconds after
162-
the previous release stops. After a rollback to a release that doesn't know
163-
the kind, its emails wait, then fail at the email channel's 24-hour `MAX_AGE`.
164-
A release from before this behaviour marks them failed at once. Either way, an
165-
operator retries them with
158+
it links: the notification page
159+
(`apps/auth-service/src/web/settings/notifications.rs`) and the email
160+
(`EmailSender::content`).
161+
- **During a deploy or a rollback.** A release that doesn't know the kind can't
162+
decode its emails, and leaves them pending for one that does, until the email
163+
channel's 24-hour `MAX_AGE` fails them
164+
([life of a delivery](../architecture/delivery-queue.md#life-of-a-delivery)).
165+
An operator retries a failed one with
166166
`auth-service deliveries retry <id> --reason "…"` once a release that knows the
167-
kind serves again; see [the delivery queue](../architecture/delivery-queue.md#operations).
167+
kind serves again.

‎docs/dev/security/account-recovery.md‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ recovery-specific has to remember it.
3535

3636
The code is `apps/auth-service/src/recovery` (links, the probation passkey,
3737
undo), `AdminService::recover_account`, `recent_recoveries` and `undo_recovery`
38-
(`apps/auth-service/src/admin/service.rs`), the passkey routes
38+
(`apps/auth-service/src/admin/service/recovery.rs`), the passkey routes
3939
(`apps/auth-service/src/passkey`), the pages `/recover` and `/recover/undo`
4040
(`apps/auth-service/src/web/auth/recovery`, with their views in
4141
`crates/ui/src/recovery/mod.rs`), the account recoveries section of
@@ -336,7 +336,8 @@ on a disabled account (U4a)
336336
`oidc::tests::tokens::a_refresh_that_waits_for_an_undo_or_disablement_issues_nothing`,
337337
and the code exchange's own session check). A refresh holds the lock until it
338338
commits, even a confidential client's, which writes nothing
339-
(`db: a_kept_token_writes_nothing_and_holds_its_locks_until_commit`).
339+
(`a_kept_token_writes_nothing_and_holds_its_locks_until_commit`, in
340+
`crates/database/src/repositories/tokens/tests.rs`).
340341

341342
What undo doesn't reach: what the link holder did inside apps that don't ask for
342343
`phr` (app data, accounts of their own inside an app, app sessions of clients
@@ -394,14 +395,16 @@ cannot shadow `account_recoveries`
394395
- A rollback to this release's predecessor keeps every way-in property and the
395396
owner's ability to undo: the backstops hold, and the predecessor already
396397
needs a confirmation for every owned-client change and re-reads a consent's
397-
session under the lock (the prerequisite PR). Never roll back below that
398+
session under the lock. Never roll back below that
398399
predecessor while a recovery can be undone.
399400
- What a rollback loses is availability: the recovery pages, P4 and the typed
400401
errors, until the release is back. This release's CLI still runs `user
401402
undo-recovery` against the same schema.
402-
- Start recoveries only once a rollout is over. A replica of the previous release
403-
can't decode the new recovery emails, and marks them failed; resend them with
404-
`auth-service deliveries retry <id> --reason "…"`.
403+
- Start recoveries only once a rollout is over. A replica of a release that
404+
can't decode a recovery email leaves it pending for one that can, until the
405+
email channel's 24-hour `MAX_AGE` fails it
406+
([life of a delivery](../architecture/delivery-queue.md#life-of-a-delivery));
407+
resend a failed one with `auth-service deliveries retry <id> --reason "…"`.
405408

406409
## Threat model
407410

‎docs/dev/security/boundaries.md‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ frontend or into the image.
130130
| --- | --- | --- | --- |
131131
| Key-encryption keys, `AUTH_KEY_ENCRYPTION_KEY` and `_ACCEPTED` | Generated by piqueld | Seals the signing keys stored in PostgreSQL with AES-256-GCM, so a database dump holds no usable private key | Auth's containers |
132132
| Signing keys | Generated by auth, stored sealed in `signing_keys` | Sign ID, access and logout tokens ([signing keys](../operations/signing-keys.md)) | Auth, with the key-encryption key |
133-
| Token digest keys, `AUTH_TOKEN_DIGEST_KEY` and `_ACCEPTED` | Generated by piqueld | Refresh tokens, codes and pending logins are stored as HMAC digests under them; rotated refresh tokens' successors and email verification, recovery and unsubscribe link tokens derive from them (`config/keys.rs`) | Auth's containers |
133+
| Token digest keys, `AUTH_TOKEN_DIGEST_KEY` and `_ACCEPTED` | Generated by piqueld | Refresh tokens, codes and pending logins are stored as HMAC digests under them; rotated refresh tokens' successors and the email verification, recovery, invitation, unsubscribe and sign-out link tokens derive from them (`config/keys.rs`) | Auth's containers |
134134
| Audit key, `AUTH_AUDIT_KEY_PROVIDER` | Stored by hand for staging and production, generated for previews | Signs audit checkpoints; its verifier keys are compiled in from `audit-key.pub` ([the audit key](audit-history.md#the-audit-key)) | Auth's containers |
135135
| Client secrets | Generated by auth, or supplied by `client apply` | Authenticate confidential clients; auth stores only their SHA-256 digest (`ClientSecret` in `crates/crypto/src/lib.rs`) | The client's owner, once |
136136
| GitHub and Google client secrets | Stored by hand ([sign-in providers](../operations/sign-in-providers.md)) | Auth's OAuth apps at the providers | Auth's containers |
@@ -151,9 +151,11 @@ database, so they work while auth is down
151151
connects as the runtime role and runs the same `AdminService` and
152152
`AccountService` operations as the dashboard, with the same safety rules, but
153153
needs no passkey: whoever can run it is trusted. It records its changes as
154-
`Actor::Cli`, with `$USER` and the host name (`Operator::terminal` in
155-
`apps/auth-service/src/admin/operator.rs`). The `keys` commands also need the
156-
key-encryption key, and `user recover` the token digest key.
154+
`Actor::Cli`, with its operator's name, from `--operator`, else `AUTH_OPERATOR`,
155+
else `$USER`, and the host name (`Operator::terminal` in
156+
`apps/auth-service/src/admin/operator.rs`). The `keys` commands that change
157+
signing keys also need the key-encryption key, and `user recover`,
158+
`invite create` and `keys digest-usage` the token digest key.
157159

158160
Database access is therefore the root of trust. Nothing SourceOrigin runs on may
159161
require auth to sign in ([recovering auth](../architecture/surfaces.md#recovering-auth)),

‎docs/dev/security/handles.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ Knowing that a handle has an account gives an attacker little:
8383
- **Nothing to guess.** Sign-in needs a passkey. A handle doesn't help forge
8484
one, and passkeys resist phishing.
8585
- **No lockout.** Rate limits count requests per client IP, never per account
86-
(`apps/auth-service/src/security/mod.rs`), so naming an account can't lock its
86+
(`apps/auth-service/src/security/http.rs`), so naming an account can't lock its
8787
owner out.
8888
- **Not evidence.** Support's evidence policy never counts knowing a handle
8989
([account recovery](account-recovery.md#supports-evidence-policy)).

‎docs/dev/security/properties.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ detail.
102102
The one exception is `/unsubscribe`, which mail clients post to from anywhere
103103
(RFC 8058): its link's token is its credential, and it only turns one
104104
account's announcements' email off.
105-
- Request throttling and expiring-state cleanup use PostgreSQL. Throttling uses separate login, token, userinfo, account and page budgets per client IP, and covers every API route except health probes and discovery.
105+
- Request throttling and expiring-state cleanup use PostgreSQL. Throttling uses a separate budget per client IP for each rate category ([rate limit](../architecture/request-lifecycle.md#rate-limit)), and covers every route except health probes and discovery.
106106
By default it uses the direct peer IP; only peers in `AUTH_TRUSTED_PROXIES`
107107
may supply a single overwritten `X-Forwarded-For`. Configure this when terminating TLS
108108
at a reverse proxy so users do not share the proxy’s budget. Untrusted headers

0 commit comments

Comments
 (0)