Skip to content

SCRAM-SHA-256 support for states.postgres_user #51217

Closed

Description

@OrangeDog

Current implementation either sends and compares plaintext or an md5hash.
There's no way to send plaintext for the server to hash, because it also adds UNENCRYPTED to the query.

ERROR: UNENCRYPTED PASSWORD is no longer supported

Activity

  1. changed the title [-]SCRAM-SHA-1 support for states.postgres_user[/-] [+]SCRAM-SHA-256 support for states.postgres_user[/+] on Jan 17, 2019
  2. OrangeDog commented on Jan 17, 2019

    @OrangeDog
    ContributorAuthor

    Python 3 implementation of postgres' algorithm

    import base64
    import hashlib
    import hmac
    import secrets
    
    
    def scram_sha_256(password):
        # TODO: saslprep
        if not isinstance(password, (bytes, bytearray)):
            password = password.encode('utf8')
        iterations = 4096
        salt = secrets.token_bytes(16)
        salted_password = hashlib.pbkdf2_hmac('sha256', password, salt, iterations)
        stored_key = hmac.new(salted_password, b'Client Key', 'sha256').digest()
        stored_key = hashlib.sha256(stored_key).digest()
        server_key = hmac.new(salted_password, b'Server Key', 'sha256').digest()
        return 'SCRAM-SHA-256$%d:%s$%s:%s' % (
            iterations,
            base64.b64encode(salt).decode('ascii'),
            base64.b64encode(stored_key).decode('ascii'),
            base64.b64encode(server_key).decode('ascii')
        )
  3. dwoz commented on Jan 17, 2019

    @dwoz
    Contributor

    @OrangeDog Can you provide me with an example state that I can use to test this?

  4. added
    needs-more-info
    on Jan 17, 2019
  5. added this to the Blocked milestone on Jan 17, 2019
  6. OrangeDog commented on Jan 18, 2019

    @OrangeDog
    ContributorAuthor

    @dwoz not sure what you mean by example state, but see linked commit.

    You can see from saltstack's source code that the states.postgres_user state is only able to compare and set unencrypted or MD5 passwords. To use SCRAM passwords, PostgreSQL 10 or higher is required.

  7. minusf commented on Sep 12, 2019

    @minusf
    Contributor

    sadly without SCRAM support the current postgres_user state has very limited usefulness. please also let the module work with already encrypted passwords like:

    postgres_user.present:
      name: blah
      password: "SCRAM-SHA-256$4096:lKj35tB36e3LV3fVaW3hlw==$NO7qHn5U1C [...] XDDEcI="
    
  8. added
    Feature
    and removed
    needs-more-info
    on Sep 12, 2019
  9. modified the milestones: Blocked, Approved on Sep 12, 2019
  10. stale commented on Jan 7, 2020

    @stale

    This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

    If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue.

  11. OrangeDog commented on Jan 7, 2020

    @OrangeDog
    ContributorAuthor

    Still a desired feature.

  12. 1 remaining item

  13. OrangeDog commented on Nov 10, 2020

    @OrangeDog
    ContributorAuthor

    There doesn't seem to be any python library providing just saslprep.
    There is an implementation in pymongo.

  14. added a commit that references this issue on Mar 1, 2021
    1e219c9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

AluminiumFeature

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions