Sanitize SSH key whitespace to prevent validation errors #16179
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.
Strip leading and trailing whitespace from SSH keys in
validate_ssh_private_key()to handle common copy-paste scenarios where hidden newlines cause base64 decoding failures.Problem
Users encounter confusing HTTP 500 errors when creating credentials with SSH keys that contain hidden newline characters from copy-paste operations. The error manifests as
binascii.Error: Incorrect paddingin server logs, but users only see a generic 500 error.Changes
data.strip()invalidate_ssh_private_key()before callingvalidate_pem()(awx/main/validators.py:185)test_ssh_key_with_whitespace()to verify keys with leading/trailing newlines are properly sanitized and validated (awx/main/tests/unit/test_validators.py:135-151)Testing
Impact
This prevents the confusing "HTTP 500: Internal Server Error" when users paste SSH keys with accidental whitespace, improving the user experience without weakening validation.
Fixes #14219