Repository navigation
Add yescrypt support for pw_hash function - #1458
Conversation
|
I deployed this change in my environment, had no problem in development, but now I observe crash of the puppetserver once in a while in a test environment when I execute an agent with this new hash function Not sure what the problem is, but it is clearly not ready for production use! |
|
OK, problem was not with the function, but with what I was passing to the function. I was within an No problem since removing the unwrap: I haven’t tested, but I suspect this is also a problem with other hash algorithms. |
|
Hi, Thanks for your job :-) |
|
Thank you for the submission, @teluq-pbrideau and for the subsequent fixes! I'm going through old PRs and trying to find out if they are still issues for people. Are you still needing this PR reviewed and merged up? |
|
Yes, still need review and merge if possible! Thanks! |
|
Thank you for the confirmation @teluq-pbrideau ! We'll keep it open and add to the list for review. |
|
@teluq-pbrideau : I just ran the Spec tests and it seems that the Rubocop check failed with an error around the use of
|
e5b64d8 to
4b3abe4
Compare
|
@jst-cyr Fixed and rebased. Thanks for moving this forward! |
|
Thank you @teluq-pbrideau for the fix! I reran the CI here and it looks like a lot more errors showing in the CI run: https://github.com/puppetlabs/puppetlabs-stdlib/actions/runs/30543857265/job/90998927150?pr=1458 |
4b3abe4 to
c4fd964
Compare
|
@jst-cyr Oh yes, my change had the |
|
CI test PR created to run tests for this PR: #1487 |
|
I rebased the PR and ran acceptance tests. Results: All green! Still requires a code review by engineering, but tests look good. |
378af62 to
0e7790f
Compare
|
Hey @teluq-pbrideau : I ran the spec tests against your latest changes, but they seem to have broken the unit tests. I didn't run acceptance tests because of that. You can see the full failed CI run here: https://github.com/puppetlabs/puppetlabs-stdlib/actions/runs/41106770030/job/129569442382?pr=1458 This doesn't look like it's caused by your change. I'm seeing that we are having nightly failures too, starting a few days ago. I'm going to try to track down with engineering what's going on. |
|
@jst-cyr Thanks. I tried to run the tests on my side just to be sure, and as you thought, all seems OK: |
|
Tests for this PR are being executed in #1506 |
|
✅ Acceptance Test Results: https://github.com/puppetlabs/puppetlabs-stdlib/actions/runs/44908951564?pr=1506 All acceptance tests are green, so testing looks good. Still needs engineering review on latest changes. |
|
Thanks @jst-cyr for all your help and patience on this PR! Here is what I discovered while implementing this: Yescrypt is stricter on its salt than bcrypt. The salt must be an exact byte length, without residual bits... For example: In this example,
A six-character encoded salt contains 36 bits. The salt In the case of bcrypt, the salt is simply changed to be valid. Provided Salt: Not sure if it is the ruby implementation that differ, or the actual yescrypt code... What to do?I actually raised an error to the user in the current implementation. But maybe I should normalize the string instead of raising an error to the user? I would like to have engineering input on that! It is probably be cleaner than failing to the user when the salt is slightly invalid... |
|
With this new change, no error would be raised if a slightly invalid salt is created with |
98a7942 to
aa4ff82
Compare
|
Thanks for the update @teluq-pbrideau , and I agree that we should have engineering include these details in the review to confirm if this is the approach that they feel should be taken. Your reasoning seems sound to me, to align with |
span786
left a comment
There was a problem hiding this comment.
Thanks @teluq-pbrideau, this has come a long way. The rework from my last comment is all in: the yescrypt-specific probe is gone, it uses #1505's prefix check, the spec is gated on crypt_supports?, and yescrypt stays off the Commons Codec path on JRuby.
On your normalize-or-raise question: normalizing is the right call. It's deterministic, so the same input always gives the same hash and runs stay idempotent, and it matches what libxcrypt already does silently for bcrypt. I checked the logic against real libxcrypt (plain Ruby String#crypt in a ruby:3.2-slim container):
$y$j9T$abcdef→*0,$y$j9T$abcde.→ valid, and$y$j9T$abcde1(what your mask turnsabcdefinto) → valid.$y$j9T$salt.salt→*0. The choppedsalt.salandsalt.salt.sal/produce exactly the hashes your spec expects, and so does plainsalt.$y$abc$salt→*0, which your code correctly reports as "invalid yescrypt parameters".
That matches libxcrypt's decode64, which needs at least one full byte per group and zero leftover bits.
Before this can merge:
- Rebase on
main(blocking).pw_hash.rbnow conflicts withmain. af52256 (MODULES-12031, rubocop fixes under the template profile) added a trailing comma to the'bcrypt-y'entry, so after the rebase the new'yescrypt'entry needs a trailing comma too. - Anchor the yescrypt salt pattern and stop stripping characters (blocking). See the inline comments. Right now the pattern is only anchored at the start, so anything can follow a valid prefix, and the normalizer then deletes the characters that don't belong. For example,
j9T$ab#cdquietly hashes with saltabcd, andj9T$salt$junkwithsaltjunk. MD5 and SHA reject salts like these with "characters in salt must ...". yescrypt should reject them the same way instead of hashing with a salt the user didn't give. Keep the trailing-bits normalization; only invalid characters should be an error. A spec for this would be good, e.g.j9T$ab#cdraisingcharacters in salt must match. - CI on the new head. The normalization commit (aa4ff82) came after the green acceptance run in #1506, so once you've rebased we'll rerun the spec tests and acceptance through a CI test PR.
Non-blocking: REFERENCE.md isn't regenerated. It's fine to leave that to release prep, or to run bundle exec rake strings:generate:reference if you prefer.
| 'bcrypt-x' => { prefix: '2x', salt: %r{^(0[4-9]|[12][0-9]|3[01])\$[./A-Za-z0-9]{22}} }, | ||
| 'bcrypt-y' => { prefix: '2y', salt: %r{^(0[4-9]|[12][0-9]|3[01])\$[./A-Za-z0-9]{22}} } | ||
| 'bcrypt-y' => { prefix: '2y', salt: %r{^(0[4-9]|[12][0-9]|3[01])\$[./A-Za-z0-9]{22}} }, | ||
| 'yescrypt' => { prefix: 'y', salt: %r{^[./A-Za-z0-9]+\$[./A-Za-z0-9]{0,86}} } |
There was a problem hiding this comment.
This pattern is only anchored at the start, and ^ also matches after a newline. So j9T$ab#cd and j9T$salt$junk both pass, and the gsub below then quietly removes the invalid characters. Anchoring the whole value makes yescrypt reject bad characters the way MD5 and SHA do (the default pattern is \A[a-zA-Z0-9./]+\z):
| 'yescrypt' => { prefix: 'y', salt: %r{^[./A-Za-z0-9]+\$[./A-Za-z0-9]{0,86}} } | |
| 'yescrypt' => { prefix: 'y', salt: %r{\A[./A-Za-z0-9]+\$[./A-Za-z0-9]{0,86}\z} }, |
The trailing comma is for the rubocop profile that's now on main (see the conflict with af52256).
5beb337 to
aca6dc3
Compare
Co-authored-by: Saurabh Pandit <139841984+span786@users.noreply.github.com>
Co-authored-by: Saurabh Pandit <139841984+span786@users.noreply.github.com>
aca6dc3 to
86e8734
Compare
|
Tests for this PR are being executed in #1510 |
|
🛑 Acceptance Test Results: https://github.com/puppetlabs/puppetlabs-stdlib/actions/runs/47011715924?pr=1510 @teluq-pbrideau : The new changes seem to have contradicted the Rubocop style rules. |
Co-authored-by: Saurabh Pandit <139841984+span786@users.noreply.github.com>
86e8734 to
16566ad
Compare
|
Ok, now both tests should pass, they at least pass locally @jst-cyr Sorry, I should have tested them before. |
|
No worries, @teluq-pbrideau ! I'll get those tests kicked off |
|
Tests for this PR are being executed in #1511 |
|
✅ ** Acceptance Test Results:** https://github.com/puppetlabs/puppetlabs-stdlib/actions/runs/47217159408?pr=1511 We have a full green across the board for the latest changes. Good for next round of review. |
There was a problem hiding this comment.
Thanks @teluq-pbrideau, all three points from my last review are in:
- Rebased on
main, and the'yescrypt'entry has its trailing comma. - The salt pattern is anchored with
\A...\zand thegsubis gone, so invalid characters are now rejected (j9T$sa#ltraisescharacters in salt must match) and only the trailing-bits normalization remains. The bit masking matches libxcrypt's little-endiandecode64, and the expected hashes in the spec match what I got from real libxcrypt last time. - CI on the current head is green across the board in #1511 (spec and acceptance).
Approving. Two non-blocking notes, fine as a follow-up:
- Error message on DES-only crypt(3) (inline). Where crypt(3) falls back to DES instead of returning NULL, as on macOS or Windows, a valid yescrypt call reports
invalid yescrypt parametersinstead ofsystem does not support enhanced salts. Linux is unaffected: libxcrypt without yescrypt (e.g. Rocky 8's 4.1.1) returns NULL, so you correctly get the "enhanced salts" error there. A matching spec would beit { is_expected.to run.with_params('password', 'yescrypt', 'j9T$salt').and_raise_error(Puppet::ParseError, %r{system does not support enhanced salts}) }in the "weak String#crypt implementation" context. REFERENCE.md: the regeneration also drops thestdlib::crc32Note(its source has@notebefore@summary, which this puppet-strings version doesn't render). That's unrelated to this PR, and release prep regenerates the file anyway.
| unless result&.start_with?("$#{hash_type[:prefix]}$") | ||
| if args[1].casecmp('yescrypt').zero? | ||
| yescrypt_probe = crypt.call('', '$y$j9T$') | ||
| raise Puppet::ParseError, 'system does not support enhanced salts' if yescrypt_probe.nil? |
There was a problem hiding this comment.
Non-blocking: a DES-only crypt(3) (macOS, Windows) doesn't return NULL here. It returns a DES hash (''.crypt('$y$j9T$') gives $yRDSVYBbSTik on macOS), so this guard passes and a valid call ends up raising invalid yescrypt parameters. Checking the prefix as well keeps the "enhanced salts" error for any system without yescrypt:
| raise Puppet::ParseError, 'system does not support enhanced salts' if yescrypt_probe.nil? | |
| raise Puppet::ParseError, 'system does not support enhanced salts' unless yescrypt_probe&.start_with?('$y$') |
Summary
Add support for yescrypt hashing algorithm in the pw_hash function.
Additional Context
The underlying OS must support
yescrypt. For exemple, it does not work on RockyLinux 8, because libxcrypt does not support it, but it does work in RockyLinux 9.Related Issues (if any)
#1445
Checklist
puppet apply)