Skip to content

Commit 09c78b4

Browse files
authored
Merge pull request #4279 from AtCoder-NoviSteps/fix/devcontainer-upstream-dns
fix:ファイアウォールが上流 DNS への問い合わせを遮断する問題を修正
2 parents c8399f8 + b89f060 commit 09c78b4

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

‎.devcontainer/init-firewall.sh‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,20 @@ iptables -A NOVISTEPS_INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
130130
iptables -A NOVISTEPS_INPUT -j DROP
131131
iptables -A NOVISTEPS_OUTPUT -o lo -j ACCEPT
132132

133-
# Only Docker's embedded DNS; port 53 to any other IP would bypass the allowlist.
133+
# Only Docker's DNS servers; port 53 to any other IP would bypass the allowlist.
134134
iptables -A NOVISTEPS_OUTPUT -p udp -d 127.0.0.11/32 --dport 53 -j ACCEPT
135135
iptables -A NOVISTEPS_OUTPUT -p tcp -d 127.0.0.11/32 --dport 53 -j ACCEPT
136136

137+
# Docker queries bare ExtServers addresses from the container's namespace and host(...) ones from the host's.
138+
read -r -a upstream_dns_entries <<<"$(sed -n 's/^# ExtServers: \[\(.*\)\]$/\1/p' /etc/resolv.conf)"
139+
140+
for upstream_dns in "${upstream_dns_entries[@]}"; do
141+
if [[ "${upstream_dns}" =~ ^[0-9.]+$ ]]; then
142+
iptables -A NOVISTEPS_OUTPUT -p udp -d "${upstream_dns}" --dport 53 -j ACCEPT
143+
iptables -A NOVISTEPS_OUTPUT -p tcp -d "${upstream_dns}" --dport 53 -j ACCEPT
144+
fi
145+
done
146+
137147
while IFS= read -r db_address; do
138148
iptables -A NOVISTEPS_OUTPUT -p tcp -d "${db_address}" --dport 5432 -j ACCEPT
139149
done <<<"${db_addresses}"

0 commit comments

Comments
 (0)