Skip to content

fix: extension authorization fix - #237

Merged
AndrewJackson2020 merged 1 commit into
masterfrom
fix_extension_privs
Nov 11, 2026
Merged

AndrewJackson2020 merged 1 commit into
masterfrom
fix_extension_privs

Conversation

@AndrewJackson2020

@AndrewJackson2020 AndrewJackson2020 commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

This PR prevents unauthorized users from creating extensions.
Current state is that any authorized user is able to create, drop, etc
extensions. Lets bolt this down a bit.

@steve-chavez

Copy link
Copy Markdown
Member

I agree with this. I raised it on before #116 (comment) but I believe there was a blocker mentioned on #118 (comment).

@AndrewJackson2020

Copy link
Copy Markdown
Contributor Author

I agree with this. I raised it on before #116 (comment) but I believe there was a blocker mentioned on #118 (comment).

Ah so its a known issue, thanks for the context.

@AndrewJackson2020

Copy link
Copy Markdown
Contributor Author

@steve-chavez I went ahead and increased the scope of this PR to every extension operation (ADD, DROP, ALTER, etc). Some of them were locked down, some were fine and I Just added tests for.

Open questions as this PR seems easy enough: how would a breaking change like this be handled at the platform level? Is it sufficient to add this as a breaking change in the change log or do we need something at the supabase platform level to warn people before they upgrade the extension?

I don't think there is anything we can do in an automated way to prevent breaking changes for customers unless we expand the scope of this PR to include some mechanism to grandfather existing users into be able to do extension operations, I'm opposed to this idea though.

@imor

imor commented Sep 27, 2026

Copy link
Copy Markdown
Collaborator

but I believe there was a blocker mentioned on #118 (comment)

@steve-chavez maybe I misunderstood, how is it a blocker for this PR? As I understood that comment, it's saying that extension custom scripts need to run as superuser to avoid some security problems, and that is still the case after this PR's change no?

@AndrewJackson2020

Copy link
Copy Markdown
Contributor Author

but I believe there was a blocker mentioned on #118 (comment)

@steve-chavez maybe I misunderstood, how is it a blocker for this PR? As I understood that comment, it's saying that extension custom scripts need to run as superuser to avoid some security problems, and that is still the case after this PR's change no?

I think this PR sidesteps this issue because of this line if (!is_current_role_privileged(policy->privileged_role) && !superuser()) { which is a pretty unique handling of superuser in the file. That said I think it makes sense to validate test coverage over this to assuage any concerns and lock down the functionality against future regressions.

Comment thread src/extensions.c
static bool create_extension(CreateExtensionStmt *stmt,
const utility_hook_args *args,
const extension_policy *policy) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The change looks good for today. One thing I'd adjust for the future: a role that isn't a member of supabase_privileged_role returns early from the new check and the statement falls through to Postgres, which installs trusted extensions (hstore, pgcrypto) for any role with CREATE on the database. Right now we have no overrides, constraints or scripts for those extensions, so nothing is lost. But the day we add one, it would be skipped silently for those roles.

I'd suggest to move the check so it only decides whether to elevate, not whether supautils runs at all. In create_extension that means keeping restrict_version_specification, constrain_extension and the custom scripts unconditional and folding the membership check into the is_extension_privileged condition in front of the elevated create. Same in alter_extension too.

Please also add a test for this case?

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 thought about this over the weekend and agree that this needs to be fixed before approval (as well as tested as this is certainly breaking stuff that isn't being picked up in the regression suite).

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 updated the C code implementation so I think it's correct now. I was not able to write unit tests to cover all of this though.

@AndrewJackson2020
AndrewJackson2020 requested a review from a team as a code owner September 29, 2026 21:59
@soedirgo
soedirgo removed their request for review October 6, 2026 02:09
This commit prevents unauthorized users from creating extensions.
Current state is that any authorized user is able to create, drop, etc
extensions. Lets bolt this down a bit.
@AndrewJackson2020
AndrewJackson2020 merged commit 67cf446 into master Nov 11, 2026
21 checks passed
@AndrewJackson2020
AndrewJackson2020 deleted the fix_extension_privs branch November 11, 2026 16:55
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.

4 participants