Skip to content

fix: Parse actual subnet from routing table instead of assuming /24#32856

Open
anshul-garg27 wants to merge 1 commit intoanthropics:mainfrom
anshul-garg27:anshullkgarg/fix-firewall-subnet-detection
Open

fix: Parse actual subnet from routing table instead of assuming /24#32856
anshul-garg27 wants to merge 1 commit intoanthropics:mainfrom
anshul-garg27:anshullkgarg/fix-firewall-subnet-detection

Conversation

@anshul-garg27
Copy link
Copy Markdown

Summary

  • Replace hardcoded /24 subnet assumption with actual routing table parsing in .devcontainer/init-firewall.sh

Problem

Line 100: HOST_NETWORK=$(echo "$HOST_IP" | sed "s/\.[0-9]*$/.0\/24/") assumes the host network is always a /24 subnet. This fails on networks with different configurations (e.g., /16, /20, /28), blocking container-to-host communication.

Fix

Parse the actual subnet CIDR from ip route output using the host IP as a lookup key. Falls back to the original /24 assumption if route parsing fails, maintaining backward compatibility.

Test plan

  • Verify bash syntax with bash -n init-firewall.sh
  • Confirm correct subnet detection on /24 networks (most common)
  • Confirm correct subnet detection on non-/24 networks
  • Confirm /24 fallback works when route parsing returns empty

The firewall init script hardcodes a /24 subnet mask for the host
network, which fails on networks with different subnet configurations
(e.g., /16, /20). Parse the actual subnet CIDR from the routing table,
with a /24 fallback for compatibility.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant