-
Notifications
You must be signed in to change notification settings - Fork 879
Allow ADMIN OPTION holders to manage Group Role membership #10315
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
dpage
wants to merge
4
commits into
pgadmin-org:master
Choose a base branch
from
dpage:fix/9450-role-membership-admin-option
base: master
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
4 commits
Select commit
Hold shift + click to select a range
bd252ca
fix: correct existingSecret path in Helm deployment template (#10214)
dpage 1f8a075
fix: place CONCURRENTLY correctly in generated REINDEX SQL (#10251)
dpage 4173ddf
fix: allow ADMIN OPTION holders to manage Group Role membership (#9450)
dpage 0df344b
fix: validate membership-only update against pre-mutation request keys
dpage 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
11 changes: 10 additions & 1 deletion
11
web/pgadmin/browser/server_groups/servers/roles/templates/roles/sql/default/permission.sql
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 |
|---|---|---|
| @@ -1,5 +1,14 @@ | ||
| SELECT | ||
| rolname, rolcanlogin, rolsuper | ||
| rolname, rolcanlogin, rolsuper, | ||
| EXISTS ( | ||
| SELECT 1 FROM pg_catalog.pg_auth_members am | ||
| WHERE am.roleid = {{ rid }}::OID | ||
| AND am.member = ( | ||
| SELECT oid FROM pg_catalog.pg_roles | ||
| WHERE rolname = current_user | ||
| ) | ||
| AND am.admin_option | ||
| ) AS has_admin_option | ||
| FROM | ||
| pg_catalog.pg_roles | ||
| WHERE oid = {{ rid }}::OID |
116 changes: 116 additions & 0 deletions
116
...pgadmin/browser/server_groups/servers/roles/tests/test_role_check_permission_unit_test.py
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 |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| ########################################################################## | ||
| # | ||
| # pgAdmin 4 - PostgreSQL Tools | ||
| # | ||
| # Copyright (C) 2013 - 2026, The pgAdmin Development Team | ||
| # This software is released under the PostgreSQL Licence | ||
| # | ||
| ########################################################################## | ||
|
|
||
| from unittest.mock import MagicMock | ||
|
|
||
| from pgadmin.utils.route import BaseTestGenerator | ||
| from pgadmin.browser.server_groups.servers.roles import RoleView | ||
|
|
||
|
|
||
| class RoleCheckPermissionTest(BaseTestGenerator): | ||
| """Unit tests for RoleView._check_permission's ADMIN OPTION carve-out. | ||
|
|
||
| A role holder who is neither a superuser nor a CREATEROLE holder, but | ||
| who has been granted ADMIN OPTION on the specific role being updated, | ||
| should be allowed through the permission gate so they can manage that | ||
| role's membership - but only for 'update', never for 'drop', and the | ||
| view should record that the request must be restricted to membership | ||
| changes only. | ||
| """ | ||
| scenarios = [ | ||
| ('Check Role Node', dict(url='/browser/role/obj/')) | ||
| ] | ||
|
|
||
| def setUp(self): | ||
| pass | ||
|
|
||
| def runTest(self): | ||
| view = RoleView(cmd=None) | ||
| view.manager = MagicMock() | ||
|
|
||
| # Plain user, no admin option: update is forbidden. | ||
| view.manager.user_info = { | ||
| 'is_superuser': False, 'can_create_role': False, 'id': 5 | ||
| } | ||
| view.has_admin_option = False | ||
| self.assertTrue(view._check_permission(True, 'update', {'rid': 10})) | ||
| self.assertFalse(view.membership_only_update) | ||
|
|
||
| # Same user, but with ADMIN OPTION on the target role: allowed | ||
| # through, flagged as membership-only. | ||
| view.has_admin_option = True | ||
| self.assertFalse(view._check_permission(True, 'update', {'rid': 10})) | ||
| self.assertTrue(view.membership_only_update) | ||
|
|
||
| # ADMIN OPTION does not extend to dropping the role. | ||
| self.assertTrue(view._check_permission(True, 'drop', {'rid': 10})) | ||
|
|
||
| # Superusers are unaffected by the ADMIN OPTION check. | ||
| view.manager.user_info = { | ||
| 'is_superuser': True, 'can_create_role': False, 'id': 5 | ||
| } | ||
| view.has_admin_option = False | ||
| self.assertFalse(view._check_permission(True, 'update', {'rid': 10})) | ||
|
|
||
| def tearDown(self): | ||
| pass | ||
|
|
||
|
|
||
| class RoleMembersOnlyUpdateRequestKeysTest(BaseTestGenerator): | ||
| """Regression test for the membership-only update guard. | ||
|
|
||
| _validate_rolemembers() mutates the request dict in place, adding | ||
| derived keys ('rol_members_list', 'rol_members_revoked_list') that | ||
| the client never sent. The membership-only update guard in | ||
| RoleView.update() must check the client-supplied keys captured | ||
| before that mutation (self.request_keys), not the mutated dict, | ||
| otherwise a valid ADMIN OPTION request containing only 'rolmembers' | ||
| would be wrongly rejected as forbidden. | ||
| """ | ||
| scenarios = [ | ||
| ('Check Role Node', dict(url='/browser/role/obj/')) | ||
| ] | ||
|
|
||
| def setUp(self): | ||
| pass | ||
|
|
||
| def runTest(self): | ||
| view = RoleView(cmd=None) | ||
| view.manager = MagicMock() | ||
| view.manager.version = 170000 | ||
|
|
||
| data = { | ||
| 'rolmembers': { | ||
| 'added': [ | ||
| {'role': 'member_role', 'admin': True, | ||
| 'inherit': True, 'set': True} | ||
| ], | ||
| 'changed': [], | ||
| 'deleted': [] | ||
| } | ||
| } | ||
|
|
||
| # Mirror what validate_request() does: capture the client | ||
| # supplied keys before running the validators. | ||
| request_keys = set(data) | ||
|
|
||
| # This mutates 'data' in place, adding derived keys. | ||
| self.assertIsNone(view._validate_rolemembers(10, data)) | ||
| self.assertIn('rol_members_list', data) | ||
|
|
||
| # The mutated dict is no longer a subset of {'rolmembers'} ... | ||
| self.assertFalse(set(data) <= {'rolmembers'}) | ||
|
|
||
| # ... but the keys captured before mutation still are, so the | ||
| # membership-only guard (which must use request_keys) allows | ||
| # the request through instead of returning 403. | ||
| self.assertTrue(request_keys <= {'rolmembers'}) | ||
|
|
||
| def tearDown(self): | ||
| pass | ||
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
Oops, something went wrong.
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.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Exercise the membership-only authorization guard.
This test does not invoke
validate_request()orRoleView.update(). If Line 1049 changes back toset(self.request), all current assertions still pass.Send a
rolmembers-only update as an ADMIN OPTION user. Assert that the update does not return 403.🤖 Prompt for AI Agents