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

postgresql_user is not idempotent when password is a SCRAM hash #301

Closed
benformosa opened this issue Jun 27, 2022 · 2 comments · Fixed by #302
Closed

postgresql_user is not idempotent when password is a SCRAM hash #301

benformosa opened this issue Jun 27, 2022 · 2 comments · Fixed by #302

Comments

@benformosa
Copy link
Contributor

SUMMARY

When providing the password parameter as a SCRAM-256 hash, postgresql_user will always give a result of changed.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

community.postgresql.postgresql_user

ANSIBLE VERSION
ansible [core 2.12.2]
  config file = /home/ben/.ansible.cfg
  configured module search path = ['/home/ben/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.8/site-packages/ansible
  ansible collection location = /home/ben/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.8.12 (default, Sep 16 2021, 10:46:05) [GCC 8.5.0 20210514 (Red Hat 8.5.0-3)]
  jinja version = 2.10.3
  libyaml = True
COLLECTION VERSION

# /home/ben/.ansible/collections/ansible_collections
Collection           Version
-------------------- -------
community.postgresql 2.1.5
CONFIGURATION
DEFAULT_HOST_LIST(/home/ben/.ansible.cfg) = ['/home/ben/git/ansible/inventory.ini']
DEFAULT_ROLES_PATH(/home/ben/.ansible.cfg) = ['/home/ben/.ansible/roles', '/home/ben/git/ansible/roles', '/home/ben/git', '/home/ben/git/ansible']
GALAXY_SERVER_LIST(/home/ben/.ansible.cfg) = ['galaxy']
OS / ENVIRONMENT

RHEL 8.6

PostgreSQL 13.7 (RHEL App Stream postgresql:13)

STEPS TO REPRODUCE

Create a user with a task like:

- name: Create user
  community.postgresql.postgresql_user:
    name: scrampassword
    password: SCRAM-SHA-256$4096:XkAEs3QAEZNaIZ49QgluOw==$P62LBGrtmFn7FuWxNJKt3ZlfuteVVV2AZmETo5EkFEI=:dJyvi8FA4emhPhsH/ND7AxSxIc2URCiGUspmdV5MGW8=
  become: true
  become_user: postgres

Full example playbook:
https://gist.github.com/benformosa/e6b95b09f0d55377738a6ff85d4189c9#file-play_postgres_user-yml

EXPECTED RESULTS

The second time the postgresql_user task is run, it should not show as changed.

ACTUAL RESULTS

The result is changed both times the task is run.

TASK [Create users] ******************************************************************************************************************************************
changed: [localhost] => (item=clearpassword)
changed: [localhost] => (item=scrampassword)

TASK [Create users - again] **********************************************************************************************************************************
ok: [localhost] => (item=clearpassword)
changed: [localhost] => (item=scrampassword)

Full log:
https://gist.github.com/benformosa/e6b95b09f0d55377738a6ff85d4189c9#file-play_postgres_user-log

Full log with -vvv:
https://gist.github.com/benformosa/e6b95b09f0d55377738a6ff85d4189c9#file-play_postgres_user_vvv-log

Possible solution

A test could be added to check if the stored password is the same as the password parameter, similar to what is done if the given password starts with md5:

elif (password.startswith('md5') and len(password) == 32 + 3) or encrypted == 'UNENCRYPTED':
if password != current_role_attrs['rolpassword']:
pwchanging = True

@matthbakeredb
Copy link

This would be useful addition. Currently doing exactly this in a local fork. Thanks for submitting this!

@Andersson007
Copy link
Collaborator

@matthbakeredb thanks for the feedback, i think we'll merge the PR this week, there's one thing that needs to be added

Andersson007 added a commit that referenced this issue Aug 2, 2022
* idempotent when password is scram hashed

Add a test to user_should_we_change_password to check if the password parameter is a SCRAM-256 hash, and if it is the same as the stored password.

Fixes #301

* Update plugins/modules/postgresql_user.py

Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>
patchback bot pushed a commit that referenced this issue Aug 2, 2022
* idempotent when password is scram hashed

Add a test to user_should_we_change_password to check if the password parameter is a SCRAM-256 hash, and if it is the same as the stored password.

Fixes #301

* Update plugins/modules/postgresql_user.py

Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>
(cherry picked from commit bfa3677)
Andersson007 pushed a commit that referenced this issue Aug 2, 2022
* idempotent when password is scram hashed

Add a test to user_should_we_change_password to check if the password parameter is a SCRAM-256 hash, and if it is the same as the stored password.

Fixes #301

* Update plugins/modules/postgresql_user.py

Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>
(cherry picked from commit bfa3677)

Co-authored-by: Ben Formosa <ben.formosa@gmail.com>
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 a pull request may close this issue.

3 participants