fix row level security readme per https://github.com/begriffs/postgre… (#579)

* fix row level security readme per https://github.com/begriffs/postgrest/issues/554

* handle anonymous access to posts / comments tables

* address insertion use case in row-level security readme
This commit is contained in:
opensrcken
2016-05-08 09:31:28 -07:00
committed by Joe Nelson
parent d9205bd838
commit 0dc33dbf9f
+38 -7
View File
@@ -71,21 +71,52 @@ security](http://www.postgresql.org/docs/9.5/static/ddl-rowsecurity.html).
Note that it requires PostgreSQL 9.5 or later.
```sql
grant select on posts, comments to anon;
ALTER TABLE posts ENABLE ROW LEVEL SECURITY;
drop policy if exists authors_eigenedit on posts;
create policy authors_eigenedit on posts
using (true)
ALTER TABLE comments ENABLE ROW LEVEL SECURITY;
drop policy if exists posts_select_unsecure on posts;
create policy posts_select_unsecure on posts for select
using (true);
drop policy if exists comments_select_unsecure on comments;
create policy comments_select_unsecure on comments for select
using (true);
drop policy if exists authors_eigencreate on posts;
create policy authors_eigencreate on posts for insert
with check (
author = basic_auth.current_email()
);
ALTER TABLE comments ENABLE ROW LEVEL SECURITY;
drop policy if exists authors_eigenedit on comments;
create policy authors_eigenedit on comments
using (true)
drop policy if exists authors_eigencreate on comments;
create policy authors_eigencreate on comments for insert
with check (
author = basic_auth.current_email()
);
drop policy if exists authors_eigenedit on posts;
create policy authors_eigenedit on posts for update
using (author = basic_auth.current_email())
with check (
author = basic_auth.current_email()
);
drop policy if exists authors_eigenedit on comments;
create policy authors_eigenedit on comments for update
using (author = basic_auth.current_email())
with check (
author = basic_auth.current_email()
);
drop policy if exists authors_eigendelete on posts;
create policy authors_eigendelete on posts for delete
using (author = basic_auth.current_email());
drop policy if exists authors_eigendelete on comments;
create policy authors_eigendelete on comments for delete
using (author = basic_auth.current_email());
```
Finally we need to modify the `users` view from the previous example.