Skip to content
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

Allow to run pg_repack by non-superuser #431

Merged
merged 2 commits into from
Nov 7, 2024

Conversation

za-arthur
Copy link
Collaborator

@za-arthur za-arthur commented Oct 30, 2024

The option --no-superuser-check allows to by-pass the check if the user is a superuser. That was done for users which run pg_repack on Amazon, where users cannot run it as a superuser.
The problem is that the option --no-superuser-check works only on the CLI level, skipping the check only by the pg_repack client. But there are also checks done by the extension functions exported to SQL.

The PR removes the check that the user is a superuser from functions repack_trigger() and repack_apply(). That check is redundant since queries executed by that functions can be executed by a user manually. Moreover repack_trigger() is a SECURITY DEFINER function, which means that it is executed with superuser privileges (pg_repack extension can be created only by superuser).

The PR changes privilege check in functions repack_swap(), repack_drop() and repack_index_swap(). Now that functions can be run by an owner of a table. That check is necessary since _swap functions swap relfilenodes on pg_class system catalog table. repack_drop() acquires ACCESS EXCLUSIVE lock and therefore it also requires privilege check.

Additionally I cherry-picked the commit 326b6e1 from the PR #427. Otherwise pg_repack will fall with segmentation fault in case of lack of permissions.

Relevant issues:

Fixed the bug that segmentation fault occurs when default_transaction_read_only is turned on during repacking. bug: #426
@andreasscherbaum
Copy link
Collaborator

Ah, nice, comes with additional tests. I like that.

Now everybody how has access to repack_trigger() and repack_apply() and
relevant objects can call that functions.

Functions repack_swap(), repack_drop() and repack_index_swap() can be
called by superuser and owners of a table.

Cherry-pick the commit 326b6e1 to not cause segmentation fault when
using -k option and not having enough permissions.
@za-arthur
Copy link
Collaborator Author

I'd like to merge the PR this week if no objections.

@za-arthur za-arthur merged commit 85b64c6 into master Nov 7, 2024
20 checks passed
@za-arthur za-arthur deleted the issue223_no_superuser_check branch November 7, 2024 13:21
za-arthur added a commit to supabase/postgres that referenced this pull request Nov 7, 2024
New version allows to run pg_repack by a non-superuser.
PR on pg_repack repo:
reorg/pg_repack#431
za-arthur added a commit to supabase/postgres that referenced this pull request Nov 7, 2024
New version allows to run pg_repack by a non-superuser.
PR on pg_repack repo:
reorg/pg_repack#431
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