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(cyclops): allow WIF sandbox lifecycle paths (#6700)

r33drichards2898473d9a74
diff --git a/libs/fleet/backend/handlers/k8s.go b/libs/fleet/backend/handlers/k8s.go
index 1d6904d189..dda4117581 100644
--- a/libs/fleet/backend/handlers/k8s.go
+++ b/libs/fleet/backend/handlers/k8s.go
@@ -225,26 +225,40 @@ func bodyRequestsMacOS(body []byte) bool {
func githubAllowedK8sPath(method, path string) (string, bool) {
parts := strings.Split(path, "/")
- if len(parts) >= 6 &&
- parts[0] == "apis" &&
- parts[1] == "cua.ai" &&
- parts[2] == "v1" &&
- parts[3] == "namespaces" &&
- parts[5] == "osgymworkspacepools" {
+ if len(parts) != 6 && len(parts) != 7 {
+ return "", false
+ }
+ if len(parts) == 7 && parts[6] == "" {
+ return "", false
+ }
+ if parts[0] != "apis" || parts[3] != "namespaces" {
+ return "", false
+ }
+
+ if parts[1] == "cua.ai" && parts[2] == "v1" && parts[5] == "osgymworkspacepools" {
switch method {
case http.MethodGet, http.MethodPost, http.MethodPatch, http.MethodDelete:
- if len(parts) == 6 || len(parts) == 7 {
- return parts[4], true
- }
+ return parts[4], true
}
}
- if len(parts) >= 6 &&
- parts[0] == "apis" &&
- parts[1] == "osgym.cua.ai" &&
- parts[2] == "v1alpha1" &&
- parts[3] == "namespaces" &&
- parts[5] == "osgymsandboxclaims" {
- if method == http.MethodGet && (len(parts) == 6 || len(parts) == 7) {
+ if parts[1] != "osgym.cua.ai" || parts[2] != "v1alpha1" {
+ return "", false
+ }
+
+ resource := parts[5]
+ isItem := len(parts) == 7
+ switch resource {
+ case "osgymsandboxwarmpools", "osgymsandboxclaims":
+ switch method {
+ case http.MethodGet:
+ return parts[4], true
+ case http.MethodPost:
+ return parts[4], !isItem
+ case http.MethodPatch, http.MethodDelete:
+ return parts[4], isItem
+ }
+ case "osgymsandboxtemplates":
+ if method == http.MethodGet {
return parts[4], true
}
}
diff --git a/libs/fleet/backend/handlers/k8s_test.go b/libs/fleet/backend/handlers/k8s_test.go
index 7d3d5279a6..6fd58f63c1 100644
--- a/libs/fleet/backend/handlers/k8s_test.go
+++ b/libs/fleet/backend/handlers/k8s_test.go
@@ -327,3 +327,44 @@ func TestK8sProxy_GitHubPrincipalRejectsClusterWidePath(t *testing.T) {
t.Fatalf("status = %d, want 403; body = %s", w.Code, w.Body.String())
}
}
+
+func TestGitHubAllowedK8sPath_SandboxLifecycle(t *testing.T) {
+ const namespace = "cua-cli-wif-smoke"
+ cases := []struct {
+ name string
+ method string
+ path string
+ want bool
+ }{
+ {"get warm pool", http.MethodGet, "apis/osgym.cua.ai/v1alpha1/namespaces/cua-cli-wif-smoke/osgymsandboxwarmpools/cua-cli-wif-smoke", true},
+ {"patch warm pool", http.MethodPatch, "apis/osgym.cua.ai/v1alpha1/namespaces/cua-cli-wif-smoke/osgymsandboxwarmpools/cua-cli-wif-smoke", true},
+ {"post warm pool item", http.MethodPost, "apis/osgym.cua.ai/v1alpha1/namespaces/cua-cli-wif-smoke/osgymsandboxwarmpools/cua-cli-wif-smoke", false},
+ {"patch warm pool collection", http.MethodPatch, "apis/osgym.cua.ai/v1alpha1/namespaces/cua-cli-wif-smoke/osgymsandboxwarmpools", false},
+ {"delete warm pool collection", http.MethodDelete, "apis/osgym.cua.ai/v1alpha1/namespaces/cua-cli-wif-smoke/osgymsandboxwarmpools", false},
+ {"patch trailing slash warm pool collection", http.MethodPatch, "apis/osgym.cua.ai/v1alpha1/namespaces/cua-cli-wif-smoke/osgymsandboxwarmpools/", false},
+ {"create claim", http.MethodPost, "apis/osgym.cua.ai/v1alpha1/namespaces/cua-cli-wif-smoke/osgymsandboxclaims", true},
+ {"post claim item", http.MethodPost, "apis/osgym.cua.ai/v1alpha1/namespaces/cua-cli-wif-smoke/osgymsandboxclaims/wif-smoke-123", false},
+ {"patch claim collection", http.MethodPatch, "apis/osgym.cua.ai/v1alpha1/namespaces/cua-cli-wif-smoke/osgymsandboxclaims", false},
+ {"delete claim collection", http.MethodDelete, "apis/osgym.cua.ai/v1alpha1/namespaces/cua-cli-wif-smoke/osgymsandboxclaims", false},
+ {"delete trailing slash claim collection", http.MethodDelete, "apis/osgym.cua.ai/v1alpha1/namespaces/cua-cli-wif-smoke/osgymsandboxclaims/", false},
+ {"get claim", http.MethodGet, "apis/osgym.cua.ai/v1alpha1/namespaces/cua-cli-wif-smoke/osgymsandboxclaims/wif-smoke-123", true},
+ {"renew claim", http.MethodPatch, "apis/osgym.cua.ai/v1alpha1/namespaces/cua-cli-wif-smoke/osgymsandboxclaims/wif-smoke-123", true},
+ {"delete claim", http.MethodDelete, "apis/osgym.cua.ai/v1alpha1/namespaces/cua-cli-wif-smoke/osgymsandboxclaims/wif-smoke-123", true},
+ {"get template", http.MethodGet, "apis/osgym.cua.ai/v1alpha1/namespaces/cua-cli-wif-smoke/osgymsandboxtemplates/cua-cli-wif-smoke-template", true},
+ {"write template", http.MethodPatch, "apis/osgym.cua.ai/v1alpha1/namespaces/cua-cli-wif-smoke/osgymsandboxtemplates/cua-cli-wif-smoke-template", false},
+ {"nested claim path", http.MethodGet, "apis/osgym.cua.ai/v1alpha1/namespaces/cua-cli-wif-smoke/osgymsandboxclaims/wif-smoke-123/status", false},
+ {"cluster-wide warm pools", http.MethodGet, "apis/osgym.cua.ai/v1alpha1/osgymsandboxwarmpools", false},
+ }
+
+ for _, tc := range cases {
+ t.Run(tc.name, func(t *testing.T) {
+ gotNamespace, got := githubAllowedK8sPath(tc.method, tc.path)
+ if got != tc.want {
+ t.Fatalf("githubAllowedK8sPath(%q, %q) allowed = %v, want %v", tc.method, tc.path, got, tc.want)
+ }
+ if tc.want && gotNamespace != namespace {
+ t.Fatalf("githubAllowedK8sPath(%q, %q) namespace = %q, want %q", tc.method, tc.path, gotNamespace, namespace)
+ }
+ })
+ }
+}