Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
larsw committed Jan 4, 2024
1 parent 1fc197c commit 44bb7b1
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions notes/rls.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
create role users;
create user johnny;
grant users to johnny;

create table secret_stuff(id serial primary key, data text not null, authz_expr text not null);
alter table secret_stuff enable row level security;
insert into secret_stuff(data, authz_expr) values('pretty secret', 'label1');
insert into secret_stuff(data, authz_expr) values('moar secret', 'label1|label2');
insert into secret_stuff(data, authz_expr) values('wat', 'label2');
insert into secret_stuff(data, authz_expr) values('win', 'label2 & (label3 | label4)');

grant select on secret_stuff to users;

create policy evaluate_policies on secret_stuff using ( accumulo_check_authorization(authz_expr, string_to_array(current_setting('session.authorizations'), ',')));

-- ...
set session authorization johnny;
select current_user,session_user;
-- current_user | session_user
----------------+--------------
-- johnny | johnny

set session.authorizations = 'label1';

select * from secret_stuff;
-- id | data | authz_expr
------+---------------+---------------
-- 1 | pretty secret | label1
-- 2 | moar secret | label1|label2
-- (2 rows)

set session.authorizations = 'label2,label3';
select * from secret_stuff;
-- id | data | authz_expr
------+-------------+----------------------------
-- 2 | moar secret | label1|label2
-- 3 | wat | label2
-- 4 | win | label2 & (label3 | label4)
-- (3 rows)

0 comments on commit 44bb7b1

Please sign in to comment.