Replies: 6 comments 2 replies
-
Putting custom stuff into |
Beta Was this translation helpful? Give feedback.
-
Using schema = pg_catalog does not imply putting stuff into pg_catalog, it only affects the search_path and the @extschema@ macro. An extension can put stuff wherever it wants regardless of the extension schema. My position is that an extension should always create its own schema to make sure it's owned by the extension and put stuff in there. Using pg_catalog as the extension schema is to negate the search_path. (but to answer the question: yes, it is possible to put stuff into pg_catalog, e.g. Timescale and Citus put functions there) |
Beta Was this translation helpful? Give feedback.
-
I asked about supported, not possible 😁 |
Beta Was this translation helpful? Give feedback.
-
Is there a reason you prefer forcing
I really like the example you provided, and I think it demonstrates how unintuitive it is for people who aren't familiar with Postgres that CREATE/ALTER extension can lead to privilege escalation. |
Beta Was this translation helpful? Give feedback.
-
As I discussed elsewhere (pgq/pgq#22 & citusdata/pg_cron#274), I am against this for several reasons the main ones being
|
Beta Was this translation helpful? Give feedback.
-
" |
Beta Was this translation helpful? Give feedback.
-
What are people's thoughts on extension schemas?
So far, I think the only right way of creating extensions is to use:
and to explicitly do a
CREATE SCHEMA myextschema
in the SQL script, which deliberately fails if the schema already exists. This effectively disables extension schemas altogether.The reason why this is important is that extension schemas can exist prior to the extension being created and a less privileged user may be able to create functions in the schema. The extension schema always is always in the search_path during the execution of CREATE/ALTER extension scripts, which is usually done as superuser.
When you do an unqualified function or operator call in PostgreSQL, pg_catalog takes precedence of whatever is in the search_path, but not if the function is overloaded and there's a better match for the argument types. For instance, if you call
fn('hello')
and there are two functionspg_catalog.fn(name)
andmyextschema.fn(text)
, PostgreSQL will prefer to call the latter because it does not require an implicit cast.Hence, a CREATE/ALTER extension that performs some unqualified function/operator call (luckily not super common, most commands are DDL) could be tricked into calling a function in an extension schema created by a less privileged user. That's a privilege escalation path that frequently hits managed services.
Jelte has a proposal for requiring that the extension owns the schema, which does make sense:
https://www.postgresql.org/message-id/flat/CAFMSG9HKmbD%2Bu8PamLRsM3uQXvFC-CV-vR_fUbpUNhb4_Z71jQ%40mail.gmail.com#50bac4bf4cd1c0ba265255bb57f76278
Note: an unqualified operator call looks like
=
, a qualified operator operator call looks likeOPERATOR(pg_catalog.=)
Beta Was this translation helpful? Give feedback.
All reactions