Skip to content

Commit d720bf7

Browse files
authored
Merge pull request anthropics#4644 from shota-0129/shota-0129/feat-docker-dns-protection
feat: Add Docker DNS protection to firewall script
2 parents b365888 + dde41f6 commit d720bf7

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

.devcontainer/init-firewall.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
set -euo pipefail # Exit on error, undefined vars, and pipeline failures
33
IFS=$'\n\t' # Stricter word splitting
44

5+
# 1. Extract Docker DNS info BEFORE any flushing
6+
DOCKER_DNS_RULES=$(iptables-save -t nat | grep "127\.0\.0\.11" || true)
7+
58
# Flush existing rules and delete existing ipsets
69
iptables -F
710
iptables -X
@@ -11,6 +14,16 @@ iptables -t mangle -F
1114
iptables -t mangle -X
1215
ipset destroy allowed-domains 2>/dev/null || true
1316

17+
# 2. Selectively restore ONLY internal Docker DNS resolution
18+
if [ -n "$DOCKER_DNS_RULES" ]; then
19+
echo "Restoring Docker DNS rules..."
20+
iptables -t nat -N DOCKER_OUTPUT 2>/dev/null || true
21+
iptables -t nat -N DOCKER_POSTROUTING 2>/dev/null || true
22+
echo "$DOCKER_DNS_RULES" | xargs -L 1 iptables -t nat
23+
else
24+
echo "No Docker DNS rules to restore"
25+
fi
26+
1427
# First allow DNS and localhost before any restrictions
1528
# Allow outbound DNS
1629
iptables -A OUTPUT -p udp --dport 53 -j ACCEPT

0 commit comments

Comments
 (0)