Skip to content

Coerce keysize to int in wheel key.gen - #69748

Merged
dwoz merged 2 commits into
saltstack:3006.xfrom
ggiesen:fix-56425-keys-keysize-int
Aug 7, 2026
Merged

dwoz merged 2 commits into
saltstack:3006.xfrom
ggiesen:fix-56425-keys-keysize-int

Conversation

@ggiesen

@ggiesen ggiesen commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Coerces the keysize argument of wheel.key.gen (and therefore gen_accept, which forwards to it) to an integer and enforces the documented 2048-bit minimum, so the salt-api rest_cherrypy POST /keys endpoint can generate keys of a requested size.

What issues does this PR fix or reference?

Fixes #56425

Previous Behavior

wheel.key.gen passed keysize verbatim to salt.crypt.gen_keys, which hands it to rsa.generate_private_key (whose key_size must be an int). cherrypy form values are always strings, so a POST /keys request specifying a keysize (e.g. 4096) reached RSA generation as "4096" and raised TypeError, surfacing as a 500 from the endpoint. The keysize docstring also promised a 2048-bit floor ("rounded up to 2048") that was never implemented.

New Behavior

gen coerces keysize to an int and applies max(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?

  • Docs - not applicable (behavior now matches the existing docstring)
  • Changelog - changelog/56425.fixed.md
  • Tests written/updated - tests/pytests/unit/wheel/test_key.py: string keysize coerced to int (pins the bug), sub-2048 floored to 2048, integer keysize passes through unchanged

Commits signed with GPG?

No

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
@ggiesen
ggiesen requested a review from a team as a code owner July 10, 2026 07:40
@charzl charzl self-assigned this Jul 10, 2026
@dwoz dwoz added the test:full Run the full test suite label Jul 10, 2026
@twangboy twangboy added this to the Sulphur v3006.28 milestone Jul 15, 2026
@dwoz
dwoz merged commit 44e2148 into saltstack:3006.x Aug 7, 2026
852 of 854 checks passed

This branch was previously deployed

1 inactive deployment
ci — 07d9e8e3 Deployed Jul 29, 2026 by ggiesen via Build Onedir Packages / macOS (x86_64) #25939
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

test:full Run the full test suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants