Secure, Fast, and Extensible Sandbox runtime for AI agents.
feat(server): seed a no-op default-allow record for policy-less fsb creates
高然a328662ebdf7
diff --git a/server/opensandbox_server/services/fast_sandbox/create_mapping.py b/server/opensandbox_server/services/fast_sandbox/create_mapping.pyindex 35d6ebcfd..9da8720a7 100644--- a/server/opensandbox_server/services/fast_sandbox/create_mapping.py+++ b/server/opensandbox_server/services/fast_sandbox/create_mapping.py@@ -133,10 +133,22 @@ def map_create_request(if request.metadata:create.metadata.update(request.metadata)+ # Every fsb sandbox registers an egress subject at create: the binding+ # is what makes the Fastlet run SET_BINDING (deny-first install, network+ # attachment) — the handler-relay surfaces (/policy/{uid},+ # /vault/{uid}) and the pause/resume state transfer attach to it. A+ # sandbox created without a networkPolicy seeds a no-op default-allow+ # record (the registration is the point — the sandbox behaves exactly+ # like today's policy-less one), and runtime changes ride the relay.if request.network_policy is not None:create.action_bindings.add(handler="egress", input=json.dumps(normalized_policy(request.network_policy)))+ else:+ create.action_bindings.add(+ handler="egress",+ input=json.dumps({"defaultAction": "allow", "egress": []}),+ )extensions = request.extensions or {}# Normalize before forwarding: a whitespace-only poolRef must not select@@ -193,10 +205,22 @@ def map_template_create_request(if request.metadata:create.metadata.update(request.metadata)+ # Every fsb sandbox registers an egress subject at create: the binding+ # is what makes the Fastlet run SET_BINDING (deny-first install, network+ # attachment) — the handler-relay surfaces (/policy/{uid},+ # /vault/{uid}) and the pause/resume state transfer attach to it. A+ # sandbox created without a networkPolicy seeds a no-op default-allow+ # record (the registration is the point — the sandbox behaves exactly+ # like today's policy-less one), and runtime changes ride the relay.if request.network_policy is not None:create.action_bindings.add(handler="egress", input=json.dumps(normalized_policy(request.network_policy)))+ else:+ create.action_bindings.add(+ handler="egress",+ input=json.dumps({"defaultAction": "allow", "egress": []}),+ )extensions = request.extensions or {}pool_ref = (extensions.get("poolRef") or "").strip()diff --git a/server/tests/test_fsb_service.py b/server/tests/test_fsb_service.pyindex b5f0c4c45..7b190f1e3 100644--- a/server/tests/test_fsb_service.py+++ b/server/tests/test_fsb_service.py@@ -856,6 +856,35 @@ def test_upstream_proxy_config_allows_delete_network_policy_rules(persisted_fsb)assert fake.last_relay is not None and fake.last_relay.path.startswith("/policy/")+def test_create_without_network_policy_still_registers_egress_binding(persisted_fsb):+ """Every fsb sandbox registers an egress subject at create — the relay+ surfaces (/policy/{uid}, /vault/{uid}) attach to it. A sandbox created+ without a networkPolicy seeds default-deny and can adopt a policy later+ through the relay."""+ client, fake, _, sandbox_id = persisted_fsb+ url = f"/v1/sandboxes/{sandbox_id}/networkpolicy"++ # The create-time binding seeded a no-op default-allow record: GET+ # serves it, and the CR carries the egress binding.+ assert client.get(url).json()["policy"] == {"defaultAction": "allow", "egress": []}+ cr = fake.crs[("ns-1", sandbox_id)]+ bindings = cr["spec"]["actionBindings"]+ assert [b["handler"] for b in bindings] == ["egress"]+ assert json.loads(bindings[0]["input"]) == {"defaultAction": "allow", "egress": []}++ # The sandbox can adopt a policy later through the relay.+ policy = {"defaultAction": "allow", "egress": [{"action": "allow", "target": "a.com"}]}+ response = client.put(url, json=policy)+ assert response.status_code == 200+ assert response.json()["policy"] == policy+ assert client.get(url).json()["policy"] == policy+ # The CR binding input stays the create-time bootstrap.+ assert json.loads(cr["spec"]["actionBindings"][0]["input"]) == {+ "defaultAction": "allow",+ "egress": [],+ }++def test_upstream_proxy_config_allows_create_without_network_policy(http_fsb):client, fake, service = http_fsbservice._app_config.egress = EgressConfig(@@ -883,8 +912,9 @@ def test_http_policy_replace_relays_and_leaves_bindings_untouched(persisted_fsb)the create-time bootstrap only, and a relay PUT never rewrites it."""client, fake, _, sandbox_id = persisted_fsburl = f"/v1/sandboxes/{sandbox_id}/networkpolicy"- # The create-time egress binding seeds the record (default deny here).- assert client.get(url).json()["policy"] == {"defaultAction": "deny", "egress": []}+ # The create-time egress binding seeds the record (a no-op+ # default-allow for a create without networkPolicy).+ assert client.get(url).json()["policy"] == {"defaultAction": "allow", "egress": []}bindings_before = [{"handler": "audit", "input": '{"enabled":true}'},{"handler": "egress", "input": '{"defaultAction":"deny"}'},diff --git a/specs/sandbox-lifecycle.yml b/specs/sandbox-lifecycle.ymlindex 4b19376de..998ff12d8 100644--- a/specs/sandbox-lifecycle.yml+++ b/specs/sandbox-lifecycle.yml@@ -2358,6 +2358,11 @@ components:Optional outbound network policy for the sandbox.Shape matches the sidecar `/policy` endpoint. If omitted or empty,the sidecar starts in allow-all mode until updated.+ For Fsb, an omitted policy still registers an egress binding,+ seeded with a no-op default-allow record (the sandbox behaves+ like a policy-less one until changed): runtime changes go+ through the networkpolicy endpoints (handler relay), which+ require that registration.Not supported together with `extensions.poolRef`; pooled pods arepre-created, so the server rejects this combination instead ofsilently ignoring the requested policy.