the _rv query with WHERE IN was faster after all, removing the JOIN variant
This commit is contained in:
parent
bafae52ce5
commit
6f6320565c
@ -47,3 +47,17 @@ BEGIN
|
|||||||
END; $$;
|
END; $$;
|
||||||
|
|
||||||
select * from randomInRange(0, 4);
|
select * from randomInRange(0, 4);
|
||||||
|
|
||||||
|
|
||||||
|
-- ========================================================
|
||||||
|
-- Test helpers
|
||||||
|
-- --------------------------------------------------------
|
||||||
|
|
||||||
|
-- there are some random ractors in test data generation, thus a range has to be accepted
|
||||||
|
CREATE OR REPLACE PROCEDURE expectBetween(actualCount integer, expectedFrom integer, expectedTo integer)
|
||||||
|
LANGUAGE plpgsql AS $$
|
||||||
|
BEGIN
|
||||||
|
IF NOT actualCount BETWEEN expectedFrom AND expectedTo THEN
|
||||||
|
RAISE EXCEPTION 'count expected to be between % and %, but got %', expectedFrom, expectedTo, actualCount;
|
||||||
|
END IF;
|
||||||
|
END; $$;
|
||||||
|
@ -107,26 +107,13 @@ CREATE TRIGGER deleteRbacRulesForCustomer_Trigger
|
|||||||
|
|
||||||
|
|
||||||
-- create RBAC restricted view
|
-- create RBAC restricted view
|
||||||
|
|
||||||
-- automatically updatable, but slow with WHERE IN
|
|
||||||
SET SESSION SESSION AUTHORIZATION DEFAULT;
|
SET SESSION SESSION AUTHORIZATION DEFAULT;
|
||||||
ALTER TABLE customer ENABLE ROW LEVEL SECURITY;
|
ALTER TABLE customer ENABLE ROW LEVEL SECURITY;
|
||||||
DROP VIEW IF EXISTS customer_rv;
|
DROP VIEW IF EXISTS customer_rv;
|
||||||
CREATE OR REPLACE VIEW customer_rv AS
|
CREATE OR REPLACE VIEW customer_rv AS
|
||||||
SELECT DISTINCT target.*
|
SELECT DISTINCT target.*
|
||||||
FROM customer AS target
|
FROM customer AS target
|
||||||
WHERE target.uuid IN (SELECT uuid FROM queryAccessibleObjectUuidsOfSubjectIds( 'view', 'customer', currentSubjectIds()));
|
WHERE target.uuid IN (SELECT queryAccessibleObjectUuidsOfSubjectIds( 'view', 'customer', currentSubjectIds()));
|
||||||
GRANT ALL PRIVILEGES ON customer_rv TO restricted;
|
|
||||||
|
|
||||||
-- not automatically updatable, but fast with JOIN
|
|
||||||
SET SESSION SESSION AUTHORIZATION DEFAULT;
|
|
||||||
ALTER TABLE customer ENABLE ROW LEVEL SECURITY;
|
|
||||||
DROP VIEW IF EXISTS customer_rv;
|
|
||||||
CREATE OR REPLACE VIEW customer_rv AS
|
|
||||||
SELECT DISTINCT target.*
|
|
||||||
FROM customer AS target
|
|
||||||
JOIN queryAccessibleObjectUuidsOfSubjectIds( 'view', 'customer', currentSubjectIds()) AS allowedObjId
|
|
||||||
ON target.uuid = allowedObjId;
|
|
||||||
GRANT ALL PRIVILEGES ON customer_rv TO restricted;
|
GRANT ALL PRIVILEGES ON customer_rv TO restricted;
|
||||||
|
|
||||||
|
|
||||||
|
@ -99,29 +99,15 @@ CREATE TRIGGER deleteRbacRulesForPackage_Trigger
|
|||||||
FOR EACH ROW EXECUTE PROCEDURE deleteRbacRulesForPackage();
|
FOR EACH ROW EXECUTE PROCEDURE deleteRbacRulesForPackage();
|
||||||
|
|
||||||
-- create RBAC-restricted view
|
-- create RBAC-restricted view
|
||||||
|
|
||||||
-- automatically updatable, but slow with WHERE IN
|
|
||||||
SET SESSION SESSION AUTHORIZATION DEFAULT;
|
SET SESSION SESSION AUTHORIZATION DEFAULT;
|
||||||
ALTER TABLE package ENABLE ROW LEVEL SECURITY;
|
ALTER TABLE package ENABLE ROW LEVEL SECURITY;
|
||||||
DROP VIEW IF EXISTS package_rv;
|
DROP VIEW IF EXISTS package_rv;
|
||||||
CREATE OR REPLACE VIEW package_rv AS
|
CREATE OR REPLACE VIEW package_rv AS
|
||||||
SELECT DISTINCT target.*
|
SELECT DISTINCT target.*
|
||||||
FROM package AS target
|
FROM package AS target
|
||||||
WHERE target.uuid IN (SELECT uuid FROM queryAccessibleObjectUuidsOfSubjectIds( 'view', 'package', currentSubjectIds()));
|
WHERE target.uuid IN (SELECT queryAccessibleObjectUuidsOfSubjectIds( 'view', 'package', currentSubjectIds()));
|
||||||
GRANT ALL PRIVILEGES ON package_rv TO restricted;
|
GRANT ALL PRIVILEGES ON package_rv TO restricted;
|
||||||
|
|
||||||
-- not automatically updatable, but fast with JOIN
|
|
||||||
SET SESSION SESSION AUTHORIZATION DEFAULT;
|
|
||||||
ALTER TABLE package ENABLE ROW LEVEL SECURITY;
|
|
||||||
DROP VIEW IF EXISTS package_rv;
|
|
||||||
CREATE OR REPLACE VIEW package_rv AS
|
|
||||||
SELECT DISTINCT target.*
|
|
||||||
FROM package AS target
|
|
||||||
JOIN queryAccessibleObjectUuidsOfSubjectIds( 'view', 'package', currentSubjectIds()) AS allowedObjId
|
|
||||||
ON target.uuid = allowedObjId;
|
|
||||||
GRANT ALL PRIVILEGES ON package_rv TO restricted;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- generate Package test data
|
-- generate Package test data
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ SET SESSION SESSION AUTHORIZATION DEFAULT ;
|
|||||||
CREATE TABLE IF NOT EXISTS UnixUser (
|
CREATE TABLE IF NOT EXISTS UnixUser (
|
||||||
uuid uuid UNIQUE REFERENCES RbacObject(uuid),
|
uuid uuid UNIQUE REFERENCES RbacObject(uuid),
|
||||||
name character varying(32),
|
name character varying(32),
|
||||||
|
comment character varying(96),
|
||||||
packageUuid uuid REFERENCES package(uuid)
|
packageUuid uuid REFERENCES package(uuid)
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -102,26 +103,13 @@ CREATE TRIGGER createRbacRulesForUnixUser_Trigger
|
|||||||
|
|
||||||
|
|
||||||
-- create RBAC-restricted view
|
-- create RBAC-restricted view
|
||||||
|
|
||||||
-- automatically updatable, but slow with WHERE IN
|
|
||||||
SET SESSION SESSION AUTHORIZATION DEFAULT;
|
SET SESSION SESSION AUTHORIZATION DEFAULT;
|
||||||
ALTER TABLE unixuser ENABLE ROW LEVEL SECURITY;
|
ALTER TABLE unixuser ENABLE ROW LEVEL SECURITY;
|
||||||
DROP VIEW IF EXISTS unixuser_rv;
|
DROP VIEW IF EXISTS unixuser_rv;
|
||||||
CREATE OR REPLACE VIEW unixuser_rv AS
|
CREATE OR REPLACE VIEW unixuser_rv AS
|
||||||
SELECT DISTINCT target.*
|
SELECT DISTINCT target.*
|
||||||
FROM unixuser AS target
|
FROM unixuser AS target
|
||||||
WHERE target.uuid IN (SELECT uuid FROM queryAccessibleObjectUuidsOfSubjectIds( 'view', 'unixuser', currentSubjectIds()));
|
WHERE target.uuid IN (SELECT queryAccessibleObjectUuidsOfSubjectIds( 'view', 'unixuser', currentSubjectIds()));
|
||||||
GRANT ALL PRIVILEGES ON unixuser_rv TO restricted;
|
|
||||||
|
|
||||||
-- not automatically updatable, but fast with JOIN
|
|
||||||
SET SESSION SESSION AUTHORIZATION DEFAULT;
|
|
||||||
ALTER TABLE unixuser ENABLE ROW LEVEL SECURITY;
|
|
||||||
DROP VIEW IF EXISTS unixuser_rv;
|
|
||||||
CREATE OR REPLACE VIEW unixuser_rv AS
|
|
||||||
SELECT DISTINCT target.*
|
|
||||||
FROM unixuser AS target
|
|
||||||
JOIN queryAccessibleObjectUuidsOfSubjectIds( 'view', 'unixuser', currentSubjectIds()) AS allowedObjId
|
|
||||||
ON target.uuid = allowedObjId;
|
|
||||||
GRANT ALL PRIVILEGES ON unixuser_rv TO restricted;
|
GRANT ALL PRIVILEGES ON unixuser_rv TO restricted;
|
||||||
|
|
||||||
|
|
||||||
|
@ -86,27 +86,15 @@ CREATE TRIGGER createRbacRulesForDomain_Trigger
|
|||||||
|
|
||||||
|
|
||||||
-- create RBAC-restricted view
|
-- create RBAC-restricted view
|
||||||
|
|
||||||
-- automatically updatable, but slow with WHERE IN
|
|
||||||
SET SESSION SESSION AUTHORIZATION DEFAULT;
|
SET SESSION SESSION AUTHORIZATION DEFAULT;
|
||||||
ALTER TABLE Domain ENABLE ROW LEVEL SECURITY;
|
ALTER TABLE Domain ENABLE ROW LEVEL SECURITY;
|
||||||
DROP VIEW IF EXISTS domain_rv;
|
DROP VIEW IF EXISTS domain_rv;
|
||||||
CREATE OR REPLACE VIEW domain_rv AS
|
CREATE OR REPLACE VIEW domain_rv AS
|
||||||
SELECT DISTINCT target.*
|
SELECT DISTINCT target.*
|
||||||
FROM Domain AS target
|
FROM Domain AS target
|
||||||
WHERE target.uuid IN (SELECT uuid FROM queryAccessibleObjectUuidsOfSubjectIds( 'view', 'domain', currentSubjectIds()));
|
WHERE target.uuid IN (SELECT queryAccessibleObjectUuidsOfSubjectIds( 'view', 'domain', currentSubjectIds()));
|
||||||
GRANT ALL PRIVILEGES ON domain_rv TO restricted;
|
GRANT ALL PRIVILEGES ON domain_rv TO restricted;
|
||||||
|
|
||||||
-- not automatically updatable, but fast with JOIN
|
|
||||||
SET SESSION SESSION AUTHORIZATION DEFAULT;
|
|
||||||
ALTER TABLE Domain ENABLE ROW LEVEL SECURITY;
|
|
||||||
DROP VIEW IF EXISTS domain_rv;
|
|
||||||
CREATE OR REPLACE VIEW domain_rv AS
|
|
||||||
SELECT DISTINCT target.*
|
|
||||||
FROM Domain AS target
|
|
||||||
JOIN queryAccessibleObjectUuidsOfSubjectIds( 'view', 'domain', currentSubjectIds()) AS allowedObjId
|
|
||||||
ON target.uuid = allowedObjId;
|
|
||||||
GRANT ALL PRIVILEGES ON domain_rv TO restricted;
|
|
||||||
|
|
||||||
-- generate Domain test data
|
-- generate Domain test data
|
||||||
|
|
||||||
|
@ -74,25 +74,13 @@ CREATE TRIGGER createRbacRulesForEMailAddress_Trigger
|
|||||||
|
|
||||||
|
|
||||||
-- create RBAC-restricted view
|
-- create RBAC-restricted view
|
||||||
|
|
||||||
-- automatically updatable, but slow with WHERE IN
|
|
||||||
SET SESSION SESSION AUTHORIZATION DEFAULT;
|
SET SESSION SESSION AUTHORIZATION DEFAULT;
|
||||||
ALTER TABLE EMailAddress ENABLE ROW LEVEL SECURITY;
|
ALTER TABLE EMailAddress ENABLE ROW LEVEL SECURITY;
|
||||||
DROP VIEW IF EXISTS EMailAddress_rv;
|
DROP VIEW IF EXISTS EMailAddress_rv;
|
||||||
CREATE OR REPLACE VIEW EMailAddress_rv AS
|
CREATE OR REPLACE VIEW EMailAddress_rv AS
|
||||||
SELECT DISTINCT target.*
|
SELECT DISTINCT target.*
|
||||||
FROM EMailAddress AS target
|
FROM EMailAddress AS target
|
||||||
WHERE target.uuid IN (SELECT DISTINCT uuid FROM queryAccessibleObjectUuidsOfSubjectIds( 'view', 'emailaddress', currentSubjectIds()));
|
WHERE target.uuid IN (SELECT queryAccessibleObjectUuidsOfSubjectIds( 'view', 'emailaddress', currentSubjectIds()));
|
||||||
GRANT ALL PRIVILEGES ON EMailAddress_rv TO restricted;
|
|
||||||
|
|
||||||
-- not automatically updatable, but fast with JOIN
|
|
||||||
SET SESSION SESSION AUTHORIZATION DEFAULT;
|
|
||||||
ALTER TABLE EMailAddress ENABLE ROW LEVEL SECURITY;
|
|
||||||
DROP VIEW IF EXISTS EMailAddress_rv;
|
|
||||||
CREATE OR REPLACE VIEW EMailAddress_rv AS
|
|
||||||
SELECT target.*
|
|
||||||
FROM EMailAddress AS target
|
|
||||||
WHERE target.uuid IN (SELECT DISTINCT uuid FROM queryAccessibleObjectUuidsOfSubjectIds( 'view', 'emailaddress', currentSubjectIds()));
|
|
||||||
GRANT ALL PRIVILEGES ON EMailAddress_rv TO restricted;
|
GRANT ALL PRIVILEGES ON EMailAddress_rv TO restricted;
|
||||||
|
|
||||||
-- generate EMailAddress test data
|
-- generate EMailAddress test data
|
||||||
|
@ -1,15 +1,6 @@
|
|||||||
ABORT;
|
ABORT;
|
||||||
SET SESSION SESSION AUTHORIZATION DEFAULT;
|
SET SESSION SESSION AUTHORIZATION DEFAULT;
|
||||||
|
|
||||||
-- there are some random ractors in test data generation, thus a range has to be accepted
|
|
||||||
CREATE OR REPLACE PROCEDURE expectBetween(actualCount integer, expectedFrom integer, expectedTo integer)
|
|
||||||
LANGUAGE plpgsql AS $$
|
|
||||||
BEGIN
|
|
||||||
IF NOT actualCount BETWEEN expectedFrom AND expectedTo THEN
|
|
||||||
RAISE EXCEPTION 'count expected to be between % and %, but got %', expectedFrom, expectedTo, actualCount;
|
|
||||||
END IF;
|
|
||||||
END; $$;
|
|
||||||
|
|
||||||
DO LANGUAGE plpgsql $$
|
DO LANGUAGE plpgsql $$
|
||||||
DECLARE
|
DECLARE
|
||||||
resultCount integer;
|
resultCount integer;
|
||||||
@ -90,8 +81,8 @@ BEGIN
|
|||||||
SET SESSION SESSION AUTHORIZATION restricted;
|
SET SESSION SESSION AUTHORIZATION restricted;
|
||||||
SET LOCAL hsadminng.currentUser = 'mike@hostsharing.net';
|
SET LOCAL hsadminng.currentUser = 'mike@hostsharing.net';
|
||||||
SET LOCAL hsadminng.assumedRoles = 'customer#aae.admin;customer#aaf.admin';
|
SET LOCAL hsadminng.assumedRoles = 'customer#aae.admin;customer#aaf.admin';
|
||||||
SELECT c.prefix, p.name as "package", ema.localPart || '@' || dom.name as "email-address"
|
-- SELECT c.prefix, p.name as "package", ema.localPart || '@' || dom.name as "email-address"
|
||||||
-- SELECT count(*) INTO resultCount
|
SELECT count(*) INTO resultCount
|
||||||
FROM emailaddress_rv ema
|
FROM emailaddress_rv ema
|
||||||
JOIN domain_rv dom ON dom.uuid = ema.domainuuid
|
JOIN domain_rv dom ON dom.uuid = ema.domainuuid
|
||||||
JOIN unixuser_rv uu ON uu.uuid = dom.unixuseruuid
|
JOIN unixuser_rv uu ON uu.uuid = dom.unixuseruuid
|
||||||
|
Loading…
Reference in New Issue
Block a user