-
Notifications
You must be signed in to change notification settings - Fork 94
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
postgresql_privs - Improved roles management #502
postgresql_privs - Improved roles management #502
Conversation
Obviously the string "X.X.X" in comments added must be replaced with the collection release that will include this PR. |
Ready for review |
|
||
if len(roles) == 1 and not role_exists(module, conn.cursor, roles[0]): | ||
roles = [] | ||
roles_raw = p.roles.split(',') |
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.
Role names containing a ,
are supported by PostgreSQL. The safest way to deal with that would probably be to extend the roles
module argument to also take a list of strings, something like:
if isinstance(p.roles, list):
roles_raw = list(p.roles)
else:
roles_raw = p.roles.split(',')
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.
Thanks for advice.
I tried to implement it but at last I had to revert.
The approach is possible but Ansible Module needs a fixed type for parameter, that can be in this case 'str' or 'list':
- If I use 'str' and provide a 'list', the list is converted to str so an 'eval' is needed to convert in list again (very dangerous).
- If I use 'list' and provide an 'str', it is converted to a list of sigle 'str' chars or to a list of 'str' words (unfortunely with commas considered as a separate word, as "['role1', ',', 'role2']).
The only way usable is use 'list' but this implies to forbid comma separated list, so allowing only one element as string or multiple elements in a list (as done by other core modules as yum, apt, etc.).
This is surely possible, but resulting in a breaking change, so I'm unable to implement it in a minor change PR.
I leaved the commits with modified code in branch history for reference in future.
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.
@RealGreenDragon
We could still make this work by making the ansible module argument type='raw'
, which disables type checking by ansible for that. Then we should be able to check the type "on our own" with something like to code example from my comment above.
I'm unresolving this in case you want to implement it in this PR. Doing it in some other PR would also be fine for me.
I fixed what requested, thanks for all advices. Seems RHEL tests fails now for "500: Internal server error": can someone check? |
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.
@RealGreenDragon thanks for pushing forward
So do we expect these changes keep backwards compatibility? i.e. users playbooks will not break after upgrading the collection?
Co-authored-by: Andrew Klychkov <[email protected]>
Co-authored-by: Andrew Klychkov <[email protected]>
@Andersson007 I confirm this PR is a minor change. I only added other implicit roles (before not supported) and fixed idempotence when roles=PUBLIC (now it reports changed only when really changed). In addiction I refactored a bit 'roles' parameter management, but without breacking changes. |
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.
PostgreSQL allows almost all role names when quoted:
test=# drop role "SESSION_USER";
DROP ROLE
Time: 2.079 ms
test=# create role "PUBLIC";
CREATE ROLE
Time: 1.997 ms
test=# create role "CURRENT_USER";
CREATE ROLE
Time: 1.829 ms
test=# create role "CURRENT_ROLE";
CREATE ROLE
Time: 1.719 ms
test=# create role "SESSION_ROLE";
CREATE ROLE
Time: 1.854 ms
test=# create role "public";
ERROR: role name "public" is reserved
LINE 1: create role "public";
^
Time: 1.049 ms
test=# create role "current_user";
CREATE ROLE
Time: 2.511 ms
So if someone was using such an confusing role name, this PR would break it. But I think we can treat it as a minor change.
Co-authored-by: betanummeric <[email protected]>
@betanummeric All advices implemented. |
I approved the PR and it's about general stuff. |
@Andersson007 assuming the open conversation from @betanummeric is addressed, i'm ok with merging it |
merged as per @Andersson007's comment on matrix |
Yes, this looks ready to be merged. |
@RealGreenDragon thanks for the great contribution! |
SUMMARY
I checked that when privileges are granted/revoked to/from PUBLIC role postgresql_privs module is not idempotent (always return changed=True).
The cause are following checks added in PR #858 (issue #857):
community.postgresql/plugins/modules/postgresql_privs.py
Line 819 in 7199adc
community.postgresql/plugins/modules/postgresql_privs.py
Line 1123 in 7199adc
Such checks is useless, as:
As in manipulate_privs function aclitems before and after queries are compared, any grant/revoke to/from every role (included PUBLIC) is correctly detected. If there are no changes than privileges are sure already granted/revoked (otherwise there is a serious PostgreSQL bug...).
Documentation about privileges and ACLs is here (for PostgreSQL 15, similar in other versions):
My PR improve general roles management in postgresql_privs module, following the changelog:
ISSUE TYPE
COMPONENT NAME
postgresql_privs
ADDITIONAL INFORMATION
Example of ACLs changes when GRANT CREATE ON DATABASE to PUBLIC: