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.

Delete cyclops-cs/backend/handlers/gateway.go (#6702)

r33drichardse33410773aa0
diff --git a/libs/fleet/backend/auth/auth.go b/libs/fleet/backend/auth/auth.go
index de0adcb14b..41c3c1acbe 100644
--- a/libs/fleet/backend/auth/auth.go
+++ b/libs/fleet/backend/auth/auth.go
@@ -5,10 +5,7 @@
// tokens do not carry a useful `aud`; GitHub OIDC validates signed
// audiences separately.
// - OPA (Rego) is used for all route-level authorization via
-// OpaMiddleware; see auth/authz.rego. The gateway surface additionally
-// enforces that the token's `namespace` claim equals "pool-{name}"
-// (CUA-527), preventing a compromised key from reaching any pool other
-// than its own.
+// OpaMiddleware; see auth/authz.rego.
// - Three token families: exact interactive clients, per-key clients, and
// user-key clients; route policy enforces each family and required claims.
package auth
diff --git a/libs/fleet/backend/auth/authz.rego b/libs/fleet/backend/auth/authz.rego
index dab53c1fbe..3b0164e912 100644
--- a/libs/fleet/backend/auth/authz.rego
+++ b/libs/fleet/backend/auth/authz.rego
@@ -14,17 +14,6 @@
# rather than 410, preserving the auth boundary
# even for a retired surface.
#
-# /api/gateway/{name} — orchestrator proxy. Requires a token issued to
-# a per-key client (azp starts with "key-") with:
-# • a non-empty `namespace` claim
-# • `namespace` == "{name}" (the token's
-# hardcoded-claim mapper must name the exact pool
-# the client belongs to, so one compromised key
-# cannot reach another pool)
-# Per-pool orchestrators no longer have a direct
-# Tailscale Ingress — all traffic MUST flow through
-# this proxy (CUA-527).
-#
# Data-visibility filtering (which events/env-vars the caller may see) lives
# in filters.rego, not here. authz.rego decides allow/deny only.
package authz
@@ -257,23 +246,6 @@ is_batch_route { input.route == "/api/label/{pool}/{label}/status" }
is_batch_route { input.route == "/api/label/{pool}/{label}/results" }
is_batch_route { input.route == "/api/label/{pool}/{label}" }
-# /api/gateway/{name}[/{path...}].
-#
-# The JWT `namespace` claim is set by a hardcoded-claim protocol mapper on
-# the per-key Keycloak client. Pool name = namespace name (1:1), so we
-# enforce the exact match here: a token for pool "foo" carries
-# namespace="foo" and may only reach /api/gateway/foo/…
-allow {
- is_gateway_route
- is_per_key_client
- valid_dns_label(input.params.name)
- input.user.namespace != ""
- input.user.namespace == input.params.name
-}
-
-is_gateway_route { input.route == "/api/gateway/{name}" }
-is_gateway_route { input.route == "/api/gateway/{name}/{path...}" }
-
# /api/svc/{namespace}/{service}[/{path...}] — generic service proxy.
#
# OPA gates authentication + parameter shape ONLY. The proxy dials
diff --git a/libs/fleet/backend/auth/authz_test.rego b/libs/fleet/backend/auth/authz_test.rego
index 8aebf09625..78cffd9334 100644
--- a/libs/fleet/backend/auth/authz_test.rego
+++ b/libs/fleet/backend/auth/authz_test.rego
@@ -46,87 +46,6 @@ test_keys_non_spa_denied if {
}
}
-# ── /api/gateway ──────────────────────────────────────────────────────────────
-#
-# Policy (CUA-527): token's `namespace` claim MUST equal the pool name.
-# A per-key client holds exactly one pool; namespace is set by the Keycloak
-# hardcoded-claim mapper.
-
-test_gateway_exact_namespace_allowed if {
- authz.allow with input as {
- "route": "/api/gateway/{name}",
- "method": "GET",
- "path": "/api/gateway/mypool",
- "params": {"name": "mypool"},
- "user": {"sub": "svc-123", "azp": "key-mypool", "namespace": "mypool", "email": ""},
- }
-}
-
-test_gateway_path_exact_namespace_allowed if {
- authz.allow with input as {
- "route": "/api/gateway/{name}/{path...}",
- "method": "GET",
- "path": "/api/gateway/mypool/step",
- "params": {"name": "mypool", "path": "step"},
- "user": {"sub": "svc-123", "azp": "key-mypool", "namespace": "mypool", "email": ""},
- }
-}
-
-# Wrong namespace — must be rejected (cross-pool attack).
-test_gateway_wrong_namespace_denied if {
- not authz.allow with input as {
- "route": "/api/gateway/{name}",
- "method": "GET",
- "path": "/api/gateway/mypool",
- "params": {"name": "mypool"},
- "user": {"sub": "svc-123", "azp": "key-mypool", "namespace": "otherpool", "email": ""},
- }
-}
-
-# Namespace matches pool name — allowed (1:1 mapping).
-test_gateway_matching_name_namespace_allowed if {
- authz.allow with input as {
- "route": "/api/gateway/{name}",
- "method": "GET",
- "path": "/api/gateway/mypool",
- "params": {"name": "mypool"},
- "user": {"sub": "svc-123", "azp": "key-mypool", "namespace": "mypool", "email": ""},
- }
-}
-
-# Empty namespace — denied.
-test_gateway_empty_namespace_denied if {
- not authz.allow with input as {
- "route": "/api/gateway/{name}",
- "method": "GET",
- "path": "/api/gateway/mypool",
- "params": {"name": "mypool"},
- "user": {"sub": "svc-123", "azp": "key-mypool", "namespace": "", "email": ""},
- }
-}
-
-# SPA token on gateway route — denied (must use per-key client).
-test_gateway_spa_token_denied if {
- not authz.allow with input as {
- "route": "/api/gateway/{name}",
- "method": "GET",
- "path": "/api/gateway/mypool",
- "params": {"name": "mypool"},
- "user": {"sub": "user-123", "azp": "cyclops-cs-spa", "namespace": "mypool", "email": "[email protected]"},
- }
-}
-
-# Invalid pool name (contains uppercase) — denied by DNS-label check.
-test_gateway_invalid_pool_name_denied if {
- not authz.allow with input as {
- "route": "/api/gateway/{name}",
- "method": "GET",
- "path": "/api/gateway/MyPool",
- "params": {"name": "MyPool"},
- "user": {"sub": "svc-123", "azp": "key-mypool", "namespace": "MyPool", "email": ""},
- }
-}
-
# ── /api/k8s ──────────────────────────────────────────────────────────────────
test_k8s_spa_allowed if {
@@ -174,8 +93,7 @@ test_orch_cua_cli_allowed if {
# ── /api/batch and /api/label ────────────────────────────────────────────────
#
# Pool is in the URL path. A per-key token's `namespace` claim MUST equal
-# the pool name, mirroring /api/gateway/{name}. SPA tokens can target any
-# pool.
+# the pool name. SPA tokens can target any pool.
test_batch_submit_spa_allowed if {
authz.allow with input as {
diff --git a/libs/fleet/backend/auth/middlewares.go b/libs/fleet/backend/auth/middlewares.go
index e4ae0349ec..c901e1a88a 100644
--- a/libs/fleet/backend/auth/middlewares.go
+++ b/libs/fleet/backend/auth/middlewares.go
@@ -400,7 +400,8 @@ func applyUserKeyIdentity(user *User, userKeyPfx string) error {
//
// The `route` and `params` map are filled by RouteContext below before
// this middleware runs; they let policy reason about the matched
-// route ("/api/gateway/{name}") and its parameters separately from the
+// route ("/api/orch/{namespace}/{service}/{path...}") and its parameters
+// separately from the
// raw URL path.
func OpaMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
diff --git a/libs/fleet/backend/docs/docs.go b/libs/fleet/backend/docs/docs.go
index 50ee4fa168..ea93c78b12 100644
--- a/libs/fleet/backend/docs/docs.go
+++ b/libs/fleet/backend/docs/docs.go
@@ -529,38 +529,6 @@ const docTemplate = `{
}
}
},
- "/api/gateway/{name}/{path}": {
- "get": {
- "description": "The per-pool HTTP orchestrator has been deprecated and removed. All pools now use OSGymSandboxClaim CRs exclusively (Path B). This endpoint returns 410 Gone for any request. See CUA-609.",
- "tags": [
- "gateway"
- ],
- "summary": "DEPRECATED: Per-pool orchestrator reverse-proxy (CUA-609)",
- "parameters": [
- {
- "type": "string",
- "description": "Pool name (DNS-1123 label)",
- "name": "name",
- "in": "path",
- "required": true
- },
- {
- "type": "string",
- "description": "Upstream path (ignored)",
- "name": "path",
- "in": "path"
- }
- ],
- "responses": {
- "410": {
- "description": "Orchestrator HTTP layer deprecated (CUA-609)",
- "schema": {
- "$ref": "#/definitions/handlers.ErrorResponse"
- }
- }
- }
- }
- },
"/api/k8s/{path}": {
"get": {
"security": [
@@ -1597,7 +1565,7 @@ const docTemplate = `{
},
"securityDefinitions": {
"BearerAuth": {
- "description": "Keycloak access token. For /api/keys and /api/{k8s,orch} the token is an interactive user JWT (azp=cyclops-cs-spa or azp=cua-cli). /api/gateway/{name} requires a per-key token whose ` + "`" + `namespace` + "`" + ` claim equals \"pool-{name}\" (enforced by OPA). The deprecated /api/batch/{pool} and /api/label/{pool} routes are permanently retired — they return 410 Gone for every request regardless of token validity.",
+ "description": "Keycloak access token. For /api/keys and /api/{k8s,orch} the token is an interactive user JWT (azp=cyclops-cs-spa or azp=cua-cli). The deprecated /api/batch/{pool} and /api/label/{pool} routes are permanently retired — they return 410 Gone for every request regardless of token validity.",
"type": "apiKey",
"name": "Authorization",
"in": "header"
@@ -1612,7 +1580,7 @@ var SwaggerInfo = &swag.Spec{
BasePath: "/",
Schemes: []string{},
Title: "Cyclops CS Backend API",
- Description: "Backend sidecar for the cyclops-cs SPA — Keycloak-authenticated key management, service proxies (k8s / orch / svc), namespace management, and deprecated gateway / batch / label routes that now return 410 Gone. All pool operations use OSGymSandboxClaim CRs (Path B).",
+ Description: "Backend sidecar for the cyclops-cs SPA — Keycloak-authenticated key management, service proxies (k8s / orch / svc), namespace management, and deprecated batch / label routes that now return 410 Gone. All pool operations use OSGymSandboxClaim CRs (Path B).",
InfoInstanceName: "swagger",
SwaggerTemplate: docTemplate,
LeftDelim: "{{",
diff --git a/libs/fleet/backend/docs/swagger.json b/libs/fleet/backend/docs/swagger.json
index 2f1d342f27..e1474fb05f 100644
--- a/libs/fleet/backend/docs/swagger.json
+++ b/libs/fleet/backend/docs/swagger.json
@@ -1,7 +1,7 @@
{
"swagger": "2.0",
"info": {
- "description": "Backend sidecar for the cyclops-cs SPA — Keycloak-authenticated key management, service proxies (k8s / orch / svc), namespace management, and deprecated gateway / batch / label routes that now return 410 Gone. All pool operations use OSGymSandboxClaim CRs (Path B).",
+ "description": "Backend sidecar for the cyclops-cs SPA — Keycloak-authenticated key management, service proxies (k8s / orch / svc), namespace management, and deprecated batch / label routes that now return 410 Gone. All pool operations use OSGymSandboxClaim CRs (Path B).",
"title": "Cyclops CS Backend API",
"contact": {},
"version": "0.1"
@@ -522,38 +522,6 @@
}
}
},
- "/api/gateway/{name}/{path}": {
- "get": {
- "description": "The per-pool HTTP orchestrator has been deprecated and removed. All pools now use OSGymSandboxClaim CRs exclusively (Path B). This endpoint returns 410 Gone for any request. See CUA-609.",
- "tags": [
- "gateway"
- ],
- "summary": "DEPRECATED: Per-pool orchestrator reverse-proxy (CUA-609)",
- "parameters": [
- {
- "type": "string",
- "description": "Pool name (DNS-1123 label)",
- "name": "name",
- "in": "path",
- "required": true
- },
- {
- "type": "string",
- "description": "Upstream path (ignored)",
- "name": "path",
- "in": "path"
- }
- ],
- "responses": {
- "410": {
- "description": "Orchestrator HTTP layer deprecated (CUA-609)",
- "schema": {
- "$ref": "#/definitions/handlers.ErrorResponse"
- }
- }
- }
- }
- },
"/api/k8s/{path}": {
"get": {
"security": [
@@ -1590,7 +1558,7 @@
},
"securityDefinitions": {
"BearerAuth": {
- "description": "Keycloak access token. For /api/keys and /api/{k8s,orch} the token is an interactive user JWT (azp=cyclops-cs-spa or azp=cua-cli). /api/gateway/{name} requires a per-key token whose `namespace` claim equals \"pool-{name}\" (enforced by OPA). The deprecated /api/batch/{pool} and /api/label/{pool} routes are permanently retired — they return 410 Gone for every request regardless of token validity.",
+ "description": "Keycloak access token. For /api/keys and /api/{k8s,orch} the token is an interactive user JWT (azp=cyclops-cs-spa or azp=cua-cli). The deprecated /api/batch/{pool} and /api/label/{pool} routes are permanently retired — they return 410 Gone for every request regardless of token validity.",
"type": "apiKey",
"name": "Authorization",
"in": "header"
diff --git a/libs/fleet/backend/docs/swagger.yaml b/libs/fleet/backend/docs/swagger.yaml
index 9a96c798bd..57a1090ece 100644
--- a/libs/fleet/backend/docs/swagger.yaml
+++ b/libs/fleet/backend/docs/swagger.yaml
@@ -163,7 +163,7 @@ info:
contact: {}
description: Backend sidecar for the cyclops-cs SPA — Keycloak-authenticated key
management, service proxies (k8s / orch / svc), namespace management, and deprecated
- gateway / batch / label routes that now return 410 Gone. All pool operations use
+ batch / label routes that now return 410 Gone. All pool operations use
OSGymSandboxClaim CRs (Path B).
title: Cyclops CS Backend API
version: "0.1"
@@ -514,29 +514,6 @@ paths:
summary: Per-user feature flags
tags:
- config
- /api/gateway/{name}/{path}:
- get:
- description: The per-pool HTTP orchestrator has been deprecated and removed.
- All pools now use OSGymSandboxClaim CRs exclusively (Path B). This endpoint
- returns 410 Gone for any request. See CUA-609.
- parameters:
- - description: Pool name (DNS-1123 label)
- in: path
- name: name
- required: true
- type: string
- - description: Upstream path (ignored)
- in: path
- name: path
- type: string
- responses:
- "410":
- description: Orchestrator HTTP layer deprecated (CUA-609)
- schema:
- $ref: '#/definitions/handlers.ErrorResponse'
- summary: 'DEPRECATED: Per-pool orchestrator reverse-proxy (CUA-609)'
- tags:
- - gateway
/api/k8s/{path}:
get:
description: Forwards requests to http://127.0.0.1:8001 (the kubectl-proxy sidecar)
@@ -1070,9 +1047,8 @@ paths:
securityDefinitions:
BearerAuth:
description: Keycloak access token. For /api/keys and /api/{k8s,orch} the token
- is an interactive user JWT (azp=cyclops-cs-spa or azp=cua-cli). /api/gateway/{name}
- requires a per-key token whose `namespace` claim equals "pool-{name}" (enforced
- by OPA). The deprecated /api/batch/{pool} and /api/label/{pool} routes are permanently
+ is an interactive user JWT (azp=cyclops-cs-spa or azp=cua-cli). The deprecated
+ /api/batch/{pool} and /api/label/{pool} routes are permanently
retired — they return 410 Gone for every request regardless of token validity.
in: header
name: Authorization
diff --git a/libs/fleet/backend/handlers/gateway.go b/libs/fleet/backend/handlers/gateway.go
deleted file mode 100644
index b8b3456b11..0000000000
--- a/libs/fleet/backend/handlers/gateway.go
+++ /dev/null
@@ -1,23 +0,0 @@
-package handlers
-
-import (
- "net/http"
-)
-
-// Gateway godoc
-//
-// @Summary DEPRECATED: Per-pool orchestrator reverse-proxy (CUA-609)
-// @Description The per-pool HTTP orchestrator has been deprecated and removed. All pools now use OSGymSandboxClaim CRs exclusively (Path B). This endpoint returns 410 Gone for any request. See CUA-609.
-// @Tags gateway
-// @Param name path string true "Pool name (DNS-1123 label)"
-// @Param path path string false "Upstream path (ignored)"
-// @Success 410 {object} ErrorResponse "Orchestrator HTTP layer deprecated (CUA-609)"
-// @Router /api/gateway/{name}/{path} [get]
-func (h Handlers) Gateway(w http.ResponseWriter, r *http.Request) {
- // CUA-609: The per-pool orchestrator HTTP layer has been removed.
- // Per-pool orchestrators (Deployments in <pool>-orchestrator namespaces)
- // no longer run. All VM operations go through OSGymSandboxClaim CRs.
- // Zero HTTP traffic was confirmed before removal.
- writeErr(w, http.StatusGone,
- "orchestrator HTTP layer deprecated (CUA-609): use OSGymSandboxClaim CRs instead")
-}
diff --git a/libs/fleet/backend/main.go b/libs/fleet/backend/main.go
index 688c640510..a294397ef7 100644
--- a/libs/fleet/backend/main.go
+++ b/libs/fleet/backend/main.go
@@ -9,14 +9,6 @@
// /api/keys[/{id}] — SPA-authenticated CRUD on per-user
// service-account clients in Keycloak.
//
-// /api/gateway/{name}[/{p...}]— DEPRECATED (CUA-609). Returns 410 Gone.
-// The per-pool orchestrator HTTP layer has
-// been removed. All pool operations now use
-// OSGymSandboxClaim CRs (Path B) directly.
-// Zero HTTP traffic was confirmed before
-// removal. Route kept for OPA continuity
-// (per-key tokens still validated).
-//
// /api/batch/{pool}, /api/label/{pool}
// — DEPRECATED. Returns 410 Gone for every
// request. The orchestrator-backed batch
@@ -25,12 +17,12 @@
//
// @title Cyclops CS Backend API
// @version 0.1
-// @description Backend sidecar for the cyclops-cs SPA — Keycloak-authenticated key management, service proxies (k8s / orch / svc), namespace management, and deprecated gateway / batch / label routes that now return 410 Gone. All pool operations use OSGymSandboxClaim CRs (Path B).
+// @description Backend sidecar for the cyclops-cs SPA — Keycloak-authenticated key management, service proxies (k8s / orch / svc), namespace management, and deprecated batch / label routes that now return 410 Gone. All pool operations use OSGymSandboxClaim CRs (Path B).
// @BasePath /
// @securityDefinitions.apikey BearerAuth
// @in header
// @name Authorization
-// @description Keycloak access token. For /api/keys and /api/{k8s,orch} the token is an interactive user JWT (azp=cyclops-cs-spa or azp=cua-cli). /api/gateway/{name} requires a per-key token whose `namespace` claim equals "pool-{name}" (enforced by OPA). The deprecated /api/batch/{pool} and /api/label/{pool} routes are permanently retired — they return 410 Gone for every request regardless of token validity.
+// @description Keycloak access token. For /api/keys and /api/{k8s,orch} the token is an interactive user JWT (azp=cyclops-cs-spa or azp=cua-cli). The deprecated /api/batch/{pool} and /api/label/{pool} routes are permanently retired — they return 410 Gone for every request regardless of token validity.
package main
import (
@@ -156,11 +148,6 @@ func setupRouter(c handlers.Handlers) http.Handler {
r.Handle("DELETE /api/github-trust-policies/{id}",
withMiddlewares("/api/github-trust-policies/{id}", []string{"id"}, c.DeleteGitHubTrustPolicy))
- r.Handle("/api/gateway/{name}",
- withMiddlewares("/api/gateway/{name}", []string{"name"}, c.Gateway))
- r.Handle("/api/gateway/{name}/{path...}",
- withMiddlewares("/api/gateway/{name}/{path...}", []string{"name", "path"}, c.Gateway))
-
// Generic service proxy — reaches a K8s Service on port 80 in a
// namespace the caller is authorized for. OPA gates authn/shape;
// namespace ownership is enforced in the handler (per-key tokens via
diff --git a/libs/fleet/backend/main_test.go b/libs/fleet/backend/main_test.go
index fa63601d15..9e543dec4d 100644
--- a/libs/fleet/backend/main_test.go
+++ b/libs/fleet/backend/main_test.go
@@ -29,6 +29,30 @@ import (
"github.com/trycua/cloud/pkg/featureflags"
)
+func TestGatewayRoutesAreRemoved(t *testing.T) {
+ router := setupRouter(handlers.Handlers{})
+
+ for _, path := range []string{"/api/gateway/mypool", "/api/gateway/mypool/step"} {
+ t.Run(path, func(t *testing.T) {
+ response := httptest.NewRecorder()
+ router.ServeHTTP(response, httptest.NewRequest(http.MethodGet, path, nil))
+ if response.Code != http.StatusNotFound {
+ t.Fatalf("status = %d, want 404; body = %s", response.Code, response.Body.String())
+ }
+ })
+ }
+}
+
+func TestSwaggerOmitsGatewayRoute(t *testing.T) {
+ data, err := os.ReadFile("docs/swagger.json")
+ if err != nil {
+ t.Fatal(err)
+ }
+ if strings.Contains(string(data), `"/api/gateway/`) {
+ t.Fatal("swagger.json still exposes the removed gateway route")
+ }
+}
+
// TestDeprecatedRoutes asserts that every deprecated batch/label endpoint
// returns HTTP 410 Gone with the canonical deprecation message. Each route
// is exercised individually so a regression on any single path is immediately
diff --git a/libs/fleet/backend/metrics/metrics.go b/libs/fleet/backend/metrics/metrics.go
index c06f3f4ea1..f5abfcef82 100644
--- a/libs/fleet/backend/metrics/metrics.go
+++ b/libs/fleet/backend/metrics/metrics.go
@@ -57,10 +57,10 @@ var (
Buckets: []float64{0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5},
}, []string{"operation", "status"})
- // Upstream proxy SLIs (/api/gateway + /api/orch + /api/k8s)
+ // Upstream proxy SLIs (/api/svc + /api/orch + /api/k8s)
UpstreamProxyRequestsTotal = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "cyclops_cs_upstream_proxy_requests_total",
- Help: "Total requests proxied to upstream services (gateway/orch/k8s).",
+ Help: "Total requests proxied to upstream services (svc/orch/k8s).",
}, []string{"target", "status_code"})
BillingWebhookEventsTotal = promauto.NewCounterVec(prometheus.CounterOpts{