@fuzdev/fuz_app 0.185.0 → 0.187.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/dist/actions/CLAUDE.md +14 -2
- package/dist/actions/perform_action.d.ts.map +1 -1
- package/dist/actions/perform_action.js +36 -5
- package/dist/actions/ws_socket_session.d.ts.map +1 -1
- package/dist/actions/ws_socket_session.js +3 -1
- package/dist/auth/CLAUDE.md +17 -6
- package/dist/auth/account_queries.d.ts +60 -44
- package/dist/auth/account_queries.d.ts.map +1 -1
- package/dist/auth/account_queries.js +64 -54
- package/dist/auth/account_routes.d.ts.map +1 -1
- package/dist/auth/account_routes.js +59 -25
- package/dist/auth/admin_actions.d.ts.map +1 -1
- package/dist/auth/admin_actions.js +26 -9
- package/dist/auth/audit_emitter.js +2 -2
- package/dist/auth/audit_log_queries.d.ts +11 -3
- package/dist/auth/audit_log_queries.d.ts.map +1 -1
- package/dist/auth/audit_log_queries.js +4 -4
- package/dist/auth/audit_log_schema.js +1 -1
- package/dist/auth/auth_ddl.d.ts.map +1 -1
- package/dist/auth/auth_ddl.js +4 -0
- package/dist/auth/cleanup.js +1 -1
- package/dist/auth/migrations.d.ts.map +1 -1
- package/dist/auth/migrations.js +35 -0
- package/dist/auth/role_grant_offer_action_specs.d.ts +1 -1
- package/dist/auth/role_grant_offer_action_specs.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_action_specs.js +2 -1
- package/dist/auth/role_grant_offer_actions.d.ts +12 -0
- package/dist/auth/role_grant_offer_actions.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_actions.js +48 -20
- package/dist/auth/role_grant_offer_queries.d.ts +28 -15
- package/dist/auth/role_grant_offer_queries.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_queries.js +35 -16
- package/dist/auth/role_grant_queries.d.ts +118 -20
- package/dist/auth/role_grant_queries.d.ts.map +1 -1
- package/dist/auth/role_grant_queries.js +145 -24
- package/dist/auth/self_service_role_actions.d.ts.map +1 -1
- package/dist/auth/self_service_role_actions.js +15 -0
- package/dist/auth/session_queries.d.ts +24 -0
- package/dist/auth/session_queries.d.ts.map +1 -1
- package/dist/auth/session_queries.js +28 -0
- package/dist/db/CLAUDE.md +3 -3
- package/dist/db/cell_ddl.d.ts +8 -3
- package/dist/db/cell_ddl.d.ts.map +1 -1
- package/dist/db/cell_ddl.js +10 -5
- package/dist/db/migrate.d.ts +46 -22
- package/dist/db/migrate.d.ts.map +1 -1
- package/dist/db/migrate.js +103 -85
- package/dist/http/body_limit.d.ts +4 -4
- package/dist/http/body_limit.js +4 -4
- package/dist/server/app_backend.d.ts.map +1 -1
- package/dist/server/app_backend.js +1 -4
- package/dist/testing/CLAUDE.md +161 -27
- package/dist/testing/app_server.d.ts +5 -7
- package/dist/testing/app_server.d.ts.map +1 -1
- package/dist/testing/app_server.js +5 -7
- package/dist/testing/auth_apps.d.ts +3 -1
- package/dist/testing/auth_apps.d.ts.map +1 -1
- package/dist/testing/auth_apps.js +22 -5
- package/dist/testing/cross_backend/backend_both_live.d.ts +47 -0
- package/dist/testing/cross_backend/backend_both_live.d.ts.map +1 -0
- package/dist/testing/cross_backend/backend_both_live.js +566 -0
- package/dist/testing/cross_backend/backend_config.d.ts +8 -0
- package/dist/testing/cross_backend/backend_config.d.ts.map +1 -1
- package/dist/testing/cross_backend/backend_log.d.ts +71 -0
- package/dist/testing/cross_backend/backend_log.d.ts.map +1 -0
- package/dist/testing/cross_backend/backend_log.js +134 -0
- package/dist/testing/cross_backend/backend_swap.d.ts +41 -0
- package/dist/testing/cross_backend/backend_swap.d.ts.map +1 -0
- package/dist/testing/cross_backend/backend_swap.js +267 -0
- package/dist/testing/cross_backend/body_size_smuggling.js +3 -3
- package/dist/testing/cross_backend/bootstrap_backend.js +4 -4
- package/dist/testing/cross_backend/conformance_case.d.ts +11 -6
- package/dist/testing/cross_backend/conformance_case.d.ts.map +1 -1
- package/dist/testing/cross_backend/conformance_case.js +4 -0
- package/dist/testing/cross_backend/conformance_principal.d.ts +2 -2
- package/dist/testing/cross_backend/conformance_principal.d.ts.map +1 -1
- package/dist/testing/cross_backend/conformance_principal.js +27 -10
- package/dist/testing/cross_backend/default_backend_configs.d.ts +38 -5
- package/dist/testing/cross_backend/default_backend_configs.d.ts.map +1 -1
- package/dist/testing/cross_backend/default_backend_configs.js +50 -15
- package/dist/testing/cross_backend/in_process_setup.d.ts.map +1 -1
- package/dist/testing/cross_backend/in_process_setup.js +52 -30
- package/dist/testing/cross_backend/revocation_drivers.d.ts +14 -2
- package/dist/testing/cross_backend/revocation_drivers.d.ts.map +1 -1
- package/dist/testing/cross_backend/revocation_drivers.js +36 -8
- package/dist/testing/cross_backend/rust_spine_stub_backend_config.d.ts +7 -0
- package/dist/testing/cross_backend/rust_spine_stub_backend_config.d.ts.map +1 -1
- package/dist/testing/cross_backend/rust_spine_stub_backend_config.js +4 -2
- package/dist/testing/cross_backend/setup.d.ts +44 -43
- package/dist/testing/cross_backend/setup.d.ts.map +1 -1
- package/dist/testing/cross_backend/setup.js +64 -62
- package/dist/testing/cross_backend/shared_database_backends.d.ts +175 -0
- package/dist/testing/cross_backend/shared_database_backends.d.ts.map +1 -0
- package/dist/testing/cross_backend/shared_database_backends.js +298 -0
- package/dist/testing/cross_backend/spawn_backend.d.ts +7 -3
- package/dist/testing/cross_backend/spawn_backend.d.ts.map +1 -1
- package/dist/testing/cross_backend/spawn_backend.js +86 -7
- package/dist/testing/cross_backend/spine_suites.d.ts +1 -1
- package/dist/testing/cross_backend/spine_suites.d.ts.map +1 -1
- package/dist/testing/cross_backend/spine_suites.js +5 -2
- package/dist/testing/cross_backend/sse_round_trip.d.ts.map +1 -1
- package/dist/testing/cross_backend/sse_round_trip.js +4 -2
- package/dist/testing/cross_backend/testing_reset_actions.d.ts +7 -6
- package/dist/testing/cross_backend/testing_reset_actions.d.ts.map +1 -1
- package/dist/testing/cross_backend/testing_reset_actions.js +10 -8
- package/dist/testing/cross_backend/testing_server_bun.d.ts.map +1 -1
- package/dist/testing/cross_backend/testing_server_bun.js +7 -31
- package/dist/testing/cross_backend/ws_round_trip.d.ts.map +1 -1
- package/dist/testing/cross_backend/ws_round_trip.js +4 -3
- package/dist/testing/data_exposure.d.ts +4 -1
- package/dist/testing/data_exposure.d.ts.map +1 -1
- package/dist/testing/data_exposure.js +93 -25
- package/dist/testing/db_invariants.d.ts +5 -5
- package/dist/testing/db_invariants.js +5 -5
- package/dist/testing/logged_errors.d.ts +61 -0
- package/dist/testing/logged_errors.d.ts.map +1 -0
- package/dist/testing/logged_errors.js +285 -0
- package/dist/testing/middleware_gate_probes.d.ts.map +1 -1
- package/dist/testing/middleware_gate_probes.js +15 -8
- package/dist/testing/rpc_attack_surface.d.ts.map +1 -1
- package/dist/testing/rpc_attack_surface.js +41 -16
- package/dist/testing/stubs.d.ts +5 -1
- package/dist/testing/stubs.d.ts.map +1 -1
- package/dist/testing/stubs.js +6 -3
- package/dist/testing/test_app.d.ts +40 -11
- package/dist/testing/test_app.d.ts.map +1 -1
- package/dist/testing/test_app.js +66 -9
- package/dist/testing/transports/fetch_transport.d.ts +10 -0
- package/dist/testing/transports/fetch_transport.d.ts.map +1 -1
- package/dist/testing/transports/fetch_transport.js +13 -0
- package/package.json +5 -3
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
import { format_session_clear_cookie, sign_session_cookie } from './session_cookie.js';
|
|
23
23
|
import { RoleGrantSummaryJson, to_session_account } from './account_schema.js';
|
|
24
24
|
import { account_status_route_shape, create_account_route_shapes, DEFAULT_MAX_SESSIONS } from './account_route_schema.js';
|
|
25
|
-
import { create_capped_session, query_session_revoke_all_for_account, query_session_revoke_by_hash_unscoped } from './session_queries.js';
|
|
26
|
-
import { query_account_by_id, query_account_by_username_or_email, query_account_lock_verified, query_update_account_password } from './account_queries.js';
|
|
25
|
+
import { create_capped_session, query_session_is_live, query_session_live_password_hash, query_session_revoke_all_for_account, query_session_revoke_by_hash_unscoped } from './session_queries.js';
|
|
26
|
+
import { query_account_by_id, query_account_by_username_or_email, query_account_lock_live, query_account_lock_verified, query_update_account_password } from './account_queries.js';
|
|
27
27
|
import { query_revoke_all_api_tokens_for_account } from './api_token_queries.js';
|
|
28
28
|
import { build_request_context, get_public_account, resolve_acting_actor } from './request_context.js';
|
|
29
29
|
import { resolved_auth_session_hash } from './resolved_auth.js';
|
|
@@ -398,7 +398,40 @@ export const create_account_route_specs = (deps, options) => {
|
|
|
398
398
|
});
|
|
399
399
|
}
|
|
400
400
|
account_reservation = account_reserved.reservation;
|
|
401
|
-
|
|
401
|
+
// Lost to a concurrent change, a delete or a purge: the caller's
|
|
402
|
+
// `current_password` may have been right when the request was
|
|
403
|
+
// authorized, so the row says so rather than "user typoed".
|
|
404
|
+
// Sessions and tokens were already revoked by the winner; no
|
|
405
|
+
// cookie clear here either.
|
|
406
|
+
const lost_race = async () => {
|
|
407
|
+
ip_reserved.reservation.record();
|
|
408
|
+
account_reservation?.record();
|
|
409
|
+
await deps.audit.emit(route, {
|
|
410
|
+
event_type: 'password_change',
|
|
411
|
+
outcome: 'failure',
|
|
412
|
+
account_id: ctx.account.id,
|
|
413
|
+
ip: route.client_ip,
|
|
414
|
+
metadata: { reason: 'concurrent_change', credential_type }
|
|
415
|
+
});
|
|
416
|
+
return route_fail(REST_INVALID_CREDENTIALS);
|
|
417
|
+
};
|
|
418
|
+
// the shape admits only a session credential, so this is its hash
|
|
419
|
+
// (the Rust `account_password` reads the same value)
|
|
420
|
+
const change_session_hash = resolved_auth_session_hash(route.credential);
|
|
421
|
+
if (change_session_hash === null) {
|
|
422
|
+
// a 500 with nothing changed, as the Rust handler answers
|
|
423
|
+
throw new Error('password: the session gate admitted a caller with no session hash');
|
|
424
|
+
}
|
|
425
|
+
// The hash to verify against, read through the session that
|
|
426
|
+
// authorized the request: a change committed since the credential
|
|
427
|
+
// leg revoked it, so a dead session has no hash to verify — the
|
|
428
|
+
// race was lost before the verify — and a live one names the hash
|
|
429
|
+
// the session was resolved under, never a later change's. Twin of
|
|
430
|
+
// the Rust spine's read at the same step.
|
|
431
|
+
const verified_hash = await query_session_live_password_hash(route, change_session_hash, ctx.account.id);
|
|
432
|
+
if (verified_hash === undefined)
|
|
433
|
+
return await lost_race();
|
|
434
|
+
const valid = await password.verify_password(current_password, verified_hash);
|
|
402
435
|
if (!valid) {
|
|
403
436
|
ip_reserved.reservation.record();
|
|
404
437
|
account_reservation?.record();
|
|
@@ -418,7 +451,7 @@ export const create_account_route_specs = (deps, options) => {
|
|
|
418
451
|
const new_hash = await password.hash_password(new_password);
|
|
419
452
|
// Conditional UPDATE keyed on the verified hash: closes the
|
|
420
453
|
// verify-write race with a concurrent password change that
|
|
421
|
-
//
|
|
454
|
+
// commits after the hash was read. Account-grain
|
|
422
455
|
// operation — `updated_by` stays null (the per-request actor is
|
|
423
456
|
// incidental; password is account-level state).
|
|
424
457
|
//
|
|
@@ -429,9 +462,23 @@ export const create_account_route_specs = (deps, options) => {
|
|
|
429
462
|
// Argon2 verify and hash held no connection). Twin of the Rust
|
|
430
463
|
// spine's `change_password`. The audit row is written last, so a
|
|
431
464
|
// refused row changes no password and revokes nothing. `null` when
|
|
432
|
-
// the
|
|
465
|
+
// the account or the session died since the hash read, or the
|
|
466
|
+
// UPDATE matched nothing — a concurrent change committed first.
|
|
433
467
|
const change = await transaction_with_post_commit_rollback(route, async (tx_ctx) => {
|
|
434
|
-
|
|
468
|
+
// The account row first, then the session again under it. The
|
|
469
|
+
// session died between the hash read and here when a delete
|
|
470
|
+
// (an undelete since makes the row live again, with the
|
|
471
|
+
// verified hash) or a logout or a session revoke committed —
|
|
472
|
+
// before the lock was granted, so this read sees it. A change
|
|
473
|
+
// by a revoked session would otherwise land. A logout or a
|
|
474
|
+
// session revoke takes no account row: one after this read
|
|
475
|
+
// meets the revoke-all at the session row, which ends that
|
|
476
|
+
// session with the rest. The same pair the token mint takes.
|
|
477
|
+
if (!(await query_account_lock_live(tx_ctx, ctx.account.id)) ||
|
|
478
|
+
!(await query_session_is_live(tx_ctx, change_session_hash, ctx.account.id))) {
|
|
479
|
+
return null;
|
|
480
|
+
}
|
|
481
|
+
const updated = await query_update_account_password(tx_ctx, ctx.account.id, new_hash, null, verified_hash);
|
|
435
482
|
if (!updated)
|
|
436
483
|
return null;
|
|
437
484
|
// revoke all sessions and API tokens (force re-auth everywhere)
|
|
@@ -463,25 +510,12 @@ export const create_account_route_specs = (deps, options) => {
|
|
|
463
510
|
// rather than netting out, which is the intent.
|
|
464
511
|
if (login_account_rate_limiter)
|
|
465
512
|
login_account_rate_limiter.reset(ctx.account.id);
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
// raced." Sessions/tokens were already revoked by the winner;
|
|
473
|
-
// no cookie clear here either.
|
|
474
|
-
ip_reserved.reservation.record();
|
|
475
|
-
account_reservation?.record();
|
|
476
|
-
await deps.audit.emit(route, {
|
|
477
|
-
event_type: 'password_change',
|
|
478
|
-
outcome: 'failure',
|
|
479
|
-
account_id: ctx.account.id,
|
|
480
|
-
ip: route.client_ip,
|
|
481
|
-
metadata: { reason: 'concurrent_change', credential_type }
|
|
482
|
-
});
|
|
483
|
-
return route_fail(REST_INVALID_CREDENTIALS);
|
|
484
|
-
}
|
|
513
|
+
// A concurrent password change committed after the hash was read —
|
|
514
|
+
// our `current_password` was correct then, but the row's
|
|
515
|
+
// `password_hash` no longer matches — or a delete or a purge did,
|
|
516
|
+
// and the row is a tombstone or gone.
|
|
517
|
+
if (!change)
|
|
518
|
+
return await lost_race();
|
|
485
519
|
const { sessions_revoked, tokens_revoked } = change;
|
|
486
520
|
// Close every live connection of this account now the password
|
|
487
521
|
// update, the revoke-all cascade, and its audit row have committed
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"admin_actions.d.ts","sourceRoot":"","sources":["../../src/lib/auth/admin_actions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,EAAuC,KAAK,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAIjG,OAAO,EAKN,KAAK,YAAY,EACjB,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"admin_actions.d.ts","sourceRoot":"","sources":["../../src/lib/auth/admin_actions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,EAAuC,KAAK,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAIjG,OAAO,EAKN,KAAK,YAAY,EACjB,MAAM,kBAAkB,CAAC;AA2D1B,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,WAAW,CAAC;AA0D3D,0CAA0C;AAC1C,MAAM,WAAW,kBAAkB;IAClC;;;;;OAKG;IACH,KAAK,CAAC,EAAE,YAAY,CAAC;CACrB;AAED;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,oBAAoB,GAChC,MAAM,yBAAyB,EAC/B,UAAS,kBAAuB,KAC9B,KAAK,CAAC,SAAS,CAwqBjB,CAAC"}
|
|
@@ -39,7 +39,7 @@ import { GRANT_PATH_ADMIN } from './grant_path_schema.js';
|
|
|
39
39
|
import { query_role_grant_offer_lock_for_account_removal, query_role_grant_offer_supersede_incoming, query_role_grant_offer_supersede_outgoing } from './role_grant_offer_queries.js';
|
|
40
40
|
import { emit_supersede_audits } from './role_grant_offer_actions.js';
|
|
41
41
|
import { queue_supersede_notifications } from './role_grant_offer_notifications.js';
|
|
42
|
-
import { query_account_by_email, query_account_by_id, query_account_by_username,
|
|
42
|
+
import { query_account_by_email, query_account_by_id, query_account_by_username, query_account_purge_advisory_lock, query_account_lock_for_purge, query_account_lock_live, query_account_soft_delete, query_account_undelete, query_actor_soft_delete, query_actor_undelete, query_actors_by_account, query_admin_account_list, query_purge_account } from './account_queries.js';
|
|
43
43
|
import { query_session_list_all_active, query_session_revoke_all_for_account } from './session_queries.js';
|
|
44
44
|
import { query_revoke_all_api_tokens_for_account } from './api_token_queries.js';
|
|
45
45
|
import { query_audit_log_list_role_grant_history, query_audit_log_list_with_usernames } from './audit_log_queries.js';
|
|
@@ -367,6 +367,14 @@ export const create_admin_actions = (deps, options = {}) => {
|
|
|
367
367
|
}
|
|
368
368
|
// Keeper + last-admin guards (fail-loud, before the tombstone).
|
|
369
369
|
await assert_account_removable(ctx, target_account_id, 'account_delete');
|
|
370
|
+
// The target's row, then the guards again under it — as a purge does
|
|
371
|
+
// (`account_purge_handler` has why): the guard's read of whether the
|
|
372
|
+
// target is an admin took no lock, and an accept making it one can commit
|
|
373
|
+
// before the tombstone takes the row. A row already gone or tombstoned
|
|
374
|
+
// skips the second pass; the tombstone then finds nothing.
|
|
375
|
+
if (await query_account_lock_live(ctx, target_account_id)) {
|
|
376
|
+
await assert_account_removable(ctx, target_account_id, 'account_delete');
|
|
377
|
+
}
|
|
370
378
|
// Snapshot actor names before the tombstone.
|
|
371
379
|
const actors = await query_actors_by_account(ctx, target_account_id);
|
|
372
380
|
const snapshot = await query_account_soft_delete(ctx, target_account_id, auth.actor.id);
|
|
@@ -436,14 +444,11 @@ export const create_admin_actions = (deps, options = {}) => {
|
|
|
436
444
|
reason: ERROR_PURGE_NOT_CONFIRMED
|
|
437
445
|
});
|
|
438
446
|
}
|
|
439
|
-
//
|
|
440
|
-
//
|
|
441
|
-
//
|
|
442
|
-
//
|
|
443
|
-
|
|
444
|
-
// them (`query_account_lock_admins_for_purge` has why). The last-admin guard
|
|
445
|
-
// then runs only for an admin target, in `assert_account_removable`.
|
|
446
|
-
await query_account_lock_admins_for_purge(ctx, input.account_id);
|
|
447
|
+
// The purge lock first, holding nothing: two purges' cascades cross at
|
|
448
|
+
// rows no row lock ahead of them covers, so purges take turns
|
|
449
|
+
// (`query_account_purge_advisory_lock` has why). The last-admin guard then
|
|
450
|
+
// runs only for an admin target, in `assert_account_removable`.
|
|
451
|
+
await query_account_purge_advisory_lock(ctx);
|
|
447
452
|
// Keeper + last-admin guards (fail-loud, before the cascade).
|
|
448
453
|
await assert_account_removable(ctx, input.account_id, 'account_purge');
|
|
449
454
|
const refuse_not_found = async () => {
|
|
@@ -461,6 +466,18 @@ export const create_admin_actions = (deps, options = {}) => {
|
|
|
461
466
|
// it — `query_account_lock_for_purge` has why.
|
|
462
467
|
if (!(await query_account_lock_for_purge(ctx, input.account_id)))
|
|
463
468
|
await refuse_not_found();
|
|
469
|
+
// The guards again, under the row lock. The first read of whether the
|
|
470
|
+
// target is an admin took no lock, and a purge holds no row of a
|
|
471
|
+
// non-admin target before its own: an accept making it an admin, in
|
|
472
|
+
// flight then, has committed by now (it holds the row this lock waited
|
|
473
|
+
// on), and a revoke the accept's grant let pass may have ended every
|
|
474
|
+
// other admin. For a target that was an admin, this count re-locks the
|
|
475
|
+
// rows the first one holds; it reaches past them only for an admin made
|
|
476
|
+
// in the window, the target or another — out of the guards' id order. A
|
|
477
|
+
// deadlock error then rolls one of the two transactions back whole,
|
|
478
|
+
// removing nothing: this purge, or the other, which may be a removal
|
|
479
|
+
// that would have committed (it answers 500).
|
|
480
|
+
await assert_account_removable(ctx, input.account_id, 'account_purge');
|
|
464
481
|
// Snapshot actors before the cascade removes them.
|
|
465
482
|
const actors = await query_actors_by_account(ctx, input.account_id);
|
|
466
483
|
// Before the cascade, whose `ON DELETE CASCADE` would take the offers
|
|
@@ -223,7 +223,7 @@ export const create_audit_emitter = (options) => {
|
|
|
223
223
|
// the whole row, and resolves `null`, so there is no row to announce.
|
|
224
224
|
const write = async (input) => {
|
|
225
225
|
try {
|
|
226
|
-
return await query_audit_log({ db }, input, audit_log_config);
|
|
226
|
+
return await query_audit_log({ db, log }, input, audit_log_config);
|
|
227
227
|
}
|
|
228
228
|
catch (err) {
|
|
229
229
|
audit_write_failures++;
|
|
@@ -282,7 +282,7 @@ export const create_audit_emitter = (options) => {
|
|
|
282
282
|
// Written in the request's transaction, so it commits or rolls back
|
|
283
283
|
// with the change it reports; a throw here fails the handler. The
|
|
284
284
|
// fan-out waits for the commit and is discarded on rollback.
|
|
285
|
-
const event = await query_audit_log({ db: ctx.db }, input, audit_log_config);
|
|
285
|
+
const event = await query_audit_log({ db: ctx.db, log }, input, audit_log_config);
|
|
286
286
|
emit_after_commit(ctx, () => notify(event));
|
|
287
287
|
};
|
|
288
288
|
// The decorated `emit` is what `emit_role_grant_target` captures below
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Logger } from '@fuzdev/fuz_util/log.ts';
|
|
1
2
|
import type { QueryDeps } from '../db/query_deps.js';
|
|
2
3
|
import { type AuditLogConfig, type AuditLogEvent, type AuditLogInput, type AuditLogListOptions, type AuditLogEventWithUsernamesJson, type RoleGrantHistoryEventJson } from './audit_log_schema.js';
|
|
3
4
|
/**
|
|
@@ -25,13 +26,20 @@ export declare const reset_audit_metadata_validation_failures: () => void;
|
|
|
25
26
|
export declare const get_audit_unknown_event_type_failures: () => number;
|
|
26
27
|
/** Reset the counter — for tests only. */
|
|
27
28
|
export declare const reset_audit_unknown_event_type_failures: () => void;
|
|
29
|
+
/**
|
|
30
|
+
* Deps for `query_audit_log`, which logs the drift it counts (an unknown
|
|
31
|
+
* `event_type`, a metadata mismatch) on `log`.
|
|
32
|
+
*/
|
|
33
|
+
export interface AuditLogQueryDeps extends QueryDeps {
|
|
34
|
+
log: Logger;
|
|
35
|
+
}
|
|
28
36
|
/**
|
|
29
37
|
* Insert an audit log entry.
|
|
30
38
|
*
|
|
31
39
|
* Returns the full row (`AUDIT_LOG_COLUMNS`) so callers receive DB-assigned
|
|
32
40
|
* fields (`id`, `seq`, `created_at`). Validates `metadata` against
|
|
33
41
|
* `config.metadata_schemas`; unknown `event_type` and metadata mismatches
|
|
34
|
-
* log
|
|
42
|
+
* log an error on `deps.log` and bump their counters
|
|
35
43
|
* but write the row anyway. Consumers extend the recognized set via
|
|
36
44
|
* `create_audit_log_config({extra_events})`.
|
|
37
45
|
*
|
|
@@ -40,14 +48,14 @@ export declare const reset_audit_unknown_event_type_failures: () => void;
|
|
|
40
48
|
* reach for `AppDeps.audit.emit` instead, which picks the transaction or the
|
|
41
49
|
* pool by outcome.
|
|
42
50
|
*
|
|
43
|
-
* @param deps - query dependencies
|
|
51
|
+
* @param deps - query dependencies and the logger the drift is reported on
|
|
44
52
|
* @param input - the audit event to record
|
|
45
53
|
* @param config - audit-log config. Defaults to `builtin_audit_log_config`.
|
|
46
54
|
* @returns the inserted audit log row
|
|
47
55
|
* @mutates `audit_log` table - inserts the new row
|
|
48
56
|
* @mutates drift counters - bumps `audit_unknown_event_type_failures` and/or `audit_metadata_validation_failures` on mismatch
|
|
49
57
|
*/
|
|
50
|
-
export declare const query_audit_log: <T extends string>(deps:
|
|
58
|
+
export declare const query_audit_log: <T extends string>(deps: AuditLogQueryDeps, input: AuditLogInput<T>, config?: AuditLogConfig) => Promise<AuditLogEvent>;
|
|
51
59
|
/**
|
|
52
60
|
* List audit log entries, newest first.
|
|
53
61
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"audit_log_queries.d.ts","sourceRoot":"","sources":["../../src/lib/auth/audit_log_queries.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAGrD,OAAO,EAGN,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,mBAAmB,EACxB,KAAK,8BAA8B,EACnC,KAAK,yBAAyB,EAC9B,MAAM,uBAAuB,CAAC;AAE/B;;;;;;;;;GASG;AACH,eAAO,MAAM,iBAAiB,mJAYyB,CAAC;AAExD;;;;GAIG;AACH,eAAO,MAAM,cAAc,8DAA4D,CAAC;AAaxF,iFAAiF;AACjF,eAAO,MAAM,sCAAsC,QAAO,MACvB,CAAC;AAEpC,0CAA0C;AAC1C,eAAO,MAAM,wCAAwC,QAAO,IAE3D,CAAC;AAYF,gFAAgF;AAChF,eAAO,MAAM,qCAAqC,QAAO,MACvB,CAAC;AAEnC,0CAA0C;AAC1C,eAAO,MAAM,uCAAuC,QAAO,I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C,aAAa,CAAC,CA0C9B,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,mCAAmC,GAC/C,MAAM,SAAS,EACf,UAAU,mBAAmB,KAC3B,OAAO,CAAC,KAAK,CAAC,8BAA8B,CAAC,CA4D/C,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,uCAAuC,GACnD,MAAM,SAAS,EACf,cAA+B,EAC/B,eAAU,KACR,OAAO,CAAC,KAAK,CAAC,yBAAyB,CAAC,CAmB1C,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,8BAA8B,GAC1C,MAAM,SAAS,EACf,QAAQ,IAAI,KACV,OAAO,CAAC,MAAM,CAMhB,CAAC"}
|
|
@@ -81,7 +81,7 @@ export const reset_audit_unknown_event_type_failures = () => {
|
|
|
81
81
|
* Returns the full row (`AUDIT_LOG_COLUMNS`) so callers receive DB-assigned
|
|
82
82
|
* fields (`id`, `seq`, `created_at`). Validates `metadata` against
|
|
83
83
|
* `config.metadata_schemas`; unknown `event_type` and metadata mismatches
|
|
84
|
-
* log
|
|
84
|
+
* log an error on `deps.log` and bump their counters
|
|
85
85
|
* but write the row anyway. Consumers extend the recognized set via
|
|
86
86
|
* `create_audit_log_config({extra_events})`.
|
|
87
87
|
*
|
|
@@ -90,7 +90,7 @@ export const reset_audit_unknown_event_type_failures = () => {
|
|
|
90
90
|
* reach for `AppDeps.audit.emit` instead, which picks the transaction or the
|
|
91
91
|
* pool by outcome.
|
|
92
92
|
*
|
|
93
|
-
* @param deps - query dependencies
|
|
93
|
+
* @param deps - query dependencies and the logger the drift is reported on
|
|
94
94
|
* @param input - the audit event to record
|
|
95
95
|
* @param config - audit-log config. Defaults to `builtin_audit_log_config`.
|
|
96
96
|
* @returns the inserted audit log row
|
|
@@ -100,7 +100,7 @@ export const reset_audit_unknown_event_type_failures = () => {
|
|
|
100
100
|
export const query_audit_log = async (deps, input, config = builtin_audit_log_config) => {
|
|
101
101
|
if (!config.event_types.includes(input.event_type)) {
|
|
102
102
|
audit_unknown_event_type_failures++;
|
|
103
|
-
|
|
103
|
+
deps.log.error(`[audit_log] unknown event_type '${input.event_type}' — register via create_audit_log_config({extra_events})`);
|
|
104
104
|
}
|
|
105
105
|
if (input.metadata != null) {
|
|
106
106
|
const schema = config.metadata_schemas[input.event_type];
|
|
@@ -108,7 +108,7 @@ export const query_audit_log = async (deps, input, config = builtin_audit_log_co
|
|
|
108
108
|
const result = parse(schema, input.metadata);
|
|
109
109
|
if (!result.ok) {
|
|
110
110
|
audit_metadata_validation_failures++;
|
|
111
|
-
|
|
111
|
+
deps.log.error(`[audit_log] metadata mismatch for '${input.event_type}':`, result.issues);
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
114
|
}
|
|
@@ -217,7 +217,7 @@ export const audit_metadata_schemas = Object.freeze({
|
|
|
217
217
|
description: 'Number of API tokens revoked as a side effect of the password change. Present on `outcome=success`.'
|
|
218
218
|
}),
|
|
219
219
|
reason: meta(optional(literal('concurrent_change')), {
|
|
220
|
-
description: 'Failure category. `concurrent_change` indicates another password change committed first against the same starting hash (verify-write race loser). Absent for typed-wrong-password failures.'
|
|
220
|
+
description: 'Failure category. `concurrent_change` indicates the conditional write matched nothing: another password change committed first against the same starting hash, or a delete tombstoned the account (verify-write race loser). Absent for typed-wrong-password failures.'
|
|
221
221
|
}),
|
|
222
222
|
credential_type: credential_type_meta
|
|
223
223
|
})),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth_ddl.d.ts","sourceRoot":"","sources":["../../src/lib/auth/auth_ddl.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAMH,eAAO,MAAM,cAAc,6ZAazB,CAAC;
|
|
1
|
+
{"version":3,"file":"auth_ddl.d.ts","sourceRoot":"","sources":["../../src/lib/auth/auth_ddl.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAMH,eAAO,MAAM,cAAc,6ZAazB,CAAC;AAMH,eAAO,MAAM,YAAY,0ZAUvB,CAAC;AAEH,eAAO,MAAM,WAAW,wEAC0C,CAAC;AAEnE;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB,8FACqD,CAAC;AAEzF,eAAO,MAAM,iBAAiB,2ZAU5B,CAAC;AAEH,eAAO,MAAM,kBAAkB,UAI9B,CAAC;AAKF,eAAO,MAAM,mBAAmB,0RAO9B,CAAC;AAEH,eAAO,MAAM,oBAAoB,UAGhC,CAAC;AAEF,eAAO,MAAM,gBAAgB,iUAU3B,CAAC;AAEH,eAAO,MAAM,mBAAmB,4GACsE,CAAC;AAEvG,eAAO,MAAM,yBAAyB,6FACiD,CAAC;AAExF,eAAO,MAAM,eAAe,gFAC8C,CAAC;AAE3E,eAAO,MAAM,qBAAqB,wJAIhC,CAAC;AAEH,6FAA6F;AAC7F,eAAO,MAAM,mBAAmB,yHAGP,CAAC;AAE1B,eAAO,MAAM,aAAa,6ZAUxB,CAAC;AAEH,eAAO,MAAM,cAAc,UAI1B,CAAC;AAEF,eAAO,MAAM,mBAAmB,oMAM9B,CAAC;AAEH,eAAO,MAAM,iBAAiB,sEACkC,CAAC"}
|
package/dist/auth/auth_ddl.js
CHANGED
|
@@ -33,6 +33,10 @@ CREATE TABLE IF NOT EXISTS account (
|
|
|
33
33
|
deleted_at TIMESTAMPTZ,
|
|
34
34
|
deleted_by UUID
|
|
35
35
|
)`;
|
|
36
|
+
// The `updated_by` / `deleted_by` foreign keys stay in this frozen v0 body —
|
|
37
|
+
// the appended `drop_provenance_stamp_foreign_keys` migration drops them, as
|
|
38
|
+
// it drops `role_grant`'s `granted_by` / `revoked_by` / `source_offer_id`
|
|
39
|
+
// (`auth/migrations.ts` has why).
|
|
36
40
|
export const ACTOR_SCHEMA = `
|
|
37
41
|
CREATE TABLE IF NOT EXISTS actor (
|
|
38
42
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
package/dist/auth/cleanup.js
CHANGED
|
@@ -225,7 +225,7 @@ export const cleanup_expired_role_grant_offers = async (deps) => {
|
|
|
225
225
|
// Account-grain offers (no `to_actor_id`) never bound to a
|
|
226
226
|
// specific actor and leave the field null. No request is behind a
|
|
227
227
|
// sweep, so `ip` stays null.
|
|
228
|
-
written.push(await query_audit_log({ db: tx }, {
|
|
228
|
+
written.push(await query_audit_log({ db: tx, log: deps.log }, {
|
|
229
229
|
event_type: 'role_grant_offer_expire',
|
|
230
230
|
actor_id: offer.from_actor_id,
|
|
231
231
|
target_account_id: offer.to_account_id,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migrations.d.ts","sourceRoot":"","sources":["../../src/lib/auth/migrations.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AA+BH,OAAO,EAGN,KAAK,kBAAkB,EACvB,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"migrations.d.ts","sourceRoot":"","sources":["../../src/lib/auth/migrations.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AA+BH,OAAO,EAGN,KAAK,kBAAkB,EACvB,MAAM,kBAAkB,CAAC;AAsS1B;;;GAGG;AACH,eAAO,MAAM,iBAAiB,EAAE,kBAG/B,CAAC"}
|
package/dist/auth/migrations.js
CHANGED
|
@@ -52,6 +52,19 @@ import { ROLE_GRANT_OFFER_SCHEMA, ROLE_GRANT_OFFER_PENDING_UNIQUE_INDEX, ROLE_GR
|
|
|
52
52
|
import { create_spine_migration_namespace } from '../db/migrate.js';
|
|
53
53
|
/** Namespace identifier for fuz_app auth migrations. */
|
|
54
54
|
const AUTH_MIGRATION_NAMESPACE = 'fuz_auth';
|
|
55
|
+
/**
|
|
56
|
+
* The statements of the `drop_provenance_stamp_foreign_keys` migration: the
|
|
57
|
+
* foreign keys of the provenance stamps, by their default names
|
|
58
|
+
* (`<table>_<column>_fkey`, the same on both spines). Statement for statement
|
|
59
|
+
* the Rust spine's `drop_provenance_stamp_foreign_keys.sql`.
|
|
60
|
+
*/
|
|
61
|
+
const DROP_PROVENANCE_STAMP_FOREIGN_KEYS = [
|
|
62
|
+
'ALTER TABLE actor DROP CONSTRAINT IF EXISTS actor_updated_by_fkey',
|
|
63
|
+
'ALTER TABLE actor DROP CONSTRAINT IF EXISTS actor_deleted_by_fkey',
|
|
64
|
+
'ALTER TABLE role_grant DROP CONSTRAINT IF EXISTS role_grant_granted_by_fkey',
|
|
65
|
+
'ALTER TABLE role_grant DROP CONSTRAINT IF EXISTS role_grant_revoked_by_fkey',
|
|
66
|
+
'ALTER TABLE role_grant DROP CONSTRAINT IF EXISTS role_grant_source_offer_id_fkey'
|
|
67
|
+
];
|
|
55
68
|
/**
|
|
56
69
|
* Auth schema migrations in order.
|
|
57
70
|
*
|
|
@@ -284,6 +297,28 @@ const AUTH_MIGRATIONS = [
|
|
|
284
297
|
CHECK (username = lower(username))`);
|
|
285
298
|
}
|
|
286
299
|
}
|
|
300
|
+
},
|
|
301
|
+
// The provenance stamps carry no foreign key: `actor.updated_by` /
|
|
302
|
+
// `deleted_by`, `role_grant.granted_by` / `revoked_by` and
|
|
303
|
+
// `role_grant.source_offer_id`.
|
|
304
|
+
//
|
|
305
|
+
// A stamp records who did a thing; nothing authorizes on it, so it keeps the
|
|
306
|
+
// id it was written with after its actor (or offer) is purged, as
|
|
307
|
+
// `audit_log`'s identity columns and `account`'s stamps do. With the foreign
|
|
308
|
+
// key, a purge's cascade wrote other accounts' rows (`ON DELETE SET NULL`)
|
|
309
|
+
// in whatever order its plan walked them, and a write stamping an actor
|
|
310
|
+
// being purged waited on that actor's row while holding the row the cascade
|
|
311
|
+
// needed next: a deadlock. Without it, the cascade never writes a stamp and
|
|
312
|
+
// a stamp write takes no lock on its actor. The references that carry
|
|
313
|
+
// meaning keep theirs: every `actor_id` and `account_id`, an offer's
|
|
314
|
+
// parties, an invite's issuer. `IF EXISTS`, so a re-run is a no-op.
|
|
315
|
+
{
|
|
316
|
+
name: 'drop_provenance_stamp_foreign_keys',
|
|
317
|
+
up: async (db) => {
|
|
318
|
+
for (const sql of DROP_PROVENANCE_STAMP_FOREIGN_KEYS) {
|
|
319
|
+
await db.query(sql);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
287
322
|
}
|
|
288
323
|
];
|
|
289
324
|
/**
|
|
@@ -684,7 +684,7 @@ export declare const role_grant_assign_action_spec: {
|
|
|
684
684
|
}>;
|
|
685
685
|
async: true;
|
|
686
686
|
description: string;
|
|
687
|
-
error_reasons: ("role_grant_offer_not_authorized" | "role_grant_offer_actor_account_mismatch" | "role_grant_builtin_scoped" | "role_not_web_grantable" | "insufficient_permissions")[];
|
|
687
|
+
error_reasons: ("role_grant_offer_not_authorized" | "role_grant_offer_actor_account_mismatch" | "role_grant_builtin_scoped" | "authentication_required" | "role_not_web_grantable" | "insufficient_permissions")[];
|
|
688
688
|
rate_limit: "account";
|
|
689
689
|
};
|
|
690
690
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"role_grant_offer_action_specs.d.ts","sourceRoot":"","sources":["../../src/lib/auth/role_grant_offer_action_specs.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAGH,OAAO,EAcN,KAAK,KAAK,EACV,MAAM,8BAA8B,CAAC;AAGtC,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAC;AAkB3E,oEAAoE;AACpE,eAAO,MAAM,kCAAkC,EAAG,8BAAuC,CAAC;AAC1F,kEAAkE;AAClE,eAAO,MAAM,+BAA+B,EAAG,2BAAoC,CAAC;AACpF,sDAAsD;AACtD,eAAO,MAAM,8BAA8B,EAAG,0BAAmC,CAAC;AAClF,wGAAwG;AACxG,eAAO,MAAM,gCAAgC,EAAG,4BAAqC,CAAC;AACtF,uIAAuI;AACvI,eAAO,MAAM,yCAAyC,EACrD,qCAA8C,CAAC;AAChD,gKAAgK;AAChK,eAAO,MA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CAAC;AAEtC,eAAO,MAAM,oCAAoC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAWZ,CAAC;AAEtC,eAAO,MAAM,iCAAiC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAWT,CAAC;AAEtC,eAAO,MAAM,oCAAoC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAWZ,CAAC;AAEtC;;;;;GAKG;AACH,eAAO,MAAM,6BAA6B;;;;;;;;;;;;;;;;;;;;;;;;CAkBL,CAAC;AAEtC;;;;GAIG;AACH,eAAO,MAAM,6BAA6B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAoBL,CAAC;AAEtC;;;;GAIG;AACH,eAAO,MAAM,iCAAiC,EAAE,KAAK,CAAC,yBAAyB,CAS9E,CAAC"}
|
|
@@ -407,7 +407,8 @@ export const role_grant_assign_action_spec = {
|
|
|
407
407
|
ERROR_ROLE_NOT_WEB_GRANTABLE,
|
|
408
408
|
ERROR_ROLE_GRANT_BUILTIN_SCOPED,
|
|
409
409
|
ERROR_ROLE_GRANT_OFFER_NOT_AUTHORIZED,
|
|
410
|
-
ERROR_ROLE_GRANT_OFFER_ACTOR_ACCOUNT_MISMATCH
|
|
410
|
+
ERROR_ROLE_GRANT_OFFER_ACTOR_ACCOUNT_MISMATCH,
|
|
411
|
+
ERROR_AUTHENTICATION_REQUIRED
|
|
411
412
|
],
|
|
412
413
|
rate_limit: 'account'
|
|
413
414
|
};
|
|
@@ -102,6 +102,18 @@ export declare const emit_supersede_audits: (ctx: ActionActorContext, audit: Aud
|
|
|
102
102
|
* check, say) reads through it. **Read-only** — the callback decides, it never
|
|
103
103
|
* writes; a write would commit or roll back with the request, and nothing
|
|
104
104
|
* enforces this but the callback.
|
|
105
|
+
*
|
|
106
|
+
* **Runs under the scope lock** when the input is scoped: both verbs take
|
|
107
|
+
* `scope_id`'s lock shared (`query_scope_lock_shared`) before calling it, so
|
|
108
|
+
* a scope-existence read sees every teardown that committed first — under READ
|
|
109
|
+
* COMMITTED, where each statement takes a fresh snapshot; under REPEATABLE
|
|
110
|
+
* READ the snapshot predates the lock's wait and the read would miss it — and
|
|
111
|
+
* a teardown still to come waits for the request to commit. That holds only
|
|
112
|
+
* for a consumer teardown that goes through
|
|
113
|
+
* `query_role_grant_revoke_for_scope` before it removes the scope row, or
|
|
114
|
+
* takes `query_scope_lock_exclusive` first; one that removes the row first
|
|
115
|
+
* leaves the window open, and one that locks the row first deadlocks with a
|
|
116
|
+
* callback that locks it.
|
|
105
117
|
*/
|
|
106
118
|
export type RoleGrantOfferCreateAuthorize = (auth: RequestContext, input: {
|
|
107
119
|
to_account_id: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"role_grant_offer_actions.d.ts","sourceRoot":"","sources":["../../src/lib/auth/role_grant_offer_actions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwDG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAEtD,OAAO,EAEN,KAAK,kBAAkB,EACvB,KAAK,aAAa,EAClB,KAAK,SAAS,EACd,MAAM,4BAA4B,CAAC;AAIpC,OAAO,EAMN,KAAK,YAAY,EACjB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAGN,KAAK,eAAe,EACpB,MAAM,8BAA8B,CAAC;AA6BtC,OAAO,EAGN,KAAK,cAAc,EACnB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,WAAW,CAAC;AAC3D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAQN,KAAK,6BAA6B,EAElC,MAAM,qCAAqC,CAAC;AA6C7C;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,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G,CAC3C,IAAI,EAAE,cAAc,EACpB,KAAK,EAAE;IACN,aAAa,EAAE,MAAM,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;CACxB,EACD,IAAI,EAAE;IAAE,GAAG,EAAE,MAAM,CAAA;CAAE,EACrB,GAAG,EAAE,aAAa,KACd,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;AAEhC,qDAAqD;AACrD,MAAM,WAAW,2BAA2B;IAC3C;;;;;OAKG;IACH,KAAK,CAAC,EAAE,YAAY,CAAC;IACrB,0FAA0F;IAC1F,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;;;;;;;OAQG;IACH,SAAS,CAAC,EAAE,6BAA6B,CAAC;CAC1C;AA6CD;;;;;;;GAOG;AACH,eAAO,MAAM,+BAA+B,GAC3C,MAAM,yBAAyB,EAC/B,UAAS,2BAAgC,KACvC,KAAK,CAAC,SAAS,CA8tBjB,CAAC"}
|
|
@@ -63,8 +63,8 @@ import { builtin_role_specs, is_builtin_role, ROLE_ADMIN, ROLE_KEEPER, role_has_
|
|
|
63
63
|
import { GRANT_PATH_ADMIN } from './grant_path_schema.js';
|
|
64
64
|
import { ROLE_GRANT_OFFER_DEFAULT_TTL_MS, to_role_grant_offer_json } from './role_grant_offer_schema.js';
|
|
65
65
|
import { query_role_grant_offer_create, query_role_grant_offer_decline, query_role_grant_offer_retract, query_role_grant_offer_list, query_role_grant_offer_history_for_account, query_accept_offer, RoleGrantOfferActorAccountMismatchError, RoleGrantOfferActorMismatchError, RoleGrantOfferGrantorNotActiveError, RoleGrantOfferRecipientNotActiveError, RoleGrantOfferAlreadyTerminalError, RoleGrantOfferBuiltinRefusedError, RoleGrantOfferExpiredError, RoleGrantOfferNotFoundError, RoleGrantOfferSelfTargetError, query_revoke_role_grant } from './role_grant_offer_queries.js';
|
|
66
|
-
import { query_account_has_active_global_role, query_account_has_global_role, query_count_active_accounts_with_global_role_locked, query_create_role_grant, query_role_grant_find_active_role_for_actor } from './role_grant_queries.js';
|
|
67
|
-
import { query_active_actors_by_account } from './account_queries.js';
|
|
66
|
+
import { query_account_has_active_global_role, query_account_has_global_role, query_count_active_accounts_with_global_role_locked, query_create_role_grant, query_role_grant_find_active_role_for_actor, query_scope_lock_shared } from './role_grant_queries.js';
|
|
67
|
+
import { query_account_lock_live_many, query_active_actors_by_account } from './account_queries.js';
|
|
68
68
|
import { has_scoped_role } from './request_context.js';
|
|
69
69
|
import { build_role_grant_offer_accepted_notification, build_role_grant_offer_declined_notification, build_role_grant_offer_received_notification, build_role_grant_offer_retracted_notification, build_role_grant_revoked_notification, queue_offer_notification, queue_supersede_notifications } from './role_grant_offer_notifications.js';
|
|
70
70
|
import { ERROR_AUTHENTICATION_REQUIRED, ERROR_INSUFFICIENT_PERMISSIONS, ERROR_ROLE_GRANT_NOT_FOUND, ERROR_ROLE_NOT_WEB_GRANTABLE } from '../http/error_schemas.js';
|
|
@@ -215,17 +215,6 @@ export const create_role_grant_offer_actions = (deps, options = {}) => {
|
|
|
215
215
|
reason: ERROR_ROLE_GRANT_OFFER_ACTOR_ACCOUNT_MISMATCH
|
|
216
216
|
})
|
|
217
217
|
: jsonrpc_errors.not_found('account');
|
|
218
|
-
// The recipient's active actors, refusing a recipient that can't receive a
|
|
219
|
-
// role: a missing or soft-deleted account (no active actor), or a named
|
|
220
|
-
// actor that is not one of them. Runs after every authority gate, so a
|
|
221
|
-
// caller refused the conferral learns nothing of the recipient.
|
|
222
|
-
const require_active_recipient = async (ctx, to_account_id, to_actor_id) => {
|
|
223
|
-
const actors = await query_active_actors_by_account(ctx, to_account_id);
|
|
224
|
-
if (to_actor_id != null ? !actors.some((a) => a.id === to_actor_id) : actors.length === 0) {
|
|
225
|
-
throw recipient_not_found_error(to_actor_id);
|
|
226
|
-
}
|
|
227
|
-
return actors;
|
|
228
|
-
};
|
|
229
218
|
// Returns {offer} only — no auto-accept. Recipient must call
|
|
230
219
|
// role_grant_offer_accept; admin tests drive the full consent flow over
|
|
231
220
|
// RPC (see testing/admin_integration.ts `offer_and_accept`), or seed
|
|
@@ -257,6 +246,12 @@ export const create_role_grant_offer_actions = (deps, options = {}) => {
|
|
|
257
246
|
reason: ERROR_ROLE_GRANT_OFFER_NOT_AUTHORIZED
|
|
258
247
|
});
|
|
259
248
|
}
|
|
249
|
+
// A scoped offer takes the scope lock before the callback reads the scope,
|
|
250
|
+
// so a teardown that committed first is seen (the callback refuses the
|
|
251
|
+
// dead scope) and one still to come waits for this offer, then supersedes
|
|
252
|
+
// it. The query takes it again, free.
|
|
253
|
+
if (input.scope_id != null)
|
|
254
|
+
await query_scope_lock_shared(ctx, input.scope_id);
|
|
260
255
|
const authorized = await authorize(auth, {
|
|
261
256
|
to_account_id: input.to_account_id,
|
|
262
257
|
role: input.role,
|
|
@@ -599,7 +594,8 @@ export const create_role_grant_offer_actions = (deps, options = {}) => {
|
|
|
599
594
|
// `role_grant_offer_create`. Gated at the dispatcher on a **global** admin
|
|
600
595
|
// (`roles: ['admin']`) and re-checked here, it re-checks admin-grantability
|
|
601
596
|
// (so keeper / CLI-only roles can't be web-assigned), refuses a scoped
|
|
602
|
-
// builtin role, runs the consumer's `authorize` callback,
|
|
597
|
+
// builtin role, runs the consumer's `authorize` callback, locks both
|
|
598
|
+
// parties' account rows and refuses either one removed, resolves the
|
|
603
599
|
// target actor, writes the idempotent grant with
|
|
604
600
|
// the input's `(scope_kind, scope_id)` pair, and emits a `role_grant_create`
|
|
605
601
|
// audit row — the same event the offer-accept and self-service paths emit.
|
|
@@ -644,7 +640,12 @@ export const create_role_grant_offer_actions = (deps, options = {}) => {
|
|
|
644
640
|
// The consumer's offer policy binds the immediate path too: assign is an
|
|
645
641
|
// offer the grantee doesn't get to decline, so a grant the `authorize`
|
|
646
642
|
// callback would refuse as an offer (a scope that doesn't exist, a role
|
|
647
|
-
// that must be scoped) is refused here, with the offer path's reason.
|
|
643
|
+
// that must be scoped) is refused here, with the offer path's reason. A
|
|
644
|
+
// scoped grant takes the scope lock first, as offer-create does, so the
|
|
645
|
+
// callback reads the scope after any teardown that committed first, and a
|
|
646
|
+
// teardown still to come waits for this grant and then revokes it.
|
|
647
|
+
if (input.scope_id != null)
|
|
648
|
+
await query_scope_lock_shared(ctx, input.scope_id);
|
|
648
649
|
const authorized = await authorize(auth, {
|
|
649
650
|
to_account_id: input.to_account_id,
|
|
650
651
|
role: input.role,
|
|
@@ -657,11 +658,38 @@ export const create_role_grant_offer_actions = (deps, options = {}) => {
|
|
|
657
658
|
reason: ERROR_ROLE_GRANT_OFFER_NOT_AUTHORIZED
|
|
658
659
|
});
|
|
659
660
|
}
|
|
660
|
-
//
|
|
661
|
-
//
|
|
662
|
-
//
|
|
663
|
-
//
|
|
664
|
-
|
|
661
|
+
// Both parties' account rows, locked in one statement in id order — the
|
|
662
|
+
// lock offer-create takes (`query_role_grant_offer_create`), at its
|
|
663
|
+
// position after every authority gate, so a caller refused the conferral
|
|
664
|
+
// learns nothing of the recipient. The credential was read before this
|
|
665
|
+
// transaction and nothing held the recipient: a delete or a purge of
|
|
666
|
+
// either, committed since, is waited for and seen, and one still to come
|
|
667
|
+
// waits for the grant to commit — so no grant lands on a tombstone (an undelete would bring
|
|
668
|
+
// it back) or meets a purged actor's foreign key. Judged recipient first,
|
|
669
|
+
// then the caller, as offer-create judges them.
|
|
670
|
+
const live = await query_account_lock_live_many(ctx, [input.to_account_id, auth.account.id]);
|
|
671
|
+
// The recipient: a live account with an active actor (the named one, when
|
|
672
|
+
// an actor is named). A missing or removed recipient 404-masks.
|
|
673
|
+
const actors = live.has(input.to_account_id)
|
|
674
|
+
? await query_active_actors_by_account(ctx, input.to_account_id)
|
|
675
|
+
: [];
|
|
676
|
+
if (input.to_actor_id != null
|
|
677
|
+
? !actors.some((a) => a.id === input.to_actor_id)
|
|
678
|
+
: actors.length === 0) {
|
|
679
|
+
throw recipient_not_found_error(input.to_actor_id);
|
|
680
|
+
}
|
|
681
|
+
// The caller: a live actor of a live account. One removed since its
|
|
682
|
+
// credential was read is refused as the dead credential it now is, as
|
|
683
|
+
// offer-create refuses its grantor, with no audit row from an account
|
|
684
|
+
// that is gone.
|
|
685
|
+
if (!live.has(auth.account.id) ||
|
|
686
|
+
!(await query_active_actors_by_account(ctx, auth.account.id)).some((a) => a.id === auth.actor.id)) {
|
|
687
|
+
throw jsonrpc_errors.unauthenticated('unauthenticated', {
|
|
688
|
+
reason: ERROR_AUTHENTICATION_REQUIRED
|
|
689
|
+
});
|
|
690
|
+
}
|
|
691
|
+
// The grant's target actor: the named one, else the account's sole active
|
|
692
|
+
// actor (a multi-actor account must name one).
|
|
665
693
|
let target_actor_id;
|
|
666
694
|
if (input.to_actor_id != null) {
|
|
667
695
|
target_actor_id = input.to_actor_id;
|