I want the rows in a table accessible to only members of groups. I create users and add them to group by following method,
CREATE USER abc LOGIN PASSWORD 'securedpassword1';
CREATE USER xyz LOGIN PASSWORD 'securedpassword2';
ALTER GROUP permanent ADD USER abc;
Then the policy I write makes it accessible to only current user. But I need whole group to access it.
CREATE TABLE table_Workers
(
worID INT
,worName CHARACTER VARYING
,pgUser CHARACTER VARYING
);
INSERT INTO table_Workers VALUES
(1,'Jason','abc'),(2,'Roy','abc'),(3,'Johny','abc')
,(4,'Jane','xyz'),(5,'Kane','xyz'),(6,'Stuart','xyz');
CREATE POLICY policy_employee_user ON table_Workers FOR ALL
TO PUBLIC USING (pgUser = current_user);
ALTER TABLE table_Workers ENABLE ROW LEVEL SECURITY;
pgUser names the user who can access the row. I wish to replace column pgUser with pgRole, where name of the group is mentioned whose members can access that particular row. Any hint or method is appreciated for making rows accessible to whole group.
using (pg_has_role(current_user, 'permanent'))
maybe? – Zoolatrycreate table
statement of the tabletable_workers
in your question (edit your question do not post code in comments). But it seems you should be able to usepg_has_role(pguser, pgrole)
then – Zoolatrypg_has_role(current_user, pgrole)
here. pgRole will have two groups including 'permanent' and 'temp' – NeoplasmpgUser
column topgRole
. Where group name will be entered. And my aim is to make the members of those groups able to access the respective rows. – Neoplasm