@fuzdev/fuz_app 0.182.0 → 0.184.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/actions/CLAUDE.md +535 -1223
- package/dist/actions/action_codegen.d.ts +1 -1
- package/dist/actions/action_codegen.d.ts.map +1 -1
- package/dist/actions/action_codegen.js +3 -2
- package/dist/actions/connection_closer.d.ts +11 -9
- package/dist/actions/connection_closer.d.ts.map +1 -1
- package/dist/actions/connection_closer.js +11 -9
- package/dist/actions/frontend_rpc_client.d.ts +1 -1
- package/dist/actions/register_action_ws.d.ts +14 -1
- package/dist/actions/register_action_ws.d.ts.map +1 -1
- package/dist/actions/register_action_ws.js +2 -1
- package/dist/actions/ws_socket_session.d.ts +9 -1
- package/dist/actions/ws_socket_session.d.ts.map +1 -1
- package/dist/actions/ws_socket_session.js +43 -19
- package/dist/auth/CLAUDE.md +430 -1024
- package/dist/auth/account_queries.d.ts +1 -1
- package/dist/auth/account_queries.js +1 -1
- package/dist/auth/account_routes.d.ts +9 -8
- package/dist/auth/account_routes.d.ts.map +1 -1
- package/dist/auth/account_routes.js +78 -75
- package/dist/auth/admin_actions.d.ts.map +1 -1
- package/dist/auth/admin_actions.js +32 -28
- package/dist/auth/api_token.d.ts +20 -3
- package/dist/auth/api_token.d.ts.map +1 -1
- package/dist/auth/api_token.js +28 -9
- package/dist/auth/api_token_queries.d.ts +2 -2
- package/dist/auth/api_token_queries.js +2 -2
- package/dist/auth/audit_emitter.d.ts +75 -84
- package/dist/auth/audit_emitter.d.ts.map +1 -1
- package/dist/auth/audit_emitter.js +83 -71
- package/dist/auth/audit_log_schema.d.ts +25 -14
- package/dist/auth/audit_log_schema.d.ts.map +1 -1
- package/dist/auth/audit_log_schema.js +23 -8
- package/dist/auth/auth_guard_resolver.d.ts +1 -1
- package/dist/auth/auth_guard_resolver.js +1 -1
- package/dist/auth/bearer_auth.d.ts +2 -5
- package/dist/auth/bearer_auth.d.ts.map +1 -1
- package/dist/auth/bearer_auth.js +4 -13
- package/dist/auth/bootstrap_account.d.ts +42 -26
- package/dist/auth/bootstrap_account.d.ts.map +1 -1
- package/dist/auth/bootstrap_account.js +36 -19
- package/dist/auth/bootstrap_routes.d.ts +20 -21
- package/dist/auth/bootstrap_routes.d.ts.map +1 -1
- package/dist/auth/bootstrap_routes.js +26 -31
- package/dist/auth/bootstrap_token_store.d.ts +3 -4
- package/dist/auth/bootstrap_token_store.d.ts.map +1 -1
- package/dist/auth/bootstrap_token_store.js +1 -1
- package/dist/auth/daemon_token.d.ts +5 -1
- package/dist/auth/daemon_token.d.ts.map +1 -1
- package/dist/auth/daemon_token_middleware.d.ts +12 -8
- package/dist/auth/daemon_token_middleware.d.ts.map +1 -1
- package/dist/auth/daemon_token_middleware.js +15 -21
- package/dist/auth/deps.d.ts +19 -5
- package/dist/auth/deps.d.ts.map +1 -1
- package/dist/auth/deps.js +3 -2
- package/dist/auth/invite_queries.d.ts +51 -3
- package/dist/auth/invite_queries.d.ts.map +1 -1
- package/dist/auth/invite_queries.js +81 -6
- package/dist/auth/invite_schema.d.ts +2 -1
- package/dist/auth/invite_schema.d.ts.map +1 -1
- package/dist/auth/middleware.d.ts +2 -3
- package/dist/auth/middleware.d.ts.map +1 -1
- package/dist/auth/middleware.js +3 -3
- package/dist/auth/request_context.d.ts +3 -3
- package/dist/auth/request_context.js +3 -3
- package/dist/auth/resolved_auth.d.ts +7 -7
- package/dist/auth/resolved_auth.d.ts.map +1 -1
- package/dist/auth/resolved_auth.js +4 -4
- package/dist/auth/role_grant_offer_actions.d.ts +27 -3
- package/dist/auth/role_grant_offer_actions.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_actions.js +42 -35
- package/dist/auth/role_grant_offer_queries.d.ts +60 -4
- package/dist/auth/role_grant_offer_queries.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_queries.js +79 -5
- package/dist/auth/role_grant_queries.d.ts +3 -52
- package/dist/auth/role_grant_queries.d.ts.map +1 -1
- package/dist/auth/role_grant_queries.js +5 -80
- package/dist/auth/self_service_role_actions.d.ts.map +1 -1
- package/dist/auth/self_service_role_actions.js +11 -22
- package/dist/auth/session_cookie.d.ts +82 -174
- package/dist/auth/session_cookie.d.ts.map +1 -1
- package/dist/auth/session_cookie.js +80 -130
- package/dist/auth/session_middleware.d.ts +8 -17
- package/dist/auth/session_middleware.d.ts.map +1 -1
- package/dist/auth/session_middleware.js +14 -23
- package/dist/auth/session_queries.d.ts +15 -17
- package/dist/auth/session_queries.d.ts.map +1 -1
- package/dist/auth/session_queries.js +28 -20
- package/dist/auth/signup_routes.d.ts.map +1 -1
- package/dist/auth/signup_routes.js +93 -43
- package/dist/db/CLAUDE.md +5 -3
- package/dist/db/sql_columns.d.ts +1 -1
- package/dist/db/sql_columns.js +1 -1
- package/dist/dev/setup.d.ts +3 -1
- package/dist/dev/setup.d.ts.map +1 -1
- package/dist/dev/setup.js +3 -1
- package/dist/http/CLAUDE.md +315 -763
- package/dist/http/db_routes.d.ts +8 -23
- package/dist/http/db_routes.d.ts.map +1 -1
- package/dist/http/db_routes.js +73 -73
- package/dist/http/origin.d.ts +7 -8
- package/dist/http/origin.d.ts.map +1 -1
- package/dist/http/origin.js +7 -8
- package/dist/http/pending_effects.d.ts +118 -6
- package/dist/http/pending_effects.d.ts.map +1 -1
- package/dist/http/pending_effects.js +114 -6
- package/dist/http/route_result.d.ts +1 -1
- package/dist/http/route_spec.d.ts +14 -11
- package/dist/http/route_spec.d.ts.map +1 -1
- package/dist/realtime/sse.d.ts +4 -23
- package/dist/realtime/sse.d.ts.map +1 -1
- package/dist/realtime/sse.js +4 -25
- package/dist/server/app_backend.d.ts +4 -5
- package/dist/server/app_backend.d.ts.map +1 -1
- package/dist/server/app_backend.js +3 -1
- package/dist/server/app_server.d.ts +80 -16
- package/dist/server/app_server.d.ts.map +1 -1
- package/dist/server/app_server.js +113 -31
- package/dist/server/app_server_context.d.ts +1 -2
- package/dist/server/app_server_context.d.ts.map +1 -1
- package/dist/server/env.js +2 -2
- package/dist/testing/CLAUDE.md +265 -796
- package/dist/testing/admin_integration.d.ts +2 -3
- package/dist/testing/admin_integration.d.ts.map +1 -1
- package/dist/testing/admin_integration.js +3 -3
- package/dist/testing/adversarial_404.d.ts +6 -1
- package/dist/testing/adversarial_404.d.ts.map +1 -1
- package/dist/testing/adversarial_404.js +38 -17
- package/dist/testing/app_server.d.ts +23 -148
- package/dist/testing/app_server.d.ts.map +1 -1
- package/dist/testing/app_server.js +53 -131
- package/dist/testing/attack_surface.d.ts +1 -1
- package/dist/testing/attack_surface.d.ts.map +1 -1
- package/dist/testing/audit_completeness.d.ts +2 -3
- package/dist/testing/audit_completeness.d.ts.map +1 -1
- package/dist/testing/audit_completeness.js +1 -1
- package/dist/testing/audit_drift_guard.d.ts +11 -6
- package/dist/testing/audit_drift_guard.d.ts.map +1 -1
- package/dist/testing/audit_drift_guard.js +15 -8
- package/dist/testing/cross_backend/audit_cross_helpers.d.ts +12 -9
- package/dist/testing/cross_backend/audit_cross_helpers.d.ts.map +1 -1
- package/dist/testing/cross_backend/audit_cross_helpers.js +13 -14
- package/dist/testing/cross_backend/capabilities.d.ts +9 -6
- package/dist/testing/cross_backend/capabilities.d.ts.map +1 -1
- package/dist/testing/cross_backend/capabilities.js +11 -7
- package/dist/testing/cross_backend/capability_mounts.d.ts +103 -0
- package/dist/testing/cross_backend/capability_mounts.d.ts.map +1 -0
- package/dist/testing/cross_backend/capability_mounts.js +428 -0
- package/dist/testing/cross_backend/cell_moderate.js +2 -2
- package/dist/testing/cross_backend/cell_relations.d.ts.map +1 -1
- package/dist/testing/cross_backend/cell_relations.js +12 -11
- package/dist/testing/cross_backend/conformance_principal.d.ts +54 -0
- package/dist/testing/cross_backend/conformance_principal.d.ts.map +1 -0
- package/dist/testing/cross_backend/conformance_principal.js +283 -0
- package/dist/testing/cross_backend/conformance_table.d.ts +7 -56
- package/dist/testing/cross_backend/conformance_table.d.ts.map +1 -1
- package/dist/testing/cross_backend/conformance_table.js +6 -274
- package/dist/testing/cross_backend/cookie_attributes.js +1 -1
- package/dist/testing/cross_backend/credential_deadline.d.ts.map +1 -1
- package/dist/testing/cross_backend/credential_deadline.js +2 -0
- package/dist/testing/cross_backend/credential_wire.d.ts +1 -1
- package/dist/testing/cross_backend/credential_wire.d.ts.map +1 -1
- package/dist/testing/cross_backend/db_state_diff.d.ts +72 -0
- package/dist/testing/cross_backend/db_state_diff.d.ts.map +1 -0
- package/dist/testing/cross_backend/db_state_diff.js +444 -0
- package/dist/testing/cross_backend/declared_skips.d.ts +68 -0
- package/dist/testing/cross_backend/declared_skips.d.ts.map +1 -0
- package/dist/testing/cross_backend/declared_skips.js +132 -0
- package/dist/testing/cross_backend/default_backend_configs.d.ts +3 -3
- package/dist/testing/cross_backend/default_spine_surface.d.ts +0 -6
- package/dist/testing/cross_backend/default_spine_surface.d.ts.map +1 -1
- package/dist/testing/cross_backend/default_spine_surface.js +4 -9
- package/dist/testing/cross_backend/differential.d.ts +13 -5
- package/dist/testing/cross_backend/differential.d.ts.map +1 -1
- package/dist/testing/cross_backend/differential.js +35 -11
- package/dist/testing/cross_backend/differential_normalize.d.ts +12 -0
- package/dist/testing/cross_backend/differential_normalize.d.ts.map +1 -1
- package/dist/testing/cross_backend/differential_normalize.js +16 -0
- package/dist/testing/cross_backend/full_spine_mount.d.ts +1 -42
- package/dist/testing/cross_backend/full_spine_mount.d.ts.map +1 -1
- package/dist/testing/cross_backend/full_spine_mount.js +45 -4
- package/dist/testing/cross_backend/in_process_setup.d.ts +28 -19
- package/dist/testing/cross_backend/in_process_setup.d.ts.map +1 -1
- package/dist/testing/cross_backend/in_process_setup.js +156 -142
- package/dist/testing/cross_backend/login_security.d.ts +12 -0
- package/dist/testing/cross_backend/login_security.d.ts.map +1 -1
- package/dist/testing/cross_backend/login_security.js +21 -4
- package/dist/testing/cross_backend/request_target_conformance_wire.d.ts +0 -2
- package/dist/testing/cross_backend/request_target_conformance_wire.d.ts.map +1 -1
- package/dist/testing/cross_backend/request_target_conformance_wire.js +3 -1
- package/dist/testing/cross_backend/revocation_drivers.d.ts +18 -5
- package/dist/testing/cross_backend/revocation_drivers.d.ts.map +1 -1
- package/dist/testing/cross_backend/revocation_drivers.js +18 -10
- package/dist/testing/cross_backend/role_grant_cross_helpers.d.ts +1 -1
- package/dist/testing/cross_backend/role_grant_cross_helpers.d.ts.map +1 -1
- package/dist/testing/cross_backend/role_grant_offer_lifecycle.d.ts.map +1 -1
- package/dist/testing/cross_backend/role_grant_offer_lifecycle.js +33 -1
- package/dist/testing/cross_backend/role_grant_participation.js +4 -4
- package/dist/testing/cross_backend/rpc_adversarial.js +1 -1
- package/dist/testing/cross_backend/rust_spine_consumer_surface.d.ts +3 -4
- package/dist/testing/cross_backend/rust_spine_consumer_surface.d.ts.map +1 -1
- package/dist/testing/cross_backend/rust_spine_consumer_surface.js +2 -2
- package/dist/testing/cross_backend/session_cap.d.ts +2 -2
- package/dist/testing/cross_backend/session_cap.d.ts.map +1 -1
- package/dist/testing/cross_backend/session_cap.js +22 -11
- package/dist/testing/cross_backend/setup.d.ts +32 -2
- package/dist/testing/cross_backend/setup.d.ts.map +1 -1
- package/dist/testing/cross_backend/setup.js +32 -1
- package/dist/testing/cross_backend/spine_suites.d.ts +125 -15
- package/dist/testing/cross_backend/spine_suites.d.ts.map +1 -1
- package/dist/testing/cross_backend/spine_suites.js +459 -62
- package/dist/testing/cross_backend/spine_surface_constants.d.ts +1 -1
- package/dist/testing/cross_backend/spine_surface_constants.d.ts.map +1 -1
- package/dist/testing/cross_backend/spine_surface_constants.js +1 -0
- package/dist/testing/cross_backend/sse_round_trip.d.ts +9 -1
- package/dist/testing/cross_backend/sse_round_trip.d.ts.map +1 -1
- package/dist/testing/cross_backend/sse_round_trip.js +123 -27
- package/dist/testing/cross_backend/standard.d.ts +2 -3
- package/dist/testing/cross_backend/standard.d.ts.map +1 -1
- package/dist/testing/cross_backend/standard.js +3 -3
- package/dist/testing/cross_backend/testing_backdoor.d.ts.map +1 -1
- package/dist/testing/cross_backend/testing_backdoor.js +4 -2
- package/dist/testing/cross_backend/testing_credential_read.d.ts +10 -11
- package/dist/testing/cross_backend/testing_credential_read.d.ts.map +1 -1
- package/dist/testing/cross_backend/testing_credential_read.js +12 -12
- package/dist/testing/cross_backend/testing_reset_actions.d.ts +84 -47
- package/dist/testing/cross_backend/testing_reset_actions.d.ts.map +1 -1
- package/dist/testing/cross_backend/testing_reset_actions.js +95 -63
- package/dist/testing/cross_backend/testing_server_core.d.ts.map +1 -1
- package/dist/testing/cross_backend/testing_server_core.js +2 -3
- package/dist/testing/cross_backend/transport_composition.d.ts +1 -1
- package/dist/testing/cross_backend/transport_composition.d.ts.map +1 -1
- package/dist/testing/cross_backend/transport_composition.js +7 -3
- package/dist/testing/cross_backend/ws_round_trip.d.ts +5 -0
- package/dist/testing/cross_backend/ws_round_trip.d.ts.map +1 -1
- package/dist/testing/cross_backend/ws_round_trip.js +54 -8
- package/dist/testing/daemon_token_rotation.d.ts.map +1 -1
- package/dist/testing/daemon_token_rotation.js +2 -3
- package/dist/testing/data_exposure.d.ts.map +1 -1
- package/dist/testing/data_exposure.js +3 -0
- package/dist/testing/db.d.ts +0 -32
- package/dist/testing/db.d.ts.map +1 -1
- package/dist/testing/db.js +0 -86
- package/dist/testing/db_entities.d.ts +14 -0
- package/dist/testing/db_entities.d.ts.map +1 -1
- package/dist/testing/db_entities.js +17 -0
- package/dist/testing/db_invariant_queries.d.ts +259 -0
- package/dist/testing/db_invariant_queries.d.ts.map +1 -0
- package/dist/testing/db_invariant_queries.js +400 -0
- package/dist/testing/db_invariants.d.ts +106 -0
- package/dist/testing/db_invariants.d.ts.map +1 -0
- package/dist/testing/db_invariants.gen.sql.d.ts +11 -0
- package/dist/testing/db_invariants.gen.sql.d.ts.map +1 -0
- package/dist/testing/db_invariants.gen.sql.js +13 -0
- package/dist/testing/db_invariants.js +141 -0
- package/dist/testing/db_invariants.sql +152 -0
- package/dist/testing/describe_db.d.ts +36 -0
- package/dist/testing/describe_db.d.ts.map +1 -0
- package/dist/testing/describe_db.js +71 -0
- package/dist/testing/integration.d.ts +8 -12
- package/dist/testing/integration.d.ts.map +1 -1
- package/dist/testing/integration.js +13 -17
- package/dist/testing/integration_helpers.d.ts +1 -1
- package/dist/testing/integration_helpers.d.ts.map +1 -1
- package/dist/testing/rate_limiting.d.ts +3 -4
- package/dist/testing/rate_limiting.d.ts.map +1 -1
- package/dist/testing/rate_limiting.js +6 -5
- package/dist/testing/role_grant_helpers.d.ts +1 -1
- package/dist/testing/role_grant_helpers.d.ts.map +1 -1
- package/dist/testing/round_trip.d.ts.map +1 -1
- package/dist/testing/round_trip.js +3 -0
- package/dist/testing/rpc_attack_surface.d.ts +8 -6
- package/dist/testing/rpc_attack_surface.d.ts.map +1 -1
- package/dist/testing/rpc_attack_surface.js +69 -6
- package/dist/testing/rpc_helpers.d.ts +1 -2
- package/dist/testing/rpc_helpers.d.ts.map +1 -1
- package/dist/testing/rpc_helpers.js +3 -3
- package/dist/testing/rpc_round_trip.d.ts +3 -4
- package/dist/testing/rpc_round_trip.d.ts.map +1 -1
- package/dist/testing/rpc_round_trip.js +4 -1
- package/dist/testing/sse_round_trip.d.ts +3 -4
- package/dist/testing/sse_round_trip.d.ts.map +1 -1
- package/dist/testing/sse_round_trip.js +15 -6
- package/dist/testing/stubs.d.ts +9 -8
- package/dist/testing/stubs.d.ts.map +1 -1
- package/dist/testing/stubs.js +20 -13
- package/dist/testing/test_app.d.ts +168 -0
- package/dist/testing/test_app.d.ts.map +1 -0
- package/dist/testing/test_app.js +123 -0
- package/dist/testing/ws_round_trip.d.ts.map +1 -1
- package/dist/testing/ws_round_trip.js +3 -0
- package/dist/ui/ui_format.d.ts.map +1 -1
- package/dist/ui/ui_format.js +1 -2
- package/package.json +1 -1
package/dist/auth/CLAUDE.md
CHANGED
|
@@ -10,521 +10,272 @@ runner contract + operator recipes: ../../../docs/migrations.md. For
|
|
|
10
10
|
workspace-wide DI vocabulary: Skill(fuz-stack) `dependency-injection.md`.
|
|
11
11
|
|
|
12
12
|
**CLAUDE.md is a map; TSDoc is the detail.** Per-symbol semantics
|
|
13
|
-
(parameters, error shapes, invariants,
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
(parameters, error shapes, invariants, timing contracts) live on TSDoc next
|
|
14
|
+
to the code. This file orients you across the modules and documents the
|
|
15
|
+
cross-cutting invariants that don't fit on any single symbol.
|
|
16
16
|
|
|
17
17
|
## AppDeps split
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
- **Route caps** — `RouteFactoryDeps` — `Omit<AppDeps, 'db'>`; handlers get `db` via `RouteContext`.
|
|
21
|
-
- **Action caps** — `ActionFactoryDeps` (`auth/deps.ts`) — the `{log, audit}` shape action factories take; `RouteFactoryDeps`/`AppDeps` satisfy it structurally. The factories whose handlers end credentials or revoke roles (`create_account_actions`, `create_admin_actions`, `create_role_grant_offer_actions`, `create_self_service_role_actions`, and the standard bundle) take `RevokingActionFactoryDeps` — `ActionFactoryDeps` plus a required `connection_closer`. The two pure-read actor factories (`actor_lookup`/`actor_search`) take only `{log: Logger}`.
|
|
22
|
-
- **Parameters** — `*Options` — static startup values, per-factory.
|
|
23
|
-
- **Runtime state** — inline ref — mutable values: `bootstrap_status`, `DaemonTokenState`. NOT in deps or options.
|
|
19
|
+
The categories are root ../../../CLAUDE.md §AppDeps Vocabulary. What auth adds:
|
|
24
20
|
|
|
25
|
-
`audit
|
|
26
|
-
|
|
27
|
-
over the pool so rows persist when request transactions roll back. See root
|
|
28
|
-
../../../CLAUDE.md §AppDeps Vocabulary for the workspace-wide split.
|
|
21
|
+
- **Action caps** — `ActionFactoryDeps` (`auth/deps.ts`), the `{log, audit}` shape action factories take; `RouteFactoryDeps` / `AppDeps` satisfy it structurally. The factories whose handlers end credentials or revoke roles (`create_account_actions`, `create_admin_actions`, `create_role_grant_offer_actions`, `create_self_service_role_actions`, and the standard bundle) take `RevokingActionFactoryDeps` — `ActionFactoryDeps` plus a required `connection_closer` (`actions/CLAUDE.md` §Connection closer). The pure-read actor factories (`actor_lookup` / `actor_search`) take only `{log}`.
|
|
22
|
+
- **Runtime state** — `bootstrap_status` and `DaemonTokenState` are inline refs, never deps or options. `DaemonTokenState.keeper_account_id` is resolved by `create_app_server` at assembly when null, and set by the bootstrap route after its commit (and by `_testing_reset`); the daemon leg never re-reads it.
|
|
29
23
|
|
|
30
24
|
## Module map
|
|
31
25
|
|
|
32
26
|
### Crypto primitives (pure, I/O-free)
|
|
33
27
|
|
|
34
|
-
- `auth/keyring.ts` — `Keyring
|
|
35
|
-
- `auth/session_cookie.ts` —
|
|
36
|
-
- `auth/credential_headers.ts` — the grammar of the three credential headers as pure readers over header lines (`
|
|
37
|
-
- `auth/password.ts` — `Password
|
|
38
|
-
- `auth/password_argon2.ts` — `
|
|
39
|
-
- `auth/api_token.ts` —
|
|
40
|
-
- `auth/daemon_token.ts` — `DaemonToken`,
|
|
41
|
-
- `auth/bootstrap_account.ts` — `bootstrap_account
|
|
42
|
-
- `auth/bootstrap_token_store.ts` — `BootstrapTokenStore
|
|
43
|
-
|
|
44
|
-
Cross-cutting notes that don't live on any single symbol:
|
|
45
|
-
|
|
46
|
-
- **Password schemas are split deliberately.** `Password` (length min 12)
|
|
47
|
-
gates creation + change; `PasswordProvided` (length min 1) gates
|
|
48
|
-
login/verify so tightening creation rules doesn't lock out existing
|
|
49
|
-
accounts. Both carry `sensitivity: 'secret'` meta.
|
|
50
|
-
- **Argon2id parameters** track OWASP guidance (`memoryCost: 19456`,
|
|
51
|
-
`timeCost: 2`, `parallelism: 1`); `verify_dummy` equalizes timing on
|
|
52
|
-
account-lookup miss.
|
|
53
|
-
- **API token format** `secret_fuz_token_<base64url>` — prefix enables
|
|
54
|
-
secret scanning (GitHub, TruffleHog); public `id` is `tok_<12 chars>`;
|
|
55
|
-
storage key is the blake3 hash. Raw token returned once.
|
|
28
|
+
- `auth/keyring.ts` — `Keyring`; `create_keyring` validates and is the one way to build one.
|
|
29
|
+
- `auth/session_cookie.ts` — the signed session cookie, named by a bare `session_cookie_name` (`SESSION_COOKIE_NAME` the default), as on the Rust spine: `parse_session_from_cookies` reads it off the `Cookie` lines as `SessionCookieRead` — `absent`, `invalid` (a present cookie that fails to verify, the empty value included) or `valid` with its token and signed expiry; no refresh, the lifetime is an absolute cap signed at mint — and the `Set-Cookie` writers for a route's result (`sign_session_cookie` over a minted token, `format_session_clear_cookie`). The attributes are fixed (`SESSION_COOKIE_ATTRIBUTES`, no option weakens them), and the writers throw on a name or value outside RFC 6265's grammar. The strings and names match the Rust spine's byte for byte.
|
|
30
|
+
- `auth/credential_headers.ts` — the grammar of the three credential headers as pure readers over header lines (`read_session_cookie_value`, `read_bearer_token`, `read_daemon_token`; a credential header sent twice is discarded). Hono-free; twin of the Rust `fuz_auth::credential_headers`, both held to `testing/cross_backend/credential_conformance.json`.
|
|
31
|
+
- `auth/password.ts` — `Password` (creation and change) vs `PasswordProvided` (login and verify): split so tightening creation rules never locks out an existing account. Both carry `sensitivity: 'secret'`.
|
|
32
|
+
- `auth/password_argon2.ts` — `argon2_password_deps` (Argon2id at OWASP parameters); `verify_dummy` equalizes timing on an account-lookup miss.
|
|
33
|
+
- `auth/api_token.ts` — the API token format: the `secret_fuz_token_` prefix exists for secret scanning; the public id (`ApiTokenId`, `to_api_token_id`) is derived from the token; storage is the blake3 hash; the raw token is returned once. `is_api_token_shaped` is the precheck that keeps a malformed bearer from costing a query.
|
|
34
|
+
- `auth/daemon_token.ts` — `DaemonToken`, its shape precheck, `DAEMON_TOKEN_HEADER`, `DaemonTokenState`.
|
|
35
|
+
- `auth/bootstrap_account.ts` — `bootstrap_account`, the one-shot keeper bootstrap: one transaction holds the `bootstrap_lock`, the account and grants, the session and its cookie line, the success row, and last the token burn — a failed burn (`BootstrapTokenBurnError`) rolls everything back and answers `token_file_undeletable`. `read_bootstrap_token` is the read it and `is_bootstrap_available` share. Its success (`BootstrapAccountSuccess`, internal) is the Rust `BootstrapSuccess`: the session token, the account and actor, and the signed `Set-Cookie` line.
|
|
36
|
+
- `auth/bootstrap_token_store.ts` — `BootstrapTokenStore`, the one seam to the token file. Its read refuses a file with a second hard link, which would outlive the burn under the other name. Twin of the Rust trait.
|
|
56
37
|
|
|
57
38
|
### Schemas, types, DDL
|
|
58
39
|
|
|
59
|
-
Convention — `*_schema.ts` holds a domain's `@fuzdev/fuz_schema` schemas;
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
- `auth/
|
|
65
|
-
- `auth/
|
|
66
|
-
- `auth/
|
|
67
|
-
- `auth/
|
|
68
|
-
- `auth/
|
|
69
|
-
- `auth/
|
|
70
|
-
- `auth/
|
|
71
|
-
- `auth/
|
|
72
|
-
- `auth/
|
|
73
|
-
- `auth/
|
|
74
|
-
- `auth/role_grant_offer_schema.ts` — `RoleGrantOffer`, `RoleGrantOfferJson
|
|
75
|
-
- `auth/role_grant_offer_ddl.ts` —
|
|
76
|
-
- `auth/role_grant_sql.ts` — the liveness predicates every grant and offer read shares
|
|
77
|
-
- `auth/role_grant_offer_notifications.ts` — the WS notification specs
|
|
40
|
+
Convention — `*_schema.ts` holds a domain's `@fuzdev/fuz_schema` schemas;
|
|
41
|
+
`*_ddl.ts` holds DDL strings. Every wire shape in auth is a fuz_schema
|
|
42
|
+
schema, its timestamps `Timestamp`s, its usernames `UsernameCanonical` on
|
|
43
|
+
output.
|
|
44
|
+
|
|
45
|
+
- `auth/account_schema.ts` — `Account`, `Actor`, `RoleGrant`, `AuthSession`, `ApiToken` and their client-safe `*Json` shapes; `SessionId` (the blake3 session hash, branded); the grant predicates `is_role_grant_active` and `has_global_role` (the client-side bare-list form of `has_scoped_role(_, role, null)`).
|
|
46
|
+
- `auth/name_schema.ts` — the one name grammar the auth vocabularies share (runs of lowercase letters joined by single underscores, capped at `NAME_LENGTH_MAX`) and `create_name_schema(label)`, so each domain keeps its own label in messages. Twin of the Rust `fuz_auth::is_valid_name`.
|
|
47
|
+
- `auth/role_schema.ts` — `RoleName`, `RoleSpec`, the builtins (`ROLE_KEEPER`, `ROLE_ADMIN`, `is_builtin_role`), `create_role_registry`, and the grant-path lookups (`role_has_grant_path`, `list_roles_with_grant_path`).
|
|
48
|
+
- `auth/scope_kind_schema.ts`, `auth/credential_type_schema.ts`, `auth/grant_path_schema.ts` — the other open name registries (§Open-registry composition) and their builtins. A `scope_kind` is copied into the row and its audit metadata; the grammar keeps out the partial unique indexes' `'GLOBAL'` token.
|
|
49
|
+
- `auth/token_lifetime.ts` — `TokenLifetimeInput` (`eternal` or `ttl`), required on `account_token_create`: no default, so `expires_at IS NULL` always means deliberately eternal.
|
|
50
|
+
- `auth/token_scope.ts` — per-credential authority narrowing on `api_token.scope`: `TokenScope` / `TokenScopeInput`, `parse_stored_token_scope` (fail-closed, byte-capped at mint and read as on the Rust spine), and the `<section>:<id>` capability vocabulary (`rpc:<method>`, `surface:<name>`). Not an open registry — ../../../docs/security.md §Token scoping says why.
|
|
51
|
+
- `auth/auth_ddl.ts` — DDL and seeds for the core identity tables.
|
|
52
|
+
- `auth/audit_log_schema.ts` — `AUDIT_EVENT_TYPES` (the builtins; read the frozen constant, not a copy), `AuditEventTypeName`, `audit_metadata_schemas`, `AuditLogEvent` (its `actor_id` / `target_actor_id` TSDoc is the per-event table), `create_audit_log_config`, the revocation scopes (§Audit emitter), and the wire rows.
|
|
53
|
+
- `auth/audit_log_ddl.ts` — the `audit_log` table; `seq BIGSERIAL` for cursor-based gap fill (`create_db` parses int8 so `seq` reads as a number).
|
|
54
|
+
- `auth/invite_schema.ts`, `auth/app_settings_schema.ts` (a single-row table, `CHECK (id = 1)`) — rows and wire shapes.
|
|
55
|
+
- `auth/role_grant_offer_schema.ts` — `RoleGrantOffer`, `RoleGrantOfferJson`, `to_role_grant_offer_json`.
|
|
56
|
+
- `auth/role_grant_offer_ddl.ts` — the offer table and indexes, `ROLE_GRANT_OFFER_SCOPE_SENTINEL_UUID` / `ROLE_GRANT_OFFER_SCOPE_KIND_GLOBAL_TOKEN`, `ROLE_GRANT_OFFER_COLUMNS` and the shared `ROLE_GRANT_OFFER_WITH_GRANTOR_SELECT` CTE tail (homed here, not with the queries, because `role_grant_queries.ts` writes offer rows too and must not import the offer queries).
|
|
57
|
+
- `auth/role_grant_sql.ts` — the liveness predicates every grant and offer read shares (`role_grant_active_sql`, `offer_pending_predicate`), twins of the Rust spine's.
|
|
58
|
+
- `auth/role_grant_offer_notifications.ts` — the offer-lifecycle WS notification specs and their post-commit send helpers (§WS notifications).
|
|
78
59
|
|
|
79
60
|
### Queries
|
|
80
61
|
|
|
81
|
-
All take `deps: QueryDeps = {db}` first
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
- `auth/
|
|
90
|
-
- `auth/
|
|
91
|
-
- `auth/
|
|
92
|
-
- `auth/
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
`
|
|
99
|
-
`
|
|
100
|
-
|
|
101
|
-
`
|
|
102
|
-
without a `satisfies keyof Row` clause, since `AppSettings` deliberately
|
|
103
|
-
doesn't carry `id`). Module direction: `role_grant_offer_queries.ts` imports
|
|
104
|
-
`role_grant_queries.ts` (the accept path writes through
|
|
105
|
-
`query_create_role_grant` / `query_role_grant_by_id`) and not the reverse —
|
|
106
|
-
the revoke cascades in `role_grant_queries.ts` still _write_ offer rows, which
|
|
107
|
-
is exactly why the offer const and the shared CTE tail live in the DDL module.
|
|
108
|
-
Every const is pinned to the live schema by
|
|
109
|
-
`src/test/db/column_projections.db.test.ts`. The Rust `fuz_auth` twin carries
|
|
110
|
-
the same nine consts (names and order), projected through
|
|
111
|
-
`fuz_db::qualify_columns` / `omit_columns`, decoded with compile-time
|
|
112
|
-
name→index (`fuz_db::col!`), and pinned by its own
|
|
113
|
-
`tests/columns.rs` registry; its narrow purpose rows (`AccountRow` is an
|
|
114
|
-
`id, username` pair) keep private per-shape lists checked as subsets of the
|
|
115
|
-
table const.
|
|
116
|
-
|
|
117
|
-
`_unscoped` suffix on `query_session_revoke_by_hash_unscoped` and
|
|
118
|
-
`query_invite_claim_unscoped` is the safety signal: SQL only checks row state,
|
|
119
|
-
caller is responsible for scoping. Production scoping for invites is enforced
|
|
120
|
-
upstream in `auth/signup_routes.ts` via `query_invite_find_unclaimed_match_for_update`
|
|
121
|
-
(SELECT … FOR UPDATE inside the signup tx — find + claim atomic on the row lock).
|
|
62
|
+
All take `deps: QueryDeps = {db}` first. Module direction:
|
|
63
|
+
`role_grant_offer_queries.ts` imports `role_grant_queries.ts`, never the
|
|
64
|
+
reverse; `query_revoke_role_grant` lives with the offer queries (as in the
|
|
65
|
+
Rust twin) because it takes the offer locks and both supersedes. Every
|
|
66
|
+
read projects through its table's `*_COLUMNS` const (../../../docs/architecture.md
|
|
67
|
+
§Query Modules), pinned to the live schema by
|
|
68
|
+
`src/test/db/column_projections.db.test.ts`.
|
|
69
|
+
|
|
70
|
+
- `auth/account_queries.ts` — account CRUD, actor resolution, password update with a verify-write race guard, the admin listing, and the account-row locks every writer of an account takes first (§Row locks).
|
|
71
|
+
- `auth/actor_lookup_queries.ts` / `auth/actor_search_queries.ts` — batched id → label and prefix search; active actors of active accounts only.
|
|
72
|
+
- `auth/role_grant_queries.ts` — idempotent create, scope-aware lookups, `query_role_grant_revoke_for_scope` (parent-scope cascade).
|
|
73
|
+
- `auth/role_grant_offer_queries.ts` — the offer lifecycle, atomic `query_accept_offer` with sibling supersede, `query_revoke_role_grant` (every revoke's one supersede rule: the revokee's incoming siblings and every offer its actor made), the offer-row lockers, and the `RoleGrantOffer*Error` classes.
|
|
74
|
+
- `auth/session_queries.ts` — server-side sessions (blake3-hashed). `create_capped_session` is the one session minter (row, cap evictions, the raw token the caller signs with `sign_session_cookie`; Hono-free; twin of the Rust one). No touch or renewal: `expires_at` is an absolute cap on the database clock. The cap and the expiry sweep return the ids they remove, so the caller closes their connections after the commit.
|
|
75
|
+
- `auth/api_token_queries.ts` — `query_validate_api_token` (records nothing, refuses an unreadable stored scope) and the separate usage touch the bearer leg runs only once the account is found live; `query_api_token_live_account`, the no-touch re-check sharing the validate query's liveness predicate; the token cap.
|
|
76
|
+
- `auth/invite_queries.ts`, `auth/app_settings_queries.ts`.
|
|
77
|
+
- `auth/audit_log_queries.ts` — `query_audit_log` (the insert), the list and history reads, the retention cleanup, and the drift counters.
|
|
78
|
+
|
|
79
|
+
`_unscoped` (`query_session_revoke_by_hash_unscoped`, logout only;
|
|
80
|
+
`query_invite_claim_unscoped`) is the safety signal: the SQL checks row
|
|
81
|
+
state, the caller owns scoping. Signup scopes the invite claim with
|
|
82
|
+
`query_invite_find_unclaimed_match_for_update` in the same transaction.
|
|
122
83
|
|
|
123
84
|
### Audit emitter
|
|
124
85
|
|
|
125
|
-
`auth/audit_emitter.ts` defines
|
|
126
|
-
`AppDeps.audit
|
|
127
|
-
`
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
- `emit
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
`
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
`get_audit_write_failures`). The Rust spine's split is the same
|
|
158
|
-
(`route_audit_emit`: `emit_in_tx` for an action's success row, `emit` on the
|
|
159
|
-
pool otherwise); the TS `/logout` runs in a route transaction, so its row is
|
|
160
|
-
in-transaction where Rust's is pooled. `db_admin_row_delete` is written on the
|
|
161
|
-
pool after its commit on both twins (TS: `emit_pool` from a post-commit
|
|
162
|
-
thunk).
|
|
163
|
-
|
|
164
|
-
**When listeners hear about a row.** The fan-out depends on the outcome: a
|
|
165
|
-
**failure** row is announced as soon as it is written — the attempt happened
|
|
166
|
-
whatever the transaction does; a **success** row is announced only after the
|
|
167
|
-
request's transaction commits (a thunk on `ctx.post_commit_effects`; after the
|
|
168
|
-
handler returns, on a route without one) and never when the handler throws. The listeners act on a success row — the revocation guards
|
|
169
|
-
close connections, the audit stream broadcasts it — so announcing one before
|
|
170
|
-
its commit would close while the revoked credential still reads as valid, and
|
|
171
|
-
a rolled-back revocation would close anyway. A route that runs without a
|
|
172
|
-
request transaction and opens its own around just its writes (`/login`,
|
|
173
|
-
`/password`) emits its success row after that transaction commits. The Rust
|
|
174
|
-
spine follows the same order: a success row emitted inside a request
|
|
175
|
-
transaction is written in it with its fan-out queued behind the commit, and
|
|
176
|
-
`/login` and `/password` emit after their own commit. `AuditEmitterContext` is therefore
|
|
177
|
-
`{db, pending_effects, post_commit_effects}` — `RouteContext` and `ActionContext`
|
|
178
|
-
both satisfy it.
|
|
179
|
-
|
|
180
|
-
**Revocation scopes** (`auth/audit_log_schema.ts`) —
|
|
181
|
-
`audit_event_revocation_scopes` declares, per builtin event type, what a
|
|
182
|
-
successful row invalidates (`RevocationScope`: `none` / `session` / `token` /
|
|
183
|
-
`account` / `role`), and `to_revocation_scope(event_type)` reads it (an unknown
|
|
184
|
-
event type is `none`). Typed over `AuditEventType`, so a new event type does not
|
|
185
|
-
compile until it declares its scope. The revocation listener
|
|
186
|
-
(`create_revocation_guard`, `actions/connection_closer.ts`) dispatches on it. Twin of the
|
|
187
|
-
`revocation_scope` column on the Rust `AUDIT_EVENT_SPECS`.
|
|
188
|
-
|
|
189
|
-
**Drift counters** (`auth/audit_log_queries.ts`) — `audit_metadata_validation_failures`
|
|
190
|
-
and `audit_unknown_event_type_failures` are process-wide, fail-open
|
|
191
|
-
(write the row anyway). Independent in implementation; under the factory
|
|
192
|
-
they track the same config. Sample via `get_*`; `reset_*` are test-only.
|
|
193
|
-
Another counter lives with the emitter (`auth/audit_emitter.ts`,
|
|
194
|
-
`get_audit_write_failures` / `reset_audit_write_failures`): rows the bound
|
|
195
|
-
emitter's pool write failed to insert. That write is fail-open too — logged,
|
|
196
|
-
counted, the request proceeds — so the count is how a lost row is seen.
|
|
86
|
+
`auth/audit_emitter.ts` defines `AuditEmitter`, the capability on
|
|
87
|
+
`AppDeps.audit`, built once by the consumer's `audit_factory` over
|
|
88
|
+
`create_audit_emitter`. Its module doc owns the rules ("Where a row is
|
|
89
|
+
written", "When listeners hear about a row"); in short:
|
|
90
|
+
|
|
91
|
+
- `emit` is async — always `await` it. A **success** row is written in the
|
|
92
|
+
transaction of the change it reports, last before the commit; a refused
|
|
93
|
+
INSERT fails the change, and with no transaction open `emit` throws. A
|
|
94
|
+
**failure** row is a fail-open pool write that survives the rollback.
|
|
95
|
+
- Listeners hear a failure row when it is written and a success row only
|
|
96
|
+
after its transaction commits — never on a rollback. The revocation guard
|
|
97
|
+
and the audit stream act on success rows, so announcing one early would
|
|
98
|
+
close connections for a revocation that might not land.
|
|
99
|
+
- `emit_role_grant_target` lifts the actor/account/ip boilerplate for
|
|
100
|
+
role-grant-shape rows; `emit_pool` is for code with no request (never a
|
|
101
|
+
success row paired with a mutation); `notify` announces rows a query wrote
|
|
102
|
+
in its own transaction; `drain_inflight` is what `AppServer.close` and
|
|
103
|
+
`_testing_drain_effects` wait on.
|
|
104
|
+
- `create_app_server` registers the audit-stream listener and the one
|
|
105
|
+
revocation guard through `add_listener`, and removes them on a failed
|
|
106
|
+
assembly or `AppServer.close` — the emitter outlives any one server.
|
|
107
|
+
- The drift counters (metadata validation, unknown event type, failed pool
|
|
108
|
+
write, success row outside a transaction) are process-wide and fail-open;
|
|
109
|
+
`install_audit_drift_guard` holds them at zero per test.
|
|
110
|
+
|
|
111
|
+
**Revocation scopes** — `audit_event_revocation_scopes`
|
|
112
|
+
(`auth/audit_log_schema.ts`) declares, per builtin event type, what a
|
|
113
|
+
successful row invalidates (`none` / `session` / `token` / `account` /
|
|
114
|
+
`role`), read by `to_revocation_scope` and dispatched on by
|
|
115
|
+
`create_revocation_guard`. Typed over `AuditEventType`, so a new builtin
|
|
116
|
+
does not compile until it declares its scope. Twin of the Rust
|
|
117
|
+
`AUDIT_EVENT_SPECS` `revocation_scope` column.
|
|
197
118
|
|
|
198
119
|
### Routes
|
|
199
120
|
|
|
200
|
-
- `auth/account_routes.ts` — `POST /login
|
|
201
|
-
- `auth/bootstrap_routes.ts` — `POST /bootstrap
|
|
202
|
-
- `auth/signup_routes.ts` — `POST /signup
|
|
203
|
-
- `auth/audit_log_routes.ts` — optional `GET /audit/stream` (SSE); list
|
|
204
|
-
- `auth/auth_guard_resolver.ts` — `fuz_auth_guard_resolver
|
|
205
|
-
|
|
206
|
-
**Hono-free route shapes.** Each cookie
|
|
207
|
-
`*_route_schema.ts`
|
|
208
|
-
`
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
`@fuzdev/fuz_schema` schemas: `/login` takes `UsernameProvided` and
|
|
222
|
-
`PasswordProvided`; the output `username` of `/logout`, `/signup` and
|
|
223
|
-
`/bootstrap` is a `UsernameCanonical`; `/password`'s revoke counts are
|
|
224
|
-
non-negative integers; `/bootstrap`'s `token` is 1 to
|
|
225
|
-
`BOOTSTRAP_TOKEN_LENGTH_MAX` (4096, the token file's cap) UTF-16 code units,
|
|
226
|
-
a longer one a `400 invalid_request_body` before the window check, with no
|
|
227
|
-
audit row — twin of the Rust `BOOTSTRAP_TOKEN_LENGTH_MAX`.
|
|
228
|
-
|
|
229
|
-
**`POST /login` timing floor.** Login 401s are floored to
|
|
230
|
-
`DEFAULT_LOGIN_FAIL_FLOOR_MS` (250ms) + uniform jitter (±25ms) via
|
|
231
|
-
`start_fail_floor` (`auth/fail_floor.ts`, shared with signup's 403 / 409
|
|
232
|
-
floor; twin of the Rust `fuz_auth::timing`), started before the work and
|
|
233
|
-
awaited after, so observed time is `max(work, delay)` and
|
|
234
|
-
found-wrong-password and not-found paths converge. 429 stays fast by design;
|
|
235
|
-
`verify_dummy` equalizes Argon2id timing on not-found. A floor of `0` or less
|
|
236
|
-
is announced once per process on stderr by `warn_if_fail_floor_disabled`
|
|
237
|
-
(`LOGIN_` / `SIGNUP_FAIL_FLOOR_DISABLED_BANNER`, the Rust spine's text).
|
|
238
|
-
|
|
239
|
-
**`POST /password` revokes everything.** Revokes all sessions + all API
|
|
240
|
-
tokens (force re-auth everywhere), then clears the session cookie. Declares
|
|
241
|
-
`credential_types: ['session']` (see ../../../docs/security.md
|
|
121
|
+
- `auth/account_routes.ts` — `POST /login`, `/logout`, `/password`, `GET /status`. Rules on `create_account_route_specs`; the close-after-commit split is below.
|
|
122
|
+
- `auth/bootstrap_routes.ts` — `POST /bootstrap`, `is_bootstrap_available` (the boot report), the `BootstrapStatus` ref. A success sets the daemon-token keeper (`daemon_token_state`) after its commit. The lock-race loser answers with no audit row.
|
|
123
|
+
- `auth/signup_routes.ts` — `POST /signup`, open or invite-gated; the success row last in its transaction, an unclassified failure a `signup` failure row with reason `internal_error`.
|
|
124
|
+
- `auth/audit_log_routes.ts` — the optional `GET /audit/stream` (SSE); list and history are RPC. Admission is two-phase (register pending, re-read the credential and role grants, admit), so a revocation racing the request opens no stream.
|
|
125
|
+
- `auth/auth_guard_resolver.ts` — `fuz_auth_guard_resolver`, injected into `apply_route_specs` so `http/` stays auth-agnostic; the one site every route spec passes, so it also refuses a malformed `required_scope` and one on an unrestricted route.
|
|
126
|
+
|
|
127
|
+
**Hono-free route shapes.** Each cookie- or SSE-coupled route module has a
|
|
128
|
+
sibling `*_route_schema.ts` holding its I/O schemas and route _shapes_
|
|
129
|
+
(`Omit<RouteSpec, 'handler'>`). The live factory attaches the handler; a
|
|
130
|
+
cross-process surface builder attaches a stub. One source for the live route
|
|
131
|
+
and the attack surface, and a Rust-only cross-process suite imports the
|
|
132
|
+
shapes without the `hono` peer. Shared limits (`DEFAULT_MAX_SESSIONS` /
|
|
133
|
+
`_TOKENS`) live in `account_route_schema.ts` for the same reason.
|
|
134
|
+
|
|
135
|
+
**`POST /login` timing floor.** Login 401s are floored (`start_fail_floor`,
|
|
136
|
+
`auth/fail_floor.ts`, shared with signup's 403 / 409; twin of the Rust
|
|
137
|
+
`fuz_auth::timing`) so found-wrong-password and not-found converge; 429
|
|
138
|
+
stays fast by design. A disabled floor is announced once per process.
|
|
139
|
+
|
|
140
|
+
**`POST /password` revokes everything** — every session and API token —
|
|
141
|
+
then clears the cookie. Session-only (../../../docs/security.md
|
|
242
142
|
§Credential-channel gating).
|
|
243
143
|
|
|
244
|
-
**The routes close what they revoke, after the commit.** `/logout`
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
`
|
|
248
|
-
|
|
144
|
+
**The routes close what they revoke, after the commit.** `/logout` closes
|
|
145
|
+
the one session it ends (the account's other sessions and tokens stay
|
|
146
|
+
valid) through the route transaction's post-commit queue
|
|
147
|
+
(`queue_connection_close`). `/login` (the sessions its cap evicts) and
|
|
148
|
+
`/password` (the account) open their own transaction around just their
|
|
149
|
+
writes and close straight after it commits
|
|
150
|
+
(`close_connections_after_commit`), so a later throw can't drop a close a
|
|
151
|
+
committed revocation owes.
|
|
249
152
|
|
|
250
|
-
|
|
251
|
-
`/
|
|
252
|
-
|
|
153
|
+
Of the auth surface only `/login`, `/logout`, `/password`, `/status`,
|
|
154
|
+
`/signup`, `/bootstrap` and the optional `/audit/stream` are REST;
|
|
155
|
+
everything else is under §RPC action surfaces.
|
|
253
156
|
|
|
254
157
|
### Middleware
|
|
255
158
|
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
159
|
+
The credential legs, their order, the chain reset, the origin carve-outs and
|
|
160
|
+
the assembly asserts (`assert_endpoint_in_auth_scope`,
|
|
161
|
+
`assert_credential_routes_in_auth_scope`, `assert_middleware_stack_mounted`)
|
|
162
|
+
are root ../../../CLAUDE.md §Middleware Ordering — its origin-verification
|
|
163
|
+
and credential-leg layers (daemon token, session parsing, request context,
|
|
164
|
+
bearer auth) and the `transform_middleware` paragraph. The modules:
|
|
165
|
+
|
|
166
|
+
- `auth/middleware.ts` — `create_auth_middleware_specs(deps, options)`, the stack `create_app_server` mounts at `AUTH_MIDDLEWARE_PATH` (the origin check at `'*'`), and the assembly asserts above.
|
|
167
|
+
- `auth/session_middleware.ts` — the session leg's cookie read and the clear of a present, invalid cookie. A route sets or clears the cookie only on its success result (`route_ok(value, {set_cookie})` with `sign_session_cookie` / `format_session_clear_cookie`); nothing writes a cookie on the context but the middleware's clear.
|
|
168
|
+
- `auth/request_context.ts` — `RequestContext`, `resolve_acting_actor`, `apply_authorization_phase`, the predicates (`has_scoped_role`, `has_any_scoped_role` — builtin-role checks read the **global** grant, `scope_id` null), the guards (`require_auth`, `require_role`, `require_credential_types`, `require_token_scope`), `get_public_account` (what a `reads_credential` route may read — `null` for a scope-narrowed token), and `RequestContextForAuth`, the narrowing a route's `route.auth` and an action's `ctx.auth` share.
|
|
169
|
+
- `auth/resolved_auth.ts` — `ResolvedAuth`, the resolved credential as one union on `credential_type`, carrying the account row the leg read (the authorization phase builds on it rather than reading again). `revalidate_resolved_auth` is the no-touch re-read a long-lived connection (WS, the audit stream) runs between registering pending and admitting.
|
|
170
|
+
- `auth/credential_deadline.ts` — when a resolved credential stops authenticating, which an open WebSocket or audit stream closes at (expiry writes nothing a revocation listener hears). Survives host suspend and `setTimeout`'s ceiling; rules in its TSDoc.
|
|
171
|
+
- `auth/bearer_auth.ts` — the soft-fail bearer leg; a request with any `Origin` or `Referer` line discards the token.
|
|
172
|
+
- `auth/daemon_token_middleware.ts` — the daemon token **consumer** only, soft-fail on every non-success path. The producer (`write_daemon_token`, `start_daemon_token_rotation`) is in `testing/daemon_token_rotation.ts` behind the dev-env guard — no production assembly mints daemon tokens, as on the Rust spine.
|
|
267
173
|
|
|
268
174
|
### Cell layer
|
|
269
175
|
|
|
270
176
|
The cell content primitive's wire schemas, RPC handlers, and authz live
|
|
271
|
-
here; the schema
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
- `
|
|
283
|
-
|
|
284
|
-
`
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
- `auth/
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
defense-in-depth). "Admin" on every tier is the **global** grant — a
|
|
310
|
-
scoped `admin` row bypasses nothing. `can_view_cell`'s public and grant
|
|
311
|
-
arms also require the cell's `moderation` to admit an audience
|
|
312
|
-
(`db/cell_moderation.ts`: unmoderated or `approved`), so a pending or
|
|
313
|
-
rejected contribution is its author's and admins' alone; `can_edit_cell`'s
|
|
314
|
-
editor-grant arm requires the same admission. `can_steward_cell`
|
|
315
|
-
is the separate moderator read: the governing root's manager on a pending or
|
|
316
|
-
rejected contribution under a live root.
|
|
317
|
-
- `auth/cell_steward.ts` — `cell_steward_admits(deps, auth, cell)`: the steward
|
|
318
|
-
arm with its governing-root load, run only after `can_view_cell` denies. Its
|
|
319
|
-
module doc names where the arm applies (`cell_get`, `cell_moderate`, the
|
|
320
|
-
cell-scoped fact route, `cell_list`'s SQL) and where it must not (clone,
|
|
321
|
-
contribution parents, relation reads, `shared_with`, grant recompute).
|
|
322
|
-
- Strict relation-read visibility — every relation read drops edges whose far
|
|
323
|
-
endpoint the caller can't view, so a viewer of a parent can't enumerate
|
|
324
|
-
private linked cells by id. **Forward and reverse** `cell_field_list` /
|
|
325
|
-
`cell_item_list` filter in SQL before their limit
|
|
326
|
-
(`db/cell_view_sql.ts`'s `can_view_cell_sql`, bound through
|
|
327
|
-
`cell_viewer_from_auth`), so a page is up to `limit` edges whose other end
|
|
328
|
-
the caller can view — `CELL_RELATION_LIST_LIMIT_DEFAULT` (50) when omitted,
|
|
329
|
-
`CELL_RELATION_LIST_LIMIT_MAX` (500) at most
|
|
330
|
-
(`auth/cell_relation_list_limit.ts`), and hidden ends never crowd out
|
|
331
|
-
visible ones. The `cell_get` bundle (whose `*_truncated` counts raw edges)
|
|
332
|
-
and the clone walk read with `CELL_VIEWER_UNRESTRICTED` and filter after,
|
|
333
|
-
through `auth/cell_relation_visibility.ts`'s `filter_visible_target_ids(deps,
|
|
334
|
-
auth, ids)`: two queries for the whole id-set, the cells read through the
|
|
335
|
-
narrow `CELL_VIEW_COLUMNS` projection (`query_cell_view_load_many`), never
|
|
336
|
-
the payload.
|
|
337
|
-
- `auth/cell_actions.ts` — `create_cell_actions(deps)`, the generic
|
|
338
|
-
handlers. `cell_create` stamps `created_by` + writes the top-level `kind`
|
|
339
|
-
column; `path` writes are admin-only. It also resolves the directory tree:
|
|
340
|
-
`parent_id` (wire) → the governing `root_id` (`parent.root_id ?? parent.id`),
|
|
341
|
-
**404**-masking a hidden parent. `cell_update` gates `visibility`
|
|
342
|
-
writes on `can_manage_cell` (`ERROR_CELL_VISIBILITY_MANAGE_ONLY`) and
|
|
343
|
-
**never touches `kind`** / `parent_id` / `root_id` / `moderation` (all
|
|
344
|
-
write-once-at-birth or control-gated, never on the update patch).
|
|
345
|
-
`cell_get` bundles visibility-filtered `fields` + `items` (one over the cap
|
|
346
|
-
for truncation detection). `cell_clone` deep-walks viewable children only
|
|
347
|
-
(each clone inherits its source's `kind`; clones are unparented), and runs
|
|
348
|
-
the mounted `authorize_create` for **every** cell it writes as a parentless
|
|
349
|
-
create — a denial is the same 403 `cell_create_forbidden`, so clone is no
|
|
350
|
-
side door past the creation policy. The optional
|
|
351
|
-
parent-aware `authorize_create` dep (`CellCreateAuthorize` — an object whose
|
|
352
|
-
`authorize` takes a wider input `{kind, data, parent_id, parent_kind,
|
|
353
|
-
root_id, root_policy}` than `validate_data` and returns a `CellCreateVerdict`
|
|
354
|
-
`{allow:false} | {allow:true, moderation_required}`, and whose optional
|
|
355
|
-
`validate_policy` accepts or refuses a root policy write)
|
|
356
|
-
gates create by capability; it runs after the validator + the parent-resolve
|
|
357
|
-
(which **404**s `cell_not_found` on a missing or soft-deleted root as on a
|
|
358
|
-
missing parent, authorizer or not).
|
|
359
|
-
A **viewable**-parent / root-creation deny is **403** `cell_create_forbidden`
|
|
360
|
-
(the create-path **404** mask is reserved for a hidden parent); `Allow` folds
|
|
361
|
-
the moderation outcome (born `pending`+private vs `approved`+author-visibility).
|
|
362
|
-
The handler reads the governing root in-tx and hands its `policy` column
|
|
363
|
-
over as `root_policy`, so a directory policy resolves `root_policy[kind]`
|
|
364
|
-
without a DB read; an authorizer needing more reads through its third
|
|
365
|
-
argument, the request `ctx` (`ctx.db` is the request transaction), and only
|
|
366
|
-
reads. `None`/omitted = open
|
|
367
|
-
create (the default; mirrors `validate_data`), and every non-null policy write
|
|
368
|
-
refused `cell_policy_unsupported`. A root's `policy` (a JSON object, roots only
|
|
369
|
-
by table CHECK, opaque to the spine, readable on `CellJson`) is set at a
|
|
370
|
-
root's `cell_create` and changed only by `cell_policy_set` — the 404 mask, then
|
|
371
|
-
manage-tier (403 `cell_policy_manage_only`, an editor grant included), then
|
|
372
|
-
root-only (400 `cell_policy_root_only`), then the authorizer's
|
|
373
|
-
`validate_policy`; audited with the new and the previous policy. `cell_update`
|
|
374
|
-
never writes it (an editor can rewrite `data`, so a policy read from `data`
|
|
375
|
-
would be the editor's to loosen), and a clone is born without one.
|
|
376
|
-
`cell_moderate` is the `pending → approved | rejected` transition (plus
|
|
377
|
-
`approved → rejected`, the takedown), gated on
|
|
378
|
-
`can_manage_cell` of the **governing root** (admin / root owner — the author
|
|
379
|
-
lands a 403, the anti-self-approval guard; a root owner reaches the check
|
|
380
|
-
through the steward arm); approve flips
|
|
381
|
-
`moderation → approved` + `visibility → public`, reject sets `rejected`
|
|
382
|
-
(visibility untouched). The write carries the from-state: approve moves only
|
|
383
|
-
a pending contribution, reject a pending or approved one (the takedown); any
|
|
384
|
-
other transition answers 400 `cell_not_pending`.
|
|
385
|
-
- `auth/cell_action_helpers.ts` — the cell verbs' shared gates, each loading
|
|
386
|
-
the cell and 404-masking a miss and a denial alike
|
|
387
|
-
(`require_viewable_cell` — `auth` may be `null`, which reads no grants —
|
|
388
|
-
`require_editable_cell`, `require_manageable_cell`), plus
|
|
389
|
-
`cell_not_found_error` and `emit_cell_audit(ctx, audit, auth, event_type,
|
|
390
|
-
metadata)`. Twins of the Rust `fuz_cell_actions` helpers.
|
|
391
|
-
- `auth/cell_ref_admission.ts` — `require_new_refs_held`, the
|
|
392
|
-
possession gate `cell_create` / `cell_update` / `cell_clone` run last before
|
|
393
|
-
their write: a non-admin write introducing a fact ref (beyond the cell's
|
|
394
|
-
current refs on update, each cloned row's source refs on clone) that its
|
|
395
|
-
acting actor holds no `fact_holder` row for is 403 `cell_ref_not_held`,
|
|
396
|
-
answered from holder rows alone (stored and unstored hashes read the same);
|
|
397
|
-
a schema without the fact chain refuses every new ref. Global admin bypasses;
|
|
398
|
-
a scoped admin doesn't. Twin of the Rust `cell_ref_admission`.
|
|
399
|
-
- `auth/cell_grant_actions.ts` / `cell_field_actions.ts` /
|
|
400
|
-
`cell_item_actions.ts` / `cell_audit_actions.ts` — the relation + ACL +
|
|
401
|
-
audit handlers, exporting `to_grant_json` / `to_field_json` /
|
|
402
|
-
`to_item_json` reused by the `cell_get` bundle. `cell_grant_create` takes an
|
|
403
|
-
optional `authorize_grant_create` (`CellGrantCreateAuthorize`), asked of a
|
|
404
|
-
manager after the spine's gates and before the write (a level change too);
|
|
405
|
-
`false` is 403 `cell_grant_not_authorized`, nothing written.
|
|
406
|
-
`cell_grant_revoke` takes an optional `authorize_grant_revoke`
|
|
407
|
-
(`CellGrantRevokeAuthorize`), the steward widening: asked only of a caller
|
|
408
|
-
who neither manages the cell nor holds the grant, for a role-shaped grant
|
|
409
|
-
with a `scope_id`; `true` revokes (audit `steward: true`) with a delete
|
|
410
|
-
matching the level it saw, `false` keeps the 404 mask. Both callbacks, like
|
|
411
|
-
the create authorizer and the offer callback, take the request `ctx` last —
|
|
412
|
-
`ctx.db` is the request transaction — and must only read through it.
|
|
413
|
-
- `auth/all_cell_actions.ts` — `create_all_cell_actions(deps, {roles})`, the
|
|
414
|
-
handler-side twin of `all_cell_action_specs` and sibling of
|
|
415
|
-
`create_standard_rpc_actions`: bundles all five cell factories (CRUD + grant
|
|
416
|
-
- field + item + audit) into one list. Reach for this whenever a backend
|
|
417
|
-
mounts the full cell layer — a single source so an HTTP-RPC mount and a WS
|
|
418
|
-
mount (or two backends) can't diverge on which cell verbs they expose.
|
|
419
|
-
Distinct from `create_cell_actions` (the CRUD-only factory it bundles).
|
|
420
|
-
- `auth/cell_audit_metadata.ts` + `cell_grant_audit_metadata.ts` +
|
|
421
|
-
`cell_field_audit_metadata.ts` + `cell_item_audit_metadata.ts` — audit
|
|
422
|
-
metadata envelopes (IDs only), `@fuzdev/fuz_schema` `loose_object`s,
|
|
423
|
-
registered via `extra_events:` on the consumer's `create_audit_log_config`.
|
|
424
|
-
- `auth/cell_audit_events.ts` — `cell_audit_events`, the canonical
|
|
425
|
-
`event_type → metadata` map bundling every cell-domain audit event.
|
|
426
|
-
Consumers spread it into `extra_events` to register the whole layer in
|
|
427
|
-
one call (aggregator by design, not a compat shim).
|
|
428
|
-
|
|
429
|
-
The cell event types (`cell_create` / `_update` / `_delete` / `_clone` /
|
|
430
|
-
`_moderate`, `cell_policy_set`, `cell_grant_create` / `_revoke`, `cell_field_set` / `_delete`,
|
|
431
|
-
`cell_item_insert` / `_move` / `_delete`) are consumer-registered extras,
|
|
432
|
-
not built-ins — see §Audit event extensibility.
|
|
177
|
+
here; the schema and queries live in `db/` (`db/CLAUDE.md` §Cell layer). The
|
|
178
|
+
handler semantics are `auth/cell_actions.ts`'s module TSDoc; the model for
|
|
179
|
+
consumers is ../../../docs/usage.md §Cell data layer, and the security
|
|
180
|
+
properties (moderation gates reads, root policy is manage-tier) are
|
|
181
|
+
../../../docs/security.md §Authorization.
|
|
182
|
+
|
|
183
|
+
Rules a caller would miss:
|
|
184
|
+
|
|
185
|
+
- **Generic only** — no app vocabulary on the wire. Per-kind shape is the
|
|
186
|
+
consumer's `validate_data(kind, data)` on `CellActionDeps`, which accepts or
|
|
187
|
+
throws and never rewrites.
|
|
188
|
+
- **`kind` is not in `data`** — it is the top-level, write-once `cell.kind`
|
|
189
|
+
column; a stray `kind` in `data` is refused (`ERROR_CELL_KIND_IN_DATA`).
|
|
190
|
+
`parent_id` / `root_id` / `moderation` are likewise top-level and never on
|
|
191
|
+
the update patch.
|
|
192
|
+
- **Consumer callbacks only read.** `authorize_create`,
|
|
193
|
+
`authorize_grant_create`, `authorize_grant_revoke` (and the offer
|
|
194
|
+
`authorize`) take the request `ctx` last; `ctx.db` is the request
|
|
195
|
+
transaction.
|
|
196
|
+
- **A clone is no side door**: it runs `authorize_create` for every cell it
|
|
197
|
+
writes as a parentless create.
|
|
198
|
+
- **Every miss and denial on a gated read is a 404**, so a private cell's
|
|
199
|
+
existence doesn't leak.
|
|
200
|
+
|
|
201
|
+
Modules:
|
|
202
|
+
|
|
203
|
+
- `auth/cell_data_schema.ts` — `CellData`, the base a per-kind schema spreads.
|
|
204
|
+
- `auth/cell_action_specs.ts` — `CellJson`, `CellPolicy`, the generic verb specs (`cell_create / get / update / delete / list / clone / moderate / policy_set`), and `all_cell_action_specs`, which spreads the grant, field, item and audit registries in so codegen sees one cell namespace.
|
|
205
|
+
- `auth/cell_grant_action_specs.ts` / `cell_field_action_specs.ts` / `cell_item_action_specs.ts` / `cell_audit_action_specs.ts` — the relation, ACL and audit-timeline specs.
|
|
206
|
+
- `auth/cell_authorize.ts` — the pure view / edit / manage predicates. Manage (global admin or the `created_by` actor) is not a grant level and not delegable; "admin" is always the **global** grant. `can_steward_cell` is the separate moderator read.
|
|
207
|
+
- `auth/cell_steward.ts` — `cell_steward_admits`; its module doc names where the steward arm applies and where it must not.
|
|
208
|
+
- `auth/cell_relation_visibility.ts`, `auth/cell_relation_list_limit.ts` — strict relation-read visibility: every relation read drops edges whose far endpoint the caller can't view.
|
|
209
|
+
- `auth/cell_actions.ts` — `create_cell_actions(deps)`, the CRUD, clone, moderate and policy handlers.
|
|
210
|
+
- `auth/cell_action_helpers.ts` — the shared load-and-404-mask gates and `emit_cell_audit`; twins of the Rust `fuz_cell_actions` helpers.
|
|
211
|
+
- `auth/cell_ref_admission.ts` — `require_new_refs_held`: a non-admin write introducing a fact ref its actor holds no `fact_holder` row for is 403 `cell_ref_not_held`. Twin of the Rust `cell_ref_admission`.
|
|
212
|
+
- `auth/cell_grant_actions.ts` / `cell_field_actions.ts` / `cell_item_actions.ts` / `cell_audit_actions.ts` — the relation, ACL and audit handlers.
|
|
213
|
+
- `auth/all_cell_actions.ts` — `create_all_cell_actions(deps, {roles})`, the handler twin of `all_cell_action_specs`. Reach for it whenever a backend mounts the full cell layer, so an HTTP-RPC mount and a WS mount can't diverge.
|
|
214
|
+
- `auth/cell_audit_events.ts` (and the `cell_*_audit_metadata.ts` modules) — `cell_audit_events`, the cell event types' metadata map; consumers spread it into `extra_events`. The cell events are consumer-registered extras, not builtins (§Audit event extensibility).
|
|
433
215
|
|
|
434
216
|
## Cross-cutting invariants
|
|
435
217
|
|
|
436
|
-
The things that span multiple files and don't fit on any one symbol's TSDoc.
|
|
437
|
-
|
|
438
218
|
### Two-phase identity
|
|
439
219
|
|
|
440
|
-
**Authentication runs in middleware** (
|
|
441
|
-
|
|
442
|
-
Account-only — never loads actor or role_grants
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
`
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
path populates `REQUEST_CONTEXT_KEY`; it sets only `RESOLVED_AUTH_KEY`. Test
|
|
471
|
-
harnesses pre-populate `REQUEST_CONTEXT_KEY` and set `TEST_CONTEXT_PRESET_KEY`
|
|
472
|
-
to the `TEST_CONTEXT_PRESET` symbol to bypass DB-backed actor resolution
|
|
473
|
-
(`has_test_context_preset` reads it; any other value, `true` or a string
|
|
474
|
-
included, is unset); production code that reads `REQUEST_CONTEXT_KEY` is
|
|
475
|
-
reading test escape-hatch state.
|
|
476
|
-
|
|
477
|
-
**The session token key is fixed.** The session middleware writes the token
|
|
478
|
-
under `SESSION_TOKEN_KEY` (`hono_context.ts`, `'auth_session_id'`) and the
|
|
479
|
-
session leg reads it there; `SessionOptions` carries no context key, so the two
|
|
480
|
-
cannot disagree and the token cannot land on another spine key.
|
|
220
|
+
**Authentication runs in middleware** (daemon token / session / bearer) and
|
|
221
|
+
sets one `ResolvedAuth` (`RESOLVED_AUTH_KEY`) on a valid credential.
|
|
222
|
+
Account-only — never loads actor or role_grants.
|
|
223
|
+
|
|
224
|
+
**Authorization runs before input validation**, per route and per action
|
|
225
|
+
(`http/CLAUDE.md` §Validation pipeline for the full phase order). When the
|
|
226
|
+
input declares `acting?: ActingActor` or the auth requires role_grants,
|
|
227
|
+
the authorization phase resolves the acting actor and builds an actor-bound
|
|
228
|
+
`RequestContext`; a malformed selector reads as omitted (it only ever picks
|
|
229
|
+
among actors the account owns, and validation rejects it a step later).
|
|
230
|
+
Account-grain routes run with `RequestContext.actor: null`, so a multi-actor
|
|
231
|
+
account can log out without picking a persona.
|
|
232
|
+
|
|
233
|
+
`apply_authorization_phase` is pure data — it returns `AuthorizationResult`
|
|
234
|
+
and each transport binds a failure to its wire shape. The one 500 is
|
|
235
|
+
`no_actors_on_account` (a live account with no active actor). It builds on
|
|
236
|
+
the credential leg's account row: an account removed after that read runs an
|
|
237
|
+
account-grain handler on the row, while an actor-grain one finds no actor and
|
|
238
|
+
answers the dead credential's 401, as on the Rust spine.
|
|
239
|
+
|
|
240
|
+
**Production-middleware invariant.** The credential legs set only
|
|
241
|
+
`RESOLVED_AUTH_KEY`. The route pipeline's authorization phase writes the
|
|
242
|
+
actor-bound context to `REQUEST_CONTEXT_KEY`, which `require_role` reads.
|
|
243
|
+
Test harnesses pre-set `REQUEST_CONTEXT_KEY` and set
|
|
244
|
+
`TEST_CONTEXT_PRESET_KEY` to the `TEST_CONTEXT_PRESET` symbol to skip
|
|
245
|
+
DB-backed resolution (`has_test_context_preset`; any other value is unset).
|
|
246
|
+
|
|
247
|
+
**The session token key is fixed** (`SESSION_TOKEN_KEY`): the session
|
|
248
|
+
middleware takes only the cookie's name, no context key, so it and the leg
|
|
249
|
+
cannot disagree.
|
|
481
250
|
|
|
482
251
|
### Row locks
|
|
483
252
|
|
|
484
253
|
One class order in every transaction — accounts, then offers, then grants and
|
|
485
254
|
actors — and id order within a class. Every writer of an account takes its row
|
|
486
255
|
first (two mints of one account take turns there, so the caps hold); a
|
|
487
|
-
multi-row write
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
256
|
+
multi-row write locks its rows in one id-ordered statement before writing.
|
|
257
|
+
Each lock's strength and reason is on its query's TSDoc; the rule set:
|
|
258
|
+
../../../docs/security.md §Row Locks. `lock_pins.cross.test.ts` pins them on
|
|
259
|
+
both spines (../../test/CLAUDE.md).
|
|
491
260
|
|
|
492
261
|
### Wire timestamp shape
|
|
493
262
|
|
|
494
|
-
Every timestamp
|
|
495
|
-
`
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
`
|
|
501
|
-
|
|
502
|
-
`to_iso8601_seconds` (`timestamp.ts`), so the mint and the later
|
|
503
|
-
`account_token_list` read agree byte for byte.
|
|
504
|
-
|
|
505
|
-
The `*Json` schemas type these as `Timestamp` (`iso_datetime`), which a
|
|
506
|
-
millisecond stamp also satisfies — so the shape is pinned behaviorally by
|
|
507
|
-
`assert_iso8601_seconds` (`testing/cross_backend/wire_shapes.ts`) inside the
|
|
508
|
-
shared suites, on both backends.
|
|
509
|
-
|
|
510
|
-
The alias costs one rule: **an `ORDER BY` in a projected SELECT qualifies
|
|
511
|
-
its column** (`ORDER BY auth_session.created_at`) — bare, Postgres resolves
|
|
512
|
-
it to the formatted output column, which ties rows written inside the same
|
|
513
|
-
second and drops the btree index. Qualified, ordering stays exact and
|
|
514
|
-
index-backed, matching the Rust twin (which aliases nothing, so its bare
|
|
515
|
-
`ORDER BY created_at` already means the column).
|
|
263
|
+
Every wire timestamp is second-precision UTC, the shape both spines emit
|
|
264
|
+
(`timestamp.ts`). Rows get it from the SQL projection
|
|
265
|
+
(`iso8601_timestamp_column`, `db/sql_columns.ts`, which also owns the one
|
|
266
|
+
rule it costs: an `ORDER BY` in a projected SELECT qualifies its column);
|
|
267
|
+
stamps minted in TS use `to_iso8601_seconds`. `Timestamp` also admits
|
|
268
|
+
milliseconds, so the shape is pinned behaviorally by
|
|
269
|
+
`assert_iso8601_seconds` (`testing/cross_backend/wire_shapes.ts`) on both
|
|
270
|
+
backends.
|
|
516
271
|
|
|
517
272
|
### Open-registry composition
|
|
518
273
|
|
|
519
|
-
Four open
|
|
520
|
-
`CredentialTypeName`, `GrantPathName` — share
|
|
521
|
-
construction-time
|
|
522
|
-
|
|
523
|
-
cross-axis validation
|
|
524
|
-
letters joined by single underscores, at most `NAME_LENGTH_MAX` characters
|
|
525
|
-
(`auth/name_schema.ts`), which a token's `surface:` name holds too.
|
|
526
|
-
|
|
527
|
-
Dependency flow:
|
|
274
|
+
Four open name registries — `RoleName`, `ScopeKindName`,
|
|
275
|
+
`CredentialTypeName`, `GrantPathName` — share one factory shape
|
|
276
|
+
(construction-time grammar, duplicate and builtin-collision checks,
|
|
277
|
+
`ReadonlyMap` output) and one name grammar (`auth/name_schema.ts`), and
|
|
278
|
+
compose into `create_role_registry` for cross-axis validation:
|
|
528
279
|
|
|
529
280
|
```
|
|
530
281
|
create_credential_type_registry()
|
|
@@ -532,379 +283,188 @@ create_scope_kind_registry() → create_role_registry({roles, options})
|
|
|
532
283
|
create_grant_path_registry()
|
|
533
284
|
```
|
|
534
285
|
|
|
535
|
-
`role_specs` drives
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
`AuditEventTypeName` is the fifth open registry but composes differently —
|
|
541
|
-
via `create_audit_log_config({extra_events})` into the bound emitter.
|
|
286
|
+
`role_specs` drives the defaults: `admin_actions.grantable_roles` (roles with
|
|
287
|
+
the `admin` grant path) and the self-service eligible set (roles with
|
|
288
|
+
`self_service`). `AuditEventTypeName` is a fifth open registry that composes
|
|
289
|
+
differently — `create_audit_log_config({extra_events})` into the emitter.
|
|
542
290
|
|
|
543
291
|
### Audit `target_*_id` rules
|
|
544
292
|
|
|
545
|
-
The two target columns on `AuditLogEvent` populate by a single rule:
|
|
546
293
|
**`target_actor_id` is set when the event subject is bound to a specific
|
|
547
|
-
actor**; `target_account_id` is
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
-
|
|
555
|
-
the subject regardless of initiator). Use `audit.emit_role_grant_target`
|
|
556
|
-
to lift the `actor_id` / `account_id` / `ip` boilerplate.
|
|
557
|
-
- **Offer-shape events** (`role_grant_offer_create` / `_expire` / `_retract` /
|
|
558
|
-
`_supersede`) populate `target_actor_id` only when the offer was
|
|
559
|
-
actor-targeted at create time (`role_grant_offer.to_actor_id` set).
|
|
294
|
+
actor**; `target_account_id` whenever there is an account subject. The full
|
|
295
|
+
per-event table is the `AuditLogEvent.actor_id` / `target_actor_id` TSDoc.
|
|
296
|
+
The pattern across emit sites:
|
|
297
|
+
|
|
298
|
+
- **Role-grant-shape events** populate both targets — the grantee actor is
|
|
299
|
+
the subject whoever initiated. Use `audit.emit_role_grant_target`.
|
|
300
|
+
- **Offer-shape events** populate `target_actor_id` only when the offer was
|
|
301
|
+
actor-targeted (`role_grant_offer.to_actor_id` set).
|
|
560
302
|
- **Account-shape events** (login, logout, signup, bootstrap, password
|
|
561
|
-
change, session/token revoke,
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
303
|
+
change, session/token revoke, app_settings_update) stay account-grain on
|
|
304
|
+
`target_actor_id`. `actor_id` is null except on signup and bootstrap, which
|
|
305
|
+
name the actor they create.
|
|
306
|
+
- **Invite events** carry the acting `actor_id` and no target. A delete of a
|
|
307
|
+
missing invite writes a failure row with `attempted_invite_id`.
|
|
308
|
+
- **Account removal** writes the account event plus one per actor
|
|
309
|
+
(`actor_delete` / `_purge` / `_undelete`, `target_actor_id` the actor), each
|
|
310
|
+
snapshotting the identity into metadata, since `audit_log` ids carry no FK.
|
|
311
|
+
|
|
312
|
+
A connection close keyed on an audit row follows the row's revocation scope:
|
|
313
|
+
`account` and `role` key on `target_account_id ?? account_id`, `session` and
|
|
314
|
+
`token` on the row's metadata (`actions/CLAUDE.md` §Revocation guard).
|
|
565
315
|
|
|
566
316
|
### Audit event extensibility
|
|
567
317
|
|
|
568
|
-
Consumers extend the closed `AUDIT_EVENT_TYPES`
|
|
569
|
-
`create_audit_log_config({extra_events})` — a
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
`
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
`
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
### `AUDIT_EVENT_TYPES` builtins
|
|
586
|
-
|
|
587
|
-
For quick reference; the source-of-truth list is the `Object.freeze`d
|
|
588
|
-
constant in `auth/audit_log_schema.ts`.
|
|
589
|
-
|
|
590
|
-
```
|
|
591
|
-
login role_grant_create
|
|
592
|
-
logout role_grant_revoke
|
|
593
|
-
bootstrap role_grant_offer_create
|
|
594
|
-
signup role_grant_offer_accept
|
|
595
|
-
password_change role_grant_offer_decline
|
|
596
|
-
session_revoke role_grant_offer_retract
|
|
597
|
-
session_revoke_all role_grant_offer_expire
|
|
598
|
-
token_create role_grant_offer_supersede
|
|
599
|
-
token_revoke invite_create
|
|
600
|
-
token_revoke_all invite_delete
|
|
601
|
-
account_delete app_settings_update
|
|
602
|
-
account_purge db_admin_row_delete
|
|
603
|
-
account_undelete
|
|
604
|
-
actor_delete
|
|
605
|
-
actor_purge
|
|
606
|
-
actor_undelete
|
|
607
|
-
```
|
|
608
|
-
|
|
609
|
-
`account_delete` / `account_purge` / `account_undelete` snapshot
|
|
610
|
-
`{username, email}` into metadata; `actor_delete` / `actor_purge` /
|
|
611
|
-
`actor_undelete` snapshot `{name}`. The account-level handlers emit the
|
|
612
|
-
account event plus one per-actor event (`delete` = soft, `purge` = hard,
|
|
613
|
-
`undelete` = reactivation — see ../../../docs/security.md §Authorization,
|
|
614
|
-
"Account-removal target guards").
|
|
615
|
-
|
|
616
|
-
`role_grant_offer_supersede` carries
|
|
617
|
-
`reason: 'sibling_accepted' | 'role_grant_revoked' | 'scope_destroyed' | 'account_deleted'` (for `account_deleted`, `cause_id` is the removed account, the grantor's or the recipient's)
|
|
618
|
-
plus `cause_id` pointing to the row that triggered the supersede. The WS
|
|
619
|
-
`role_grant_offer_supersede` notification's reason set is narrower —
|
|
620
|
-
`sibling_accepted | role_grant_revoked | account_deleted`; `scope_destroyed`
|
|
621
|
-
is an audit reason only (a consumer's own cascade writes it).
|
|
318
|
+
Consumers extend the closed `AUDIT_EVENT_TYPES` via
|
|
319
|
+
`create_audit_log_config({extra_events})` — a fuz_schema metadata schema or
|
|
320
|
+
`null` per type; a collision with a builtin, an off-grammar name, or a value
|
|
321
|
+
that is no schema throws at construction. The DB column is `TEXT NOT NULL`,
|
|
322
|
+
and the read side (`AuditLogEvent.event_type`, the wire row, the
|
|
323
|
+
`audit_log_list` filter) is the widened `AuditEventTypeName`, so consumer
|
|
324
|
+
rows round-trip like builtins. The write side (`AuditLogInput<T>`,
|
|
325
|
+
`AuditMetadataMap`) stays closed so a builtin's metadata narrows by its
|
|
326
|
+
type. An unknown type or a metadata mismatch is logged and counted, and the
|
|
327
|
+
row written anyway; a failed pool write logs the lost row with its secret
|
|
328
|
+
fields masked.
|
|
329
|
+
|
|
330
|
+
`role_grant_offer_supersede` carries `reason` (`sibling_accepted` /
|
|
331
|
+
`role_grant_revoked` / `scope_destroyed` / `account_deleted`) and `cause_id`,
|
|
332
|
+
the row that triggered it. `scope_destroyed` is an audit reason only (a
|
|
333
|
+
consumer's own cascade writes it); the WS notification's set omits it.
|
|
622
334
|
|
|
623
335
|
### Keeper auth shape
|
|
624
336
|
|
|
625
337
|
Keeper is not a dedicated guard — it's a composable `RouteAuth` shape:
|
|
626
338
|
`{account: 'required', actor: 'required', roles: ['keeper'], credential_types: ['daemon_token']}`.
|
|
627
|
-
The
|
|
628
|
-
`ERROR_CREDENTIAL_TYPE_REQUIRED`)
|
|
629
|
-
(403 `ERROR_INSUFFICIENT_PERMISSIONS`)
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
in the HTTP RPC dispatcher (`actions/action_rpc.ts`), the WS dispatcher
|
|
634
|
-
(`actions/register_action_ws.ts`), and the admin bypasses inside
|
|
339
|
+
The channel gate (`require_credential_types`, 403
|
|
340
|
+
`ERROR_CREDENTIAL_TYPE_REQUIRED`) runs pre-authorization and the role gate
|
|
341
|
+
(`require_role`, 403 `ERROR_INSUFFICIENT_PERMISSIONS`) post-authorization,
|
|
342
|
+
so a non-daemon credential is refused before the route resolves an actor
|
|
343
|
+
for it. The same scope-aware check runs for actions in
|
|
344
|
+
`actions/perform_action.ts` (both dispatchers) and in the admin bypasses of
|
|
635
345
|
`auth/role_grant_offer_actions.ts`.
|
|
636
346
|
|
|
637
347
|
### Migrations
|
|
638
348
|
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
the
|
|
642
|
-
|
|
643
|
-
`
|
|
644
|
-
|
|
645
|
-
unless it is the spine's own object (`AUTH_MIGRATION_NS`, `CELL_MIGRATION_NS`,
|
|
646
|
-
`FACT_MIGRATION_NS`, each built by `create_spine_migration_namespace`). Runner contract, error vocabulary, and
|
|
647
|
-
operator recipes (rename, mark applied, reset, baseline) are in
|
|
648
|
-
../../../docs/migrations.md.
|
|
349
|
+
`auth/migrations.ts` — a frozen, append-only chain (`full_auth_schema`
|
|
350
|
+
first) under the reserved namespace `'fuz_auth'` (`AUTH_MIGRATION_NS`), each
|
|
351
|
+
entry twinned by name on the Rust spine. The reserved names are
|
|
352
|
+
`reserved_migration_namespaces` in `db/migrate.ts`, a consumer namespace under
|
|
353
|
+
one refused as `namespace-reserved`; that refusal, the runner contract, and the
|
|
354
|
+
operator recipes are ../../../docs/migrations.md.
|
|
649
355
|
|
|
650
356
|
## RPC action surfaces
|
|
651
357
|
|
|
652
|
-
Each registry splits across `*_action_specs.ts` (schemas
|
|
653
|
-
codegen
|
|
654
|
-
|
|
655
|
-
|
|
358
|
+
Each registry splits across `*_action_specs.ts` (schemas, specs, registry —
|
|
359
|
+
what client codegen imports, without the handlers' query-layer deps) and
|
|
360
|
+
`*_actions.ts` (`create_*_actions(deps, options)`). The spec modules carry
|
|
361
|
+
each action's input, output, auth and `error_reasons`; the handler modules'
|
|
362
|
+
TSDoc carries their semantics. This section keeps what spans actions.
|
|
656
363
|
|
|
657
|
-
- `create_admin_actions` —
|
|
658
|
-
- `create_role_grant_offer_actions` —
|
|
659
|
-
- `create_account_actions` —
|
|
660
|
-
- `create_self_service_role_actions` —
|
|
661
|
-
- `create_actor_lookup_actions` —
|
|
662
|
-
- `create_actor_search_actions` —
|
|
364
|
+
- `create_admin_actions` — `all_admin_action_specs` — bundled in `create_standard_rpc_actions`.
|
|
365
|
+
- `create_role_grant_offer_actions` — `all_role_grant_offer_action_specs` — bundled.
|
|
366
|
+
- `create_account_actions` — `all_account_action_specs` — bundled.
|
|
367
|
+
- `create_self_service_role_actions` — `all_self_service_role_action_specs` — not bundled (`eligible_roles` is app-specific).
|
|
368
|
+
- `create_actor_lookup_actions` — `all_actor_lookup_action_specs` — not bundled (opt-in id → label resolver).
|
|
369
|
+
- `create_actor_search_actions` — `all_actor_search_action_specs` — not bundled (opt-in prefix-search picker).
|
|
663
370
|
|
|
664
|
-
`auth/all_action_spec_registries.ts` exposes
|
|
665
|
-
for registry-wide invariant tests
|
|
666
|
-
|
|
371
|
+
`auth/all_action_spec_registries.ts` exposes
|
|
372
|
+
`all_fuz_auth_action_spec_registries` for registry-wide invariant tests — not
|
|
373
|
+
a mounting surface; protocol specs excluded.
|
|
667
374
|
|
|
668
375
|
### Authorization patterns
|
|
669
376
|
|
|
670
|
-
- **Spec-level enforcement.**
|
|
671
|
-
`auth: {account: 'required', actor: 'required', roles: ['admin']}
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
refers to another account. The spec can't express this because auth runs
|
|
680
|
-
before input parsing.
|
|
377
|
+
- **Spec-level enforcement.** Admin specs declare
|
|
378
|
+
`auth: {account: 'required', actor: 'required', roles: ['admin']}`, checked
|
|
379
|
+
per spec, so mixed-auth factories compose (`role_grant_revoke` is
|
|
380
|
+
admin-gated beside non-admin offer siblings).
|
|
381
|
+
- **Input-dependent elevation.** `role_grant_offer_list` / `_history` (GET
|
|
382
|
+
addressable, `side_effects: false`) admit any caller to its own inbox; the
|
|
383
|
+
handler requires admin when `account_id` names another account — auth runs
|
|
384
|
+
before input parsing, so the spec can't say it. `account_delete`'s self
|
|
385
|
+
path is session-only the same way.
|
|
681
386
|
- **Account-grain self-service.** `account_*` specs declare
|
|
682
|
-
`
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
`
|
|
691
|
-
|
|
692
|
-
resulting grant outlives revoking the token. `role_grant_offer_create`
|
|
693
|
-
carries it for the same pivot onto another account (a leaked bearer offers a
|
|
694
|
-
role to an account its holder controls); scripted conferral is
|
|
695
|
-
`role_grant_assign`'s.
|
|
696
|
-
REST `POST /logout` also declares `credential_types: ['session']`, but
|
|
697
|
-
for forensic fidelity rather than a threat — a bearer / daemon token
|
|
698
|
-
holds no session to end, so the gate refuses it instead of returning a
|
|
699
|
-
misleading 200 + a phantom `logout` audit row. `GET /audit/stream` carries
|
|
700
|
-
it so the stream stays closable (SSE subscribers are keyed by session
|
|
701
|
-
hash, so `token_revoke` could not close a bearer's stream).
|
|
702
|
-
Admin token/session revoke specs deliberately stay unrestricted (admin
|
|
703
|
-
scripting from CLI/bearer is legitimate operator workflow). See
|
|
704
|
-
../../../docs/security.md §Credential-channel gating.
|
|
705
|
-
- **Rate-limit posture.** Admin specs and authed-spam-prone surfaces
|
|
706
|
-
(`role_grant_offer_create`, `role_grant_revoke`, `account_token_create`,
|
|
707
|
-
`self_service_role_set`, `actor_lookup`, `actor_search`) declare
|
|
708
|
-
`rate_limit: 'account'`. Throttle-requests semantics — every invocation
|
|
709
|
-
records, regardless of outcome. Default
|
|
710
|
-
`default_action_account_rate_limit` is 1200/15min per actor.
|
|
387
|
+
`actor: 'none'`, with no `acting` on the input; IDOR is the account-scoped
|
|
388
|
+
queries.
|
|
389
|
+
- **Credential-channel gating** — which specs and routes are session-only,
|
|
390
|
+
and why (`/logout` for forensic fidelity; `/audit/stream` because a
|
|
391
|
+
long-lived admin feed is not handed to a channel the deployment never
|
|
392
|
+
chose): ../../../docs/security.md §Credential-channel gating. Every gated
|
|
393
|
+
event records `credential_type` in its metadata.
|
|
394
|
+
- **Rate limits.** Admin specs and the spam-prone surfaces declare
|
|
395
|
+
`rate_limit: 'account'`, which records every invocation whatever its
|
|
396
|
+
outcome (`default_action_account_rate_limit`, keyed per account).
|
|
711
397
|
|
|
712
398
|
### Admin actions
|
|
713
399
|
|
|
714
400
|
`create_admin_actions(deps, options?)` in `auth/admin_actions.ts`.
|
|
715
401
|
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
- `
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
Constants: `AUDIT_LOG_LIST_LIMIT_MAX = 200`, `ADMIN_ACCOUNT_LIST_DEFAULT_LIMIT = 50`,
|
|
741
|
-
`ADMIN_ACCOUNT_LIST_LIMIT_MAX = 200`.
|
|
742
|
-
|
|
743
|
-
Error reasons via `error.data.reason`: `ERROR_ACCOUNT_NOT_FOUND` (404 via
|
|
744
|
-
`jsonrpc_errors.not_found`) on admin revoke-all + account delete/purge,
|
|
745
|
-
`ERROR_INSUFFICIENT_PERMISSIONS` (403) when `account_delete` targets another
|
|
746
|
-
account without admin, `ERROR_PURGE_NOT_CONFIRMED` (400) when `account_purge`
|
|
747
|
-
omits `confirm: true`, `ERROR_CANNOT_DELETE_KEEPER` (403) when `account_delete` /
|
|
748
|
-
`account_purge` targets a keeper-role account (the keeper account is never
|
|
749
|
-
API-removable — auth + daemon-token both pivot on it),
|
|
750
|
-
`ERROR_CANNOT_DELETE_LAST_ADMIN` (403) when `account_delete` / `account_purge`
|
|
751
|
-
targets the sole remaining active admin (soft-deleted admins don't count; the
|
|
752
|
-
count locks its rows, so concurrent removals can't both pass), `ERROR_INVITE_ACCOUNT_EXISTS_USERNAME` /
|
|
753
|
-
`_EMAIL` / `ERROR_INVITE_DUPLICATE` on invite create, `ERROR_INVITE_NOT_FOUND`
|
|
754
|
-
on invite delete. `invite_create` empty input is rejected at the schema by a
|
|
755
|
-
`check` and surfaces as `invalid_params` with `error.data.issues` (DEV-only `WireIssue`s).
|
|
756
|
-
|
|
757
|
-
Closure state:
|
|
758
|
-
|
|
759
|
-
- `grantable_roles` derived once from `options.roles?.role_specs ?? builtin_role_specs`
|
|
760
|
-
via `list_roles_with_grant_path(_, GRANT_PATH_ADMIN)`.
|
|
761
|
-
- `app_settings_get`/`_update` handlers are always wired and read/write the DB
|
|
762
|
-
directly (`query_app_settings_load`/`query_app_settings_update`);
|
|
763
|
-
`auth/signup_routes.ts` reads the current value fresh per request. There is no
|
|
764
|
-
`options.app_settings` ref.
|
|
765
|
-
- `deps.connection_closer` (required, `RevokingActionFactoryDeps`) —
|
|
766
|
-
`admin_session_revoke_all` / `admin_token_revoke_all` / `account_delete` /
|
|
767
|
-
`account_purge` queue a close of the target account's live connections
|
|
768
|
-
(`queue_connection_close`), run after the handler's transaction commits and
|
|
769
|
-
dropped if it throws. The close does not depend on the audit write; the
|
|
770
|
-
audit listeners repeat it on the announced row. Failure outcomes queue no
|
|
771
|
-
close.
|
|
772
|
-
|
|
773
|
-
Failure-outcome audit rows: `admin_session_revoke_all` and `_token_revoke_all`
|
|
774
|
-
emit an `outcome: 'failure'` row on `ERROR_ACCOUNT_NOT_FOUND` for forensic
|
|
775
|
-
visibility — `target_account_id` is null (FK rejects missing ids), and the
|
|
776
|
-
probed id is preserved under `metadata.attempted_account_id`. Every gated
|
|
777
|
-
event additionally records `credential_type` in metadata (defense in depth).
|
|
402
|
+
- **`account_delete` / `account_purge` / `account_undelete` carry `account_*`
|
|
403
|
+
names**, not `admin_`: privilege lives in the auth spec, so soft delete
|
|
404
|
+
stays self-service. They sit in the admin factory because their actor-grain
|
|
405
|
+
shape and queries match it. `account_undelete` is admin-only — a tombstoned
|
|
406
|
+
account can't authenticate, so there is no self path.
|
|
407
|
+
- **Account removal** (delete and purge alike) supersedes every pending offer
|
|
408
|
+
the account made and every one made to it (`account_deleted`, audited and
|
|
409
|
+
notified), deletes the unclaimed invites it issued, revokes its sessions and
|
|
410
|
+
tokens, and writes the account row plus one per actor. Delete keeps the role
|
|
411
|
+
grants, inert; purge is the keeper-only cascading delete with
|
|
412
|
+
`confirm: true`. The target guards (never a keeper account, never the last
|
|
413
|
+
active admin) and what an undelete restores are ../../../docs/security.md
|
|
414
|
+
§Authorization.
|
|
415
|
+
- **Failure rows on a miss.** `admin_session_revoke_all`,
|
|
416
|
+
`admin_token_revoke_all`, account delete / purge and `invite_delete` write
|
|
417
|
+
a failure row on a missing target, the probed id in metadata
|
|
418
|
+
(`attempted_account_id`, `attempted_invite_id`) since the FK rejects it.
|
|
419
|
+
- **Closure state.** `grantable_roles` is derived once from
|
|
420
|
+
`options.roles?.role_specs ?? builtin_role_specs`. App settings are read and
|
|
421
|
+
written in the database; signup reads `open_signup` fresh per request, so
|
|
422
|
+
there is no shared in-memory ref.
|
|
423
|
+
- **Closes.** The revoke-alls and the account removals queue a close of the
|
|
424
|
+
target account's connections (`queue_connection_close`), after the commit
|
|
425
|
+
and independent of the audit row; failure outcomes queue none.
|
|
778
426
|
|
|
779
427
|
### Role-grant-offer actions
|
|
780
428
|
|
|
781
429
|
`create_role_grant_offer_actions(deps, options?)` in
|
|
782
|
-
`auth/role_grant_offer_actions.ts
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
> `
|
|
787
|
-
>
|
|
788
|
-
> `testing/admin_integration.ts`
|
|
789
|
-
>
|
|
790
|
-
> `testing/db_entities.ts`
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
-
|
|
807
|
-
|
|
808
|
-
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
the locked count `query_count_active_accounts_with_global_role_locked`,
|
|
815
|
-
which leaves the revoked grant out — §Row locks). Besides the revokee's
|
|
816
|
-
incoming sibling offers, the revoke supersedes every pending offer the
|
|
817
|
-
revokee's actor made (`query_role_grant_offer_supersede_outgoing`);
|
|
818
|
-
`account_delete` / `account_purge` supersede both directions for the whole
|
|
819
|
-
account (`reason: 'account_deleted'`). Every supersede cascade returns —
|
|
820
|
-
and audits and notifies — its rows ordered by `created_at, id`; who is
|
|
821
|
-
told: §WS notifications.
|
|
822
|
-
- `role_grant_assign_action_spec` — global-admin-only immediate conferral (no
|
|
823
|
-
consent step); input `{to_account_id, to_actor_id?, role, scope_kind?, scope_id?}`
|
|
824
|
-
(the pair as on offer-create); output `{ok, role_grant_id}`. The handler:
|
|
825
|
-
- re-checks the global admin grant behind the dispatcher gate;
|
|
826
|
-
- runs the same admin-grant-path gate as offer-create, and refuses a scoped
|
|
827
|
-
`admin` (`invalid_params` + `ERROR_ROLE_GRANT_BUILTIN_SCOPED`; a scoped
|
|
828
|
-
`keeper` stays 403 `ERROR_ROLE_NOT_WEB_GRANTABLE`, since `keeper` is never
|
|
829
|
-
web-grantable);
|
|
830
|
-
- runs the consumer's `RoleGrantOfferCreateAuthorize` callback (the offer
|
|
831
|
-
policy binds the consent-free path too — a refusal is 403
|
|
832
|
-
`ERROR_ROLE_GRANT_OFFER_NOT_AUTHORIZED`, failure-audited);
|
|
833
|
-
- resolves the target actor (named `to_actor_id` ∈ the account's active
|
|
834
|
-
actors, else its sole active actor — multi-actor → `invalid_params`,
|
|
835
|
-
actorless → 404);
|
|
836
|
-
- writes the `(scope_kind, scope_id)` pair via the idempotent
|
|
837
|
-
`query_create_role_grant`, and emits a `role_grant_create` audit row
|
|
838
|
-
(metadata carries `scope_kind`, success and failure).
|
|
839
|
-
|
|
840
|
-
No WS notification in v1. Reasons: `ERROR_INSUFFICIENT_PERMISSIONS`,
|
|
841
|
-
`ERROR_ROLE_NOT_WEB_GRANTABLE`, `ERROR_ROLE_GRANT_BUILTIN_SCOPED`,
|
|
842
|
-
`ERROR_ROLE_GRANT_OFFER_NOT_AUTHORIZED`,
|
|
843
|
-
`ERROR_ROLE_GRANT_OFFER_ACTOR_ACCOUNT_MISMATCH`.
|
|
844
|
-
|
|
845
|
-
Every input carries `acting?: ActingActor` (registry-time invariant 2).
|
|
846
|
-
`role_grant_revoke` keys on **`actor_id`**, not `account_id` — role_grants
|
|
847
|
-
are actor-scoped and deriving actor from account collapses under multi-actor
|
|
848
|
-
accounts.
|
|
849
|
-
|
|
850
|
-
`role_grant_offer_create` runs the **admin-grantability gate first** (offered
|
|
851
|
-
role's `RoleSpec.grant_paths` must include `'admin'`), then the
|
|
852
|
-
`RoleGrantOfferCreateAuthorize` callback. **Default `default_authorize`: the
|
|
853
|
-
caller must hold a _global_ `admin` grant** — conferral is admin-only, with no
|
|
854
|
-
holder-propagation (holding the offered role confers no power to offer it). The
|
|
855
|
-
global check (`has_scoped_role(_, ROLE_ADMIN, null)`) stops a scoped `admin`
|
|
856
|
-
escalating into global authority over the offer surface. A consumer needing
|
|
857
|
-
scope-aware delegation (e.g. a classroom teacher offering within their own
|
|
858
|
-
scope) supplies a custom `authorize` callback. The callback receives
|
|
859
|
-
`{to_account_id, role, scope_kind, scope_id}` and the request `ctx` (`ctx.db` is
|
|
860
|
-
the request transaction, for read-only checks), and also gates
|
|
861
|
-
`role_grant_assign`.
|
|
862
|
-
|
|
863
|
-
**Builtin roles (`admin` / `keeper`) are global-only**, decided by the spine
|
|
864
|
-
ahead of any callback. Offer-create refuses a scoped `admin`
|
|
865
|
-
(`invalid_params` + `ERROR_ROLE_GRANT_BUILTIN_SCOPED`; `keeper`, scoped or not,
|
|
866
|
-
stays 403 `ERROR_ROLE_GRANT_OFFER_ROLE_NOT_GRANTABLE` at the grant-path gate)
|
|
867
|
-
and a builtin offered by
|
|
868
|
-
a caller without a global `admin` (`ERROR_ROLE_GRANT_OFFER_NOT_AUTHORIZED`), so
|
|
869
|
-
a consumer callback only ever sees app roles or a global admin's unscoped
|
|
870
|
-
builtin offer. Accept (`query_accept_offer`, the chokepoint where an offer
|
|
871
|
-
becomes a grant) refuses a `keeper` offer (`ERROR_ROLE_GRANT_OFFER_ROLE_NOT_GRANTABLE`),
|
|
872
|
-
a scoped `admin` offer (`invalid_request` + `ERROR_ROLE_GRANT_BUILTIN_SCOPED`), and a
|
|
873
|
-
builtin offer whose grantor no longer holds an active global `admin` on an
|
|
874
|
-
active actor of an active account (`ERROR_ROLE_GRANT_OFFER_NOT_AUTHORIZED`,
|
|
875
|
-
read under the grantor's account lock) — via
|
|
876
|
-
`RoleGrantOfferBuiltinRefusedError` (`refusal: BuiltinOfferRefusal`). Each
|
|
877
|
-
refusal leaves the offer pending and is audited as a failed
|
|
878
|
-
`role_grant_offer_accept` with `{offer_id, role, scope_id, reason}`. The
|
|
879
|
-
grantor re-check is builtin-only: an app-role offer's authority was the
|
|
880
|
-
callback's call at create time.
|
|
881
|
-
|
|
882
|
-
Error reasons (`as const` literals):
|
|
883
|
-
|
|
884
|
-
- `ERROR_ROLE_GRANT_OFFER_SELF_TARGET`
|
|
885
|
-
- `ERROR_ROLE_GRANT_OFFER_TERMINAL`
|
|
886
|
-
- `ERROR_ROLE_GRANT_OFFER_EXPIRED`
|
|
887
|
-
- `ERROR_ROLE_GRANT_OFFER_NOT_FOUND` (404-over-403 IDOR mask)
|
|
888
|
-
- `ERROR_ROLE_GRANT_OFFER_ROLE_NOT_GRANTABLE`
|
|
889
|
-
- `ERROR_ROLE_GRANT_OFFER_NOT_AUTHORIZED`
|
|
890
|
-
- `ERROR_ROLE_GRANT_OFFER_ACTOR_ACCOUNT_MISMATCH` (supplied `to_actor_id` doesn't belong to `to_account_id`)
|
|
891
|
-
- `ERROR_ROLE_GRANT_OFFER_ACTOR_MISMATCH` (actor-targeted offer accepted by wrong actor)
|
|
892
|
-
- `ERROR_ROLE_GRANT_BUILTIN_SCOPED` (a grant path asked to bind `admin` / `keeper` to a scope)
|
|
893
|
-
|
|
894
|
-
Plus re-uses from `http/error_schemas.ts`: `ERROR_ROLE_GRANT_NOT_FOUND`,
|
|
895
|
-
`ERROR_ROLE_NOT_WEB_GRANTABLE`, `ERROR_INSUFFICIENT_PERMISSIONS`,
|
|
896
|
-
`ERROR_ACCOUNT_NOT_FOUND`. Each spec declares the reason codes its handler
|
|
897
|
-
may surface via `spec.error_reasons`; drift is caught per-module by
|
|
898
|
-
../../test/auth/role_grant_offer_actions.error_reasons.test.ts.
|
|
899
|
-
|
|
900
|
-
Failure-outcome audits use `emit_create_failure_audit` /
|
|
901
|
-
`emit_revoke_failure_audit` so all denial paths land uniform rows; the
|
|
902
|
-
admin-role-denied path (pre-IDOR) on `role_grant_revoke` emits no audit,
|
|
903
|
-
matching the middleware auth-guard precedent.
|
|
430
|
+
`auth/role_grant_offer_actions.ts`; the authorization rules per action are
|
|
431
|
+
its module TSDoc, the threat model ../../../docs/security.md §Authorization
|
|
432
|
+
(builtin roles global-only, consentful grants, the supersede cascade).
|
|
433
|
+
|
|
434
|
+
> **Hazard — `role_grant_offer_create` does not auto-accept**, admin or not.
|
|
435
|
+
> It returns `{offer}`; acceptance is a separate `role_grant_offer_accept`.
|
|
436
|
+
> A test that needs a grant drives offer + accept (`testing/admin_integration.ts`
|
|
437
|
+
> `offer_and_accept`) or skips the consent path with
|
|
438
|
+
> `create_test_role_grant_direct` (`testing/db_entities.ts`).
|
|
439
|
+
|
|
440
|
+
- **Default `authorize`: the caller holds a _global_ `admin` grant.** No
|
|
441
|
+
holder-propagation — holding a role confers no power to offer it. A
|
|
442
|
+
consumer needing scope-aware delegation (a teacher offering within their
|
|
443
|
+
classroom) supplies `authorize` (`RoleGrantOfferCreateAuthorize`), which
|
|
444
|
+
also gates `role_grant_assign`. It runs after the admin-grant-path gate and
|
|
445
|
+
only ever sees app roles or a global admin's unscoped builtin offer — the
|
|
446
|
+
builtin rules are decided first.
|
|
447
|
+
- **`role_grant_revoke` keys on `actor_id`**, not `account_id`: grants are
|
|
448
|
+
actor-scoped, and deriving the actor collapses under multi-actor accounts.
|
|
449
|
+
A revoke supersedes the revokee's incoming siblings and every offer its
|
|
450
|
+
actor made (`query_revoke_role_grant`, shared with the self-service
|
|
451
|
+
disable). A global grant's revoke queues a role-gated close of the
|
|
452
|
+
revokee's connections; a scoped revoke closes nothing, since a role gate
|
|
453
|
+
admits on global grants alone.
|
|
454
|
+
- **`role_grant_assign`** is the global-admin-only consent-free path; it
|
|
455
|
+
sends no WS notification.
|
|
456
|
+
- **Denials are audited uniformly** as failure rows; the admin-role denial on
|
|
457
|
+
`role_grant_revoke` (pre-IDOR) writes none, as an auth-guard refusal
|
|
458
|
+
doesn't. Supersede rows go through `emit_supersede_audits`, shared by both
|
|
459
|
+
revokes and account removal, as in the Rust twin.
|
|
460
|
+
- `error_reasons` drift is pinned per module by
|
|
461
|
+
../../test/auth/role_grant_offer_actions.error_reasons.test.ts.
|
|
904
462
|
|
|
905
463
|
#### WS notifications
|
|
906
464
|
|
|
907
|
-
Post-commit via `emit_after_commit` (
|
|
465
|
+
Post-commit via `emit_after_commit` (`http/CLAUDE.md` §Pending Effects),
|
|
466
|
+
through `ctx.notification_sender` (`actions/CLAUDE.md` §Notification
|
|
467
|
+
sender):
|
|
908
468
|
|
|
909
469
|
- Create — `role_grant_offer_received` → recipient.
|
|
910
470
|
- Retract — `role_grant_offer_retracted` → recipient.
|
|
@@ -912,240 +472,86 @@ Post-commit via `emit_after_commit` (see `http/CLAUDE.md` §Pending Effects):
|
|
|
912
472
|
- Decline — `role_grant_offer_declined` → grantor.
|
|
913
473
|
- Revoke (`role_grant_revoke`) — `role_grant_revoked` → revokee + `_supersede` per superseded offer (the revokee's incoming siblings and its own outgoing offers), each to its grantor and its recipient.
|
|
914
474
|
- Delete / purge (`account_delete`, `account_purge`) — `_supersede` (`account_deleted`) per superseded offer to the live party: the recipient of each offer the account made, the grantor of each offer made to it. The removed account hears nothing (its sockets close).
|
|
915
|
-
- Self-service disable — `_supersede` per
|
|
916
|
-
|
|
917
|
-
`queue_supersede_notifications
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
`
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
`scope_kind` and `scope_id` both `null` for a global grant, every key
|
|
928
|
-
required. `role_grant_offer_notification_actions` holds the specs as
|
|
929
|
-
handler-less actions: `to_ws_actions` (`actions/protocol.ts`) appends them to
|
|
930
|
-
the WS action set of an RPC list holding `role_grant_offer_create`, so the WS
|
|
931
|
-
endpoint's surface lists them as `remote_notification` methods. The revokee's
|
|
932
|
-
notification is `role_grant_revoked`, not the admin action's
|
|
933
|
-
`role_grant_revoke`, so the two methods never collide. They never reach
|
|
934
|
-
dispatch: an inbound frame for one is answered `method_not_found`. They are not SSE events; `role_grant_offer_notification_specs`
|
|
935
|
-
holds them as `EventSpec`s for a consumer that broadcasts them on an SSE
|
|
936
|
-
channel of its own. Handlers send through `ctx.notification_sender`
|
|
937
|
-
(`actions/CLAUDE.md` §Notification sender) with `queue_offer_notification` /
|
|
938
|
-
`queue_supersede_notifications`, each queued post-commit.
|
|
939
|
-
|
|
940
|
-
Deps: `RevokingActionFactoryDeps`.
|
|
941
|
-
`role_grant_revoke` of a global grant queues a close of the revokee account's
|
|
942
|
-
connections gated on the role (`queue_connection_close`, `{kind: 'role'}`),
|
|
943
|
-
run after the transaction commits and independent of the audit row's
|
|
944
|
-
announcement; the revocation guard repeats it on the announced row. A scoped revoke
|
|
945
|
-
closes nothing — a role gate admits on global grants alone.
|
|
946
|
-
Target account travels via the send argument, not the payload — `revoked_by`
|
|
947
|
-
is deliberately not in the `role_grant_revoked` payload (the revokee doesn't
|
|
948
|
-
need to learn the admin's identity).
|
|
949
|
-
|
|
950
|
-
Options: `roles?: RoleRegistry` (drives admin-grant-path lookup),
|
|
951
|
-
`default_ttl_ms?` (defaults to `ROLE_GRANT_OFFER_DEFAULT_TTL_MS` = 30 days),
|
|
952
|
-
`authorize?: RoleGrantOfferCreateAuthorize`.
|
|
475
|
+
- Self-service disable — `_supersede` per superseded offer, each to its grantor and its recipient, as the admin revoke (the caller's answer lists no offers).
|
|
476
|
+
|
|
477
|
+
`queue_supersede_notifications` sends in the cascade's row order
|
|
478
|
+
(`created_at, id`), grantor before recipient; `SupersedeAudience` names the
|
|
479
|
+
`cause_id` each party gets (a recipient never learns its grantor's account
|
|
480
|
+
id). The specs are `auth/role_grant_offer_notifications.ts`'s handler-less
|
|
481
|
+
`remote_notification` actions: `to_ws_actions` lists them on a WS endpoint
|
|
482
|
+
holding `role_grant_offer_create`, and an inbound frame for one is
|
|
483
|
+
`method_not_found`. The revokee's method is `role_grant_revoked`, never the
|
|
484
|
+
admin action's `role_grant_revoke`, and its payload omits who revoked.
|
|
485
|
+
`role_grant_offer_notification_specs` holds them as `EventSpec`s for a
|
|
486
|
+
consumer broadcasting them over SSE of its own.
|
|
953
487
|
|
|
954
488
|
### Account actions — self-service
|
|
955
489
|
|
|
956
|
-
`create_account_actions(deps, options?)` in `auth/account_actions.ts
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
- `
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
- `
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
`session_id` validates as `SessionId`, the fuz_schema `Blake3Hash` branded;
|
|
973
|
-
`token_id` as `ApiTokenId` (`tok_[A-Za-z0-9_-]{12}`). Every input and output
|
|
974
|
-
is a `@fuzdev/fuz_schema` schema.
|
|
975
|
-
|
|
976
|
-
Audit events via `deps.audit.emit` with `ip: ctx.client_ip`:
|
|
977
|
-
`session_revoke`, `session_revoke_all`, `token_create`, `token_revoke`. Every
|
|
978
|
-
gated event also records `credential_type` in metadata (mirrors REST
|
|
979
|
-
`password_change`).
|
|
980
|
-
|
|
981
|
-
Options: `max_tokens?: number | null` (defaults to `DEFAULT_MAX_TOKENS`;
|
|
982
|
-
`null` disables). Deps: `RevokingActionFactoryDeps` — `log`, `audit`, and the
|
|
983
|
-
required `connection_closer`. Each revoking handler queues its close
|
|
984
|
-
(`queue_connection_close`: one session, one token, or the account), which runs
|
|
985
|
-
after the handler's transaction commits and is dropped if it throws;
|
|
986
|
-
`account_token_create` queues a token close for each token its cap evicts.
|
|
987
|
-
Failure outcomes (`revoked: false`) queue no close — mirrors the listeners'
|
|
988
|
-
`outcome === 'success'` guard so attacker-guessable ids can't target
|
|
989
|
-
arbitrary connections.
|
|
490
|
+
`create_account_actions(deps, options?)` in `auth/account_actions.ts`
|
|
491
|
+
(session and token list / revoke / revoke-all, token create, and
|
|
492
|
+
`account_verify`).
|
|
493
|
+
|
|
494
|
+
- **`account_verify` is the credential probe** on both spines, callable by a
|
|
495
|
+
narrowed token that names it. There is no REST probe; `GET /status`
|
|
496
|
+
answers a narrowed token as anonymous.
|
|
497
|
+
- **`account_token_create` is default-deny at mint**: `scope` and `lifetime`
|
|
498
|
+
are both required. The token cap (`max_tokens`, `DEFAULT_MAX_TOKENS`,
|
|
499
|
+
`null` disables) evicts the oldest, closing each evicted token's
|
|
500
|
+
connections.
|
|
501
|
+
- **Each revoking handler queues its close** (one session, one token, or the
|
|
502
|
+
account) after the commit. A failure outcome (`revoked: false`) queues
|
|
503
|
+
none, so an attacker-guessable id can't target another user's
|
|
504
|
+
connections — the same reason the revocation guard acts only on success
|
|
505
|
+
rows.
|
|
990
506
|
|
|
991
507
|
### Standard RPC bundle
|
|
992
508
|
|
|
993
|
-
`create_standard_rpc_actions(deps, options)`
|
|
994
|
-
spreads
|
|
995
|
-
`
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
`
|
|
999
|
-
|
|
1000
|
-
Option routing — `roles` is shared between admin + role-grant-offer;
|
|
1001
|
-
`default_ttl_ms` + `authorize` → role-grant-offer
|
|
1002
|
-
only; `max_tokens` → account only. On `deps`: `connection_closer`
|
|
1003
|
-
(required) → admin, account, and role-grant-offer (the role revoke's close).
|
|
1004
|
-
The notification sender is on every action's context, not on `deps`.
|
|
1005
|
-
|
|
1006
|
-
Pair with `create_app_server`'s `rpc_endpoints` factory form
|
|
1007
|
-
`(ctx) => Array<RpcEndpointSpec>` so the combined action list gets
|
|
1008
|
-
`ctx.deps`. `create_app_server` auto-mounts the
|
|
1009
|
-
endpoint via `create_rpc_endpoint`. To expose the standard surface over
|
|
1010
|
-
WebSocket as well, spread `protocol_actions` and the same factory into
|
|
1011
|
-
`ws_endpoints` — per-message authorization and rate limiting fire
|
|
1012
|
-
identically across HTTP RPC and WS.
|
|
1013
|
-
|
|
1014
|
-
Bundling account actions into the "standard" surface is deliberate: the
|
|
1015
|
-
admin integration suite exercises `account_token_create` / `_revoke` for
|
|
1016
|
-
cross-account isolation, so a consumer wiring the admin surface without
|
|
1017
|
-
account actions hits `method_not_found` on first admin-suite run.
|
|
509
|
+
`create_standard_rpc_actions(deps, options)` (`auth/standard_rpc_actions.ts`)
|
|
510
|
+
spreads the admin, role-grant-offer and account factories into one
|
|
511
|
+
`Array<RpcAction>`; the frontend mirror is `all_standard_action_specs`
|
|
512
|
+
(`auth/standard_action_specs.ts`). Option routing: `roles` → admin and
|
|
513
|
+
role-grant-offer; `default_ttl_ms` and `authorize` → role-grant-offer;
|
|
514
|
+
`max_tokens` → account. `deps.connection_closer` reaches all three.
|
|
1018
515
|
|
|
1019
|
-
|
|
516
|
+
Mount it through `create_app_server`'s `rpc_endpoints` factory form
|
|
517
|
+
`(ctx) => Array<RpcEndpointSpec>` so the handlers get `ctx.deps`; over
|
|
518
|
+
WebSocket, the same list goes in `ws_endpoints` (root ../../../CLAUDE.md
|
|
519
|
+
§Action Registries).
|
|
1020
520
|
|
|
1021
|
-
|
|
1022
|
-
`
|
|
1023
|
-
|
|
1024
|
-
caller. Idempotent in both directions (`changed: false` when the post-call
|
|
1025
|
-
state already matched). Its input and output are `@fuzdev/fuz_schema`
|
|
1026
|
-
`object`s, refusing unknown keys, `role` a `RoleName`.
|
|
1027
|
-
|
|
1028
|
-
Audit metadata carries `self_service: true` so admin reviewers can
|
|
1029
|
-
distinguish self-toggled role_grants. Eligibility derives from
|
|
1030
|
-
`roles.role_specs` by selecting roles with `'self_service' ∈ grant_paths`;
|
|
1031
|
-
override via `eligible_roles`. Roles outside the eligible set are rejected
|
|
1032
|
-
with `ERROR_ROLE_NOT_SELF_SERVICE_ELIGIBLE`. The eligible set is validated at
|
|
1033
|
-
construction (`validate_self_service_eligible_roles`): a builtin role or a name
|
|
1034
|
-
outside the `RoleName` grammar throws — self-toggling a builtin would hand any
|
|
1035
|
-
account instance-wide authority.
|
|
1036
|
-
|
|
1037
|
-
Deps are `RevokingActionFactoryDeps`: a disable that revokes queues a close of
|
|
1038
|
-
the caller's connections gated on the role (`queue_connection_close`,
|
|
1039
|
-
`{kind: 'role'}`), after the commit and independent of the audit write.
|
|
1040
|
-
|
|
1041
|
-
Method name is static (`role` lives in input, not method) — per-role
|
|
1042
|
-
parameterized methods would break the `satisfies RequestResponseActionSpec`
|
|
1043
|
-
codegen invariant.
|
|
1044
|
-
|
|
1045
|
-
Bundle **not** included in `create_standard_rpc_actions` — `eligible_roles`
|
|
1046
|
-
is app-specific.
|
|
521
|
+
Bundling the account actions is deliberate: the admin integration suite
|
|
522
|
+
exercises `account_token_create` / `_revoke` for cross-account isolation, so
|
|
523
|
+
a consumer mounting admin without account hits `method_not_found`.
|
|
1047
524
|
|
|
1048
|
-
###
|
|
1049
|
-
|
|
1050
|
-
Two opt-in helpers for surfaces that stamp actor ids (bylines, owner
|
|
1051
|
-
columns, grantor labels, picker UIs):
|
|
1052
|
-
|
|
1053
|
-
- `create_actor_lookup_actions(deps)` — `actor_lookup({ids}) → {actors}`,
|
|
1054
|
-
batched id → label resolver. `ACTOR_LOOKUP_IDS_MAX = 50`.
|
|
1055
|
-
- `create_actor_search_actions(deps)` — `actor_search({query, scope_ids?, limit?}) → {actors}`,
|
|
1056
|
-
prefix search. Default limit `ACTOR_SEARCH_LIMIT_DEFAULT = 20`, cap
|
|
1057
|
-
`_MAX = 50`. Non-admin callers must pass `scope_ids` (filtered to actors
|
|
1058
|
-
holding active role_grants on those scopes); admin-only when `scope_ids`
|
|
1059
|
-
is empty. `ERROR_ACTOR_SEARCH_SCOPE_REQUIRED` on non-admin + empty
|
|
1060
|
-
`scope_ids`.
|
|
1061
|
-
|
|
1062
|
-
Both: `auth: {account: 'required', actor: 'none'}` + `rate_limit: 'account'`,
|
|
1063
|
-
pure reads (no audit, no side effects), their input and output schemas
|
|
1064
|
-
`@fuzdev/fuz_schema` `object`s, which refuse unknown keys. `ActorLookupEntryJson` deliberately
|
|
1065
|
-
omits `account_id`, `email`, credentials, timestamps, and role state —
|
|
1066
|
-
control-plane details, timing-oracle avoidance, separation of concern. LIKE
|
|
1067
|
-
wildcards in the user-supplied query are escaped at the JS layer so
|
|
1068
|
-
`%xyz`-style inputs can't widen the per-call cap.
|
|
525
|
+
### Self-service role toggle
|
|
1069
526
|
|
|
1070
|
-
|
|
527
|
+
`create_self_service_role_actions(deps, {eligible_roles?, roles?})` —
|
|
528
|
+
`self_service_role_set({role, enabled})`, idempotent both ways, audited with
|
|
529
|
+
`self_service: true`. Eligibility defaults to roles with the `self_service`
|
|
530
|
+
grant path; a builtin or off-grammar name in `eligible_roles` throws at
|
|
531
|
+
construction, since self-toggling a builtin would hand any account
|
|
532
|
+
instance-wide authority. A disable revokes through `query_revoke_role_grant`,
|
|
533
|
+
so it supersedes what the admin revoke does and queues the same role-gated
|
|
534
|
+
close. The method is static (`role` is input) so codegen's
|
|
535
|
+
`satisfies RequestResponseActionSpec` holds.
|
|
1071
536
|
|
|
1072
|
-
###
|
|
537
|
+
### Actor lookup / actor search
|
|
1073
538
|
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
`
|
|
1077
|
-
|
|
1078
|
-
`
|
|
539
|
+
Two opt-in, account-grain, rate-limited pure reads for surfaces that stamp
|
|
540
|
+
actor ids (bylines, grantor labels, pickers): `create_actor_lookup_actions`
|
|
541
|
+
(`actor_lookup({ids})`, batched) and `create_actor_search_actions`
|
|
542
|
+
(`actor_search({query, scope_ids?, limit?})`, prefix). A non-admin search
|
|
543
|
+
must pass `scope_ids` (`ERROR_ACTOR_SEARCH_SCOPE_REQUIRED`). The entry shape
|
|
544
|
+
deliberately omits `account_id`, email, credentials, timestamps and role
|
|
545
|
+
state, and LIKE wildcards in the query are escaped so `%`-inputs can't widen
|
|
546
|
+
a call. Caps and limits are on the spec modules.
|
|
1079
547
|
|
|
1080
548
|
## Cleanup
|
|
1081
549
|
|
|
1082
|
-
`auth/cleanup.ts
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
pass at once, then one per interval (`DEFAULT_AUTH_CLEANUP_INTERVAL_MS`, ten
|
|
1091
|
-
minutes), until `stop()`. `create_app_server`'s `auth_cleanup` option calls
|
|
1092
|
-
it with `backend.deps` and chains `stop` into `AppServer.close`. **Off by
|
|
1093
|
-
default** there; a production server turns it on, and an in-process test
|
|
1094
|
-
harness leaves it off (a background pass deletes rows and writes audit rows
|
|
1095
|
-
mid-test).
|
|
1096
|
-
|
|
1097
|
-
`AuthCleanupDeps` is `{db, log, audit, connection_closer}`, all required —
|
|
1098
|
-
`AppDeps` satisfies it. Tests pass `create_test_audit_emitter()` from
|
|
1099
|
-
`testing/stubs.ts` and, where nothing is to be closed, `noop_connection_closer`.
|
|
1100
|
-
The sweep belongs in the process that holds the connections: run from another
|
|
1101
|
-
process against a live server's database, it deletes the rows that server's
|
|
1102
|
-
own pass would have closed for.
|
|
1103
|
-
|
|
1104
|
-
**The session sweep closes what it sweeps.** A connection never re-reads its
|
|
1105
|
-
session, and once the sweep deletes an expired row `account_session_revoke`
|
|
1106
|
-
has nothing left to close for — so `cleanup_expired_sessions` closes each
|
|
1107
|
-
swept session's connections itself, by session id
|
|
1108
|
-
(`connection_closer.close_connections` with a `session` target), which is why
|
|
1109
|
-
`query_session_cleanup_expired` returns the deleted ids. The close repeats
|
|
1110
|
-
one already made: every connection closes at its credential's deadline
|
|
1111
|
-
(`auth/credential_deadline.ts`) in the process holding it, sweep or no sweep.
|
|
1112
|
-
An expired API token's row is not swept; its connections close at their
|
|
1113
|
-
deadline (`account_token_revoke` still finds the row).
|
|
1114
|
-
|
|
1115
|
-
- The delete runs in its own transaction and the closes follow the commit —
|
|
1116
|
-
the rule every revocation close keeps (`actions/CLAUDE.md` §Connection
|
|
1117
|
-
closer).
|
|
1118
|
-
- A transaction that fails once the delete has answered still closes: the
|
|
1119
|
-
sessions are expired either way, the error is thrown after the closes, and
|
|
1120
|
-
the next pass deletes the rows the commit left.
|
|
1121
|
-
- A closer that throws for one session is logged and the rest still close.
|
|
1122
|
-
- No audit row is written for a swept session, so no listener repeats the
|
|
1123
|
-
close.
|
|
1124
|
-
|
|
1125
|
-
**The schedule** is `start_periodic` (`periodic.ts`, twin of the Rust
|
|
1126
|
-
`fuz_sys::periodic::spawn_periodic`), which owns the loop's rules:
|
|
1127
|
-
`start_auth_cleanup` is that loop over `run_auth_cleanup` plus the swept-counts
|
|
1128
|
-
log. Passes never overlap, and a pass that overruns its interval delays the
|
|
1129
|
-
next one (which starts when the slow one ends, the one after a full interval
|
|
1130
|
-
later) rather than bursting. A failed pass is logged at `warn` with its error
|
|
1131
|
-
and retried on the next interval. The timer is unref'd. An interval that is
|
|
1132
|
-
not a positive finite number, or exceeds `PERIODIC_INTERVAL_MS_MAX` (the
|
|
1133
|
-
largest delay a timer honors), throws at the call. **Shutdown differs from
|
|
1134
|
-
Rust**: its task drops a pass in progress; `stop()` ends the schedule at once
|
|
1135
|
-
and its promise resolves when the pass in progress has finished — await it
|
|
1136
|
-
before closing the database. The wait has no bound of its own.
|
|
1137
|
-
|
|
1138
|
-
**Offer idempotency.** `cleanup_expired_role_grant_offers` runs one transaction:
|
|
1139
|
-
`query_role_grant_offer_sweep_expired` claims the expired pending offers not
|
|
1140
|
-
yet audited by stamping `role_grant_offer.expire_audited_at` (`UPDATE …
|
|
1141
|
-
RETURNING`), and each claimed row's `role_grant_offer_expire` audit row is
|
|
1142
|
-
inserted in the same transaction; events fan out via `audit.notify` after the
|
|
1143
|
-
commit. Each expiry is audited exactly once — a second run finds nothing, and
|
|
1144
|
-
concurrent runs claim disjoint rows (a row another sweep holds blocks on its
|
|
1145
|
-
row lock, then fails the re-checked stamp). A failed audit insert rolls the
|
|
1146
|
-
stamps back and the next run retries, so the offer sweep can throw. The stamp
|
|
1147
|
-
is not a lifecycle state (outside the terminal CHECK and the pending
|
|
1148
|
-
predicate) and stays off the wire (`to_role_grant_offer_json` drops it); the
|
|
1149
|
-
create upsert's re-offer clears it, so a refreshed offer's own expiry is
|
|
1150
|
-
audited too. The `role_grant_offer_expire_sweep` partial index serves the
|
|
1151
|
-
claim.
|
|
550
|
+
`auth/cleanup.ts`, twin of the Rust `fuz_auth::auth_cleanup`:
|
|
551
|
+
`run_auth_cleanup` (one pass — the session sweep, which closes the swept
|
|
552
|
+
sessions' connections, then the offer-expiry sweep, audited exactly once)
|
|
553
|
+
and `start_auth_cleanup` (scheduled on `start_periodic`, `periodic.ts`). Off
|
|
554
|
+
by default in `create_app_server`; run it in the process that holds the
|
|
555
|
+
connections, never from another process against a live server's database.
|
|
556
|
+
The rules are the module TSDoc and `periodic.ts`'s (whose `stop()` differs
|
|
557
|
+
from the Rust shutdown); wiring is ../../../docs/usage.md §Auth cleanup.
|