Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

feat(agent-vault): on-behalf-of sessions need the bundle granted to the identity too

Scott Wilsonc8e78fe12931
diff --git a/backend/e2e-test/routes/v1/agent-vault.spec.ts b/backend/e2e-test/routes/v1/agent-vault.spec.ts
index 70ef6ffa9b..17d6ed0137 100644
--- a/backend/e2e-test/routes/v1/agent-vault.spec.ts
+++ b/backend/e2e-test/routes/v1/agent-vault.spec.ts
@@ -3974,7 +3974,7 @@ describe("Agent Vault V1 Router", async () => {
const alice = await createAgentVaultUser("obo-alice", projectId);
const bob = await createAgentVaultUser("obo-bob", projectId);
try {
- await grantBundle(bundle.id, { userIds: [alice.userId, bob.userId] });
+ await grantBundle(bundle.id, { userIds: [alice.userId, bob.userId], machineIdentityIds: [bot.id] });
const undelegated = await mintFor(bot, { userId: alice.userId }, bundle.name);
expect(undelegated.statusCode).toBe(403);
@@ -4029,7 +4029,7 @@ describe("Agent Vault V1 Router", async () => {
const carol = await createAgentVaultUser("obo-carol", null);
await testDb("user_group_membership").insert({ groupId: group.id, userId: carol.userId });
try {
- await grantBundle(bundle.id, { groupIds: [group.id] });
+ await grantBundle(bundle.id, { groupIds: [group.id], machineIdentityIds: [bot.id] });
const direct = await inject("PUT", delegationUrl(bot.id), { scope: "selected", userIds: [carol.userId] });
expect(direct.statusCode).toBe(400);
@@ -4052,18 +4052,34 @@ describe("Agent Vault V1 Router", async () => {
}
});
- test("the session reaches the bundles the user reaches, never the identity's own", async () => {
+ test("a session on a user's behalf can use only a bundle both the user and the identity can use", async () => {
const projectId = await getProjectId();
- const theirs = await createAccessBundle(`obo-theirs-${Date.now()}`);
+ const shared = await createAccessBundle(`obo-shared-${Date.now()}`);
+ const usersOnly = await createAccessBundle(`obo-users-only-${Date.now()}`);
const botsOnly = await createAccessBundle(`obo-bots-only-${Date.now()}`);
const bot = await createMemberIdentity(`obo-reach-bot-${Date.now()}`);
const alice = await createAgentVaultUser("obo-reach-alice", projectId);
try {
- await grantBundle(theirs.id, { userIds: [alice.userId] });
+ await grantBundle(shared.id, { userIds: [alice.userId], machineIdentityIds: [bot.id] });
+ await grantBundle(usersOnly.id, { userIds: [alice.userId] });
await grantBundle(botsOnly.id, { machineIdentityIds: [bot.id] });
await delegate(bot, { scope: "selected", userIds: [alice.userId] });
- expect((await mintFor(bot, { userId: alice.userId }, theirs.name)).statusCode).toBe(200);
+ expect((await mintFor(bot, { userId: alice.userId }, shared.name)).statusCode).toBe(200);
+
+ // The identity's own bundles are checked before the user is looked up, so a name that doesn't exist and a user
+ // who doesn't exist read exactly like a bundle the identity isn't granted.
+ const notTheBots = await Promise.all([
+ mintFor(bot, { userId: alice.userId }, usersOnly.name),
+ mintFor(bot, { userId: crypto.randomUUID() }, usersOnly.name),
+ mintFor(bot, { userId: alice.userId }, `obo-no-such-bundle-${Date.now()}`)
+ ]);
+ notTheBots.forEach((refused) => {
+ expect(refused.statusCode).toBe(400);
+ expect(refused.json().message).toMatch(
+ /^No access bundle named '[^']+' is granted to this machine identity\. A session on behalf of a user can use only bundles granted to both the user and the machine identity, so check the name, or ask an Agent Vault admin to grant the bundle to the machine identity\.$/
+ );
+ });
const notTheirs = await mintFor(bot, { userId: alice.userId }, botsOnly.name);
expect(notTheirs.statusCode).toBe(400);
@@ -4083,7 +4099,7 @@ describe("Agent Vault V1 Router", async () => {
const alice = await createAgentVaultUser("obo-all-alice", projectId);
const outsider = await createAgentVaultUser("obo-all-outsider", null);
try {
- await grantBundle(bundle.id, { userIds: [alice.userId] });
+ await grantBundle(bundle.id, { userIds: [alice.userId], machineIdentityIds: [bot.id] });
const delegation = await delegate(bot, { scope: "all-members" });
expect(delegation).toMatchObject({ scope: "all-members", users: [], groups: [] });
@@ -4161,7 +4177,10 @@ describe("Agent Vault V1 Router", async () => {
});
const bot = await createMemberIdentity(`obo-resolve-bot-${Date.now()}`);
+ const serviceNames = (res: Awaited<ReturnType<typeof resolve>>) =>
+ (res.json().services as { name: string }[]).map((service) => service.name);
try {
+ await grantBundle(bundle.id, { machineIdentityIds: [bot.id] });
await delegate(bot, { scope: "selected", userIds: [seedData1.id] });
const minted = await mintFor(bot, { userId: seedData1.id }, bundle.name);
expect(minted.statusCode).toBe(200);
@@ -4181,6 +4200,17 @@ describe("Agent Vault V1 Router", async () => {
await delegate(bot, { scope: "selected", userIds: [seedData1.id] });
expect((await resolve(token)).statusCode).toBe(200);
+ // The admin user still reaches the bundle, but the identity losing its grant takes the bundle's services away,
+ // the way losing a user's grant does, and granting it again brings them back.
+ expect((await inject("DELETE", bundleMembersUrl(bundle.id), { machineIdentityIds: [bot.id] })).statusCode).toBe(
+ 200
+ );
+ const withoutGrant = await resolve(token);
+ expect(withoutGrant.statusCode).toBe(200);
+ expect(serviceNames(withoutGrant)).not.toContain("github");
+ await grantBundle(bundle.id, { machineIdentityIds: [bot.id] });
+ expect(serviceNames(await resolve(token))).toContain("github");
+
// Removing the identity from Agent Vault deletes its delegation, so adding it back restores nothing.
expect(
(await inject("DELETE", "/api/v1/agent-vault/members", { machineIdentityIds: [bot.id] })).statusCode
@@ -4199,7 +4229,7 @@ describe("Agent Vault V1 Router", async () => {
const bot = await createMemberIdentity(botName);
const alice = await createAgentVaultUser("obo-owner-alice", projectId);
try {
- await grantBundle(bundle.id, { userIds: [alice.userId] });
+ await grantBundle(bundle.id, { userIds: [alice.userId], machineIdentityIds: [bot.id] });
await delegate(bot, { scope: "selected", userIds: [alice.userId] });
const first = (await mintFor(bot, { userId: alice.userId }, bundle.name)).json().session.id as string;
diff --git a/backend/src/ee/services/agent-vault-proxy/agent-vault-proxy-service.ts b/backend/src/ee/services/agent-vault-proxy/agent-vault-proxy-service.ts
index f35eeb94ac..5673b42c3c 100644
--- a/backend/src/ee/services/agent-vault-proxy/agent-vault-proxy-service.ts
+++ b/backend/src/ee/services/agent-vault-proxy/agent-vault-proxy-service.ts
@@ -30,7 +30,11 @@ import {
TAgentVaultMemberProvidedField
} from "../agent-vault/agent-vault-enums";
import { TAgentVaultOwner } from "../agent-vault/agent-vault-owner-fns";
-import { findReachableAccessBundleIds, liveGroupIdsFrom } from "../agent-vault/agent-vault-permission";
+import {
+ findReachableAccessBundleIds,
+ intersectAccessBundleIds,
+ liveGroupIdsFrom
+} from "../agent-vault/agent-vault-permission";
import { expandStoredVariableReferences, findStoredVariableIds } from "../agent-vault/agent-vault-variable-fns";
import { TAgentVaultServiceCustomHeaderDALFactory } from "../agent-vault-access-bundle/agent-vault-service-custom-header-dal";
import { TAgentVaultServiceSubstitutionDALFactory } from "../agent-vault-access-bundle/agent-vault-service-substitution-dal";
@@ -632,8 +636,9 @@ export const agentVaultProxyServiceFactory = ({
// The identity that started a session on a user's behalf has to still be in the org and in Agent Vault, and its
// delegation has to still cover the user. Read on every resolve, so taking any of them away ends the session on
- // the proxy's next poll.
- const $assertActingIdentityStillDelegated = async ({
+ // the proxy's next poll. Returns the bundles the identity reaches (null for every bundle), since the session reaches
+ // only what both the identity and the user reach.
+ const $getActingIdentityReach = async ({
projectId,
orgId,
userId,
@@ -643,7 +648,7 @@ export const agentVaultProxyServiceFactory = ({
orgId: string;
userId: string | null;
actingIdentityId: string | null;
- }) => {
+ }): Promise<string[] | null> => {
const refused = () =>
new UnauthorizedError({
message: "The machine identity that started this session is no longer allowed to act on behalf of its user"
@@ -658,8 +663,10 @@ export const agentVaultProxyServiceFactory = ({
});
if (!orgMembership?.isActive) throw refused();
+ let isAdmin: boolean;
+ let liveGroupIds: string[];
try {
- const { permission } = await permissionService.getProjectPermission({
+ const { permission, hasRole, memberships } = await permissionService.getProjectPermission({
actor: ActorType.IDENTITY,
actorId: actingIdentityId,
projectId,
@@ -670,6 +677,8 @@ export const agentVaultProxyServiceFactory = ({
if (!permission.can(ProjectPermissionAgentVaultSessionActions.Read, ProjectPermissionSub.AgentVaultSessions)) {
throw refused();
}
+ isAdmin = hasRole(ProjectMembershipRole.Admin);
+ liveGroupIds = liveGroupIdsFrom(memberships);
} catch (error) {
if (error instanceof ForbiddenRequestError && error.name === "ProjectMembershipNotFound") throw refused();
throw error;
@@ -678,6 +687,13 @@ export const agentVaultProxyServiceFactory = ({
if (!(await agentVaultDelegationDAL.identityCoversUser({ projectId, identityId: actingIdentityId, userId }))) {
throw refused();
}
+
+ if (isAdmin) return null;
+ return findReachableAccessBundleIds(membershipDAL, {
+ projectId,
+ actor: { type: ActorType.IDENTITY, id: actingIdentityId },
+ groupIds: liveGroupIds
+ });
};
/** The only endpoint that decrypts a credential. The proxy's JWT authorizes; the session token is a selector. */
@@ -702,14 +718,16 @@ export const agentVaultProxyServiceFactory = ({
throw new UnauthorizedError({ message: "The identity this session belonged to has been deleted" });
}
// The name marks an on-behalf-of session even after deleting the identity nulls its id.
- if (session.actingIdentityName) {
- await $assertActingIdentityStillDelegated({
- projectId: session.projectId,
- orgId,
- userId: session.userId ?? null,
- actingIdentityId: session.actingIdentityId ?? null
- });
- }
+ const actingIdentity = session.actingIdentityName
+ ? {
+ reach: await $getActingIdentityReach({
+ projectId: session.projectId,
+ orgId,
+ userId: session.userId ?? null,
+ actingIdentityId: session.actingIdentityId ?? null
+ })
+ }
+ : null;
const actor = session.userId
? { type: ActorType.USER as const, id: session.userId }
@@ -756,13 +774,14 @@ export const agentVaultProxyServiceFactory = ({
throw error;
}
- const accessBundleIds = isAdmin
+ const actorReach = isAdmin
? null
: await findReachableAccessBundleIds(membershipDAL, {
projectId: session.projectId,
actor,
groupIds: liveGroupIds
});
+ const accessBundleIds = actingIdentity ? intersectAccessBundleIds(actorReach, actingIdentity.reach) : actorReach;
const rows = await agentVaultResolveDAL.findResolvableServices({
sessionId: session.id,
diff --git a/backend/src/ee/services/agent-vault-session/agent-vault-session-service.ts b/backend/src/ee/services/agent-vault-session/agent-vault-session-service.ts
index 903698e12c..d077570c13 100644
--- a/backend/src/ee/services/agent-vault-session/agent-vault-session-service.ts
+++ b/backend/src/ee/services/agent-vault-session/agent-vault-session-service.ts
@@ -87,17 +87,7 @@ export const agentVaultSessionServiceFactory = ({
status: deriveSessionStatus({ ...session, userId, identityId, actingIdentityId, actingIdentityName })
});
- // The delegation is checked before the user is looked up, so an identity no admin delegated learns nothing about
- // who is in the org, and a user who doesn't exist reads exactly like one the delegation doesn't cover.
- const resolveOnBehalfOfUser = async ({
- projectId,
- ctx,
- onBehalfOf
- }: {
- projectId: string;
- ctx: TGenericPermission;
- onBehalfOf: TOnBehalfOfUser;
- }) => {
+ const findCallerDelegation = async ({ projectId, ctx }: { projectId: string; ctx: TGenericPermission }) => {
if (ctx.actor !== ActorType.IDENTITY) {
throw new BadRequestError({ message: "Only a machine identity can start a session on behalf of a user" });
}
@@ -109,7 +99,21 @@ export const agentVaultSessionServiceFactory = ({
"This machine identity isn't allowed to start sessions on behalf of users. An Agent Vault admin can allow it by setting its delegation under Access Control."
});
}
+ return delegation;
+ };
+ // A user who doesn't exist reads exactly like one the delegation doesn't cover.
+ const resolveOnBehalfOfUser = async ({
+ projectId,
+ ctx,
+ onBehalfOf,
+ delegation
+ }: {
+ projectId: string;
+ ctx: TGenericPermission;
+ onBehalfOf: TOnBehalfOfUser;
+ delegation: Awaited<ReturnType<typeof findCallerDelegation>>;
+ }) => {
const identifier = onBehalfOf.userId ?? onBehalfOf.userEmail ?? "";
const notCovered = () =>
new ForbiddenRequestError({
@@ -132,8 +136,8 @@ export const agentVaultSessionServiceFactory = ({
if (!(await agentVaultDelegationDAL.coversUser({ delegation, userId: user.id }))) throw notCovered();
- // The session reaches what the user reaches, so their own role and grants decide the bundle, never the
- // identity's. actorAuthMethod is null as in resolve: the session row stores no auth method.
+ // The user's own role and grants decide what they reach. actorAuthMethod is null as in resolve: the session row
+ // stores no auth method.
const userCtx: TGenericPermission = {
actor: ActorType.USER,
actorId: user.id,
@@ -196,21 +200,6 @@ export const agentVaultSessionServiceFactory = ({
ProjectPermissionSub.AgentVaultSessions
);
- let reachable: string[] | null;
- let onBehalfOfUser: Awaited<ReturnType<typeof resolveOnBehalfOfUser>> | null = null;
- if (onBehalfOf) {
- onBehalfOfUser = await resolveOnBehalfOfUser({ projectId, ctx, onBehalfOf });
- reachable = onBehalfOfUser.accessBundleIds;
- // getProjectPermission leaves the last actor it ran for in the request context, where the audit log reads the
- // caller's permission metadata. Running the caller's check again, memoized so it costs no query, puts it back.
- await getAgentVaultPermission({ permissionService }, { projectId, ctx });
- } else {
- ({ accessBundleIds: reachable } = await getAgentVaultReachability(
- { permissionService, membershipDAL },
- { projectId, ctx }
- ));
- }
-
if (!accessBundles.length) {
throw new BadRequestError({ message: "Name the access bundle this session should carry" });
}
@@ -223,17 +212,52 @@ export const agentVaultSessionServiceFactory = ({
const bundles = await agentVaultAccessBundleDAL.find({ projectId, $in: { name: accessBundles } });
const bundlesByName = new Map(bundles.map((bundle) => [bundle.name, bundle]));
-
- const unreachable = accessBundles.find((name) => {
- const bundle = bundlesByName.get(name);
- return !bundle || (reachable !== null && !reachable.includes(bundle.id));
- });
- if (unreachable) {
- throw new BadRequestError({
- message: onBehalfOfUser
- ? `No access bundle named '${unreachable}' is granted to '${onBehalfOfUser.user.username}'. Check the name, or ask an Agent Vault admin to grant it to them.`
- : `No access bundle named '${unreachable}' is granted to you. Check the name, or ask an Agent Vault admin to grant it.`
+ // An unknown name reads like an ungranted one, so the error never confirms that a bundle exists.
+ const firstUnreachable = (reachable: string[] | null) =>
+ accessBundles.find((name) => {
+ const bundle = bundlesByName.get(name);
+ return !bundle || (reachable !== null && !reachable.includes(bundle.id));
});
+
+ let onBehalfOfUser: Awaited<ReturnType<typeof resolveOnBehalfOfUser>> | null = null;
+ if (onBehalfOf) {
+ // A session on a user's behalf can use only the bundles both the user and the identity reach. The delegation is
+ // checked first and the identity's own bundles next, so an identity learns nothing about who is in the org until
+ // an admin has delegated it and granted it the bundle it asks for.
+ const delegation = await findCallerDelegation({ projectId, ctx });
+ const { accessBundleIds: identityReach } = await getAgentVaultReachability(
+ { permissionService, membershipDAL },
+ { projectId, ctx }
+ );
+ const notGrantedToIdentity = firstUnreachable(identityReach);
+ if (notGrantedToIdentity) {
+ throw new BadRequestError({
+ message: `No access bundle named '${notGrantedToIdentity}' is granted to this machine identity. A session on behalf of a user can use only bundles granted to both the user and the machine identity, so check the name, or ask an Agent Vault admin to grant the bundle to the machine identity.`
+ });
+ }
+
+ onBehalfOfUser = await resolveOnBehalfOfUser({ projectId, ctx, onBehalfOf, delegation });
+ // getProjectPermission leaves the last actor it ran for in the request context, where the audit log reads the
+ // caller's permission metadata. Running the caller's check again, memoized so it costs no query, puts it back.
+ await getAgentVaultPermission({ permissionService }, { projectId, ctx });
+
+ const notGrantedToUser = firstUnreachable(onBehalfOfUser.accessBundleIds);
+ if (notGrantedToUser) {
+ throw new BadRequestError({
+ message: `No access bundle named '${notGrantedToUser}' is granted to '${onBehalfOfUser.user.username}'. Check the name, or ask an Agent Vault admin to grant it to them.`
+ });
+ }
+ } else {
+ const { accessBundleIds } = await getAgentVaultReachability(
+ { permissionService, membershipDAL },
+ { projectId, ctx }
+ );
+ const notGranted = firstUnreachable(accessBundleIds);
+ if (notGranted) {
+ throw new BadRequestError({
+ message: `No access bundle named '${notGranted}' is granted to you. Check the name, or ask an Agent Vault admin to grant it.`
+ });
+ }
}
const expiresAt = ttl === AGENT_VAULT_SESSION_TTL_NEVER ? null : new Date(Date.now() + ms(ttl));
@@ -245,8 +269,8 @@ export const agentVaultSessionServiceFactory = ({
kmsService
);
- // An on-behalf-of session belongs to the user, so resolve uses their reach and their personal values, and the
- // caller is kept as the acting identity.
+ // An on-behalf-of session belongs to the user, so resolve uses their personal values, and the caller is kept as
+ // the acting identity, whose reach resolve intersects with the user's.
const owner = onBehalfOfUser
? {
userId: onBehalfOfUser.user.id,
diff --git a/backend/src/ee/services/agent-vault/AGENTS.md b/backend/src/ee/services/agent-vault/AGENTS.md
index 12656f7d13..5d631878d4 100644
--- a/backend/src/ee/services/agent-vault/AGENTS.md
+++ b/backend/src/ee/services/agent-vault/AGENTS.md
@@ -117,8 +117,9 @@ and `packages/agentvault/` in the CLI repo. Frontend: `frontend/src/pages/agent-
## Sessions on behalf of users
A machine identity with a **delegation** can mint a session on behalf of a user (`onBehalfOf` on mint). The session
-belongs to the user: `userId` is the user, so resolve uses the user's role, reach and personal values without a branch
-of its own. The identity is kept as `actingIdentityId` and `actingIdentityName`. A delegation is one
+belongs to the user: `userId` is the user, so resolve uses the user's role and personal values without a branch of its
+own. The identity is kept as `actingIdentityId` and `actingIdentityName`, and its reach narrows the user's. A delegation
+is one
`agent_vault_delegations` row per identity, with a scope of `all-members` or `selected`, plus
`agent_vault_delegation_subjects` rows naming users and groups.
@@ -129,14 +130,16 @@ of its own. The identity is kept as `actingIdentityId` and `actingIdentityName`.
same lesson as `actorType`. A session with the name and no id is orphaned: it reads as revoked
(`isOrphanedSession`) and resolve refuses it.
- **Resolve re-checks the acting identity every time**: active in the org, a live Agent Vault role, and a delegation
- that still covers the user (`$assertActingIdentityStillDelegated`). Any miss is a 401, like an actor removed from
+ that still covers the user (`$getActingIdentityReach`). Any miss is a 401, like an actor removed from
Agent Vault. Removing a delegation revokes nothing, so its sessions work again if it comes back; revoking is what
ends one. Settled the same way as removal from Agent Vault.
-- **Reach is the user's alone, never intersected with the identity's.** Intersection is a possible later option,
- not a bug. An admin user reaches every bundle, so an all-members delegation covers every bundle too.
-- **Mint checks the delegation before it looks the user up**, so an identity no admin delegated learns nothing about
- who is in the org, and an unknown user gets the same message as an uncovered one. Only a machine identity may send
- `onBehalfOf`. The user must be an active, accepted org member, as resolve requires.
+- **Reach is the intersection of the user's and the identity's** (`intersectAccessBundleIds`): a bundle needs both,
+ through the admin role or a grant, at mint and on every resolve. Settled with the product owner. The identity losing
+ a grant drops the bundle's services like a user's lost grant, with no 401.
+- **Mint checks the delegation, then the identity's own bundles, then the user**, so an identity learns nothing about
+ who is in the org until an admin has delegated it and granted it the bundle, and an unknown user gets the same message
+ as an uncovered one. Only a machine identity may send `onBehalfOf`. The user must be an active, accepted org member,
+ as resolve requires.
- **Mint runs `getProjectPermission` for the user, then once more for the caller.** The permission service leaves
the last actor it ran for in the request context, where the audit log reads the caller's permission metadata. The
second call is memoized, so it costs no query; dropping it attributes the user's metadata to the identity.
diff --git a/backend/src/ee/services/agent-vault/agent-vault-permission.ts b/backend/src/ee/services/agent-vault/agent-vault-permission.ts
index 228b25eac6..ad212f8e84 100644
--- a/backend/src/ee/services/agent-vault/agent-vault-permission.ts
+++ b/backend/src/ee/services/agent-vault/agent-vault-permission.ts
@@ -56,6 +56,14 @@ export const findReachableAccessBundleIds = async (
return [...new Set(reachable.map((row) => row.scopeResourceId!))];
};
+// null reaches every bundle, so intersecting with it returns the other side unchanged.
+export const intersectAccessBundleIds = (a: string[] | null, b: string[] | null): string[] | null => {
+ if (a === null) return b;
+ if (b === null) return a;
+ const inB = new Set(b);
+ return a.filter((id) => inB.has(id));
+};
+
const $loadAgentVaultPermission = async (
{ permissionService }: { permissionService: TPermissionDep },
{ projectId, ctx }: { projectId: string; ctx: TGenericPermission }
diff --git a/backend/src/lib/api-docs/constants.ts b/backend/src/lib/api-docs/constants.ts
index 6f385a1d07..70b0c0c699 100644
--- a/backend/src/lib/api-docs/constants.ts
+++ b/backend/src/lib/api-docs/constants.ts
@@ -4730,7 +4730,7 @@ export const AGENT_VAULT = {
accessBundles: "The access bundle this session carries, by name. A list that accepts exactly one name.",
ttl: "How long the session lasts: a duration such as 30m, 8h or 7d (at least 1m), or never. Defaults to 7d. A session started on behalf of a user defaults to 1h and lasts at most 24h, so never isn't allowed for it.",
onBehalfOf:
- "Start the session on behalf of a user instead of yourself. Only a machine identity whose delegation covers the user can do this. The session then reaches the access bundles the user reaches and uses the user's personal values. Name the user by userId or by userEmail.",
+ "Start the session on behalf of a user instead of yourself. Only a machine identity whose delegation covers the user can do this. The session can use only an access bundle that both the user and the machine identity can use, and it uses the user's personal values. Name the user by userId or by userEmail.",
onBehalfOfUserId: "The ID of the user to start the session on behalf of.",
onBehalfOfUserEmail: "The email address of the user to start the session on behalf of.",
token: "The session token. Returned once, at mint, and never again.",
diff --git a/docs/documentation/platform/agent-vault/sessions-api.mdx b/docs/documentation/platform/agent-vault/sessions-api.mdx
index cf10fde884..8d0f108869 100644
--- a/docs/documentation/platform/agent-vault/sessions-api.mdx
+++ b/docs/documentation/platform/agent-vault/sessions-api.mdx
@@ -59,7 +59,7 @@ curl -X POST https://app.infisical.com/api/v1/agent-vault/sessions \
- `ttl` accepts a duration of at least one minute, such as `30m`, `8h`, or `7d`, or `never`, and defaults to `7d` (see [Choose how long a session lasts](#choose-how-long-a-session-lasts) to pick a value)
<Tip>
- If your code runs agents for other people, as a chat bot does, the machine identity can create each session [on behalf of the person who asked](/documentation/platform/agent-vault/sessions-on-behalf-of-users), so the session gets that person's access bundles and personal values.
+ If your code runs agents for other people, as a chat bot does, the machine identity can create each session [on behalf of the person who asked](/documentation/platform/agent-vault/sessions-on-behalf-of-users), so the session uses that person's personal values and gets no more access than that person.
</Tip>
The response includes the session's ID, the session token, and when the session expires:
diff --git a/docs/documentation/platform/agent-vault/sessions-on-behalf-of-users.mdx b/docs/documentation/platform/agent-vault/sessions-on-behalf-of-users.mdx
index e2fcc323b2..4b3f78f35a 100644
--- a/docs/documentation/platform/agent-vault/sessions-on-behalf-of-users.mdx
+++ b/docs/documentation/platform/agent-vault/sessions-on-behalf-of-users.mdx
@@ -1,11 +1,11 @@
---
title: "Sessions on behalf of users"
-description: "Let a machine identity, such as a chat bot or a task runner, create sessions that use a user's own access bundles and personal values."
+description: "Let a machine identity, such as a chat bot or a task runner, create sessions on behalf of users, with each user's own personal values."
---
-A delegation lets a [machine identity](/documentation/platform/identities/machine-identities) create [sessions](/documentation/platform/agent-vault/sessions) on behalf of users in Agent Vault. A session created on behalf of a user belongs to that user, so it reaches only the [access bundles](/documentation/platform/agent-vault/access-bundles) granted to the user, and the proxy uses the user's own [personal values](/documentation/platform/agent-vault/services#member-provided-values).
+A delegation lets a [machine identity](/documentation/platform/identities/machine-identities) create [sessions](/documentation/platform/agent-vault/sessions) on behalf of users in Agent Vault. A session created on behalf of a user belongs to that user, so the proxy uses the user's own [personal values](/documentation/platform/agent-vault/services#member-provided-values). The session can use an [access bundle](/documentation/platform/agent-vault/access-bundles) only if both the user and the machine identity can use the bundle.
-Use a delegation when one service starts agents for many people, such as a chat bot that runs an agent for each message, or a task runner that runs an agent for each ticket. Each agent then gets only the access of the person who asked for it, and uses that person's own credential wherever a service leaves part of its credential to members.
+Use a delegation when one service starts agents for many people, such as a chat bot that runs an agent for each message, or a task runner that runs an agent for each ticket. Each agent then gets no more access than the person who asked for it, and uses that person's own credential wherever a service leaves part of its credential to members.
```mermaid
sequenceDiagram
@@ -27,6 +27,7 @@ sequenceDiagram
- The **Admin** role in [Agent Vault](/documentation/platform/agent-vault/access-control#product-membership), or an Agent Vault admin who can [set up the delegation](#set-up-a-delegation) for you
- A machine identity that's a member of Agent Vault and can log in with [Universal Auth](/documentation/platform/identities/universal-auth), as [Step 1 of Create sessions with the API](/documentation/platform/agent-vault/sessions-api#step-1-set-up-a-machine-identity) describes
+- A [grant](/documentation/platform/agent-vault/access-bundles#manage-access-to-access-bundles) for the machine identity on each access bundle its sessions use
- Users who are members of Agent Vault and have a grant on the access bundles their agents use
## Set up a delegation
@@ -81,17 +82,18 @@ curl -X POST https://app.infisical.com/api/v1/agent-vault/sessions \
```
- In `onBehalfOf`, set either `userEmail` or `userId`, not both
-- In `accessBundles`, name a bundle that's granted to the user, not to the machine identity
+- In `accessBundles`, name a bundle that both the user and the machine identity can use
- `ttl` defaults to `1h` and can be at most `24h`, so `never` isn't allowed
Start the agent with the session token from the response, and revoke the session when the agent finishes, as [Step 4 of Create sessions with the API](/documentation/platform/agent-vault/sessions-api#step-4-start-the-agent-with-the-session-token) describes.
## What the session can reach
-A session created on behalf of a user gets the user's access, not the machine identity's:
+A session created on behalf of a user can use an access bundle only if both the user and the machine identity can use the bundle, and the session uses the user's personal values:
-- The session can use only the access bundles granted to the user, directly or through a group (if the user is an Agent Vault admin, every bundle)
-- The proxy uses the user's personal values, and refuses the session's requests to a service until the user [sets up their personal values](/documentation/platform/agent-vault/access-bundles#set-up-your-personal-values) for it
+- The user can use the access bundles granted to them, directly or through a group (if the user is an Agent Vault admin, every bundle)
+- The machine identity can use the access bundles granted to it, directly or through a group (if the machine identity is an Agent Vault admin, every bundle)
+- The proxy refuses the session's requests to a service until the user [sets up their personal values](/documentation/platform/agent-vault/access-bundles#set-up-your-personal-values) for it
## When the session stops working
@@ -104,7 +106,7 @@ Infisical checks the delegation again each time the proxy polls, once every [pol
If an admin sets up the delegation again, or adds the user back to it, the session works again. To end a session for good, [revoke it](/documentation/platform/agent-vault/sessions#revoke-a-session).
-Changes to the user's own access, such as losing a grant on the access bundle, affect the session the same way they affect the user's other sessions, as [Access changes](/documentation/platform/agent-vault/sessions#access-changes) describes.
+If the user or the machine identity can no longer use the access bundle, the session stops getting credentials for the bundle, as [Access changes](/documentation/platform/agent-vault/sessions#access-changes) describes.
## Track sessions created on behalf of users
@@ -124,10 +126,13 @@ When the machine identity creates the session, the audit event names the machine
<Accordion title="Creating the session fails with &quot;This machine identity isn't allowed to start sessions on behalf of users&quot;">
The machine identity has no delegation. [Set one up](#set-up-a-delegation), or ask an Agent Vault admin to.
</Accordion>
+ <Accordion title="Creating the session fails with &quot;No access bundle named ... is granted to this machine identity&quot;">
+ The access bundle isn't granted to the machine identity, or no access bundle has that name. [Grant the bundle](/documentation/platform/agent-vault/access-bundles#manage-access-to-access-bundles) to the machine identity, or name a bundle the machine identity already has.
+ </Accordion>
<Accordion title="Creating the session fails with &quot;This machine identity can't start sessions on behalf of ...&quot;">
The delegation doesn't cover the user, or no active member of your organization has that email or ID. Check the email or ID you sent, then check the users and groups in the machine identity's delegation.
</Accordion>
- <Accordion title="Creating the session fails with &quot;No access bundle named ... is granted to ...&quot;">
+ <Accordion title="Creating the session fails with &quot;No access bundle named ... is granted to '...'&quot;">
The access bundle isn't granted to the user. [Grant the bundle](/documentation/platform/agent-vault/access-bundles#manage-access-to-access-bundles) to the user, or name a bundle the user already has.
</Accordion>
<Accordion title="Creating the session fails with &quot;A session started on behalf of a user lasts at most 24h&quot;">
diff --git a/docs/documentation/platform/agent-vault/sessions.mdx b/docs/documentation/platform/agent-vault/sessions.mdx
index 72874bc4fc..a927af15c0 100644
--- a/docs/documentation/platform/agent-vault/sessions.mdx
+++ b/docs/documentation/platform/agent-vault/sessions.mdx
@@ -12,7 +12,7 @@ Every session is scoped to one access bundle and expires on a schedule you set.
Anyone granted at least one access bundle can create a session. Admins can create one with any access bundle.
<Tip>
- If you want to create sessions programmatically, you can have a [machine identity](/documentation/platform/identities/machine-identities) create a new session for each run using [the CLI](/documentation/platform/agent-vault/sessions-cli) or [the API](/documentation/platform/agent-vault/sessions-api). A machine identity can also create sessions [on behalf of users](/documentation/platform/agent-vault/sessions-on-behalf-of-users), so that each agent gets the access and personal values of the person it runs for.
+ If you want to create sessions programmatically, you can have a [machine identity](/documentation/platform/identities/machine-identities) create a new session for each run using [the CLI](/documentation/platform/agent-vault/sessions-cli) or [the API](/documentation/platform/agent-vault/sessions-api). A machine identity can also create sessions [on behalf of users](/documentation/platform/agent-vault/sessions-on-behalf-of-users), so that each agent uses the personal values of the person it runs for and gets no more access than that person.
</Tip>
<Tabs>
diff --git a/frontend/src/components/agent-vault/IdentityDelegationSection.tsx b/frontend/src/components/agent-vault/IdentityDelegationSection.tsx
index 5c505b2873..8d740c4118 100644
--- a/frontend/src/components/agent-vault/IdentityDelegationSection.tsx
+++ b/frontend/src/components/agent-vault/IdentityDelegationSection.tsx
@@ -238,7 +238,8 @@ export const IdentityDelegationSection = ({ machineIdentityId, machineIdentityNa
</CardTitle>
<CardDescription>
The users this machine identity can start sessions on behalf of. Each session uses that
- user&apos;s access bundles and personal values.
+ user&apos;s personal values, and only access bundles that both the user and this machine
+ identity can use.
</CardDescription>
{!isPending && (
<CardAction>