Menggabungkan beberapa kebijakan per pengguna - Amazon Redshift

Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.

Menggabungkan beberapa kebijakan per pengguna

RLS di Amazon Redshift mendukung melampirkan beberapa kebijakan per pengguna dan objek. Jika ada beberapa kebijakan yang ditentukan untuk pengguna, Amazon Redshift menerapkan semua kebijakan dengan sintaks AND atau OR tergantung pada setelan JENIS KONJUNGSI RLS untuk tabel. Untuk informasi lebih lanjut tentang jenis konjungsi, lihatALTER TABLE.

Beberapa kebijakan pada tabel dapat dikaitkan dengan Anda. Baik beberapa kebijakan secara langsung melekat pada Anda, atau Anda termasuk dalam beberapa peran, dan peran tersebut memiliki kebijakan berbeda yang melekat padanya.

Jika beberapa kebijakan harus membatasi akses baris dalam relasi tertentu, Anda dapat menyetel JENIS KONJUNGSI RLS dari relasi ke AND. Pertimbangkan contoh berikut. Alice hanya dapat melihat acara Olahraga yang memiliki “catname” NBA sesuai kebijakan yang ditentukan.

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

Ketika beberapa kebijakan harus mengizinkan pengguna untuk melihat lebih banyak baris dalam relasi tertentu, pengguna dapat menyetel JENIS KONJUNGSI RLS dari relasi ke OR. Pertimbangkan contoh berikut. Alice hanya dapat melihat “Konser” dan “Olahraga” sebagai kebijakan yang ditentukan.

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