Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions slack-agent-modal/docs/contract.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <slug>`). 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: ["<slug>"], 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: "<slug>", 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 '<x>' 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.
Expand Down
4 changes: 2 additions & 2 deletions slack-agent-modal/src/smoke.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions slack-agent-modal/src/test-helpers/fakes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}` };
}

Expand Down
16 changes: 12 additions & 4 deletions slack-agent-modal/src/vault.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,19 @@ function vault(routes: Parameters<typeof fakeFetch>[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());

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+$/);
});

Expand All @@ -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]: () => ({
Expand All @@ -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);
Expand Down
7 changes: 5 additions & 2 deletions slack-agent-modal/src/vault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down Expand Up @@ -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 {
Comment thread
saifsmailbox98 marked this conversation as resolved.
Resolved
session: { id: string; token: string };
};
return { id: session.id, token: session.token };
Expand Down
6 changes: 3 additions & 3 deletions slack-agent-sandbox/docs/contract.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ Observed:
`src/vault.ts` implements this, and `npm run smoke -- --preflight --ungranted-bundle <slug>` exercises it:

- `POST /api/v1/auth/universal-auth/login` `{clientId, clientSecret}` returns `{accessToken, expiresIn, ...}`.
- `POST /api/v1/agent-vault/sessions` `{accessBundles: ["<slug>"], 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: "<slug>", 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 '<x>' 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.
Expand Down
4 changes: 2 additions & 2 deletions slack-agent-sandbox/src/smoke.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions slack-agent-sandbox/src/test-helpers/fakes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}` };
}

Expand Down
16 changes: 12 additions & 4 deletions slack-agent-sandbox/src/vault.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,19 @@ function vault(routes: Parameters<typeof fakeFetch>[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());

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+$/);
});

Expand All @@ -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]: () => ({
Expand All @@ -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);
Expand Down
7 changes: 5 additions & 2 deletions slack-agent-sandbox/src/vault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down Expand Up @@ -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 };
Expand Down