revoke excess permissions - #298
AndrewJackson2020 wants to merge 7 commits into
Conversation
| revoke insert on all tables in schema net to PUBLIC; | ||
| revoke update on all tables in schema net to PUBLIC; | ||
| revoke delete on all tables in schema net to PUBLIC; | ||
| revoke truncate on all tables in schema net to PUBLIC; |
There was a problem hiding this comment.
IIRC this is used sometimes by users to clear the http_request_que rows, if it grows too big I recall there were problems #216
There was a problem hiding this comment.
Maybe we can only grant truncate on that one table then? It still seems odd granting that privilege to all as the pg_net queue is a shared resource and you are basically allowing any read only user to clobber everyone elses request.
There was a problem hiding this comment.
Maybe we can only grant truncate on that one table then?
Sounds fine to me.
There was a problem hiding this comment.
I went ahead and added delete/truncate to public on this table. TBH I still feel a bit weird doing this. pg_cron does not allow usage on the net schema at all by default so the user has to opt into a user being able to use any of the functionality. I wonder if we should do the same.
| revoke insert on all tables in schema net to PUBLIC; | ||
| revoke update on all tables in schema net to PUBLIC; |
There was a problem hiding this comment.
These are likely not needed, also insert shouldn't work correctly since #199
There was a problem hiding this comment.
Not needed as its okay to revoke and the above statements are fine?
|
|
||
| revoke insert on all tables in schema net to PUBLIC; | ||
| revoke update on all tables in schema net to PUBLIC; | ||
| revoke delete on all tables in schema net to PUBLIC; |
There was a problem hiding this comment.
added delete above with reservation.
| revoke delete on all tables in schema net to PUBLIC; | ||
| revoke truncate on all tables in schema net to PUBLIC; | ||
| revoke references on all tables in schema net to PUBLIC; | ||
| revoke trigger on all tables in schema net to PUBLIC; |
There was a problem hiding this comment.
Some users have added triggers in the past #62 (comment)
There was a problem hiding this comment.
This is one again where I would want to consult what the default permissions are. A trigger will essentially highjack another users session with code provided by the client that created the trigger, correct? Seems like this opens up a plethora of security issues.
There was a problem hiding this comment.
Agree, the case in #62 does self-hosting too so I guess they can use superuser anyway.
| revoke update on all tables in schema net to PUBLIC; | ||
| revoke delete on all tables in schema net to PUBLIC; | ||
| revoke truncate on all tables in schema net to PUBLIC; | ||
| revoke references on all tables in schema net to PUBLIC; |
There was a problem hiding this comment.
If there's no PRIMARY or UNIQUE key on the tables then this should be fine
There was a problem hiding this comment.
Per the docs I think this needs to be revoked either way, seems live a vector for a privilege escalation attack:
Allows creation of a foreign key constraint referencing a table, or specific column(s) of a table. Great care should be taken when granting this privilege, since a user who creates a foreign key can arrange for enforcement of that foreign key to call an arbitrary function, such as a cast function, and such functions will be called with the privileges of the table owner.
https://www.postgresql.org/docs/current/ddl-priv.html#DDL-PRIV-REFERENCES
| revoke trigger on all tables in schema net to PUBLIC; | ||
| revoke maintain on all tables in schema net to PUBLIC; |
There was a problem hiding this comment.
This would prevent users from running VACUUM, not sure if needed, it might.
There was a problem hiding this comment.
Not postgres/superuser but obv supabase platform users don't have that anyway. I think what I should do here is validate all of the permissions and only revoke non default permissions that postgres wouldn't grant on a a create table.
There was a problem hiding this comment.
This permission would allow any authenticated user to lock the table. Also it seems like it is not a default permission in postgres which leads me to think we should not allow it.
11:22:15 aj@localhost:5432/postgres 96469 =#
create table something3 (c1 int);
CREATE TABLE
11:22:20 aj@localhost:5432/postgres 96469 =#
create user whatever3;
CREATE ROLE
11:22:28 aj@localhost:5432/postgres 96469 =#
SELECT * FROM has_table_privilege('whatever3', 'something3', 'MAINTAIN')
;
has_table_privilege
---------------------
f
(1 row)
Allows VACUUM, ANALYZE, CLUSTER, REFRESH MATERIALIZED VIEW, REINDEX, LOCK TABLE, and database object statistics manipulation functions (see Table 9.105) on a relation.
https://www.postgresql.org/docs/current/ddl-priv.html#DDL-PRIV-MAINTAIN
|
Not opposed to the changes, but they might be breaking. |
They are absolutely breaking. I think most of the work here is deciding how to handle that. |
26879e5 to
6d89518
Compare
|
@AndrewJackson2020 also bump the version since this PR adds |
Currently pg_net, by default grants all permissions on tables and sequences in
netschema. This seems problematic from a security perspective.pg_cron, for example creates a cron schema but only grants select on the jobs table0, it does not provide usage on the schema even. Instead pg_cron provides documentation for how to provide users access1 via a schema usage grant.