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

fix(crypt): Add salt to passlib calls #5252

Closed

Conversation

holmanb
Copy link
Member

@holmanb holmanb commented May 2, 2024

Proposed Commit Message

fix(crypt): Add salt to passlib calls

- Refactor multiple crypt callsites to a single Python module.
- Add tests to verify standardized behavior between passlib and crypt.

[1] https://github.com/canonical/cloud-init/issues/4791

Additional Context

It would be trivial to add openssl support as well, but this isn't a dependency in minimal images currently so probably not worth it.

In the standard library hashlib.sha512() also exists, but this isn't in the right format and I couldn't find documentation to make this compatible with crypt.

Merge type

  • Squash merge using "Proposed Commit Message"
  • Rebase and merge unique commits. Requires commit messages per-commit each referencing the pull request number (#<PR_NUM>)

- Refactor multiple crypt callsites to a single Python module.
- Add tests to verify standardized behavior between passlib and crypt.

[1] canonical#4791
@holmanb holmanb force-pushed the holmanb/match-passlib-to-crypt branch from 26e3137 to f8e5dc8 Compare May 2, 2024 00:44
Copy link
Member

@TheRealFalcon TheRealFalcon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice refactor, but is there a reason to provide our own salt? Passlib will automatically provide a salt by default.


def _passlib_crypt(secret: str, salt: str):
"""crypt.crypt() interface based on passlib"""
return passlib.hash.sha512_crypt.hash(secret, salt=salt, rounds=5000)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't BSD require bcrypt rather than sha512_crypt?

Also, this method of calling hash is deprecated. I think it should instead look something like

passlib.hash.sha512_crypt.using(salt=salt, rounds=5000).hash(secret)

@TheRealFalcon TheRealFalcon self-assigned this May 2, 2024
@holmanb
Copy link
Member Author

holmanb commented May 3, 2024

Nice refactor, but is there a reason to provide our own salt? Passlib will automatically provide a salt by default.

I guess not really then - the idea of making sure that the behavior "matches" was appealing from a testing perspective, but so long as passlib actually has a future, then I guess library defaults might be better.

Aside: before I pushed this PR I actually had an openssl implementation that also matched the passlib and crypt output, but I deleted it because I didn't want cloud-init to pull it into minimal images.

@holmanb
Copy link
Member Author

holmanb commented May 5, 2024

Doesn't BSD require bcrypt rather than sha512_crypt?

Ugh, you're right. I'm going to close this PR since there isn't much benefit to it as is, and there really isn't much code to share between the two call sites.

@holmanb holmanb closed this May 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants