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
feat(auth): add run.cua.ai CLI device authorization (#5806)
r33drichards95c68886fedc
diff --git a/libs/fleet/backend/auth/auth.go b/libs/fleet/backend/auth/auth.goindex b477cb0ba7..39d0fb10e0 100644--- a/libs/fleet/backend/auth/auth.go+++ b/libs/fleet/backend/auth/auth.go@@ -10,8 +10,8 @@// enforces that the token's `namespace` claim equals "pool-{name}"// (CUA-527), preventing a compromised key from reaching any pool other// than its own.-// - Two flavors of token use: SPA (azp must equal the SPA client) and-// Gateway (azp must be a per-key client; namespace claim mandatory).+// - Three token families: exact interactive clients, per-key clients, and+// user-key clients; route policy enforces each family and required claims.package authimport (diff --git a/libs/fleet/backend/auth/authz.rego b/libs/fleet/backend/auth/authz.regoindex 42f61f46ce..4a870c9aff 100644--- a/libs/fleet/backend/auth/authz.rego+++ b/libs/fleet/backend/auth/authz.rego@@ -2,11 +2,10 @@## Surfaces, distinguished by `input.route`:#-# /api/keys, /api/k8s, /api/orch — SPA surfaces. Require a token-# issued to the cyclops-cs-spa client-# (azp == "cyclops-cs-spa") and a non-empty-# subject. Anyone signed into the cyclops-cs realm-# may use them.+# /api/keys, /api/k8s, /api/orch — interactive user surfaces. Require a+# non-empty subject and a token issued to one of the+# exact public interactive clients: cyclops-cs-spa or+# cua-cli. Other realm clients are not implicitly trusted.## /api/batch/{pool}, /api/label/{pool}# — DEPRECATED. The handler returns 410 Gone for@@ -45,60 +44,71 @@ is_admin {# ── Route allow rules ───────────────────────────────────────────────────────+# Exact interactive clients. Keep this allowlist closed: accepting any+# arbitrary public realm client would let unrelated clients call user APIs.+is_interactive_client {+ input.user.azp == "cyclops-cs-spa"+}++is_interactive_client {+ input.user.azp == "cua-cli"+}++# /api/keys (POST/GET) and /api/keys/{id} (DELETE).allow {input.route == "/api/keys"input.user.sub != ""- input.user.azp == "cyclops-cs-spa"+ is_interactive_client}allow {input.route == "/api/keys/{id}"input.user.sub != ""- input.user.azp == "cyclops-cs-spa"+ is_interactive_client}-# /api/config — per-user feature flags. SPA-only.+# /api/config — per-user feature flags for exact interactive clients.allow {input.route == "/api/config"input.user.sub != ""- input.user.azp == "cyclops-cs-spa"+ is_interactive_client}# /api/namespaces — namespace management (list, create, delete).-# SPA-only; any authenticated user may manage their own namespaces.+# Exact interactive clients may manage their own namespaces.# Capsule enforces per-user scoping at the K8s API level via# impersonation headers added by the backend.allow {input.route == "/api/namespaces"input.user.sub != ""- input.user.azp == "cyclops-cs-spa"+ is_interactive_client}allow {input.route == "/api/namespaces/{name}"input.user.sub != ""- input.user.azp == "cyclops-cs-spa"+ is_interactive_client}# /api/pool-templates — per-user saved pool configs (list, create, get,-# delete). SPA-only; the backend scopes every operation to the caller's+# delete). Exact interactive clients only; the backend scopes operations to the caller's# sub, so a user can only ever read or mutate their own templates.allow {input.route == "/api/pool-templates"input.user.sub != ""- input.user.azp == "cyclops-cs-spa"+ is_interactive_client}allow {input.route == "/api/pool-templates/{name}"input.user.sub != ""- input.user.azp == "cyclops-cs-spa"+ is_interactive_client}# /api/k8s/{path...} — kubectl-proxy passthrough.#-# Any SPA user may read customer-facing resources (their pools, the pods+# Any exact interactive client may read customer-facing resources (their pools, the pods# backing their VMs, pod logs, metrics, and the K8s event feed — the event# *contents* are still redacted for non-admins by filters.rego's# visible_events). Infra-only resources (cluster nodes, cluster-wide pod@@ -107,14 +117,14 @@ allow {allow {input.route == "/api/k8s/{path...}"input.user.sub != ""- input.user.azp == "cyclops-cs-spa"+ is_interactive_clientnot is_infra_k8s_path(input.params.path)}allow {input.route == "/api/k8s/{path...}"input.user.sub != ""- input.user.azp == "cyclops-cs-spa"+ is_interactive_clientis_admin}@@ -158,13 +168,13 @@ is_infra_k8s_path(path) {}# /api/orch/{namespace}/{service}/{path...} — per-namespace orchestrator-# catalog read. SPA-only; namespace + service must be DNS-1123 labels.+# catalog read. Exact interactive clients only; namespace + service must be DNS-1123 labels.# Like /api/svc, this proxy dials Service DNS directly, so namespace# ownership is enforced in Go (handlers.requireNamespaceAccess).allow {input.route == "/api/orch/{namespace}/{service}/{path...}"input.user.sub != ""- input.user.azp == "cyclops-cs-spa"+ is_interactive_clientvalid_dns_label(input.params.namespace)valid_dns_label(input.params.service)}@@ -179,7 +189,7 @@ allow {allow {is_batch_routeinput.user.sub != ""- input.user.azp == "cyclops-cs-spa"+ is_interactive_clientvalid_dns_label(input.params.pool)}allow {@@ -267,13 +277,13 @@ is_per_key_client { startswith(input.user.azp, "key-") }allow {input.route == "/api/user-keys"input.user.sub != ""- input.user.azp == "cyclops-cs-spa"+ is_interactive_client}allow {input.route == "/api/user-keys/{id}"input.user.sub != ""- input.user.azp == "cyclops-cs-spa"+ is_interactive_client}# ── User API key access to SPA surfaces ────────────────────────────────diff --git a/libs/fleet/backend/auth/authz_test.rego b/libs/fleet/backend/auth/authz_test.regoindex fa752d9421..0389c7800f 100644--- a/libs/fleet/backend/auth/authz_test.rego+++ b/libs/fleet/backend/auth/authz_test.rego@@ -16,6 +16,26 @@ test_keys_spa_allowed if {}}+test_keys_cua_cli_allowed if {+ authz.allow with input as {+ "route": "/api/keys",+ "method": "POST",+ "path": "/api/keys",+ "params": {},+ "user": {"sub": "user-123", "azp": "cua-cli", "namespace": "", "email": "[email protected]"},+ }+}++test_keys_other_interactive_client_denied if {+ not authz.allow with input as {+ "route": "/api/keys",+ "method": "POST",+ "path": "/api/keys",+ "params": {},+ "user": {"sub": "user-123", "azp": "kubernetes", "namespace": "", "email": "[email protected]"},+ }+}+test_keys_non_spa_denied if {not authz.allow with input as {"route": "/api/keys",@@ -119,6 +139,16 @@ test_k8s_spa_allowed if {}}+test_k8s_cua_cli_allowed if {+ authz.allow with input as {+ "route": "/api/k8s/{path...}",+ "method": "GET",+ "path": "/api/k8s/api/v1/namespaces",+ "params": {"path": "api/v1/namespaces"},+ "user": {"sub": "user-123", "azp": "cua-cli", "namespace": "", "email": "[email protected]"},+ }+}+# ── /api/orch ─────────────────────────────────────────────────────────────────test_orch_spa_allowed if {@@ -131,6 +161,16 @@ test_orch_spa_allowed if {}}+test_orch_cua_cli_allowed if {+ authz.allow with input as {+ "route": "/api/orch/{namespace}/{service}/{path...}",+ "method": "GET",+ "path": "/api/orch/mypool/mypool-orchestrator/status",+ "params": {"namespace": "mypool", "service": "mypool-orchestrator", "path": "status"},+ "user": {"sub": "user-123", "azp": "cua-cli", "namespace": "", "email": "[email protected]"},+ }+}+# ── /api/batch and /api/label ────────────────────────────────────────────────## Pool is in the URL path. A per-key token's `namespace` claim MUST equaldiff --git a/libs/fleet/backend/main.go b/libs/fleet/backend/main.goindex 85daeb7c17..67c59c4491 100644--- a/libs/fleet/backend/main.go+++ b/libs/fleet/backend/main.go@@ -30,7 +30,7 @@// @securityDefinitions.apikey BearerAuth// @in header// @name Authorization-// @description Keycloak access token. For /api/keys and /api/{k8s,orch} the token is the SPA's user JWT (azp=cyclops-cs-spa). /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). /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.package mainimport (diff --git a/libs/fleet/e2e/device.spec.ts b/libs/fleet/e2e/device.spec.tsnew file mode 100644index 0000000000..2adcd94457--- /dev/null+++ b/libs/fleet/e2e/device.spec.ts@@ -0,0 +1,38 @@+import { expect, test } from "@playwright/test"++test.describe("CLI device authorization", () => {+ test("continues sign-in and signup from a normalized user code", async ({ page }) => {+ await page.goto("/device?user_code=abcd-efgh")++ await expect(+ page.getByRole("heading", { name: "Connect your Cua CLI" }),+ ).toBeVisible()+ await expect(page.getByText("ABCD-EFGH", { exact: true })).toBeVisible()++ const signIn = page.getByRole("link", { name: "Sign in and continue" })+ await expect(signIn).toHaveAttribute(+ "href",+ "https://auth.cua.ai/realms/cyclops-cs/device?user_code=ABCD-EFGH",+ )++ const signUp = page.getByRole("link", { name: "Create an account" })+ const signUpHref = await signUp.getAttribute("href")+ expect(signUpHref).toBe(+ "https://cua.ai/signup?redirect_url=%2Fdevice%3Fuser_code%3DABCD-EFGH",+ )+ })++ test("rejects missing or malformed user codes", async ({ page }) => {+ await page.goto("/device?user_code=not-a-code")++ await expect(page.getByRole("alert")).toContainText(+ "Enter the code shown by the CLI",+ )+ await expect(+ page.getByRole("link", { name: "Sign in and continue" }),+ ).toHaveCount(0)+ await expect(+ page.getByRole("link", { name: "Create an account" }),+ ).toHaveCount(0)+ })+})diff --git a/libs/fleet/src/main.tsx b/libs/fleet/src/main.tsxindex 434ab27c98..07f9c6e074 100644--- a/libs/fleet/src/main.tsx+++ b/libs/fleet/src/main.tsx@@ -4,13 +4,20 @@ import "@cloudscape-design/global-styles/index.css"import { applyMode, Mode } from "@cloudscape-design/global-styles"import { App } from "./App"import { AuthProvider } from "./auth/AuthProvider"+import { DeviceAuthorization } from "./pages/DeviceAuthorization"applyMode(Mode.Dark)+const isDeviceAuthorization = window.location.pathname === "/device"+ReactDOM.createRoot(document.getElementById("root")!).render(<React.StrictMode>- <AuthProvider>- <App />- </AuthProvider>+ {isDeviceAuthorization ? (+ <DeviceAuthorization />+ ) : (+ <AuthProvider>+ <App />+ </AuthProvider>+ )}</React.StrictMode>,)diff --git a/libs/fleet/src/pages/DeviceAuthorization.css b/libs/fleet/src/pages/DeviceAuthorization.cssnew file mode 100644index 0000000000..fd848bea6a--- /dev/null+++ b/libs/fleet/src/pages/DeviceAuthorization.css@@ -0,0 +1,210 @@+.device-page {+ --device-ink: #15231d;+ --device-muted: #66736d;+ --device-cream: #f4f0e6;+ --device-paper: rgba(255, 253, 247, 0.92);+ --device-green: #167653;+ --device-green-dark: #0c573c;+ min-height: 100vh;+ display: grid;+ place-items: center;+ overflow: hidden;+ position: relative;+ padding: 32px 20px;+ color: var(--device-ink);+ background:+ radial-gradient(circle at 15% 15%, rgba(211, 228, 190, 0.9), transparent 34%),+ radial-gradient(circle at 86% 82%, rgba(245, 194, 139, 0.72), transparent 30%),+ linear-gradient(135deg, #e7eee3 0%, var(--device-cream) 52%, #f1e3d2 100%);+ font-family: Georgia, "Times New Roman", serif;+}++.device-page::before {+ content: "";+ position: absolute;+ inset: 0;+ opacity: 0.28;+ background-image: linear-gradient(rgba(21, 35, 29, 0.08) 1px, transparent 1px),+ linear-gradient(90deg, rgba(21, 35, 29, 0.08) 1px, transparent 1px);+ background-size: 32px 32px;+ mask-image: linear-gradient(to bottom, black, transparent 88%);+}++.device-orbit {+ position: absolute;+ border: 1px solid rgba(22, 118, 83, 0.22);+ border-radius: 50%;+ pointer-events: none;+}++.device-orbit-one {+ width: 440px;+ height: 440px;+ top: -220px;+ right: -100px;+}++.device-orbit-two {+ width: 300px;+ height: 300px;+ bottom: -150px;+ left: -80px;+}++.device-card {+ width: min(100%, 620px);+ position: relative;+ z-index: 1;+ padding: clamp(32px, 6vw, 64px);+ border: 1px solid rgba(21, 35, 29, 0.14);+ border-radius: 28px 28px 88px 28px;+ background: var(--device-paper);+ box-shadow: 0 32px 90px rgba(46, 62, 51, 0.18);+ backdrop-filter: blur(14px);+ animation: device-rise 480ms ease-out both;+}++.device-wordmark {+ font: 800 29px/1.1 ui-rounded, "Arial Rounded MT Bold", sans-serif;+ letter-spacing: -0.08em;+ color: var(--device-green);+ margin-bottom: 42px;+}++.device-eyebrow {+ margin: 0 0 12px;+ color: var(--device-green);+ font: 700 12px/1.2 ui-monospace, "SFMono-Regular", Consolas, monospace;+ letter-spacing: 0.14em;+ text-transform: uppercase;+}++.device-card h1 {+ margin: 0;+ max-width: 470px;+ font-size: clamp(38px, 8vw, 64px);+ line-height: 0.96;+ letter-spacing: -0.045em;+ font-weight: 500;+}++.device-lede {+ max-width: 500px;+ margin: 24px 0 30px;+ color: var(--device-muted);+ font: 400 17px/1.65 ui-sans-serif, "Avenir Next", "Segoe UI", sans-serif;+}++.device-code {+ display: inline-block;+ padding: 16px 20px;+ border: 1px solid rgba(21, 35, 29, 0.16);+ border-radius: 12px;+ color: var(--device-ink);+ background: rgba(236, 241, 231, 0.78);+ font: 750 clamp(25px, 7vw, 34px)/1 ui-monospace, "SFMono-Regular", Consolas, monospace;+ letter-spacing: 0.16em;+ box-shadow: inset 0 -3px 0 rgba(22, 118, 83, 0.12);+}++.device-actions {+ display: grid;+ grid-template-columns: 1fr 1fr;+ gap: 12px;+ margin-top: 28px;+}++.device-button {+ display: inline-flex;+ min-height: 50px;+ align-items: center;+ justify-content: center;+ padding: 0 18px;+ border-radius: 999px;+ text-decoration: none;+ font: 700 14px/1 ui-sans-serif, "Avenir Next", "Segoe UI", sans-serif;+ transition: transform 160ms ease, box-shadow 160ms ease, background 160ms ease;+}++.device-button:hover {+ transform: translateY(-2px);+}++.device-button:focus-visible {+ outline: 3px solid rgba(22, 118, 83, 0.3);+ outline-offset: 3px;+}++.device-button-primary {+ color: white;+ background: var(--device-green);+ box-shadow: 0 12px 30px rgba(22, 118, 83, 0.24);+}++.device-button-primary:hover {+ background: var(--device-green-dark);+}++.device-button-secondary {+ color: var(--device-ink);+ border: 1px solid rgba(21, 35, 29, 0.2);+ background: rgba(255, 255, 255, 0.55);+}++.device-footnote {+ margin: 20px 0 0;+ color: var(--device-muted);+ font: 400 13px/1.5 ui-sans-serif, "Avenir Next", "Segoe UI", sans-serif;+}++.device-alert {+ display: grid;+ gap: 8px;+ padding: 18px 20px;+ border-left: 4px solid #b75b35;+ border-radius: 8px;+ color: #522d20;+ background: rgba(252, 230, 214, 0.8);+ font: 400 15px/1.5 ui-sans-serif, "Avenir Next", "Segoe UI", sans-serif;+}++@keyframes device-rise {+ from {+ opacity: 0;+ transform: translateY(18px) scale(0.985);+ }+ to {+ opacity: 1;+ transform: translateY(0) scale(1);+ }+}++@media (max-width: 600px) {+ .device-page {+ align-items: start;+ padding: 18px 12px;+ }++ .device-card {+ padding: 30px 24px 38px;+ border-radius: 22px 22px 58px 22px;+ }++ .device-wordmark {+ margin-bottom: 34px;+ }++ .device-actions {+ grid-template-columns: 1fr;+ }+}++@media (prefers-reduced-motion: reduce) {+ .device-card {+ animation: none;+ }++ .device-button {+ transition: none;+ }+}diff --git a/libs/fleet/src/pages/DeviceAuthorization.tsx b/libs/fleet/src/pages/DeviceAuthorization.tsxnew file mode 100644index 0000000000..3f68d6e02d--- /dev/null+++ b/libs/fleet/src/pages/DeviceAuthorization.tsx@@ -0,0 +1,86 @@+import "./DeviceAuthorization.css"++const USER_CODE_PATTERN = /^[A-Z0-9]{4}-[A-Z0-9]{4}$/++function normalizeUserCode(value: string | null): string | null {+ if (!value) return null+ const normalized = value.trim().toUpperCase()+ return USER_CODE_PATTERN.test(normalized) ? normalized : null+}++function keycloakBaseUrl(): string {+ return window.__CYCLOPS_CS_CFG__?.kcUrl ?? "https://auth.cua.ai"+}++function keycloakRealm(): string {+ return window.__CYCLOPS_CS_CFG__?.kcRealm ?? "cyclops-cs"+}++function deviceVerificationUrl(userCode: string): string {+ const base = keycloakBaseUrl().replace(/\/$/, "")+ const realm = encodeURIComponent(keycloakRealm())+ return `${base}/realms/${realm}/device?user_code=${encodeURIComponent(userCode)}`+}++function signupUrl(userCode: string): string {+ const continuation = `/device?user_code=${encodeURIComponent(userCode)}`+ return `https://cua.ai/signup?redirect_url=${encodeURIComponent(continuation)}`+}++export function DeviceAuthorization() {+ const userCode = normalizeUserCode(+ new URLSearchParams(window.location.search).get("user_code"),+ )++ return (+ <main className="device-page">+ <div className="device-orbit device-orbit-one" />+ <div className="device-orbit device-orbit-two" />+ <section className="device-card" aria-labelledby="device-title">+ <div className="device-wordmark">+ cua+ </div>+ <p className="device-eyebrow">Secure device authorization</p>+ <h1 id="device-title">Connect your Cua CLI</h1>+ <p className="device-lede">+ Confirm the code from your terminal, then sign in to authorize this+ device. Your CLI never receives your password.+ </p>++ {userCode ? (+ <>+ <div className="device-code">+ {userCode}+ </div>+ <div className="device-actions">+ <a+ className="device-button device-button-primary"+ href={deviceVerificationUrl(userCode)}+ >+ Sign in and continue+ </a>+ <a+ className="device-button device-button-secondary"+ href={signupUrl(userCode)}+ >+ Create an account+ </a>+ </div>+ <p className="device-footnote">+ Only continue if this code exactly matches the one shown by the+ CLI. Codes expire automatically.+ </p>+ </>+ ) : (+ <div className="device-alert" role="alert">+ <strong>Enter the code shown by the CLI.</strong>+ <span>+ Open the complete verification link printed in your terminal,+ including its eight-character code.+ </span>+ </div>+ )}+ </section>+ </main>+ )+}