From a065360a31380e64071cf99e7ddecb88e94cfe9c Mon Sep 17 00:00:00 2001
From: Neil
Date: Thu, 12 Nov 2026 22:56:54 -0800
Subject: [PATCH] feat(cloud): effective secrets view answers for shared
workspaces (no personal values), with a note
---
cloud/apps/sandbox-control/src/secrets.ts | 24 ++++-
.../test/effective-shared.test.ts | 57 +++++++++++
.../cloud-secrets-client.test.ts | 8 +-
.../cloud-secrets/cloud-secrets-client.ts | 26 +++--
src/main/cloud-secrets/cloud-secrets-ipc.ts | 8 +-
src/preload/api/cloud-secrets-bridge.ts | 7 +-
.../CloudSecretsPane.fixture.tsx | 31 ++++++
.../cloud-secrets/CloudSecretsPane.tsx | 98 +++++++++++++++++--
.../cloud-secrets-fixture-data.ts | 22 ++++-
.../cloud-secrets/use-cloud-secrets.ts | 18 +++-
src/renderer/src/i18n/locales/en.json | 7 +-
.../cloud-secrets/cloud-secrets-wire.ts | 6 ++
12 files changed, 285 insertions(+), 27 deletions(-)
create mode 100644 cloud/apps/sandbox-control/test/effective-shared.test.ts
diff --git a/cloud/apps/sandbox-control/src/secrets.ts b/cloud/apps/sandbox-control/src/secrets.ts
index 1f7713324ad..3e855b1b2d7 100644
--- a/cloud/apps/sandbox-control/src/secrets.ts
+++ b/cloud/apps/sandbox-control/src/secrets.ts
@@ -411,9 +411,17 @@ export const PRECEDENCE: Record = {
agent_key: ['org', 'repo', 'personal']
}
-/** What a session of this caller (in `repo`) would receive, by name and winning scope; no values. */
-export async function effectiveSecrets(db: D1Database, caller: SandboxCaller, repoParam: string | null): Promise {
- const pairs: [SecretScope, string][] = [['personal', personalOwner(caller.userId, caller.dev === true)]]
+/**
+ * What a session of this caller (in `repo`) would receive, by name and winning scope; no values.
+ * `shared`: a workspace shared with teammates, which gets no personal secrets (SEC-5, ownersForSandbox).
+ */
+export async function effectiveSecrets(
+ db: D1Database,
+ caller: SandboxCaller,
+ repoParam: string | null,
+ options: { shared?: boolean } = {}
+): Promise {
+ const pairs: [SecretScope, string][] = options.shared ? [] : [['personal', personalOwner(caller.userId, caller.dev === true)]]
if (caller.orgId) {
pairs.push(['org', caller.accountId])
}
@@ -421,6 +429,9 @@ export async function effectiveSecrets(db: D1Database, caller: SandboxCaller, re
if (repo) {
pairs.push(['repo', repoOwner(caller.accountId, repo)])
}
+ if (pairs.length === 0) {
+ return []
+ }
const where = pairs.map(() => '(scope = ? AND owner_id = ?)').join(' OR ')
const { results } = await db
.prepare(`SELECT scope, owner_id, name, hint, updated_at, updated_by FROM secrets WHERE ${where}`)
@@ -498,8 +509,13 @@ export async function handleSecretsRoute(
if (request.method !== 'GET') {
return json({ error: 'not_found' }, 404)
}
+ const workspace = url.searchParams.get('workspace') ?? 'private'
+ if (workspace !== 'private' && workspace !== 'shared') {
+ return json({ error: 'invalid_request', reason: 'invalid_workspace' }, 400)
+ }
const admin = isOrgAdmin(caller)
return json({
+ workspace,
caller: {
userId: caller.userId,
orgId: caller.orgId ?? null,
@@ -507,7 +523,7 @@ export async function handleSecretsRoute(
canWrite: { personal: true, org: Boolean(caller.orgId) && admin, repo: !caller.orgId || admin }
},
precedence: PRECEDENCE,
- secrets: await effectiveSecrets(db, caller, repoQuery)
+ secrets: await effectiveSecrets(db, caller, repoQuery, { shared: workspace === 'shared' })
})
}
if (url.pathname === '/v1/secrets/activity') {
diff --git a/cloud/apps/sandbox-control/test/effective-shared.test.ts b/cloud/apps/sandbox-control/test/effective-shared.test.ts
new file mode 100644
index 00000000000..cb3659b1ad9
--- /dev/null
+++ b/cloud/apps/sandbox-control/test/effective-shared.test.ts
@@ -0,0 +1,57 @@
+// SECRETS-EFFECTIVE-SHARED: the effective view can answer for a workspace shared with the team, which
+// gets no personal secrets (SEC-5), so Settings never shows a personal value winning there.
+import { describe, expect, it } from 'vitest'
+import { createHarness } from './harness'
+
+const KEK = Buffer.alloc(32, 7).toString('base64')
+
+async function setup() {
+ const h = await createHarness({ SECRETS_KEK: KEK })
+ const admin = await h.token('ada', 'acme', 'sandbox', { org_role: 'admin' })
+ const mia = await h.token('mia', 'acme', 'sandbox', { org_role: 'member' })
+ const put = (scope: string, name: string, value: string, bearer: string, repo?: string) =>
+ h.call('PUT', `/v1/secrets/${scope}/${name}${repo ? `?repo=${encodeURIComponent(repo)}` : ''}`, { body: { value }, bearer })
+ await put('org', 'FOO', 'org-foo-value', admin)
+ await put('personal', 'FOO', 'personal-foo-value', mia)
+ await put('personal', 'ONLY_MINE', 'mine', mia)
+ await put('org', 'ANTHROPIC_API_KEY', 'sk-ant-api03-fake-org-0000-aaaa', admin)
+ await put('personal', 'ANTHROPIC_API_KEY', 'sk-ant-api03-fake-mine-1111-bbbb', mia)
+ await put('repo', 'BAR', 'repo-bar-value', admin, 'acme/app')
+ const effective = async (query: string) => (await h.call('GET', `/v1/secrets/effective?${query}`, { bearer: mia })).body
+ return { h, mia, effective }
+}
+
+const summary = (secrets: { name: string; scope: string; shadowed: { scope: string }[] }[]) =>
+ secrets.map((s) => [s.name, s.scope, s.shadowed.map((x) => x.scope)])
+
+describe('effective view for a shared workspace', () => {
+ it('drops personal values: no personal winner, nothing personal shadowed, personal-only names gone', async () => {
+ const { effective } = await setup()
+ const shared = await effective('repo=acme/app&workspace=shared')
+ expect(shared.workspace).toBe('shared')
+ expect(summary(shared.secrets)).toEqual([
+ ['ANTHROPIC_API_KEY', 'org', []],
+ ['BAR', 'repo', []],
+ ['FOO', 'org', []]
+ ])
+ // The default (not shared) still shows the personal value winning for env.
+ const own = await effective('repo=acme/app')
+ expect(own.workspace).toBe('private')
+ expect(summary(own.secrets)).toEqual([
+ ['ANTHROPIC_API_KEY', 'org', ['personal']],
+ ['BAR', 'repo', []],
+ ['FOO', 'personal', ['org']],
+ ['ONLY_MINE', 'personal', []]
+ ])
+ })
+
+ it('a personal account’s shared view with no repo is empty, and an unknown mode is refused', async () => {
+ const { h } = await setup()
+ const solo = await h.token('carol')
+ await h.call('PUT', '/v1/secrets/personal/MY_VAR', { body: { value: 'x' }, bearer: solo })
+ expect((await h.call('GET', '/v1/secrets/effective?workspace=shared', { bearer: solo })).body.secrets).toEqual([])
+ const bad = await h.call('GET', '/v1/secrets/effective?workspace=public', { bearer: solo })
+ expect(bad.status).toBe(400)
+ expect(bad.body).toMatchObject({ reason: 'invalid_workspace' })
+ })
+})
diff --git a/src/main/cloud-secrets/cloud-secrets-client.test.ts b/src/main/cloud-secrets/cloud-secrets-client.test.ts
index 03410c45d03..4d933356273 100644
--- a/src/main/cloud-secrets/cloud-secrets-client.test.ts
+++ b/src/main/cloud-secrets/cloud-secrets-client.test.ts
@@ -152,9 +152,15 @@ describe('createCloudSecretsClient', () => {
)
expect(await client.effective('acme/app')).toEqual(effective)
expect(await client.refreshEnv('sbx_1')).toBe(true)
+ await client.effective('acme/app', undefined, 'shared')
+ await client.effective(undefined, undefined, 'shared')
+ await client.effective()
expect(seen.map((request) => `${request.method} ${request.url}`)).toEqual([
'GET https://control.test/v1/secrets/effective?repo=acme%2Fapp',
- 'POST https://control.test/v1/sandboxes/sbx_1/env/refresh'
+ 'POST https://control.test/v1/sandboxes/sbx_1/env/refresh',
+ 'GET https://control.test/v1/secrets/effective?repo=acme%2Fapp&workspace=shared',
+ 'GET https://control.test/v1/secrets/effective?workspace=shared',
+ 'GET https://control.test/v1/secrets/effective'
])
})
})
diff --git a/src/main/cloud-secrets/cloud-secrets-client.ts b/src/main/cloud-secrets/cloud-secrets-client.ts
index d797bc8585c..dcbdd63f9e1 100644
--- a/src/main/cloud-secrets/cloud-secrets-client.ts
+++ b/src/main/cloud-secrets/cloud-secrets-client.ts
@@ -13,6 +13,7 @@ import {
type CloudSecretsErrorCode,
type CloudSecretTarget,
type CloudSecretView,
+ type CloudSecretWorkspaceMode,
type CloudSecretsEffective,
type CloudWorkspaceSharing
} from '../../shared/cloud-secrets/cloud-secrets-wire'
@@ -30,7 +31,11 @@ export type CloudSecretsClient = {
target: CloudSecretTarget,
change: { set?: Record; delete?: string[] }
): Promise
- effective(repo?: string, signal?: AbortSignal): Promise
+ effective(
+ repo?: string,
+ signal?: AbortSignal,
+ workspace?: CloudSecretWorkspaceMode
+ ): Promise
refreshEnv(sandboxId: string): Promise
/** Who owns a sandbox and whether teammates share it (GET /v1/agent-sources?workspaceId=). */
workspaceSharing(sandboxId: string): Promise
@@ -85,11 +90,20 @@ export function createCloudSecretsClient(
body: change,
kind: 'control'
}),
- effective: (repo, signal) =>
- call('GET', withRepo('v1/secrets/effective', repo), CloudSecretsEffectiveResponseSchema, {
- kind: 'control',
- signal
- }),
+ effective: (repo, signal, workspace) =>
+ call(
+ 'GET',
+ `v1/secrets/effective${
+ repo || workspace === 'shared'
+ ? `?${new URLSearchParams({
+ ...(repo ? { repo } : {}),
+ ...(workspace === 'shared' ? { workspace } : {})
+ })}`
+ : ''
+ }`,
+ CloudSecretsEffectiveResponseSchema,
+ { kind: 'control', signal }
+ ),
refreshEnv: async (sandboxId) =>
(
await call(
diff --git a/src/main/cloud-secrets/cloud-secrets-ipc.ts b/src/main/cloud-secrets/cloud-secrets-ipc.ts
index 5c936e5d704..6a2d61e8288 100644
--- a/src/main/cloud-secrets/cloud-secrets-ipc.ts
+++ b/src/main/cloud-secrets/cloud-secrets-ipc.ts
@@ -4,6 +4,7 @@ import { app, ipcMain } from 'electron'
import { z } from 'zod'
import {
CLOUD_SECRET_SCOPES,
+ CLOUD_SECRET_WORKSPACE_MODES,
MAX_CLOUD_SECRET_BATCH,
type CloudSecretsResult,
type CloudSecretsStatus
@@ -55,7 +56,10 @@ const BatchRequest = z
Object.keys(request.set ?? {}).length + (request.delete?.length ?? 0) <=
MAX_CLOUD_SECRET_BATCH
)
-const EffectiveRequest = z.object({ repo: Repo.optional() })
+const EffectiveRequest = z.object({
+ repo: Repo.optional(),
+ workspace: z.enum(CLOUD_SECRET_WORKSPACE_MODES).optional()
+})
const RefreshRequest = z.object({ runtimeEnvironmentId: z.string().min(1).max(256) })
const SaveDesktopKeyRequest = z.object({
agent: z.string().refine(isTuiAgent),
@@ -144,7 +148,7 @@ export function registerCloudSecretsHandlers(userDataPath: string): void {
})
ipcMain.handle('cloudSecrets:effective', (_event, raw: unknown) => {
const request = EffectiveRequest.safeParse(raw ?? {})
- return request.success ? attempt(client, (c) => c.effective(request.data.repo)) : invalid
+ return request.success ? attempt(client, (c) => c.effective(request.data.repo, undefined, request.data.workspace)) : invalid
})
// One desktop-sealed key, unsealed here and sent once to the user's personal Cloud secrets; the
// renderer names it (agent + variable) and never sees the value. Each call is one explicit click.
diff --git a/src/preload/api/cloud-secrets-bridge.ts b/src/preload/api/cloud-secrets-bridge.ts
index 8a0381587a2..58159600996 100644
--- a/src/preload/api/cloud-secrets-bridge.ts
+++ b/src/preload/api/cloud-secrets-bridge.ts
@@ -3,6 +3,7 @@ import type {
CloudSecretBatchResult,
CloudSecretTarget,
CloudSecretView,
+ CloudSecretWorkspaceMode,
CloudSecretsEffective,
CloudSecretsResult,
CloudSecretsStatus,
@@ -27,7 +28,11 @@ export type CloudSecretsApi = {
set?: Record
delete?: string[]
}) => Promise>
- effective: (request: { repo?: string }) => Promise>
+ /** `workspace: 'shared'`: what a workspace shared with the team gets (no personal secrets). */
+ effective: (request: {
+ repo?: string
+ workspace?: CloudSecretWorkspaceMode
+ }) => Promise>
/** Best-effort nudge so a running workspace picks up new values now; the server also does it on write. */
refreshEnv: (request: { runtimeEnvironmentId: string }) => Promise>
/** Who owns an Orca Cloud workspace and whether teammates share it (control plane only). */
diff --git a/src/renderer/src/components/settings/cloud-secrets/CloudSecretsPane.fixture.tsx b/src/renderer/src/components/settings/cloud-secrets/CloudSecretsPane.fixture.tsx
index ab2291b3601..7b4b3a01b53 100644
--- a/src/renderer/src/components/settings/cloud-secrets/CloudSecretsPane.fixture.tsx
+++ b/src/renderer/src/components/settings/cloud-secrets/CloudSecretsPane.fixture.tsx
@@ -127,6 +127,37 @@ export const effective = defineFixture({
)
})
+export const effectiveShared = defineFixture({
+ width: 760,
+ render: () => (
+
+
+
+ )
+})
+
+export const effectiveSolo = defineFixture({
+ width: 760,
+ render: () => (
+
+
+
+ )
+})
+
export const effectiveEmpty = defineFixture({
width: 760,
render: () => (
diff --git a/src/renderer/src/components/settings/cloud-secrets/CloudSecretsPane.tsx b/src/renderer/src/components/settings/cloud-secrets/CloudSecretsPane.tsx
index 70d236a775e..715fa2eee48 100644
--- a/src/renderer/src/components/settings/cloud-secrets/CloudSecretsPane.tsx
+++ b/src/renderer/src/components/settings/cloud-secrets/CloudSecretsPane.tsx
@@ -119,15 +119,81 @@ function ScopeTab({
)
}
+type WorkspaceMode = 'private' | 'shared'
+
+function WorkspacePicker({
+ value,
+ onChange
+}: {
+ value: WorkspaceMode
+ onChange: (mode: WorkspaceMode) => void
+}): React.JSX.Element {
+ const t = useTranslate()
+ const id = useId()
+ return (
+
+
+
+
+ )
+}
+
function EffectiveTab({
api,
- repo
+ repo,
+ mode,
+ inTeam
}: {
api: CloudSecretsApi
repo: string | null
+ mode: WorkspaceMode
+ /** Only team accounts share workspaces, so only they need the shared-workspace note. */
+ inTeam: boolean
}): React.JSX.Element {
- const { effective, reload } = useCloudSecretsEffective(api, repo)
- return
+ const t = useTranslate()
+ const { effective, reload } = useCloudSecretsEffective(api, repo, mode === 'shared')
+ // SEC-5: a shared workspace gets no personal secrets. Say so where a personal value would matter.
+ const personalInPlay =
+ effective.status === 'ready' &&
+ effective.value.secrets.some(
+ (secret) =>
+ secret.scope === 'personal' || secret.shadowed.some((entry) => entry.scope === 'personal')
+ )
+ const note =
+ mode === 'shared'
+ ? t(
+ 'cloudSecrets.effective.sharedNote',
+ 'Workspaces shared with your team don’t get personal secrets, so only shared and repository values are listed.'
+ )
+ : inTeam && personalInPlay
+ ? t(
+ 'cloudSecrets.effective.privateNote',
+ 'Personal values apply only to workspaces you haven’t shared. Once you share one, it gets only shared and repository values.'
+ )
+ : null
+ return (
+
+ {note ? : null}
+
+
+ )
}
/** Orca Cloud secrets by scope, plus which scope wins. Values are write-only. */
@@ -137,7 +203,8 @@ export function CloudSecretsPane({
people,
onSetUpAgent,
onAddProject,
- initialTab = 'personal'
+ initialTab = 'personal',
+ initialWorkspaceMode = 'private'
}: {
api: CloudSecretsApi
repos: readonly CloudSecretRepoChoice[]
@@ -146,17 +213,22 @@ export function CloudSecretsPane({
/** Opens the app's Add project flow, the way to get a GitHub repository here. */
onAddProject?: () => void
initialTab?: Tab
+ /** Fixtures: start the effective view on a shared workspace. */
+ initialWorkspaceMode?: WorkspaceMode
}): React.JSX.Element {
const t = useTranslate()
const [tab, setTab] = useState(initialTab)
// Undefined until the user picks, so a repo list that loads after mount still preselects its first entry.
const [pickedRepo, setRepo] = useState(undefined)
+ const [workspaceMode, setWorkspaceMode] = useState(initialWorkspaceMode)
const repo = pickedRepo === undefined ? (repos[0]?.key ?? null) : pickedRepo
const repoTabRepo = repo ?? repos[0]?.key ?? null
const { effective: callerView } = useCloudSecretsEffective(api, null)
const caller = callerView.status === 'ready' ? callerView.value.caller : null
// Until the caller is known, keep the Shared tab so the tab row does not shift when it loads.
const inTeam = callerView.status === 'loading' || (caller !== null && caller.orgId !== null)
+ // Known team member: personal accounts have no teammates to share a workspace with.
+ const teamCaller = caller !== null && caller.orgId !== null
const withViewer: CloudSecretPeople = { ...people, viewerUserId: caller?.userId ?? null }
const adminNotice = t(
'cloudSecrets.readOnly.shared',
@@ -316,10 +388,22 @@ export function CloudSecretsPane({
'What a new cloud workspace gets, and which scope each value comes from.'
)}
- {repos.length > 0 ? (
-
+ {repos.length > 0 || teamCaller ? (
+
+ {repos.length > 0 ? (
+
+ ) : null}
+ {teamCaller ? (
+
+ ) : null}
+
) : null}
-
+
diff --git a/src/renderer/src/components/settings/cloud-secrets/cloud-secrets-fixture-data.ts b/src/renderer/src/components/settings/cloud-secrets/cloud-secrets-fixture-data.ts
index e1fdf8bb5c2..0562beae319 100644
--- a/src/renderer/src/components/settings/cloud-secrets/cloud-secrets-fixture-data.ts
+++ b/src/renderer/src/components/settings/cloud-secrets/cloud-secrets-fixture-data.ts
@@ -117,6 +117,20 @@ export const FIXTURE_NAMES: Record = { u_dana: 'Dana Reyes', u_r
const never = (): Promise => new Promise(() => {})
+/** What the server answers for a shared workspace: personal values never win or count (SEC-5). */
+function withoutPersonal(
+ secrets: CloudSecretsEffective['secrets']
+): CloudSecretsEffective['secrets'] {
+ return secrets.flatMap((secret) => {
+ const others = secret.shadowed.filter((entry) => entry.scope !== 'personal')
+ if (secret.scope !== 'personal') {
+ return [{ ...secret, shadowed: others }]
+ }
+ const [next, ...rest] = others
+ return next ? [{ ...secret, scope: next.scope, hint: next.hint, shadowed: rest }] : []
+ })
+}
+
export function fixtureCloudSecretsApi(options: {
caller?: CloudSecretsCaller
secrets?: Partial>
@@ -153,16 +167,20 @@ export function fixtureCloudSecretsApi(options: {
deleted: [],
errors: []
}),
- effective: () =>
+ effective: ({ workspace }) =>
options.pending
? never()
: ok({
caller,
+ workspace: workspace ?? 'private',
precedence: {
env: ['repo', 'personal', 'org'],
agent_key: ['org', 'repo', 'personal']
},
- secrets: options.effective ?? FIXTURE_EFFECTIVE_SECRETS
+ secrets:
+ workspace === 'shared'
+ ? withoutPersonal(options.effective ?? FIXTURE_EFFECTIVE_SECRETS)
+ : (options.effective ?? FIXTURE_EFFECTIVE_SECRETS)
}),
refreshEnv: () => ok(true),
saveDesktopKey: ({ envName }) =>
diff --git a/src/renderer/src/components/settings/cloud-secrets/use-cloud-secrets.ts b/src/renderer/src/components/settings/cloud-secrets/use-cloud-secrets.ts
index 93c687925fa..6c09f75cf0b 100644
--- a/src/renderer/src/components/settings/cloud-secrets/use-cloud-secrets.ts
+++ b/src/renderer/src/components/settings/cloud-secrets/use-cloud-secrets.ts
@@ -173,9 +173,21 @@ export function useCloudSecretList(
/** Who the caller is (role gating) and which scope wins per name, optionally for one repo. */
export function useCloudSecretsEffective(
api: CloudSecretsApi,
- repo: string | null
+ repo: string | null,
+ /** `true`: answer for a workspace shared with the team, which gets no personal secrets. */
+ shared = false
): { effective: Loadable; reload: () => void } {
- const read = useCallback(() => api.effective(repo ? { repo } : {}), [api, repo])
- const [effective, , reload] = useLoad(`effective:${repo ?? ''}`, read)
+ const read = useCallback(
+ () =>
+ api.effective({
+ ...(repo ? { repo } : {}),
+ ...(shared ? { workspace: 'shared' as const } : {})
+ }),
+ [api, repo, shared]
+ )
+ const [effective, , reload] = useLoad(
+ `effective:${shared ? 'shared' : 'private'}:${repo ?? ''}`,
+ read
+ )
return { effective, reload }
}
diff --git a/src/renderer/src/i18n/locales/en.json b/src/renderer/src/i18n/locales/en.json
index 2c9dbbad384..9a73544d247 100644
--- a/src/renderer/src/i18n/locales/en.json
+++ b/src/renderer/src/i18n/locales/en.json
@@ -28009,7 +28009,12 @@
"value": "Value",
"shadowed": "Overrides",
"overrides": "Overrides {{scopes}}",
- "description": "What a new cloud workspace gets, and which scope each value comes from."
+ "description": "What a new cloud workspace gets, and which scope each value comes from.",
+ "workspaceLabel": "Workspace",
+ "workspacePrivate": "Not shared",
+ "workspaceShared": "Shared with your team",
+ "sharedNote": "Workspaces shared with your team don’t get personal secrets, so only shared and repository values are listed.",
+ "privateNote": "Personal values apply only to workspaces you haven’t shared. Once you share one, it gets only shared and repository values."
},
"repo": {
"label": "Repository",
diff --git a/src/shared/cloud-secrets/cloud-secrets-wire.ts b/src/shared/cloud-secrets/cloud-secrets-wire.ts
index 707f3e370ae..7debe963df0 100644
--- a/src/shared/cloud-secrets/cloud-secrets-wire.ts
+++ b/src/shared/cloud-secrets/cloud-secrets-wire.ts
@@ -42,7 +42,13 @@ export type CloudSecretBatchResult = z.infer