Repository navigation
fix(sandbox): run shared network grant rules before driver contributions - #3213
Conversation
Agent network-policy preview, save and the worker recheck validated grants only with the selected Sandbox Driver's sandbox-network-policy contribution. A package Driver with a looser contribution let preview report success for grants the shared rules refuse, and save then failed late at the database check with a 404. The ceiling check also counted an empty port list or a reversed range as covered. OCC now runs the shared SandboxNetworkPolicyConfiguration first; a Driver contribution can only narrow it. sandboxNetworkGrantsWithinCeiling refuses grants with no ports or a reversed range. Adds a PostgreSQL regression case with a looser package contribution and ceiling assertions.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
…aragraph Review nits: the changelog lists apply and deploy admission too, the paragraph wraps like its neighbours, and the empty-port test comment says the shared rules refuse it before the ceiling.
|
Codex review: needs maintainer review before merge. What this changesThis PR validates Agent network grants against shared rules before Driver contributions and rejects empty or reversed port ranges during ceiling checks. Example: A loose Sandbox Driver accepts /usr/bin/python3.11 accessing example.org with ports [{"from":65535,"to":1}].
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Regression provenanceRegression provenance — suspected predecessor, not a causality claim: source commit Possible regression — suspected (reviewed change). No predecessor PR is attributed. Merge readiness✅ Ready for maintainer review Keep this PR open: it repairs a source-confirmed admission regression with a focused change and relevant PostgreSQL coverage; no actionable introduced defect was found. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherOCC admits proposed network grants before storing policy or deployment snapshots; the durable worker rechecks policy before invoking the selected Sandbox Driver. flowchart TB
A[Agent policy request] --> B[Exact resource authorization]
B --> C[Shared grant validation]
C --> D[Driver and ceiling admission]
D --> E[PostgreSQL policy and work]
E --> F[Worker authority and policy recheck]
F --> G[Sandbox provider operations]
Technical reviewBest possible solution: Retain the shared validator in OCC admission and worker rechecks, with Driver contributions permitted to narrow the accepted grants. Do we have a high-confidence way to reproduce the issue? Current main can accept empty or reversed port ranges through a loose Driver contribution before PostgreSQL rejects persistence; the author reports a failing-main/passing-head regression, but this review ran no tests. Is this the best way to solve the issue? The patch restores the existing shared contract at its owning admission boundaries and hardens the common containment helper without adding a parallel validator or configuration option. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 4b019d47b58f. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
Review metrics
LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed October 22, 2026, 9:47 AM ET / 13:47 UTC. |
Problem
Since #2980, Agent network-policy admission (preview, save, and the worker recheck before a live apply) validates grants only with the selected Sandbox Driver's
sandbox-network-policycontribution. The sharedSandboxNetworkPolicyConfigurationfrom #2599 (unique IDs, normalized executable paths, DNS labels, ordered port ranges) no longer runs in OCC. RFC-0022 requires a Sandbox Driver to contribute exactly that definition, but nothing checks it does.With a package Sandbox Driver whose contribution is looser and whose
admitNetworkPolicydoes not recheck:POST .../sandbox-policy/networking/validate) returnssuccess: truefor a grant with no port range on an unlisted host, or with a reversed range such as{ from: 65535, to: 1 }on a delegated executable and host;sandbox_policies_document_validcheck refuses the row, and the API answers404 NOT_FOUNDinstead of field details (the in-memory store answers 500).sandboxNetworkGrantsWithinCeilingis part of why preview passes: an empty port list or a reversed range counts as covered. Storage stays protected by the database check. The bundled OpenShell Driver repeats the shared rules itself and is unaffected.Change
admitAgentNetworkPolicy(preview and save) andreconcileSandboxPolicy(worker) run the shared grant rules first. A Driver contribution can then only narrow them.sandboxNetworkGrantsWithinCeilingrefuses a grant that has no port range or a reversed one.For the bundled Driver, refusals and their
error.detailsare unchanged, because its contribution is the shared definition.Verification
tests/integration/postgres-agent-sandbox-policy.test.mjs. It registers a looser package contribution through the existingcreatePolicyApphelper. It fails on main (preview reports success; save answers 404) and passes with the fix: preview returns theminItemsdetail, and save answers 409 with theINVALID_RANGEdetail and keeps version 1. The whole file passes 4/4 locally against a disposable PostgreSQL.tests/conformance/contracts.test.mjs: 20/20 pass, and the new assertion fails on main.tsc --build, ESLint and Prettier pass on the touched files.Risks
Low. Grants that the shared rules refuse could never be stored in PostgreSQL anyway. The only change in behavior is that such grants are now refused at preview and save with field details, instead of later with a 404.