Combinazione di più policy per utente - Amazon Redshift

Le traduzioni sono generate tramite traduzione automatica. In caso di conflitto tra il contenuto di una traduzione e la versione originale in Inglese, quest'ultima prevarrà.

Combinazione di più policy per utente

RLSin Amazon Redshift supporta l'associazione di più policy per utente e oggetto. Quando sono definite più policy per un utente, Amazon Redshift applica tutte le policy con una delle due AND o con la sintassi OR a seconda dell'RLSCONJUNCTIONTYPEimpostazione della tabella. Per ulteriori informazioni sui tipi di combinazione, consulta ALTER TABLE.

Più policy su una tabella possono essere associate alla tua utenza. Le policy possono essere collegate direttamente a te o puoi appartenere a più ruoli e i ruoli hanno policy diverse associate.

Quando le politiche multiple devono limitare l'accesso alle righe in una determinata relazione, puoi impostare RLS CONJUNCTION TYPE la relazione a. AND Analizza l'esempio seguente. Alice può vedere solo gli eventi sportivi il cui «nome gatto» corrisponde NBA alla politica specificata.

-- 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)

Quando le politiche multiple dovrebbero consentire agli utenti di vedere più righe in una determinata relazione, l'utente può impostare RLS CONJUNCTION TYPE la relazione su OR. Analizza l'esempio seguente. Alice può vedere solo "Concerts" e "Sports", come specificato nella policy.

-- 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)