Fresh security audit PASS; verifier ECARTS(10) addressed: - publish re-checks the approver's sheet_reviewer grant (publish.approval.invalid) - scope disclaimer enforced at approve and publish (publish.disclaimer.missing, O6) - to_confirm split from inherited (publish.to_confirm.open distinct from publish.inherited.present) - save_sheet_draft requires an active sheet; working copy adds the 2 MiB octet_length check - delete_sheet_asset EXECUTE revoked from service_role (§5.4 surface) - species table comment updated (§7.2); lease columns dropped from the reviews grant - lock order sheet->version->round in decide/publish; conflict_retry kind (40001/40P01) in sheets.ts Tests: pgTAP 016 (omitted status, separation, revoked-reviewer + renewal, ack carry, inactive-species publish refusal, deprecated-delete, schema_version 1, content-write without actor, working-copy positive), 001 census (no other writer of profile_roles). 871 real-stack pgTAP / 122 PGlite / 4 sandbox green; typecheck, lint, types drift clean.
84 lines
4.6 KiB
PL/PgSQL
84 lines
4.6 KiB
PL/PgSQL
-- Schema contract: objects exist, RLS is on, API roles start from zero.
|
|
begin;
|
|
select plan(27);
|
|
|
|
-- Schemas
|
|
select has_schema('private', 'schema private exists');
|
|
select has_schema('audit', 'schema audit exists');
|
|
|
|
-- Tables
|
|
select has_table('public', 'profiles', 'table public.profiles exists');
|
|
select has_table('public', 'profile_roles', 'table public.profile_roles exists');
|
|
select has_table('audit', 'audit_logs', 'table audit.audit_logs exists');
|
|
|
|
-- RLS enabled everywhere (pgTAP has no helper: read pg_class)
|
|
select ok(
|
|
(select relrowsecurity from pg_class where oid = 'public.profiles'::regclass),
|
|
'RLS enabled on profiles'
|
|
);
|
|
select ok(
|
|
(select relrowsecurity from pg_class where oid = 'public.profile_roles'::regclass),
|
|
'RLS enabled on profile_roles'
|
|
);
|
|
select ok(
|
|
(select relrowsecurity from pg_class where oid = 'audit.audit_logs'::regclass),
|
|
'RLS enabled on audit_logs'
|
|
);
|
|
|
|
-- Enum
|
|
select enum_has_labels(
|
|
'public', 'platform_role',
|
|
array['owner', 'admin', 'moderator', 'support'],
|
|
'platform_role has exactly the four platform roles (no professional status)'
|
|
);
|
|
|
|
-- Functions
|
|
select has_function('private', 'log_event', 'private.log_event exists');
|
|
select has_function('private', 'is_platform_owner', array['uuid'], 'private.is_platform_owner exists');
|
|
select has_function('private', 'is_platform_admin', array['uuid'], 'private.is_platform_admin exists');
|
|
select has_function('private', 'is_platform_moderator', array['uuid'], 'private.is_platform_moderator exists');
|
|
select has_function('private', 'is_support', array['uuid'], 'private.is_support exists');
|
|
select has_function('public', 'grant_platform_role', array['uuid', 'platform_role'], 'public.grant_platform_role exists');
|
|
select has_function('public', 'revoke_platform_role', array['uuid', 'platform_role', 'text'], 'public.revoke_platform_role exists');
|
|
|
|
-- Privileges: anon has nothing, authenticated has only what RLS then filters
|
|
select ok(not has_table_privilege('anon', 'public.profiles', 'select'), 'anon cannot select profiles');
|
|
select ok(not has_table_privilege('anon', 'public.profile_roles', 'select'), 'anon cannot select profile_roles');
|
|
select ok(not has_table_privilege('authenticated', 'public.profiles', 'insert'), 'authenticated cannot insert profiles');
|
|
select ok(not has_table_privilege('authenticated', 'public.profiles', 'delete'), 'authenticated cannot delete profiles');
|
|
select ok(not has_table_privilege('authenticated', 'public.profile_roles', 'insert'), 'authenticated cannot insert profile_roles');
|
|
select ok(not has_column_privilege('authenticated', 'public.profiles', 'active', 'update'), 'authenticated cannot update profiles.active');
|
|
select ok(not has_schema_privilege('anon', 'private', 'usage'), 'anon has no usage on schema private');
|
|
select ok(not has_function_privilege('anon', 'public.grant_platform_role(uuid, public.platform_role)', 'execute'), 'anon cannot execute grant_platform_role');
|
|
|
|
-- Private helpers: EXECUTE revoked from everyone except the predicates the policies evaluate.
|
|
-- (has_function_privilege is true for any role while proacl is null, i.e. the built-in PUBLIC default.)
|
|
select is(
|
|
(select count(*) from pg_proc p join pg_namespace n on n.oid = p.pronamespace
|
|
where n.nspname in ('private', 'audit') and has_function_privilege('anon', p.oid, 'execute')),
|
|
0::bigint, 'anon can execute nothing in private/audit'
|
|
);
|
|
select is(
|
|
(select string_agg(p.proname::text, ',' order by p.proname::text collate "C")
|
|
from pg_proc p join pg_namespace n on n.oid = p.pronamespace
|
|
where n.nspname in ('private', 'audit') and has_function_privilege('authenticated', p.oid, 'execute')),
|
|
'asset_in_catalog_version,caller_can_see_official_sheet,caller_is_catalog_staff,caller_workspace_ids,can_read_avatar_object,can_read_catalog_sheet,can_read_sheet_asset_object,can_upload_avatar_object,can_upload_sheet_asset_object,fold_text,has_mfa,has_platform_role,is_platform_admin,is_platform_moderator,is_platform_owner,is_support',
|
|
'authenticated executes only the policy predicates in private'
|
|
);
|
|
|
|
-- No write path to profile_roles other than the two private writers (§16.2,
|
|
-- §5.7 inventory). prosrc of every function is scanned for an insert/update/
|
|
-- delete on public.profile_roles; reads (has_platform_role, the owner count)
|
|
-- are excluded.
|
|
select is(
|
|
(select string_agg(p.proname::text, ',' order by p.proname::text collate "C")
|
|
from pg_proc p join pg_namespace n on n.oid = p.pronamespace
|
|
where n.nspname in ('public', 'private')
|
|
and p.prosrc ~ '(insert into|update|delete from)\s+public\.profile_roles'),
|
|
'assign_platform_role,withdraw_platform_role',
|
|
'only assign_platform_role / withdraw_platform_role write profile_roles'
|
|
);
|
|
|
|
select * from finish();
|
|
rollback;
|