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
{{ message }}
Repository navigation
Commit ed55eb8
Browse filesBrowse the repository at this point in the historyBrowse files
feat(sandbox): allow egress to private IP space via allowed_ips policy field
Add an allowed_ips field to NetworkEndpoint that accepts CIDR notation and
exact IPs, enabling sandboxes to reach private IP space under policy control
while maintaining SSRF protections for loopback and link-local addresses.
Three modes are supported:
- Default (no allowed_ips): all private IPs blocked (existing behavior)
- Host + allowlist: domain must resolve to an IP in allowed_ips
- Hostless allowlist (no host): any domain allowed if resolved IP matches
Closes#59
Copy file name to clipboardExpand all lines: .agents/skills/generate-sandbox-policy/SKILL.md
+58-1Lines changed: 58 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -109,6 +109,7 @@ Ask these when the user's intent is broad and more specificity is possible:
109
109
| Multiple hosts in one policy | "Do all of these hosts need the same access level? If some need tighter restrictions, I can split them into separate policies." |
110
110
|`access: full` with `enforcement: audit`| "Full access in audit mode means nothing is actually restricted — all traffic flows through and violations are only logged. Is that intentional, or did you want to enforce restrictions?" |
111
111
|`**` path glob on all rules | "Using `**` on all paths allows any URL path. Do you know the specific API path prefixes you need (e.g., `/api/v1/`)?" |
112
+
| Private/internal IP destination | "Does this service resolve to a private IP (10.x, 172.16.x, 192.168.x)? If so, you'll need `allowed_ips` to permit access — what CIDR range should be allowed?" |
112
113
113
114
### Auto-Discovery of API Docs for Well-Known Services
-**Private IP Access via `allowed_ips`** — CIDR allowlist for private IP space
166
168
-**Validation Rules** — what combinations are valid/invalid
167
169
168
170
Also read the example policy for real-world patterns:
@@ -257,10 +259,35 @@ network_policies:
257
259
- allow:
258
260
method: <METHOD>
259
261
path: "<glob_pattern>"
262
+
# Optional: allow private IP destinations (CIDR or exact IP)
263
+
# allowed_ips:
264
+
# - "10.0.5.0/24"
260
265
binaries:
261
266
- { path: <binary_path> }
262
267
```
263
268
269
+
### Private IP Destinations
270
+
271
+
When the endpoint resolves to a private IP (RFC 1918), the proxy's SSRF protection blocks the connection by default. Use `allowed_ips` to selectively allow specific private IP ranges:
272
+
273
+
- **Host + allowlist**: `host` + `allowed_ips` — domain must resolve to an IP in the allowlist
274
+
- **Hostless allowlist**: `allowed_ips` only (no `host`) — any domain on the port is allowed if it resolves to an IP in the allowlist
275
+
276
+
Loopback (`127.0.0.0/8`) and link-local (`169.254.0.0/16`) are **always blocked** regardless of `allowed_ips`.
277
+
278
+
```yaml
279
+
# Example: Allow access to internal service at a known private IP range
280
+
internal_api:
281
+
name: internal_api
282
+
endpoints:
283
+
- host: api.internal.corp
284
+
port: 8080
285
+
allowed_ips:
286
+
- "10.0.5.0/24"
287
+
binaries:
288
+
- { path: /usr/bin/curl }
289
+
```
290
+
264
291
### Policy Key Naming
265
292
266
293
Use descriptive snake_case keys: `github_api`, `nvidia_inference`, `internal_service_readonly`.
@@ -309,6 +336,8 @@ Evaluate the generated policy for overly broad access and **include warnings in
309
336
| **Wildcard binary** (`*` or `**` in binary path) | "This policy allows any binary matching the glob pattern. A compromised or unexpected binary in that directory could use this policy. Consider listing specific binary paths." |
310
337
| **`**` path glob** on all explicit rules | "All rules use `**` path patterns, which match any URL path. This is equivalent to a preset — consider using `access: read-only` (or similar) for clarity, or narrowing paths if you know the API structure." |
311
338
| **Multiple broad endpoints** in one policy | "This policy grants the same broad access to N different hosts. If any of these hosts needs tighter restrictions later, you'll need to split the policy." |
339
+
| **Hostless `allowed_ips`** (no `host` field) | "This endpoint has no `host` — any domain resolving to the allowed IP range on this port will be permitted. Consider adding a `host` field to restrict which domains can use this allowlist." |
340
+
| **Broad CIDR** in `allowed_ips` (e.g., `10.0.0.0/8`) | "This `allowed_ips` entry covers a very broad range. Consider narrowing to a specific subnet (e.g., `10.0.5.0/24`) to minimize exposure." |
312
341
313
342
Format breadth warnings clearly in the output, e.g.:
314
343
@@ -484,6 +513,34 @@ internal_svc:
484
513
- { path: /usr/bin/curl }
485
514
```
486
515
516
+
### Private IP Access (Host + Allowlist)
517
+
518
+
```yaml
519
+
internal_db:
520
+
name: internal_db
521
+
endpoints:
522
+
- host: db.internal.corp
523
+
port: 5432
524
+
allowed_ips:
525
+
- "10.0.5.0/24"
526
+
binaries:
527
+
- { path: /usr/bin/curl }
528
+
```
529
+
530
+
### Private IP Access (Hostless — Any Domain in Range)
531
+
532
+
```yaml
533
+
private_services:
534
+
name: private_services
535
+
endpoints:
536
+
- port: 8080
537
+
allowed_ips:
538
+
- "10.0.5.0/24"
539
+
- "10.0.6.0/24"
540
+
binaries:
541
+
- { path: /usr/bin/curl }
542
+
```
543
+
487
544
## Additional Resources
488
545
489
546
- Full policy schema: [architecture/security-policy.md](../../../architecture/security-policy.md)
### Example P1: Internal Service with Known IP Range
631
+
632
+
**User**: "Allow curl to reach our internal API at api.internal.corp on port 8080. It resolves to 10.0.5.x addresses."
633
+
634
+
The user knows the service resolves to private IPs. Use `allowed_ips` to permit the specific subnet.
635
+
636
+
```yaml
637
+
network_policies:
638
+
internal_api:
639
+
name: internal_api
640
+
endpoints:
641
+
- host: api.internal.corp
642
+
port: 8080
643
+
allowed_ips:
644
+
- "10.0.5.0/24"
645
+
binaries:
646
+
- { path: /usr/bin/curl }
647
+
```
648
+
649
+
**What this allows**: Connections to `api.internal.corp:8080` when DNS resolves to any IP in `10.0.5.0/24`.
650
+
**What this blocks**: Connections if the domain resolves outside the allowlist, or to any loopback/link-local address.
651
+
652
+
---
653
+
654
+
### Example P2: Multiple Internal Subnets
655
+
656
+
**User**: "Our microservices are spread across 10.0.5.x and 10.0.6.x on port 8080. Let opencode reach any of them without listing every hostname."
657
+
658
+
Use a hostless endpoint with `allowed_ips` — any domain on port 8080 is allowed if it resolves to an IP in the listed ranges.
659
+
660
+
```yaml
661
+
network_policies:
662
+
private_services:
663
+
name: private_services
664
+
endpoints:
665
+
- port: 8080
666
+
allowed_ips:
667
+
- "10.0.5.0/24"
668
+
- "10.0.6.0/24"
669
+
binaries:
670
+
- { path: /usr/local/bin/opencode }
671
+
```
672
+
673
+
**What this allows**: Any hostname on port 8080 whose DNS resolves to `10.0.5.0/24` or `10.0.6.0/24`.
674
+
**What this blocks**: Any hostname resolving outside these ranges, or to loopback/link-local addresses.
675
+
676
+
**Note**: No `host` field means any domain name is accepted — only the resolved IP is checked. This is broader; use `host` when you know the specific hostname.
677
+
678
+
---
679
+
680
+
### Example P3: Private IP with L7 Inspection
681
+
682
+
**User**: "Allow read-only REST access to db-proxy.internal on port 3128. It's at 172.16.1.50."
683
+
684
+
Combine `allowed_ips` with L7 inspection for fine-grained control over a private service.
685
+
686
+
```yaml
687
+
network_policies:
688
+
db_proxy_readonly:
689
+
name: db_proxy_readonly
690
+
endpoints:
691
+
- host: db-proxy.internal
692
+
port: 3128
693
+
protocol: rest
694
+
enforcement: enforce
695
+
access: read-only
696
+
allowed_ips:
697
+
- "172.16.1.50"
698
+
binaries:
699
+
- { path: /usr/bin/curl }
700
+
```
701
+
702
+
**What this allows**: GET, HEAD, OPTIONS on any path to `db-proxy.internal:3128`, only if it resolves to `172.16.1.50`.
703
+
**What this blocks**: POST, PUT, PATCH, DELETE, and connections resolving to any other IP.
704
+
705
+
---
706
+
707
+
### Example P4: Exact IP (No CIDR)
708
+
709
+
**User**: "Allow curl to reach exactly 10.0.5.20 on port 9090 via metrics.internal."
710
+
711
+
```yaml
712
+
network_policies:
713
+
metrics_internal:
714
+
name: metrics_internal
715
+
endpoints:
716
+
- host: metrics.internal
717
+
port: 9090
718
+
allowed_ips:
719
+
- "10.0.5.20"
720
+
binaries:
721
+
- { path: /usr/bin/curl }
722
+
```
723
+
724
+
An exact IP is treated as `/32` — only that specific address is permitted.
0 commit comments