diff --git a/cloud/apps/sandbox-control/src/account-providers.ts b/cloud/apps/sandbox-control/src/account-providers.ts index a32a321691c..f0ddd66de92 100644 --- a/cloud/apps/sandbox-control/src/account-providers.ts +++ b/cloud/apps/sandbox-control/src/account-providers.ts @@ -32,9 +32,10 @@ export type AccountProvider = { credential(db: D1Database, keyring: Keyring, userId: string, now: number): Promise } -/** D13: a workspace shared with teammates never uses a personal account. */ +/** D13: a workspace shared with teammates never uses a personal account. Fails closed: only a row + * known to be private counts as unshared. */ export function isSharedWorkspace(row: Pick): boolean { - return row.visibility === 'team' + return row.visibility !== 'private' } export const claudeAccount: AccountProvider = { diff --git a/cloud/apps/sandbox-control/test/agent-accounts.test.ts b/cloud/apps/sandbox-control/test/agent-accounts.test.ts index efb68967bd4..998596a338d 100644 --- a/cloud/apps/sandbox-control/test/agent-accounts.test.ts +++ b/cloud/apps/sandbox-control/test/agent-accounts.test.ts @@ -1,5 +1,6 @@ import { SignJWT, createLocalJWKSet, exportJWK, generateKeyPair } from 'jose' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' +import { isSharedWorkspace } from '../src/account-providers' import { ENV_COMMAND, START_COMMAND } from '../src/sandbox-vm-commands' import { createHarness } from './harness' @@ -199,3 +200,13 @@ describe('egress-time Source (D10) and shared workspaces (D13)', () => { expect((await h.call('GET', '/v1/agent-credentials', { bearer: mia })).body.providerEnabled.claude).toBe(false) }) }) + +describe('D13 fails closed', () => { + it('treats any visibility other than private as shared', () => { + expect(isSharedWorkspace({ visibility: 'private' })).toBe(false) + expect(isSharedWorkspace({ visibility: 'team' })).toBe(true) + for (const visibility of ['', 'org', null, undefined] as unknown as string[]) { + expect(isSharedWorkspace({ visibility } as never)).toBe(true) + } + }) +}) diff --git a/src/renderer/src/components/agent-host-panel/cloud-sections/CloudMissingSecretRow.tsx b/src/renderer/src/components/agent-host-panel/cloud-sections/CloudMissingSecretRow.tsx index 2917af5db7f..ab442e17869 100644 --- a/src/renderer/src/components/agent-host-panel/cloud-sections/CloudMissingSecretRow.tsx +++ b/src/renderer/src/components/agent-host-panel/cloud-sections/CloudMissingSecretRow.tsx @@ -20,11 +20,7 @@ import type { CloudSecretsErrorCode } from '../../../../../shared/cloud-secrets/cloud-secrets-wire' import { parseScope, writableScopes } from '../../cloud-secrets-ask/cloud-secrets-ask-model' -import { - isGuestInSharedWorkspace, - type CloudPanelAddSecret, - type CloudPanelSectionsData -} from './use-cloud-panel-sections' +import type { CloudPanelAddSecret, CloudPanelSectionsData } from './use-cloud-panel-sections' /** A declared name nobody provides: Missing chip, then Add (members: Add mine) opens an inline field. */ export function CloudMissingSecretRow({ @@ -47,8 +43,8 @@ export function CloudMissingSecretRow({ const t = useTranslate() const id = React.useId() const admin = data.effective.caller.canWrite.org - // A teammate's Personal values don't reach someone else's shared workspace. - const guest = isGuestInSharedWorkspace(data) + // A teammate's Personal values don't reach someone else's shared workspace (or one we can't tell). + const guest = data.withoutPersonal const scopes = writableScopes(data.effective.caller, { repo: data.repoKey !== null, shared: true diff --git a/src/renderer/src/components/agent-host-panel/cloud-sections/CloudPanelSections.fixture.tsx b/src/renderer/src/components/agent-host-panel/cloud-sections/CloudPanelSections.fixture.tsx index c1e3ef34c31..c91e67fa15c 100644 --- a/src/renderer/src/components/agent-host-panel/cloud-sections/CloudPanelSections.fixture.tsx +++ b/src/renderer/src/components/agent-host-panel/cloud-sections/CloudPanelSections.fixture.tsx @@ -183,7 +183,8 @@ export const empty = defineFixture({ missing: [], repoKey: 'github.com/acme/web', asleep: false, - sharing: null + sharing: null, + withoutPersonal: false } }} /> diff --git a/src/renderer/src/components/agent-host-panel/cloud-sections/cloud-panel-sections-model.test.ts b/src/renderer/src/components/agent-host-panel/cloud-sections/cloud-panel-sections-model.test.ts index 325eeaca5b0..b32c87666c4 100644 --- a/src/renderer/src/components/agent-host-panel/cloud-sections/cloud-panel-sections-model.test.ts +++ b/src/renderer/src/components/agent-host-panel/cloud-sections/cloud-panel-sections-model.test.ts @@ -111,4 +111,27 @@ describe('shared workspaces (D13)', () => { .missing ).toEqual([]) }) + + it('fails closed when the workspace sharing could not be read (D13)', () => { + const declared = ['NPM_TOKEN', 'SENTRY_DSN', 'DATABASE_URL'] + const data = cloudPanelSectionsData({ + effective: values, + envVarNames: declared, + repoKey: null, + asleep: false, + sharing: null, + sharingUnknown: true + }) + expect(data.withoutPersonal).toBe(true) + expect(data.missing).toEqual(['NPM_TOKEN']) + expect( + cloudPanelSectionsData({ + effective: values, + envVarNames: declared, + repoKey: null, + asleep: false, + sharing: null + }).withoutPersonal + ).toBe(false) + }) }) diff --git a/src/renderer/src/components/agent-host-panel/cloud-sections/use-cloud-panel-sections.ts b/src/renderer/src/components/agent-host-panel/cloud-sections/use-cloud-panel-sections.ts index 788a52a1a62..7badd914942 100644 --- a/src/renderer/src/components/agent-host-panel/cloud-sections/use-cloud-panel-sections.ts +++ b/src/renderer/src/components/agent-host-panel/cloud-sections/use-cloud-panel-sections.ts @@ -23,6 +23,11 @@ export type CloudPanelSectionsData = { asleep: boolean /** Shared with teammates (D13), and whose workspace it is; null when unknown. */ sharing: CloudWorkspaceSharing | null + /** + * The caller's Personal values are left out: a teammate in a shared workspace, or a workspace whose + * sharing couldn't be read (D13 fails closed: it may be someone else's shared workspace). + */ + withoutPersonal: boolean } /** A teammate's view of someone else's shared workspace: only their non-Personal values apply. */ @@ -36,10 +41,13 @@ export function cloudPanelSectionsData(args: { repoKey: string | null asleep: boolean sharing: CloudWorkspaceSharing | null + /** The workspace's sharing read failed; treat it as possibly someone else's shared workspace. */ + sharingUnknown?: boolean }): CloudPanelSectionsData { - const guest = isGuestInSharedWorkspace(args) - const effective = guest ? withoutCallerPersonal(args.effective) : args.effective + const withoutPersonal = args.sharingUnknown === true || isGuestInSharedWorkspace(args) + const effective = withoutPersonal ? withoutCallerPersonal(args.effective) : args.effective return { + withoutPersonal, effective, missing: args.envVarNames ? missingSecretNames(args.envVarNames, effective) : [], repoKey: args.repoKey, @@ -103,7 +111,9 @@ export function useCloudPanelSections(args: { envVarNames: environment?.envVarNames ?? null, repoKey, asleep, - sharing: sharing?.ok ? sharing.value : null + sharing: sharing?.ok ? sharing.value : null, + // A sandbox whose sharing couldn't be read fails closed (D13). + sharingUnknown: runtimeEnvironmentId !== null && !sharing?.ok }) }) })()