Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

GBRA-218 (A2): v282 enables row-level security on its folder-rule tables

garrytanbd099964c8ff
diff --git a/src/core/schema-migrations/v282-folder-access-rules.ts b/src/core/schema-migrations/v282-folder-access-rules.ts
index 540e0a4348..0e6fa791b9 100644
--- a/src/core/schema-migrations/v282-folder-access-rules.ts
+++ b/src/core/schema-migrations/v282-folder-access-rules.ts
@@ -143,5 +143,14 @@ CREATE TRIGGER access_rules_mark_restricted AFTER INSERT ON access_rules
DROP TRIGGER IF EXISTS access_pending_coverage_mark_restricted ON access_pending_coverage;
CREATE TRIGGER access_pending_coverage_mark_restricted AFTER INSERT ON access_pending_coverage
FOR EACH ROW EXECUTE FUNCTION gbrain_access_mark_restricted();
+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_policy_state ENABLE ROW LEVEL SECURITY;
+ ALTER TABLE access_rules ENABLE ROW LEVEL SECURITY;
+ ALTER TABLE access_policy_revisions ENABLE ROW LEVEL SECURITY;
+ ALTER TABLE access_pending_coverage ENABLE ROW LEVEL SECURITY;
+ ALTER TABLE access_policy_migrations 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.json
index 37231ad14c..3a4d0c53ca 100644
--- a/test/fixtures/goldens/catalog/pglite-engine-init-default.json
+++ b/test/fixtures/goldens/catalog/pglite-engine-init-default.json
@@ -1724,7 +1724,7 @@
"5 detail jsonb/jsonb NULL",
"6 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_policy_migrations": {
"columns": [
@@ -1736,7 +1736,7 @@
"6 created_at timestamp with time zone/timestamptz NOT NULL DEFAULT now()",
"7 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_policy_revisions": {
"columns": [
@@ -1753,14 +1753,14 @@
"11 applied_at timestamp with time zone/timestamptz NULL",
"12 approved_at timestamp with time zone/timestamptz NULL"
],
- "flags": "relkind=r rls=false force_rls=false"
+ "flags": "relkind=r rls=true force_rls=false"
},
"access_policy_state": {
"columns": [
"1 source_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_rules": {
"columns": [
@@ -1772,7 +1772,7 @@
"6 created_at timestamp with time zone/timestamptz NOT NULL DEFAULT now()",
"7 created_by text/text NULL"
],
- "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.json
index 5a7937836f..93c5fdf920 100644
--- a/test/fixtures/goldens/catalog/pglite-engine-init-fts-portuguese.json
+++ b/test/fixtures/goldens/catalog/pglite-engine-init-fts-portuguese.json
@@ -1724,7 +1724,7 @@
"5 detail jsonb/jsonb NULL",
"6 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_policy_migrations": {
"columns": [
@@ -1736,7 +1736,7 @@
"6 created_at timestamp with time zone/timestamptz NOT NULL DEFAULT now()",
"7 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_policy_revisions": {
"columns": [
@@ -1753,14 +1753,14 @@
"11 applied_at timestamp with time zone/timestamptz NULL",
"12 approved_at timestamp with time zone/timestamptz NULL"
],
- "flags": "relkind=r rls=false force_rls=false"
+ "flags": "relkind=r rls=true force_rls=false"
},
"access_policy_state": {
"columns": [
"1 source_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_rules": {
"columns": [
@@ -1772,7 +1772,7 @@
"6 created_at timestamp with time zone/timestamptz NOT NULL DEFAULT now()",
"7 created_by text/text NULL"
],
- "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.json
index b40cf14aac..f6c22dfcca 100644
--- a/test/fixtures/goldens/catalog/pglite-engine-init-high-dims.json
+++ b/test/fixtures/goldens/catalog/pglite-engine-init-high-dims.json
@@ -1720,7 +1720,7 @@
"5 detail jsonb/jsonb NULL",
"6 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_policy_migrations": {
"columns": [
@@ -1732,7 +1732,7 @@
"6 created_at timestamp with time zone/timestamptz NOT NULL DEFAULT now()",
"7 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_policy_revisions": {
"columns": [
@@ -1749,14 +1749,14 @@
"11 applied_at timestamp with time zone/timestamptz NULL",
"12 approved_at timestamp with time zone/timestamptz NULL"
],
- "flags": "relkind=r rls=false force_rls=false"
+ "flags": "relkind=r rls=true force_rls=false"
},
"access_policy_state": {
"columns": [
"1 source_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_rules": {
"columns": [
@@ -1768,7 +1768,7 @@
"6 created_at timestamp with time zone/timestamptz NOT NULL DEFAULT now()",
"7 created_by text/text NULL"
],
- "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/pglite-upgrade-replay/catalog-after-boot.json b/test/fixtures/goldens/pglite-upgrade-replay/catalog-after-boot.json
index ec097193f8..ff2740fcfe 100644
--- a/test/fixtures/goldens/pglite-upgrade-replay/catalog-after-boot.json
+++ b/test/fixtures/goldens/pglite-upgrade-replay/catalog-after-boot.json
@@ -1724,7 +1724,7 @@
"5 detail jsonb/jsonb NULL",
"6 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_policy_migrations": {
"columns": [
@@ -1736,7 +1736,7 @@
"6 created_at timestamp with time zone/timestamptz NOT NULL DEFAULT now()",
"7 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_policy_revisions": {
"columns": [
@@ -1753,14 +1753,14 @@
"11 applied_at timestamp with time zone/timestamptz NULL",
"12 approved_at timestamp with time zone/timestamptz NULL"
],
- "flags": "relkind=r rls=false force_rls=false"
+ "flags": "relkind=r rls=true force_rls=false"
},
"access_policy_state": {
"columns": [
"1 source_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_rules": {
"columns": [
@@ -1772,7 +1772,7 @@
"6 created_at timestamp with time zone/timestamptz NOT NULL DEFAULT now()",
"7 created_by text/text NULL"
],
- "flags": "relkind=r rls=false force_rls=false"
+ "flags": "relkind=r rls=true force_rls=false"
},
"access_tokens": {
"columns": [