@consiliency/agent-board-schema 1.75.0 → 1.79.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/fixtures/already-applied.json +16 -0
- package/migrations/20261109000100_agent_board_step_up_groundwork.sql +343 -0
- package/migrations/20261120000200_agent_board_thread_key_serialize.sql +118 -0
- package/migrations/20261121000100_agent_board_thread_key_guards.sql +196 -0
- package/migrations/20261124000100_agent_board_step_up_enforcement.sql +1213 -0
- package/package.json +1 -1
- package/schema-manifest.json +39 -3
- package/src/deployment-drift-main.test.mjs +89 -6
- package/src/deployment-drift.test.mjs +20 -1
- package/src/tooling.test.mjs +10 -2
- package/tests/agent_board_717_message_replay_scope.test.sql +39 -2
- package/tests/agent_board_717_tasking_replay_scope.test.sql +21 -2
- package/tests/agent_board_enrollment_audit_content.test.sql +6 -1
- package/tests/agent_board_role_guard.test.sql +3 -1
- package/tests/agent_board_send_outcome.test.sql +39 -1
- package/tests/agent_board_session_identity_approval_revocation.test.sql +5 -0
- package/tests/agent_board_step_up.test.sql +991 -0
- package/tests/agent_board_step_up_helper.test.sql +815 -0
- package/tests/agent_board_thread_key_guards.test.sql +186 -0
- package/tests/agent_board_thread_key_serialize.test.sql +182 -0
- package/tests/agent_board_write_enforcement_class.test.sql +8 -4
- package/tests/catalog/function_execute_privileges.json +72 -0
- package/tests/catalog/p_metadata_parameters.json +32 -0
- package/tests/catalog/step_up_gated_closure.json +24 -0
- package/tests/fixtures/pgtap-unexposed.sql +9 -4
- package/tests/isolation/expected/create_or_find_thread_same_key_race.out +641 -0
- package/tests/isolation/expected/session_identity_links.out +4 -0
- package/tests/isolation/specs/create_or_find_thread_same_key_race.spec +252 -0
- package/tests/isolation/specs/session_identity_links.spec +5 -0
- package/tests/mutations/669/M10_service_role_blanket.sql +10 -0
- package/tests/mutations/669/M12a_no_parse_wrapper.sql +17 -0
- package/tests/mutations/669/M12b_no_session_wrapper.sql +23 -0
- package/tests/mutations/669/M12c_no_claim_type_guard.sql +13 -0
- package/tests/mutations/669/M12d_no_amr_element_guards.sql +15 -0
- package/tests/mutations/669/M14_now_not_clock.sql +9 -0
- package/tests/mutations/669/M15_classifier_reads_metadata.sql +17 -0
- package/tests/mutations/669/M17_skip_ledger.sql +15 -0
- package/tests/mutations/669/M18_service_role_sub_insensitive.sql +9 -0
- package/tests/mutations/669/M18b_drop_uid_conjunct.sql +9 -0
- package/tests/mutations/669/M23_definer_wrapper_over_writer.sql +5 -0
- package/tests/mutations/669/M3_age_from_iat.sql +9 -0
- package/tests/mutations/669/M4_window_900.sql +9 -0
- package/tests/mutations/669/M4b_lt_to_le.sql +9 -0
- package/tests/mutations/669/M5_no_skew_bound.sql +9 -0
- package/tests/mutations/669/M6a_user_metadata_amr.sql +9 -0
- package/tests/mutations/669/M6b_app_metadata_claim.sql +9 -0
- package/tests/mutations/669/M6c_legacy_guc.sql +9 -0
- package/tests/mutations/669/M7_either_claim_any_human.sql +9 -0
- package/tests/mutations/669/M8_any_amr_method.sql +9 -0
- package/tests/mutations/669/M8b_accept_aal2.sql +9 -0
- package/tests/mutations/669/M9_every_kind.sql +9 -0
- package/tests/mutations/669/MAL_allowlist_nonempty.sql +9 -0
- package/tests/mutations/669/MAR_writer_arg_renamed.sql +14 -0
- package/tests/mutations/669/MAU_audit_mode_retyped.sql +2 -0
- package/tests/mutations/669/MA_helper_always_raises.sql +10 -0
- package/tests/mutations/669/MDX_dynamic_execute_definer.sql +5 -0
- package/tests/mutations/669/MD_detail_carries_value.sql +12 -0
- package/tests/mutations/669/MEC0_caller_of_helper.sql +4 -0
- package/tests/mutations/669/MEC0b_overload_caller.sql +4 -0
- package/tests/mutations/669/MG1_helper_granted_authenticated.sql +2 -0
- package/tests/mutations/669/MG2_ledger_insert_authenticated.sql +2 -0
- package/tests/mutations/669/MG3_ledger_policy.sql +2 -0
- package/tests/mutations/669/MR1_writer_no_class_check.sql +9 -0
- package/tests/mutations/669/MR2_writer_wide_window.sql +9 -0
- package/tests/mutations/669/MR3_writer_prunes_everyone.sql +11 -0
- package/tests/mutations/669/MR4_writer_lower_exclusive.sql +9 -0
- package/tests/mutations/669/MR5_writer_upper_exclusive.sql +9 -0
- package/tests/mutations/669/MR6_writer_upper_61.sql +9 -0
- package/tests/mutations/669/MW2_second_ledger_writer.sql +4 -0
- package/tests/mutations/669/MXS_cross_schema_wrapper.sql +4 -0
- package/tests/mutations/669/run.sh +80 -0
- package/tests/mutations/669b/M11_ceil_first.sql +10 -0
- package/tests/mutations/669b/M11_gate_first.sql +10 -0
- package/tests/mutations/669b/M11_grant_first.sql +10 -0
- package/tests/mutations/669b/M11_inv_first.sql +10 -0
- package/tests/mutations/669b/M11_mem_first.sql +10 -0
- package/tests/mutations/669b/M11_readmit_first.sql +10 -0
- package/tests/mutations/669b/M13a_gate_member_preset.sql +12 -0
- package/tests/mutations/669b/M13b_ungate_admin_preset.sql +12 -0
- package/tests/mutations/669b/M16_actor_is_target.sql +14 -0
- package/tests/mutations/669b/M19_drop_readmit.sql +9 -0
- package/tests/mutations/669b/M1_drop_grant.sql +9 -0
- package/tests/mutations/669b/M20_drop_d5_refusal.sql +9 -0
- package/tests/mutations/669b/M21_drop_removal.sql +9 -0
- package/tests/mutations/669b/M21b_only_removed.sql +9 -0
- package/tests/mutations/669b/M21c_gate_members.sql +12 -0
- package/tests/mutations/669b/M21d_requested_state.sql +9 -0
- package/tests/mutations/669b/M23b_api_wrapper_over_audit_writer.sql +6 -0
- package/tests/mutations/669b/M23c_drop_register_type_refusal.sql +9 -0
- package/tests/mutations/669b/M24_drop_kind_refusal.sql +9 -0
- package/tests/mutations/669b/M24b_drop_auth_bind_refusal.sql +9 -0
- package/tests/mutations/669b/M2a_drop_gate.sql +9 -0
- package/tests/mutations/669b/M2b_drop_ceiling.sql +9 -0
- package/tests/mutations/669b/M2c_drop_invite.sql +9 -0
- package/tests/mutations/669b/MAL2_drop_otp.sql +9 -0
- package/tests/mutations/669b/MAL3_admit_passkey.sql +9 -0
- package/tests/mutations/669b/MD7a_no_revocation.sql +2 -0
- package/tests/mutations/669b/MD7b_overwrite_revoked.sql +2 -0
- package/tests/mutations/669b/MD7c_revoke_members.sql +2 -0
- package/tests/mutations/669b/MD7d_revoke_expired.sql +2 -0
- package/tests/mutations/669b/ME1_wrapper_over_gate.sql +7 -0
- package/tests/mutations/669b/MEC2_write_after_helper.sql +10 -0
- package/tests/mutations/669b/MQX_query_to_xml_definer.sql +6 -0
- package/tests/mutations/669b/MQXb_ts_stat_other_schema.sql +4 -0
- package/tests/mutations/669b/MTR_trigger_route.sql +9 -0
- package/tests/mutations/669b/MTRb_new_assign.sql +11 -0
- package/tests/mutations/669b/MTRc_sync_assigns_value.sql +47 -0
- package/tests/mutations/669b/MTX1_tombstone_second_gated_call.sql +15 -0
- package/tests/mutations/669b/MTX2_tombstone_non_delegate_target.sql +10 -0
- package/tests/mutations/669b/MXS_other_schema_names_gated.sql +5 -0
- package/tests/mutations/669b/run.sh +83 -0
- package/tests/mutations/670/M18a_read_operation_default_dropped.sql +11 -0
- package/tests/mutations/670/M18b_read_operation_default_changed.sql +7 -0
- package/tests/mutations/670/M3-DM_helper_on_replay_branch.sql +10 -0
- package/tests/mutations/670/M3-MC_helper_on_replay_branch.sql +10 -0
- package/tests/mutations/s12/M0_identity.sql +56 -0
- package/tests/mutations/s12/M1_serialise_actor_key.sql +57 -0
- package/tests/mutations/s12/M1b_serialise_key_only.sql +57 -0
- package/tests/mutations/s12/M2_unique_index_no_handler.sql +9 -0
- package/tests/mutations/s12/M3_no_trim.sql +56 -0
- package/tests/mutations/s12/M4_casefold.sql +56 -0
- package/tests/mutations/s12/M5_lookup_ignores_actor.sql +56 -0
- package/tests/mutations/s12/M6_reuse_reports_false.sql +56 -0
- package/tests/mutations/s12/run.sh +112 -0
- package/tests/mutations/s12-fix/M0_identity.sql +83 -0
- package/tests/mutations/s12-fix/M10_security_invoker.sql +9 -0
- package/tests/mutations/s12-fix/M11_search_path_changed.sql +9 -0
- package/tests/mutations/s12-fix/M12_reuse_writes_task.sql +84 -0
- package/tests/mutations/s12-fix/M13_dead_inbox_write.sql +84 -0
- package/tests/mutations/s12-fix/M14_metadata_unchecked.sql +78 -0
- package/tests/mutations/s12-fix/M15_metadata_check_after_lock.sql +84 -0
- package/tests/mutations/s12-fix/M16_sql_null_metadata_refused.sql +83 -0
- package/tests/mutations/s12-fix/M17_isolation_unchecked.sql +70 -0
- package/tests/mutations/s12-fix/M18_isolation_check_after_lock.sql +82 -0
- package/tests/mutations/s12-fix/M19_isolation_rr_only.sql +83 -0
- package/tests/mutations/s12-fix/M1_lock_dropped.sql +78 -0
- package/tests/mutations/s12-fix/M1b_lock_key_only.sql +83 -0
- package/tests/mutations/s12-fix/M20_isolation_unsafe_levels_only.sql +83 -0
- package/tests/mutations/s12-fix/M21_isolation_check_miss_path_only.sql +83 -0
- package/tests/mutations/s12-fix/M22_isolation_inverted.sql +83 -0
- package/tests/mutations/s12-fix/M23_isolation_wrong_sqlstate.sql +83 -0
- package/tests/mutations/s12-fix/M24_create_thread_key_unchecked.sql +37 -0
- package/tests/mutations/s12-fix/M25_create_thread_key_nonnull_only.sql +45 -0
- package/tests/mutations/s12-fix/M26_create_thread_key_casefold.sql +45 -0
- package/tests/mutations/s12-fix/M27_create_thread_no_object_guard.sql +45 -0
- package/tests/mutations/s12-fix/M28_create_thread_key_stripped.sql +40 -0
- package/tests/mutations/s12-fix/M29_create_thread_key_nested_refused.sql +45 -0
- package/tests/mutations/s12-fix/M2_lock_actor_only.sql +83 -0
- package/tests/mutations/s12-fix/M30_create_thread_security_invoker.sql +9 -0
- package/tests/mutations/s12-fix/M31_create_thread_search_path_changed.sql +9 -0
- package/tests/mutations/s12-fix/M32_class_new_thread_inserter.sql +14 -0
- package/tests/mutations/s12-fix/M33_class_metadata_update.sql +12 -0
- package/tests/mutations/s12-fix/M33b_class_metadata_update_upper.sql +17 -0
- package/tests/mutations/s12-fix/M33c_class_metadata_update_row_form.sql +16 -0
- package/tests/mutations/s12-fix/M33d_class_metadata_merge_update.sql +16 -0
- package/tests/mutations/s12-fix/M33e_class_metadata_upsert.sql +16 -0
- package/tests/mutations/s12-fix/M34_class_api_role_insert.sql +9 -0
- package/tests/mutations/s12-fix/M3_lock_after_lookup.sql +83 -0
- package/tests/mutations/s12-fix/M4_lock_raw_key.sql +83 -0
- package/tests/mutations/s12-fix/M5_no_trim.sql +83 -0
- package/tests/mutations/s12-fix/M6_casefold.sql +83 -0
- package/tests/mutations/s12-fix/M7_lookup_ignores_actor.sql +82 -0
- package/tests/mutations/s12-fix/M8_reuse_reports_false.sql +83 -0
- package/tests/mutations/s12-fix/M9_blank_key_admitted.sql +83 -0
- package/tests/mutations/s12-fix/run.sh +288 -0
- package/tests/seeds/20261124000100_agent_board_step_up_enforcement.sql.pre.sql +47 -0
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
# S-12 — create_or_find_thread, SAME actor + SAME normalized idempotency key, two sessions.
|
|
2
|
+
#
|
|
3
|
+
# THE QUESTION (Portal's new-thread hold). Two sessions call
|
|
4
|
+
# agent_board.create_or_find_thread at once with an identical (actor, normalized key). Does
|
|
5
|
+
# the board end with exactly ONE thread, do both calls return that one id (one reused=false,
|
|
6
|
+
# one reused=true), and does neither surface a unique violation?
|
|
7
|
+
#
|
|
8
|
+
# THE CONTRACT, read from the body (first defined in 20260517000000_agent_board_addressing.sql,
|
|
9
|
+
# redefined by 20261120000200_agent_board_thread_key_serialize.sql; one overload,
|
|
10
|
+
# (uuid, text, text, text, jsonb)):
|
|
11
|
+
# * the key is normalized by `nullif(trim(p_idempotency_key), '')` and NOTHING ELSE. trim()
|
|
12
|
+
# with no character list strips only the space character: case is preserved, and a tab or
|
|
13
|
+
# newline is part of the key. So ' s12-key ' IS the key 's12-key'; 'S12-KEY' is NOT.
|
|
14
|
+
# * the identity of a key is (threads.created_by_agent_id, metadata->>'addressingThreadKey').
|
|
15
|
+
# * reuse = `select … for update` on that pair; miss = a plain INSERT. There is no ON
|
|
16
|
+
# CONFLICT and no unique index on the pair (threads' only unique index is threads_pkey).
|
|
17
|
+
# Under READ COMMITTED the FOR UPDATE matches nothing while the first session's row is
|
|
18
|
+
# uncommitted, so on its own it cannot wait for it. Since 20261120000200 the lookup is
|
|
19
|
+
# preceded by `_lock_idempotency_key('create_or_find_thread:' || actor, key)`, a
|
|
20
|
+
# transaction-scoped advisory lock on (actor, key): THAT is what makes the second caller wait.
|
|
21
|
+
# * since 20261121000100 a caller whose transaction is not READ COMMITTED is refused with
|
|
22
|
+
# 0A000 before the lock and the lookup (#815). The lock only helps if the lookup after the
|
|
23
|
+
# wait sees the winner's committed row, and a REPEATABLE READ or SERIALIZABLE snapshot does
|
|
24
|
+
# not advance while waiting.
|
|
25
|
+
#
|
|
26
|
+
# Every session records what its call RETURNED into s12_results, so `check` can compare the
|
|
27
|
+
# ids the callers saw against the rows the table holds without printing a uuid.
|
|
28
|
+
# threads rows for (actor A, key 's12-key') — the property wants 1
|
|
29
|
+
# distinct_ids distinct thread ids the two calls returned — the property wants 1
|
|
30
|
+
# reused_flags the reused values, in session order
|
|
31
|
+
# orphans rows for that (actor, key) that NO caller was handed
|
|
32
|
+
#
|
|
33
|
+
# Catalog facts behind those claims, read from a database built from this bundle rather than
|
|
34
|
+
# from the text (measured on the pre-fix bundle, #808): create_or_find_thread has exactly 1
|
|
35
|
+
# overload; agent_board.threads has exactly 1 unique index (threads_pkey), 0 exclusion
|
|
36
|
+
# constraints and 0 user triggers.
|
|
37
|
+
#
|
|
38
|
+
# HISTORY OF THE GOLDEN. #808 added this spec with a golden that PINNED THE DEFECT:
|
|
39
|
+
# permutations 1 and 2 showed threads=2, distinct_ids=2, s1=false,s2=false, no `<waiting ...>`,
|
|
40
|
+
# no error -- two rows for one (actor, normalized key), silently. 20261120000200 serialises the
|
|
41
|
+
# miss path, and the golden was regenerated: in permutations 1 and 2 the second call now WAITS
|
|
42
|
+
# for s1's commit, then returns reused=true with s1's id (threads=1, distinct_ids=1).
|
|
43
|
+
# Permutations 3-6 are controls and are byte-identical before and after the fix.
|
|
44
|
+
#
|
|
45
|
+
# Permutation 7 (added with the metadata refusal) is new; it has no pre-fix counterpart.
|
|
46
|
+
#
|
|
47
|
+
# Permutations 8-12 (added with 20261121000100, #815) pin the isolation-level refusal. Session s4
|
|
48
|
+
# chooses its level in BEGIN and calls through public.s12_level_call(), which reports what the
|
|
49
|
+
# call did as one text value -- `returned reused=<bool>` or `refused <SQLSTATE>: <message>` -- so
|
|
50
|
+
# the golden carries the SQLSTATE (isolationtester prints only an error's message). A pgTAP file
|
|
51
|
+
# cannot do this: the level is fixed by a transaction's first statement, and pgTAP is inside one.
|
|
52
|
+
# Without the guard, permutation 8 is the #815 defect itself: s4 waits for s1, then inserts a
|
|
53
|
+
# second thread (returned reused=false, threads=2).
|
|
54
|
+
#
|
|
55
|
+
# Discrimination is pinned twice. tests/mutations/s12/run.sh (#808) applies scratch bodies to
|
|
56
|
+
# the PRE-fix bundle; tests/mutations/s12-fix/run.sh applies them to this one and asserts that
|
|
57
|
+
# dropping the lock reverts permutations 1 and 2 to the defect, and that locking on the key
|
|
58
|
+
# alone makes permutation 5's different actors wait on each other.
|
|
59
|
+
|
|
60
|
+
setup
|
|
61
|
+
{
|
|
62
|
+
insert into agent_board.agents(id, agent_type, kind, handle, display_name, status)
|
|
63
|
+
values ('b5120000-0000-4000-8000-00000000000a','agent','agent','s12-actor-a','S12 Actor A','active'),
|
|
64
|
+
('b5120000-0000-4000-8000-00000000000b','agent','agent','s12-actor-b','S12 Actor B','active');
|
|
65
|
+
|
|
66
|
+
create table public.s12_results(
|
|
67
|
+
session text primary key,
|
|
68
|
+
thread_id uuid not null,
|
|
69
|
+
reused boolean not null
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
create function public.s12_level_call() returns text
|
|
73
|
+
language plpgsql as $f$
|
|
74
|
+
declare
|
|
75
|
+
v_id uuid;
|
|
76
|
+
v_reused boolean;
|
|
77
|
+
begin
|
|
78
|
+
select t.thread_id, t.reused into v_id, v_reused
|
|
79
|
+
from agent_board.create_or_find_thread(
|
|
80
|
+
'b5120000-0000-4000-8000-00000000000a', 'S-12 subject', 's12-key') t;
|
|
81
|
+
insert into public.s12_results(session, thread_id, reused) values ('s4', v_id, v_reused);
|
|
82
|
+
return 'returned reused=' || v_reused::text;
|
|
83
|
+
exception when others then
|
|
84
|
+
return 'refused ' || sqlstate || ': ' || sqlerrm;
|
|
85
|
+
end
|
|
86
|
+
$f$;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
teardown
|
|
90
|
+
{
|
|
91
|
+
drop function public.s12_level_call();
|
|
92
|
+
drop table public.s12_results;
|
|
93
|
+
delete from agent_board.threads
|
|
94
|
+
where created_by_agent_id in ('b5120000-0000-4000-8000-00000000000a',
|
|
95
|
+
'b5120000-0000-4000-8000-00000000000b');
|
|
96
|
+
delete from agent_board.agents
|
|
97
|
+
where id in ('b5120000-0000-4000-8000-00000000000a',
|
|
98
|
+
'b5120000-0000-4000-8000-00000000000b');
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
# Actor A, the canonical key.
|
|
102
|
+
session "s1"
|
|
103
|
+
step "s1_begin" { BEGIN; SET LOCAL "request.jwt.claim.role" = 'service_role'; }
|
|
104
|
+
step "s1_call" {
|
|
105
|
+
insert into public.s12_results(session, thread_id, reused)
|
|
106
|
+
select 's1', t.thread_id, t.reused
|
|
107
|
+
from agent_board.create_or_find_thread(
|
|
108
|
+
'b5120000-0000-4000-8000-00000000000a', 'S-12 subject', 's12-key') t
|
|
109
|
+
returning session, reused;
|
|
110
|
+
}
|
|
111
|
+
step "s1_commit" { COMMIT; }
|
|
112
|
+
|
|
113
|
+
# Actor A, the canonical key — a second caller of the same pair.
|
|
114
|
+
session "s2"
|
|
115
|
+
step "s2_begin" { BEGIN; SET LOCAL "request.jwt.claim.role" = 'service_role'; }
|
|
116
|
+
step "s2_call" {
|
|
117
|
+
insert into public.s12_results(session, thread_id, reused)
|
|
118
|
+
select 's2', t.thread_id, t.reused
|
|
119
|
+
from agent_board.create_or_find_thread(
|
|
120
|
+
'b5120000-0000-4000-8000-00000000000a', 'S-12 subject', 's12-key') t
|
|
121
|
+
returning session, reused;
|
|
122
|
+
}
|
|
123
|
+
# Actor A, a key that differs from 's12-key' only by what trim() removes.
|
|
124
|
+
step "s2_call_padded" {
|
|
125
|
+
insert into public.s12_results(session, thread_id, reused)
|
|
126
|
+
select 's2', t.thread_id, t.reused
|
|
127
|
+
from agent_board.create_or_find_thread(
|
|
128
|
+
'b5120000-0000-4000-8000-00000000000a', 'S-12 subject', ' s12-key ') t
|
|
129
|
+
returning session, reused;
|
|
130
|
+
}
|
|
131
|
+
# Actor A, a key that differs only in CASE — not part of the normalization.
|
|
132
|
+
step "s2_call_upper" {
|
|
133
|
+
insert into public.s12_results(session, thread_id, reused)
|
|
134
|
+
select 's2', t.thread_id, t.reused
|
|
135
|
+
from agent_board.create_or_find_thread(
|
|
136
|
+
'b5120000-0000-4000-8000-00000000000a', 'S-12 subject', 'S12-KEY') t
|
|
137
|
+
returning session, reused;
|
|
138
|
+
}
|
|
139
|
+
# Actor A, the canonical key, but a JSON ARRAY as metadata: refused (22023) since 20261120000200.
|
|
140
|
+
step "s2_call_array" {
|
|
141
|
+
insert into public.s12_results(session, thread_id, reused)
|
|
142
|
+
select 's2', t.thread_id, t.reused
|
|
143
|
+
from agent_board.create_or_find_thread(
|
|
144
|
+
'b5120000-0000-4000-8000-00000000000a', 'S-12 subject', 's12-key', 'coordination', '[]'::jsonb) t
|
|
145
|
+
returning session, reused;
|
|
146
|
+
}
|
|
147
|
+
step "s2_commit" { COMMIT; }
|
|
148
|
+
|
|
149
|
+
# Actor B, the same literal key — a different (actor, key) pair.
|
|
150
|
+
session "s3"
|
|
151
|
+
step "s3_begin" { BEGIN; SET LOCAL "request.jwt.claim.role" = 'service_role'; }
|
|
152
|
+
step "s3_call_other_actor" {
|
|
153
|
+
insert into public.s12_results(session, thread_id, reused)
|
|
154
|
+
select 's3', t.thread_id, t.reused
|
|
155
|
+
from agent_board.create_or_find_thread(
|
|
156
|
+
'b5120000-0000-4000-8000-00000000000b', 'S-12 subject', 's12-key') t
|
|
157
|
+
returning session, reused;
|
|
158
|
+
}
|
|
159
|
+
step "s3_commit" { COMMIT; }
|
|
160
|
+
|
|
161
|
+
# Actor A, the canonical key, at a level chosen in BEGIN (#815). One call step for every level,
|
|
162
|
+
# so the only thing that differs between these permutations is the level itself.
|
|
163
|
+
session "s4"
|
|
164
|
+
step "s4_begin_rr" { BEGIN ISOLATION LEVEL REPEATABLE READ; SET LOCAL "request.jwt.claim.role" = 'service_role'; }
|
|
165
|
+
step "s4_begin_sz" { BEGIN ISOLATION LEVEL SERIALIZABLE; SET LOCAL "request.jwt.claim.role" = 'service_role'; }
|
|
166
|
+
step "s4_begin_ru" { BEGIN ISOLATION LEVEL READ UNCOMMITTED; SET LOCAL "request.jwt.claim.role" = 'service_role'; }
|
|
167
|
+
step "s4_begin_rc" { BEGIN ISOLATION LEVEL READ COMMITTED; SET LOCAL "request.jwt.claim.role" = 'service_role'; }
|
|
168
|
+
step "s4_call" { select public.s12_level_call() as outcome; }
|
|
169
|
+
step "s4_commit" { COMMIT; }
|
|
170
|
+
step "s4_rollback" { ROLLBACK; }
|
|
171
|
+
|
|
172
|
+
session "check"
|
|
173
|
+
step "check" {
|
|
174
|
+
select (select count(*)::int from agent_board.threads t
|
|
175
|
+
where t.created_by_agent_id = 'b5120000-0000-4000-8000-00000000000a'
|
|
176
|
+
and t.metadata ->> 'addressingThreadKey' = 's12-key') as threads,
|
|
177
|
+
(select count(distinct r.thread_id)::int from public.s12_results r
|
|
178
|
+
where r.session in ('s1','s2')) as distinct_ids,
|
|
179
|
+
(select string_agg(r.session || '=' || r.reused::text, ',' order by r.session)
|
|
180
|
+
from public.s12_results r) as reused_flags,
|
|
181
|
+
(select count(*)::int from agent_board.threads t
|
|
182
|
+
where t.created_by_agent_id = 'b5120000-0000-4000-8000-00000000000a'
|
|
183
|
+
and t.metadata ->> 'addressingThreadKey' = 's12-key'
|
|
184
|
+
and t.id not in (select r.thread_id from public.s12_results r)) as orphans,
|
|
185
|
+
(select string_agg(t.metadata ->> 'addressingThreadKey', ',' order by t.metadata ->> 'addressingThreadKey')
|
|
186
|
+
from agent_board.threads t
|
|
187
|
+
where t.created_by_agent_id = 'b5120000-0000-4000-8000-00000000000a') as actor_a_keys,
|
|
188
|
+
(select count(*)::int from agent_board.threads t
|
|
189
|
+
where t.created_by_agent_id = 'b5120000-0000-4000-8000-00000000000b') as actor_b_threads,
|
|
190
|
+
(select bool_and(r3.thread_id <> r1.thread_id)
|
|
191
|
+
from public.s12_results r1, public.s12_results r3
|
|
192
|
+
where r1.session = 's1' and r3.session = 's3') as other_actor_distinct;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
# 1. S-12 PROPER. Same actor, same key, both inside open transactions. The property wants
|
|
196
|
+
# s2_call to wait for s1 and come back reused=true with s1's id; threads=1, distinct_ids=1.
|
|
197
|
+
# MEASURED since 20261120000200: exactly that. (Before it, s2_call did not wait and inserted
|
|
198
|
+
# a second thread: threads=2, distinct_ids=2.)
|
|
199
|
+
permutation "s1_begin" "s1_call" "s2_begin" "s2_call" "s1_commit" "s2_commit" "check"
|
|
200
|
+
|
|
201
|
+
# 2. The same race through the normalization: s2's key is ' s12-key '. The lock is keyed on
|
|
202
|
+
# the TRIMMED key, so s2 waits and reuses s1's row exactly as in permutation 1.
|
|
203
|
+
permutation "s1_begin" "s1_call" "s2_begin" "s2_call_padded" "s1_commit" "s2_commit" "check"
|
|
204
|
+
|
|
205
|
+
# 3. CONTROL — the reuse path itself. s1 COMMITS before s2 calls, so the FOR UPDATE can see
|
|
206
|
+
# the row. One thread, one id, s1=false, s2=true. This is what permutation 1 is measured
|
|
207
|
+
# against: the defect is concurrency, not the reuse lookup.
|
|
208
|
+
permutation "s1_begin" "s1_call" "s1_commit" "s2_begin" "s2_call_padded" "s2_commit" "check"
|
|
209
|
+
|
|
210
|
+
# 4. CONTROL — case is NOT normalized. Committed first, then 'S12-KEY': a second thread
|
|
211
|
+
# under a distinct key, reused=false both times. The function's contract, asserted as is.
|
|
212
|
+
permutation "s1_begin" "s1_call" "s1_commit" "s2_begin" "s2_call_upper" "s2_commit" "check"
|
|
213
|
+
|
|
214
|
+
# 5. CONTROL — different actors with the same key are independent: two threads, two
|
|
215
|
+
# reused=false, no wait between them, distinct ids. (threads counts actor A only, so 1.)
|
|
216
|
+
# A lock keyed on the key alone, without the actor, makes s3 wait here.
|
|
217
|
+
permutation "s1_begin" "s1_call" "s3_begin" "s3_call_other_actor" "s1_commit" "s3_commit" "check"
|
|
218
|
+
|
|
219
|
+
# 6. CONTROL — actor scoping of the REUSE lookup. Permutation 5 cannot pin it on the shipped
|
|
220
|
+
# body: s3 could not see s1's uncommitted row whatever the predicate said. Here s1 commits
|
|
221
|
+
# first, so a lookup that ignored the actor would hand s3 actor A's thread (s3=true).
|
|
222
|
+
permutation "s1_begin" "s1_call" "s1_commit" "s3_begin" "s3_call_other_actor" "s3_commit" "check"
|
|
223
|
+
|
|
224
|
+
# 7. The metadata refusal comes BEFORE the lock. s1 holds the (actor, key) lock; s2 calls with the
|
|
225
|
+
# same pair and a JSON array as metadata. It must fail at once with 22023 -- no `<waiting ...>`
|
|
226
|
+
# -- and leave s1's single thread. A refusal placed after the lock would make s2 wait for s1
|
|
227
|
+
# first (tests/mutations/s12-fix M15); no refusal at all lets s2 wait and then reuse (M14).
|
|
228
|
+
permutation "s1_begin" "s1_call" "s2_begin" "s2_call_array" "s1_commit" "s2_commit" "check"
|
|
229
|
+
|
|
230
|
+
# 8. #815: REPEATABLE READ is refused, by name and with 0A000, BEFORE the lock. s1 holds the
|
|
231
|
+
# (actor, key) lock; s4 calls with the same pair at REPEATABLE READ. It must be refused at once
|
|
232
|
+
# -- no `<waiting ...>` -- and s1's thread stays the only one. A guard placed after the lock
|
|
233
|
+
# makes s4 wait first; no guard lets s4 wait and then insert a duplicate (threads=2).
|
|
234
|
+
permutation "s1_begin" "s1_call" "s4_begin_rr" "s4_call" "s1_commit" "s4_rollback" "check"
|
|
235
|
+
|
|
236
|
+
# 9. #815: SERIALIZABLE is refused the same way. Its own permutation because only the levels a
|
|
237
|
+
# permutation NAMES are pinned: a guard narrowed to `= 'repeatable read'` passes permutation 8.
|
|
238
|
+
permutation "s1_begin" "s1_call" "s4_begin_sz" "s4_call" "s1_commit" "s4_rollback" "check"
|
|
239
|
+
|
|
240
|
+
# 10. #815: READ UNCOMMITTED is refused too. PostgreSQL runs it AS read committed, so this pins the
|
|
241
|
+
# guard's one-accepted-spelling contract (`<> 'read committed'`), not a correctness property:
|
|
242
|
+
# a guard that lists the two unsafe levels instead lets this one through.
|
|
243
|
+
permutation "s1_begin" "s1_call" "s4_begin_ru" "s4_call" "s1_commit" "s4_rollback" "check"
|
|
244
|
+
|
|
245
|
+
# 11. #815: the refusal is of the LEVEL, not of the miss path. s1 has committed, so the lookup
|
|
246
|
+
# would find the thread and no duplicate could be written -- and the REPEATABLE READ caller is
|
|
247
|
+
# still refused. A guard placed after the reuse return hands s4 the thread here.
|
|
248
|
+
permutation "s1_begin" "s1_call" "s1_commit" "s4_begin_rr" "s4_call" "s4_rollback" "check"
|
|
249
|
+
|
|
250
|
+
# 12. #815 ALLOW SIDE: the identical call with READ COMMITTED named in BEGIN succeeds and reuses
|
|
251
|
+
# s1's thread. A refusal that fired at every level would fail here (and in permutations 1-6).
|
|
252
|
+
permutation "s1_begin" "s1_call" "s1_commit" "s4_begin_rc" "s4_call" "s4_commit" "check"
|
|
@@ -59,9 +59,14 @@ session "b"
|
|
|
59
59
|
step "b_begin" { BEGIN; SET LOCAL ROLE service_role; SET LOCAL "request.jwt.claim.role" = 'service_role'; SET LOCAL "request.jwt.claim.sub" = '71000000-0000-4000-8000-000000000001'; }
|
|
60
60
|
step "b_same" { select agent_board.link_session_alias('72000000-0000-4000-8000-000000000002', '0', 'continued-a'); }
|
|
61
61
|
step "b_other" { select agent_board.link_session_alias('72000000-0000-4000-8000-000000000002', '0', 'continued-b'); }
|
|
62
|
+
# #669 PR-B (D3, plan §5.4): the narrowing grant runs as the OPERATOR KEY (service_role, no sub).
|
|
63
|
+
# Under the session's sub (a session identity with no lease claim, so no resolved principal) the
|
|
64
|
+
# step-up helper refuses it with MBS01, which is the R-14b case by design.
|
|
62
65
|
step "b_narrow" {
|
|
66
|
+
SET LOCAL "request.jwt.claim.sub" = '';
|
|
63
67
|
select role from agent_board.grant_board_role('74000000-0000-4000-8000-000000000002', '72000000-0000-4000-8000-000000000001', 'observer', '72000000-0000-4000-8000-000000000001');
|
|
64
68
|
select allowed_scopes from agent_board.upsert_delegation_policy('72000000-0000-4000-8000-000000000001', 'root_minted', '["read"]', 200, interval '8 hours', true);
|
|
69
|
+
SET LOCAL "request.jwt.claim.sub" = '71000000-0000-4000-8000-000000000001';
|
|
65
70
|
}
|
|
66
71
|
step "b_commit" { COMMIT; }
|
|
67
72
|
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
-- every service_role call exempt (early return); must fail R-14 (#62)
|
|
2
|
+
do $m$
|
|
3
|
+
declare d text := pg_get_functiondef('agent_board._require_human_step_up(text)'::regprocedure); n text;
|
|
4
|
+
begin
|
|
5
|
+
n := d;
|
|
6
|
+
if strpos(n, ' -- (a) The operator key') = 0 then raise exception 'MUTATION ANCHOR MISS (1)'; end if;
|
|
7
|
+
n := replace(n, ' -- (a) The operator key', ' if v_service is true then return; end if;
|
|
8
|
+
-- (a) The operator key');
|
|
9
|
+
execute n;
|
|
10
|
+
end $m$;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
-- remove the claims-parse exception wrapper; must fail R-7 not-json (#48) with 22P02
|
|
2
|
+
do $m$
|
|
3
|
+
declare d text := pg_get_functiondef('agent_board._require_human_step_up(text)'::regprocedure); n text;
|
|
4
|
+
begin
|
|
5
|
+
n := d;
|
|
6
|
+
if strpos(n, ' begin
|
|
7
|
+
v_claims := v_raw::jsonb;
|
|
8
|
+
exception when others then
|
|
9
|
+
v_claims := null;
|
|
10
|
+
end;') = 0 then raise exception 'MUTATION ANCHOR MISS (1)'; end if;
|
|
11
|
+
n := replace(n, ' begin
|
|
12
|
+
v_claims := v_raw::jsonb;
|
|
13
|
+
exception when others then
|
|
14
|
+
v_claims := null;
|
|
15
|
+
end;', ' v_claims := v_raw::jsonb;');
|
|
16
|
+
execute n;
|
|
17
|
+
end $m$;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
-- remove the session-reader exception wrapper; must fail R-7 not-json (#48) with 22P02
|
|
2
|
+
do $m$
|
|
3
|
+
declare d text := pg_get_functiondef('agent_board._require_human_step_up(text)'::regprocedure); n text;
|
|
4
|
+
begin
|
|
5
|
+
n := d;
|
|
6
|
+
if strpos(n, ' begin
|
|
7
|
+
v_service := agent_board._is_service_role();
|
|
8
|
+
v_uid := auth.uid();
|
|
9
|
+
v_actor := agent_board.current_agent_id();
|
|
10
|
+
exception when others then
|
|
11
|
+
raise exception ''step_up_required'' using errcode = ''MBS01'', detail = p_operation;
|
|
12
|
+
end;') = 0 then raise exception 'MUTATION ANCHOR MISS (1)'; end if;
|
|
13
|
+
n := replace(n, ' begin
|
|
14
|
+
v_service := agent_board._is_service_role();
|
|
15
|
+
v_uid := auth.uid();
|
|
16
|
+
v_actor := agent_board.current_agent_id();
|
|
17
|
+
exception when others then
|
|
18
|
+
raise exception ''step_up_required'' using errcode = ''MBS01'', detail = p_operation;
|
|
19
|
+
end;', ' v_service := agent_board._is_service_role();
|
|
20
|
+
v_uid := auth.uid();
|
|
21
|
+
v_actor := agent_board.current_agent_id();');
|
|
22
|
+
execute n;
|
|
23
|
+
end $m$;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
-- remove the T JSON-number guard; must fail R-7 malformed-T rows (#49-50) with 22P02
|
|
2
|
+
do $m$
|
|
3
|
+
declare d text := pg_get_functiondef('agent_board._require_human_step_up(text)'::regprocedure); n text;
|
|
4
|
+
begin
|
|
5
|
+
n := d;
|
|
6
|
+
if strpos(n, ' if jsonb_typeof(v_t) is distinct from ''number'' then
|
|
7
|
+
raise exception ''step_up_required'' using errcode = ''MBS01'', detail = p_operation;
|
|
8
|
+
end if;') = 0 then raise exception 'MUTATION ANCHOR MISS (1)'; end if;
|
|
9
|
+
n := replace(n, ' if jsonb_typeof(v_t) is distinct from ''number'' then
|
|
10
|
+
raise exception ''step_up_required'' using errcode = ''MBS01'', detail = p_operation;
|
|
11
|
+
end if;', '');
|
|
12
|
+
execute n;
|
|
13
|
+
end $m$;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
-- remove the amr element object/timestamp guards; must fail R-7b's string-timestamp row (#59)
|
|
2
|
+
do $m$
|
|
3
|
+
declare d text := pg_get_functiondef('agent_board._require_human_step_up(text)'::regprocedure); n text;
|
|
4
|
+
begin
|
|
5
|
+
n := d;
|
|
6
|
+
if strpos(n, ' continue when jsonb_typeof(v_e) is distinct from ''object'';
|
|
7
|
+
') = 0 then raise exception 'MUTATION ANCHOR MISS (1)'; end if;
|
|
8
|
+
n := replace(n, ' continue when jsonb_typeof(v_e) is distinct from ''object'';
|
|
9
|
+
', '');
|
|
10
|
+
if strpos(n, ' continue when jsonb_typeof(v_e -> ''timestamp'') is distinct from ''number'';
|
|
11
|
+
') = 0 then raise exception 'MUTATION ANCHOR MISS (2)'; end if;
|
|
12
|
+
n := replace(n, ' continue when jsonb_typeof(v_e -> ''timestamp'') is distinct from ''number'';
|
|
13
|
+
', '');
|
|
14
|
+
execute n;
|
|
15
|
+
end $m$;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
-- measure freshness on now() instead of clock_timestamp(); must fail the M14 row (#67)
|
|
2
|
+
do $m$
|
|
3
|
+
declare d text := pg_get_functiondef('agent_board._require_human_step_up(text)'::regprocedure); n text;
|
|
4
|
+
begin
|
|
5
|
+
n := d;
|
|
6
|
+
if strpos(n, 'v_now := extract(epoch from clock_timestamp());') = 0 then raise exception 'MUTATION ANCHOR MISS (1)'; end if;
|
|
7
|
+
n := replace(n, 'v_now := extract(epoch from clock_timestamp());', 'v_now := extract(epoch from now());');
|
|
8
|
+
execute n;
|
|
9
|
+
end $m$;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
-- the classifier accepts agents.metadata federation; must fail the M15 row (#66), RP-M15 (#74)
|
|
2
|
+
do $m$
|
|
3
|
+
declare d text := pg_get_functiondef('agent_board._step_up_is_portal_human(uuid)'::regprocedure); n text;
|
|
4
|
+
begin
|
|
5
|
+
n := d;
|
|
6
|
+
if strpos(n, 'and exists (
|
|
7
|
+
select 1
|
|
8
|
+
from agent_board.enrollment_federation_audit f') = 0 then raise exception 'MUTATION ANCHOR MISS (1)'; end if;
|
|
9
|
+
n := replace(n, 'and exists (
|
|
10
|
+
select 1
|
|
11
|
+
from agent_board.enrollment_federation_audit f', 'and (a.metadata ? ''federation'' or exists (
|
|
12
|
+
select 1
|
|
13
|
+
from agent_board.enrollment_federation_audit f');
|
|
14
|
+
if strpos(n, 'and f.mode = ''fedsession''))') = 0 then raise exception 'MUTATION ANCHOR MISS (2)'; end if;
|
|
15
|
+
n := replace(n, 'and f.mode = ''fedsession''))', 'and f.mode = ''fedsession'')))');
|
|
16
|
+
execute n;
|
|
17
|
+
end $m$;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
-- the helper skips the ledger lookup; must fail R-5f (#46)
|
|
2
|
+
do $m$
|
|
3
|
+
declare d text := pg_get_functiondef('agent_board._require_human_step_up(text)'::regprocedure); n text;
|
|
4
|
+
begin
|
|
5
|
+
n := d;
|
|
6
|
+
if strpos(n, ' if not exists (
|
|
7
|
+
select 1
|
|
8
|
+
from agent_board.portal_step_up_proofs p') = 0 then raise exception 'MUTATION ANCHOR MISS (1)'; end if;
|
|
9
|
+
n := replace(n, ' if not exists (
|
|
10
|
+
select 1
|
|
11
|
+
from agent_board.portal_step_up_proofs p', ' if false and not exists (
|
|
12
|
+
select 1
|
|
13
|
+
from agent_board.portal_step_up_proofs p');
|
|
14
|
+
execute n;
|
|
15
|
+
end $m$;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
-- operator rule ignores principal and sub (D3); must fail R-14 (#62)
|
|
2
|
+
do $m$
|
|
3
|
+
declare d text := pg_get_functiondef('agent_board._require_human_step_up(text)'::regprocedure); n text;
|
|
4
|
+
begin
|
|
5
|
+
n := d;
|
|
6
|
+
if strpos(n, 'if v_service is true and v_actor is null and v_uid is null then') = 0 then raise exception 'MUTATION ANCHOR MISS (1)'; end if;
|
|
7
|
+
n := replace(n, 'if v_service is true and v_actor is null and v_uid is null then', 'if v_service is true then');
|
|
8
|
+
execute n;
|
|
9
|
+
end $m$;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
-- drop the auth.uid() IS NULL conjunct; must fail R-14b (#63)
|
|
2
|
+
do $m$
|
|
3
|
+
declare d text := pg_get_functiondef('agent_board._require_human_step_up(text)'::regprocedure); n text;
|
|
4
|
+
begin
|
|
5
|
+
n := d;
|
|
6
|
+
if strpos(n, 'if v_service is true and v_actor is null and v_uid is null then') = 0 then raise exception 'MUTATION ANCHOR MISS (1)'; end if;
|
|
7
|
+
n := replace(n, 'if v_service is true and v_actor is null and v_uid is null then', 'if v_service is true and v_actor is null then');
|
|
8
|
+
execute n;
|
|
9
|
+
end $m$;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
-- E-2 M23: an authenticated-executable SECURITY DEFINER wrapper over record_portal_step_up; must fail EC-SU-4 (#4), naming it
|
|
2
|
+
create function agent_board.zz_m23_forge_step_up(p_agent_id uuid, p_t bigint) returns boolean
|
|
3
|
+
language sql security definer set search_path = '' as $$ select agent_board.record_portal_step_up(p_agent_id, p_t) $$;
|
|
4
|
+
revoke all on function agent_board.zz_m23_forge_step_up(uuid, bigint) from public;
|
|
5
|
+
grant execute on function agent_board.zz_m23_forge_step_up(uuid, bigint) to authenticated;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
-- the Portal branch measures age from the token iat; must fail R-4 (#34)
|
|
2
|
+
do $m$
|
|
3
|
+
declare d text := pg_get_functiondef('agent_board._require_human_step_up(text)'::regprocedure); n text;
|
|
4
|
+
begin
|
|
5
|
+
n := d;
|
|
6
|
+
if strpos(n, 'if agent_board._step_up_is_fresh(v_proof, v_now) is not true then') = 0 then raise exception 'MUTATION ANCHOR MISS (1)'; end if;
|
|
7
|
+
n := replace(n, 'if agent_board._step_up_is_fresh(v_proof, v_now) is not true then', 'if agent_board._step_up_is_fresh((v_claims ->> ''iat'')::numeric, v_now) is not true then');
|
|
8
|
+
execute n;
|
|
9
|
+
end $m$;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
-- window 300 -> 900; must fail R-1 (#29), P-2 (#18)
|
|
2
|
+
do $m$
|
|
3
|
+
declare d text := pg_get_functiondef('agent_board._step_up_max_age_seconds()'::regprocedure); n text;
|
|
4
|
+
begin
|
|
5
|
+
n := d;
|
|
6
|
+
if strpos(n, 'select 300::numeric') = 0 then raise exception 'MUTATION ANCHOR MISS (1)'; end if;
|
|
7
|
+
n := replace(n, 'select 300::numeric', 'select 900::numeric');
|
|
8
|
+
execute n;
|
|
9
|
+
end $m$;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
-- `<` -> `<=` in the predicate; must fail P-2 (#18)
|
|
2
|
+
do $m$
|
|
3
|
+
declare d text := pg_get_functiondef('agent_board._step_up_is_fresh(numeric,numeric)'::regprocedure); n text;
|
|
4
|
+
begin
|
|
5
|
+
n := d;
|
|
6
|
+
if strpos(n, 'p_now - p_proof < agent_board._step_up_max_age_seconds()') = 0 then raise exception 'MUTATION ANCHOR MISS (1)'; end if;
|
|
7
|
+
n := replace(n, 'p_now - p_proof < agent_board._step_up_max_age_seconds()', 'p_now - p_proof <= agent_board._step_up_max_age_seconds()');
|
|
8
|
+
execute n;
|
|
9
|
+
end $m$;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
-- drop the future-skew bound; must fail P-4 (#20), R-6 (#47)
|
|
2
|
+
do $m$
|
|
3
|
+
declare d text := pg_get_functiondef('agent_board._step_up_is_fresh(numeric,numeric)'::regprocedure); n text;
|
|
4
|
+
begin
|
|
5
|
+
n := d;
|
|
6
|
+
if strpos(n, 'and p_proof - p_now <= agent_board._step_up_future_skew_seconds()') = 0 then raise exception 'MUTATION ANCHOR MISS (1)'; end if;
|
|
7
|
+
n := replace(n, 'and p_proof - p_now <= agent_board._step_up_future_skew_seconds()', '');
|
|
8
|
+
execute n;
|
|
9
|
+
end $m$;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
-- local proof also read from user_metadata.amr; must fail R-5 (#41)
|
|
2
|
+
do $m$
|
|
3
|
+
declare d text := pg_get_functiondef('agent_board._require_human_step_up(text)'::regprocedure); n text;
|
|
4
|
+
begin
|
|
5
|
+
n := d;
|
|
6
|
+
if strpos(n, 'v_amr := v_claims -> ''amr'';') = 0 then raise exception 'MUTATION ANCHOR MISS (1)'; end if;
|
|
7
|
+
n := replace(n, 'v_amr := v_claims -> ''amr'';', 'v_amr := coalesce(v_claims -> ''user_metadata'' -> ''amr'', v_claims -> ''amr'');');
|
|
8
|
+
execute n;
|
|
9
|
+
end $m$;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
-- Portal claim also read from app_metadata; must fail R-5b (#42)
|
|
2
|
+
do $m$
|
|
3
|
+
declare d text := pg_get_functiondef('agent_board._require_human_step_up(text)'::regprocedure); n text;
|
|
4
|
+
begin
|
|
5
|
+
n := d;
|
|
6
|
+
if strpos(n, 'v_t := v_claims -> ''agent_board_step_up_at'';') = 0 then raise exception 'MUTATION ANCHOR MISS (1)'; end if;
|
|
7
|
+
n := replace(n, 'v_t := v_claims -> ''agent_board_step_up_at'';', 'v_claims := v_claims || coalesce(v_claims -> ''app_metadata'', ''{}''::jsonb); v_t := v_claims -> ''agent_board_step_up_at'';');
|
|
8
|
+
execute n;
|
|
9
|
+
end $m$;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
-- Portal claim also read from the legacy request.jwt.claim.* GUC; must fail R-5c (#43)
|
|
2
|
+
do $m$
|
|
3
|
+
declare d text := pg_get_functiondef('agent_board._require_human_step_up(text)'::regprocedure); n text;
|
|
4
|
+
begin
|
|
5
|
+
n := d;
|
|
6
|
+
if strpos(n, 'v_t := v_claims -> ''agent_board_step_up_at'';') = 0 then raise exception 'MUTATION ANCHOR MISS (1)'; end if;
|
|
7
|
+
n := replace(n, 'v_t := v_claims -> ''agent_board_step_up_at'';', 'if nullif(current_setting(''request.jwt.claim.agent_board_step_up_at'', true), '''') is not null then v_claims := v_claims || jsonb_build_object(''agent_board_step_up_at'', current_setting(''request.jwt.claim.agent_board_step_up_at'', true)::numeric); end if; v_t := v_claims -> ''agent_board_step_up_at'';');
|
|
8
|
+
execute n;
|
|
9
|
+
end $m$;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
-- either claim honoured for any human (class decided by claim presence); must fail R-5d (#44), R-5e (#45)
|
|
2
|
+
do $m$
|
|
3
|
+
declare d text := pg_get_functiondef('agent_board._require_human_step_up(text)'::regprocedure); n text;
|
|
4
|
+
begin
|
|
5
|
+
n := d;
|
|
6
|
+
if strpos(n, 'if agent_board._step_up_is_portal_human(v_actor) is true then') = 0 then raise exception 'MUTATION ANCHOR MISS (1)'; end if;
|
|
7
|
+
n := replace(n, 'if agent_board._step_up_is_portal_human(v_actor) is true then', 'if v_claims ? ''agent_board_step_up_at'' then');
|
|
8
|
+
execute n;
|
|
9
|
+
end $m$;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
-- accept any amr method; must fail R-4b (#35), R-4c (#36-39), E-0-AL (#16)
|
|
2
|
+
do $m$
|
|
3
|
+
declare d text := pg_get_functiondef('agent_board._require_human_step_up(text)'::regprocedure); n text;
|
|
4
|
+
begin
|
|
5
|
+
n := d;
|
|
6
|
+
if strpos(n, 'continue when ((v_e ->> ''method'') = any (v_methods)) is not true;') = 0 then raise exception 'MUTATION ANCHOR MISS (1)'; end if;
|
|
7
|
+
n := replace(n, 'continue when ((v_e ->> ''method'') = any (v_methods)) is not true;', '');
|
|
8
|
+
execute n;
|
|
9
|
+
end $m$;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
-- accept aal2 as freshness; must fail R-4c aal row (#40)
|
|
2
|
+
do $m$
|
|
3
|
+
declare d text := pg_get_functiondef('agent_board._require_human_step_up(text)'::regprocedure); n text;
|
|
4
|
+
begin
|
|
5
|
+
n := d;
|
|
6
|
+
if strpos(n, 'v_amr := v_claims -> ''amr'';') = 0 then raise exception 'MUTATION ANCHOR MISS (1)'; end if;
|
|
7
|
+
n := replace(n, 'v_amr := v_claims -> ''amr'';', 'if v_claims ->> ''aal'' = ''aal2'' then return; end if; v_amr := v_claims -> ''amr'';');
|
|
8
|
+
execute n;
|
|
9
|
+
end $m$;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
-- apply to every kind (no agent exemption); must fail C-3 (#26)
|
|
2
|
+
do $m$
|
|
3
|
+
declare d text := pg_get_functiondef('agent_board._require_human_step_up(text)'::regprocedure); n text;
|
|
4
|
+
begin
|
|
5
|
+
n := d;
|
|
6
|
+
if strpos(n, 'if v_kind in (''agent'', ''system'') then') = 0 then raise exception 'MUTATION ANCHOR MISS (1)'; end if;
|
|
7
|
+
n := replace(n, 'if v_kind in (''agent'', ''system'') then', 'if false then');
|
|
8
|
+
execute n;
|
|
9
|
+
end $m$;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
-- the allowlist ships non-empty; must fail E-0-AL (#15, #16)
|
|
2
|
+
do $m$
|
|
3
|
+
declare d text := pg_get_functiondef('agent_board._step_up_amr_methods()'::regprocedure); n text;
|
|
4
|
+
begin
|
|
5
|
+
n := d;
|
|
6
|
+
if strpos(n, 'select ''{}''::text[]') = 0 then raise exception 'MUTATION ANCHOR MISS (1)'; end if;
|
|
7
|
+
n := replace(n, 'select ''{}''::text[]', 'select ''{otp}''::text[]');
|
|
8
|
+
execute n;
|
|
9
|
+
end $m$;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
-- S2-4: the writer's argument p_proof_at renamed; must fail RP-13 (#99)
|
|
2
|
+
drop function agent_board.record_portal_step_up(uuid, bigint);
|
|
3
|
+
create function agent_board.record_portal_step_up(p_agent_id uuid, p_proof bigint) returns boolean
|
|
4
|
+
language plpgsql security definer set search_path = '' as $$
|
|
5
|
+
begin
|
|
6
|
+
if p_agent_id is null or p_proof is null then return false; end if;
|
|
7
|
+
if agent_board._step_up_is_portal_human(p_agent_id) is not true then return false; end if;
|
|
8
|
+
if agent_board._step_up_proof_recordable(p_proof::numeric, extract(epoch from clock_timestamp())) is not true then return false; end if;
|
|
9
|
+
insert into agent_board.portal_step_up_proofs(agent_id, proof_at) values (p_agent_id, p_proof) on conflict (agent_id, proof_at) do nothing;
|
|
10
|
+
return true;
|
|
11
|
+
end $$;
|
|
12
|
+
revoke all on function agent_board.record_portal_step_up(uuid, bigint) from public, anon, authenticated, agent_board_delegate;
|
|
13
|
+
grant execute on function agent_board.record_portal_step_up(uuid, bigint) to service_role;
|
|
14
|
+
comment on function agent_board.record_portal_step_up(uuid, bigint) is 'mutant';
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
-- S2-3: enrollment_federation_audit.mode changes type (text -> varchar(32)); must fail EC-SU-4i (#101). (A RENAME also breaks this file's own fixture insert and aborts it, which is never counted as a kill; the type change keeps the fixture working and isolates the pin.)
|
|
2
|
+
alter table agent_board.enrollment_federation_audit alter column mode type varchar(32);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
-- E-6(b): the helper always raises; must fail C-1..C-4b (#22-28)
|
|
2
|
+
do $m$
|
|
3
|
+
declare d text := pg_get_functiondef('agent_board._require_human_step_up(text)'::regprocedure); n text;
|
|
4
|
+
begin
|
|
5
|
+
n := d;
|
|
6
|
+
if strpos(n, ' -- Claims: parsed in their own guarded block.') = 0 then raise exception 'MUTATION ANCHOR MISS (1)'; end if;
|
|
7
|
+
n := replace(n, ' -- Claims: parsed in their own guarded block.', ' raise exception ''step_up_required'' using errcode = ''MBS01'', detail = p_operation;
|
|
8
|
+
-- Claims: parsed in their own guarded block.');
|
|
9
|
+
execute n;
|
|
10
|
+
end $m$;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
-- S1-2: an authenticated-executable SECURITY DEFINER routine (public schema) with dynamic EXECUTE; must fail EC-SU-4d (#105)
|
|
2
|
+
create function public.zz_mdx_dynamic(p_sql text) returns void
|
|
3
|
+
language plpgsql security definer set search_path = '' as $$ begin execute p_sql; end $$;
|
|
4
|
+
revoke all on function public.zz_mdx_dynamic(text) from public;
|
|
5
|
+
grant execute on function public.zz_mdx_dynamic(text) to authenticated;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
-- §6.1: DETAIL carries the claim value; must fail the DETAIL row (#68)
|
|
2
|
+
do $m$
|
|
3
|
+
declare d text := pg_get_functiondef('agent_board._require_human_step_up(text)'::regprocedure); n text;
|
|
4
|
+
begin
|
|
5
|
+
n := d;
|
|
6
|
+
if strpos(n, ' if agent_board._step_up_is_fresh(v_proof, v_now) is not true then
|
|
7
|
+
raise exception ''step_up_required'' using errcode = ''MBS01'', detail = p_operation;') = 0 then raise exception 'MUTATION ANCHOR MISS (1)'; end if;
|
|
8
|
+
n := replace(n, ' if agent_board._step_up_is_fresh(v_proof, v_now) is not true then
|
|
9
|
+
raise exception ''step_up_required'' using errcode = ''MBS01'', detail = p_operation;', ' if agent_board._step_up_is_fresh(v_proof, v_now) is not true then
|
|
10
|
+
raise exception ''step_up_required'' using errcode = ''MBS01'', detail = p_operation || '':'' || v_proof::text;');
|
|
11
|
+
execute n;
|
|
12
|
+
end $m$;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
-- EC-SU-0 discriminance: a function that calls the helper; must fail EC-SU-0 (#1), naming it
|
|
2
|
+
create function agent_board.zz_mec0_gated_write() returns void
|
|
3
|
+
language plpgsql security definer set search_path = '' as $$ begin perform agent_board._require_human_step_up('zz'); end $$;
|
|
4
|
+
revoke all on function agent_board.zz_mec0_gated_write() from public;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
-- S1-1: an OVERLOAD _require_human_step_up(uuid) that calls the helper; must fail EC-SU-0 (#1), naming the overload by signature
|
|
2
|
+
create function agent_board._require_human_step_up(p_x uuid) returns void
|
|
3
|
+
language plpgsql security definer set search_path = '' as $$ begin perform agent_board._require_human_step_up('zz'::text); end $$;
|
|
4
|
+
revoke all on function agent_board._require_human_step_up(uuid) from public;
|