Kombinieren mehrerer Richtlinien pro Benutzer - Amazon Redshift

Die vorliegende Übersetzung wurde maschinell erstellt. Im Falle eines Konflikts oder eines Widerspruchs zwischen dieser übersetzten Fassung und der englischen Fassung (einschließlich infolge von Verzögerungen bei der Übersetzung) ist die englische Fassung maßgeblich.

Kombinieren mehrerer Richtlinien pro Benutzer

RLS in Amazon Redshift unterstützt das Anfügen mehrerer Richtlinien pro Benutzer und Objekt. Wenn für einen Benutzer mehrere Richtlinien definiert sind, wendet Amazon Redshift alle Richtlinien mit der UND- oder ODER-Syntax an, abhängig von der Einstellung RLS CONJUNCTION TYPE für die Tabelle. Weitere Informationen zu Verbindungstypen finden Sie unter ALTER TABLE.

Ihnen können mehrere Richtlinien für eine Tabelle zugeordnet werden. Entweder sind Ihnen mehrere Richtlinien direkt zugeordnet, oder Sie gehören mehreren Rollen an, und den Rollen sind unterschiedliche Richtlinien zugeordnet.

Wenn mehrere Richtlinien den Zeilenzugriff in einer bestimmten Relation einschränken sollen, können Sie RLS CONJUNCTION TYPE der Relation auf AND setzen. Betrachten Sie das folgende Beispiel. Alice kann nur Sport-Ereignisse sehen, deren „Katzenname“ in der angegebenen Richtlinie „NBA“ ist.

-- Create an analyst role and grant it to a user named Alice. CREATE ROLE analyst; CREATE USER alice WITH PASSWORD 'Name_is_alice_1'; GRANT ROLE analyst TO alice; -- Create an RLS policy that only lets the user see sports. CREATE RLS POLICY policy_sports WITH (catgroup VARCHAR(10)) USING (catgroup = 'Sports'); -- Create an RLS policy that only lets the user see NBA. CREATE RLS POLICY policy_nba WITH (catname VARCHAR(10)) USING (catname = 'NBA'); -- Attach both to the analyst role. ATTACH RLS POLICY policy_sports ON category TO ROLE analyst; ATTACH RLS POLICY policy_nba ON category TO ROLE analyst; -- Activate RLS on the category table with AND CONJUNCTION TYPE. ALTER TABLE category ROW LEVEL SECURITY ON CONJUNCTION TYPE AND; -- Change session to Alice. SET SESSION AUTHORIZATION alice; -- Select all from the category table. SELECT catgroup, catname FROM category; catgroup | catname ---------+--------- Sports | NBA (1 row)

Wenn mehrere Richtlinien Benutzern ermöglichen sollen, mehr Zeilen in einer bestimmten Relation zu sehen, kann der Benutzer RLS CONJUNCTION TYPE der Relation auf OR setzen. Betrachten Sie das folgende Beispiel. Alice kann gemäß der angegebenen Richtlinie nur „Konzerte“ und „Sport“ sehen.

-- Create an analyst role and grant it to a user named Alice. CREATE ROLE analyst; CREATE USER alice WITH PASSWORD 'Name_is_alice_1'; GRANT ROLE analyst TO alice; -- Create an RLS policy that only lets the user see concerts. CREATE RLS POLICY policy_concerts WITH (catgroup VARCHAR(10)) USING (catgroup = 'Concerts'); -- Create an RLS policy that only lets the user see sports. CREATE RLS POLICY policy_sports WITH (catgroup VARCHAR(10)) USING (catgroup = 'Sports'); -- Attach both to the analyst role. ATTACH RLS POLICY policy_concerts ON category TO ROLE analyst; ATTACH RLS POLICY policy_sports ON category TO ROLE analyst; -- Activate RLS on the category table with OR CONJUNCTION TYPE. ALTER TABLE category ROW LEVEL SECURITY ON CONJUNCTION TYPE OR; -- Change session to Alice. SET SESSION AUTHORIZATION alice; -- Select all from the category table. SELECT catgroup, count(*) FROM category GROUP BY catgroup ORDER BY catgroup; catgroup | count ---------+------- Concerts | 3 Sports | 5 (2 rows)