-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Refactor WireGuard key management #14803
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Claude finished @jackivanov's task —— View job PR Review: Refactor WireGuard key managementThis is a significant security improvement that moves WireGuard key generation from remote servers to the local control node. Overall, this is well-implemented with good test coverage, but I've identified several areas for consideration. Review Checklist:
🔒 Security Assessment - EXCELLENTStrengths:
🐛 Code Quality & Potential IssuesStrengths:
Areas of Concern:
⚡ Performance ConsiderationsGood:
Potential Optimization:
🧪 Test Coverage Assessment - VERY GOODComprehensive Testing (
Test Quality Highlights:
Minor Test Improvement Suggestions:
📝 Architecture & DesignExcellent Design Decisions:
Task Structure (
🔧 Minor Recommendations
✅ Overall AssessmentThis is a high-quality security improvement that addresses the original issue effectively. The implementation is robust, well-tested, and follows good security practices. The custom Ansible module is well-designed and the integration is seamless. Recommendation: APPROVE - This significantly improves Algo's security posture while maintaining usability and reliability. Key Achievements:
|
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>
…ible 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
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>
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>
afadef9 to
7bec66d
Compare
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>
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>
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.
Description
This PR updates WireGuard key management so that all private, public, and preshared keys are generated and handled locally on the Ansible control node using Ansible modules. Keys are never generated on remote servers, and public keys are only updated if their content changes. The process is now more secure, reliable, and idempotent.
Motivation and Context
Previously, WireGuard keys were generated on remote servers, which could expose private keys and make management harder. By generating all keys locally, we improve security (private keys never leave the control node), simplify troubleshooting, and ensure consistent, repeatable deployments. This also makes the setup easier to audit and maintain.
Fixes #14693
How Has This Been Tested?
I tested these changes by deploying a server to AWS Lightsail and connecting to it using WireGuard. The keys were generated locally, and the connection was successful. All Ansible tasks completed without errors, and the resulting configuration worked as expected.
Types of changes
Checklist: