Multiplayer agent harness for work.
Serve deployment credentials through the broker as org-wide grants, reserve their slugs, and keep them off decision providers
Josh Francecfbb80658910
diff --git a/src/api/routes/admin-resources.ts b/src/api/routes/admin-resources.tsindex c2efcf02a..7d8fadf18 100644--- a/src/api/routes/admin-resources.ts+++ b/src/api/routes/admin-resources.ts@@ -936,6 +936,12 @@ export const ADMIN_RESOURCES: readonly AdminResource[] = [const ref = encodeRef(serviceCredRef(slug));const allCreds = await deps.serviceCreds.listServiceCredentials(scope);const existing = allCreds.find((c) => c.slug === slug);+ if (existing?.source === "deployment")+ return {+ error: `"${slug}" is supplied by this deployment's configuration and can't be edited, deleted or reused here.`,+ code: "deployment_credential",+ status: 409,+ };const conflict = () => ({error: "Credential changed after this editor was loaded. Reload it before continuing.",code: "version_conflict",diff --git a/src/api/routes/decisions-resource.ts b/src/api/routes/decisions-resource.tsindex fb82a3d0a..ed2a5bea4 100644--- a/src/api/routes/decisions-resource.ts+++ b/src/api/routes/decisions-resource.ts@@ -16,7 +16,9 @@ export const decisionsResource: AdminResource = {deps.decisions && {...decisionCatalog(),models: selectableBaseModels().map((m) => m.id),- credentials: ((await deps.serviceCreds?.listServiceCredentials(scope)) ?? []).map((c) => c.slug),+ credentials: ((await deps.serviceCreds?.listServiceCredentials(scope)) ?? [])+ .filter((c) => c.source !== "deployment")+ .map((c) => c.slug),providers: await deps.decisions.providers(),rules: await deps.decisions.rules(),},@@ -37,6 +39,10 @@ export const decisionsResource: AdminResource = {} else if (body.provider !== undefined) {const parsed = parseDecisionProvider(body.provider);if ("error" in parsed) return parsed;+ const credential = parsed.provider.credential;+ const credentials = credential ? ((await ctx.deps.serviceCreds?.listServiceCredentials(scope)) ?? []) : [];+ if (credentials.some((c) => c.slug === credential && c.source === "deployment"))+ return { error: `credential ${credential} is supplied by this deployment for the broker only` };await store.saveProvider(parsed.provider, by);change = ["decision.provider.save", parsed.provider.id];} else if (body.rule !== undefined) {diff --git a/src/core/orchestrator.ts b/src/core/orchestrator.tsindex 43c3fce70..fe1ca7790 100644--- a/src/core/orchestrator.ts+++ b/src/core/orchestrator.ts@@ -1548,36 +1548,40 @@ export function createOrchestrator(deps: OrchestratorDeps): Orchestrator {perf.credsMs += Date.now() - credsStart;// Service credentials: one read of the org's credential list and one grant scan feed both// the env-delivery gate (below) and the broker token mint (further down). Same grants gate both.+ // Deployment-supplied credentials carry an implicit org-wide grant: every participant must+ // be entitled to the org, exactly as an org grantee row would require.+ const grantedServiceCredSlugs = async (records: readonly PublicServiceCredential[]): Promise<Set<string>> => {+ const granted = new Set(+ (+ await deps.acl.grantsOfKind(+ "service-cred",+ conversation.audience,+ scopeId,+ resolution.orgScopeId,+ principalEntitledToScope,+ )+ ).map((g) => parseRef(g.ref).id),+ );+ const orgWide =+ conversation.audience.length > 0 &&+ conversation.audience.every((p) =>+ principalEntitledToScope(p, resolution.orgScopeId, scopeId, resolution.orgScopeId),+ );+ if (orgWide) for (const record of records) if (record.source === "deployment") granted.add(record.slug);+ return granted;+ };let serviceCredRecords: PublicServiceCredential[] = [];let grantedCredSlugs = new Set<string>();if (!strictReadOnly && deps.serviceCreds) {serviceCredRecords = (await deps.serviceCreds.listServiceCredentials(resolution.orgScopeId)).filter((record) =>serviceAllowed(record.slug),);- if (serviceCredRecords.length > 0) {- grantedCredSlugs = new Set(- (- await deps.acl.grantsOfKind(- "service-cred",- conversation.audience,- scopeId,- resolution.orgScopeId,- principalEntitledToScope,- )- ).map((g) => parseRef(g.ref).id),- );- }+ if (serviceCredRecords.length > 0) grantedCredSlugs = await grantedServiceCredSlugs(serviceCredRecords);}const authorizeServiceCredential = async (slug: string): Promise<void> => {if (!serviceAllowed(slug)) throw new Error("Service is not approved for external Slack.");- const grants = await deps.acl.grantsOfKind(- "service-cred",- conversation.audience,- scopeId,- resolution.orgScopeId,- principalEntitledToScope,- );- if (!grants.some((grant) => parseRef(grant.ref).id === slug)) {+ const records = (await deps.serviceCreds?.listServiceCredentials(resolution.orgScopeId)) ?? [];+ if (!(await grantedServiceCredSlugs(records)).has(slug)) {throw new Error(`Service credential is no longer authorized: ${slug}`);}};@@ -1723,14 +1727,7 @@ export function createOrchestrator(deps: OrchestratorDeps): Orchestrator {const records = (await deps.serviceCreds.listServiceCredentials(resolution.orgScopeId)).filter((record) =>serviceAllowed(record.slug),);- const grants = await deps.acl.grantsOfKind(- "service-cred",- conversation.audience,- scopeId,- resolution.orgScopeId,- principalEntitledToScope,- );- const granted = new Set(grants.map((grant) => parseRef(grant.ref).id));+ const granted = await grantedServiceCredSlugs(records);const available = records.filter((record) => !isBackendCredential(record) && record.enabled && record.hasSecret && granted.has(record.slug),);diff --git a/src/wiring.ts b/src/wiring.tsindex 8e06376b6..bcb1d911f 100644--- a/src/wiring.ts+++ b/src/wiring.ts@@ -1,4 +1,5 @@import type { MemoryEmbedder } from "./model/embeddings.ts";+import { withDeploymentCredentials } from "./credentials/deployment-credentials.ts";import { resolveEmbeddingModel } from "./model/pi-models.ts";import { createPostgresTeamStore, type TeamStore } from "./teams/teams.ts";import { brokerCredentialAuthHeader } from "./api/credential-broker.ts";@@ -1311,6 +1312,12 @@ export function buildApp(// every other personal credential.const userModelCredentials = createUserModelCredentialStore({ keychain: credentialStore });const keychain: Keychain | undefined = keychainKeyMaterial ? credentialStore : undefined;+ const deploymentBrokerSlugs = new Set((config.brokerCredentials ?? []).map((c) => c.slug));+ const serviceCreds = withDeploymentCredentials(+ credentialStore,+ scopeId("org", config.orgId),+ config.brokerCredentials ?? [],+ );const mcpToolService = createMcpToolService({servers: mcpServers,audit: auditLog,@@ -1500,6 +1507,7 @@ export function buildApp(}: {}),credential: async (slug) => {+ if (deploymentBrokerSlugs.has(slug)) return null;const rec = await keychain?.getServiceCredentialSecret(scopeId("org", config.orgId), slug);return rec ? { host: rec.host, enabled: rec.enabled, header: brokerCredentialAuthHeader(rec) } : null;},@@ -1850,7 +1858,7 @@ export function buildApp(};const orgScope = scopeId("org", config.orgId);const credentials = await deploymentCredentialSlugs(- await credentialStore.listServiceCredentials(orgScope),+ await serviceCreds.listServiceCredentials(orgScope),orgScope,acl,);@@ -2105,7 +2113,7 @@ export function buildApp(connectorStatusCache,resolveConnectorClient: resolveClient,...(keychain ? { keychain } : {}),- serviceCreds: credentialStore,+ serviceCreds,deliveries,approvals,approvalGrants: artifactMap<CommandApprovalGrant>("approval_grants"),@@ -2146,7 +2154,7 @@ export function buildApp(resolvePackAuth({serviceCredential: async (slug) => {- const record = await keychain.getServiceCredentialSecret(scopeId("org", config.orgId), slug);+ const record = await serviceCreds.getServiceCredentialSecret(scopeId("org", config.orgId), slug);return record && record.delivery !== "env" ? record : undefined;},connectorToken: async (host, principalId) =>@@ -2980,7 +2988,7 @@ export function buildApp(workspace,memory,...(keychain ? { keychain } : {}),- serviceCreds: credentialStore,+ serviceCreds,deliveries,...(keychainApprovals ? { keychainApprovals } : {}),...(askResolution ? { fireAskResolution: askResolution } : {}),