@@ -42,7 +42,6 @@ if [ -z "$gh_ranges" ]; then
4242 echo " ERROR: Failed to fetch GitHub IP ranges"
4343 exit 1
4444fi
45-
4645if ! echo " $gh_ranges " | jq -e ' .web and .api and .git' > /dev/null; then
4746 echo " ERROR: GitHub API response missing required fields"
4847 exit 1
@@ -78,9 +77,8 @@ for domain in \
7877 done < <( echo " $ips " )
7978done
8079
81- GOOGLE_CLOUD_CUSTOMER_IP_URL=" https://www.gstatic.com/ipranges/cloud.json"
82- echo " Fetching gcloud customer IPs $GOOGLE_CLOUD_CUSTOMER_IP_URL ."
83- cloud_ips=$( curl -s $GOOGLE_CLOUD_CUSTOMER_IP_URL )
80+ echo " Fetching gcloud customer IPs."
81+ cloud_ips=$( curl -s https://www.gstatic.com/ipranges/cloud.json)
8482if [ -z " $cloud_ips " ]; then
8583 echo " ERROR: Failed to fetch Google Cloud Customer IPs"
8684 exit 1
@@ -95,10 +93,8 @@ while read -r cidr; do
9593 ipset add google-customer-ips " $cidr " 2> /dev/null || true
9694done < <( echo " $CLOUD_NETBLOCKS " )
9795
98- # Get all IPs in Google Cloud
99- GOOGLE_ALL_IP_URL=" https://www.gstatic.com/ipranges/goog.json"
100- echo " Fetching gcloud full ip ranges $GOOGLE_ALL_IP_URL ."
101- goog_ips=$( curl -s $GOOGLE_ALL_IP_URL )
96+ echo " Fetching all gcloud IPs."
97+ goog_ips=$( curl -s https://www.gstatic.com/ipranges/goog.json)
10298if [ -z " $goog_ips " ]; then
10399 echo " ERROR: Failed to fetch Google All IPs"
104100 exit 1
@@ -133,28 +129,27 @@ iptables -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
133129
134130# Allow GitHub and Anthropic
135131iptables -A OUTPUT -m set --match-set github-anthropic dst -j ACCEPT
136- # Block all Google Cloud customer IPs
132+ # Block all gcloud customer IPs
137133# since this rule is after github-anthropic ACCEPT it shouldn't block any IPs in both sets
138134iptables -A OUTPUT -m set --match-set google-customer-ips dst -j REJECT --reject-with icmp-admin-prohibited
139- # Allow complement of All Google IPs and Customer Google Cloud IPs
140- # since this rule is after google-customer-ips REJECT it should allow
141- # IPs used by google not assigned to customers
135+ # Allow complement set of all gcloud IPs and customer gcloud IPs
136+ # since this rule is after google-customer-ips REJECT
137+ # the intended effect is to only allow gcloud IPs google's internal services use
138+ # and not allow accessing IPs assigned to google's customers
142139iptables -A OUTPUT -m set --match-set google-all-ips dst -j ACCEPT
143140
144- # Explicitly REJECT all other outbound traffic for immediate feedback
145141iptables -A OUTPUT -j REJECT --reject-with icmp-admin-prohibited
146142
147143echo " Firewall configuration complete"
148144echo " Verifying firewall rules..."
149145if curl --connect-timeout 5 https://example.com > /dev/null 2>&1 ; then
150146 echo " ERROR: Firewall verification failed - was able to reach https://example.com"
151147 exit 1
152- else
153- echo " Firewall verification passed - unable to reach https://example.com as expected"
154148fi
149+ echo " Firewall verification passed - unable to reach https://example.com as expected"
150+
155151if ! curl --connect-timeout 5 https://api.github.com/zen > /dev/null 2>&1 ; then
156152 echo " ERROR: Firewall verification failed - unable to reach https://api.github.com"
157153 exit 1
158- else
159- echo " Firewall verification passed - able to reach https://api.github.com as expected"
160154fi
155+ echo " Firewall verification passed - able to reach https://api.github.com as expected"
0 commit comments