@consiliency/agent-board-schema 1.74.0 → 1.76.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 +8 -0
- package/migrations/20261108000100_agent_board_send_outcome.sql +708 -0
- package/migrations/20261109000100_agent_board_step_up_groundwork.sql +343 -0
- package/package.json +1 -1
- package/schema-manifest.json +21 -3
- package/src/deployment-drift-main.test.mjs +20 -3
- package/src/deployment-drift-script.test.mjs +77 -2
- package/src/deployment-drift.test.mjs +60 -0
- package/src/tooling.test.mjs +4 -2
- package/tests/agent_board_667_history_class.test.sql +2 -0
- package/tests/agent_board_717_native_surface.test.sql +223 -0
- package/tests/agent_board_delegate_role_class.test.sql +2 -2
- package/tests/agent_board_delivery_writer_execute.test.sql +4 -2
- package/tests/agent_board_enrollment_audit_content.test.sql +6 -1
- package/tests/agent_board_hosted_delegates.test.sql +8 -1
- package/tests/agent_board_send_outcome.test.sql +805 -0
- package/tests/agent_board_step_up_helper.test.sql +711 -0
- package/tests/agent_board_write_enforcement_class.test.sql +12 -5
- package/tests/catalog/function_execute_privileges.json +96 -0
- package/tests/catalog/p_metadata_parameters.json +40 -0
- package/tests/fixtures/isolation-substrate.sql +8 -0
- package/tests/fixtures/pgtap-unexposed.sql +61 -0
- package/tests/isolation/expected/send_outcome_cross_board.out +40 -0
- package/tests/isolation/expected/send_outcome_independence.out +295 -0
- package/tests/isolation/expected/send_outcome_membership.out +140 -0
- package/tests/isolation/expected/send_outcome_overlap.out +89 -0
- package/tests/isolation/expected/send_outcome_reader.out +87 -0
- package/tests/isolation/expected/send_outcome_recovery.out +107 -0
- package/tests/isolation/specs/send_outcome_cross_board.spec +66 -0
- package/tests/isolation/specs/send_outcome_independence.spec +95 -0
- package/tests/isolation/specs/send_outcome_membership.spec +73 -0
- package/tests/isolation/specs/send_outcome_overlap.spec +69 -0
- package/tests/isolation/specs/send_outcome_reader.spec +61 -0
- package/tests/isolation/specs/send_outcome_recovery.spec +68 -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 +72 -0
- package/tests/mutations/670/E1_helper_author_from_message.sql +7 -0
- package/tests/mutations/670/E2_helper_no_null_check.sql +13 -0
- package/tests/mutations/670/M10_lock_removed.sql +10 -0
- package/tests/mutations/670/M11_table_granted_to_authenticated.sql +2 -0
- package/tests/mutations/670/M12_helper_granted_to_service_role.sql +2 -0
- package/tests/mutations/670/M13_message_fk_no_cascade.sql +8 -0
- package/tests/mutations/670/M14_post_message_mints_from_metadata.sql +11 -0
- package/tests/mutations/670/M15_second_receipt_writer.sql +9 -0
- package/tests/mutations/670/M16_read_no_btrim.sql +7 -0
- package/tests/mutations/670/M17_read_volatile.sql +2 -0
- package/tests/mutations/670/M1_helper_no_service_role_guard.sql +13 -0
- package/tests/mutations/670/M3_helper_on_replay_branch.sql +10 -0
- package/tests/mutations/670/M4_read_checks_thread_existence.sql +10 -0
- package/tests/mutations/670/M5a_read_requires_thread_access.sql +10 -0
- package/tests/mutations/670/M5b_read_requires_board_membership.sql +11 -0
- package/tests/mutations/670/M6_read_admits_service_role.sql +14 -0
- package/tests/mutations/670/M7_confirmed_adds_message_sequence.sql +12 -0
- package/tests/mutations/670/M8_delivery_swallows_errors.sql +19 -0
- package/tests/mutations/670/M9_lock_key_includes_board.sql +10 -0
- package/tests/mutations/670/run.sh +84 -0
|
@@ -0,0 +1,711 @@
|
|
|
1
|
+
-- STEPUP PR-A pgTAP (#669, migration 20261109000100_agent_board_step_up_groundwork.sql).
|
|
2
|
+
--
|
|
3
|
+
-- THE CONTRACT (plans/STEPUP-669-plan.md §3, §4, §5.1, §6.1, §9, §10.1-§10.3 and §11.1, with the
|
|
4
|
+
-- §14 errata E-2 and E-6). PR-A is authority-neutral: nothing calls _require_human_step_up
|
|
5
|
+
-- (EC-SU-0), so these rows call the helper DIRECTLY as a privileged role with request.jwt.claims
|
|
6
|
+
-- set, exactly as a SECURITY DEFINER chokepoint will in PR-B.
|
|
7
|
+
-- * _step_up_is_fresh(proof, now): now - proof < 300 and proof - now <= 30 (P-rows, exact).
|
|
8
|
+
-- * The helper exempts only (a) the operator key -- service_role, no principal, no sub -- and
|
|
9
|
+
-- (b) agent/system principals. A Portal human needs a fresh top-level JSON-number
|
|
10
|
+
-- agent_board_step_up_at AND a ledger row (actor, T). A local human needs a fresh allowlisted
|
|
11
|
+
-- top-level amr entry. Its only raise is MBS01 step_up_required.
|
|
12
|
+
-- * record_portal_step_up(agent, T): service_role only; false unless the agent is a Portal
|
|
13
|
+
-- human and T is in [clock - 330, clock + 60]; inserts on conflict do nothing; prunes that
|
|
14
|
+
-- agent's rows older than a day.
|
|
15
|
+
--
|
|
16
|
+
-- METHOD (AGENTS.md rules 1-3).
|
|
17
|
+
-- * Allow-side rows use lives_ok; refusals use throws_ok with the SQLSTATE and message. No bare
|
|
18
|
+
-- select of a raising call: pg_temp.step raises inside throws_ok/lives_ok's own subtransaction.
|
|
19
|
+
-- * The allowlist ships EMPTY (E-0-AL pins it). E-6(b): the L-class rows run under a
|
|
20
|
+
-- transaction-local override of _step_up_amr_methods() = {otp,totp}, created after the
|
|
21
|
+
-- empty-allowlist rows; the file's rollback discards it. Without it every L REJECT row would
|
|
22
|
+
-- pass vacuously.
|
|
23
|
+
-- * Class assertions are catalog-derived (agent_board_test.fn_call_closure / stripped_body /
|
|
24
|
+
-- writes_any_re), so a new writer or caller names itself.
|
|
25
|
+
-- * Mutation labels: rows are named by their plan id (R-n, P-n, EC-SU-n, C-n for the E-6(b)
|
|
26
|
+
-- positive controls, RP-n for the ledger writer). Receipts: plans/evidence/669/.
|
|
27
|
+
create extension if not exists pgtap with schema extensions;
|
|
28
|
+
set search_path = extensions, public, agent_board;
|
|
29
|
+
|
|
30
|
+
begin;
|
|
31
|
+
|
|
32
|
+
select plan(108);
|
|
33
|
+
|
|
34
|
+
do $$
|
|
35
|
+
begin
|
|
36
|
+
if not (select rolsuper from pg_roles where rolname = current_user) then
|
|
37
|
+
execute format('grant agent_board_delegate, anon, authenticated, service_role to %I with set true', current_user);
|
|
38
|
+
end if;
|
|
39
|
+
end $$;
|
|
40
|
+
|
|
41
|
+
create temp table _h(k text primary key, v text);
|
|
42
|
+
create function pg_temp.v(p_k text) returns text language sql as $$ select v from _h where k = p_k $$;
|
|
43
|
+
create function pg_temp.u(p_k text) returns uuid language sql as $$
|
|
44
|
+
select case when v ~* '^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$' then v::uuid end from _h where k = p_k $$;
|
|
45
|
+
create function pg_temp.put(p_k text, p_v text) returns void language sql as $$
|
|
46
|
+
insert into _h values (p_k, p_v) on conflict (k) do update set v = excluded.v $$;
|
|
47
|
+
|
|
48
|
+
-- The database clock in whole seconds, read at call time (claims carry integer seconds).
|
|
49
|
+
create function pg_temp.now_s() returns bigint language sql volatile as $$
|
|
50
|
+
select floor(extract(epoch from clock_timestamp()))::bigint $$;
|
|
51
|
+
|
|
52
|
+
-- Record a ledger row directly, as the table owner, and return T (a fixture, not the writer).
|
|
53
|
+
create function pg_temp.ledger(p_who text, p_t bigint) returns bigint language sql volatile as $$
|
|
54
|
+
insert into agent_board.portal_step_up_proofs(agent_id, proof_at) values (pg_temp.u(p_who), p_t)
|
|
55
|
+
on conflict do nothing;
|
|
56
|
+
select p_t $$;
|
|
57
|
+
|
|
58
|
+
-- p_who's base claims (role, sub, aud) merged with p_extra.
|
|
59
|
+
create function pg_temp.c(p_who text, p_extra jsonb default '{}'::jsonb) returns text language sql as $$
|
|
60
|
+
select (jsonb_strip_nulls(jsonb_build_object(
|
|
61
|
+
'role', coalesce(pg_temp.v(p_who || '.role'), 'authenticated'),
|
|
62
|
+
'sub', pg_temp.v(p_who || '.auth'),
|
|
63
|
+
'aud', 'authenticated')) || p_extra)::text $$;
|
|
64
|
+
|
|
65
|
+
-- Set ONE JSON claim set; every flattened legacy claim GUC is cleared unless named.
|
|
66
|
+
create function pg_temp.set_claims(p_claims text, p_legacy_name text default null, p_legacy_value text default null)
|
|
67
|
+
returns void language plpgsql as $$
|
|
68
|
+
begin
|
|
69
|
+
perform set_config('request.jwt.claim.sub', '', true);
|
|
70
|
+
perform set_config('request.jwt.claim.role', '', true);
|
|
71
|
+
perform set_config('request.jwt.claim.agent_credential_id', '', true);
|
|
72
|
+
perform set_config('request.jwt.claim.identity_lease_epoch', '', true);
|
|
73
|
+
perform set_config('request.jwt.claim.agent_board_step_up_at', '', true);
|
|
74
|
+
perform set_config('request.jwt.claim.amr', '', true);
|
|
75
|
+
if p_legacy_name is not null then
|
|
76
|
+
perform set_config('request.jwt.claim.' || p_legacy_name, p_legacy_value, true);
|
|
77
|
+
end if;
|
|
78
|
+
perform set_config('request.jwt.claims', coalesce(p_claims, ''), true);
|
|
79
|
+
end $$;
|
|
80
|
+
|
|
81
|
+
-- Call the helper under p_claims. Raises the helper's error (inside the caller's
|
|
82
|
+
-- throws_ok/lives_ok subtransaction, which reverts the GUCs); on success restores no-claims.
|
|
83
|
+
create function pg_temp.step(p_claims text, p_legacy_name text default null, p_legacy_value text default null)
|
|
84
|
+
returns void language plpgsql as $$
|
|
85
|
+
begin
|
|
86
|
+
perform pg_temp.set_claims(p_claims, p_legacy_name, p_legacy_value);
|
|
87
|
+
perform agent_board._require_human_step_up('grant_board_role');
|
|
88
|
+
perform pg_temp.set_claims(null);
|
|
89
|
+
end $$;
|
|
90
|
+
|
|
91
|
+
-- The helper's error as 'SQLSTATE|message|detail', or 'ok'. Never raises.
|
|
92
|
+
create function pg_temp.diag(p_claims text) returns text language plpgsql as $$
|
|
93
|
+
declare v_state text; v_msg text; v_detail text;
|
|
94
|
+
begin
|
|
95
|
+
begin
|
|
96
|
+
perform pg_temp.step(p_claims);
|
|
97
|
+
return 'ok';
|
|
98
|
+
exception when others then
|
|
99
|
+
get stacked diagnostics v_state = returned_sqlstate, v_msg = message_text, v_detail = pg_exception_detail;
|
|
100
|
+
perform pg_temp.set_claims(null);
|
|
101
|
+
return v_state || '|' || v_msg || '|' || coalesce(v_detail, '(null)');
|
|
102
|
+
end;
|
|
103
|
+
end $$;
|
|
104
|
+
|
|
105
|
+
-- record_portal_step_up as role p_role (claims cleared): 'true'/'false', 'ERR <state>:fn' when the
|
|
106
|
+
-- error names record_portal_step_up itself (a privilege refusal ON the writer), else
|
|
107
|
+
-- 'ERR <state>:<message>'. The agent id is resolved BEFORE the role switch: API roles cannot read
|
|
108
|
+
-- the fixture table, and a refusal on _h must never pass for a refusal on the writer.
|
|
109
|
+
create function pg_temp.rec(p_role text, p_who text, p_t bigint) returns text language plpgsql as $$
|
|
110
|
+
declare v boolean; r text; v_id uuid := pg_temp.u(p_who);
|
|
111
|
+
begin
|
|
112
|
+
perform pg_temp.set_claims(case when p_role = 'postgres' then null
|
|
113
|
+
else jsonb_build_object('role', p_role)::text end);
|
|
114
|
+
if p_role <> 'postgres' then
|
|
115
|
+
execute format('set local role %I', p_role);
|
|
116
|
+
end if;
|
|
117
|
+
begin
|
|
118
|
+
-- Dynamic SQL: a static call is a PL/pgSQL simple expression whose EXECUTE check runs once,
|
|
119
|
+
-- at its first initialisation in the transaction (as service_role in RP-1), and is not
|
|
120
|
+
-- repeated after SET ROLE. Planning each call afresh checks the CURRENT role.
|
|
121
|
+
execute format('select agent_board.record_portal_step_up(%L::uuid, %s::bigint)', v_id, p_t) into v;
|
|
122
|
+
r := coalesce(v::text, '(null)');
|
|
123
|
+
exception when others then
|
|
124
|
+
r := 'ERR ' || sqlstate || ':' || case when sqlerrm like '%record_portal_step_up%' then 'fn'
|
|
125
|
+
when sqlerrm = 'permission denied for schema agent_board' then 'schema'
|
|
126
|
+
else sqlerrm end;
|
|
127
|
+
end;
|
|
128
|
+
reset role;
|
|
129
|
+
perform pg_temp.set_claims(null);
|
|
130
|
+
return r;
|
|
131
|
+
end $$;
|
|
132
|
+
|
|
133
|
+
-- Run p_sql (a single-scalar select) as role p_role with claims cleared; same result shape as rec().
|
|
134
|
+
create function pg_temp.rec_sql(p_role text, p_sql text) returns text language plpgsql as $$
|
|
135
|
+
declare v text;
|
|
136
|
+
begin
|
|
137
|
+
perform pg_temp.set_claims(case when p_role = 'postgres' then null else jsonb_build_object('role', p_role)::text end);
|
|
138
|
+
if p_role <> 'postgres' then execute format('set local role %I', p_role); end if;
|
|
139
|
+
begin
|
|
140
|
+
execute p_sql into v;
|
|
141
|
+
v := coalesce(v, '(null)');
|
|
142
|
+
exception when others then
|
|
143
|
+
v := 'ERR ' || sqlstate || ':' || sqlerrm;
|
|
144
|
+
end;
|
|
145
|
+
reset role;
|
|
146
|
+
perform pg_temp.set_claims(null);
|
|
147
|
+
return v;
|
|
148
|
+
end $$;
|
|
149
|
+
|
|
150
|
+
create function pg_temp.rows_for(p_who text) returns int language sql as $$
|
|
151
|
+
select count(*)::int from agent_board.portal_step_up_proofs where agent_id = pg_temp.u(p_who) $$;
|
|
152
|
+
create function pg_temp.has_row(p_who text, p_t bigint) returns boolean language sql as $$
|
|
153
|
+
select exists (select 1 from agent_board.portal_step_up_proofs where agent_id = pg_temp.u(p_who) and proof_at = p_t) $$;
|
|
154
|
+
|
|
155
|
+
-- ===========================================================================
|
|
156
|
+
-- Fixtures (§10 fixtures, reduced to what a direct helper call needs)
|
|
157
|
+
-- P Portal human: kind=human + enrollment_federation_audit row mode='fedsession'
|
|
158
|
+
-- L local human: kind=human, no audit row
|
|
159
|
+
-- G agent principal
|
|
160
|
+
-- SUS suspended human (relay sub of R-14b)
|
|
161
|
+
-- LM local human whose agents.metadata claims a federation (M15's forged slot)
|
|
162
|
+
-- NOAGENT an auth user with no agent row
|
|
163
|
+
-- ===========================================================================
|
|
164
|
+
insert into auth.users(id, instance_id, aud, role, email)
|
|
165
|
+
select ('669a0000-0000-4000-8000-' || lpad(n::text, 12, '0'))::uuid,
|
|
166
|
+
'00000000-0000-0000-0000-000000000000', 'authenticated', 'authenticated', 'su669-' || n || '@t.test'
|
|
167
|
+
from generate_series(1, 6) n;
|
|
168
|
+
insert into agent_board.agents(id, agent_type, kind, handle, display_name, status, auth_user_id, owner_user_id, metadata)
|
|
169
|
+
values
|
|
170
|
+
('669a1000-0000-4000-8000-000000000001', 'human', 'human', 'su669-p', 'SU669 P', 'active',
|
|
171
|
+
'669a0000-0000-4000-8000-000000000001', '669a0000-0000-4000-8000-000000000001', '{}'),
|
|
172
|
+
('669a1000-0000-4000-8000-000000000002', 'human', 'human', 'su669-l', 'SU669 L', 'active',
|
|
173
|
+
'669a0000-0000-4000-8000-000000000002', '669a0000-0000-4000-8000-000000000002', '{}'),
|
|
174
|
+
('669a1000-0000-4000-8000-000000000003', 'agent', 'agent', 'su669-g', 'SU669 G', 'active',
|
|
175
|
+
'669a0000-0000-4000-8000-000000000003', null, '{}'),
|
|
176
|
+
('669a1000-0000-4000-8000-000000000004', 'human', 'human', 'su669-sus', 'SU669 SUS', 'suspended',
|
|
177
|
+
'669a0000-0000-4000-8000-000000000004', '669a0000-0000-4000-8000-000000000004', '{}'),
|
|
178
|
+
('669a1000-0000-4000-8000-000000000005', 'human', 'human', 'su669-lm', 'SU669 LM', 'active',
|
|
179
|
+
'669a0000-0000-4000-8000-000000000005', '669a0000-0000-4000-8000-000000000005',
|
|
180
|
+
'{"federation":{"issuer":"https://forged-metadata.test","subject":"su669-forged"},"mode":"fedsession"}');
|
|
181
|
+
do $$
|
|
182
|
+
declare h text; n int := 0;
|
|
183
|
+
begin
|
|
184
|
+
foreach h in array array['P', 'L', 'G', 'SUS', 'LM', 'NOAGENT'] loop
|
|
185
|
+
n := n + 1;
|
|
186
|
+
if h <> 'NOAGENT' then
|
|
187
|
+
perform pg_temp.put(h, '669a1000-0000-4000-8000-' || lpad(n::text, 12, '0'));
|
|
188
|
+
end if;
|
|
189
|
+
perform pg_temp.put(h || '.auth', '669a0000-0000-4000-8000-' || lpad(n::text, 12, '0'));
|
|
190
|
+
end loop;
|
|
191
|
+
end $$;
|
|
192
|
+
-- P's class evidence: the service-written fedsession audit row (§3.3).
|
|
193
|
+
insert into agent_board.enrollment_federation_audit(
|
|
194
|
+
issuer, audience, subject, human_identity_claim, agent_id, auth_user_id, requested_scopes, granted_scopes, mode)
|
|
195
|
+
values ('https://su669-portal.test', 'message-board', 'su669-p-subject',
|
|
196
|
+
'{"iss":"https://su669-portal.test","sub":"su669-p-subject"}'::jsonb,
|
|
197
|
+
pg_temp.u('P'), pg_temp.u('P.auth'), '{}', '{}', 'fedsession');
|
|
198
|
+
-- A live credential for P (R-8: an agent-shaped token on a human).
|
|
199
|
+
insert into agent_board.agent_credentials(id, agent_id, refresh_token_hash, hash_version, credential_label, expires_at)
|
|
200
|
+
values ('669a3000-0000-4000-8000-000000000001', pg_temp.u('P'), decode(md5('su669-p-refresh'), 'hex'), 1, 'su669-p', now() + interval '1 day');
|
|
201
|
+
select pg_temp.put('P.cred', '669a3000-0000-4000-8000-000000000001');
|
|
202
|
+
|
|
203
|
+
-- Fixture sanity: the classifier sees P as portal and L as local (a wrong fixture must stop the
|
|
204
|
+
-- file loudly). LM is deliberately NOT checked here: whether its forged metadata buys a class is
|
|
205
|
+
-- the property under test, judged by the counted M15 rows, never by an abort.
|
|
206
|
+
do $$
|
|
207
|
+
begin
|
|
208
|
+
if agent_board._step_up_is_portal_human(pg_temp.u('P')) is not true
|
|
209
|
+
or agent_board._step_up_is_portal_human(pg_temp.u('L')) is not false then
|
|
210
|
+
raise exception 'fixture: classifier does not see P as portal and L as local';
|
|
211
|
+
end if;
|
|
212
|
+
end $$;
|
|
213
|
+
|
|
214
|
+
create temp table _cl as select * from agent_board_test.fn_call_closure();
|
|
215
|
+
create temp table _su_fns(sig text primary key);
|
|
216
|
+
insert into _su_fns values
|
|
217
|
+
('agent_board._require_human_step_up(text)'),
|
|
218
|
+
('agent_board._step_up_is_fresh(numeric,numeric)'),
|
|
219
|
+
('agent_board._step_up_max_age_seconds()'),
|
|
220
|
+
('agent_board._step_up_future_skew_seconds()'),
|
|
221
|
+
('agent_board._step_up_amr_methods()'),
|
|
222
|
+
('agent_board._step_up_is_portal_human(uuid)'),
|
|
223
|
+
('agent_board._step_up_proof_recordable(numeric,numeric)'),
|
|
224
|
+
('agent_board.record_portal_step_up(uuid,bigint)');
|
|
225
|
+
|
|
226
|
+
-- ===========================================================================
|
|
227
|
+
-- §10.1 catalog class: EC-SU-0, EC-SU-4 (ledger clause, E-2 closure form), EC-SU-5
|
|
228
|
+
-- ===========================================================================
|
|
229
|
+
|
|
230
|
+
-- EC-SU-0 (PR-A neutrality): no function but the helper itself reaches _require_human_step_up.
|
|
231
|
+
-- Both sides are keyed by OID, never by name: an overload such as _require_human_step_up(uuid)
|
|
232
|
+
-- that calls the helper is a caller and must name itself (by signature).
|
|
233
|
+
select is(
|
|
234
|
+
(select coalesce(string_agg(distinct c.root_oid::regprocedure::text, ' ' order by c.root_oid::regprocedure::text), '(none)')
|
|
235
|
+
from _cl c
|
|
236
|
+
where c.reached_oid = 'agent_board._require_human_step_up(text)'::regprocedure
|
|
237
|
+
and c.root_oid <> 'agent_board._require_human_step_up(text)'::regprocedure),
|
|
238
|
+
'(none)',
|
|
239
|
+
'EC-SU-0: no agent_board function calls _require_human_step_up (PR-A changes no authority outcome)');
|
|
240
|
+
|
|
241
|
+
-- EC-SU-0 control: the same closure DOES see the helper's own calls, so (1) is not vacuous.
|
|
242
|
+
select is(
|
|
243
|
+
(select string_agg(distinct c.reached_name collate "C", ' ' order by c.reached_name collate "C")
|
|
244
|
+
from _cl c
|
|
245
|
+
where c.root_oid = 'agent_board._require_human_step_up(text)'::regprocedure and c.reached_name like '\_step\_up\_%'),
|
|
246
|
+
'_step_up_amr_methods _step_up_future_skew_seconds _step_up_is_fresh _step_up_is_portal_human _step_up_max_age_seconds',
|
|
247
|
+
'EC-SU-0 control: fn_call_closure resolves the helper''s calls to the step-up functions');
|
|
248
|
+
|
|
249
|
+
-- EC-SU-4: W(portal_step_up_proofs) is exactly record_portal_step_up (positive: the writer exists).
|
|
250
|
+
select is(
|
|
251
|
+
(select coalesce(string_agg(p.oid::regprocedure::text, ' ' order by p.oid::regprocedure::text), '(none)')
|
|
252
|
+
from pg_proc p
|
|
253
|
+
where p.pronamespace = 'agent_board'::regnamespace and p.prokind in ('f', 'p')
|
|
254
|
+
and p.prolang <> (select oid from pg_language where lanname = 'internal')
|
|
255
|
+
and agent_board_test.stripped_body(p.oid) ~ agent_board_test.writes_any_re(array['portal_step_up_proofs'])),
|
|
256
|
+
'agent_board.record_portal_step_up(uuid,bigint)'::regprocedure::text,
|
|
257
|
+
'EC-SU-4: record_portal_step_up is the only function whose body writes portal_step_up_proofs');
|
|
258
|
+
|
|
259
|
+
-- EC-SU-4 (E-2): no member of the reflexive reverse call closure of the ledger's writers is
|
|
260
|
+
-- executable by anon, authenticated or agent_board_delegate. A definer wrapper names itself.
|
|
261
|
+
select is(
|
|
262
|
+
(select coalesce(string_agg(distinct c.root_oid::regprocedure::text || '<-' || r.role, ' '
|
|
263
|
+
order by c.root_oid::regprocedure::text || '<-' || r.role), '(none)')
|
|
264
|
+
from _cl c
|
|
265
|
+
join pg_proc w on w.oid = c.reached_oid
|
|
266
|
+
cross join (values ('anon'), ('authenticated'), ('agent_board_delegate')) r(role)
|
|
267
|
+
where agent_board_test.stripped_body(w.oid) ~ agent_board_test.writes_any_re(array['portal_step_up_proofs'])
|
|
268
|
+
and has_function_privilege(r.role, c.root_oid, 'EXECUTE')),
|
|
269
|
+
'(none)',
|
|
270
|
+
'EC-SU-4 (E-2): no API role can execute any function whose call closure reaches a ledger writer');
|
|
271
|
+
|
|
272
|
+
-- EC-SU-4 control: that reverse closure is non-empty (it contains the writer itself).
|
|
273
|
+
select ok(
|
|
274
|
+
(select count(distinct c.root_oid) >= 1
|
|
275
|
+
from _cl c join pg_proc w on w.oid = c.reached_oid
|
|
276
|
+
where agent_board_test.stripped_body(w.oid) ~ agent_board_test.writes_any_re(array['portal_step_up_proofs'])),
|
|
277
|
+
'EC-SU-4 control: the ledger writers'' reverse closure is non-empty, so (4) inspected something');
|
|
278
|
+
|
|
279
|
+
-- EC-SU-4: no API role, and not service_role, holds any table privilege on the ledger.
|
|
280
|
+
select is(
|
|
281
|
+
(select coalesce(string_agg(r.role || ':' || pv.priv, ' ' order by r.role, pv.priv), '(none)')
|
|
282
|
+
from (values ('anon'), ('authenticated'), ('agent_board_delegate'), ('service_role')) r(role)
|
|
283
|
+
cross join (values ('SELECT'), ('INSERT'), ('UPDATE'), ('DELETE'), ('TRUNCATE'), ('REFERENCES'), ('TRIGGER')) pv(priv)
|
|
284
|
+
where has_table_privilege(r.role, 'agent_board.portal_step_up_proofs', pv.priv)),
|
|
285
|
+
'(none)',
|
|
286
|
+
'EC-SU-4: no API role and not service_role holds any privilege on portal_step_up_proofs');
|
|
287
|
+
|
|
288
|
+
-- EC-SU-4: RLS on, zero policies.
|
|
289
|
+
select is(
|
|
290
|
+
(select c.relrowsecurity::text || '/' || (select count(*) from pg_policy p where p.polrelid = c.oid)::text
|
|
291
|
+
from pg_class c where c.oid = 'agent_board.portal_step_up_proofs'::regclass),
|
|
292
|
+
'true/0',
|
|
293
|
+
'EC-SU-4: portal_step_up_proofs has RLS enabled and zero policies');
|
|
294
|
+
|
|
295
|
+
-- EC-SU-4 (D2): a unique index whose only key is agents.auth_user_id exists.
|
|
296
|
+
select ok(
|
|
297
|
+
exists (
|
|
298
|
+
select 1 from pg_index i
|
|
299
|
+
where i.indrelid = 'agent_board.agents'::regclass and i.indisunique and i.indnkeyatts = 1
|
|
300
|
+
and i.indkey[0] = (select attnum from pg_attribute where attrelid = 'agent_board.agents'::regclass and attname = 'auth_user_id')),
|
|
301
|
+
'EC-SU-4 (D2): agents.auth_user_id is unique, so current_agent_id() resolves one principal');
|
|
302
|
+
|
|
303
|
+
-- EC-SU-4g (the positive claim behind agent_board_enrollment_audit_content's exemption):
|
|
304
|
+
-- _step_up_is_portal_human is the only step-up function that references
|
|
305
|
+
-- enrollment_federation_audit, and it never writes it.
|
|
306
|
+
select is(
|
|
307
|
+
(select coalesce(string_agg(p.proname || case when agent_board_test.stripped_body(p.oid) ~ agent_board_test.writes_any_re(array['enrollment_federation_audit'])
|
|
308
|
+
then ':WRITES' else ':reads' end, ' ' order by p.proname), '(none)')
|
|
309
|
+
from _su_fns f join pg_proc p on p.oid = f.sig::regprocedure
|
|
310
|
+
where agent_board_test.stripped_body(p.oid, true) ~ agent_board_test.qname_re('enrollment_federation_audit')),
|
|
311
|
+
'_step_up_is_portal_human:reads',
|
|
312
|
+
'EC-SU-4g: only the class binding references enrollment_federation_audit, and only to read it');
|
|
313
|
+
|
|
314
|
+
-- EC-SU-5: none of the seven step-up functions is executable by PUBLIC or an API role.
|
|
315
|
+
select is(
|
|
316
|
+
(select coalesce(string_agg(f.sig || '<-' || r.role, ' ' order by f.sig, r.role), '(none)')
|
|
317
|
+
from _su_fns f
|
|
318
|
+
cross join (values ('public'), ('anon'), ('authenticated'), ('agent_board_delegate')) r(role)
|
|
319
|
+
where has_function_privilege(r.role, f.sig::regprocedure, 'EXECUTE')),
|
|
320
|
+
'(none)',
|
|
321
|
+
'EC-SU-5: no step-up function is executable by PUBLIC, anon, authenticated or agent_board_delegate');
|
|
322
|
+
|
|
323
|
+
-- EC-SU-5: service_role executes record_portal_step_up and nothing else of the seven.
|
|
324
|
+
select is(
|
|
325
|
+
(select string_agg(f.sig, ' ' order by f.sig) from _su_fns f
|
|
326
|
+
where has_function_privilege('service_role', f.sig::regprocedure, 'EXECUTE')),
|
|
327
|
+
'agent_board.record_portal_step_up(uuid,bigint)',
|
|
328
|
+
'EC-SU-5: service_role can execute record_portal_step_up and none of the internal step-up helpers');
|
|
329
|
+
|
|
330
|
+
-- EC-SU-5: each carries a COMMENT.
|
|
331
|
+
select is(
|
|
332
|
+
(select coalesce(string_agg(f.sig, ' ' order by f.sig), '(none)') from _su_fns f
|
|
333
|
+
where coalesce(obj_description(f.sig::regprocedure, 'pg_proc'), '') = ''),
|
|
334
|
+
'(none)',
|
|
335
|
+
'EC-SU-5: every step-up function has a COMMENT');
|
|
336
|
+
|
|
337
|
+
-- EC-SU-5 shape: the window, skew, predicate and allowlist are IMMUTABLE; the helper and the
|
|
338
|
+
-- classifier are SECURITY INVOKER; the writer is SECURITY DEFINER; all pin search_path=''.
|
|
339
|
+
select is(
|
|
340
|
+
(select coalesce(string_agg(p.oid::regprocedure::text, ' ' order by p.oid::regprocedure::text), '(none)')
|
|
341
|
+
from _su_fns f join pg_proc p on p.oid = f.sig::regprocedure
|
|
342
|
+
where not (coalesce(p.proconfig, '{}') @> array['search_path=""'])
|
|
343
|
+
or (p.proname in ('_step_up_is_fresh', '_step_up_max_age_seconds', '_step_up_future_skew_seconds', '_step_up_amr_methods',
|
|
344
|
+
'_step_up_proof_recordable')
|
|
345
|
+
and p.provolatile <> 'i')
|
|
346
|
+
or (p.proname in ('_require_human_step_up', '_step_up_is_portal_human', '_step_up_is_fresh',
|
|
347
|
+
'_step_up_max_age_seconds', '_step_up_future_skew_seconds', '_step_up_amr_methods',
|
|
348
|
+
'_step_up_proof_recordable')
|
|
349
|
+
and p.prosecdef)
|
|
350
|
+
or (p.proname = 'record_portal_step_up' and not p.prosecdef)),
|
|
351
|
+
'(none)',
|
|
352
|
+
'EC-SU-5: volatility, security mode and search_path of every step-up function match §4/§6.1/§9.1');
|
|
353
|
+
|
|
354
|
+
-- The window constants (D9).
|
|
355
|
+
select is(
|
|
356
|
+
agent_board._step_up_max_age_seconds()::text || '/' || agent_board._step_up_future_skew_seconds()::text,
|
|
357
|
+
'300/30',
|
|
358
|
+
'D9: the window is 300 s with 30 s future skew');
|
|
359
|
+
|
|
360
|
+
-- §11.1: the allowlist ships EMPTY in PR-A.
|
|
361
|
+
select is(agent_board._step_up_amr_methods(), '{}'::text[], 'E-0-AL: _step_up_amr_methods() is empty in PR-A');
|
|
362
|
+
|
|
363
|
+
-- E-0-AL consequence: under the shipped (empty) allowlist a fresh otp proves nothing.
|
|
364
|
+
select throws_ok(
|
|
365
|
+
format('select pg_temp.step(%L)', pg_temp.c('L', jsonb_build_object('amr', jsonb_build_array(jsonb_build_object('method', 'otp', 'timestamp', pg_temp.now_s() - 10))))),
|
|
366
|
+
'MBS01', 'step_up_required',
|
|
367
|
+
'E-0-AL: a local human with a fresh otp gets MBS01 while the allowlist is empty');
|
|
368
|
+
|
|
369
|
+
-- ===========================================================================
|
|
370
|
+
-- §10.3 predicate rows (D9), p_now = 1000000
|
|
371
|
+
-- ===========================================================================
|
|
372
|
+
select is(agent_board._step_up_is_fresh(1000000 - 299.999, 1000000), true, 'P-1: age 299.999 is fresh');
|
|
373
|
+
select is(agent_board._step_up_is_fresh(1000000 - 300, 1000000), false, 'P-2: age 300 is stale');
|
|
374
|
+
select is(agent_board._step_up_is_fresh(1000000 + 30, 1000000), true, 'P-3: 30 s in the future is fresh');
|
|
375
|
+
select is(agent_board._step_up_is_fresh(1000000 + 30.001, 1000000), false, 'P-4: 30.001 s in the future is stale');
|
|
376
|
+
select is(agent_board._step_up_is_fresh(null, 1000000), false, 'P-5: a NULL proof is false, never NULL');
|
|
377
|
+
|
|
378
|
+
-- E-6(b): transaction-local test override of the allowlist; the file's rollback discards it.
|
|
379
|
+
create or replace function agent_board._step_up_amr_methods()
|
|
380
|
+
returns text[] language sql immutable parallel safe set search_path = '' as $$ select '{otp,totp}'::text[] $$;
|
|
381
|
+
|
|
382
|
+
-- ===========================================================================
|
|
383
|
+
-- E-6(b) positive controls (lives_ok). "The helper always raises" must turn each red.
|
|
384
|
+
-- ===========================================================================
|
|
385
|
+
-- C-1: Portal human, T = clock - 10, with a ledger row.
|
|
386
|
+
select lives_ok(
|
|
387
|
+
format('select pg_temp.step(%L)', pg_temp.c('P', jsonb_build_object('agent_board_step_up_at', pg_temp.ledger('P', pg_temp.now_s() - 10)))),
|
|
388
|
+
'C-1: a Portal human with a fresh claim and its ledger row passes');
|
|
389
|
+
-- C-1b (A-1b): T = clock + 20 (inside the 30 s skew), with a ledger row.
|
|
390
|
+
select lives_ok(
|
|
391
|
+
format('select pg_temp.step(%L)', pg_temp.c('P', jsonb_build_object('agent_board_step_up_at', pg_temp.ledger('P', pg_temp.now_s() + 20)))),
|
|
392
|
+
'C-1b: a Portal proof 20 s in the future passes');
|
|
393
|
+
-- C-2 (A-2): local human, [{oauth, clock - 3000}, {otp, clock - 10}] under the override.
|
|
394
|
+
select lives_ok(
|
|
395
|
+
format('select pg_temp.step(%L)', pg_temp.c('L', jsonb_build_object('amr', jsonb_build_array(
|
|
396
|
+
jsonb_build_object('method', 'oauth', 'timestamp', pg_temp.now_s() - 3000),
|
|
397
|
+
jsonb_build_object('method', 'otp', 'timestamp', pg_temp.now_s() - 10))))),
|
|
398
|
+
'C-2: a local human with a fresh allowlisted otp passes');
|
|
399
|
+
-- C-2b (A-2b): local human, [{totp, clock - 10}].
|
|
400
|
+
select lives_ok(
|
|
401
|
+
format('select pg_temp.step(%L)', pg_temp.c('L', jsonb_build_object('amr', jsonb_build_array(
|
|
402
|
+
jsonb_build_object('method', 'totp', 'timestamp', pg_temp.now_s() - 10))))),
|
|
403
|
+
'C-2b: a local human with a fresh totp passes');
|
|
404
|
+
-- C-3 (A-3): an agent principal with no proof at all.
|
|
405
|
+
select lives_ok(format('select pg_temp.step(%L)', pg_temp.c('G')), 'C-3: an agent principal is exempt');
|
|
406
|
+
-- C-4 (A-5): the operator key, role service_role with no sub.
|
|
407
|
+
select lives_ok(format('select pg_temp.step(%L)', '{"role":"service_role"}'), 'C-4: the operator key (service_role, no sub) is exempt');
|
|
408
|
+
-- C-4b: a direct postgres session with no JWT is the operator too (_is_service_role()).
|
|
409
|
+
select lives_ok('select pg_temp.step(null)', 'C-4b: a direct database session with no claims is exempt (operator)');
|
|
410
|
+
|
|
411
|
+
-- ===========================================================================
|
|
412
|
+
-- §10.2 REJECT rows, called directly (throws_ok MBS01 step_up_required)
|
|
413
|
+
-- ===========================================================================
|
|
414
|
+
-- R-1: T = clock - 301 with a ledger row.
|
|
415
|
+
select throws_ok(
|
|
416
|
+
format('select pg_temp.step(%L)', pg_temp.c('P', jsonb_build_object('agent_board_step_up_at', pg_temp.ledger('P', pg_temp.now_s() - 301)))),
|
|
417
|
+
'MBS01', 'step_up_required', 'R-1: a stale Portal proof (301 s) is refused');
|
|
418
|
+
-- R-2: no claim, ledger row present.
|
|
419
|
+
select pg_temp.ledger('P', pg_temp.now_s() - 5);
|
|
420
|
+
select throws_ok(format('select pg_temp.step(%L)', pg_temp.c('P')),
|
|
421
|
+
'MBS01', 'step_up_required', 'R-2: a Portal human with a fresh ledger row but no claim is refused');
|
|
422
|
+
-- R-2b: amr absent.
|
|
423
|
+
select throws_ok(format('select pg_temp.step(%L)', pg_temp.c('L')),
|
|
424
|
+
'MBS01', 'step_up_required', 'R-2b: a local human with no amr is refused');
|
|
425
|
+
-- R-2b: amr [].
|
|
426
|
+
select throws_ok(format('select pg_temp.step(%L)', pg_temp.c('L', '{"amr":[]}')),
|
|
427
|
+
'MBS01', 'step_up_required', 'R-2b: a local human with amr [] is refused');
|
|
428
|
+
-- R-3: [{otp, clock - 301}].
|
|
429
|
+
select throws_ok(
|
|
430
|
+
format('select pg_temp.step(%L)', pg_temp.c('L', jsonb_build_object('amr', jsonb_build_array(jsonb_build_object('method', 'otp', 'timestamp', pg_temp.now_s() - 301))))),
|
|
431
|
+
'MBS01', 'step_up_required', 'R-3: a stale otp (301 s) is refused');
|
|
432
|
+
-- R-4: re-mint, no ceremony: iat = clock, T = clock - 301, ledger row.
|
|
433
|
+
select throws_ok(
|
|
434
|
+
format('select pg_temp.step(%L)', pg_temp.c('P', jsonb_build_object('iat', pg_temp.now_s(),
|
|
435
|
+
'agent_board_step_up_at', pg_temp.ledger('P', pg_temp.now_s() - 301)))),
|
|
436
|
+
'MBS01', 'step_up_required', 'R-4: a re-minted token (fresh iat, stale T) is refused; iat is never freshness');
|
|
437
|
+
-- R-4b: silent refresh: iat = clock, [{otp, clock - 301}, {token_refresh, clock}].
|
|
438
|
+
select throws_ok(
|
|
439
|
+
format('select pg_temp.step(%L)', pg_temp.c('L', jsonb_build_object('iat', pg_temp.now_s(), 'amr', jsonb_build_array(
|
|
440
|
+
jsonb_build_object('method', 'otp', 'timestamp', pg_temp.now_s() - 301),
|
|
441
|
+
jsonb_build_object('method', 'token_refresh', 'timestamp', pg_temp.now_s()))))),
|
|
442
|
+
'MBS01', 'step_up_required', 'R-4b: a silent refresh (fresh token_refresh, stale otp) is refused');
|
|
443
|
+
-- R-4c: non-qualifying fresh methods (Q3 exclusions).
|
|
444
|
+
select throws_ok(
|
|
445
|
+
format('select pg_temp.step(%L)', pg_temp.c('L', jsonb_build_object('amr', jsonb_build_array(jsonb_build_object('method', m, 'timestamp', pg_temp.now_s()))))),
|
|
446
|
+
'MBS01', 'step_up_required', 'R-4c: a fresh ' || m || ' sign-in is not a step-up')
|
|
447
|
+
from unnest(array['oauth', 'password', 'magiclink', 'mfa/recovery_code']) m;
|
|
448
|
+
-- R-4c: aal2 with a stale totp (aal is never consulted).
|
|
449
|
+
select throws_ok(
|
|
450
|
+
format('select pg_temp.step(%L)', pg_temp.c('L', jsonb_build_object('aal', 'aal2', 'amr', jsonb_build_array(
|
|
451
|
+
jsonb_build_object('method', 'totp', 'timestamp', pg_temp.now_s() - 301))))),
|
|
452
|
+
'MBS01', 'step_up_required', 'R-4c: aal2 with a stale totp is refused (aal is never freshness)');
|
|
453
|
+
-- R-5: forged slots: fresh user_metadata.amr / user_metadata.agent_board_step_up_at, top-level stale.
|
|
454
|
+
select throws_ok(
|
|
455
|
+
format('select pg_temp.step(%L)', pg_temp.c('L', jsonb_build_object(
|
|
456
|
+
'user_metadata', jsonb_build_object(
|
|
457
|
+
'amr', jsonb_build_array(jsonb_build_object('method', 'otp', 'timestamp', pg_temp.now_s())),
|
|
458
|
+
'agent_board_step_up_at', pg_temp.now_s()),
|
|
459
|
+
'amr', jsonb_build_array(jsonb_build_object('method', 'otp', 'timestamp', pg_temp.now_s() - 301))))),
|
|
460
|
+
'MBS01', 'step_up_required', 'R-5: fresh proofs under user_metadata are ignored');
|
|
461
|
+
-- R-5b: fresh app_metadata.agent_board_step_up_at with a ledger row, no top-level claim.
|
|
462
|
+
select throws_ok(
|
|
463
|
+
format('select pg_temp.step(%L)', pg_temp.c('P', jsonb_build_object('app_metadata',
|
|
464
|
+
jsonb_build_object('agent_board_step_up_at', pg_temp.ledger('P', pg_temp.now_s() - 7))))),
|
|
465
|
+
'MBS01', 'step_up_required', 'R-5b: a fresh claim under app_metadata is ignored');
|
|
466
|
+
-- R-5c: the legacy flattened GUC carries a fresh T (with a ledger row); request.jwt.claims does not.
|
|
467
|
+
select throws_ok(
|
|
468
|
+
format('select pg_temp.step(%L, %L, %L)', pg_temp.c('P'), 'agent_board_step_up_at', pg_temp.ledger('P', pg_temp.now_s() - 8)::text),
|
|
469
|
+
'MBS01', 'step_up_required', 'R-5c: the legacy request.jwt.claim.* GUC is never freshness');
|
|
470
|
+
-- R-5d cross-class: a local human with a fresh top-level agent_board_step_up_at and even a ledger row.
|
|
471
|
+
select throws_ok(
|
|
472
|
+
format('select pg_temp.step(%L)', pg_temp.c('L', jsonb_build_object('agent_board_step_up_at', pg_temp.ledger('L', pg_temp.now_s() - 9)))),
|
|
473
|
+
'MBS01', 'step_up_required', 'R-5d: a Portal-style claim buys a local human nothing');
|
|
474
|
+
-- R-5e cross-class: a Portal human with a fresh allowlisted amr.
|
|
475
|
+
select throws_ok(
|
|
476
|
+
format('select pg_temp.step(%L)', pg_temp.c('P', jsonb_build_object('amr', jsonb_build_array(jsonb_build_object('method', 'otp', 'timestamp', pg_temp.now_s()))))),
|
|
477
|
+
'MBS01', 'step_up_required', 'R-5e: a fresh amr buys a Portal human nothing');
|
|
478
|
+
-- R-5f (D8): a fresh T with NO ledger row. P's earlier rows are removed first, so a
|
|
479
|
+
-- same-second collision with an earlier fixture's T cannot satisfy the lookup.
|
|
480
|
+
delete from agent_board.portal_step_up_proofs where agent_id = pg_temp.u('P');
|
|
481
|
+
select throws_ok(
|
|
482
|
+
format('select pg_temp.step(%L)', pg_temp.c('P', jsonb_build_object('agent_board_step_up_at', pg_temp.now_s() - 11))),
|
|
483
|
+
'MBS01', 'step_up_required', 'R-5f: a fresh Portal claim without its ledger row is refused');
|
|
484
|
+
-- R-6: T = clock + 31, with a ledger row.
|
|
485
|
+
select throws_ok(
|
|
486
|
+
format('select pg_temp.step(%L)', pg_temp.c('P', jsonb_build_object('agent_board_step_up_at', pg_temp.ledger('P', pg_temp.now_s() + 31)))),
|
|
487
|
+
'MBS01', 'step_up_required', 'R-6: a proof 31 s in the future is refused');
|
|
488
|
+
-- R-7: request.jwt.claims is not JSON (never 22P02).
|
|
489
|
+
select throws_ok(format('select pg_temp.step(%L)', 'not json'),
|
|
490
|
+
'MBS01', 'step_up_required', 'R-7: unparseable claims are MBS01, never 22P02');
|
|
491
|
+
-- R-7: malformed T values (never 22P02/22008/22003).
|
|
492
|
+
select pg_temp.ledger('P', -1);
|
|
493
|
+
select throws_ok(
|
|
494
|
+
format('select pg_temp.step(%L)', pg_temp.c('P', jsonb_build_object('agent_board_step_up_at', t))),
|
|
495
|
+
'MBS01', 'step_up_required', 'R-7: agent_board_step_up_at = ' || t::text || ' is refused without a cast error')
|
|
496
|
+
from unnest(array['"x"'::jsonb, '{}'::jsonb, '[]'::jsonb, '-1'::jsonb, '1e30'::jsonb, '1.5'::jsonb]) t;
|
|
497
|
+
-- R-7b: amr shapes (never 22023/22P02/22008).
|
|
498
|
+
select throws_ok(
|
|
499
|
+
format('select pg_temp.step(%L)', pg_temp.c('L', jsonb_build_object('amr', a))),
|
|
500
|
+
'MBS01', 'step_up_required', 'R-7b: amr = ' || left(a::text, 60) || ' is refused without error')
|
|
501
|
+
from unnest(array[
|
|
502
|
+
'{}'::jsonb, '"x"'::jsonb, '5'::jsonb, '["otp","password"]'::jsonb,
|
|
503
|
+
jsonb_build_array(jsonb_build_object('method', 'otp', 'timestamp', pg_temp.now_s()::text)),
|
|
504
|
+
'[{"method":"otp","timestamp":1e30}]'::jsonb]) a;
|
|
505
|
+
-- R-8: an agent-shaped human (live agent_credential_id), no proof: kind decides.
|
|
506
|
+
select throws_ok(
|
|
507
|
+
format('select pg_temp.step(%L)', pg_temp.c('P', jsonb_build_object('agent_credential_id', pg_temp.v('P.cred')))),
|
|
508
|
+
'MBS01', 'step_up_required', 'R-8: a human with a live credential claim is still a human');
|
|
509
|
+
-- R-14 (D3): relay shape, role service_role with sub = P's auth user, no proof.
|
|
510
|
+
select throws_ok(
|
|
511
|
+
format('select pg_temp.step(%L)', jsonb_build_object('role', 'service_role', 'sub', pg_temp.v('P.auth'))::text),
|
|
512
|
+
'MBS01', 'step_up_required', 'R-14: a relay service_role token carrying a human sub is not the operator');
|
|
513
|
+
-- R-14b (§5.4): relay shape with sub = a suspended human (current_agent_id() is NULL).
|
|
514
|
+
select throws_ok(
|
|
515
|
+
format('select pg_temp.step(%L)', jsonb_build_object('role', 'service_role', 'sub', pg_temp.v('SUS.auth'))::text),
|
|
516
|
+
'MBS01', 'step_up_required', 'R-14b: a relay token whose sub names a suspended human is refused (auth.uid() IS NULL conjunct)');
|
|
517
|
+
-- R-14c: relay shape with sub = an auth user that has no agent row.
|
|
518
|
+
select throws_ok(
|
|
519
|
+
format('select pg_temp.step(%L)', jsonb_build_object('role', 'service_role', 'sub', pg_temp.v('NOAGENT.auth'))::text),
|
|
520
|
+
'MBS01', 'step_up_required', 'R-14c: a relay token whose sub maps to no principal is refused');
|
|
521
|
+
-- §5.1: a NULL actor on a non-service session.
|
|
522
|
+
select throws_ok(format('select pg_temp.step(%L)', pg_temp.c('NOAGENT')),
|
|
523
|
+
'MBS01', 'step_up_required', '§5.1: an authenticated session with no principal is refused');
|
|
524
|
+
-- M15 row: LM's agents.metadata claims a federation; a fresh T with a ledger row (inserted
|
|
525
|
+
-- directly, as the writer would refuse LM) still buys nothing, because metadata is not evidence.
|
|
526
|
+
select throws_ok(
|
|
527
|
+
format('select pg_temp.step(%L)', pg_temp.c('LM', jsonb_build_object('agent_board_step_up_at', pg_temp.ledger('LM', pg_temp.now_s() - 12)))),
|
|
528
|
+
'MBS01', 'step_up_required', 'M15 row: agents.metadata never makes a local human Portal-class');
|
|
529
|
+
-- M14 row: after a 2 s in-transaction wait, a proof clock - 301 is stale. now() would see it
|
|
530
|
+
-- as at most 299 s old (the transaction began earlier).
|
|
531
|
+
select pg_sleep(2);
|
|
532
|
+
select throws_ok(
|
|
533
|
+
format('select pg_temp.step(%L)', pg_temp.c('P', jsonb_build_object('agent_board_step_up_at', pg_temp.ledger('P', pg_temp.now_s() - 301)))),
|
|
534
|
+
'MBS01', 'step_up_required', 'M14 row: freshness is measured on clock_timestamp(), not the transaction start');
|
|
535
|
+
-- §6.1: DETAIL carries the operation name only.
|
|
536
|
+
select is(
|
|
537
|
+
pg_temp.diag(pg_temp.c('P', jsonb_build_object('agent_board_step_up_at', pg_temp.now_s() - 400))),
|
|
538
|
+
'MBS01|step_up_required|grant_board_role',
|
|
539
|
+
'§6.1: the refusal is MBS01 step_up_required with DETAIL = the operation name, never a value');
|
|
540
|
+
|
|
541
|
+
-- ===========================================================================
|
|
542
|
+
-- §9.1 the ledger writer (RP rows)
|
|
543
|
+
-- ===========================================================================
|
|
544
|
+
select pg_temp.put('T0', pg_temp.now_s()::text);
|
|
545
|
+
-- RP-1: a Portal human, T = clock -> true, and the row exists.
|
|
546
|
+
select is(pg_temp.rec('service_role', 'P', pg_temp.v('T0')::bigint), 'true', 'RP-1: service_role records a Portal human''s proof');
|
|
547
|
+
select ok(pg_temp.has_row('P', pg_temp.v('T0')::bigint), 'RP-1 state: the (P, T) row exists');
|
|
548
|
+
-- RP-2: a local human -> false, no row.
|
|
549
|
+
select is(pg_temp.rec('service_role', 'L', pg_temp.v('T0')::bigint), 'false', 'RP-2: a local human''s proof is refused (false)');
|
|
550
|
+
select ok(not pg_temp.has_row('L', pg_temp.v('T0')::bigint), 'RP-2 state: no (L, T) row');
|
|
551
|
+
-- RP-3: an agent -> false.
|
|
552
|
+
select is(pg_temp.rec('service_role', 'G', pg_temp.v('T0')::bigint), 'false', 'RP-3: an agent''s proof is refused (false)');
|
|
553
|
+
-- RP-M15: LM (forged metadata) -> false.
|
|
554
|
+
select is(pg_temp.rec('service_role', 'LM', pg_temp.now_s()), 'false', 'RP-M15: agents.metadata never makes a Portal-class agent for the writer');
|
|
555
|
+
-- RP-4: clock - 331 and clock + 61 lie outside [clock - 330, clock + 60] -> false, no rows.
|
|
556
|
+
-- (now_s + 61 > clock + 60 because clock < now_s + 1; now_s - 331 < clock - 330 because clock >= now_s.)
|
|
557
|
+
select pg_temp.put('T_OLD', (pg_temp.now_s() - 331)::text), pg_temp.put('T_NEW', (pg_temp.now_s() + 61)::text);
|
|
558
|
+
select is(pg_temp.rec('service_role', 'P', pg_temp.v('T_OLD')::bigint), 'false', 'RP-4: a proof older than clock - 330 is refused');
|
|
559
|
+
select is(pg_temp.rec('service_role', 'P', pg_temp.v('T_NEW')::bigint), 'false', 'RP-4: a proof later than clock + 60 is refused');
|
|
560
|
+
select ok(not pg_temp.has_row('P', pg_temp.v('T_OLD')::bigint) and not pg_temp.has_row('P', pg_temp.v('T_NEW')::bigint),
|
|
561
|
+
'RP-4 state: neither out-of-range row was written');
|
|
562
|
+
-- RP-5: inside the range at clock - 300 -> true.
|
|
563
|
+
select is(pg_temp.rec('service_role', 'P', pg_temp.now_s() - 300), 'true', 'RP-5: a proof 300 s old is still recordable');
|
|
564
|
+
-- RP-6: a duplicate is true (on conflict do nothing), one row.
|
|
565
|
+
select is(pg_temp.rec('service_role', 'P', pg_temp.v('T0')::bigint), 'true', 'RP-6: re-recording the same proof is true');
|
|
566
|
+
select is((select count(*)::int from agent_board.portal_step_up_proofs where agent_id = pg_temp.u('P') and proof_at = pg_temp.v('T0')::bigint),
|
|
567
|
+
1, 'RP-6 state: still exactly one (P, T) row');
|
|
568
|
+
-- RP-7: a write prunes THAT agent's rows older than a day, and no one else's.
|
|
569
|
+
select pg_temp.ledger('P', pg_temp.now_s() - 90000), pg_temp.ledger('L', pg_temp.now_s() - 90000);
|
|
570
|
+
select is(pg_temp.rec('service_role', 'P', pg_temp.now_s()), 'true', 'RP-7: a fresh record succeeds');
|
|
571
|
+
select is(
|
|
572
|
+
(select (count(*) filter (where agent_id = pg_temp.u('P')))::text || '/' || (count(*) filter (where agent_id = pg_temp.u('L')))::text
|
|
573
|
+
from agent_board.portal_step_up_proofs where proof_at < pg_temp.now_s() - 86400),
|
|
574
|
+
'0/1',
|
|
575
|
+
'RP-7 state: P''s day-old row is pruned, L''s is untouched');
|
|
576
|
+
-- RP-8: NULL arguments -> false.
|
|
577
|
+
select is(
|
|
578
|
+
(select coalesce(agent_board.record_portal_step_up(null, pg_temp.now_s())::text, '(null)') || '/' ||
|
|
579
|
+
coalesce(agent_board.record_portal_step_up(pg_temp.u('P'), null)::text, '(null)')),
|
|
580
|
+
'false/false', 'RP-8: NULL agent or NULL instant is false');
|
|
581
|
+
-- RP-9: an unknown agent id -> false.
|
|
582
|
+
select is(
|
|
583
|
+
coalesce(agent_board.record_portal_step_up('669a1000-0000-4000-8000-0000000000ff', pg_temp.now_s())::text, '(null)'),
|
|
584
|
+
'false', 'RP-9: an unknown agent is false');
|
|
585
|
+
-- RP-10: no API role can call the writer (42501).
|
|
586
|
+
select is(pg_temp.rec('authenticated', 'P', pg_temp.now_s()), 'ERR 42501:fn', 'RP-10: authenticated cannot execute record_portal_step_up');
|
|
587
|
+
select ok(pg_temp.rec('anon', 'P', pg_temp.now_s()) in ('ERR 42501:fn', 'ERR 42501:schema'),
|
|
588
|
+
'RP-10: anon cannot execute record_portal_step_up (refused on the function, or earlier on the schema)');
|
|
589
|
+
select is(pg_temp.rec('agent_board_delegate', 'P', pg_temp.now_s()), 'ERR 42501:fn', 'RP-10: agent_board_delegate cannot execute record_portal_step_up');
|
|
590
|
+
|
|
591
|
+
-- ===========================================================================
|
|
592
|
+
-- Fix round 1 (S1/S2 review of #800). Appended so every row number above stays stable.
|
|
593
|
+
-- ===========================================================================
|
|
594
|
+
|
|
595
|
+
-- RP-11: clock - 329 is inside the window (now_s - 329 > clock - 330) -> true, and the row exists.
|
|
596
|
+
select pg_temp.put('T_329', (pg_temp.now_s() - 329)::text);
|
|
597
|
+
select is(pg_temp.rec('service_role', 'P', pg_temp.v('T_329')::bigint), 'true', 'RP-11: a proof at clock - 329 is recordable');
|
|
598
|
+
select ok(pg_temp.has_row('P', pg_temp.v('T_329')::bigint), 'RP-11 state: the clock - 329 row exists');
|
|
599
|
+
-- RP-12: now_s + 60 <= clock + 60 -> true, and the row exists.
|
|
600
|
+
select pg_temp.put('T_P60', (pg_temp.now_s() + 60)::text);
|
|
601
|
+
select is(pg_temp.rec('service_role', 'P', pg_temp.v('T_P60')::bigint), 'true', 'RP-12: a proof at clock + 60 is recordable');
|
|
602
|
+
select ok(pg_temp.has_row('P', pg_temp.v('T_P60')::bigint), 'RP-12 state: the clock + 60 row exists');
|
|
603
|
+
-- WR: the writer's window predicate, exact and inclusive, p_now = 1000000. The moving
|
|
604
|
+
-- fractional clock cannot pin -330 against -330.001, so the boundary lives here.
|
|
605
|
+
select is(agent_board._step_up_proof_recordable(1000000 - 329, 1000000), true, 'WR-1: -329 is recordable');
|
|
606
|
+
select is(agent_board._step_up_proof_recordable(1000000 - 330, 1000000), true, 'WR-2: -330 is recordable (inclusive)');
|
|
607
|
+
select is(agent_board._step_up_proof_recordable(1000000 - 330.001, 1000000), false, 'WR-3: -330.001 is not');
|
|
608
|
+
select is(agent_board._step_up_proof_recordable(1000000 - 331, 1000000), false, 'WR-4: -331 is not');
|
|
609
|
+
select is(agent_board._step_up_proof_recordable(1000000 + 60, 1000000), true, 'WR-5: +60 is recordable (inclusive)');
|
|
610
|
+
select is(agent_board._step_up_proof_recordable(1000000 + 60.001, 1000000), false, 'WR-6: +60.001 is not');
|
|
611
|
+
select is(agent_board._step_up_proof_recordable(1000000 + 61, 1000000), false, 'WR-7: +61 is not');
|
|
612
|
+
|
|
613
|
+
-- RP-13 (S2-4): service_role calls the writer with EXACTLY the argument names
|
|
614
|
+
-- supabase/functions/portal-session/deps.ts sends (p_agent_id, p_proof_at), in named
|
|
615
|
+
-- notation, as PostgREST resolves an RPC. A renamed argument fails here; the deno suite pins
|
|
616
|
+
-- the same two names on the deps.ts side (STEPUP RPC-ARGS).
|
|
617
|
+
select pg_temp.put('T_NAMED', pg_temp.now_s()::text);
|
|
618
|
+
select is(
|
|
619
|
+
pg_temp.rec_sql('service_role',
|
|
620
|
+
format('select agent_board.record_portal_step_up(p_agent_id => %L::uuid, p_proof_at => %s::bigint)', pg_temp.v('P'), pg_temp.v('T_NAMED'))),
|
|
621
|
+
'true',
|
|
622
|
+
'RP-13: record_portal_step_up(p_agent_id => ..., p_proof_at => ...) answers service_role with the deps.ts argument names');
|
|
623
|
+
|
|
624
|
+
-- EC-SU-4i (S2-3): the audit columns the class binding reads, and the value it matches.
|
|
625
|
+
select col_type_is('agent_board', 'enrollment_federation_audit', 'agent_id', 'uuid',
|
|
626
|
+
'EC-SU-4i: enrollment_federation_audit.agent_id (read by _step_up_is_portal_human) is uuid');
|
|
627
|
+
select col_type_is('agent_board', 'enrollment_federation_audit', 'mode', 'text',
|
|
628
|
+
'EC-SU-4i: enrollment_federation_audit.mode (read by _step_up_is_portal_human) is text');
|
|
629
|
+
select ok(
|
|
630
|
+
(select count(*) >= 1
|
|
631
|
+
from pg_proc p
|
|
632
|
+
where p.pronamespace = 'agent_board'::regnamespace and p.prokind in ('f', 'p')
|
|
633
|
+
and p.prolang <> (select oid from pg_language where lanname = 'internal')
|
|
634
|
+
and agent_board_test.stripped_body(p.oid) ~ agent_board_test.writes_any_re(array['enrollment_federation_audit'])
|
|
635
|
+
and agent_board_test.stripped_body(p.oid, true) ~ '''fedsession'''),
|
|
636
|
+
'EC-SU-4i: some audit writer still inserts the literal mode ''fedsession'' the class binding matches');
|
|
637
|
+
|
|
638
|
+
-- EC-SU-4h (S1-2 floor b): fn_call_closure scans agent_board only, so no routine in ANY
|
|
639
|
+
-- other persistent schema may name record_portal_step_up (stripped body, literals kept);
|
|
640
|
+
-- counted. Session temp schemas (pg_temp_N) are excluded: they hold this file's own
|
|
641
|
+
-- fixtures and cannot persist a route.
|
|
642
|
+
select is(
|
|
643
|
+
(select coalesce(string_agg(p.oid::regprocedure::text, ' ' order by p.oid::regprocedure::text), '(none)')
|
|
644
|
+
from pg_proc p join pg_namespace n on n.oid = p.pronamespace join pg_language l on l.oid = p.prolang
|
|
645
|
+
where n.nspname <> 'agent_board' and n.nspname !~ '^pg_(toast_)?temp_' and l.lanname not in ('internal', 'c')
|
|
646
|
+
-- literals KEPT (true): a dynamic call carries the writer's name inside a string literal, so
|
|
647
|
+
-- this absence claim must see literals; comments are stripped (a comment cannot call).
|
|
648
|
+
and agent_board_test.stripped_body(p.oid, true) ~* 'record_portal_step_up'),
|
|
649
|
+
'(none)',
|
|
650
|
+
'EC-SU-4h: no routine outside agent_board names record_portal_step_up');
|
|
651
|
+
select ok(
|
|
652
|
+
(select count(*) > 100 from pg_proc p join pg_namespace n on n.oid = p.pronamespace
|
|
653
|
+
where n.nspname not in ('agent_board', 'pg_catalog', 'information_schema') and coalesce(p.prosrc, '') <> ''),
|
|
654
|
+
'EC-SU-4h control: the cross-schema scan inspected more than 100 non-agent_board routines');
|
|
655
|
+
|
|
656
|
+
-- EC-SU-4d (S1-2 floor a): the closure cannot see dynamic EXECUTE. The API-executable
|
|
657
|
+
-- SECURITY DEFINER routines in EVERY schema whose bodies can run dynamic SQL (plpgsql with an
|
|
658
|
+
-- EXECUTE outside literals and comments, or any procedural language other than sql/plpgsql)
|
|
659
|
+
-- are an EXACT, assessed set (plans/evidence/669/README.md, "dynamic EXECUTE inventory").
|
|
660
|
+
-- A new one names itself here and must be assessed for reaching record_portal_step_up.
|
|
661
|
+
select is(
|
|
662
|
+
(select coalesce(string_agg(p.oid::regprocedure::text, ' ' order by p.oid::regprocedure::text), '(none)')
|
|
663
|
+
from pg_proc p join pg_namespace n on n.oid = p.pronamespace join pg_language l on l.oid = p.prolang
|
|
664
|
+
where p.prosecdef and l.lanname not in ('sql', 'internal', 'c') and n.nspname not in ('pg_catalog', 'information_schema')
|
|
665
|
+
and exists (select 1 from unnest(array['anon', 'authenticated', 'agent_board_delegate']) r where has_function_privilege(r, p.oid, 'EXECUTE'))
|
|
666
|
+
and (l.lanname <> 'plpgsql' or agent_board_test.stripped_body(p.oid) ~ agent_board_test.re(agent_board_test.lead_guard() || agent_board_test.ci_re('execute') || agent_board_test.trail_guard()))),
|
|
667
|
+
'(none)',
|
|
668
|
+
'EC-SU-4d: no API-executable SECURITY DEFINER routine in any schema can run dynamic SQL');
|
|
669
|
+
|
|
670
|
+
-- EC-SU-4d (closure half): no API-executable agent_board root statically reaches an agent_board
|
|
671
|
+
-- routine that runs dynamic SQL (whatever that routine's own grants).
|
|
672
|
+
select is(
|
|
673
|
+
(select coalesce(string_agg(distinct c.root_oid::regprocedure::text, ' ' order by c.root_oid::regprocedure::text), '(none)')
|
|
674
|
+
from _cl c join pg_proc d on d.oid = c.reached_oid join pg_language l on l.oid = d.prolang
|
|
675
|
+
where l.lanname = 'plpgsql' and agent_board_test.stripped_body(d.oid) ~ agent_board_test.re(agent_board_test.lead_guard() || agent_board_test.ci_re('execute') || agent_board_test.trail_guard())
|
|
676
|
+
and exists (select 1 from unnest(array['anon', 'authenticated', 'agent_board_delegate']) r where has_function_privilege(r, c.root_oid, 'EXECUTE'))),
|
|
677
|
+
'(none)',
|
|
678
|
+
'EC-SU-4d: no API-executable agent_board routine reaches a dynamic-EXECUTE routine through its call closure');
|
|
679
|
+
|
|
680
|
+
-- EC-SU-4d (cross-schema half): no agent_board routine names, schema-qualified, a routine in
|
|
681
|
+
-- another schema that runs dynamic SQL (the invoker-language pgTAP, realtime and storage
|
|
682
|
+
-- helpers). Such a call from an agent_board SECURITY DEFINER would run that dynamic SQL as
|
|
683
|
+
-- the definer's owner. Floor: an unqualified call resolved through search_path is not seen;
|
|
684
|
+
-- agent_board routines pin search_path to '' or agent_board[, public].
|
|
685
|
+
select is(
|
|
686
|
+
(select coalesce(string_agg(distinct a.oid::regprocedure::text || '->' || d.oid::regprocedure::text, ' '
|
|
687
|
+
order by a.oid::regprocedure::text || '->' || d.oid::regprocedure::text), '(none)')
|
|
688
|
+
from pg_proc d join pg_namespace dn on dn.oid = d.pronamespace join pg_language dl on dl.oid = d.prolang
|
|
689
|
+
join pg_proc a on a.pronamespace = 'agent_board'::regnamespace and a.prokind in ('f', 'p')
|
|
690
|
+
and a.prolang <> (select oid from pg_language where lanname = 'internal')
|
|
691
|
+
where dn.nspname not in ('agent_board', 'pg_catalog', 'information_schema') and dl.lanname = 'plpgsql'
|
|
692
|
+
and agent_board_test.stripped_body(d.oid) ~ agent_board_test.re(agent_board_test.lead_guard() || agent_board_test.ci_re('execute') || agent_board_test.trail_guard())
|
|
693
|
+
and (strpos(lower(agent_board_test.stripped_body(a.oid)), lower(dn.nspname || '.' || d.proname || '(')) > 0
|
|
694
|
+
or strpos(lower(agent_board_test.stripped_body(a.oid)), lower(dn.nspname || '."' || d.proname || '"(')) > 0)),
|
|
695
|
+
'(none)',
|
|
696
|
+
'EC-SU-4d: no agent_board routine calls a dynamic-EXECUTE routine in another schema');
|
|
697
|
+
|
|
698
|
+
-- EC-SU-4d control: the detector is not vacuous. Over ALL grants and schemas, the SECURITY
|
|
699
|
+
-- DEFINER routines that run dynamic SQL are exactly this set (measured run 42575487045; about
|
|
700
|
+
-- fifty SECURITY INVOKER ones exist too, in extensions/realtime/storage/agent_board, and run
|
|
701
|
+
-- with the caller's privileges, which never include EXECUTE on the writer, EC-SU-5).
|
|
702
|
+
select is(
|
|
703
|
+
(select coalesce(string_agg(p.oid::regprocedure::text, ' ' order by p.oid::regprocedure::text), '(none)')
|
|
704
|
+
from pg_proc p join pg_namespace n on n.oid = p.pronamespace join pg_language l on l.oid = p.prolang
|
|
705
|
+
where p.prosecdef and l.lanname = 'plpgsql' and n.nspname not in ('pg_catalog', 'information_schema')
|
|
706
|
+
and agent_board_test.stripped_body(p.oid) ~ agent_board_test.re(agent_board_test.lead_guard() || agent_board_test.ci_re('execute') || agent_board_test.trail_guard())),
|
|
707
|
+
'agent_board.mark_retention_metadata(text,timestamp with time zone,uuid,text)'::regprocedure::text,
|
|
708
|
+
'EC-SU-4d control: the dynamic-EXECUTE detector finds exactly the one SECURITY DEFINER routine that has it (service_role only)');
|
|
709
|
+
|
|
710
|
+
select * from finish();
|
|
711
|
+
rollback;
|