You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add VPC egress firewall support for Cloud Run (#158)
* Upload large commands to GCS when they exceed env var limits
Cloud Run passes commands via environment variables, which have a ~32KB
limit. When a command exceeds 30KB, upload it to GCS and replace it with
a bootstrap script that downloads and executes it.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* Add VPC Direct Egress support for egress firewall
Route Cloud Run container traffic through a VPC where Cloud NGFW
firewall policies control outbound access by domain name (FQDN rules).
We previously tried iptables inside the container but found that
curl -6 bypasses iptables on Cloud Run, ip6tables kills the container,
and /proc/sys is read-only. The VPC approach applies firewall rules at
the GCP infrastructure level, outside the container.
Changes:
- Add vpc_network/vpc_subnet/vpc_egress to CloudRunClientConfig
- Configure run_v2.VpcAccess on job creation
- Add vpc_network/vpc_subnet/vpc_egress to ClaudeCodeClientConfig
- Document egress firewall setup in README (with example FQDN rules)
- Add integration test for VPC egress (allowed/blocked domains)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: safetytooling/infra/cloud_run/README.md
+126-1Lines changed: 126 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -177,12 +177,131 @@ client = ClaudeCodeClient(
177
177
-**Without this, Claude could take over your entire GCP project** - don't skip this step!
178
178
179
179
**What this doesn't limit:**
180
-
- Outbound network access (Claude could exfiltrate data to external URLs)
180
+
- Outbound network access (see Egress Firewall below)
181
181
- Anthropic API usage (Claude could use your API key for other purposes)
182
182
183
183
For the "yolo Claude" use case, the main risks are data exfiltration and API key abuse.
184
184
Containers are ephemeral (destroyed after job), so there's no persistence risk.
185
185
186
+
## Egress Firewall (Recommended)
187
+
188
+
By default, containers can make outbound requests to any host. To restrict egress (e.g., only allow `api.anthropic.com` and Google APIs), use VPC Direct Egress with Cloud NGFW firewall rules.
189
+
190
+
**How it works:** When `vpc_network` is set, all container traffic routes through a VPC where a Cloud NGFW firewall policy controls access by domain name (FQDN rules). This covers both IPv4 and IPv6.
**Costs:** Cloud NAT charges per VM-hour and per GB processed ([pricing](https://cloud.google.com/nat/pricing)). NGFW Standard charges $0.018/GB on internet-bound traffic evaluated by FQDN rules ([pricing](https://cloud.google.com/firewall/pricing)) — negligible for typical API call workloads but could add up if transferring large files.
282
+
283
+
**Key facts:**
284
+
- FQDN rules don't support wildcards — must list each Google API subdomain individually
285
+
- IPv6 is fully blocked at the VPC level (deny `::/0`)
286
+
287
+
**Verifying your setup:**
288
+
289
+
An integration test is included at `tests/test_vpc_egress.py`. It launches a Cloud Run container with VPC egress enabled and curls several domains from inside:
290
+
291
+
- Allowed domains (`api.anthropic.com`, `pypi.org`, `registry.npmjs.org`) should return an HTTP response
292
+
- Blocked domains (`example.com`) should time out (HTTP code `000`)
0 commit comments