-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Only open VPN ports in cloud security groups when enabled #14898
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
base: master
Are you sure you want to change the base?
Conversation
When ipsec_enabled or wireguard_enabled is false, don't open those ports in cloud provider security groups/firewalls. Previously, ports 500, 4500, and the WireGuard port were always opened regardless of which VPN protocols were actually enabled. This follows the principle of least privilege - only open ports for services that are actually running. Changes by provider: - EC2: Add CloudFormation conditions for conditional SecurityGroupIngress - Lightsail: Convert to Jinja2 template with conditional port blocks - Azure: Convert to Jinja2 template with conditional security rules - Vultr: Build firewall rules list conditionally - GCE: Build allowed list conditionally - OpenStack: Build security rules list conditionally - CloudStack: Build security rules list conditionally Note: The instance-level iptables firewall already blocked unused ports, so this change improves security posture at the cloud provider level. Fixes #14293 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Code ReviewThis PR implements conditional firewall port opening based on enabled VPN protocols, which is a solid security improvement following the principle of least privilege. The implementation is well-structured across multiple cloud providers with consistent patterns. ✅ Strengths
🔍 Code Quality Observations1. Jinja2 Template Rendering (Azure/Lightsail)The conversion of static files to # Azure deployment.json.j2 - good comma placement
}
{% if ipsec_enabled | default(true) | bool %}
,{
"name": "AllowIPSEC500",The leading comma approach works but is unconventional. While it solves the "last item" problem in JSON, consider if this might confuse future maintainers. It does work correctly though. 2. EC2 CloudFormation Implementation# Excellent use of native CloudFormation features
Conditions:
OpenIpsecPorts: \!Equals ['true', \!Ref IpsecEnabled]
OpenWireguardPorts: \!Equals ['true', \!Ref WireguardEnabled]✅ This is the correct way to do conditional resources in CloudFormation. Separating the rules into individual Minor improvement opportunity: The parameter type could be more semantic: IpsecEnabled:
Type: String # Currently
# Could be more explicit, though String works fine for CloudFormation3. Complex List Concatenation (GCE, Vultr, etc.)allowed: >-
{{
[{ 'ip_protocol': 'tcp', 'ports': [ssh_port | string] }]
+ ([{ 'ip_protocol': 'udp', 'ports': ['500', '4500'] }] if ipsec_enabled | default(true) | bool else [])
+ ([{ 'ip_protocol': 'udp', 'ports': [wireguard_port | string] }] if wireguard_enabled | default(true) | bool else [])
}}This is functionally correct but quite dense. The multi-line formatting helps readability significantly. One consideration:
That said, for the number of rules involved, this is acceptable and maintains consistency. 🐛 Potential Issues1. Missing IPv6 Handling in Some ProvidersLooking at the Vultr implementation - it correctly handles both IPv4 and IPv6: { 'protocol': 'tcp', 'port': ssh_port, 'ip': 'v4', 'cidr': '0.0.0.0/0' },
{ 'protocol': 'tcp', 'port': ssh_port, 'ip': 'v6', 'cidr': '::/0' }But GCE doesn't specify IP versions in the diff shown. Double-check that IPv6 rules work correctly across all providers. 2. EC2 Parameter ConversionIpsecEnabled: "{{ ipsec_enabled | default(true) | string | lower }}"
WireguardEnabled: "{{ wireguard_enabled | default(true) | string | lower }}"✅ Good catch converting to lowercase strings. CloudFormation's 3. Description Updates# Before
"description": "Locks inbound down to ssh default port 22.",
# After
"description": "Allow WireGuard VPN",✅ Good fix - the old description was clearly copy-pasted and wrong. 🧪 Testing RecommendationsYour test plan in the PR description is good, but I'd suggest adding:
📝 Documentation ConsiderationsConsider updating documentation to:
🔒 Security Assessment✅ No security concerns identified. This change:
📊 Summary
Recommendations
Overall, this is a well-implemented feature that meaningfully improves security posture. The code is clean, the approach is sound, and the backwards compatibility is maintained. Once testing is complete, this should be good to merge. 🤖 Generated with Claude Code |
Summary
When
ipsec_enabledorwireguard_enabledisfalse, don't open those ports in cloud provider security groups/firewalls. Previously, ports 500, 4500, and the WireGuard port were always opened regardless of which VPN protocols were actually enabled.This follows the principle of least privilege - only open ports for services that are actually running.
Changes by Provider
Notes
Fixes #14293
Test plan
ipsec_enabled: false- verify ports 500/4500 not in security groupwireguard_enabled: false- verify WireGuard port not in security group🤖 Generated with Claude Code