@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
|
@@ -70,10 +70,11 @@ export const AUDIT_EVENT_TYPES = Object.freeze([
|
|
|
70
70
|
* until it declares its scope here.
|
|
71
71
|
*
|
|
72
72
|
* A scope other than `none` marks an event whose success invalidates a live
|
|
73
|
-
* connection's credential or access: `
|
|
73
|
+
* connection's credential or access: `password_change`,
|
|
74
74
|
* `session_revoke_all`, `token_revoke_all`, `account_delete`, and
|
|
75
|
-
* `account_purge` are account-wide, `session_revoke
|
|
76
|
-
* the one credential they ended, and `role_grant_revoke`
|
|
75
|
+
* `account_purge` are account-wide, `session_revoke`, `logout` and
|
|
76
|
+
* `token_revoke` name the one credential they ended, and `role_grant_revoke`
|
|
77
|
+
* names the lost role.
|
|
77
78
|
* Granting access revokes nothing, and neither does an event about a subject
|
|
78
79
|
* other than a connection's identity.
|
|
79
80
|
*
|
|
@@ -82,7 +83,7 @@ export const AUDIT_EVENT_TYPES = Object.freeze([
|
|
|
82
83
|
*/
|
|
83
84
|
export const audit_event_revocation_scopes = Object.freeze({
|
|
84
85
|
login: 'none',
|
|
85
|
-
logout: '
|
|
86
|
+
logout: 'session',
|
|
86
87
|
bootstrap: 'none',
|
|
87
88
|
signup: 'none',
|
|
88
89
|
password_change: 'account',
|
|
@@ -185,7 +186,11 @@ export const audit_metadata_schemas = Object.freeze({
|
|
|
185
186
|
login: nullable(loose_object({
|
|
186
187
|
username: meta(string, { description: 'Username submitted with the login attempt.' })
|
|
187
188
|
})),
|
|
188
|
-
logout:
|
|
189
|
+
logout: loose_object({
|
|
190
|
+
session_id: meta(SessionId, {
|
|
191
|
+
description: 'Blake3 hash identifying the session row the logout ended.'
|
|
192
|
+
})
|
|
193
|
+
}),
|
|
189
194
|
bootstrap: nullable(loose_object({
|
|
190
195
|
error: meta(string, { description: 'Error message for a failed bootstrap attempt.' })
|
|
191
196
|
})),
|
|
@@ -373,8 +378,19 @@ export const audit_metadata_schemas = Object.freeze({
|
|
|
373
378
|
email: meta(nullable(string), { description: 'Invited email address; null when not set.' }),
|
|
374
379
|
username: meta(nullable(string), { description: 'Invited username; null when not set.' })
|
|
375
380
|
}),
|
|
381
|
+
// A delete of an id naming no unclaimed invite writes an `outcome=failure`
|
|
382
|
+
// row with no `invite_id`: `reason` carries the failure category and
|
|
383
|
+
// `attempted_invite_id` the probed id.
|
|
376
384
|
invite_delete: loose_object({
|
|
377
|
-
invite_id: meta(Uuid, {
|
|
385
|
+
invite_id: meta(optional(Uuid), {
|
|
386
|
+
description: 'Id of the deleted invite. Omitted on `outcome=failure`.'
|
|
387
|
+
}),
|
|
388
|
+
reason: meta(optional(string), {
|
|
389
|
+
description: 'Failure category. Set only on `outcome=failure`.'
|
|
390
|
+
}),
|
|
391
|
+
attempted_invite_id: meta(optional(Uuid), {
|
|
392
|
+
description: 'Probed invite id when no unclaimed invite matched. Set only on `outcome=failure`.'
|
|
393
|
+
})
|
|
378
394
|
}),
|
|
379
395
|
// Account/actor deletion snapshots identity into metadata so the
|
|
380
396
|
// identity behind a now-orphaned audit id survives a purge (the
|
|
@@ -382,8 +398,7 @@ export const audit_metadata_schemas = Object.freeze({
|
|
|
382
398
|
// tombstone), `purge` = hard (irreversible cascading removal). Known
|
|
383
399
|
// fields are optional so the same schema validates the success
|
|
384
400
|
// snapshot and the not-found failure shape (`reason` /
|
|
385
|
-
// `attempted_account_id`). See `auth/CLAUDE.md` §
|
|
386
|
-
// (delete = soft, purge = hard).
|
|
401
|
+
// `attempted_account_id`). See `auth/CLAUDE.md` §Admin actions.
|
|
387
402
|
account_delete: loose_object({
|
|
388
403
|
username: meta(optional(string), { description: 'Username at soft-delete time.' }),
|
|
389
404
|
email: meta(optional(nullable(string)), {
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* gate that reads only what the auth middleware already set: `require_auth`
|
|
10
10
|
* whenever `auth.account === 'required'` or `auth.actor === 'required'`
|
|
11
11
|
* (per registry-time invariant 3, `actor: 'required'` today implies a
|
|
12
|
-
* credential — accountless actors are out of scope
|
|
12
|
+
* credential — accountless actors are out of scope),
|
|
13
13
|
* `require_credential_types(types)` whenever `auth.credential_types?.length`,
|
|
14
14
|
* and the token-scope guard whenever `auth.required_scope` names a capability.
|
|
15
15
|
* All three fire before any body parsing, so a caller they refuse never sees
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* gate that reads only what the auth middleware already set: `require_auth`
|
|
10
10
|
* whenever `auth.account === 'required'` or `auth.actor === 'required'`
|
|
11
11
|
* (per registry-time invariant 3, `actor: 'required'` today implies a
|
|
12
|
-
* credential — accountless actors are out of scope
|
|
12
|
+
* credential — accountless actors are out of scope),
|
|
13
13
|
* `require_credential_types(types)` whenever `auth.credential_types?.length`,
|
|
14
14
|
* and the token-scope guard whenever `auth.required_scope` names a capability.
|
|
15
15
|
* All three fire before any body parsing, so a caller they refuse never sees
|
|
@@ -4,11 +4,8 @@
|
|
|
4
4
|
* Bearer tokens are rejected when `Origin` or `Referer` headers are present —
|
|
5
5
|
* browsers must use cookie auth. This reduces attack surface: a stolen token
|
|
6
6
|
* cannot be replayed from a browser context (the browser adds `Origin`
|
|
7
|
-
* automatically). The discard is silent on the wire (anti-enumeration)
|
|
8
|
-
*
|
|
9
|
-
* bearer_discarded_browser_context` response header so tests/tooling can tell
|
|
10
|
-
* "token discarded for browser context" apart from "no credential supplied"
|
|
11
|
-
* without weakening production.
|
|
7
|
+
* automatically). The discard is silent on the wire (anti-enumeration) and
|
|
8
|
+
* logged at debug, the line the Rust spine logs.
|
|
12
9
|
*
|
|
13
10
|
* Token generation and hashing utilities live in `auth/api_token.ts`.
|
|
14
11
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bearer_auth.d.ts","sourceRoot":"","sources":["../../src/lib/auth/bearer_auth.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"bearer_auth.d.ts","sourceRoot":"","sources":["../../src/lib/auth/bearer_auth.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAC;AAC9C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAQtD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAKrD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,eAAO,MAAM,6BAA6B,GAAI,MAAM,SAAS,EAAE,KAAK,MAAM,KAAG,iBAsE5E,CAAC"}
|
package/dist/auth/bearer_auth.js
CHANGED
|
@@ -4,17 +4,13 @@
|
|
|
4
4
|
* Bearer tokens are rejected when `Origin` or `Referer` headers are present —
|
|
5
5
|
* browsers must use cookie auth. This reduces attack surface: a stolen token
|
|
6
6
|
* cannot be replayed from a browser context (the browser adds `Origin`
|
|
7
|
-
* automatically). The discard is silent on the wire (anti-enumeration)
|
|
8
|
-
*
|
|
9
|
-
* bearer_discarded_browser_context` response header so tests/tooling can tell
|
|
10
|
-
* "token discarded for browser context" apart from "no credential supplied"
|
|
11
|
-
* without weakening production.
|
|
7
|
+
* automatically). The discard is silent on the wire (anti-enumeration) and
|
|
8
|
+
* logged at debug, the line the Rust spine logs.
|
|
12
9
|
*
|
|
13
10
|
* Token generation and hashing utilities live in `auth/api_token.ts`.
|
|
14
11
|
*
|
|
15
12
|
* @module
|
|
16
13
|
*/
|
|
17
|
-
import { DEV } from 'esm-env';
|
|
18
14
|
import { RESOLVED_AUTH_KEY } from '../hono_context.js';
|
|
19
15
|
import { credential_deadline_after } from './credential_deadline.js';
|
|
20
16
|
import { get_resolved_auth } from './resolved_auth.js';
|
|
@@ -87,14 +83,9 @@ export const create_bearer_auth_middleware = (deps, log) => {
|
|
|
87
83
|
// the RPC dispatcher can still handle public actions or fall through to
|
|
88
84
|
// cookie auth.
|
|
89
85
|
if (is_browser_context(get_header_lines(c, 'origin'), get_header_lines(c, 'referer'))) {
|
|
86
|
+
// silent on the wire by design: a stolen-token probe gets an
|
|
87
|
+
// indistinguishable 401, not a "your token was dropped" signal
|
|
90
88
|
log.debug('bearer auth rejected: browser context (Origin/Referer present)');
|
|
91
|
-
// The discard is silent on the wire by design (a stolen-token probe
|
|
92
|
-
// gets an indistinguishable 401, not a "your token was dropped"
|
|
93
|
-
// signal — anti-enumeration). That same silence makes the contract
|
|
94
|
-
// easy to trip over in tests/tooling, so surface the reason in DEV
|
|
95
|
-
// only: production never emits it, so it leaks nothing to an attacker.
|
|
96
|
-
if (DEV)
|
|
97
|
-
c.header('X-Fuz-Auth-Debug', 'bearer_discarded_browser_context');
|
|
98
89
|
await next();
|
|
99
90
|
return;
|
|
100
91
|
}
|
|
@@ -12,34 +12,33 @@
|
|
|
12
12
|
import type { Logger } from '@fuzdev/fuz_util/log.ts';
|
|
13
13
|
import type { PasswordHashDeps } from './password.js';
|
|
14
14
|
import { ERROR_INVALID_TOKEN, ERROR_ALREADY_BOOTSTRAPPED, ERROR_TOKEN_FILE_MISSING, ERROR_TOKEN_FILE_UNDELETABLE } from '../http/error_schemas.js';
|
|
15
|
-
import type { Account, Actor
|
|
16
|
-
import type
|
|
15
|
+
import type { Account, Actor } from './account_schema.js';
|
|
16
|
+
import { type RequestEffectsContext } from '../http/pending_effects.js';
|
|
17
|
+
import type { AuditEmitter } from './audit_emitter.js';
|
|
17
18
|
import type { BootstrapTokenStore } from './bootstrap_token_store.js';
|
|
18
19
|
import type { Keyring } from './keyring.js';
|
|
19
|
-
import type { SessionOptions } from './session_cookie.js';
|
|
20
20
|
/** Input for the bootstrap account creation. */
|
|
21
21
|
export interface BootstrapAccountInput {
|
|
22
22
|
username: string;
|
|
23
23
|
password: string;
|
|
24
24
|
}
|
|
25
|
-
/**
|
|
26
|
-
|
|
25
|
+
/**
|
|
26
|
+
* Successful bootstrap result: the new session and the created entities. Twin
|
|
27
|
+
* of the Rust `BootstrapSuccess`; internal — the route answers
|
|
28
|
+
* `BootstrapOutput` from it.
|
|
29
|
+
*/
|
|
30
|
+
export interface BootstrapAccountSuccess {
|
|
31
|
+
ok: true;
|
|
32
|
+
/** The raw session token (its hash is the `auth_session` row id) — a live credential. */
|
|
33
|
+
session_token: string;
|
|
27
34
|
account: Account;
|
|
28
35
|
actor: Actor;
|
|
29
|
-
role_grants: {
|
|
30
|
-
keeper: RoleGrant;
|
|
31
|
-
admin: RoleGrant;
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
/** Successful bootstrap result with the created entities and the new session. */
|
|
35
|
-
export interface BootstrapAccountSuccess extends BootstrapAccountCreated {
|
|
36
|
-
ok: true;
|
|
37
36
|
/**
|
|
38
|
-
* The
|
|
39
|
-
* transaction, for the caller to set on its
|
|
40
|
-
* because the transaction committed.
|
|
37
|
+
* The `Set-Cookie` line of the session minted in the bootstrap
|
|
38
|
+
* transaction, formatted inside it, for the caller to set on its
|
|
39
|
+
* response — it exists only because the transaction committed.
|
|
41
40
|
*/
|
|
42
|
-
|
|
41
|
+
set_cookie: string;
|
|
43
42
|
}
|
|
44
43
|
/** Bootstrap failure result. */
|
|
45
44
|
export type BootstrapAccountFailure = {
|
|
@@ -65,7 +64,8 @@ export type BootstrapAccountResult = BootstrapAccountSuccess | BootstrapAccountF
|
|
|
65
64
|
* Dependencies for `bootstrap_account`.
|
|
66
65
|
*/
|
|
67
66
|
export interface BootstrapAccountDeps {
|
|
68
|
-
|
|
67
|
+
/** Writes the `bootstrap` success row in the bootstrap transaction. */
|
|
68
|
+
audit: Pick<AuditEmitter, 'emit'>;
|
|
69
69
|
/**
|
|
70
70
|
* The one-shot token: read through the hardened secret read (a symlinked,
|
|
71
71
|
* non-regular, group/other-readable, multiply-linked, or oversized file is
|
|
@@ -80,10 +80,20 @@ export interface BootstrapAccountDeps {
|
|
|
80
80
|
/** Structured logger instance. */
|
|
81
81
|
log: Logger;
|
|
82
82
|
}
|
|
83
|
+
/**
|
|
84
|
+
* The request `bootstrap_account` runs for: its pool-level `db` (the bootstrap
|
|
85
|
+
* opens its own transaction), its side-effect queues (the success row's
|
|
86
|
+
* listener fan-out is queued post-commit), and the client IP its audit row
|
|
87
|
+
* records. A `RouteContext` satisfies it.
|
|
88
|
+
*/
|
|
89
|
+
export interface BootstrapAccountContext extends RequestEffectsContext {
|
|
90
|
+
/** Resolved client IP from the trusted-proxy middleware — `'unknown'` if not resolved. */
|
|
91
|
+
client_ip: string;
|
|
92
|
+
}
|
|
83
93
|
/** Static options for `bootstrap_account`. */
|
|
84
94
|
export interface BootstrapAccountOptions {
|
|
85
|
-
/**
|
|
86
|
-
|
|
95
|
+
/** The session cookie's name for the session the bootstrap mints. */
|
|
96
|
+
session_cookie_name: string;
|
|
87
97
|
}
|
|
88
98
|
/**
|
|
89
99
|
* The fewest bytes a bootstrap token holds, counted after its one optional
|
|
@@ -119,27 +129,33 @@ export declare const read_bootstrap_token: (deps: Pick<BootstrapAccountDeps, "to
|
|
|
119
129
|
* the race loser, `already_bootstrapped`, nothing burned); create the
|
|
120
130
|
* account + actor; grant keeper and admin (no expiry, `granted_by =
|
|
121
131
|
* null`); mint the session through the capped minter login uses (the cap
|
|
122
|
-
* evicts nothing on a new account)
|
|
132
|
+
* evicts nothing on a new account) and format its `Set-Cookie` line; write
|
|
133
|
+
* the `bootstrap` success audit row; then burn the token file, last, just
|
|
123
134
|
* before the commit
|
|
124
135
|
*
|
|
125
136
|
* The burn comes after the lock, so only the lock winner burns (its row lock
|
|
126
137
|
* is held across the unlink, so a concurrent attempt waits on its UPDATE);
|
|
127
138
|
* after the inserts, so a failed insert spends nothing; last, so the window
|
|
128
|
-
* between a burn and a failed commit is one round trip.
|
|
139
|
+
* between a burn and a failed commit is one round trip. The audit row is
|
|
140
|
+
* written before the burn, so a refused row rolls the bootstrap back with the
|
|
141
|
+
* token unburned and the window open, as a failed insert does; its listener
|
|
142
|
+
* fan-out is discarded with any rollback. A burn that fails
|
|
129
143
|
* rolls everything back and answers `token_file_undeletable`: nothing was
|
|
130
144
|
* created and the token is still valid, so the operator fixes the directory
|
|
131
145
|
* and retries. A commit that fails after the burn is logged as an error — the
|
|
132
146
|
* token is gone and a new one must be written. Twin of the Rust
|
|
133
147
|
* `bootstrap_handler`.
|
|
134
148
|
*
|
|
135
|
-
* @param deps -
|
|
149
|
+
* @param deps - token store, password hashing, keyring, audit emitter, and logger
|
|
150
|
+
* @param ctx - the request's pool `db`, side-effect queues, and client IP
|
|
136
151
|
* @param provided_token - the bootstrap token from the user
|
|
137
152
|
* @param input - username and password
|
|
138
153
|
* @param options - the session cookie configuration
|
|
139
|
-
* @returns the created account
|
|
154
|
+
* @returns the created account and actor, and the session's `Set-Cookie` line — or a bootstrap failure
|
|
140
155
|
* @mutates `bootstrap_lock` row - flips `bootstrapped` to `true` atomically
|
|
141
|
-
* @mutates `account` / `actor` / `role_grant` / `auth_session` tables - inserts the bootstrap account, actor, keeper + admin role_grants, and
|
|
156
|
+
* @mutates `account` / `actor` / `role_grant` / `auth_session` / `audit_log` tables - inserts the bootstrap account, actor, keeper + admin role_grants, session, and success row
|
|
157
|
+
* @mutates `ctx.post_commit_effects` - appends the success row's listener fan-out, discarded on rollback
|
|
142
158
|
* @mutates filesystem - burns the bootstrap token file inside the transaction
|
|
143
159
|
*/
|
|
144
|
-
export declare const bootstrap_account: (deps: BootstrapAccountDeps, provided_token: string, input: BootstrapAccountInput, options: BootstrapAccountOptions) => Promise<BootstrapAccountResult>;
|
|
160
|
+
export declare const bootstrap_account: (deps: BootstrapAccountDeps, ctx: BootstrapAccountContext, provided_token: string, input: BootstrapAccountInput, options: BootstrapAccountOptions) => Promise<BootstrapAccountResult>;
|
|
145
161
|
//# sourceMappingURL=bootstrap_account.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bootstrap_account.d.ts","sourceRoot":"","sources":["../../src/lib/auth/bootstrap_account.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAGtD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EACN,mBAAmB,EACnB,0BAA0B,EAC1B,wBAAwB,EACxB,4BAA4B,EAC5B,MAAM,0BAA0B,CAAC;AAElC,OAAO,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"bootstrap_account.d.ts","sourceRoot":"","sources":["../../src/lib/auth/bootstrap_account.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAGtD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EACN,mBAAmB,EACnB,0BAA0B,EAC1B,wBAAwB,EACxB,4BAA4B,EAC5B,MAAM,0BAA0B,CAAC;AAElC,OAAO,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAG1D,OAAO,EAEN,KAAK,qBAAqB,EAC1B,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAK5C,gDAAgD;AAChD,MAAM,WAAW,qBAAqB;IACrC,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CACjB;AAED;;;;GAIG;AACH,MAAM,WAAW,uBAAuB;IACvC,EAAE,EAAE,IAAI,CAAC;IACT,yFAAyF;IACzF,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,KAAK,CAAC;IACb;;;;OAIG;IACH,UAAU,EAAE,MAAM,CAAC;CACnB;AAED,gCAAgC;AAChC,MAAM,MAAM,uBAAuB,GAChC;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,OAAO,0BAA0B,CAAC;IAAC,MAAM,EAAE,GAAG,CAAA;CAAE,GACpE;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,OAAO,wBAAwB,CAAC;IAAC,MAAM,EAAE,GAAG,CAAA;CAAE,GAClE;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,OAAO,mBAAmB,CAAC;IAAC,MAAM,EAAE,GAAG,CAAA;CAAE,GAC7D;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,OAAO,4BAA4B,CAAC;IAAC,MAAM,EAAE,GAAG,CAAA;CAAE,CAAC;AAE1E,qFAAqF;AACrF,MAAM,MAAM,sBAAsB,GAAG,uBAAuB,GAAG,uBAAuB,CAAC;AAEvF;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACpC,uEAAuE;IACvE,KAAK,EAAE,IAAI,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC;IAClC;;;;;OAKG;IACH,WAAW,EAAE,mBAAmB,CAAC;IACjC,6EAA6E;IAC7E,QAAQ,EAAE,IAAI,CAAC,gBAAgB,EAAE,eAAe,CAAC,CAAC;IAClD,0DAA0D;IAC1D,OAAO,EAAE,OAAO,CAAC;IACjB,kCAAkC;IAClC,GAAG,EAAE,MAAM,CAAC;CACZ;AAED;;;;;GAKG;AACH,MAAM,WAAW,uBAAwB,SAAQ,qBAAqB;IACrE,0FAA0F;IAC1F,SAAS,EAAE,MAAM,CAAC;CAClB;AAED,8CAA8C;AAC9C,MAAM,WAAW,uBAAuB;IACvC,qEAAqE;IACrE,mBAAmB,EAAE,MAAM,CAAC;CAC5B;AAsBD;;;;;;;;GAQG;AACH,eAAO,MAAM,yBAAyB,KAAK,CAAC;AAE5C;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,oBAAoB,GAChC,MAAM,IAAI,CAAC,oBAAoB,EAAE,aAAa,GAAG,KAAK,CAAC,KACrD,OAAO,CAAC,UAAU,CASpB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,eAAO,MAAM,iBAAiB,GAC7B,MAAM,oBAAoB,EAC1B,KAAK,uBAAuB,EAC5B,gBAAgB,MAAM,EACtB,OAAO,qBAAqB,EAC5B,SAAS,uBAAuB,KAC9B,OAAO,CAAC,sBAAsB,CAwHhC,CAAC"}
|
|
@@ -15,6 +15,8 @@ import { ERROR_INVALID_TOKEN, ERROR_ALREADY_BOOTSTRAPPED, ERROR_TOKEN_FILE_MISSI
|
|
|
15
15
|
import { ROLE_ADMIN, ROLE_KEEPER } from './role_schema.js';
|
|
16
16
|
import { query_create_account_with_actor } from './account_queries.js';
|
|
17
17
|
import { query_create_role_grant } from './role_grant_queries.js';
|
|
18
|
+
import { transaction_with_post_commit_rollback } from '../http/pending_effects.js';
|
|
19
|
+
import { sign_session_cookie } from './session_cookie.js';
|
|
18
20
|
import { create_capped_session } from './session_queries.js';
|
|
19
21
|
import { DEFAULT_MAX_SESSIONS } from './account_route_schema.js';
|
|
20
22
|
/**
|
|
@@ -78,30 +80,36 @@ export const read_bootstrap_token = async (deps) => {
|
|
|
78
80
|
* the race loser, `already_bootstrapped`, nothing burned); create the
|
|
79
81
|
* account + actor; grant keeper and admin (no expiry, `granted_by =
|
|
80
82
|
* null`); mint the session through the capped minter login uses (the cap
|
|
81
|
-
* evicts nothing on a new account)
|
|
83
|
+
* evicts nothing on a new account) and format its `Set-Cookie` line; write
|
|
84
|
+
* the `bootstrap` success audit row; then burn the token file, last, just
|
|
82
85
|
* before the commit
|
|
83
86
|
*
|
|
84
87
|
* The burn comes after the lock, so only the lock winner burns (its row lock
|
|
85
88
|
* is held across the unlink, so a concurrent attempt waits on its UPDATE);
|
|
86
89
|
* after the inserts, so a failed insert spends nothing; last, so the window
|
|
87
|
-
* between a burn and a failed commit is one round trip.
|
|
90
|
+
* between a burn and a failed commit is one round trip. The audit row is
|
|
91
|
+
* written before the burn, so a refused row rolls the bootstrap back with the
|
|
92
|
+
* token unburned and the window open, as a failed insert does; its listener
|
|
93
|
+
* fan-out is discarded with any rollback. A burn that fails
|
|
88
94
|
* rolls everything back and answers `token_file_undeletable`: nothing was
|
|
89
95
|
* created and the token is still valid, so the operator fixes the directory
|
|
90
96
|
* and retries. A commit that fails after the burn is logged as an error — the
|
|
91
97
|
* token is gone and a new one must be written. Twin of the Rust
|
|
92
98
|
* `bootstrap_handler`.
|
|
93
99
|
*
|
|
94
|
-
* @param deps -
|
|
100
|
+
* @param deps - token store, password hashing, keyring, audit emitter, and logger
|
|
101
|
+
* @param ctx - the request's pool `db`, side-effect queues, and client IP
|
|
95
102
|
* @param provided_token - the bootstrap token from the user
|
|
96
103
|
* @param input - username and password
|
|
97
104
|
* @param options - the session cookie configuration
|
|
98
|
-
* @returns the created account
|
|
105
|
+
* @returns the created account and actor, and the session's `Set-Cookie` line — or a bootstrap failure
|
|
99
106
|
* @mutates `bootstrap_lock` row - flips `bootstrapped` to `true` atomically
|
|
100
|
-
* @mutates `account` / `actor` / `role_grant` / `auth_session` tables - inserts the bootstrap account, actor, keeper + admin role_grants, and
|
|
107
|
+
* @mutates `account` / `actor` / `role_grant` / `auth_session` / `audit_log` tables - inserts the bootstrap account, actor, keeper + admin role_grants, session, and success row
|
|
108
|
+
* @mutates `ctx.post_commit_effects` - appends the success row's listener fan-out, discarded on rollback
|
|
101
109
|
* @mutates filesystem - burns the bootstrap token file inside the transaction
|
|
102
110
|
*/
|
|
103
|
-
export const bootstrap_account = async (deps, provided_token, input, options) => {
|
|
104
|
-
const {
|
|
111
|
+
export const bootstrap_account = async (deps, ctx, provided_token, input, options) => {
|
|
112
|
+
const { token_store, password, keyring, audit, log } = deps;
|
|
105
113
|
// 1. Read and verify token (non-destructive, before transaction). The
|
|
106
114
|
// secure read fails loud on a symlink / non-regular file / permissive mode /
|
|
107
115
|
// second hard link / oversized file, and the read refuses a token under the minimum length —
|
|
@@ -128,23 +136,22 @@ export const bootstrap_account = async (deps, provided_token, input, options) =>
|
|
|
128
136
|
let burned = false;
|
|
129
137
|
let tx_result;
|
|
130
138
|
try {
|
|
131
|
-
tx_result = await
|
|
132
|
-
const lock_rows = await
|
|
139
|
+
tx_result = await transaction_with_post_commit_rollback(ctx, async (tx_ctx) => {
|
|
140
|
+
const lock_rows = await tx_ctx.db.query('UPDATE bootstrap_lock SET bootstrapped = true WHERE id = 1 AND bootstrapped = false RETURNING id');
|
|
133
141
|
if (lock_rows.length === 0) {
|
|
134
142
|
return { ok: false, error: ERROR_ALREADY_BOOTSTRAPPED, status: 403 };
|
|
135
143
|
}
|
|
136
|
-
const
|
|
137
|
-
const { account, actor } = await query_create_account_with_actor(tx_deps, {
|
|
144
|
+
const { account, actor } = await query_create_account_with_actor(tx_ctx, {
|
|
138
145
|
username: input.username,
|
|
139
146
|
password_hash
|
|
140
147
|
});
|
|
141
|
-
|
|
148
|
+
await query_create_role_grant(tx_ctx, {
|
|
142
149
|
actor_id: actor.id,
|
|
143
150
|
role: ROLE_KEEPER,
|
|
144
151
|
granted_by: null,
|
|
145
152
|
expires_at: null
|
|
146
153
|
});
|
|
147
|
-
|
|
154
|
+
await query_create_role_grant(tx_ctx, {
|
|
148
155
|
actor_id: actor.id,
|
|
149
156
|
role: ROLE_ADMIN,
|
|
150
157
|
granted_by: null,
|
|
@@ -153,13 +160,23 @@ export const bootstrap_account = async (deps, provided_token, input, options) =>
|
|
|
153
160
|
// The account was created above, so the cap evicts nothing. Routed
|
|
154
161
|
// through the shared minter anyway: the cap is a property of session
|
|
155
162
|
// creation, not of the login route.
|
|
156
|
-
const {
|
|
157
|
-
|
|
158
|
-
deps: tx_deps,
|
|
163
|
+
const { token: session_token } = await create_capped_session({
|
|
164
|
+
deps: tx_ctx,
|
|
159
165
|
account_id: account.id,
|
|
160
|
-
session_options: options.session_options,
|
|
161
166
|
max_sessions: DEFAULT_MAX_SESSIONS
|
|
162
167
|
});
|
|
168
|
+
// signed here, as login and signup sign theirs: a line the formatter
|
|
169
|
+
// refuses rolls the bootstrap back with the token unburned
|
|
170
|
+
const set_cookie = await sign_session_cookie(keyring, session_token, options.session_cookie_name);
|
|
171
|
+
// The success row, in the transaction and ahead of the burn: a refused
|
|
172
|
+
// INSERT rolls the bootstrap back with the token unburned and the
|
|
173
|
+
// window open, as a failed insert above does.
|
|
174
|
+
await audit.emit(tx_ctx, {
|
|
175
|
+
event_type: 'bootstrap',
|
|
176
|
+
actor_id: actor.id,
|
|
177
|
+
account_id: account.id,
|
|
178
|
+
ip: ctx.client_ip
|
|
179
|
+
});
|
|
163
180
|
// the burn, last before the commit
|
|
164
181
|
let outcome;
|
|
165
182
|
try {
|
|
@@ -174,10 +191,10 @@ export const bootstrap_account = async (deps, provided_token, input, options) =>
|
|
|
174
191
|
}
|
|
175
192
|
return {
|
|
176
193
|
ok: true,
|
|
194
|
+
session_token,
|
|
177
195
|
account,
|
|
178
196
|
actor,
|
|
179
|
-
|
|
180
|
-
session_cookie_value: cookie_value
|
|
197
|
+
set_cookie
|
|
181
198
|
};
|
|
182
199
|
});
|
|
183
200
|
}
|
|
@@ -7,8 +7,7 @@
|
|
|
7
7
|
* @module
|
|
8
8
|
*/
|
|
9
9
|
import type { Logger } from '@fuzdev/fuz_util/log.ts';
|
|
10
|
-
import {
|
|
11
|
-
import { type BootstrapAccountCreated } from './bootstrap_account.js';
|
|
10
|
+
import type { DaemonTokenState } from './daemon_token.js';
|
|
12
11
|
import type { BootstrapTokenStore } from './bootstrap_token_store.js';
|
|
13
12
|
import type { Db } from '../db/db.js';
|
|
14
13
|
import { type RouteSpec } from '../http/route_spec.js';
|
|
@@ -21,22 +20,15 @@ import type { RouteFactoryDeps } from './deps.js';
|
|
|
21
20
|
export interface BootstrapStatus {
|
|
22
21
|
available: boolean;
|
|
23
22
|
}
|
|
24
|
-
/**
|
|
25
|
-
* Called after a successful bootstrap has committed, with what it created.
|
|
26
|
-
* Use for app-specific post-bootstrap work like generating API tokens. It
|
|
27
|
-
* gets no request context: the response — its session cookie included — is
|
|
28
|
-
* the route's. A throw is logged and the bootstrap still succeeds, since it
|
|
29
|
-
* has already committed. Twin of the Rust `BootstrapKeeperResolved`.
|
|
30
|
-
*/
|
|
31
|
-
export type OnBootstrap = (created: BootstrapAccountCreated) => Promise<void>;
|
|
32
23
|
/**
|
|
33
24
|
* Per-factory configuration for bootstrap route specs.
|
|
34
25
|
*
|
|
35
|
-
* `bootstrap_status`
|
|
36
|
-
*
|
|
26
|
+
* `bootstrap_status` and `daemon_token_state` are runtime state (mutable refs),
|
|
27
|
+
* not deps or options values — passed through so the route handler can flip
|
|
28
|
+
* the one and set the other's keeper.
|
|
37
29
|
*/
|
|
38
30
|
export interface BootstrapRouteOptions {
|
|
39
|
-
|
|
31
|
+
session_cookie_name: string;
|
|
40
32
|
/** Shared mutable reference — flipped to false when the window closes. */
|
|
41
33
|
bootstrap_status: BootstrapStatus;
|
|
42
34
|
/**
|
|
@@ -45,8 +37,14 @@ export interface BootstrapRouteOptions {
|
|
|
45
37
|
* server does.
|
|
46
38
|
*/
|
|
47
39
|
token_store: BootstrapTokenStore | null;
|
|
48
|
-
/**
|
|
49
|
-
|
|
40
|
+
/**
|
|
41
|
+
* The daemon-token state whose `keeper_account_id` a successful bootstrap
|
|
42
|
+
* sets to the new account once it has committed, so the keeper's daemon
|
|
43
|
+
* token authenticates from the next request; `null` when the server takes
|
|
44
|
+
* no daemon token. `create_app_server` passes its own. Twin of the Rust
|
|
45
|
+
* `BootstrapOptions.on_keeper_resolved`, which the spine wires the same way.
|
|
46
|
+
*/
|
|
47
|
+
daemon_token_state: DaemonTokenState | null;
|
|
50
48
|
/**
|
|
51
49
|
* Rate limiter for bootstrap attempts, keyed by client IP. Pass `null` to
|
|
52
50
|
* disable. Its own instance, not login's: bootstrap is one-shot and its
|
|
@@ -62,15 +60,16 @@ export interface BootstrapRouteOptions {
|
|
|
62
60
|
bootstrap_ip_rate_limiter: RateLimiter | null;
|
|
63
61
|
}
|
|
64
62
|
/**
|
|
65
|
-
* Dependencies for
|
|
63
|
+
* Dependencies for `is_bootstrap_available`.
|
|
66
64
|
*/
|
|
67
|
-
export interface
|
|
65
|
+
export interface IsBootstrapAvailableDeps {
|
|
68
66
|
/** Only the single-row `bootstrap_lock` read — narrower than the full `Db`. */
|
|
69
67
|
db: Pick<Db, 'query_one'>;
|
|
70
68
|
log: Logger;
|
|
71
69
|
}
|
|
72
70
|
/**
|
|
73
|
-
*
|
|
71
|
+
* Whether bootstrap is available — read once at startup into the
|
|
72
|
+
* `BootstrapStatus` ref.
|
|
74
73
|
*
|
|
75
74
|
* Bootstrap is available when a token store is configured, the
|
|
76
75
|
* `bootstrap_lock` row shows `bootstrapped = false`, and the token file
|
|
@@ -94,11 +93,11 @@ export interface CheckBootstrapStatusDeps {
|
|
|
94
93
|
*
|
|
95
94
|
* @param deps - the lock read and a logger
|
|
96
95
|
* @param options - the token store, `null` when bootstrap is not configured
|
|
97
|
-
* @returns the
|
|
96
|
+
* @returns whether the bootstrap window is open
|
|
98
97
|
*/
|
|
99
|
-
export declare const
|
|
98
|
+
export declare const is_bootstrap_available: (deps: IsBootstrapAvailableDeps, options: {
|
|
100
99
|
token_store: BootstrapTokenStore | null;
|
|
101
|
-
}) => Promise<
|
|
100
|
+
}) => Promise<boolean>;
|
|
102
101
|
/**
|
|
103
102
|
* Create bootstrap route specs for first-time account creation.
|
|
104
103
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bootstrap_routes.d.ts","sourceRoot":"","sources":["../../src/lib/auth/bootstrap_routes.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"bootstrap_routes.d.ts","sourceRoot":"","sources":["../../src/lib/auth/bootstrap_routes.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAGtD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAEtE,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AACtC,OAAO,EAAwB,KAAK,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAG7E,OAAO,EAAoB,KAAK,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACxE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAYlD;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC/B,SAAS,EAAE,OAAO,CAAC;CACnB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,qBAAqB;IACrC,mBAAmB,EAAE,MAAM,CAAC;IAC5B,0EAA0E;IAC1E,gBAAgB,EAAE,eAAe,CAAC;IAClC;;;;OAIG;IACH,WAAW,EAAE,mBAAmB,GAAG,IAAI,CAAC;IACxC;;;;;;OAMG;IACH,kBAAkB,EAAE,gBAAgB,GAAG,IAAI,CAAC;IAC5C;;;;;;;;;;;OAWG;IACH,yBAAyB,EAAE,WAAW,GAAG,IAAI,CAAC;CAC9C;AAED;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACxC,+EAA+E;IAC/E,EAAE,EAAE,IAAI,CAAC,EAAE,EAAE,WAAW,CAAC,CAAC;IAC1B,GAAG,EAAE,MAAM,CAAC;CACZ;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,eAAO,MAAM,sBAAsB,GAClC,MAAM,wBAAwB,EAC9B,SAAS;IAAE,WAAW,EAAE,mBAAmB,GAAG,IAAI,CAAA;CAAE,KAClD,OAAO,CAAC,OAAO,CA0CjB,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,4BAA4B,GACxC,MAAM,gBAAgB,EACtB,SAAS,qBAAqB,KAC5B,KAAK,CAAC,SAAS,CA8HjB,CAAC"}
|
|
@@ -7,7 +7,6 @@
|
|
|
7
7
|
* @module
|
|
8
8
|
*/
|
|
9
9
|
import { to_error_message } from '@fuzdev/fuz_util/error.ts';
|
|
10
|
-
import { session_cookie_header } from './session_cookie.js';
|
|
11
10
|
import { bootstrap_account, read_bootstrap_token } from './bootstrap_account.js';
|
|
12
11
|
import { bootstrap_route_shape } from './bootstrap_route_schema.js';
|
|
13
12
|
import { attach_route_handler } from '../http/route_spec.js';
|
|
@@ -16,7 +15,8 @@ import { rate_limit_ip_key } from '../http/ip_canonical.js';
|
|
|
16
15
|
import { reserve_optional } from '../rate_limiter.js';
|
|
17
16
|
import { ERROR_ALREADY_BOOTSTRAPPED, ERROR_TOKEN_FILE_MISSING, ERROR_TOKEN_FILE_UNDELETABLE, REST_ALREADY_BOOTSTRAPPED, REST_INVALID_TOKEN, REST_RATE_LIMIT_EXCEEDED, REST_TOKEN_FILE_MISSING, REST_TOKEN_FILE_UNDELETABLE } from '../http/error_schemas.js';
|
|
18
17
|
/**
|
|
19
|
-
*
|
|
18
|
+
* Whether bootstrap is available — read once at startup into the
|
|
19
|
+
* `BootstrapStatus` ref.
|
|
20
20
|
*
|
|
21
21
|
* Bootstrap is available when a token store is configured, the
|
|
22
22
|
* `bootstrap_lock` row shows `bootstrapped = false`, and the token file
|
|
@@ -40,17 +40,17 @@ import { ERROR_ALREADY_BOOTSTRAPPED, ERROR_TOKEN_FILE_MISSING, ERROR_TOKEN_FILE_
|
|
|
40
40
|
*
|
|
41
41
|
* @param deps - the lock read and a logger
|
|
42
42
|
* @param options - the token store, `null` when bootstrap is not configured
|
|
43
|
-
* @returns the
|
|
43
|
+
* @returns whether the bootstrap window is open
|
|
44
44
|
*/
|
|
45
|
-
export const
|
|
45
|
+
export const is_bootstrap_available = async (deps, options) => {
|
|
46
46
|
const { db, log } = deps;
|
|
47
47
|
const { token_store } = options;
|
|
48
48
|
if (!token_store)
|
|
49
|
-
return
|
|
49
|
+
return false;
|
|
50
50
|
const lock_row = await db.query_one('SELECT bootstrapped FROM bootstrap_lock WHERE id = 1');
|
|
51
51
|
if (!lock_row) {
|
|
52
52
|
log.error('Bootstrap unavailable: the bootstrap_lock row is missing — the auth migration seeds it; restore it to bootstrap');
|
|
53
|
-
return
|
|
53
|
+
return false;
|
|
54
54
|
}
|
|
55
55
|
if (lock_row.bootstrapped) {
|
|
56
56
|
let present = true;
|
|
@@ -66,17 +66,17 @@ export const check_bootstrap_status = async (deps, options) => {
|
|
|
66
66
|
else {
|
|
67
67
|
log.info('Bootstrap unavailable: already bootstrapped');
|
|
68
68
|
}
|
|
69
|
-
return
|
|
69
|
+
return false;
|
|
70
70
|
}
|
|
71
71
|
try {
|
|
72
72
|
await read_bootstrap_token({ token_store, log });
|
|
73
73
|
}
|
|
74
74
|
catch (err) {
|
|
75
75
|
log.warn(`Bootstrap unavailable: token file unreadable: ${to_error_message(err)}`);
|
|
76
|
-
return
|
|
76
|
+
return false;
|
|
77
77
|
}
|
|
78
78
|
log.info(`Bootstrap token available: ${token_store.path}`);
|
|
79
|
-
return
|
|
79
|
+
return true;
|
|
80
80
|
};
|
|
81
81
|
/**
|
|
82
82
|
* Create bootstrap route specs for first-time account creation.
|
|
@@ -86,7 +86,7 @@ export const check_bootstrap_status = async (deps, options) => {
|
|
|
86
86
|
* @returns route specs (not yet applied to Hono)
|
|
87
87
|
*/
|
|
88
88
|
export const create_bootstrap_route_specs = (deps, options) => {
|
|
89
|
-
const {
|
|
89
|
+
const { session_cookie_name, bootstrap_status, token_store, daemon_token_state, bootstrap_ip_rate_limiter } = options;
|
|
90
90
|
return [
|
|
91
91
|
attach_route_handler(bootstrap_route_shape, async (route) => {
|
|
92
92
|
// Short-circuit if bootstrap already completed or surface-only mounted.
|
|
@@ -117,14 +117,15 @@ export const create_bootstrap_route_specs = (deps, options) => {
|
|
|
117
117
|
try {
|
|
118
118
|
const input = route.input;
|
|
119
119
|
// `transaction: false` makes `route.db` the pool. `bootstrap_account`
|
|
120
|
-
// manages its own transaction internally
|
|
120
|
+
// manages its own transaction internally, and writes the success
|
|
121
|
+
// row in it.
|
|
121
122
|
const result = await bootstrap_account({
|
|
122
|
-
db: route.db,
|
|
123
123
|
token_store,
|
|
124
124
|
password: deps.password,
|
|
125
125
|
keyring: deps.keyring,
|
|
126
|
+
audit: deps.audit,
|
|
126
127
|
log: deps.log
|
|
127
|
-
}, input.token, input, {
|
|
128
|
+
}, route, input.token, input, { session_cookie_name });
|
|
128
129
|
if (!result.ok) {
|
|
129
130
|
// The lock-race loser — the window open here, the lock already
|
|
130
131
|
// flipped in the database. Close the window so the next caller
|
|
@@ -138,7 +139,7 @@ export const create_bootstrap_route_specs = (deps, options) => {
|
|
|
138
139
|
return route_fail(REST_ALREADY_BOOTSTRAPPED);
|
|
139
140
|
}
|
|
140
141
|
// An unreadable token file closes the window. Bootstrap cannot
|
|
141
|
-
// succeed without one, and `
|
|
142
|
+
// succeed without one, and `is_bootstrap_available` already reads
|
|
142
143
|
// an unreadable file as unavailable at startup — so leaving the
|
|
143
144
|
// flag set means the two disagree, and every later request takes
|
|
144
145
|
// this leg and writes another audit row. A wrong token and an
|
|
@@ -166,24 +167,18 @@ export const create_bootstrap_route_specs = (deps, options) => {
|
|
|
166
167
|
// most `max_attempts - 1` residual entries survive — and they sit
|
|
167
168
|
// on this route's own limiter, not login's.
|
|
168
169
|
bootstrap_status.available = false;
|
|
169
|
-
// the session was minted
|
|
170
|
-
// success
|
|
171
|
-
const set_cookie =
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
}
|
|
170
|
+
// the session was minted, and its cookie line formatted, in the
|
|
171
|
+
// transaction; the line rides the success
|
|
172
|
+
const { account, actor, set_cookie } = result;
|
|
173
|
+
// the new keeper, set only now that its account has committed, so
|
|
174
|
+
// the daemon leg never resolves to a row a rollback could undo
|
|
175
|
+
if (daemon_token_state) {
|
|
176
|
+
daemon_token_state.keeper_account_id = account.id;
|
|
177
|
+
// the Rust spine's `DaemonTokenKeeperResolved` line
|
|
178
|
+
deps.log.info('daemon token: keeper account set by bootstrap', {
|
|
179
|
+
account_id: account.id
|
|
180
|
+
});
|
|
180
181
|
}
|
|
181
|
-
await deps.audit.emit(route, {
|
|
182
|
-
event_type: 'bootstrap',
|
|
183
|
-
actor_id: actor.id,
|
|
184
|
-
account_id: account.id,
|
|
185
|
-
ip: route.client_ip
|
|
186
|
-
});
|
|
187
182
|
return route_ok({
|
|
188
183
|
ok: true,
|
|
189
184
|
account: { id: account.id, username: account.username },
|