Repository navigation
Coerce keysize to int in wheel key.gen - #69748
Merged
Merged
Conversation
wheel.key.gen passed keysize straight to salt.crypt.gen_keys, which feeds it to rsa.generate_private_key (key_size must be an int). The salt-api rest_cherrypy POST /keys endpoint passes keysize as a string (cherrypy form values are always strings), so a request specifying a keysize raised TypeError and returned a 500 (saltstack#56425). Coerce keysize to an int and enforce the 2048-bit minimum that gen's docstring already documents. Fixes saltstack#56425
twangboy
approved these changes
Jul 15, 2026
dwoz
approved these changes
Aug 7, 2026
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Coerces the
keysizeargument ofwheel.key.gen(and thereforegen_accept, which forwards to it) to an integer and enforces the documented 2048-bit minimum, so the salt-apirest_cherrypyPOST /keysendpoint can generate keys of a requested size.What issues does this PR fix or reference?
Fixes #56425
Previous Behavior
wheel.key.genpassedkeysizeverbatim tosalt.crypt.gen_keys, which hands it torsa.generate_private_key(whosekey_sizemust be an int). cherrypy form values are always strings, so aPOST /keysrequest specifying akeysize(e.g.4096) reached RSA generation as"4096"and raisedTypeError, surfacing as a 500 from the endpoint. Thekeysizedocstring also promised a 2048-bit floor ("rounded up to 2048") that was never implemented.New Behavior
gencoerceskeysizeto an int and appliesmax(2048, int(keysize)), matching the long-standing docstring. String keysizes from the API now work, integer callers are unaffected (a no-op), and sub-2048 values are rounded up to 2048 as documented.Merge requirements satisfied?
changelog/56425.fixed.mdtests/pytests/unit/wheel/test_key.py: string keysize coerced to int (pins the bug), sub-2048 floored to 2048, integer keysize passes through unchangedCommits signed with GPG?
No