Skip to content

revoke excess permissions - #298

Draft
AndrewJackson2020 wants to merge 7 commits into
masterfrom
remove_permissions
Draft

AndrewJackson2020 wants to merge 7 commits into
masterfrom
remove_permissions

Conversation

@AndrewJackson2020

Copy link
Copy Markdown
Contributor

Currently pg_net, by default grants all permissions on tables and sequences in net schema. 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.

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;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can only grant truncate on that one table then?

Sounds fine to me.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +3 to +4
revoke insert on all tables in schema net to PUBLIC;
revoke update on all tables in schema net to PUBLIC;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are likely not needed, also insert shouldn't work correctly since #199

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same use case as TRUNCATE

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some users have added triggers in the past #62 (comment)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there's no PRIMARY or UNIQUE key on the tables then this should be fine

@AndrewJackson2020 AndrewJackson2020 Sep 23, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment on lines +8 to +9
revoke trigger on all tables in schema net to PUBLIC;
revoke maintain on all tables in schema net to PUBLIC;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would prevent users from running VACUUM, not sure if needed, it might.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@steve-chavez

Copy link
Copy Markdown
Member

Not opposed to the changes, but they might be breaking.

@AndrewJackson2020

Copy link
Copy Markdown
Contributor Author

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.

@imor

imor commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

@AndrewJackson2020 also bump the version since this PR adds sql/pg_net--0.20.5--0.20.6.sql?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants