Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(access): v281 enables row-level security on the member tables
garrytan0e5eef8acdb7
diff --git a/src/core/schema-migrations/v281-member-read-access.ts b/src/core/schema-migrations/v281-member-read-access.tsindex 1302052b18..a23ee1d387 100644--- a/src/core/schema-migrations/v281-member-read-access.ts+++ b/src/core/schema-migrations/v281-member-read-access.ts@@ -125,5 +125,12 @@ INSERT INTO config (key, value)SELECT 'access.restrictions_present', '1'WHERE EXISTS (SELECT 1 FROM pages WHERE frontmatter ? 'readable_by') OR EXISTS (SELECT 1 FROM access_members)ON CONFLICT (key) DO UPDATE SET value = '1';+DO $rls$ BEGIN+ IF EXISTS (SELECT 1 FROM pg_roles pr WHERE pg_has_role(current_user, pr.oid, 'USAGE') AND (pr.rolbypassrls OR pr.rolsuper)) THEN+ ALTER TABLE access_members ENABLE ROW LEVEL SECURITY;+ ALTER TABLE access_groups ENABLE ROW LEVEL SECURITY;+ ALTER TABLE access_group_members ENABLE ROW LEVEL SECURITY;+ END IF;+END $rls$;`,};diff --git a/test/fixtures/goldens/catalog/pglite-engine-init-default.json b/test/fixtures/goldens/catalog/pglite-engine-init-default.jsonindex efedf56bd5..c9fc2d764d 100644--- a/test/fixtures/goldens/catalog/pglite-engine-init-default.json+++ b/test/fixtures/goldens/catalog/pglite-engine-init-default.json@@ -1652,14 +1652,14 @@"1 group_id text/text NOT NULL","2 member_id text/text NOT NULL"],- "flags": "relkind=r rls=false force_rls=false"+ "flags": "relkind=r rls=true force_rls=false"},"access_groups": {"columns": ["1 id text/text NOT NULL","2 created_at timestamp with time zone/timestamptz NOT NULL DEFAULT now()"],- "flags": "relkind=r rls=false force_rls=false"+ "flags": "relkind=r rls=true force_rls=false"},"access_members": {"columns": [@@ -1670,7 +1670,7 @@"5 created_at timestamp with time zone/timestamptz NOT NULL DEFAULT now()","6 updated_at timestamp with time zone/timestamptz NOT NULL DEFAULT now()"],- "flags": "relkind=r rls=false force_rls=false"+ "flags": "relkind=r rls=true force_rls=false"},"access_tokens": {"columns": [diff --git a/test/fixtures/goldens/catalog/pglite-engine-init-fts-portuguese.json b/test/fixtures/goldens/catalog/pglite-engine-init-fts-portuguese.jsonindex 16d565bb4a..cc2e56f060 100644--- a/test/fixtures/goldens/catalog/pglite-engine-init-fts-portuguese.json+++ b/test/fixtures/goldens/catalog/pglite-engine-init-fts-portuguese.json@@ -1652,14 +1652,14 @@"1 group_id text/text NOT NULL","2 member_id text/text NOT NULL"],- "flags": "relkind=r rls=false force_rls=false"+ "flags": "relkind=r rls=true force_rls=false"},"access_groups": {"columns": ["1 id text/text NOT NULL","2 created_at timestamp with time zone/timestamptz NOT NULL DEFAULT now()"],- "flags": "relkind=r rls=false force_rls=false"+ "flags": "relkind=r rls=true force_rls=false"},"access_members": {"columns": [@@ -1670,7 +1670,7 @@"5 created_at timestamp with time zone/timestamptz NOT NULL DEFAULT now()","6 updated_at timestamp with time zone/timestamptz NOT NULL DEFAULT now()"],- "flags": "relkind=r rls=false force_rls=false"+ "flags": "relkind=r rls=true force_rls=false"},"access_tokens": {"columns": [diff --git a/test/fixtures/goldens/catalog/pglite-engine-init-high-dims.json b/test/fixtures/goldens/catalog/pglite-engine-init-high-dims.jsonindex 5097b6312d..e0fc703f4f 100644--- a/test/fixtures/goldens/catalog/pglite-engine-init-high-dims.json+++ b/test/fixtures/goldens/catalog/pglite-engine-init-high-dims.json@@ -1648,14 +1648,14 @@"1 group_id text/text NOT NULL","2 member_id text/text NOT NULL"],- "flags": "relkind=r rls=false force_rls=false"+ "flags": "relkind=r rls=true force_rls=false"},"access_groups": {"columns": ["1 id text/text NOT NULL","2 created_at timestamp with time zone/timestamptz NOT NULL DEFAULT now()"],- "flags": "relkind=r rls=false force_rls=false"+ "flags": "relkind=r rls=true force_rls=false"},"access_members": {"columns": [@@ -1666,7 +1666,7 @@"5 created_at timestamp with time zone/timestamptz NOT NULL DEFAULT now()","6 updated_at timestamp with time zone/timestamptz NOT NULL DEFAULT now()"],- "flags": "relkind=r rls=false force_rls=false"+ "flags": "relkind=r rls=true force_rls=false"},"access_tokens": {"columns": [diff --git a/test/fixtures/goldens/migrations/records.json b/test/fixtures/goldens/migrations/records.jsonindex 1afa04699e..12ed33d87d 100644--- a/test/fixtures/goldens/migrations/records.json+++ b/test/fixtures/goldens/migrations/records.json@@ -4550,8 +4550,8 @@"idempotent": true,"name": "member_read_access","sql": {- "length": 5992,- "sha256": "717b58dd097275d8a5116be7fbe7c6920452d25ad01cac17c019f35b2ee91add"+ "length": 6338,+ "sha256": "482913b07ebd9603c0cd04329ae5f15d9d26e85bae3fa527ec7bf03b025ea0b3"},"sqlFor": "absent","transaction": "absent",diff --git a/test/fixtures/goldens/pglite-upgrade-replay/catalog-after-boot.json b/test/fixtures/goldens/pglite-upgrade-replay/catalog-after-boot.jsonindex d388d48b8b..1659a74967 100644--- a/test/fixtures/goldens/pglite-upgrade-replay/catalog-after-boot.json+++ b/test/fixtures/goldens/pglite-upgrade-replay/catalog-after-boot.json@@ -1652,14 +1652,14 @@"1 group_id text/text NOT NULL","2 member_id text/text NOT NULL"],- "flags": "relkind=r rls=false force_rls=false"+ "flags": "relkind=r rls=true force_rls=false"},"access_groups": {"columns": ["1 id text/text NOT NULL","2 created_at timestamp with time zone/timestamptz NOT NULL DEFAULT now()"],- "flags": "relkind=r rls=false force_rls=false"+ "flags": "relkind=r rls=true force_rls=false"},"access_members": {"columns": [@@ -1670,7 +1670,7 @@"5 created_at timestamp with time zone/timestamptz NOT NULL DEFAULT now()","6 updated_at timestamp with time zone/timestamptz NOT NULL DEFAULT now()"],- "flags": "relkind=r rls=false force_rls=false"+ "flags": "relkind=r rls=true force_rls=false"},"access_tokens": {"columns": [