Refresh HiveGrid Cloud reference snapshot
This commit is contained in:
1 parent
5e99e14772
commit
7f88026f79
5955 files changed
+1177325
-188362
No files matched your search
@@ -7,7 +7,7 @@
|
||||
--
|
||||
-- IMPORTANT: `App` is a GLOBAL catalog table (no tenantId) → NO policy, NO RLS.
|
||||
-- Only the tenant-scoped rows are isolated: DataConnection, AppSyncRun,
|
||||
-- AppSyncRunLog, AppSyncItem.
|
||||
-- AppSyncRunLog, AppSyncItem, AppEntityBinding.
|
||||
--
|
||||
-- WHY DEFERRED: with RLS + FORCE on, any query WITHOUT `app.tenant_id` returns
|
||||
-- ZERO rows. The dataConnection/appSync services always scope by
|
||||
@@ -27,7 +27,7 @@ DO $$
|
||||
DECLARE
|
||||
tbl text;
|
||||
BEGIN
|
||||
FOREACH tbl IN ARRAY ARRAY['DataConnection', 'AppSyncRun', 'AppSyncRunLog', 'AppSyncItem']
|
||||
FOREACH tbl IN ARRAY ARRAY['DataConnection', 'AppSyncRun', 'AppSyncRunLog', 'AppSyncItem', 'AppEntityBinding']
|
||||
LOOP
|
||||
EXECUTE format('ALTER TABLE %I ENABLE ROW LEVEL SECURITY;', tbl);
|
||||
EXECUTE format('ALTER TABLE %I FORCE ROW LEVEL SECURITY;', tbl);
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
-- R-P12a Automation isolation artifact.
|
||||
-- Companion to prisma/rls/tenant-isolation.sql. Enable during the merge
|
||||
-- migration once the schema lands and the automation service has shipped.
|
||||
-- Global template catalog writes must run through a separately privileged
|
||||
-- deploy/seed path. The tenant runtime may read global templates, but may only
|
||||
-- create, update, or delete rows belonging to its active tenant.
|
||||
--
|
||||
-- Verification:
|
||||
-- psql "$DIRECT_URL" -f prisma/rls/automation-isolation.sql
|
||||
@@ -49,9 +52,27 @@ ALTER TABLE "AutomationTemplate" ENABLE ROW LEVEL SECURITY;
|
||||
ALTER TABLE "AutomationTemplate" FORCE ROW LEVEL SECURITY;
|
||||
|
||||
DROP POLICY IF EXISTS "tenant_isolation_automation_template" ON "AutomationTemplate";
|
||||
CREATE POLICY "tenant_isolation_automation_template" ON "AutomationTemplate"
|
||||
USING ("tenantId" IS NULL OR "tenantId" = current_setting('app.tenant_id', true))
|
||||
WITH CHECK ("tenantId" IS NULL OR "tenantId" = current_setting('app.tenant_id', true));
|
||||
DROP POLICY IF EXISTS "tenant_isolation_automation_template_select" ON "AutomationTemplate";
|
||||
DROP POLICY IF EXISTS "tenant_isolation_automation_template_insert" ON "AutomationTemplate";
|
||||
DROP POLICY IF EXISTS "tenant_isolation_automation_template_update" ON "AutomationTemplate";
|
||||
DROP POLICY IF EXISTS "tenant_isolation_automation_template_delete" ON "AutomationTemplate";
|
||||
|
||||
CREATE POLICY "tenant_isolation_automation_template_select" ON "AutomationTemplate"
|
||||
FOR SELECT
|
||||
USING ("tenantId" IS NULL OR "tenantId" = current_setting('app.tenant_id', true));
|
||||
|
||||
CREATE POLICY "tenant_isolation_automation_template_insert" ON "AutomationTemplate"
|
||||
FOR INSERT
|
||||
WITH CHECK ("tenantId" = current_setting('app.tenant_id', true));
|
||||
|
||||
CREATE POLICY "tenant_isolation_automation_template_update" ON "AutomationTemplate"
|
||||
FOR UPDATE
|
||||
USING ("tenantId" = current_setting('app.tenant_id', true))
|
||||
WITH CHECK ("tenantId" = current_setting('app.tenant_id', true));
|
||||
|
||||
CREATE POLICY "tenant_isolation_automation_template_delete" ON "AutomationTemplate"
|
||||
FOR DELETE
|
||||
USING ("tenantId" = current_setting('app.tenant_id', true));
|
||||
|
||||
ALTER TABLE "AutomationTriggerMeter" ENABLE ROW LEVEL SECURITY;
|
||||
ALTER TABLE "AutomationTriggerMeter" FORCE ROW LEVEL SECURITY;
|
||||
@@ -60,3 +81,17 @@ DROP POLICY IF EXISTS "tenant_isolation_automation_trigger_meter" ON "Automation
|
||||
CREATE POLICY "tenant_isolation_automation_trigger_meter" ON "AutomationTriggerMeter"
|
||||
USING ("tenantId" = current_setting('app.tenant_id', true))
|
||||
WITH CHECK ("tenantId" = current_setting('app.tenant_id', true));
|
||||
|
||||
GRANT SELECT, INSERT, UPDATE, DELETE ON "AutomationRule" TO hivegrid_app;
|
||||
GRANT SELECT, INSERT, UPDATE, DELETE ON "AutomationRuleStep" TO hivegrid_app;
|
||||
GRANT SELECT, INSERT, UPDATE, DELETE ON "AutomationExecution" TO hivegrid_app;
|
||||
GRANT SELECT, INSERT, UPDATE, DELETE ON "AutomationStepExecution" TO hivegrid_app;
|
||||
GRANT SELECT, INSERT, UPDATE, DELETE ON "AutomationCredential" TO hivegrid_app;
|
||||
GRANT SELECT, INSERT, UPDATE, DELETE ON "AutomationTemplate" TO hivegrid_app;
|
||||
GRANT SELECT, INSERT, UPDATE, DELETE ON "AutomationTriggerMeter" TO hivegrid_app;
|
||||
|
||||
-- Inverse per table:
|
||||
-- REVOKE SELECT, INSERT, UPDATE, DELETE ON "<table>" FROM hivegrid_app;
|
||||
-- DROP POLICY IF EXISTS "<policy>" ON "<table>";
|
||||
-- ALTER TABLE "<table>" NO FORCE ROW LEVEL SECURITY;
|
||||
-- ALTER TABLE "<table>" DISABLE ROW LEVEL SECURITY;
|
||||
@@ -1,11 +1,15 @@
|
||||
-- AK-P16b · P16 Booking — HARD DOUBLE-BOOKING GUARD (deferred, NOT in the Prisma schema)
|
||||
-- AK-P16b · P16 Booking — HARD DOUBLE-BOOKING GUARD (NOT in the Prisma schema)
|
||||
-- =============================================================================
|
||||
-- SHIPPED: since 20260717090000_ak_p16b_booking_overlap_constraint this
|
||||
-- constraint is part of the tracked migration chain (that migration is the
|
||||
-- authoritative copy, incl. a pre-flight overlap check). This file remains the
|
||||
-- feature-branch template for `psql -f` on db-push-only databases.
|
||||
--
|
||||
-- The race-protection backstop for DoD 2: a PostgreSQL EXCLUDE USING gist
|
||||
-- constraint that makes it physically impossible to persist two OVERLAPPING active
|
||||
-- appointments for the SAME provider. This cannot be expressed in the Prisma schema
|
||||
-- (Prisma has no exclusion-constraint primitive), so — like the RLS block — it
|
||||
-- ships out-of-band: `psql -f` on the feature branch, folded into the merge
|
||||
-- migration at main-merge (AD-21).
|
||||
-- appointments for the SAME provider WITHIN A TENANT (tenant-scoped like the
|
||||
-- slot engine; tenant-agnostic would leak cross-tenant busy state). This cannot be expressed in the Prisma schema
|
||||
-- (Prisma has no exclusion-constraint primitive), so it stays raw SQL.
|
||||
--
|
||||
-- This is the second layer. The first layer is the application Serializable
|
||||
-- transaction in BookingSubmitService that re-checks slot availability and returns
|
||||
@@ -24,7 +28,7 @@
|
||||
-- -- (leave btree_gist installed; other modules may rely on it)
|
||||
-- =============================================================================
|
||||
|
||||
-- gist over a scalar (providerUserId) + a range (tstzrange) needs the btree_gist
|
||||
-- gist over a scalar (providerUserId) + a range (tsrange) needs the btree_gist
|
||||
-- extension to put the equality column into the same gist index.
|
||||
CREATE EXTENSION IF NOT EXISTS btree_gist;
|
||||
|
||||
@@ -40,8 +44,9 @@ BEGIN
|
||||
ALTER TABLE "Appointment"
|
||||
ADD CONSTRAINT appointment_no_overlap
|
||||
EXCLUDE USING gist (
|
||||
"tenantId" WITH =,
|
||||
"providerUserId" WITH =,
|
||||
tstzrange("startAt", "endAt", ''[)'') WITH &&
|
||||
tsrange("startAt", "endAt", ''[)'') WITH &&
|
||||
)
|
||||
WHERE (status IN (''scheduled'', ''held''))
|
||||
';
|
||||
|
||||
@@ -28,3 +28,13 @@ DROP POLICY IF EXISTS "tenant_isolation_widget_instance" ON "WidgetInstance";
|
||||
CREATE POLICY "tenant_isolation_widget_instance" ON "WidgetInstance"
|
||||
USING ("tenantId" = current_setting('app.tenant_id', true))
|
||||
WITH CHECK ("tenantId" = current_setting('app.tenant_id', true));
|
||||
|
||||
GRANT SELECT, INSERT, UPDATE, DELETE ON "Dashboard" TO hivegrid_app;
|
||||
GRANT SELECT, INSERT, UPDATE, DELETE ON "DashboardLayout" TO hivegrid_app;
|
||||
GRANT SELECT, INSERT, UPDATE, DELETE ON "WidgetInstance" TO hivegrid_app;
|
||||
|
||||
-- Inverse per table:
|
||||
-- REVOKE SELECT, INSERT, UPDATE, DELETE ON "<table>" FROM hivegrid_app;
|
||||
-- DROP POLICY IF EXISTS "<policy>" ON "<table>";
|
||||
-- ALTER TABLE "<table>" NO FORCE ROW LEVEL SECURITY;
|
||||
-- ALTER TABLE "<table>" DISABLE ROW LEVEL SECURITY;
|
||||
@@ -0,0 +1,39 @@
|
||||
-- VR-P32b/VR-P32d · KWP inbound capability — RLS companion artifact.
|
||||
--
|
||||
-- Forward-only. Inverse per table:
|
||||
-- REVOKE SELECT, INSERT, UPDATE, DELETE ON "<tbl>" FROM hivegrid_app, hivegrid_worker;
|
||||
-- DROP POLICY IF EXISTS "<tbl>_tenant_isolation" ON "<tbl>";
|
||||
-- ALTER TABLE "<tbl>" NO FORCE ROW LEVEL SECURITY;
|
||||
-- ALTER TABLE "<tbl>" DISABLE ROW LEVEL SECURITY;
|
||||
|
||||
DO $$
|
||||
DECLARE
|
||||
tbl text;
|
||||
BEGIN
|
||||
FOREACH tbl IN ARRAY ARRAY[
|
||||
'KwpApiContractSnapshot',
|
||||
'KwpCapabilityState',
|
||||
'KwpErrorReport',
|
||||
'KwpProjectRouting',
|
||||
'KwpMaterialPosition'
|
||||
]
|
||||
LOOP
|
||||
EXECUTE format('ALTER TABLE %I ENABLE ROW LEVEL SECURITY;', tbl);
|
||||
EXECUTE format('ALTER TABLE %I FORCE ROW LEVEL SECURITY;', tbl);
|
||||
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM pg_policies
|
||||
WHERE schemaname = current_schema()
|
||||
AND tablename = tbl
|
||||
AND policyname = tbl || '_tenant_isolation'
|
||||
) THEN
|
||||
EXECUTE format(
|
||||
'CREATE POLICY %I ON %I USING ("tenantId" = current_setting(''app.tenant_id'', true)) WITH CHECK ("tenantId" = current_setting(''app.tenant_id'', true));',
|
||||
tbl || '_tenant_isolation', tbl
|
||||
);
|
||||
END IF;
|
||||
|
||||
EXECUTE format('GRANT SELECT, INSERT, UPDATE, DELETE ON %I TO hivegrid_app, hivegrid_worker;', tbl);
|
||||
END LOOP;
|
||||
END
|
||||
$$;
|
||||
@@ -0,0 +1,105 @@
|
||||
-- VA-P26b merge input: internal-user and PortalUser actor invariants.
|
||||
--
|
||||
-- Prisma models the nullable foreign-key columns but cannot express these
|
||||
-- cross-column CHECK contracts. This artifact must be embedded after the
|
||||
-- approved merge migration's audited legacy backfill. Constraints are first
|
||||
-- installed NOT VALID (so new writes are protected immediately) and then
|
||||
-- validated in the same transaction. Any unresolved legacy actor fails closed.
|
||||
|
||||
BEGIN;
|
||||
|
||||
DO $$
|
||||
BEGIN
|
||||
IF NOT current_setting('is_superuser')::boolean
|
||||
AND NOT pg_has_role(current_user, 'hivegrid_rls_definer', 'MEMBER') THEN
|
||||
RAISE EXCEPTION 'Actor-contract installer must be superuser or a member of hivegrid_rls_definer';
|
||||
END IF;
|
||||
END$$;
|
||||
|
||||
GRANT SELECT ON "Form" TO hivegrid_rls_definer;
|
||||
GRANT CREATE ON SCHEMA public TO hivegrid_rls_definer;
|
||||
SET LOCAL ROLE hivegrid_rls_definer;
|
||||
|
||||
-- FormSubmission cannot reference Form.subtype directly from a plain CHECK.
|
||||
-- This stable, fail-closed predicate binds the submission to the exact tenant
|
||||
-- form: authenticated portal_form rows require one actor; standard/public and
|
||||
-- legacy rows may remain anonymous but may never carry two actors.
|
||||
CREATE OR REPLACE FUNCTION public.hivegrid_form_submission_actor_contract(
|
||||
p_form_id text,
|
||||
p_tenant_id text,
|
||||
p_internal_user_id text,
|
||||
p_portal_user_id text
|
||||
)
|
||||
RETURNS boolean
|
||||
LANGUAGE sql
|
||||
STABLE
|
||||
SECURITY DEFINER
|
||||
SET search_path = pg_catalog, public
|
||||
SET row_security = off
|
||||
AS $function$
|
||||
SELECT COALESCE((
|
||||
SELECT CASE
|
||||
-- Compare through text so this reviewed contract can be installed in
|
||||
-- the same outer transaction that adds the portal_form enum value.
|
||||
WHEN form."subtype"::text = 'portal_form'
|
||||
THEN pg_catalog.num_nonnulls(p_internal_user_id, p_portal_user_id) = 1
|
||||
ELSE pg_catalog.num_nonnulls(p_internal_user_id, p_portal_user_id) <= 1
|
||||
END
|
||||
FROM public."Form" AS form
|
||||
WHERE form."id" = p_form_id
|
||||
AND form."tenantId" = p_tenant_id
|
||||
), false)
|
||||
$function$;
|
||||
ALTER FUNCTION public.hivegrid_form_submission_actor_contract(text,text,text,text) OWNER TO hivegrid_rls_definer;
|
||||
REVOKE ALL ON FUNCTION public.hivegrid_form_submission_actor_contract(text,text,text,text)
|
||||
FROM PUBLIC, hivegrid_portal, hivegrid_authentik_jit;
|
||||
GRANT EXECUTE ON FUNCTION public.hivegrid_form_submission_actor_contract(text,text,text,text)
|
||||
TO hivegrid_migrator, hivegrid_app, hivegrid_worker;
|
||||
|
||||
RESET ROLE;
|
||||
REVOKE CREATE ON SCHEMA public FROM hivegrid_rls_definer;
|
||||
|
||||
DO $$
|
||||
BEGIN
|
||||
IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'File_actor_exactly_one_check' AND conrelid = '"File"'::regclass) THEN
|
||||
ALTER TABLE "File"
|
||||
ADD CONSTRAINT "File_actor_exactly_one_check"
|
||||
CHECK (pg_catalog.num_nonnulls("createdByUserId", "createdByPortalUserId") = 1) NOT VALID;
|
||||
END IF;
|
||||
IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'FileUpload_actor_exactly_one_check' AND conrelid = '"FileUpload"'::regclass) THEN
|
||||
ALTER TABLE "FileUpload"
|
||||
ADD CONSTRAINT "FileUpload_actor_exactly_one_check"
|
||||
CHECK (pg_catalog.num_nonnulls("createdByUserId", "createdByPortalUserId") = 1) NOT VALID;
|
||||
END IF;
|
||||
IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'FileEntityLink_actor_exactly_one_check' AND conrelid = '"FileEntityLink"'::regclass) THEN
|
||||
ALTER TABLE "FileEntityLink"
|
||||
ADD CONSTRAINT "FileEntityLink_actor_exactly_one_check"
|
||||
CHECK (pg_catalog.num_nonnulls("createdByUserId", "createdByPortalUserId") = 1) NOT VALID;
|
||||
END IF;
|
||||
IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'FormSubmission_actor_contract_check' AND conrelid = '"FormSubmission"'::regclass) THEN
|
||||
ALTER TABLE "FormSubmission"
|
||||
ADD CONSTRAINT "FormSubmission_actor_contract_check"
|
||||
CHECK (public.hivegrid_form_submission_actor_contract("formId", "tenantId", "createdByUserId", "createdByPortalUserId")) NOT VALID;
|
||||
END IF;
|
||||
END$$;
|
||||
|
||||
ALTER TABLE "File" VALIDATE CONSTRAINT "File_actor_exactly_one_check";
|
||||
ALTER TABLE "FileUpload" VALIDATE CONSTRAINT "FileUpload_actor_exactly_one_check";
|
||||
ALTER TABLE "FileEntityLink" VALIDATE CONSTRAINT "FileEntityLink_actor_exactly_one_check";
|
||||
ALTER TABLE "FormSubmission" VALIDATE CONSTRAINT "FormSubmission_actor_contract_check";
|
||||
|
||||
-- The migrator needs EXECUTE only while PostgreSQL validates the CHECK. It is
|
||||
-- revoked before the outer transaction can commit.
|
||||
SET LOCAL ROLE hivegrid_rls_definer;
|
||||
REVOKE EXECUTE ON FUNCTION public.hivegrid_form_submission_actor_contract(text,text,text,text)
|
||||
FROM hivegrid_migrator;
|
||||
RESET ROLE;
|
||||
|
||||
COMMIT;
|
||||
|
||||
-- Inverse merge SQL (execute only during an approved rollback):
|
||||
-- ALTER TABLE "FormSubmission" DROP CONSTRAINT IF EXISTS "FormSubmission_actor_contract_check";
|
||||
-- ALTER TABLE "FileEntityLink" DROP CONSTRAINT IF EXISTS "FileEntityLink_actor_exactly_one_check";
|
||||
-- ALTER TABLE "FileUpload" DROP CONSTRAINT IF EXISTS "FileUpload_actor_exactly_one_check";
|
||||
-- ALTER TABLE "File" DROP CONSTRAINT IF EXISTS "File_actor_exactly_one_check";
|
||||
-- DROP FUNCTION IF EXISTS public.hivegrid_form_submission_actor_contract(text,text,text,text);
|
||||
File diff suppressed because it is too large.
Load diff
+87
@@ -0,0 +1,87 @@
|
||||
-- VA-P26a feature-branch helper only. This is deliberately NOT a migration.
|
||||
--
|
||||
-- The frozen 20260713190000_appwide_rls_cutover migration installs policies
|
||||
-- whose expressions join the old per-PortalUser commerce tables. Prisma cannot
|
||||
-- drop those referenced tables during `db push` while the policies still
|
||||
-- exist. Remove only the seven reviewed policies before syncing a disposable
|
||||
-- local/CI database to the feature schema.
|
||||
--
|
||||
-- PortalUserRegistration is an eighth removed legacy table, but its policy
|
||||
-- does not reference the commerce tables and therefore is deliberately not
|
||||
-- part of this narrowly scoped db-push unblocker. Merge migration contract
|
||||
-- (AD-21): the eventual forward-only migration must contain these exact seven
|
||||
-- commerce-policy drops plus the separately reviewed PortalUserRegistration
|
||||
-- policy/table drop before child-first DROP TABLE statements.
|
||||
-- Its Inverse-SQL comment must recreate the tables, indexes, foreign keys and
|
||||
-- policies in parent-first order and explicitly state that deleted row data is
|
||||
-- not recoverable from DDL alone. Do not copy this helper in place of a merge
|
||||
-- migration and do not edit the historical cutover migration.
|
||||
|
||||
BEGIN;
|
||||
|
||||
DO $va_p26a_portal_legacy_commerce_recut$
|
||||
DECLARE
|
||||
legacy_tables CONSTANT text[] := ARRAY[
|
||||
'PortalCheckoutSessionStatus',
|
||||
'PortalSubscriptionFeature',
|
||||
'PortalSubscriptionPrice',
|
||||
'PortalSubscriptionProduct',
|
||||
'PortalUserSubscription',
|
||||
'PortalUserSubscriptionProduct',
|
||||
'PortalUserSubscriptionProductPrice'
|
||||
];
|
||||
legacy_policies CONSTANT text[] := ARRAY[
|
||||
'hg_PortalCheckoutSessionStatus_all',
|
||||
'hg_PortalSubscriptionFeature_all',
|
||||
'hg_PortalSubscriptionPrice_all',
|
||||
'hg_PortalSubscriptionProduct_all',
|
||||
'hg_PortalUserSubscription_all',
|
||||
'hg_PortalUserSubscriptionProduct_all',
|
||||
'hg_PortalUserSubscriptionProductPrice_all'
|
||||
];
|
||||
legacy record;
|
||||
remaining_policies text[];
|
||||
BEGIN
|
||||
IF cardinality(legacy_tables) <> cardinality(legacy_policies) THEN
|
||||
RAISE EXCEPTION 'VA-P26a legacy commerce recut allowlist is malformed';
|
||||
END IF;
|
||||
|
||||
FOR legacy IN
|
||||
SELECT *
|
||||
FROM unnest(legacy_tables, legacy_policies)
|
||||
AS allowlist(table_name, policy_name)
|
||||
LOOP
|
||||
IF to_regclass(format('%I.%I', 'public', legacy.table_name)) IS NULL THEN
|
||||
CONTINUE;
|
||||
END IF;
|
||||
|
||||
EXECUTE format(
|
||||
'DROP POLICY IF EXISTS %I ON %I.%I',
|
||||
legacy.policy_name,
|
||||
'public',
|
||||
legacy.table_name
|
||||
);
|
||||
END LOOP;
|
||||
|
||||
-- Unknown policies are not removed implicitly. Failing here keeps the whole
|
||||
-- transaction atomic and exposes a new dependency for explicit review.
|
||||
SELECT array_agg(
|
||||
format('%I.%I', relation.relname, policy.polname)
|
||||
ORDER BY relation.relname, policy.polname
|
||||
)
|
||||
INTO remaining_policies
|
||||
FROM pg_policy AS policy
|
||||
JOIN pg_class AS relation ON relation.oid = policy.polrelid
|
||||
JOIN pg_namespace AS namespace ON namespace.oid = relation.relnamespace
|
||||
WHERE namespace.nspname = 'public'
|
||||
AND relation.relname = ANY (legacy_tables);
|
||||
|
||||
IF remaining_policies IS NOT NULL THEN
|
||||
RAISE EXCEPTION
|
||||
'VA-P26a legacy commerce recut found non-allowlisted policies: %',
|
||||
remaining_policies;
|
||||
END IF;
|
||||
END
|
||||
$va_p26a_portal_legacy_commerce_recut$;
|
||||
|
||||
COMMIT;
|
||||
+3759
File diff suppressed because it is too large.
Load diff
@@ -24,7 +24,8 @@ BEGIN
|
||||
'Projekt',
|
||||
'ProjektStageChange',
|
||||
'PipelineAggregateSnapshot',
|
||||
'ProjektKontakt'
|
||||
'ProjektKontakt',
|
||||
'ProjektAdressDetail'
|
||||
]
|
||||
LOOP
|
||||
EXECUTE format('ALTER TABLE %I ENABLE ROW LEVEL SECURITY;', tbl);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
-- R-P11a Global Search isolation artifact.
|
||||
-- R-P11a Global Search isolation rollout artifact.
|
||||
-- Companion to prisma/rls/tenant-isolation.sql. These tables are tenant-scoped
|
||||
-- metadata around Meilisearch documents and recent searches. Enable during the
|
||||
-- merge migration once the schema lands.
|
||||
-- metadata around Meilisearch documents and recent searches. Activate only once
|
||||
-- every runtime access uses withTenantRLS() and therefore sets app.tenant_id.
|
||||
--
|
||||
-- Verification:
|
||||
-- psql "$DIRECT_URL" -f prisma/rls/search-isolation.sql
|
||||
@@ -11,13 +11,24 @@ ALTER TABLE "SearchIndexEntry" FORCE ROW LEVEL SECURITY;
|
||||
|
||||
DROP POLICY IF EXISTS "tenant_isolation_search_index_entry" ON "SearchIndexEntry";
|
||||
CREATE POLICY "tenant_isolation_search_index_entry" ON "SearchIndexEntry"
|
||||
USING ("tenantId" = current_setting('app.current_tenant_id', true))
|
||||
WITH CHECK ("tenantId" = current_setting('app.current_tenant_id', true));
|
||||
USING ("tenantId" = current_setting('app.tenant_id', true))
|
||||
WITH CHECK ("tenantId" = current_setting('app.tenant_id', true));
|
||||
|
||||
ALTER TABLE "RecentSearch" ENABLE ROW LEVEL SECURITY;
|
||||
ALTER TABLE "RecentSearch" FORCE ROW LEVEL SECURITY;
|
||||
|
||||
DROP POLICY IF EXISTS "tenant_isolation_recent_search" ON "RecentSearch";
|
||||
CREATE POLICY "tenant_isolation_recent_search" ON "RecentSearch"
|
||||
USING ("tenantId" = current_setting('app.current_tenant_id', true))
|
||||
WITH CHECK ("tenantId" = current_setting('app.current_tenant_id', true));
|
||||
USING ("tenantId" = current_setting('app.tenant_id', true))
|
||||
WITH CHECK ("tenantId" = current_setting('app.tenant_id', true));
|
||||
|
||||
GRANT SELECT, INSERT, UPDATE, DELETE ON "SearchIndexEntry", "RecentSearch" TO hivegrid_app;
|
||||
|
||||
-- Inverse SQL (coordinated rollback):
|
||||
-- REVOKE SELECT, INSERT, UPDATE, DELETE ON "SearchIndexEntry", "RecentSearch" FROM hivegrid_app;
|
||||
-- DROP POLICY IF EXISTS "tenant_isolation_search_index_entry" ON "SearchIndexEntry";
|
||||
-- ALTER TABLE "SearchIndexEntry" NO FORCE ROW LEVEL SECURITY;
|
||||
-- ALTER TABLE "SearchIndexEntry" DISABLE ROW LEVEL SECURITY;
|
||||
-- DROP POLICY IF EXISTS "tenant_isolation_recent_search" ON "RecentSearch";
|
||||
-- ALTER TABLE "RecentSearch" NO FORCE ROW LEVEL SECURITY;
|
||||
-- ALTER TABLE "RecentSearch" DISABLE ROW LEVEL SECURITY;
|
||||
@@ -6,6 +6,10 @@ ALTER TABLE "SignatureProviderConnection" ENABLE ROW LEVEL SECURITY;
|
||||
ALTER TABLE "ProjektSignatureDocument" ENABLE ROW LEVEL SECURITY;
|
||||
ALTER TABLE "ProjektSignatureSigner" ENABLE ROW LEVEL SECURITY;
|
||||
ALTER TABLE "SignatureEvent" ENABLE ROW LEVEL SECURITY;
|
||||
ALTER TABLE "SignatureProviderConnection" FORCE ROW LEVEL SECURITY;
|
||||
ALTER TABLE "ProjektSignatureDocument" FORCE ROW LEVEL SECURITY;
|
||||
ALTER TABLE "ProjektSignatureSigner" FORCE ROW LEVEL SECURITY;
|
||||
ALTER TABLE "SignatureEvent" FORCE ROW LEVEL SECURITY;
|
||||
|
||||
DROP POLICY IF EXISTS signature_provider_connection_tenant_isolation ON "SignatureProviderConnection";
|
||||
CREATE POLICY signature_provider_connection_tenant_isolation ON "SignatureProviderConnection"
|
||||
@@ -26,3 +30,14 @@ DROP POLICY IF EXISTS signature_event_tenant_isolation ON "SignatureEvent";
|
||||
CREATE POLICY signature_event_tenant_isolation ON "SignatureEvent"
|
||||
USING ("tenantId" = current_setting('app.tenant_id', true))
|
||||
WITH CHECK ("tenantId" = current_setting('app.tenant_id', true));
|
||||
|
||||
GRANT SELECT, INSERT, UPDATE, DELETE ON "SignatureProviderConnection" TO hivegrid_app;
|
||||
GRANT SELECT, INSERT, UPDATE, DELETE ON "ProjektSignatureDocument" TO hivegrid_app;
|
||||
GRANT SELECT, INSERT, UPDATE, DELETE ON "ProjektSignatureSigner" TO hivegrid_app;
|
||||
GRANT SELECT, INSERT, UPDATE, DELETE ON "SignatureEvent" TO hivegrid_app;
|
||||
|
||||
-- Inverse per table:
|
||||
-- REVOKE SELECT, INSERT, UPDATE, DELETE ON "<table>" FROM hivegrid_app;
|
||||
-- DROP POLICY IF EXISTS "<policy>" ON "<table>";
|
||||
-- ALTER TABLE "<table>" NO FORCE ROW LEVEL SECURITY;
|
||||
-- ALTER TABLE "<table>" DISABLE ROW LEVEL SECURITY;
|
||||
@@ -9,12 +9,14 @@
|
||||
--
|
||||
-- Idempotent. Inverse-SQL (DoD 28) am Dateiende.
|
||||
|
||||
-- 1) Restricted Application-Rolle: NICHT Superuser, NICHT BYPASSRLS, NICHT Tabellen-Owner
|
||||
-- -> RLS-Policies greifen fuer diese Rolle (Superuser/Owner wuerden sonst bypassen).
|
||||
-- 1) Restricted application role: not a superuser, not BYPASSRLS, and not the
|
||||
-- table owner, so policies apply. Authentication credentials are provisioned
|
||||
-- separately by the deployment secret workflow; this artifact must never
|
||||
-- contain a reusable database password.
|
||||
DO $$
|
||||
BEGIN
|
||||
IF NOT EXISTS (SELECT 1 FROM pg_roles WHERE rolname = 'hivegrid_app') THEN
|
||||
CREATE ROLE hivegrid_app LOGIN PASSWORD 'hivegrid_app_pw' NOSUPERUSER NOCREATEDB NOCREATEROLE NOBYPASSRLS;
|
||||
CREATE ROLE hivegrid_app LOGIN NOSUPERUSER NOCREATEDB NOCREATEROLE NOBYPASSRLS;
|
||||
ELSE
|
||||
ALTER ROLE hivegrid_app NOSUPERUSER NOBYPASSRLS;
|
||||
END IF;
|
||||
|
||||
+13617
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user