Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support row-level security #512

Closed
zhibor opened this issue Feb 24, 2021 · 4 comments
Closed

Support row-level security #512

zhibor opened this issue Feb 24, 2021 · 4 comments
Labels
feature New fetures product/buildui prestd BuildUI

Comments

@zhibor
Copy link

zhibor commented Feb 24, 2021

It doesn't seem prest supports row-level security yet. Is it in the plan to utilize postgresql's row-level security to restrict visibility and access for the current user?

@zhibor zhibor added feature New fetures product/buildui prestd BuildUI labels Feb 24, 2021
@fabriziomello
Copy link
Contributor

fabriziomello commented Feb 24, 2021

For now I can't see a big win adding it to pREST level because IMHO the RLS (Row-Level Security) is a database engine feature and there are no problem to create your policies inside the PostgreSQL to reflect it on pREST.

The big problem I can see here is nowadays we connect to PostgreSQL using just one user and it cannot help to much if you want to create policies to restrict rows for different users. But there are an open issue about API redesign (#435) that the main goal is improve the interaction with multiple databases and schemas and one of the proposal is create several configurations and using this you can create connections with different users.

Anyway can you please explain more what problem are you want to solve?

@zhibor
Copy link
Author

zhibor commented Feb 24, 2021

@fabriziomello thanks a lot for your prompt response!

say we have a todos table

create table todos (
	id    serial primary key,
	todo  text not null,
	private boolean default true,  
	owner_id int references "users"(id)
);

the following api call should return only the items "owned" by current_user except for public items.

GET /app/public/todos

any pointers on how to implement this feature would be greatly appreciated!

@fabriziomello
Copy link
Contributor

You should use CREATE POLICY statement to create your own policies. Have a look at the official documentation:

https://www.postgresql.org/docs/current/ddl-rowsecurity.html
https://www.postgresql.org/docs/current/sql-createpolicy.html

@zhibor
Copy link
Author

zhibor commented Mar 3, 2021

very much appreciated!

@zhibor zhibor closed this as completed Mar 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New fetures product/buildui prestd BuildUI
Projects
None yet
Development

No branches or pull requests

2 participants