Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.
Rust agentai-agentapplecomputer-usecomputer-use-agentcontainerizationcuadesktop-automationhacktoberfestlumemacosmanusoperatorswiftvirtualizationvirtualization-frameworkwindowswindows-sandbox
Fleet dynamic service exposure: allow PATCH on sandbox services (#7553)
r33drichardsf3e1f8b307d3
diff --git a/libs/fleet/backend/auth/authz_k8s.rego b/libs/fleet/backend/auth/authz_k8s.regoindex 542ab7a232..b133480c75 100644--- a/libs/fleet/backend/auth/authz_k8s.rego+++ b/libs/fleet/backend/auth/authz_k8s.rego@@ -194,6 +194,24 @@ k8s_request_allowed {input.method == "GET"}+# The one write clients get on a Sandbox: PATCH on an item, so a claim holder+# can expose an extra service port on a RUNNING sandbox by appending to+# spec.vmTemplate.services (the pool-operator creates the matching per-sandbox+# Service; the VMI forwards all guest ports, so no restart is needed). This is+# a reviewed product decision (Fleet dynamic service exposure), not observed+# traffic. The body is NOT free-form: sandbox_services_admission.rego runs as+# a conjunct on this surface (see K8sRoutePolicy) and rejects any PATCH that+# touches more than spec.vmTemplate.services, so image, sizing and runtime+# stay operator-owned. Capsule scopes the caller to their own namespaces, the+# same as every other namespaced path here.+k8s_request_allowed {+ parts := split(input.params.path, "/")+ apis_namespaced_group(parts, "osgym.cua.ai", "v1alpha1")+ parts[5] == "osgymsandboxes"+ apis_item(parts)+ input.method == "PATCH"+}+# ── Fleet CRDs, legacy group ────────────────────────────────────────────────## apis/cua.ai/v1/namespaces/{ns}/osgymworkspacepools@@ -239,6 +257,43 @@ k8s_request_allowed {input.method == "GET"}+# ── Direct Service writes: denied with guidance ─────────────────────────────+#+# Nothing below admits a write to core Services, so a client that POSTs one —+# the obvious way to try to expose a new port on a sandbox — is denied either+# way. What this query adds is the reason: K8sRoutePolicy evaluates it wrapped+# in Because(...) BEFORE the allow leaf, so exactly these requests 403 with a+# message naming the supported alternative (spec.vmTemplate.services) instead+# of the generic "k8s request is not allowed". It changes no verdict: every+# request it denies, the allowlist denies too.+default not_direct_service_write = false++not_direct_service_write {+ not is_direct_service_write+}++is_direct_service_write {+ parts := split(input.params.path, "/")+ core_namespaced_resource(parts, "services")+ is_write_method+}++is_write_method {+ input.method == "POST"+}++is_write_method {+ input.method == "PUT"+}++is_write_method {+ input.method == "PATCH"+}++is_write_method {+ input.method == "DELETE"+}+# ── Pod metrics ─────────────────────────────────────────────────────────────## apis/metrics.k8s.io/v1beta1/namespaces/{ns}/pods — the CPU/memory numbersdiff --git a/libs/fleet/backend/auth/authz_k8s_test.rego b/libs/fleet/backend/auth/authz_k8s_test.regoindex 1740dc014f..46323e370a 100644--- a/libs/fleet/backend/auth/authz_k8s_test.rego+++ b/libs/fleet/backend/auth/authz_k8s_test.rego@@ -869,3 +869,86 @@ watch_admin_subs(admin) := ["admin-1"] if {watch_admin_subs(admin) := [] if {not admin}++# ── Bound-sandbox service exposure ──────────────────────────────────────────+#+# PATCH on a Sandbox item is the one write clients get on osgymsandboxes, so a+# claim holder can expose an extra service port on a running sandbox by+# appending to spec.vmTemplate.services. The body restriction (only that field+# may move) is sandbox_services_admission.rego's job and is tested there; these+# cases pin the route-authorization half.++test_sandbox_item_patch_allowed if {+ route_allow with input as spa_request("PATCH", "apis/osgym.cua.ai/v1alpha1/namespaces/ns-a/osgymsandboxes/sandbox-1")+}++test_sandbox_item_patch_allowed_for_user_key if {+ request := object.union(+ spa_request("PATCH", "apis/osgym.cua.ai/v1alpha1/namespaces/ns-a/osgymsandboxes/sandbox-1"),+ {"user": {"sub": "user-1", "azp": "ukey-abc", "namespace": "", "email": ""}},+ )++ route_allow with input as request+}++# The item verb matrix stays otherwise closed: PATCH is the only write, and the+# collection takes no writes at all.+test_sandbox_write_matrix_stays_closed if {+ not route_allow with input as spa_request("PATCH", "apis/osgym.cua.ai/v1alpha1/namespaces/ns-a/osgymsandboxes")+ not route_allow with input as spa_request("PUT", "apis/osgym.cua.ai/v1alpha1/namespaces/ns-a/osgymsandboxes/sandbox-1")+ not route_allow with input as spa_request("POST", "apis/osgym.cua.ai/v1alpha1/namespaces/ns-a/osgymsandboxes")+ not route_allow with input as spa_request("DELETE", "apis/osgym.cua.ai/v1alpha1/namespaces/ns-a/osgymsandboxes/sandbox-1")+ not route_allow with input as spa_request("PATCH", "apis/osgym.cua.ai/v1alpha1/namespaces/ns-a/osgymsandboxes/sandbox-1/status")+}++# An empty namespace or name segment must not satisfy the item shape.+test_sandbox_patch_needs_namespace_and_name if {+ not route_allow with input as spa_request("PATCH", "apis/osgym.cua.ai/v1alpha1/namespaces//osgymsandboxes/sandbox-1")+ not route_allow with input as spa_request("PATCH", "apis/osgym.cua.ai/v1alpha1/namespaces/ns-a/osgymsandboxes/")+}++# GitHub OIDC principals keep their own enumerated grant, which does not+# include sandboxes at all.+test_sandbox_patch_denied_for_github_oidc if {+ request := object.union(+ spa_request("PATCH", "apis/osgym.cua.ai/v1alpha1/namespaces/ns-a/osgymsandboxes/sandbox-1"),+ {"user": {+ "sub": "repo:trycua/cloud",+ "azp": "github-oidc",+ "principal_type": "github_oidc",+ "allowed_namespaces": ["ns-a"],+ }},+ )++ not route_allow with input as request+}++# ── The service-write guidance query ────────────────────────────────────────+#+# not_direct_service_write is the Because(...) conjunct K8sRoutePolicy runs+# before the allow leaf: it must deny exactly the core-Services writes (so the+# 403 carries the guidance message) and allow everything else (so it never+# shadows another rule's verdict or reason).++test_direct_service_write_guidance_denies_writes if {+ every method in ["POST", "PUT", "PATCH", "DELETE"] {+ not authz_k8s.not_direct_service_write with input as spa_request(method, "api/v1/namespaces/ns-a/services")+ not authz_k8s.not_direct_service_write with input as spa_request(method, "api/v1/namespaces/ns-a/services/sandbox-1-source-mcp")+ }+}++test_direct_service_write_guidance_passes_everything_else if {+ authz_k8s.not_direct_service_write with input as spa_request("GET", "api/v1/namespaces/ns-a/services")+ authz_k8s.not_direct_service_write with input as spa_request("GET", "api/v1/namespaces/ns-a/services/sandbox-1")+ authz_k8s.not_direct_service_write with input as spa_request("POST", "apis/osgym.cua.ai/v1alpha1/namespaces/ns-a/osgymsandboxclaims")+ authz_k8s.not_direct_service_write with input as spa_request("POST", "api/v1/namespaces/ns-a/pods")+ authz_k8s.not_direct_service_write with input as spa_request("PATCH", "apis/osgym.cua.ai/v1alpha1/namespaces/ns-a/osgymsandboxes/sandbox-1")+}++# The denial the guidance annotates is real with or without the annotation:+# the allowlist itself never admits a core-Services write. This is the exact+# request shape from the field report — POST a ClusterIP Service selecting the+# sandbox — and it must stay denied by both conjuncts.+test_direct_service_create_denied if {+ not route_allow with input as spa_request("POST", "api/v1/namespaces/ns-a/services")+}diff --git a/libs/fleet/backend/auth/middlewares.go b/libs/fleet/backend/auth/middlewares.goindex 52717bc3ea..1c70810ccf 100644--- a/libs/fleet/backend/auth/middlewares.go+++ b/libs/fleet/backend/auth/middlewares.go@@ -51,6 +51,14 @@ var poolAdmissionPolicy string//go:embed custom_resource_creation_admission.regovar customResourceCreationAdmissionPolicy string+// sandboxServicesAdmissionPolicy restricts the one Sandbox write /api/k8s+// admits (PATCH on an osgymsandboxes item) to a body that touches nothing but+// spec.vmTemplate.services. Like pool_admission.rego it is a conjunct on the+// k8s surface rather than a surface, so it is registered by name below.+//+//go:embed sandbox_services_admission.rego+var sandboxServicesAdmissionPolicy string+// authzOwnershipPolicy is the namespace-ownership boundary. Like// pool_admission.rego it is not a surface — it is a conjunct several surfaces// carry — so it is registered by name below rather than through@@ -381,6 +389,7 @@ func LoadOpa() {RegisterPolicyModule("authz", "authz.rego", authzPolicy)RegisterPolicyModule("pool-admission", "pool_admission.rego", poolAdmissionPolicy)RegisterPolicyModule("custom-resource-creation-admission", "custom_resource_creation_admission.rego", customResourceCreationAdmissionPolicy)+ RegisterPolicyModule("sandbox-services-admission", "sandbox_services_admission.rego", sandboxServicesAdmissionPolicy)RegisterPolicyModule("authz-ownership", "authz_ownership.rego", authzOwnershipPolicy)for name, module := range surfacePolicySources {RegisterPolicyModule(name, module.filename, module.source)diff --git a/libs/fleet/backend/auth/policy_characterization_test.go b/libs/fleet/backend/auth/policy_characterization_test.goindex 0fdd26a96b..9a67f0805b 100644--- a/libs/fleet/backend/auth/policy_characterization_test.go+++ b/libs/fleet/backend/auth/policy_characterization_test.go@@ -339,6 +339,31 @@ func characterizationCases() map[string][]routeCase {path: "apis/cua.ai/v1/namespaces/ns-a/osgymworkspacepools",body: `{"spec":{"template":{"containerDiskImage":"evil.example/workspace:latest","imagePullSecret":"ecr-credentials"}}}`,},++ // Bound-sandbox service exposure. PATCH on a Sandbox item is the one+ // Sandbox write on the allowlist, and only with a body that touches+ // nothing but spec.vmTemplate.services — the two bodies record the+ // sandbox-services admission conjunct's answer alongside the+ // allowlist's. Every other verb on the item, and every write on the+ // collection, stays denied.+ {+ name: "sandbox-item-services-patch",+ path: "apis/osgym.cua.ai/v1alpha1/namespaces/ns-a/osgymsandboxes/sandbox-1",+ body: `{"spec":{"vmTemplate":{"services":[{"name":"source-mcp","targetPort":3100}]}}}`,+ },+ {+ name: "sandbox-item-image-patch",+ path: "apis/osgym.cua.ai/v1alpha1/namespaces/ns-a/osgymsandboxes/sandbox-1",+ body: `{"spec":{"vmTemplate":{"containerDiskImage":"evil.example/workspace:latest"}}}`,+ },+ // The field report's exact attempt: writing a core Service directly.+ // Denied on every write verb (with a guidance message this table does+ // not record); the read stays open.+ {+ name: "namespaced-services",+ path: "api/v1/namespaces/ns-a/services",+ body: `{"apiVersion":"v1","kind":"Service","spec":{"selector":{"app":"sandbox-1"},"ports":[{"port":80,"targetPort":3100}]}}`,+ },}k8s := make([]routeCase, 0, len(k8sPaths))for _, k8sPath := range k8sPaths {diff --git a/libs/fleet/backend/auth/policy_routes.go b/libs/fleet/backend/auth/policy_routes.goindex c78f530499..3efefd33f2 100644--- a/libs/fleet/backend/auth/policy_routes.go+++ b/libs/fleet/backend/auth/policy_routes.go@@ -186,16 +186,18 @@ func AccountLookupRoutePolicy() Node {}// K8sRoutePolicy guards /api/k8s/{path...}. It is the same base + surface shape-// as every other route, with two admission conjuncts: card-or-admin admission-// for custom-resource creation, and pool admission over the request body.+// as every other route, with three admission conjuncts: card-or-admin admission+// for custom-resource creation, pool admission over the request body, and+// sandbox-services admission over the body of the one Sandbox write the+// allowlist admits.//-// Every conjunct must pass. The pool-admission leaf reads the raw body (bounded at 1 MiB)-// to inspect the object being created or patched, which is why it names-// pool_admission.rego alongside authz.rego — pool_admission imports-// data.authz.is_admin. It stays a separate leaf rather than rules inside-// authz_k8s.rego because it is the only thing on this surface that needs the-// body, and folding it in would put every k8s request's verdict behind a body-// read.+// Every conjunct must pass. The two body-reading leaves read the raw body+// (bounded at 1 MiB) to inspect the object being created or patched, which is+// why pool admission names pool_admission.rego alongside authz.rego —+// pool_admission imports data.authz.is_admin. They stay separate leaves rather+// than rules inside authz_k8s.rego because they are the only things on this+// surface that need the body, and folding them in would put every k8s+// request's verdict behind a body read.func CustomResourceCreationAdmissionPolicy() Node {leaf := func(query string, options ...PolicyOption) Node {return Policy(@@ -217,9 +219,28 @@ func CustomResourceCreationAdmissionPolicy() Node {)}+// ServiceWriteNotSupportedMessage is the 403 body for a direct write to core+// Services through /api/k8s — the obvious but unsupported way to expose a new+// port on a sandbox. The allowlist denies these writes either way; this+// message exists so the denial names the supported alternative instead of+// reading as an unexplained policy defect.+const ServiceWriteNotSupportedMessage = "creating or modifying Kubernetes Services directly is not supported. Declare the port under spec.vmTemplate.services on the pool template, or PATCH spec.vmTemplate.services on your bound OSGymSandbox to expose it on a running sandbox; the matching Service is created for you."++// SandboxPatchRestrictedMessage is the 403 body when a Sandbox PATCH body+// strays outside the one field clients may write.+const SandboxPatchRestrictedMessage = "a sandbox PATCH may only modify spec.vmTemplate.services (an optional metadata.resourceVersion precondition is also accepted)"+func K8sRoutePolicy() Node {return All(BasePolicy(),+ // Before the allow leaf on purpose: All's fold short-circuits on the+ // first denying child and keeps ITS reason, so this Because only+ // reaches the response when it is the first conjunct to deny — which,+ // placed here, is every direct core-Services write and nothing else.+ Because(+ surfaceLeaf("authz-k8s", "data.authz_k8s.not_direct_service_write"),+ ServiceWriteNotSupportedMessage,+ ),surfaceLeaf("authz-k8s", "data.authz_k8s.allow"),Because(CustomResourceCreationAdmissionPolicy(), BillingSetupRequiredMessage),Policy(@@ -230,6 +251,14 @@ func K8sRoutePolicy() Node {Query("data.pool_admission.allow"),WithRawBody(1<<20),),+ Because(+ Policy(+ Registered("sandbox-services-admission"),+ Query("data.sandbox_services_admission.allow"),+ WithRawBody(1<<20),+ ),+ SandboxPatchRestrictedMessage,+ ),)}diff --git a/libs/fleet/backend/auth/policy_sandbox_services_test.go b/libs/fleet/backend/auth/policy_sandbox_services_test.gonew file mode 100644index 0000000000..470dedc4f5--- /dev/null+++ b/libs/fleet/backend/auth/policy_sandbox_services_test.go@@ -0,0 +1,88 @@+package auth++import (+ "context"+ "net/http"+ "testing"+)++// These tests pin the two response contracts the Fleet dynamic-service-exposure+// work added to the k8s surface, end to end through the production tree and+// middleware options:+//+// - A direct write to core Services 403s with a message naming the supported+// alternative, instead of the generic surface denial. The verdict itself is+// unchanged (the allowlist never admitted these); only the reason moved.+// - PATCH on an osgymsandboxes item is admitted exactly when its body touches+// nothing but spec.vmTemplate.services, and a body that strays 403s with+// its own message rather than the generic one.+//+// The generic-denial case for unrelated paths stays pinned by+// TestK8sUnrelatedDenialKeepsSurfaceMessage in policy_card_admission_test.go.++func sandboxServicesRequest(method, path, body string) *http.Request {+ request := routeRequest(method, "/api/k8s/"+path, "/api/k8s/{path...}", map[string]string{"path": path}, body)+ ctx := context.WithValue(request.Context(), UserKey, &User{ID: "user-1", AZP: "cyclops-cs-spa", PrincipalType: PrincipalTypeUser})+ return request.WithContext(ctx)+}++func TestK8sDirectServiceWriteReturnsGuidance(t *testing.T) {+ setCardAdmissionFlags(t, false)+ const body = `{"apiVersion":"v1","kind":"Service","metadata":{"name":"sandbox-1-source-mcp"},"spec":{"type":"ClusterIP","selector":{"app":"sandbox-1"},"ports":[{"port":80,"targetPort":3100}]}}`++ for _, testCase := range []struct {+ name string+ method string+ path string+ }{+ {name: "create", method: http.MethodPost, path: "api/v1/namespaces/ns-a/services"},+ {name: "replace", method: http.MethodPut, path: "api/v1/namespaces/ns-a/services/sandbox-1-source-mcp"},+ {name: "patch", method: http.MethodPatch, path: "api/v1/namespaces/ns-a/services/sandbox-1-source-mcp"},+ {name: "delete", method: http.MethodDelete, path: "api/v1/namespaces/ns-a/services/sandbox-1-source-mcp"},+ } {+ t.Run(testCase.name, func(t *testing.T) {+ response, reached := runK8sPolicyResponse(t, sandboxServicesRequest(testCase.method, testCase.path, body))+ if response.Code != http.StatusForbidden || reached {+ t.Fatalf("status, reached = %d, %v; want %d, false", response.Code, reached, http.StatusForbidden)+ }+ if got := policyErrorMessage(t, response); got != ServiceWriteNotSupportedMessage {+ t.Fatalf("error = %q, want %q", got, ServiceWriteNotSupportedMessage)+ }+ })+ }+}++// Reading Services stays allowed, so the guidance conjunct provably denies+// writes alone.+func TestK8sServiceReadStillAllowed(t *testing.T) {+ setCardAdmissionFlags(t, false)+ response, reached := runK8sPolicyResponse(t, sandboxServicesRequest(http.MethodGet, "api/v1/namespaces/ns-a/services", ""))+ if response.Code != http.StatusNoContent || !reached {+ t.Fatalf("status, reached = %d, %v; want %d, true", response.Code, reached, http.StatusNoContent)+ }+}++func TestK8sSandboxServicesPatchAdmitted(t *testing.T) {+ setCardAdmissionFlags(t, false)+ const path = "apis/osgym.cua.ai/v1alpha1/namespaces/ns-a/osgymsandboxes/sandbox-1"+ const body = `{"spec":{"vmTemplate":{"services":[{"name":"source-mcp","targetPort":3100}]}}}`++ response, reached := runK8sPolicyResponse(t, sandboxServicesRequest(http.MethodPatch, path, body))+ if response.Code != http.StatusNoContent || !reached {+ t.Fatalf("status, reached = %d, %v; want %d, true", response.Code, reached, http.StatusNoContent)+ }+}++func TestK8sSandboxPatchBeyondServicesReturnsRestrictedMessage(t *testing.T) {+ setCardAdmissionFlags(t, false)+ const path = "apis/osgym.cua.ai/v1alpha1/namespaces/ns-a/osgymsandboxes/sandbox-1"+ const body = `{"spec":{"vmTemplate":{"containerDiskImage":"evil.example/workspace:latest"}}}`++ response, reached := runK8sPolicyResponse(t, sandboxServicesRequest(http.MethodPatch, path, body))+ if response.Code != http.StatusForbidden || reached {+ t.Fatalf("status, reached = %d, %v; want %d, false", response.Code, reached, http.StatusForbidden)+ }+ if got := policyErrorMessage(t, response); got != SandboxPatchRestrictedMessage {+ t.Fatalf("error = %q, want %q", got, SandboxPatchRestrictedMessage)+ }+}diff --git a/libs/fleet/backend/auth/policy_test.go b/libs/fleet/backend/auth/policy_test.goindex 033b02a810..fff9cd8a6f 100644--- a/libs/fleet/backend/auth/policy_test.go+++ b/libs/fleet/backend/auth/policy_test.go@@ -34,8 +34,9 @@ import (// belonging in this table — reading input.facts is the point of that option.func TestRouteModulesNeverReadInputFacts(t *testing.T) {modules := map[string]string{- "authz.rego": authzPolicy,- "pool_admission.rego": poolAdmissionPolicy,+ "authz.rego": authzPolicy,+ "pool_admission.rego": poolAdmissionPolicy,+ "sandbox_services_admission.rego": sandboxServicesAdmissionPolicy,}// Every base and surface module too, read from the same map LoadOpa// registers, so a surface added there is covered without being named here.diff --git a/libs/fleet/backend/auth/sandbox_services_admission.rego b/libs/fleet/backend/auth/sandbox_services_admission.regonew file mode 100644index 0000000000..64f39eec8e--- /dev/null+++ b/libs/fleet/backend/auth/sandbox_services_admission.rego@@ -0,0 +1,157 @@+# Admission over the request body for the one write /api/k8s admits on+# osgymsandboxes: a PATCH whose body touches nothing but+# spec.vmTemplate.services, plus an optional metadata.resourceVersion CAS+# precondition. Everything else on the Sandbox spec — image, pull secret,+# sizing, runtime, probes, OIDC — stays operator-owned, so this module is what+# keeps "clients may expose a port on their sandbox" from quietly becoming+# "clients may rewrite their sandbox".+#+# It runs as a conjunct of K8sRoutePolicy (policy_routes.go), the same shape as+# pool_admission.rego: `applies` matches the write shapes on the resource this+# module owns, `allow { not applies }` passes everything else on the surface+# untouched, and an applying request must prove its body is the one permitted+# shape. That makes it fail-closed against future allowlist widening too — a+# POST or PUT on osgymsandboxes admitted later would land here and be denied+# until someone decides what its body may say.+#+# The service entries' types (name a string, targetPort 1-65535, protocol an+# enum) are validated by the CRD's structural schema at the apiserver, so this+# module mostly pins the SHAPE of the patch — with two exceptions the schema+# does not cover:+#+# - a count cap, because each entry becomes a real Kubernetes Service and+# the schema has no maxItems;+# - name validity and uniqueness, because the operator creates a Service+# literally named `<sandbox>-<name>` (an RFC-1123 DNS label of at most 63+# characters) and keys its reconcile by `name`. A name the apiserver would+# reject must 403 here, at the API boundary, rather than wedge the+# operator's field handler in a retry loop against an impossible create;+# duplicates would silently collapse to the last entry.+package sandbox_services_admission++default allow = false++# The most services one sandbox may declare. Each entry costs a Kubernetes+# Service object; a real sandbox exposes a handful.+max_services := 32++write_method {+ input.method == "POST"+}++write_method {+ input.method == "PUT"+}++write_method {+ input.method == "PATCH"+}++# apis/osgym.cua.ai/v1alpha1/namespaces/{ns}/osgymsandboxes — the collection.+sandbox_resource_path {+ parts := split(input.params.path, "/")+ count(parts) == 6+ parts[0] == "apis"+ parts[1] == "osgym.cua.ai"+ parts[2] == "v1alpha1"+ parts[3] == "namespaces"+ parts[4] != ""+ parts[5] == "osgymsandboxes"+}++# apis/osgym.cua.ai/v1alpha1/namespaces/{ns}/osgymsandboxes/{name} — an item.+sandbox_resource_path {+ parts := split(input.params.path, "/")+ count(parts) == 7+ parts[0] == "apis"+ parts[1] == "osgym.cua.ai"+ parts[2] == "v1alpha1"+ parts[3] == "namespaces"+ parts[4] != ""+ parts[5] == "osgymsandboxes"+ parts[6] != ""+}++applies {+ write_method+ sandbox_resource_path+}++allow {+ not applies+}++request_object := json.unmarshal(input.body) {+ applies+}++# The body's top level may name spec alone, or spec plus a metadata that+# carries only the resourceVersion precondition (the optimistic-concurrency+# handle for read-modify-write of the services array; JSON merge patch+# replaces the whole array, so concurrent blind writes would clobber).+#+# object.keys sees every key whatever its value, so a smuggled+# `"status": null` (a merge-patch delete) or `"metadata": {"labels": ...}`+# fails the comparison rather than slipping past a truthiness filter.+top_level_shape_allowed {+ object.keys(request_object) == {"spec"}+}++top_level_shape_allowed {+ object.keys(request_object) == {"metadata", "spec"}+ metadata := request_object.metadata+ is_object(metadata)+ object.keys(metadata) == {"resourceVersion"}+ is_string(metadata.resourceVersion)+}++services_only_patch {+ is_object(request_object)+ top_level_shape_allowed+ spec := request_object.spec+ is_object(spec)+ object.keys(spec) == {"vmTemplate"}+ vm_template := spec.vmTemplate+ is_object(vm_template)+ object.keys(vm_template) == {"services"}+ services := vm_template.services+ is_array(services)+ count(services) <= max_services+ service_names_valid(services)+}++# Every entry must carry a name the apiserver will accept as part of the+# Service name `<sandbox>-<name>` (RFC-1123 DNS label, ≤ 63 characters+# combined with the sandbox name from the path), and no two entries may share+# a name. Entries are checked by negation — one bad entry fails the whole+# patch — and an entry with no name (or a non-string one) counts as bad, the+# same verdict the CRD schema would reach one hop later.+service_names_valid(services) {+ names := {name | name := services[_].name}+ count(names) == count(services)+ not any_entry_name_invalid(services)+}++any_entry_name_invalid(services) {+ entry := services[_]+ not entry_name_valid(entry)+}++entry_name_valid(entry) {+ is_object(entry)+ name := entry.name+ is_string(name)+ regex.match(`^[a-z0-9]([-a-z0-9]*[a-z0-9])?$`, name)+ parts := split(input.params.path, "/")+ sandbox_name := parts[6]+ (count(sandbox_name) + 1) + count(name) <= 63+}++# Only the PATCH verb ever reaches `applies` today (the allowlist admits no+# other sandbox write), but the check is explicit so an admitted POST or PUT+# cannot ride through on a services-shaped body.+allow {+ applies+ input.method == "PATCH"+ services_only_patch+}diff --git a/libs/fleet/backend/auth/sandbox_services_admission_test.rego b/libs/fleet/backend/auth/sandbox_services_admission_test.regonew file mode 100644index 0000000000..952b2f3771--- /dev/null+++ b/libs/fleet/backend/auth/sandbox_services_admission_test.rego@@ -0,0 +1,192 @@+package sandbox_services_admission_test++import data.sandbox_services_admission++item_path := "apis/osgym.cua.ai/v1alpha1/namespaces/ns-a/osgymsandboxes/sandbox-1"++collection_path := "apis/osgym.cua.ai/v1alpha1/namespaces/ns-a/osgymsandboxes"++services_patch := `{"spec":{"vmTemplate":{"services":[{"name":"source-mcp","targetPort":3100}]}}}`++patch_input(path, body) := {+ "method": "PATCH",+ "params": {"path": path},+ "body": body,+}++# Requests off this module's resource pass through untouched, whatever the+# body says — the module gates sandbox writes and nothing else.+test_unrelated_request_allowed {+ sandbox_services_admission.allow with input as {+ "method": "POST",+ "params": {"path": "apis/cua.ai/v1/namespaces/ns-a/osgymworkspacepools"},+ "body": "not json",+ }+}++test_sandbox_read_allowed {+ sandbox_services_admission.allow with input as {+ "method": "GET",+ "params": {"path": item_path},+ "body": "",+ }+}++# The one permitted shape: a merge patch that names spec.vmTemplate.services+# and nothing else.+test_services_only_patch_allowed {+ sandbox_services_admission.allow with input as patch_input(item_path, services_patch)+}++test_services_patch_with_resource_version_allowed {+ sandbox_services_admission.allow with input as patch_input(+ item_path,+ `{"metadata":{"resourceVersion":"12345"},"spec":{"vmTemplate":{"services":[{"name":"source-mcp","targetPort":3100,"protocol":"TCP"}]}}}`,+ )+}++# Clearing the extra services is spelled with an empty array, which is a+# services-only patch like any other.+test_empty_services_patch_allowed {+ sandbox_services_admission.allow with input as patch_input(+ item_path,+ `{"spec":{"vmTemplate":{"services":[]}}}`,+ )+}++test_malformed_body_denied {+ not sandbox_services_admission.allow with input as patch_input(item_path, "not json")+}++# A JSON Patch body is an array, not an object, and can address arbitrary+# fields — only the merge-patch object shape is admitted.+test_json_patch_array_denied {+ not sandbox_services_admission.allow with input as patch_input(+ item_path,+ `[{"op":"replace","path":"/spec/vmTemplate/containerDiskImage","value":"evil.example/x"}]`,+ )+}++# Anything beyond the services field is operator-owned.+test_image_patch_denied {+ not sandbox_services_admission.allow with input as patch_input(+ item_path,+ `{"spec":{"vmTemplate":{"containerDiskImage":"evil.example/workspace:latest"}}}`,+ )+}++test_services_plus_image_patch_denied {+ not sandbox_services_admission.allow with input as patch_input(+ item_path,+ `{"spec":{"vmTemplate":{"services":[{"name":"mcp","targetPort":3100}],"cpuCores":64}}}`,+ )+}++test_status_smuggled_alongside_spec_denied {+ not sandbox_services_admission.allow with input as patch_input(+ item_path,+ `{"spec":{"vmTemplate":{"services":[]}},"status":{"phase":"Ready"}}`,+ )+}++# A merge-patch null is a delete; a null smuggled at the top level must fail+# the key-set comparison rather than slip past a truthiness filter.+test_null_valued_key_denied {+ not sandbox_services_admission.allow with input as patch_input(+ item_path,+ `{"spec":{"vmTemplate":{"services":[]}},"status":null}`,+ )+}++test_metadata_beyond_resource_version_denied {+ not sandbox_services_admission.allow with input as patch_input(+ item_path,+ `{"metadata":{"resourceVersion":"1","labels":{"osgym.cua.ai/warmpool":"stolen"}},"spec":{"vmTemplate":{"services":[]}}}`,+ )+}++test_services_must_be_an_array {+ not sandbox_services_admission.allow with input as patch_input(+ item_path,+ `{"spec":{"vmTemplate":{"services":null}}}`,+ )+ not sandbox_services_admission.allow with input as patch_input(+ item_path,+ `{"spec":{"vmTemplate":{"services":false}}}`,+ )+}++# Each entry becomes a real Kubernetes Service; the cap bounds the churn one+# sandbox can demand.+test_service_count_cap_enforced {+ over_cap := json.marshal({"spec": {"vmTemplate": {"services": [{"name": sprintf("svc-%d", [i]), "targetPort": 3000 + i} | i := numbers.range(1, 33)[_]]}}})+ not sandbox_services_admission.allow with input as patch_input(item_path, over_cap)++ at_cap := json.marshal({"spec": {"vmTemplate": {"services": [{"name": sprintf("svc-%d", [i]), "targetPort": 3000 + i} | i := numbers.range(1, 32)[_]]}}})+ sandbox_services_admission.allow with input as patch_input(item_path, at_cap)+}++# The collection takes no writes, and non-PATCH verbs on the item stay denied+# here even with a services-shaped body — fail-closed against a future+# allowlist widening.+test_collection_write_denied {+ not sandbox_services_admission.allow with input as {+ "method": "POST",+ "params": {"path": collection_path},+ "body": services_patch,+ }+}++test_put_denied_even_with_services_body {+ not sandbox_services_admission.allow with input as {+ "method": "PUT",+ "params": {"path": item_path},+ "body": services_patch,+ }+}++# The operator creates a Service literally named `<sandbox>-<name>`, so a+# name the apiserver would reject must be denied here, at the API boundary,+# instead of wedging the operator's field handler in a retry loop.+test_invalid_service_name_charset_denied {+ not sandbox_services_admission.allow with input as patch_input(+ item_path,+ `{"spec":{"vmTemplate":{"services":[{"name":"Source_MCP","targetPort":3100}]}}}`,+ )+ not sandbox_services_admission.allow with input as patch_input(+ item_path,+ `{"spec":{"vmTemplate":{"services":[{"name":"-mcp","targetPort":3100}]}}}`,+ )+ not sandbox_services_admission.allow with input as patch_input(+ item_path,+ `{"spec":{"vmTemplate":{"services":[{"name":"","targetPort":3100}]}}}`,+ )+}++# `<sandbox>-<name>` must fit an RFC-1123 label: 63 characters. The sandbox+# name comes from the path ("sandbox-1", 9 chars), leaving 53 for the suffix.+test_combined_service_name_length_bounded {+ name_53 := concat("", [x | numbers.range(1, 53)[_]; x := "b"])+ at_limit := json.marshal({"spec": {"vmTemplate": {"services": [{"name": name_53, "targetPort": 3100}]}}})+ sandbox_services_admission.allow with input as patch_input(item_path, at_limit)++ name_54 := concat("", [x | numbers.range(1, 54)[_]; x := "b"])+ over_limit := json.marshal({"spec": {"vmTemplate": {"services": [{"name": name_54, "targetPort": 3100}]}}})+ not sandbox_services_admission.allow with input as patch_input(item_path, over_limit)+}++# The reconciler keys Services by name; duplicates would silently collapse to+# the last entry, so they are rejected instead.+test_duplicate_service_names_denied {+ not sandbox_services_admission.allow with input as patch_input(+ item_path,+ `{"spec":{"vmTemplate":{"services":[{"name":"mcp","targetPort":3100},{"name":"mcp","targetPort":3200}]}}}`,+ )+}++test_entry_without_name_denied {+ not sandbox_services_admission.allow with input as patch_input(+ item_path,+ `{"spec":{"vmTemplate":{"services":[{"targetPort":3100}]}}}`,+ )+}diff --git a/libs/fleet/backend/auth/testdata/k8s-route-plan.txt b/libs/fleet/backend/auth/testdata/k8s-route-plan.txtindex 939bb73851..7c07966845 100644--- a/libs/fleet/backend/auth/testdata/k8s-route-plan.txt+++ b/libs/fleet/backend/auth/testdata/k8s-route-plan.txt@@ -1,8 +1,12 @@AllLeaf query=data.authz_base.allow source=registered:authz-base+ Because reason="creating or modifying Kubernetes Services directly is not supported. Declare the port under spec.vmTemplate.services on the pool template, or PATCH spec.vmTemplate.services on your bound OSGymSandbox to expose it on a running sandbox; the matching Service is created for you."+ Leaf query=data.authz_k8s.not_direct_service_write source=multi["registered:authz","registered:authz-k8s"]Leaf query=data.authz_k8s.allow source=multi["registered:authz","registered:authz-k8s"]Because reason="A payment method is required to create this resource. Add one in Billing and try again."AnyLeaf query=data.custom_resource_creation_admission.exempt source=multi["registered:authz","registered:custom-resource-creation-admission"]Leaf query=data.custom_resource_creation_admission.billing_eligible source=multi["registered:authz","registered:custom-resource-creation-admission"] facts=stripe_cards@registered-facts:stripe-cards facts=time@registered-facts:current-year facts=time@registered-facts:current-monthLeaf query=data.pool_admission.allow source=multi["registered:authz","registered:pool-admission"] body=1048576+ Because reason="a sandbox PATCH may only modify spec.vmTemplate.services (an optional metadata.resourceVersion precondition is also accepted)"+ Leaf query=data.sandbox_services_admission.allow source=registered:sandbox-services-admission body=1048576diff --git a/libs/fleet/backend/auth/testdata/route-authorization-table.txt b/libs/fleet/backend/auth/testdata/route-authorization-table.txtindex e7663d33d7..0838bef52a 100644--- a/libs/fleet/backend/auth/testdata/route-authorization-table.txt+++ b/libs/fleet/backend/auth/testdata/route-authorization-table.txt@@ -2088,6 +2088,61 @@/api/k8s/{path...} | namespaced-secrets | QUERY | spa = deny/api/k8s/{path...} | namespaced-secrets | QUERY | user-key = deny/api/k8s/{path...} | namespaced-secrets | QUERY | user-key-verified = deny+/api/k8s/{path...} | namespaced-services | DELETE | admin-spa = deny+/api/k8s/{path...} | namespaced-services | DELETE | cua-cli = deny+/api/k8s/{path...} | namespaced-services | DELETE | dcr-client = deny+/api/k8s/{path...} | namespaced-services | DELETE | empty-sub = deny+/api/k8s/{path...} | namespaced-services | DELETE | github-oidc = deny+/api/k8s/{path...} | namespaced-services | DELETE | oauth2-proxy = deny+/api/k8s/{path...} | namespaced-services | DELETE | per-key-other-ns = deny+/api/k8s/{path...} | namespaced-services | DELETE | per-key-owned-ns = deny+/api/k8s/{path...} | namespaced-services | DELETE | spa = deny+/api/k8s/{path...} | namespaced-services | DELETE | user-key = deny+/api/k8s/{path...} | namespaced-services | DELETE | user-key-verified = deny+/api/k8s/{path...} | namespaced-services | GET | admin-spa = allow+/api/k8s/{path...} | namespaced-services | GET | cua-cli = allow+/api/k8s/{path...} | namespaced-services | GET | dcr-client = deny+/api/k8s/{path...} | namespaced-services | GET | empty-sub = deny+/api/k8s/{path...} | namespaced-services | GET | github-oidc = deny+/api/k8s/{path...} | namespaced-services | GET | oauth2-proxy = deny+/api/k8s/{path...} | namespaced-services | GET | per-key-other-ns = deny+/api/k8s/{path...} | namespaced-services | GET | per-key-owned-ns = deny+/api/k8s/{path...} | namespaced-services | GET | spa = allow+/api/k8s/{path...} | namespaced-services | GET | user-key = allow+/api/k8s/{path...} | namespaced-services | GET | user-key-verified = allow+/api/k8s/{path...} | namespaced-services | PATCH | admin-spa = deny+/api/k8s/{path...} | namespaced-services | PATCH | cua-cli = deny+/api/k8s/{path...} | namespaced-services | PATCH | dcr-client = deny+/api/k8s/{path...} | namespaced-services | PATCH | empty-sub = deny+/api/k8s/{path...} | namespaced-services | PATCH | github-oidc = deny+/api/k8s/{path...} | namespaced-services | PATCH | oauth2-proxy = deny+/api/k8s/{path...} | namespaced-services | PATCH | per-key-other-ns = deny+/api/k8s/{path...} | namespaced-services | PATCH | per-key-owned-ns = deny+/api/k8s/{path...} | namespaced-services | PATCH | spa = deny+/api/k8s/{path...} | namespaced-services | PATCH | user-key = deny+/api/k8s/{path...} | namespaced-services | PATCH | user-key-verified = deny+/api/k8s/{path...} | namespaced-services | POST | admin-spa = deny+/api/k8s/{path...} | namespaced-services | POST | cua-cli = deny+/api/k8s/{path...} | namespaced-services | POST | dcr-client = deny+/api/k8s/{path...} | namespaced-services | POST | empty-sub = deny+/api/k8s/{path...} | namespaced-services | POST | github-oidc = deny+/api/k8s/{path...} | namespaced-services | POST | oauth2-proxy = deny+/api/k8s/{path...} | namespaced-services | POST | per-key-other-ns = deny+/api/k8s/{path...} | namespaced-services | POST | per-key-owned-ns = deny+/api/k8s/{path...} | namespaced-services | POST | spa = deny+/api/k8s/{path...} | namespaced-services | POST | user-key = deny+/api/k8s/{path...} | namespaced-services | POST | user-key-verified = deny+/api/k8s/{path...} | namespaced-services | QUERY | admin-spa = deny+/api/k8s/{path...} | namespaced-services | QUERY | cua-cli = deny+/api/k8s/{path...} | namespaced-services | QUERY | dcr-client = deny+/api/k8s/{path...} | namespaced-services | QUERY | empty-sub = deny+/api/k8s/{path...} | namespaced-services | QUERY | github-oidc = deny+/api/k8s/{path...} | namespaced-services | QUERY | oauth2-proxy = deny+/api/k8s/{path...} | namespaced-services | QUERY | per-key-other-ns = deny+/api/k8s/{path...} | namespaced-services | QUERY | per-key-owned-ns = deny+/api/k8s/{path...} | namespaced-services | QUERY | spa = deny+/api/k8s/{path...} | namespaced-services | QUERY | user-key = deny+/api/k8s/{path...} | namespaced-services | QUERY | user-key-verified = deny/api/k8s/{path...} | pod-logs | DELETE | admin-spa = deny/api/k8s/{path...} | pod-logs | DELETE | cua-cli = deny/api/k8s/{path...} | pod-logs | DELETE | dcr-client = deny@@ -2253,6 +2308,116 @@/api/k8s/{path...} | pool-create-disallowed-image | QUERY | spa = deny/api/k8s/{path...} | pool-create-disallowed-image | QUERY | user-key = deny/api/k8s/{path...} | pool-create-disallowed-image | QUERY | user-key-verified = deny+/api/k8s/{path...} | sandbox-item-image-patch | DELETE | admin-spa = deny+/api/k8s/{path...} | sandbox-item-image-patch | DELETE | cua-cli = deny+/api/k8s/{path...} | sandbox-item-image-patch | DELETE | dcr-client = deny+/api/k8s/{path...} | sandbox-item-image-patch | DELETE | empty-sub = deny+/api/k8s/{path...} | sandbox-item-image-patch | DELETE | github-oidc = deny+/api/k8s/{path...} | sandbox-item-image-patch | DELETE | oauth2-proxy = deny+/api/k8s/{path...} | sandbox-item-image-patch | DELETE | per-key-other-ns = deny+/api/k8s/{path...} | sandbox-item-image-patch | DELETE | per-key-owned-ns = deny+/api/k8s/{path...} | sandbox-item-image-patch | DELETE | spa = deny+/api/k8s/{path...} | sandbox-item-image-patch | DELETE | user-key = deny+/api/k8s/{path...} | sandbox-item-image-patch | DELETE | user-key-verified = deny+/api/k8s/{path...} | sandbox-item-image-patch | GET | admin-spa = allow+/api/k8s/{path...} | sandbox-item-image-patch | GET | cua-cli = allow+/api/k8s/{path...} | sandbox-item-image-patch | GET | dcr-client = deny+/api/k8s/{path...} | sandbox-item-image-patch | GET | empty-sub = deny+/api/k8s/{path...} | sandbox-item-image-patch | GET | github-oidc = deny+/api/k8s/{path...} | sandbox-item-image-patch | GET | oauth2-proxy = deny+/api/k8s/{path...} | sandbox-item-image-patch | GET | per-key-other-ns = deny+/api/k8s/{path...} | sandbox-item-image-patch | GET | per-key-owned-ns = deny+/api/k8s/{path...} | sandbox-item-image-patch | GET | spa = allow+/api/k8s/{path...} | sandbox-item-image-patch | GET | user-key = allow+/api/k8s/{path...} | sandbox-item-image-patch | GET | user-key-verified = allow+/api/k8s/{path...} | sandbox-item-image-patch | PATCH | admin-spa = deny+/api/k8s/{path...} | sandbox-item-image-patch | PATCH | cua-cli = deny+/api/k8s/{path...} | sandbox-item-image-patch | PATCH | dcr-client = deny+/api/k8s/{path...} | sandbox-item-image-patch | PATCH | empty-sub = deny+/api/k8s/{path...} | sandbox-item-image-patch | PATCH | github-oidc = deny+/api/k8s/{path...} | sandbox-item-image-patch | PATCH | oauth2-proxy = deny+/api/k8s/{path...} | sandbox-item-image-patch | PATCH | per-key-other-ns = deny+/api/k8s/{path...} | sandbox-item-image-patch | PATCH | per-key-owned-ns = deny+/api/k8s/{path...} | sandbox-item-image-patch | PATCH | spa = deny+/api/k8s/{path...} | sandbox-item-image-patch | PATCH | user-key = deny+/api/k8s/{path...} | sandbox-item-image-patch | PATCH | user-key-verified = deny+/api/k8s/{path...} | sandbox-item-image-patch | POST | admin-spa = deny+/api/k8s/{path...} | sandbox-item-image-patch | POST | cua-cli = deny+/api/k8s/{path...} | sandbox-item-image-patch | POST | dcr-client = deny+/api/k8s/{path...} | sandbox-item-image-patch | POST | empty-sub = deny+/api/k8s/{path...} | sandbox-item-image-patch | POST | github-oidc = deny+/api/k8s/{path...} | sandbox-item-image-patch | POST | oauth2-proxy = deny+/api/k8s/{path...} | sandbox-item-image-patch | POST | per-key-other-ns = deny+/api/k8s/{path...} | sandbox-item-image-patch | POST | per-key-owned-ns = deny+/api/k8s/{path...} | sandbox-item-image-patch | POST | spa = deny+/api/k8s/{path...} | sandbox-item-image-patch | POST | user-key = deny+/api/k8s/{path...} | sandbox-item-image-patch | POST | user-key-verified = deny+/api/k8s/{path...} | sandbox-item-image-patch | QUERY | admin-spa = deny+/api/k8s/{path...} | sandbox-item-image-patch | QUERY | cua-cli = deny+/api/k8s/{path...} | sandbox-item-image-patch | QUERY | dcr-client = deny+/api/k8s/{path...} | sandbox-item-image-patch | QUERY | empty-sub = deny+/api/k8s/{path...} | sandbox-item-image-patch | QUERY | github-oidc = deny+/api/k8s/{path...} | sandbox-item-image-patch | QUERY | oauth2-proxy = deny+/api/k8s/{path...} | sandbox-item-image-patch | QUERY | per-key-other-ns = deny+/api/k8s/{path...} | sandbox-item-image-patch | QUERY | per-key-owned-ns = deny+/api/k8s/{path...} | sandbox-item-image-patch | QUERY | spa = deny+/api/k8s/{path...} | sandbox-item-image-patch | QUERY | user-key = deny+/api/k8s/{path...} | sandbox-item-image-patch | QUERY | user-key-verified = deny+/api/k8s/{path...} | sandbox-item-services-patch | DELETE | admin-spa = deny+/api/k8s/{path...} | sandbox-item-services-patch | DELETE | cua-cli = deny+/api/k8s/{path...} | sandbox-item-services-patch | DELETE | dcr-client = deny+/api/k8s/{path...} | sandbox-item-services-patch | DELETE | empty-sub = deny+/api/k8s/{path...} | sandbox-item-services-patch | DELETE | github-oidc = deny+/api/k8s/{path...} | sandbox-item-services-patch | DELETE | oauth2-proxy = deny+/api/k8s/{path...} | sandbox-item-services-patch | DELETE | per-key-other-ns = deny+/api/k8s/{path...} | sandbox-item-services-patch | DELETE | per-key-owned-ns = deny+/api/k8s/{path...} | sandbox-item-services-patch | DELETE | spa = deny+/api/k8s/{path...} | sandbox-item-services-patch | DELETE | user-key = deny+/api/k8s/{path...} | sandbox-item-services-patch | DELETE | user-key-verified = deny+/api/k8s/{path...} | sandbox-item-services-patch | GET | admin-spa = allow+/api/k8s/{path...} | sandbox-item-services-patch | GET | cua-cli = allow+/api/k8s/{path...} | sandbox-item-services-patch | GET | dcr-client = deny+/api/k8s/{path...} | sandbox-item-services-patch | GET | empty-sub = deny+/api/k8s/{path...} | sandbox-item-services-patch | GET | github-oidc = deny+/api/k8s/{path...} | sandbox-item-services-patch | GET | oauth2-proxy = deny+/api/k8s/{path...} | sandbox-item-services-patch | GET | per-key-other-ns = deny+/api/k8s/{path...} | sandbox-item-services-patch | GET | per-key-owned-ns = deny+/api/k8s/{path...} | sandbox-item-services-patch | GET | spa = allow+/api/k8s/{path...} | sandbox-item-services-patch | GET | user-key = allow+/api/k8s/{path...} | sandbox-item-services-patch | GET | user-key-verified = allow+/api/k8s/{path...} | sandbox-item-services-patch | PATCH | admin-spa = allow+/api/k8s/{path...} | sandbox-item-services-patch | PATCH | cua-cli = allow+/api/k8s/{path...} | sandbox-item-services-patch | PATCH | dcr-client = deny+/api/k8s/{path...} | sandbox-item-services-patch | PATCH | empty-sub = deny+/api/k8s/{path...} | sandbox-item-services-patch | PATCH | github-oidc = deny+/api/k8s/{path...} | sandbox-item-services-patch | PATCH | oauth2-proxy = deny+/api/k8s/{path...} | sandbox-item-services-patch | PATCH | per-key-other-ns = deny+/api/k8s/{path...} | sandbox-item-services-patch | PATCH | per-key-owned-ns = deny+/api/k8s/{path...} | sandbox-item-services-patch | PATCH | spa = allow+/api/k8s/{path...} | sandbox-item-services-patch | PATCH | user-key = allow+/api/k8s/{path...} | sandbox-item-services-patch | PATCH | user-key-verified = allow+/api/k8s/{path...} | sandbox-item-services-patch | POST | admin-spa = deny+/api/k8s/{path...} | sandbox-item-services-patch | POST | cua-cli = deny+/api/k8s/{path...} | sandbox-item-services-patch | POST | dcr-client = deny+/api/k8s/{path...} | sandbox-item-services-patch | POST | empty-sub = deny+/api/k8s/{path...} | sandbox-item-services-patch | POST | github-oidc = deny+/api/k8s/{path...} | sandbox-item-services-patch | POST | oauth2-proxy = deny+/api/k8s/{path...} | sandbox-item-services-patch | POST | per-key-other-ns = deny+/api/k8s/{path...} | sandbox-item-services-patch | POST | per-key-owned-ns = deny+/api/k8s/{path...} | sandbox-item-services-patch | POST | spa = deny+/api/k8s/{path...} | sandbox-item-services-patch | POST | user-key = deny+/api/k8s/{path...} | sandbox-item-services-patch | POST | user-key-verified = deny+/api/k8s/{path...} | sandbox-item-services-patch | QUERY | admin-spa = deny+/api/k8s/{path...} | sandbox-item-services-patch | QUERY | cua-cli = deny+/api/k8s/{path...} | sandbox-item-services-patch | QUERY | dcr-client = deny+/api/k8s/{path...} | sandbox-item-services-patch | QUERY | empty-sub = deny+/api/k8s/{path...} | sandbox-item-services-patch | QUERY | github-oidc = deny+/api/k8s/{path...} | sandbox-item-services-patch | QUERY | oauth2-proxy = deny+/api/k8s/{path...} | sandbox-item-services-patch | QUERY | per-key-other-ns = deny+/api/k8s/{path...} | sandbox-item-services-patch | QUERY | per-key-owned-ns = deny+/api/k8s/{path...} | sandbox-item-services-patch | QUERY | spa = deny+/api/k8s/{path...} | sandbox-item-services-patch | QUERY | user-key = deny+/api/k8s/{path...} | sandbox-item-services-patch | QUERY | user-key-verified = deny/api/k8s/{path...} | ungranted-ns-pools | DELETE | admin-spa = deny/api/k8s/{path...} | ungranted-ns-pools | DELETE | cua-cli = deny/api/k8s/{path...} | ungranted-ns-pools | DELETE | dcr-client = denydiff --git a/libs/fleet/backend/docs/docs.go b/libs/fleet/backend/docs/docs.goindex 3290b7b274..1a2cec9e11 100644--- a/libs/fleet/backend/docs/docs.go+++ b/libs/fleet/backend/docs/docs.go@@ -1129,7 +1129,7 @@ const docTemplate = `{"BearerAuth": []}],- "description": "Forwards requests to http://127.0.0.1:8001 (the kubectl-proxy sidecar) so the caller can read K8s resources via the pod ServiceAccount. SPA-only; OPA-gated. The policy is an allowlist: only enumerated group/version/resource/method combinations are proxied (the osgym.cua.ai and cua.ai fleet CRDs, namespaced pod/service reads, pod logs and metrics, KubeVirt reads, and API discovery). Anything else, including Kubernetes events and any cluster-scoped path, is denied and never reaches the sidecar.",+ "description": "Forwards requests to http://127.0.0.1:8001 (the kubectl-proxy sidecar) so the caller can read K8s resources via the pod ServiceAccount. SPA-only; OPA-gated. The policy is an allowlist: only enumerated group/version/resource/method combinations are proxied (the osgym.cua.ai and cua.ai fleet CRDs, namespaced pod/service reads, a PATCH on osgymsandboxes items whose body touches only spec.vmTemplate.services, pod logs and metrics, KubeVirt reads, and API discovery). Anything else, including Kubernetes events and any cluster-scoped path, is denied and never reaches the sidecar.","tags": ["passthrough"],diff --git a/libs/fleet/backend/docs/swagger.json b/libs/fleet/backend/docs/swagger.jsonindex 4d69f36a3f..8d16f653e3 100644--- a/libs/fleet/backend/docs/swagger.json+++ b/libs/fleet/backend/docs/swagger.json@@ -1122,7 +1122,7 @@"BearerAuth": []}],- "description": "Forwards requests to http://127.0.0.1:8001 (the kubectl-proxy sidecar) so the caller can read K8s resources via the pod ServiceAccount. SPA-only; OPA-gated. The policy is an allowlist: only enumerated group/version/resource/method combinations are proxied (the osgym.cua.ai and cua.ai fleet CRDs, namespaced pod/service reads, pod logs and metrics, KubeVirt reads, and API discovery). Anything else, including Kubernetes events and any cluster-scoped path, is denied and never reaches the sidecar.",+ "description": "Forwards requests to http://127.0.0.1:8001 (the kubectl-proxy sidecar) so the caller can read K8s resources via the pod ServiceAccount. SPA-only; OPA-gated. The policy is an allowlist: only enumerated group/version/resource/method combinations are proxied (the osgym.cua.ai and cua.ai fleet CRDs, namespaced pod/service reads, a PATCH on osgymsandboxes items whose body touches only spec.vmTemplate.services, pod logs and metrics, KubeVirt reads, and API discovery). Anything else, including Kubernetes events and any cluster-scoped path, is denied and never reaches the sidecar.","tags": ["passthrough"],diff --git a/libs/fleet/backend/docs/swagger.yaml b/libs/fleet/backend/docs/swagger.yamlindex 43c1a24e15..2f45ab4ef1 100644--- a/libs/fleet/backend/docs/swagger.yaml+++ b/libs/fleet/backend/docs/swagger.yaml@@ -1208,7 +1208,8 @@ paths:sidecar) so the caller can read K8s resources via the pod ServiceAccount.SPA-only; OPA-gated. The policy is an allowlist: only enumerated group/version/resource/methodcombinations are proxied (the osgym.cua.ai and cua.ai fleet CRDs, namespaced- pod/service reads, pod logs and metrics, KubeVirt reads, and API discovery).+ pod/service reads, a PATCH on osgymsandboxes items whose body touches only+ spec.vmTemplate.services, pod logs and metrics, KubeVirt reads, and API discovery).Anything else, including Kubernetes events and any cluster-scoped path, isdenied and never reaches the sidecar.'parameters:diff --git a/libs/fleet/backend/handlers/k8s.go b/libs/fleet/backend/handlers/k8s.goindex ff646087b2..07051445e2 100644--- a/libs/fleet/backend/handlers/k8s.go+++ b/libs/fleet/backend/handlers/k8s.go@@ -29,7 +29,7 @@ func kubectlProxyAddr() string {// K8s godoc//// @Summary Authenticated proxy to the in-pod kubectl-proxy sidecar-// @Description Forwards requests to http://127.0.0.1:8001 (the kubectl-proxy sidecar) so the caller can read K8s resources via the pod ServiceAccount. SPA-only; OPA-gated. The policy is an allowlist: only enumerated group/version/resource/method combinations are proxied (the osgym.cua.ai and cua.ai fleet CRDs, namespaced pod/service reads, pod logs and metrics, KubeVirt reads, and API discovery). Anything else, including Kubernetes events and any cluster-scoped path, is denied and never reaches the sidecar.+// @Description Forwards requests to http://127.0.0.1:8001 (the kubectl-proxy sidecar) so the caller can read K8s resources via the pod ServiceAccount. SPA-only; OPA-gated. The policy is an allowlist: only enumerated group/version/resource/method combinations are proxied (the osgym.cua.ai and cua.ai fleet CRDs, namespaced pod/service reads, a PATCH on osgymsandboxes items whose body touches only spec.vmTemplate.services, pod logs and metrics, KubeVirt reads, and API discovery). Anything else, including Kubernetes events and any cluster-scoped path, is denied and never reaches the sidecar.// @Tags passthrough// @Param path path string true "K8s API path"// @Success 200 {string} string "K8s API response"