Skip to content

feat: allow privileged_role to manage FDWs #39

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 8, 2022

Conversation

soedirgo
Copy link
Member

@soedirgo soedirgo commented Dec 8, 2022

What kind of change does this PR introduce?

feature

What is the current behavior?

Non-superusers can't manage FDWs, which is a blocker for https://github.com/supabase/wrappers

What is the new behavior?

privileged_role can create/alter/drop FDWs.

@soedirgo soedirgo requested a review from steve-chavez December 8, 2022 12:04
@soedirgo soedirgo force-pushed the bs/privileged-role-fdw branch from 43a242f to 007ebe4 Compare December 8, 2022 12:08
@soedirgo soedirgo force-pushed the bs/privileged-role-fdw branch from 007ebe4 to 8fbe5dd Compare December 8, 2022 12:26
@soedirgo soedirgo force-pushed the bs/privileged-role-fdw branch from 8fbe5dd to 2aa24dd Compare December 8, 2022 12:37
src/supautils.c Outdated

run_process_utility_hook(prev_hook);

// GRANT USAGE on the FDW so we can do CREATE SERVER.
Copy link
Member

Choose a reason for hiding this comment

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

If we're already superuser, why do we need this GRANT USAGE?

Copy link
Member Author

Choose a reason for hiding this comment

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

The privileged_role won't be a superuser, so after the FDW is created, it needs GRANT USAGE to do CREATE SERVER ... FOREIGN DATA WRAPPER ...

Copy link
Member Author

Choose a reason for hiding this comment

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

One alternative I considered is to make the privileged_role the owner of the FDW, but since you need to be a superuser to own a FDW, I had to temporarily make the privileged_role a superuser - a bit icky, but might be a cleaner end state?

Copy link
Member

Choose a reason for hiding this comment

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

but might be a cleaner end state?

If we can avoid mutating the privileged role here it'd be better. Otherwise users could revoke this usage and be left confused why the fdw fails.

Copy link
Member Author

Choose a reason for hiding this comment

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

Gotcha - updated the PR

Copy link
Member

Choose a reason for hiding this comment

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

Looks good. I see we can drop the FDW despite not being superuser later on.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah nice catch, simplified the code a bit

@soedirgo soedirgo force-pushed the bs/privileged-role-fdw branch from 061f34b to f1f220f Compare December 8, 2022 15:41
@soedirgo soedirgo merged commit b250e7d into master Dec 8, 2022
@soedirgo soedirgo deleted the bs/privileged-role-fdw branch December 8, 2022 15:43
soedirgo added a commit to supabase/postgres that referenced this pull request Dec 10, 2022
Incorporates supabase/supautils#39 which
unblocks Wrappers
soedirgo added a commit to supabase/postgres that referenced this pull request Dec 10, 2022
Incorporates supabase/supautils#39 which
unblocks Wrappers
hf pushed a commit to supabase/postgres that referenced this pull request Jan 23, 2023
Incorporates supabase/supautils#39 which
unblocks Wrappers
damonrand pushed a commit to cepro/postgres that referenced this pull request Jun 15, 2025
Incorporates supabase/supautils#39 which
unblocks Wrappers
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