Skip to content

Conversation

@joeywashburn
Copy link

@joeywashburn joeywashburn commented Nov 15, 2025

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 padding in server logs, but users only see a generic 500 error.

ISSUE TYPE
  • Bug, Docs Fix or other nominal change

Changes

  • Added data.strip() in validate_ssh_private_key() before calling validate_pem() (awx/main/validators.py:185)
  • Added 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

  • All existing validator tests pass (48 tests)
  • New test verifies SSH keys with leading/trailing whitespace are accepted
  • Invalid keys are still properly rejected (validated with existing tests)

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

@tvo318
Copy link
Member

tvo318 commented Jan 15, 2026

Thanks for your contribution, @joeywashburn. There is a failed CI check that I've cleared by adding the issue type information.

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.

Changes:
- Added data.strip() in validate_ssh_private_key() before calling validate_pem()
- Added test_ssh_key_with_whitespace() to verify keys with leading/trailing
  newlines are properly sanitized and validated

This prevents the confusing "HTTP 500: Internal Server Error" and
"binascii.Error: Incorrect padding" errors when users paste SSH keys with
accidental whitespace.

Fixes ansible#14219

Signed-off-by: Joey Washburn <joey@joeywashburn.com>
@jessicamack jessicamack force-pushed the fix-ssh-key-whitespace branch from 6145b18 to b83daed Compare January 21, 2026 14:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

2 participants