Skip to content

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

feat(agent-vault): drop the 24h cap on sessions on behalf of users

Scott Wilson476d0b0af237
diff --git a/backend/e2e-test/routes/v1/agent-vault.spec.ts b/backend/e2e-test/routes/v1/agent-vault.spec.ts
index 18991097c7..771a811033 100644
--- a/backend/e2e-test/routes/v1/agent-vault.spec.ts
+++ b/backend/e2e-test/routes/v1/agent-vault.spec.ts
@@ -4124,7 +4124,7 @@ describe("Agent Vault V1 Router", async () => {
}
});
- test("a session on a user's behalf lasts an hour unless asked, and never more than a day", async () => {
+ test("a session on a user's behalf lasts an hour unless asked", async () => {
const projectId = await getProjectId();
const bundle = await createAccessBundle(`obo-ttl-${Date.now()}`);
const bot = await createMemberIdentity(`obo-ttl-bot-${Date.now()}`);
@@ -4138,15 +4138,13 @@ describe("Agent Vault V1 Router", async () => {
expect(byDefault.statusCode).toBe(200);
expect(hoursFromNow(byDefault.json().session.expiresAt as string)).toBeCloseTo(1, 1);
- expect((await mintFor(bot, { userId: alice.userId }, bundle.name, "24h")).statusCode).toBe(200);
- for (const ttl of ["25h", "never"]) {
- // eslint-disable-next-line no-await-in-loop
- const refused = await mintFor(bot, { userId: alice.userId }, bundle.name, ttl);
- expect(refused.statusCode).toBe(400);
- expect(refused.json().message).toBe(
- "A session started on behalf of a user lasts at most 24h. Set ttl to 24h or less."
- );
- }
+ // There's no maximum for now, never included.
+ const longer = await mintFor(bot, { userId: alice.userId }, bundle.name, "25h");
+ expect(longer.statusCode).toBe(200);
+ expect(hoursFromNow(longer.json().session.expiresAt as string)).toBeCloseTo(25, 1);
+ const unending = await mintFor(bot, { userId: alice.userId }, bundle.name, "never");
+ expect(unending.statusCode).toBe(200);
+ expect(unending.json().session.expiresAt).toBeNull();
// A session the identity starts for itself keeps the usual default.
const own = await bot.as("POST", sessionsUrl, { accessBundles: [bundle.name] });
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 24a2bf9f87..65a196a647 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
@@ -39,10 +39,9 @@ export const AGENT_VAULT_SESSION_TTL_NEVER = "never";
// Past roughly 1e8 days the expiry overflows Date and Postgres rejects the row as a 500. A century is
// far beyond any real lifetime and keeps the message honest; "never" exists for no expiry at all.
export const AGENT_VAULT_SESSION_MAX_TTL_MS = 100 * 365 * 24 * 60 * 60 * 1000;
-// The user an on-behalf-of session acts for didn't start it and may not know it exists, so it is short by default
-// and never outlives a day.
+// The user an on-behalf-of session acts for didn't start it and may not know it exists, so it is short by default.
+// It should probably have a maximum too, but for now any TTL is allowed, never included.
export const AGENT_VAULT_ON_BEHALF_OF_SESSION_DEFAULT_TTL = "1h";
-export const AGENT_VAULT_ON_BEHALF_OF_SESSION_MAX_TTL = "24h";
type TAgentVaultSessionServiceFactoryDep = {
agentVaultSessionDAL: TAgentVaultSessionDALFactory;
@@ -170,17 +169,8 @@ export const agentVaultSessionServiceFactory = ({
return { user, identifier, accessBundleIds: reachability.accessBundleIds };
};
- const resolveSessionTtl = (ttl: string | undefined, isOnBehalfOf: boolean) => {
- if (!isOnBehalfOf) return ttl ?? AGENT_VAULT_SESSION_DEFAULT_TTL;
-
- const resolved = ttl ?? AGENT_VAULT_ON_BEHALF_OF_SESSION_DEFAULT_TTL;
- if (resolved === AGENT_VAULT_SESSION_TTL_NEVER || ms(resolved) > ms(AGENT_VAULT_ON_BEHALF_OF_SESSION_MAX_TTL)) {
- throw new BadRequestError({
- message: `A session started on behalf of a user lasts at most ${AGENT_VAULT_ON_BEHALF_OF_SESSION_MAX_TTL}. Set ttl to ${AGENT_VAULT_ON_BEHALF_OF_SESSION_MAX_TTL} or less.`
- });
- }
- return resolved;
- };
+ const resolveSessionTtl = (ttl: string | undefined, isOnBehalfOf: boolean) =>
+ ttl ?? (isOnBehalfOf ? AGENT_VAULT_ON_BEHALF_OF_SESSION_DEFAULT_TTL : AGENT_VAULT_SESSION_DEFAULT_TTL);
const mintSession = async ({
projectId,
diff --git a/backend/src/ee/services/agent-vault/AGENTS.md b/backend/src/ee/services/agent-vault/AGENTS.md
index 470af97058..fa1e71e4ed 100644
--- a/backend/src/ee/services/agent-vault/AGENTS.md
+++ b/backend/src/ee/services/agent-vault/AGENTS.md
@@ -150,8 +150,9 @@ is one
second call is memoized, so it costs no query; dropping it attributes the user's metadata to the identity.
- **The user's session permission is checked with `can()`, not thrown through CASL**, since a CASL denial would be
recorded against the identity making the request.
-- **TTL defaults to 1h and caps at 24h, and `never` is refused**: the user didn't start the session and may not know
- it exists. The route's `ttl` is optional rather than defaulted because the default depends on `onBehalfOf`.
+- **TTL defaults to 1h, with no maximum for now**: the user didn't start the session and may not know it exists, so a
+ cap probably belongs here too, but any TTL is allowed for now, `never` included. The route's `ttl` is optional rather
+ than defaulted because the default depends on `onBehalfOf`.
- **The acting identity holds the session alongside the user**: the identity's list, get, revoke and session log
reads match `actingIdentityId` as well as `identityId` (`isSessionOwnedBy`, the session DAL's actor filter).
- **Coverage reads group membership without `isPending`**, the way the permission engine grants access through a
diff --git a/backend/src/lib/api-docs/constants.ts b/backend/src/lib/api-docs/constants.ts
index 0063520e97..31791f441d 100644
--- a/backend/src/lib/api-docs/constants.ts
+++ b/backend/src/lib/api-docs/constants.ts
@@ -4728,7 +4728,7 @@ export const AGENT_VAULT = {
SESSION: {
sessionId: "The ID of the session.",
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.",
+ ttl: "How long the session lasts: a duration such as 30m, 8h or 7d (at least 1m), or never. Defaults to 7d, or to 1h for a session started on behalf of a user.",
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 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, not both.",
onBehalfOfUserId: "The ID of the user to start the session on behalf of.",
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 ecfa972654..8a6d3f65c0 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
@@ -87,7 +87,7 @@ 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 both the user and the machine identity can use
-- `ttl` defaults to `1h` and can be at most `24h`, so `never` isn't allowed
+- `ttl` defaults to `1h`, instead of the `7d` default for other sessions
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.
@@ -141,9 +141,6 @@ When the machine identity creates the session, Infisical writes an audit event w
<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;">
- Set `ttl` to `24h` or less. If the agent runs longer than a day, create a new session before the old one expires, as [Choose how long a session lasts](/documentation/platform/agent-vault/sessions-api#choose-how-long-a-session-lasts) describes.
- </Accordion>
</AccordionGroup>
## Next steps