algo/roles
Jack Ivanov 5214c5f819
Refactor WireGuard key management (#14803)
* Refactor WireGuard key management: generate all keys locally with Ansible modules

- Move all WireGuard key generation from remote hosts to local execution via Ansible modules
- Enhance x25519_pubkey module for robust, idempotent, and secure key handling
- Update WireGuard role tasks to use local key generation and management
- Improve error handling and support for check mode

* Improve x25519_pubkey module code quality and add integration tests

Code Quality Improvements:
- Fix import organization and Ruff linting errors
- Replace bare except clauses with practical error handling
- Simplify documentation while maintaining useful debugging info
- Use dictionary literals instead of dict() calls for better performance

New Integration Test:
- Add comprehensive WireGuard key generation test (test_wireguard_key_generation.py)
- Tests actual deployment scenarios matching roles/wireguard/tasks/keys.yml
- Validates mathematical correctness of X25519 key derivation
- Tests both file and string input methods used by Algo
- Includes consistency validation and WireGuard tool integration
- Addresses documented test gap in tests/README.md line 63-67

Test Coverage:
- Module import validation
- Raw private key file processing
- Base64 private key string processing
- Key derivation consistency checks
- Optional WireGuard tool validation (when available)

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* Trigger CI build for PR #14803

Testing x25519_pubkey module improvements and WireGuard key generation changes.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* Fix yamllint error: add missing newline at end of keys.yml

Resolves: no new line character at the end of file (new-line-at-end-of-file)

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* Fix critical binary data corruption bug in x25519_pubkey module

Issue: Private keys with whitespace-like bytes (0x09, 0x0A, etc.) at edges
were corrupted by .strip() call on binary data, causing 32-byte keys to
become 31 bytes and deployment failures.

Root Cause:
- Called .strip() on raw binary data unconditionally
- X25519 keys containing whitespace bytes were truncated
- Error: "got 31 bytes" instead of expected 32 bytes

Fix:
- Only strip whitespace when processing base64 text data
- Preserve raw binary data integrity for 32-byte keys
- Maintain backward compatibility with both formats

Addresses deployment failure: "Private key file must be either base64
or exactly 32 raw bytes, got 31 bytes"

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* Add inline comments to prevent binary data corruption bug

Explain the base64/raw file detection logic with clear warnings about
the critical issue where .strip() on raw binary data corrupts X25519
keys containing whitespace-like bytes (0x09, 0x0A, etc.).

This prevents future developers from accidentally reintroducing the
'got 31 bytes' deployment error by misunderstanding the dual-format
key handling logic.

---------

Co-authored-by: Dan Guido <dan@trailofbits.com>
Co-authored-by: Claude <noreply@anthropic.com>
2025-08-03 18:24:12 -07:00
..
client Ansible upgrade 6.1 (#14500) 2022-07-30 15:01:24 +03:00
cloud-azure Fix AWS CloudFormation linter warnings (#14294) (#14782) 2025-08-03 04:49:40 -04:00
cloud-cloudstack/tasks feat: Add comprehensive performance optimizations to reduce deployment time by 30-60% 2025-08-03 16:42:17 -07:00
cloud-digitalocean/tasks Fix DigitalOcean cloud-init compatibility and deprecation warnings (#14801) 2025-08-03 14:25:47 -04:00
cloud-ec2 feat: Add AWS credentials file support (#14778) 2025-08-03 15:07:57 -06:00
cloud-gce/tasks feat: Add comprehensive performance optimizations to reduce deployment time by 30-60% 2025-08-03 16:42:17 -07:00
cloud-hetzner/tasks Fix hetzner module (#14698) 2024-03-14 09:25:09 +01:00
cloud-lightsail Optimize GitHub Actions workflows for security and performance (#14769) 2025-08-02 23:31:54 -04:00
cloud-linode Ansible upgrade 6.1 (#14500) 2022-07-30 15:01:24 +03:00
cloud-openstack/tasks feat: Add comprehensive performance optimizations to reduce deployment time by 30-60% 2025-08-03 16:42:17 -07:00
cloud-scaleway Ansible upgrade 6.1 (#14500) 2022-07-30 15:01:24 +03:00
cloud-vultr/tasks feat: add support for vultr api v2 (#14773) 2025-08-03 14:56:40 -06:00
common Fix IPv6 address selection on BSD systems (#14786) 2025-08-03 17:15:27 -07:00
dns feat: Add comprehensive performance optimizations to reduce deployment time by 30-60% 2025-08-03 16:42:17 -07:00
local/tasks fix: Fix shellcheck POSIX sh issue and make ansible-lint stricter (#14789) 2025-08-03 07:04:04 -04:00
ssh_tunneling Fix DigitalOcean cloud-init compatibility and deprecation warnings (#14801) 2025-08-03 14:25:47 -04:00
strongswan feat: Add comprehensive performance optimizations to reduce deployment time by 30-60% 2025-08-03 16:42:17 -07:00
wireguard Refactor WireGuard key management (#14803) 2025-08-03 18:24:12 -07:00