-
Notifications
You must be signed in to change notification settings - Fork 301
skip and warn about role mismatch in Maintenance Functions #806
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
Open
jw1u1
wants to merge
2
commits into
pgpartman:development
Choose a base branch
from
jw1u1:prevent_partition_owner_mismatch
base: development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,6 +44,7 @@ v_parent_exists text; | |
| v_parent_oid oid; | ||
| v_parent_schema text; | ||
| v_parent_tablename text; | ||
| v_parent_owner text; | ||
| v_partition_expression text; | ||
| v_premade_count int; | ||
| v_row record; | ||
|
|
@@ -162,13 +163,18 @@ LOOP | |
| END IF; | ||
| END IF; | ||
|
|
||
| SELECT n.nspname, c.relname, c.oid | ||
| INTO v_parent_schema, v_parent_tablename, v_parent_oid | ||
| SELECT n.nspname, c.relname, c.oid, c.relowner::regrole | ||
| INTO v_parent_schema, v_parent_tablename, v_parent_oid, v_parent_owner | ||
| FROM pg_catalog.pg_class c | ||
| JOIN pg_catalog.pg_namespace n ON c.relnamespace = n.oid | ||
| WHERE n.nspname = split_part(v_row.parent_table, '.', 1)::name | ||
| AND c.relname = split_part(v_row.parent_table, '.', 2)::name; | ||
|
|
||
| IF v_parent_owner != current_role THEN | ||
| RAISE WARNING 'Child partition creation skipped for parent table % owner is % but current role is %', v_row.parent_table, v_parent_owner, current_role; | ||
| CONTINUE; | ||
| END IF; | ||
|
|
||
| -- Always returns the default partition first if it exists | ||
| SELECT partition_tablename INTO v_default_tablename | ||
| FROM @[email protected]_partitions(v_row.parent_table, p_include_default := true) LIMIT 1; | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I don't think this is accounting for role inheritance/group membership. It's just looking to see if the name of the owner simply matches the name of the current role. If a role is a member of another role, it's considered an owner of all of the same objects.
Also doesn't account for if a superuser is running it, which should be able to succeed as well.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you ever seen a proper setup with different Owner of Partitions?
You'll usually want to have the same owner.
Of course does run_maintenance work as a superuser but the background worker will fail to drop partitions owned by postgres.
And postgres might have not the same default privileges as inheritance/group membership is not taken into account with default privileges.
Would you like to add a new config parameter "ensure_same_partition_owner"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pg_partman already has a setting to force ownership/permissions to be passed down from the parent. If you set
inherit_privilegestotrueinpart_configit will do this.I'm not 100% on what ownership PG does by default for partitioned tables, so I'll have to test it out what happens when another role in the same group or the superuser adds a child. But by default, privileges are not inherited to children so users must go through the parent to access the data. Inheriting privileges allows the users of the table to by-pass the read/write penalties of going through the parent if they happen to know what the child table name is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Owner is the role that executes the maintenance function and that's a mess.
If inherit_privileges=true changes the owner, please make it default.