diff --git a/slack-agent-modal/docs/contract.md b/slack-agent-modal/docs/contract.md index 54f35ce..808b1fc 100644 --- a/slack-agent-modal/docs/contract.md +++ b/slack-agent-modal/docs/contract.md @@ -39,14 +39,14 @@ Not yet verified: `src/vault.ts` implements this. Shapes are from the Infisical backend (`ee/routes/v1/agent-vault-routers/agent-vault-session-router.ts`, `ee/services/agent-vault-session/agent-vault-session-service.ts`) and were exercised live by the preflight (`npm run smoke -- --preflight --ungranted-bundle `). They are independent of the sandbox backend: - `POST /api/v1/auth/universal-auth/login` `{clientId, clientSecret}` returns `{accessToken, expiresIn, ...}`. -- `POST /api/v1/agent-vault/sessions` `{accessBundles: [""], ttl: "15m"}` returns `{session: {id, token, expiresAt, createdAt, accessBundles: [{id, name, position}]}}`. The token starts `agv_` and is returned only here. -- `GET /api/v1/agent-vault/sessions/:id` returns `{session: {id, status, expiresAt, revokedAt, createdAt, actor, accessBundles}}`. `status` is `active`, `revoked` or `expired`. +- `POST /api/v1/agent-vault/sessions` `{accessBundle: "", ttl: "15m"}` returns `{session: {id, token, expiresAt, createdAt, accessBundle: {id, name}}}`. The token starts `agv_` and is returned only here. +- `GET /api/v1/agent-vault/sessions/:id` returns `{session: {id, status, expiresAt, revokedAt, createdAt, actor, accessBundle}}`. `status` is `active`, `revoked` or `expired`. - `POST /api/v1/agent-vault/sessions/:id/revoke` returns 200 `{session}`, and again 200 for a session already revoked. - The proxy rejects a revoked token after its poll interval (lag not measured). Rules the server enforces: -- **One bundle per session** (`AGENT_VAULT_MAX_SESSION_BUNDLES = 1`); more is a 400. The API and `SessionApi.create` still take an array. +- **One bundle per session.** `SessionApi.create` still takes an array, and `src/vault.ts` sends its one name as `accessBundle`. - **Only granted bundles.** A bundle the identity isn't granted, or one that doesn't exist, is a 400: `No access bundle named '' is granted to you`. Verified live with an ungranted name. - **Admins bypass grants.** An Agent Vault admin can mint over any bundle, so the identity must be a plain member. The preflight flags an identity that can mint the ungranted bundle. - **TTL** is a duration of at least `1m`, or `never`. It defaults to `7d`, so Apollo always sends one: the run timeout plus 5 minutes. diff --git a/slack-agent-modal/src/smoke.ts b/slack-agent-modal/src/smoke.ts index 2cd46f1..e3aab1d 100644 --- a/slack-agent-modal/src/smoke.ts +++ b/slack-agent-modal/src/smoke.ts @@ -130,8 +130,8 @@ export async function checkSessionApi(vault: VaultApi, accessBundles: string[], const active = await vault.getSession(session.id); fail(active.status === "active", `a new session is ${active.status}, not active`); fail(active.expiresAt !== null, "a one-minute session has no expiry"); - const names = active.accessBundles.map((b) => b.name); - fail(names.join() === accessBundles.join(), `the session carries [${names}], not [${accessBundles}]`); + const name = active.accessBundle.name; + fail(name === accessBundles[0], `the session carries ${name}, not ${accessBundles[0]}`); } finally { await vault.sessions.revoke(session.id); } diff --git a/slack-agent-modal/src/test-helpers/fakes.ts b/slack-agent-modal/src/test-helpers/fakes.ts index 144b2a6..793f9ba 100644 --- a/slack-agent-modal/src/test-helpers/fakes.ts +++ b/slack-agent-modal/src/test-helpers/fakes.ts @@ -127,8 +127,8 @@ export class FakeSessions implements SessionApi { const id = `sess-${++this.next}`; this.log.push(`create ${id}`); this.active.add(id); - const accessBundles = request.accessBundles.map((name) => ({ name })); - this.sessions.set(id, { id, status: "active", revokedAt: null, expiresAt: "later", accessBundles }); + const accessBundle = { name: request.accessBundles[0] }; + this.sessions.set(id, { id, status: "active", revokedAt: null, expiresAt: "later", accessBundle }); return { id, token: `agv_secret-${this.next}` }; } diff --git a/slack-agent-modal/src/vault.test.ts b/slack-agent-modal/src/vault.test.ts index 5a8dec1..0798d4c 100644 --- a/slack-agent-modal/src/vault.test.ts +++ b/slack-agent-modal/src/vault.test.ts @@ -45,10 +45,11 @@ function vault(routes: Parameters[0]) { } const request = (accessBundles = ["coding-agent"], ttl = "15m") => ({ accessBundles, ttl }); +const wireBody = (accessBundle = "coding-agent", ttl = "15m") => ({ accessBundle, ttl }); test("create: logs in once, then mints a session for the bundle with the ttl", async () => { const { calls, sessions } = vault({ - [CREATE]: () => ({ body: { session: { id: "s1", token: "agv_x", expiresAt: null, accessBundles: [] } } }), + [CREATE]: () => ({ body: { session: { id: "s1", token: "agv_x", expiresAt: null, accessBundle: { name: "coding-agent" } } } }), }); assert.deepEqual(await sessions.create(request()), { id: "s1", token: "agv_x" }); await sessions.create(request()); @@ -56,7 +57,7 @@ test("create: logs in once, then mints a session for the bundle with the ttl", a assert.equal(calls.filter((c) => c.url.endsWith("/login")).length, 1, "access token is cached"); assert.deepEqual(calls[0].body, { clientId: "cid", clientSecret: "csecret" }); assert.equal(calls[1].url, "https://infisical.test/api/v1/agent-vault/sessions"); - assert.deepEqual(calls[1].body, { accessBundles: ["coding-agent"], ttl: "15m" }); + assert.deepEqual(calls[1].body, wireBody()); assert.match(calls[1].auth ?? "", /^Bearer at-\d+$/); }); @@ -66,10 +67,17 @@ test("create: each session carries the bundles its caller chose, not one fixed o await sessions.create(request(["read-only"], "5m")); assert.deepEqual( calls.filter((c) => c.url.endsWith("/sessions")).map((c) => c.body), - [request(["coding-agent"]), request(["read-only"], "5m")], + [wireBody("coding-agent"), wireBody("read-only", "5m")], ); }); +test("create: refuses anything but exactly one bundle before calling Infisical", async () => { + const { calls, sessions } = vault({}); + await assert.rejects(sessions.create(request([])), /exactly one access bundle/); + await assert.rejects(sessions.create(request(["a", "b"])), /exactly one access bundle/); + assert.equal(calls.length, 0); +}); + test("create: a bundle the identity isn't granted is refused by Infisical, and no token comes back", async () => { const { sessions } = vault({ [CREATE]: () => ({ @@ -92,7 +100,7 @@ test("getSession: returns the session's status", async () => { status: "revoked", revokedAt: "2026-10-18T00:00:00Z", expiresAt: null, - accessBundles: [{ name: "coding-agent" }], + accessBundle: { name: "coding-agent" }, }; const { getSession } = vault({ "GET /api/v1/agent-vault/sessions/s1": () => ({ body: { session } }) }); assert.deepEqual(await getSession("s1"), session); diff --git a/slack-agent-modal/src/vault.ts b/slack-agent-modal/src/vault.ts index 19468ae..e49ce2e 100644 --- a/slack-agent-modal/src/vault.ts +++ b/slack-agent-modal/src/vault.ts @@ -24,7 +24,7 @@ export interface SessionStatus { status: string; revokedAt: string | null; expiresAt: string | null; - accessBundles: { name: string }[]; + accessBundle: { name: string }; } /** Re-login this long before the access token expires, so a request never carries a stale one. */ @@ -71,7 +71,10 @@ export function createVault({ const sessions: SessionApi = { async create({ accessBundles, ttl }) { - const { session } = (await authed("POST", "/api/v1/agent-vault/sessions", { accessBundles, ttl })) as { + // SessionApi keeps a list, but a session carries exactly one bundle on the wire. + if (accessBundles.length !== 1) throw new Error("a session carries exactly one access bundle"); + const body = { accessBundle: accessBundles[0], ttl }; + const { session } = (await authed("POST", "/api/v1/agent-vault/sessions", body)) as { session: { id: string; token: string }; }; return { id: session.id, token: session.token }; diff --git a/slack-agent-sandbox/docs/contract.md b/slack-agent-sandbox/docs/contract.md index e31dc93..66a3708 100644 --- a/slack-agent-sandbox/docs/contract.md +++ b/slack-agent-sandbox/docs/contract.md @@ -71,13 +71,13 @@ Observed: `src/vault.ts` implements this, and `npm run smoke -- --preflight --ungranted-bundle ` exercises it: - `POST /api/v1/auth/universal-auth/login` `{clientId, clientSecret}` returns `{accessToken, expiresIn, ...}`. -- `POST /api/v1/agent-vault/sessions` `{accessBundles: [""], ttl: "15m"}` returns `{session: {id, token, expiresAt, createdAt, accessBundles: [{id, name, position}]}}`. The token starts `agv_` and is returned only here. -- `GET /api/v1/agent-vault/sessions/:id` returns `{session: {id, status, expiresAt, revokedAt, createdAt, actor, accessBundles}}`. `status` is `active`, `revoked` or `expired`. +- `POST /api/v1/agent-vault/sessions` `{accessBundle: "", ttl: "15m"}` returns `{session: {id, token, expiresAt, createdAt, accessBundle: {id, name}}}`. The token starts `agv_` and is returned only here. +- `GET /api/v1/agent-vault/sessions/:id` returns `{session: {id, status, expiresAt, revokedAt, createdAt, actor, accessBundle}}`. `status` is `active`, `revoked` or `expired`. - `POST /api/v1/agent-vault/sessions/:id/revoke` returns 200 `{session}`, and again 200 for a session already revoked. Rules the server enforces: -- **One access bundle per session**; more is a 400. The API and `SessionApi.create` still take an array. +- **One access bundle per session.** `SessionApi.create` still takes an array, and `src/vault.ts` sends its one name as `accessBundle`. - **Only granted access bundles.** One the identity isn't granted, or one that doesn't exist, is a 400: `No access bundle named '' is granted to you`. - **Admins bypass grants.** An Agent Vault Admin can mint over any access bundle, so the identity must be a plain Member. The preflight flags an identity that can mint an ungranted bundle. - **TTL** is a duration of at least `1m`, or `never`. It defaults to `7d`, so Atlas always sends one: the run timeout plus 5 minutes. diff --git a/slack-agent-sandbox/src/smoke.ts b/slack-agent-sandbox/src/smoke.ts index 8ea2cfc..b2cc11a 100644 --- a/slack-agent-sandbox/src/smoke.ts +++ b/slack-agent-sandbox/src/smoke.ts @@ -130,8 +130,8 @@ export async function checkSessionApi(vault: VaultApi, accessBundles: string[], const active = await vault.getSession(session.id); fail(active.status === "active", `a new session is ${active.status}, not active`); fail(active.expiresAt !== null, "a one-minute session has no expiry"); - const names = active.accessBundles.map((b) => b.name); - fail(names.join() === accessBundles.join(), `the session carries [${names}], not [${accessBundles}]`); + const name = active.accessBundle.name; + fail(name === accessBundles[0], `the session carries ${name}, not ${accessBundles[0]}`); } finally { await vault.sessions.revoke(session.id); } diff --git a/slack-agent-sandbox/src/test-helpers/fakes.ts b/slack-agent-sandbox/src/test-helpers/fakes.ts index 4b77870..c9400f3 100644 --- a/slack-agent-sandbox/src/test-helpers/fakes.ts +++ b/slack-agent-sandbox/src/test-helpers/fakes.ts @@ -142,8 +142,8 @@ export class FakeSessions implements SessionApi { const id = `sess-${++this.next}`; this.log.push(`create ${id}`); this.active.add(id); - const accessBundles = request.accessBundles.map((name) => ({ name })); - this.sessions.set(id, { id, status: "active", revokedAt: null, expiresAt: "later", accessBundles }); + const accessBundle = { name: request.accessBundles[0] }; + this.sessions.set(id, { id, status: "active", revokedAt: null, expiresAt: "later", accessBundle }); return { id, token: `agv_secret-${this.next}` }; } diff --git a/slack-agent-sandbox/src/vault.test.ts b/slack-agent-sandbox/src/vault.test.ts index 5a8dec1..0798d4c 100644 --- a/slack-agent-sandbox/src/vault.test.ts +++ b/slack-agent-sandbox/src/vault.test.ts @@ -45,10 +45,11 @@ function vault(routes: Parameters[0]) { } const request = (accessBundles = ["coding-agent"], ttl = "15m") => ({ accessBundles, ttl }); +const wireBody = (accessBundle = "coding-agent", ttl = "15m") => ({ accessBundle, ttl }); test("create: logs in once, then mints a session for the bundle with the ttl", async () => { const { calls, sessions } = vault({ - [CREATE]: () => ({ body: { session: { id: "s1", token: "agv_x", expiresAt: null, accessBundles: [] } } }), + [CREATE]: () => ({ body: { session: { id: "s1", token: "agv_x", expiresAt: null, accessBundle: { name: "coding-agent" } } } }), }); assert.deepEqual(await sessions.create(request()), { id: "s1", token: "agv_x" }); await sessions.create(request()); @@ -56,7 +57,7 @@ test("create: logs in once, then mints a session for the bundle with the ttl", a assert.equal(calls.filter((c) => c.url.endsWith("/login")).length, 1, "access token is cached"); assert.deepEqual(calls[0].body, { clientId: "cid", clientSecret: "csecret" }); assert.equal(calls[1].url, "https://infisical.test/api/v1/agent-vault/sessions"); - assert.deepEqual(calls[1].body, { accessBundles: ["coding-agent"], ttl: "15m" }); + assert.deepEqual(calls[1].body, wireBody()); assert.match(calls[1].auth ?? "", /^Bearer at-\d+$/); }); @@ -66,10 +67,17 @@ test("create: each session carries the bundles its caller chose, not one fixed o await sessions.create(request(["read-only"], "5m")); assert.deepEqual( calls.filter((c) => c.url.endsWith("/sessions")).map((c) => c.body), - [request(["coding-agent"]), request(["read-only"], "5m")], + [wireBody("coding-agent"), wireBody("read-only", "5m")], ); }); +test("create: refuses anything but exactly one bundle before calling Infisical", async () => { + const { calls, sessions } = vault({}); + await assert.rejects(sessions.create(request([])), /exactly one access bundle/); + await assert.rejects(sessions.create(request(["a", "b"])), /exactly one access bundle/); + assert.equal(calls.length, 0); +}); + test("create: a bundle the identity isn't granted is refused by Infisical, and no token comes back", async () => { const { sessions } = vault({ [CREATE]: () => ({ @@ -92,7 +100,7 @@ test("getSession: returns the session's status", async () => { status: "revoked", revokedAt: "2026-10-18T00:00:00Z", expiresAt: null, - accessBundles: [{ name: "coding-agent" }], + accessBundle: { name: "coding-agent" }, }; const { getSession } = vault({ "GET /api/v1/agent-vault/sessions/s1": () => ({ body: { session } }) }); assert.deepEqual(await getSession("s1"), session); diff --git a/slack-agent-sandbox/src/vault.ts b/slack-agent-sandbox/src/vault.ts index dac90b3..8c0ddec 100644 --- a/slack-agent-sandbox/src/vault.ts +++ b/slack-agent-sandbox/src/vault.ts @@ -24,7 +24,7 @@ export interface SessionStatus { status: string; revokedAt: string | null; expiresAt: string | null; - accessBundles: { name: string }[]; + accessBundle: { name: string }; } /** Re-login this long before the access token expires, so a request never carries a stale one. */ @@ -71,7 +71,10 @@ export function createVault({ const sessions: SessionApi = { async create({ accessBundles, ttl }) { - const { session } = (await authed("POST", "/api/v1/agent-vault/sessions", { accessBundles, ttl })) as { + // SessionApi keeps a list, but a session carries exactly one bundle on the wire. + if (accessBundles.length !== 1) throw new Error("a session carries exactly one access bundle"); + const body = { accessBundle: accessBundles[0], ttl }; + const { session } = (await authed("POST", "/api/v1/agent-vault/sessions", body)) as { session: { id: string; token: string }; }; return { id: session.id, token: session.token };