Multiplayer agent harness for work.
Refuse deployment credentials through one helper in the decision and skill-pack lookups
Josh France28502f8333c8
diff --git a/docs/deployment-broker-credentials.md b/docs/deployment-broker-credentials.mdindex 986b47ca3..c1ec1d162 100644--- a/docs/deployment-broker-credentials.md+++ b/docs/deployment-broker-credentials.md@@ -37,6 +37,7 @@ can see them in Settings but can't edit, delete or replace them.| `allowedPathPrefixes` | no | Allowed path prefixes. Defaults to any path. || `maxRequestsPerDay` | no | Cap on calls let through per UTC day, shared by every core process. Calls over the cap get `429 daily_cap_reached`. |+Never put a secret in `BROKER_CREDENTIALS` itself; a JSON syntax error can quote part of the value.Unknown fields, a missing secret, a duplicate slug or any invalid value stop the core at startup with anerror naming the entry. Errors never include secret values.diff --git a/src/credentials/deployment-credentials.ts b/src/credentials/deployment-credentials.tsindex 7210f7264..a18f6012a 100644--- a/src/credentials/deployment-credentials.ts+++ b/src/credentials/deployment-credentials.ts@@ -129,6 +129,10 @@ function projected(c: DeploymentBrokerCredential): PublicServiceCredential {return { ...rest, hasSecret: true, updatedAt: 0 };}+export function nonDeploymentCredential<T extends { source?: "deployment" }>(record: T | null): T | null {+ return record && record.source !== "deployment" ? record : null;+}+export function reservedSlugError(slug: string): Error {return new Error(`credential "${slug}" is supplied by this deployment and cannot be changed here`);}diff --git a/src/wiring.ts b/src/wiring.tsindex e0d50b77b..a3aab8852 100644--- a/src/wiring.ts+++ b/src/wiring.ts@@ -1,5 +1,5 @@import type { MemoryEmbedder } from "./model/embeddings.ts";-import { withDeploymentCredentials } from "./credentials/deployment-credentials.ts";+import { nonDeploymentCredential, 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";@@ -1519,11 +1519,9 @@ export function buildApp(: {}),credential: async (slug) => {const rec = keychain- ? await serviceCreds.getServiceCredentialSecret(scopeId("org", config.orgId), slug)- : null;- return rec && rec.source !== "deployment"- ? { host: rec.host, enabled: rec.enabled, header: brokerCredentialAuthHeader(rec) }+ ? nonDeploymentCredential(await serviceCreds.getServiceCredentialSecret(scopeId("org", config.orgId), slug)): null;+ return rec ? { host: rec.host, enabled: rec.enabled, header: brokerCredentialAuthHeader(rec) } : null;},}),auditLog,@@ -2168,8 +2166,10 @@ export function buildApp(resolvePackAuth({serviceCredential: async (slug) => {- const record = await serviceCreds.getServiceCredentialSecret(scopeId("org", config.orgId), slug);- return record && record.delivery !== "env" && record.source !== "deployment" ? record : undefined;+ const record = nonDeploymentCredential(+ await serviceCreds.getServiceCredentialSecret(scopeId("org", config.orgId), slug),+ );+ return record && record.delivery !== "env" ? record : undefined;},connectorToken: async (host, principalId) =>(await keychain.connectorAccessToken(host, principalId)) ?? undefined,diff --git a/test/deployment-broker-credentials.test.ts b/test/deployment-broker-credentials.test.tsindex c97e72c5c..b8cf58791 100644--- a/test/deployment-broker-credentials.test.ts+++ b/test/deployment-broker-credentials.test.ts@@ -16,6 +16,7 @@ import { decisionsResource } from "../src/api/routes/decisions-resource.ts";import type { ApiCtx } from "../src/api/routes/route.ts";import {deploymentBrokerCredentialsFromEnv,+ nonDeploymentCredential,withDeploymentCredentials,type DeploymentBrokerCredential,} from "../src/credentials/deployment-credentials.ts";@@ -149,6 +150,8 @@ test("deployment credentials win lookups in their org and reserve their slugs agassert.equal((await store.getServiceCredentialSecret(ORG, "search"))?.secret, KEY);assert.equal((await store.getServiceCredentialSecret(ORG, "search"))?.source, "deployment");assert.equal((await store.getServiceCredentialSecret(ORG, "stored"))?.source, undefined);+ assert.equal(nonDeploymentCredential(await store.getServiceCredentialSecret(ORG, "search")), null);+ assert.equal(nonDeploymentCredential(await store.getServiceCredentialSecret(ORG, "stored"))?.secret, "db-secret");assert.equal((await store.getServiceCredentialSecret(ORG, "stored"))?.secret, "db-secret");assert.equal((await store.getServiceCredentialSecret("org:other", "search"))?.secret, "db-secret");assert.equal((await store.listServiceCredentials("org:other")).length, 2);