Skip to content
Merged
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
12 changes: 12 additions & 0 deletions .changeset/audit-sinks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
'seamless-auth-api': minor
---

Stream audit events to a SIEM (ADR 0005, #420).

- Admin API under `/admin/audit-sinks`: create, update, disable and delete sinks, and send a test record. Every write takes step-up and is audited as `admin_audit_sink_created`, `admin_audit_sink_updated` or `admin_audit_sink_deleted`.
- OTLP/HTTP with JSON encoding to `<endpoint>/v1/logs`, and syslog (RFC 5424) over TLS with octet counting. Plain TCP syslog is refused in production.
- Every record carries the event's `seamless-auth-events/1` export line, so the hash chain verifies downstream as an export does.
- Each sink has its own cursor and retries until its collector takes the events, backing off to one minute. There is no dead letter: a sink reports how far behind the chain head it is.
- Credentials are never stored. A sink names env vars ending `_AUDIT_SINK_SECRET`, read at send time.
- Audit retention no longer deletes events a sink has yet to deliver.
6 changes: 6 additions & 0 deletions adapter-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@
{ "method": "GET", "path": "/admin/applications/{id}/resources", "credential": "access" },
{ "method": "PUT", "path": "/admin/applications/{id}/resources", "credential": "access" },
{ "method": "POST", "path": "/admin/applications/{id}/secret", "credential": "access" },
{ "method": "GET", "path": "/admin/audit-sinks", "credential": "access" },
{ "method": "POST", "path": "/admin/audit-sinks", "credential": "access" },
{ "method": "DELETE", "path": "/admin/audit-sinks/{id}", "credential": "access" },
{ "method": "GET", "path": "/admin/audit-sinks/{id}", "credential": "access" },
{ "method": "PATCH", "path": "/admin/audit-sinks/{id}", "credential": "access" },
{ "method": "POST", "path": "/admin/audit-sinks/{id}/test", "credential": "access" },
{ "method": "GET", "path": "/admin/auth-events", "credential": "access" },
{ "method": "GET", "path": "/admin/auth-events/export", "credential": "access" },
{ "method": "GET", "path": "/admin/auth-events/integrity", "credential": "access" },
Expand Down
8 changes: 6 additions & 2 deletions docs/adr/0005-extensibility-callouts.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@ Among roles of one kind, sets apply in role-name order, so the last name alphabe
- OTLP/HTTP with JSON encoding to `<endpoint>/v1/logs`, and syslog (RFC 5424) over TLS (RFC 5425) with octet counting. Plain TCP only outside production, never UDP.
- Every record carries the event's `seamless-auth-events/1` line, with `seq`, `prevHash`, `hash` and `payload`, so the chain verifies downstream as an export does.
- Each sink has its own cursor and retries until its destination takes the events, backing off to one minute. There is no dead letter: a sink falls behind and reports its lag.
- Credentials are never stored. A sink names env vars ending `_AUDIT_SINK_SECRET`, the same pattern OAuth providers use.
- Credentials are never stored. A sink names env vars ending `_AUDIT_SINK_SECRET`, the same pattern OAuth providers use. A send whose named env var is unset or unusable, or whose settings production does not allow (plain TCP syslog), fails as `misconfigured` before any connection.
- Retention never deletes past the oldest sink cursor, and a disabled sink holds it too (decided 2026-11-07). An audit event deleted before a SIEM receives it cannot be recovered, so a disabled sink holds retention until it is deleted. Retention logs a warning naming the holding sink and saying to delete it to release retention.
- An OTLP 2xx counts as delivered, including one whose `partialSuccess` reports rejected records (decided 2026-11-07). A collector rejects such records for their content, so retrying them would stall the sink forever.
- Syslog records carry `seq` and `hash` in the SD-ID `seamless@32473`. 32473 is the RFC 5612 documentation number, a placeholder until Fells Code has an IANA Private Enterprise Number (#586). A release must not ship with it.

### E8. Every callout follows the same reachability rules

Expand All @@ -109,7 +112,7 @@ Among roles of one kind, sets apply in role-name order, so the last name alphabe
- Other private and loopback addresses are refused in production unless the host is listed in `CALLOUT_PRIVATE_HOSTS`. It is an env var, so nothing written through the API can widen it, and it is separate from `OAUTH_PROVIDER_PRIVATE_HOSTS`, so allowing an internal hook service does not also allow it as an identity provider.
- Redirects are never followed. Responses are capped at 64 KiB. The deadline covers the whole request, so a destination that trickles bytes cannot hold a sign-in open.
- URLs are checked when written and again at connect time.
- Failures are reported as `refused`, `timed_out`, `connection_failed`, `http_status`, `invalid_response` or `too_large`, never with the resolved address or the socket's error text, so the delivery log cannot be used to map the internal network.
- Failures are reported as `refused`, `misconfigured`, `timed_out`, `connection_failed`, `http_status`, `invalid_response` or `too_large`, never with the resolved address or the socket's error text, so the delivery log cannot be used to map the internal network. `refused` means the API would not connect to the destination's address; `misconfigured` means the destination's own settings cannot be used, so no call was attempted.

### E9. Signing secrets are encrypted at rest

Expand All @@ -120,6 +123,7 @@ They must be read back to sign, so they cannot be hashed. They are AES-256-GCM e
- `login_success` is written when `/login` resolves which methods an identifier may use, before any factor is proven, so it cannot be the source of `user.signed_in`. No event recorded that a session was created. `issueSessionAndRespond` now writes `session_created`, with the method and organization.
- Deleting a passkey (`DELETE /users/credentials`) wrote no audit event. It now writes `credentials_deleted` naming the passkey. Reproducing test first.
- Passkey registration and account registration both write `registration_success`. The passkey path now names the credential in metadata, which is how the catalog tells them apart.
- Audit retention deleted by age alone, so a sink that fell behind for longer than the retention period would have lost events it never sent. Retention now stops at the oldest sink cursor, enabled or disabled, and a sink cannot be created to replay from before the oldest event still held. Decided 2026-11-07: an audit event deleted before a SIEM receives it cannot be recovered, so a disabled sink holds retention until it is deleted.
- `organization_member_updated` recorded only what was added and removed. It now records the roles after the change too, which the webhook carries.
- Login hooks (#419):
- A denied sign-in answers 403 `login_denied`, with the hook's `userMessage` as `message`. A hook that fails closed answers 503 `login_hook_unavailable`, since the user did nothing wrong and can retry.
Expand Down
41 changes: 30 additions & 11 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,19 +112,38 @@ then daily, and each run also logs the audit chain head as an external anchor. S
| `AUDIT_ARCHIVE_DIR` | With retention | - | Where expired events are written before they are deleted, as `auth-events-<firstSeq>-<lastSeq>.ndjson` with a `.sha256` file beside each. Use durable storage, such as a mounted volume, since a file here is the only copy once its rows are gone. |
| `AUDIT_RETENTION_DATABASE_URL` | No | `DATABASE_URL` | A connection for the retention job alone, so it can run as a role that holds DELETE on `auth_events` while the application role does not. |

Retention never deletes an event an [audit sink](#siem-streaming) has yet to deliver, so a sink
that has fallen behind, or is turned off, holds retention back until it catches up or is
deleted. An event deleted before a SIEM receives it cannot be recovered, so a disabled sink
holds retention until it is deleted. Retention logs a warning naming the holding sink while it
is held.

### SIEM streaming

Audit sinks under `/admin/audit-sinks` stream every audit event to a collector, over OTLP/HTTP
(JSON, to `<endpoint>/v1/logs`) or syslog (RFC 5424 over TLS, octet counted). Each record carries
the event's `seamless-auth-events/1` export line, so the hash chain verifies downstream as an
export does. A sink retries until its collector takes the events, backing off to one minute, and
reports how far behind the chain head it is. Destinations follow the same rules as webhooks,
including `CALLOUT_PRIVATE_HOSTS`, and plain TCP syslog is refused in production.

| Variable | Required | Default | Notes |
| -------------------------- | -------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `<NAME>_AUDIT_SINK_SECRET` | No | - | Credentials a sink names rather than stores: an OTLP header value (`headersFromEnv`), or a PEM CA, client certificate or client key for syslog TLS. Names must end in `_AUDIT_SINK_SECRET`. Read at send time; a sink whose variable is unset fails with `refused` and sends nothing. |

### Service tokens and secrets

| Variable | Required | Default | Notes |
| ------------------------------- | ------------------------------------ | ---------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `SEAMLESS_SERVICE_TOKEN` | Yes | - | Trusted server-adapter and internal bearer secret. No other secret falls back to it. |
| `API_SERVICE_TOKEN` | No | - | Supported fallback name for `SEAMLESS_SERVICE_TOKEN`. Used only when `SEAMLESS_SERVICE_TOKEN` is unset, with an info notice at boot. Setting both to different values stops the server at boot. |
| `REFRESH_TOKEN_LOOKUP_SECRET` | Production | development-only value | HMAC key for indexed refresh-token lookup fingerprints. Always required in production. |
| `TOTP_SECRET_ENCRYPTION_KEY` | Production, once TOTP is used | development-only value | Encrypts stored TOTP secrets (hashed with SHA-256 to derive the key, so any high-entropy value works). Production refuses to start while any TOTP credential exists without it, and `POST /totp/enroll/start` answers `409 secret_required` until it is set. |
| `OAUTH_STATE_SECRET` | Production, once OAuth is configured | development-only value | Signs OAuth state. Production refuses to start with a provider configured and no value, and adding a provider answers `409 secret_required` until it is set. |
| `DECOY_SUBJECT_SECRET` | Production | development-only value | HMAC key the decoy pre-auth subjects on `POST /login` derive from. Always required in production. Rotating it re-maps which subject an unknown identifier gets, which is harmless: decoys are stateless and pre-auth tokens live five minutes. |
| `OAUTH_PROVIDER_PRIVATE_HOSTS` | No | - | Comma-separated OAuth provider hosts allowed to resolve to private or loopback addresses in production, for an on-premises IdP. Other provider hosts must resolve to public addresses. Link-local is always refused. |
| `CALLOUT_SECRET_ENCRYPTION_KEY` | Production, once a webhook exists | development-only value | Encrypts stored webhook signing secrets (hashed with SHA-256 to derive the key). Production refuses to start while any webhook exists without it, and creating one answers `409` until it is set. |
| `CALLOUT_PRIVATE_HOSTS` | No | - | Comma-separated webhook hosts allowed to resolve to private or loopback addresses in production, for a receiver inside your own network. Separate from `OAUTH_PROVIDER_PRIVATE_HOSTS`. Link-local, multicast and the unspecified address are always refused, and a webhook can never point at the API's own issuer host. |
| Variable | Required | Default | Notes |
| ------------------------------- | ------------------------------------ | ---------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `SEAMLESS_SERVICE_TOKEN` | Yes | - | Trusted server-adapter and internal bearer secret. No other secret falls back to it. |
| `API_SERVICE_TOKEN` | No | - | Supported fallback name for `SEAMLESS_SERVICE_TOKEN`. Used only when `SEAMLESS_SERVICE_TOKEN` is unset, with an info notice at boot. Setting both to different values stops the server at boot. |
| `REFRESH_TOKEN_LOOKUP_SECRET` | Production | development-only value | HMAC key for indexed refresh-token lookup fingerprints. Always required in production. |
| `TOTP_SECRET_ENCRYPTION_KEY` | Production, once TOTP is used | development-only value | Encrypts stored TOTP secrets (hashed with SHA-256 to derive the key, so any high-entropy value works). Production refuses to start while any TOTP credential exists without it, and `POST /totp/enroll/start` answers `409 secret_required` until it is set. |
| `OAUTH_STATE_SECRET` | Production, once OAuth is configured | development-only value | Signs OAuth state. Production refuses to start with a provider configured and no value, and adding a provider answers `409 secret_required` until it is set. |
| `DECOY_SUBJECT_SECRET` | Production | development-only value | HMAC key the decoy pre-auth subjects on `POST /login` derive from. Always required in production. Rotating it re-maps which subject an unknown identifier gets, which is harmless: decoys are stateless and pre-auth tokens live five minutes. |
| `OAUTH_PROVIDER_PRIVATE_HOSTS` | No | - | Comma-separated OAuth provider hosts allowed to resolve to private or loopback addresses in production, for an on-premises IdP. Other provider hosts must resolve to public addresses. Link-local is always refused. |
| `CALLOUT_SECRET_ENCRYPTION_KEY` | Production, once a webhook exists | development-only value | Encrypts stored webhook signing secrets (hashed with SHA-256 to derive the key). Production refuses to start while any webhook exists without it, and creating one answers `409` until it is set. |
| `CALLOUT_PRIVATE_HOSTS` | No | - | Comma-separated webhook and audit sink hosts allowed to resolve to private or loopback addresses in production, for a receiver inside your own network. Separate from `OAUTH_PROVIDER_PRIVATE_HOSTS`. Link-local, multicast and the unspecified address are always refused, and a callout can never point at the API's own issuer host. |

> None of these falls back to the service token. Development (any `NODE_ENV` other than
> `production`) uses a fixed development-only value for each unset one, with a warning. See
Expand Down
Loading
Loading