Skip to content

armgit / cua

Public Imported from GitHub
0

Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.

fix(auth): restrict initial Image API rollout to admin subjects (#7785)

r33drichards31c2184f860b
diff --git a/libs/fleet/backend/auth/IMAGE_ROLLOUT.md b/libs/fleet/backend/auth/IMAGE_ROLLOUT.md
new file mode 100644
index 0000000000..13d0f6e014
--- /dev/null
+++ b/libs/fleet/backend/auth/IMAGE_ROLLOUT.md
@@ -0,0 +1,36 @@
+# Initial Image API rollout
+
+`ImageRolloutPolicy` is a mandatory shared conjunct on `K8sRoutePolicy` and
+`ImageUploadsRoutePolicy`. It requires the existing `authz.is_admin` decision for:
+
+- Image collection POST and item PATCH/DELETE through
+ `/api/k8s/apis/images.cua.ai/v1alpha1/namespaces/{namespace}/images`.
+- POST `/api/image-uploads/presign`, before the upload handler or object store runs.
+
+This reuses `/feature-flags/cyclops-cs/admin-subs` as a user-subject cohort, not a
+namespace list. User API keys are evaluated using the owner subject resolved by
+`TokenAuthMiddleware`; already-authorized GitHub delegation from an admin owner
+uses the same existing subject semantics. Namespace keys do not acquire owner
+identity or Image proxy access. No membership or principal-family rules change.
+Membership uses the existing authorization flag cache (up to one minute); absent
+membership does not authorize an Image write.
+
+The gate is composed with `All`, not an alternative allow branch. Resource and
+principal allowlists, namespace ownership, billing admission (including its
+existing admin exemption), and Image body restrictions still apply. Presign
+namespace authorization remains in the handler. Read/list/watch behavior and
+other resources and routes are unchanged; unsupported methods and subresources
+remain denied by their existing policies/router.
+
+This restricts the initial API rollout only. It does not activate the controller,
+change `BuildDisabled`, deploy a preparation worker, or make a feature flag
+sufficient to start builds. Raw Kubernetes API admission is a separate unresolved
+boundary; this HTTP authorization policy is not an admission webhook and cannot
+gate callers that bypass the Cyclops API. Previously issued upload URLs are not
+revoked by this policy.
+
+Regression coverage includes the Go Image authorization matrices, the real
+presign route middleware plus handler, Rego scope tests, and the route
+characterization table. The table's expected changes are only nonadmin Image
+POST/DELETE decisions and nonadmin upload POST decisions (its Image PATCH rows
+already lack the required merge-patch content type and remain denied).
diff --git a/libs/fleet/backend/auth/image_rollout.rego b/libs/fleet/backend/auth/image_rollout.rego
new file mode 100644
index 0000000000..c0c350bddb
--- /dev/null
+++ b/libs/fleet/backend/auth/image_rollout.rego
@@ -0,0 +1,31 @@
+package image_rollout
+
+import data.authz
+
+default allow = false
+
+applies {
+ input.route == "/api/image-uploads/presign"
+ input.method == "POST"
+}
+
+applies {
+ input.route == "/api/k8s/{path...}"
+ {"POST", "PATCH", "DELETE"}[input.method]
+ parts := split(input.params.path, "/")
+ count(parts) >= 6
+ parts[0] == "apis"
+ parts[1] == "images.cua.ai"
+ parts[2] == "v1alpha1"
+ parts[3] == "namespaces"
+ parts[5] == "images"
+}
+
+allow {
+ not applies
+}
+
+allow {
+ applies
+ authz.is_admin
+}
diff --git a/libs/fleet/backend/auth/image_rollout_test.rego b/libs/fleet/backend/auth/image_rollout_test.rego
new file mode 100644
index 0000000000..6afa385ac4
--- /dev/null
+++ b/libs/fleet/backend/auth/image_rollout_test.rego
@@ -0,0 +1,70 @@
+package image_rollout_test
+
+import rego.v1
+
+import data.image_rollout
+
+image_input(method, sub) := {
+ "route": "/api/k8s/{path...}",
+ "method": method,
+ "params": {"path": "apis/images.cua.ai/v1alpha1/namespaces/tenant-a/images/image-a"},
+ "user": {"sub": sub},
+ "flags": {"admin_subs": ["admin-owner"]},
+}
+
+test_admin_image_mutations_allowed if {
+ every method in ["POST", "PATCH", "DELETE"] {
+ image_rollout.allow with input as image_input(method, "admin-owner")
+ }
+}
+
+test_nonadmin_image_mutations_denied if {
+ every method in ["POST", "PATCH", "DELETE"] {
+ not image_rollout.allow with input as image_input(method, "ordinary-owner")
+ }
+}
+
+test_read_methods_unchanged if {
+ every method in ["GET", "HEAD", "OPTIONS"] {
+ image_rollout.allow with input as image_input(method, "ordinary-owner")
+ }
+}
+
+test_upload_presign_uses_same_subject_membership if {
+ image_rollout.allow with input as image_input("POST", "admin-owner")
+ with input.route as "/api/image-uploads/presign"
+ not image_rollout.allow with input as image_input("POST", "ordinary-owner")
+ with input.route as "/api/image-uploads/presign"
+}
+
+test_missing_membership_denies if {
+ every flags in [{}, {"admin_subs": []}] {
+ not image_rollout.allow with input as image_input("POST", "admin-owner")
+ with input.flags as flags
+ }
+}
+
+test_membership_is_subject_not_namespace if {
+ not image_rollout.allow with input as image_input("POST", "ordinary-owner")
+ with input.flags.admin_subs as ["tenant-a"]
+}
+
+test_other_resources_unchanged if {
+ every path in [
+ "apis/osgym.cua.ai/v1alpha1/namespaces/tenant-a/osgymsandboxclaims",
+ "apis/images.cua.ai/v1alpha1/namespaces/tenant-a/builders",
+ "apis/other.example/v1alpha1/namespaces/tenant-a/images",
+ ] {
+ every method in ["POST", "PATCH", "DELETE"] {
+ image_rollout.allow with input as image_input(method, "ordinary-owner")
+ with input.params.path as path
+ }
+ }
+}
+
+test_other_routes_unchanged if {
+ every route in ["/api/namespaces", "/api/keys", "/api/user-keys"] {
+ image_rollout.allow with input as image_input("POST", "ordinary-owner")
+ with input.route as route
+ }
+}
diff --git a/libs/fleet/backend/auth/middlewares.go b/libs/fleet/backend/auth/middlewares.go
index d76f490e66..4e6e98391f 100644
--- a/libs/fleet/backend/auth/middlewares.go
+++ b/libs/fleet/backend/auth/middlewares.go
@@ -62,6 +62,9 @@ var sandboxServicesAdmissionPolicy string
//go:embed image_admission.rego
var imageAdmissionPolicy string
+//go:embed image_rollout.rego
+var imageRolloutPolicy 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
@@ -398,6 +401,7 @@ func LoadOpa() {
RegisterPolicyModule("custom-resource-creation-admission", "custom_resource_creation_admission.rego", customResourceCreationAdmissionPolicy)
RegisterPolicyModule("sandbox-services-admission", "sandbox_services_admission.rego", sandboxServicesAdmissionPolicy)
RegisterPolicyModule("image-admission", "image_admission.rego", imageAdmissionPolicy)
+ RegisterPolicyModule("image-rollout", "image_rollout.rego", imageRolloutPolicy)
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_image_rollout_test.go b/libs/fleet/backend/auth/policy_image_rollout_test.go
new file mode 100644
index 0000000000..f9e5953ff8
--- /dev/null
+++ b/libs/fleet/backend/auth/policy_image_rollout_test.go
@@ -0,0 +1,70 @@
+package auth
+
+import (
+ "net/http"
+ "testing"
+)
+
+func TestImageAdminRollout(t *testing.T) {
+ t.Cleanup(resetFlagsCache)
+ setCardAdmissionFlags(t, false, "admin-owner")
+ installCountingFacts(t, "tenant-a")
+ for _, subject := range []string{"admin-owner", "ordinary-owner"} {
+ userKey := &User{ID: "service-account", AZP: "ukey-example", Claims: map[string]string{"user_sub": subject}}
+ if err := applyUserKeyIdentity(userKey, "ukey-"); err != nil {
+ t.Fatal(err)
+ }
+ for _, principal := range []struct {
+ name string
+ user *User
+ }{
+ {"interactive", &User{ID: subject, AZP: "cyclops-cs-spa"}},
+ {"cli", &User{ID: subject, AZP: "cua-cli"}},
+ {"desktop", &User{ID: subject, AZP: "cua-desktop"}},
+ {"resolved-user-key", userKey},
+ {"github", &User{ID: subject, PrincipalType: PrincipalTypeGitHubOIDC, AllowedNamespaces: []string{"tenant-a"}}},
+ {"namespace-key", &User{ID: "service-account", AZP: "key-example", Namespace: "tenant-a", Claims: map[string]string{"user_sub": subject}}},
+ {"namespace-key-admin-sub", &User{ID: subject, AZP: "key-example", Namespace: "tenant-a"}},
+ } {
+ for _, namespace := range []string{"tenant-a", "tenant-b"} {
+ for _, operation := range []struct{ name, method, suffix, body string }{
+ {"create", "POST", "", `{"spec":{}}`},
+ {"patch", "PATCH", "/image-a", `{"spec":{}}`},
+ {"delete", "DELETE", "/image-a", ""},
+ {"list", "GET", "", ""},
+ {"get", "GET", "/image-a", ""},
+ {"watch", "GET", "?watch=true", ""},
+ } {
+ t.Run(subject+"/"+principal.name+"/"+namespace+"/"+operation.name, func(t *testing.T) {
+ path := "apis/images.cua.ai/v1alpha1/namespaces/" + namespace + "/images" + operation.suffix
+ response, reached := imagePolicyResponse(t, operation.method, path, operation.body, principal.user)
+ allowed := namespace == "tenant-a" && principal.user.AZP != "key-example" && (subject == "admin-owner" || operation.method == "GET")
+ want := http.StatusForbidden
+ if allowed {
+ want = http.StatusNoContent
+ }
+ if response.Code != want || reached != allowed {
+ t.Fatalf("status=%d reached=%v, want %d; %s", response.Code, reached, want, response.Body.String())
+ }
+ })
+ }
+ }
+ }
+ }
+}
+
+func TestImageRolloutRequiresResolvedAdminMembership(t *testing.T) {
+ t.Cleanup(resetFlagsCache)
+ setCardAdmissionFlags(t, false)
+ installCountingFacts(t, "tenant-a")
+ for _, admins := range []string{`[]`, `not-json`, `["someone-else"]`} {
+ t.Run(admins, func(t *testing.T) {
+ t.Setenv("CYCLOPS_CS_ADMIN_SUBS", admins)
+ InvalidateFeatureFlags()
+ response, reached := imagePolicyResponse(t, "POST", "apis/images.cua.ai/v1alpha1/namespaces/tenant-a/images", `{"spec":{}}`, &User{ID: "owner", AZP: "cua-cli"})
+ if response.Code != http.StatusForbidden || reached {
+ t.Fatalf("status=%d reached=%v; %s", response.Code, reached, response.Body.String())
+ }
+ })
+ }
+}
diff --git a/libs/fleet/backend/auth/policy_images_test.go b/libs/fleet/backend/auth/policy_images_test.go
index fae5ea0df4..3bacc62e8b 100644
--- a/libs/fleet/backend/auth/policy_images_test.go
+++ b/libs/fleet/backend/auth/policy_images_test.go
@@ -42,7 +42,7 @@ func imagePolicyResponseWithContentTypes(t *testing.T, method, path, body string
func TestImageTenantCRUD(t *testing.T) {
t.Cleanup(resetFlagsCache)
- setCardAdmissionFlags(t, false)
+ setCardAdmissionFlags(t, false, "owner-a")
installCountingFacts(t, "tenant-a")
for _, principal := range []struct {
name string
@@ -80,7 +80,7 @@ func TestImageTenantCRUD(t *testing.T) {
func TestImageMutationBillingAdmission(t *testing.T) {
t.Cleanup(resetFlagsCache)
- setCardAdmissionFlags(t, true)
+ setCardAdmissionFlags(t, true, "admin")
installCountingFacts(t, "tenant-a")
stripe := &countingAdmissionFacts{cacheKey: StripeCardsFactProvider}
installAdmissionFacts(t, StripeCardsFactProvider, stripe)
@@ -92,6 +92,9 @@ func TestImageMutationBillingAdmission(t *testing.T) {
}{
{"user", &User{ID: "owner-a", AZP: "cua-cli"}},
{"github", &User{ID: "owner-a", PrincipalType: PrincipalTypeGitHubOIDC, AllowedNamespaces: []string{"tenant-a"}}},
+ {"admin-user", &User{ID: "admin", AZP: "cua-cli"}},
+ {"admin-user-key", &User{ID: "admin", AZP: "ukey-example", PrincipalType: PrincipalTypeUserKey}},
+ {"admin-github", &User{ID: "admin", PrincipalType: PrincipalTypeGitHubOIDC, AllowedNamespaces: []string{"tenant-a"}}},
} {
for _, hasCard := range []bool{false, true} {
for _, operation := range []struct{ name, method, suffix, body string }{
@@ -115,12 +118,8 @@ func TestImageMutationBillingAdmission(t *testing.T) {
}
before := stripe.loads.Load()
response, reached := imagePolicyResponse(t, operation.method, "apis/images.cua.ai/v1alpha1/namespaces/tenant-a/images"+operation.suffix, operation.body, principal.user)
- billed := operation.method == "POST" || operation.method == "PATCH"
wantStatus, wantLoads := http.StatusNoContent, int64(0)
- if billed {
- wantLoads = 1
- }
- if operation.method == "PUT" || (billed && !hasCard) {
+ if operation.method == "PUT" || (operation.method != "GET" && principal.user.ID != "admin") {
wantStatus = http.StatusForbidden
}
if response.Code != wantStatus || reached != (wantStatus == http.StatusNoContent) || stripe.loads.Load()-before != wantLoads {
@@ -266,7 +265,7 @@ func TestImagePolicyBoundaries(t *testing.T) {
}
}
-func TestImageCreationRequiresBillingAdmission(t *testing.T) {
+func TestImageCreationBillingAdmissionRemainsIndependent(t *testing.T) {
t.Cleanup(resetFlagsCache)
setCardAdmissionFlags(t, true)
installCountingFacts(t, "tenant-a")
@@ -275,13 +274,22 @@ func TestImageCreationRequiresBillingAdmission(t *testing.T) {
installAdmissionFacts(t, CurrentYearFactProvider, &countingAdmissionFacts{cacheKey: CurrentYearFactProvider, facts: FactSet{"current_year": 2026}})
installAdmissionFacts(t, CurrentMonthFactProvider, &countingAdmissionFacts{cacheKey: CurrentMonthFactProvider, facts: FactSet{"current_month": 9}})
const path = "apis/images.cua.ai/v1alpha1/namespaces/tenant-a/images"
- user := &User{ID: "owner-a", AZP: "cua-cli"}
- response, reached := imagePolicyResponse(t, "POST", path, `{"spec":{}}`, user)
+ checkBilling := func() (*httptest.ResponseRecorder, bool) {
+ reached := false
+ handler := PolicyMiddleware(All(BasePolicy(), CustomResourceCreationAdmissionPolicy()))(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
+ reached = true
+ w.WriteHeader(http.StatusNoContent)
+ }))
+ response := httptest.NewRecorder()
+ handler.ServeHTTP(response, cardAdmissionRequest("POST", path, "owner-a"))
+ return response, reached
+ }
+ response, reached := checkBilling()
if response.Code != http.StatusForbidden || reached || stripe.loads.Load() != 1 {
t.Fatalf("without card: status=%d reached=%v stripe loads=%d", response.Code, reached, stripe.loads.Load())
}
stripe.facts = FactSet{"cards": []map[string]any{{"exp_year": 2027, "exp_month": 1}}}
- response, reached = imagePolicyResponse(t, "POST", path, `{"spec":{}}`, user)
+ response, reached = checkBilling()
if response.Code != http.StatusNoContent || !reached {
t.Fatalf("with card: status=%d reached=%v; %s", response.Code, reached, response.Body.String())
}
diff --git a/libs/fleet/backend/auth/policy_routes.go b/libs/fleet/backend/auth/policy_routes.go
index d8b71b53ee..9fcbd5263b 100644
--- a/libs/fleet/backend/auth/policy_routes.go
+++ b/libs/fleet/backend/auth/policy_routes.go
@@ -188,7 +188,14 @@ func AccountLookupRoutePolicy() Node {
// ImageUploadsRoutePolicy guards bounded image upload signing. Namespace ownership
// is evaluated by the handler because the namespace is carried in the JSON body.
func ImageUploadsRoutePolicy() Node {
- return All(BasePolicy(), surfaceLeaf("authz-image-uploads", "data.authz_image_uploads.allow"))
+ return All(BasePolicy(), surfaceLeaf("authz-image-uploads", "data.authz_image_uploads.allow"), ImageRolloutPolicy())
+}
+
+func ImageRolloutPolicy() Node {
+ return Policy(
+ Modules(Registered("authz"), Registered("image-rollout")),
+ Query("data.image_rollout.allow"),
+ )
}
// K8sRoutePolicy guards /api/k8s/{path...}. It is the same base + surface shape
@@ -248,6 +255,7 @@ func K8sRoutePolicy() Node {
ServiceWriteNotSupportedMessage,
),
surfaceLeaf("authz-k8s", "data.authz_k8s.allow"),
+ ImageRolloutPolicy(),
NamespaceOwnershipPolicy(),
Because(CustomResourceCreationAdmissionPolicy(), BillingSetupRequiredMessage),
Policy(
diff --git a/libs/fleet/backend/auth/policy_test.go b/libs/fleet/backend/auth/policy_test.go
index f6323b16bd..3561b42bc6 100644
--- a/libs/fleet/backend/auth/policy_test.go
+++ b/libs/fleet/backend/auth/policy_test.go
@@ -38,6 +38,7 @@ func TestRouteModulesNeverReadInputFacts(t *testing.T) {
"pool_admission.rego": poolAdmissionPolicy,
"sandbox_services_admission.rego": sandboxServicesAdmissionPolicy,
"image_admission.rego": imageAdmissionPolicy,
+ "image_rollout.rego": imageRolloutPolicy,
}
// 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/testdata/image-uploads-route-plan.txt b/libs/fleet/backend/auth/testdata/image-uploads-route-plan.txt
index 5186cb9892..7a0b9c2e8d 100644
--- a/libs/fleet/backend/auth/testdata/image-uploads-route-plan.txt
+++ b/libs/fleet/backend/auth/testdata/image-uploads-route-plan.txt
@@ -1,3 +1,4 @@
All
Leaf query=data.authz_base.allow source=registered:authz-base
Leaf query=data.authz_image_uploads.allow source=multi["registered:authz","registered:authz-image-uploads"]
+ Leaf query=data.image_rollout.allow source=multi["registered:authz","registered:image-rollout"]
diff --git a/libs/fleet/backend/auth/testdata/k8s-route-plan.txt b/libs/fleet/backend/auth/testdata/k8s-route-plan.txt
index 1ceb7b7932..5873130a03 100644
--- a/libs/fleet/backend/auth/testdata/k8s-route-plan.txt
+++ b/libs/fleet/backend/auth/testdata/k8s-route-plan.txt
@@ -3,6 +3,7 @@ All
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"]
+ Leaf query=data.image_rollout.allow source=multi["registered:authz","registered:image-rollout"]
Any
Leaf query=data.authz_ownership.claim_allow source=multi["registered:authz","registered:authz-ownership"]
All
diff --git a/libs/fleet/backend/auth/testdata/route-authorization-table.txt b/libs/fleet/backend/auth/testdata/route-authorization-table.txt
index c0957c7a5a..70164816b8 100644
--- a/libs/fleet/backend/auth/testdata/route-authorization-table.txt
+++ b/libs/fleet/backend/auth/testdata/route-authorization-table.txt
@@ -967,16 +967,16 @@
/api/image-uploads/presign | plain | PATCH | user-key = allow
/api/image-uploads/presign | plain | PATCH | user-key-verified = allow
/api/image-uploads/presign | plain | POST | admin-spa = allow
-/api/image-uploads/presign | plain | POST | cua-cli = allow
+/api/image-uploads/presign | plain | POST | cua-cli = deny
/api/image-uploads/presign | plain | POST | dcr-client = deny
/api/image-uploads/presign | plain | POST | empty-sub = deny
-/api/image-uploads/presign | plain | POST | github-oidc = allow
+/api/image-uploads/presign | plain | POST | github-oidc = deny
/api/image-uploads/presign | plain | POST | oauth2-proxy = deny
-/api/image-uploads/presign | plain | POST | per-key-other-ns = allow
-/api/image-uploads/presign | plain | POST | per-key-owned-ns = allow
-/api/image-uploads/presign | plain | POST | spa = allow
-/api/image-uploads/presign | plain | POST | user-key = allow
-/api/image-uploads/presign | plain | POST | user-key-verified = allow
+/api/image-uploads/presign | plain | POST | per-key-other-ns = deny
+/api/image-uploads/presign | plain | POST | per-key-owned-ns = deny
+/api/image-uploads/presign | plain | POST | spa = deny
+/api/image-uploads/presign | plain | POST | user-key = deny
+/api/image-uploads/presign | plain | POST | user-key-verified = deny
/api/image-uploads/presign | plain | QUERY | admin-spa = allow
/api/image-uploads/presign | plain | QUERY | cua-cli = allow
/api/image-uploads/presign | plain | QUERY | dcr-client = deny
@@ -1847,16 +1847,16 @@
/api/k8s/{path...} | image-collection | PATCH | user-key = deny
/api/k8s/{path...} | image-collection | PATCH | user-key-verified = deny
/api/k8s/{path...} | image-collection | POST | admin-spa = allow
-/api/k8s/{path...} | image-collection | POST | cua-cli = allow
+/api/k8s/{path...} | image-collection | POST | cua-cli = deny
/api/k8s/{path...} | image-collection | POST | dcr-client = deny
/api/k8s/{path...} | image-collection | POST | empty-sub = deny
-/api/k8s/{path...} | image-collection | POST | github-oidc = allow
+/api/k8s/{path...} | image-collection | POST | github-oidc = deny
/api/k8s/{path...} | image-collection | POST | oauth2-proxy = deny
/api/k8s/{path...} | image-collection | POST | per-key-other-ns = deny
/api/k8s/{path...} | image-collection | POST | per-key-owned-ns = deny
-/api/k8s/{path...} | image-collection | POST | spa = allow
-/api/k8s/{path...} | image-collection | POST | user-key = allow
-/api/k8s/{path...} | image-collection | POST | user-key-verified = allow
+/api/k8s/{path...} | image-collection | POST | spa = deny
+/api/k8s/{path...} | image-collection | POST | user-key = deny
+/api/k8s/{path...} | image-collection | POST | user-key-verified = deny
/api/k8s/{path...} | image-collection | QUERY | admin-spa = deny
/api/k8s/{path...} | image-collection | QUERY | cua-cli = deny
/api/k8s/{path...} | image-collection | QUERY | dcr-client = deny
@@ -1924,16 +1924,16 @@
/api/k8s/{path...} | image-group-builders | QUERY | user-key = deny
/api/k8s/{path...} | image-group-builders | QUERY | user-key-verified = deny
/api/k8s/{path...} | image-item | DELETE | admin-spa = allow
-/api/k8s/{path...} | image-item | DELETE | cua-cli = allow
+/api/k8s/{path...} | image-item | DELETE | cua-cli = deny
/api/k8s/{path...} | image-item | DELETE | dcr-client = deny
/api/k8s/{path...} | image-item | DELETE | empty-sub = deny
-/api/k8s/{path...} | image-item | DELETE | github-oidc = allow
+/api/k8s/{path...} | image-item | DELETE | github-oidc = deny
/api/k8s/{path...} | image-item | DELETE | oauth2-proxy = deny
/api/k8s/{path...} | image-item | DELETE | per-key-other-ns = deny
/api/k8s/{path...} | image-item | DELETE | per-key-owned-ns = deny
-/api/k8s/{path...} | image-item | DELETE | spa = allow
-/api/k8s/{path...} | image-item | DELETE | user-key = allow
-/api/k8s/{path...} | image-item | DELETE | user-key-verified = allow
+/api/k8s/{path...} | image-item | DELETE | spa = deny
+/api/k8s/{path...} | image-item | DELETE | user-key = deny
+/api/k8s/{path...} | image-item | DELETE | user-key-verified = deny
/api/k8s/{path...} | image-item | GET | admin-spa = allow
/api/k8s/{path...} | image-item | GET | cua-cli = allow
/api/k8s/{path...} | image-item | GET | dcr-client = deny
diff --git a/libs/fleet/backend/handlers/image_uploads_rollout_test.go b/libs/fleet/backend/handlers/image_uploads_rollout_test.go
new file mode 100644
index 0000000000..55728e9438
--- /dev/null
+++ b/libs/fleet/backend/handlers/image_uploads_rollout_test.go
@@ -0,0 +1,62 @@
+package handlers
+
+import (
+ "net/http"
+ "net/http/httptest"
+ "testing"
+
+ "cyclops-cs-backend/auth"
+)
+
+func TestPresignImageUploadsAdminRolloutRoute(t *testing.T) {
+ t.Setenv("CYCLOPS_CS_ADMIN_SUBS", `["admin-owner"]`)
+ auth.InvalidateFeatureFlags()
+ t.Cleanup(auth.InvalidateFeatureFlags)
+ auth.LoadOpa()
+ for _, subject := range []string{"admin-owner", "ordinary-owner"} {
+ for _, principal := range []struct {
+ name string
+ user *auth.User
+ }{
+ {"interactive", &auth.User{ID: subject, AZP: "cyclops-cs-spa"}},
+ {"cli", &auth.User{ID: subject, AZP: "cua-cli"}},
+ {"user-key", &auth.User{ID: subject, AZP: "ukey-example", PrincipalType: auth.PrincipalTypeUserKey}},
+ {"github", &auth.User{ID: subject, PrincipalType: auth.PrincipalTypeGitHubOIDC, AllowedNamespaces: []string{"workers"}}},
+ {"namespace-key", &auth.User{ID: "service-account", AZP: "key-example", Namespace: "workers", Claims: map[string]string{"user_sub": subject}}},
+ } {
+ for _, namespace := range []string{"workers", "foreign"} {
+ t.Run(subject+"/"+principal.name+"/"+namespace, func(t *testing.T) {
+ status := http.StatusForbidden
+ if namespace == "workers" {
+ status = http.StatusOK
+ }
+ fakeK8s := newFakeK8s(status, `{"items":[]}`)
+ defer fakeK8s.server.Close()
+ overrideK8sClient(fakeK8s.server.Client(), fakeK8s.server.URL, "fake-sa-token")
+ store := &fakeImageObjectStore{presignedURL: "https://objects.example.test/upload"}
+ h := imageUploadHandlers(store)
+ mux := http.NewServeMux()
+ const route = "/api/image-uploads/presign"
+ mux.Handle("POST "+route, auth.RouteContext(route)(auth.RouteMiddleware(route)(http.HandlerFunc(h.PresignImageUploads))))
+ payload := validImageUploadRequest("rootfs")
+ payload.Namespace = namespace
+ response := httptest.NewRecorder()
+ mux.ServeHTTP(response, withUser(jsonRequest(t, payload), principal.user))
+ allowed := subject == "admin-owner" && principal.name != "namespace-key" && namespace == "workers"
+ want := http.StatusForbidden
+ if allowed {
+ want = http.StatusOK
+ }
+ if response.Code != want {
+ t.Fatalf("status=%d, want %d; %s", response.Code, want, response.Body.String())
+ }
+ if !allowed {
+ assertImageObjectStoreUnused(t, store)
+ } else if len(store.presignCalls) != 1 {
+ t.Fatalf("presign calls=%d, want 1", len(store.presignCalls))
+ }
+ })
+ }
+ }
+ }
+}