Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
feat: add support for machine identity approvals
Sheen Capadnganbcc0b94643fe
diff --git a/backend/src/ee/routes/v1/pam-routers/pam-access-request-router.ts b/backend/src/ee/routes/v1/pam-routers/pam-access-request-router.tsindex 9acdc3f619..700ba861d5 100644--- a/backend/src/ee/routes/v1/pam-routers/pam-access-request-router.ts+++ b/backend/src/ee/routes/v1/pam-routers/pam-access-request-router.ts@@ -39,7 +39,7 @@ export const registerPamAccessRequestRouter = async (server: FastifyZodProvider)})}},- onRequest: verifyAuth([AuthMode.JWT]),+ onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),handler: async (req) => {const result = await server.services.pamAccessRequest.createRequest({accountId: req.body.accountId,diff --git a/backend/src/ee/services/pam-access-request/pam-access-request-service.ts b/backend/src/ee/services/pam-access-request/pam-access-request-service.tsindex afbd96e14d..32a205b77e 100644--- a/backend/src/ee/services/pam-access-request/pam-access-request-service.ts+++ b/backend/src/ee/services/pam-access-request/pam-access-request-service.ts@@ -42,6 +42,8 @@ import {createApprovalRequestWithSteps,notifyApproversForStep} from "@app/services/approval-policy/approval-request-fns";+import { ActorType } from "@app/services/auth/auth-type";+import { TIdentityDALFactory } from "@app/services/identity/identity-dal";import { TKmsServiceFactory } from "@app/services/kms/kms-service";import { TMembershipDALFactory } from "@app/services/membership/membership-dal";import { TMembershipRoleDALFactory } from "@app/services/membership/membership-role-dal";@@ -70,6 +72,7 @@ import { TPamSessionDALFactory } from "../pam-session/pam-session-dal";import { sendPamSessionCancellationSignal } from "../pam-session/pam-session-fns";import { getSlackSendTargets, parseNotificationChannels, parseNotificationEvents } from "./pam-access-request-fns";import {+ TAccessRequestActor,TCheckGrantDTO,TCreateAccessRequestDTO,TGetAccessRequestCountDTO,@@ -129,6 +132,7 @@ type TPamAccessRequestServiceFactoryDep = {groupDAL: Pick<TGroupDALFactory, "find">;userGroupMembershipDAL: Pick<TUserGroupMembershipDALFactory, "find" | "findGroupMembershipsByUserIdInOrg">;userDAL: Pick<TUserDALFactory, "findById" | "find">;+ identityDAL: Pick<TIdentityDALFactory, "findById">;pamFolderNotificationConfigDAL: Pick<TPamFolderNotificationConfigDALFactory,"findByFolderIdWithIntegration" | "delete" | "insertMany" | "transaction"@@ -163,6 +167,7 @@ export const pamAccessRequestServiceFactory = ({groupDAL,userGroupMembershipDAL,userDAL,+ identityDAL,pamFolderNotificationConfigDAL,workflowIntegrationDAL,slackIntegrationDAL,@@ -178,6 +183,26 @@ export const pamAccessRequestServiceFactory = ({return policy ?? null;};+ // Requests and grants attribute their actor to exactly one column: a user or a machine identity.+ // These build the matching filter so every lookup stays scoped to the calling actor's own rows.+ const actorRequestFilter = ({ actorId, actor }: TAccessRequestActor) =>+ actor === ActorType.IDENTITY ? { machineIdentityId: actorId } : { requesterId: actorId };++ const actorGrantFilter = ({ actorId, actor }: TAccessRequestActor) =>+ actor === ActorType.IDENTITY ? { granteeMachineIdentityId: actorId } : { granteeUserId: actorId };++ // Machine identities have no email; their name is the only human-readable attribution available.+ const resolveRequesterDisplay = async ({ actorId, actor }: TAccessRequestActor) => {+ if (actor === ActorType.IDENTITY) {+ const identity = await identityDAL.findById(actorId);+ return { name: identity?.name || actorId, email: "" };+ }+ const user = await userDAL.findById(actorId);+ if (!user) return { name: actorId, email: "" };+ const fullName = [user.firstName, user.lastName].filter((part): part is string => Boolean(part?.trim())).join(" ");+ return { name: fullName || user.username || user.email || actorId, email: user.email ?? "" };+ };+const getNotificationConfigs = async (folderId: string) => {const configs = await pamFolderNotificationConfigDAL.findByFolderIdWithIntegration(folderId);return configs.map((config) => ({@@ -657,7 +682,7 @@ export const pamAccessRequestServiceFactory = ({}const existingPending = await approvalRequestDAL.find({- requesterId: ctx.actorId,+ ...actorRequestFilter(ctx),type: ApprovalPolicyType.PamAccess,status: ApprovalRequestStatus.Pending,projectId@@ -690,8 +715,8 @@ export const pamAccessRequestServiceFactory = ({approvers: s.approvers}));- const user = await userDAL.findById(ctx.actorId);- const requesterName = [user.firstName, user.lastName].filter(Boolean).join(" ") || user.username || user.email;+ const isIdentityActor = ctx.actor === ActorType.IDENTITY;+ const { name: requesterName, email: requesterEmail } = await resolveRequesterDisplay(ctx);const requestData = {accountId: account.id,@@ -709,9 +734,10 @@ export const pamAccessRequestServiceFactory = ({policySteps: stepsForRequest,requestData,justification: trimmedReason,- requesterUserId: ctx.actorId,- requesterName: requesterName || "Unknown",- requesterEmail: user.email || "",+ requesterUserId: ctx.actor === ActorType.USER ? ctx.actorId : null,+ machineIdentityId: ctx.actor === ActorType.IDENTITY ? ctx.actorId : null,+ requesterName,+ requesterEmail,scopeType: ApprovalPolicyScope.PamFolder,scopeId: account.folderId},@@ -755,8 +781,9 @@ export const pamAccessRequestServiceFactory = ({subjectLine: "PAM Access Request",template: SmtpTemplates.AccessPamRequest,substitutions: {- requesterFullName: requesterName || "Unknown",- requesterEmail: user.email ?? "",+ requesterFullName: requesterName,+ // Machine identities have no email; the template renders the label alone+ requesterEmail: isIdentityActor ? "Machine Identity" : requesterEmail,accountName: account.name,folderName: account.folderName ?? undefined,accessDuration: formatDuration(duration),@@ -777,8 +804,8 @@ export const pamAccessRequestServiceFactory = ({notification: {type: TriggerFeature.PAM_ACCESS_REQUESTED,payload: {- requesterFullName: requesterName || "Unknown",- requesterEmail: user.email ?? "",+ requesterFullName: requesterName,+ requesterEmail: isIdentityActor ? "Machine Identity" : requesterEmail,accountName: account.name,folderName: account.folderName ?? "",accessDuration: formatDuration(duration),@@ -1165,7 +1192,9 @@ export const pamAccessRequestServiceFactory = ({{projectId: request.projectId,requestId: request.id,+ // The request carries exactly one actor column; mirror it onto the grantgranteeUserId: request.requesterId,+ granteeMachineIdentityId: request.machineIdentityId,status: ApprovalRequestGrantStatus.Active,type: ApprovalPolicyType.PamAccess,attributes: {@@ -1254,7 +1283,11 @@ export const pamAccessRequestServiceFactory = ({const liveSessions = await pamSessionDAL.find({accountId: attrs.accountId,- userId: grant.granteeUserId ?? null,+ // Sessions mirror the grant's actor column: machine identity sessions carry identityId+ // with a null userId, so filter on whichever the grant was issued to.+ ...(grant.granteeMachineIdentityId+ ? { identityId: grant.granteeMachineIdentityId }+ : { userId: grant.granteeUserId ?? null }),$in: { status: [PamSessionStatus.Active, PamSessionStatus.Starting] }},{ tx }@@ -1394,13 +1427,13 @@ export const pamAccessRequestServiceFactory = ({};const checkGrant = async ({- userId,accountId,accountFolderId,- projectId+ projectId,+ ...actorCtx}: TCheckGrantDTO): Promise<TApprovalRequestGrants | null> => {const grants = await approvalRequestGrantsDAL.find({- granteeUserId: userId,+ ...actorGrantFilter(actorCtx),type: ApprovalPolicyType.PamAccess,status: ApprovalRequestGrantStatus.Active,projectId@@ -1421,7 +1454,7 @@ export const pamAccessRequestServiceFactory = ({};const getAccessStatusBatch = async (- userId: string,+ actorCtx: TAccessRequestActor,accountIds: string[],projectId: string): Promise<Map<string, { accessStatus: PamAccessStatus; grantExpiresAt: Date | null }>> => {@@ -1431,7 +1464,7 @@ export const pamAccessRequestServiceFactory = ({const now = new Date();const activeGrants = await approvalRequestGrantsDAL.find({- granteeUserId: userId,+ ...actorGrantFilter(actorCtx),type: ApprovalPolicyType.PamAccess,status: ApprovalRequestGrantStatus.Active,projectId@@ -1449,7 +1482,7 @@ export const pamAccessRequestServiceFactory = ({}const pendingRequests = await approvalRequestDAL.find({- requesterId: userId,+ ...actorRequestFilter(actorCtx),type: ApprovalPolicyType.PamAccess,status: ApprovalRequestStatus.Pending,projectId@@ -1510,7 +1543,7 @@ export const pamAccessRequestServiceFactory = ({}));const pendingRequests = await approvalRequestDAL.find({- requesterId: ctx.actorId,+ ...actorRequestFilter(ctx),type: ApprovalPolicyType.PamAccess,status: ApprovalRequestStatus.Pending,projectIddiff --git a/backend/src/ee/services/pam-access-request/pam-access-request-types.ts b/backend/src/ee/services/pam-access-request/pam-access-request-types.tsindex 5a4b8ffc3e..ed8ba230cf 100644--- a/backend/src/ee/services/pam-access-request/pam-access-request-types.ts+++ b/backend/src/ee/services/pam-access-request/pam-access-request-types.ts@@ -1,4 +1,5 @@import { ApprovalRequestApprovalDecision, ApproverType } from "@app/services/approval-policy/approval-policy-enums";+import { ActorType } from "@app/services/auth/auth-type";import { PamNotificationEvent } from "../pam/pam-enums";import { TActorContext } from "../pam/pam-permission";@@ -61,12 +62,17 @@ export type TRevokeAccessRequestDTO = {projectId: string;} & TActorContext;+// Requests and grants key their actor by user OR machine identity, never both+export type TAccessRequestActor = {+ actorId: string;+ actor: ActorType;+};+export type TCheckGrantDTO = {- userId: string;accountId: string;accountFolderId?: string | null;projectId: string;-};+} & TAccessRequestActor;export type TPamAccessRequestData = {accountId: string;diff --git a/backend/src/ee/services/pam-account/pam-account-service.ts b/backend/src/ee/services/pam-account/pam-account-service.tsindex 48cd2c9867..02eb8494fe 100644--- a/backend/src/ee/services/pam-account/pam-account-service.ts+++ b/backend/src/ee/services/pam-account/pam-account-service.ts@@ -218,7 +218,11 @@ export const pamAccountServiceFactory = (deps: TPamAccountServiceFactoryDep) =>];const [accessStatusMap, foldersWithApprovalPolicy, permissionsByAccountId] = await Promise.all([- deps.pamAccessRequestService.getAccessStatusBatch(ctx.actorId, accountIdsRequiringApproval, projectId),+ deps.pamAccessRequestService.getAccessStatusBatch(+ { actorId: ctx.actorId, actor: ctx.actor },+ accountIdsRequiringApproval,+ projectId+ ),deps.pamAccessRequestService.getFolderPolicyConfigured(folderIdsRequiringApproval),// Resolve every account's effective permissions in one membership fetchgetAccountPermissionRulesMap(@@ -857,7 +861,11 @@ export const pamAccountServiceFactory = (deps: TPamAccountServiceFactoryDep) =>...new Set(accountsRequiringApproval.map((a) => a.folderId).filter(Boolean) as string[])];const [accessStatusMap, foldersWithApprovalPolicy] = await Promise.all([- deps.pamAccessRequestService.getAccessStatusBatch(ctx.actorId, accountIdsRequiringApproval, projectId),+ deps.pamAccessRequestService.getAccessStatusBatch(+ { actorId: ctx.actorId, actor: ctx.actor },+ accountIdsRequiringApproval,+ projectId+ ),deps.pamAccessRequestService.getFolderPolicyConfigured(folderIdsRequiringApproval)]);diff --git a/backend/src/ee/services/pam-session/pam-session-service.ts b/backend/src/ee/services/pam-session/pam-session-service.tsindex 6d5b3cc453..8db99e1b7b 100644--- a/backend/src/ee/services/pam-session/pam-session-service.ts+++ b/backend/src/ee/services/pam-session/pam-session-service.ts@@ -475,14 +475,9 @@ export const pamSessionServiceFactory = ({// guided into requesting access (where the request reason is collected) rather than being// blocked on a launch reason for a session they cannot start yet.if (requiresApproval) {- if (!isUserActor) {- throw new ForbiddenRequestError({- message:- "This account is gated behind access-request approval, which machine identities cannot request. Grant the identity access to a non-gated account instead."- });- }const grant = await pamAccessRequestService.checkGrant({- userId: actor.actorId,+ actorId: actor.actorId,+ actor: actor.actor,accountId: account.id,accountFolderId: account.folderId,projectId@@ -491,7 +486,11 @@ export const pamSessionServiceFactory = ({// Distinguish "no request yet" from "request awaiting review" and from "folder has no// approvers", so the CLI can guide the user instead of prompting into a 400const [statusMap, foldersWithApprovalPolicy] = await Promise.all([- pamAccessRequestService.getAccessStatusBatch(actor.actorId, [account.id], projectId),+ pamAccessRequestService.getAccessStatusBatch(+ { actorId: actor.actorId, actor: actor.actor },+ [account.id],+ projectId+ ),pamAccessRequestService.getFolderPolicyConfigured(account.folderId ? [account.folderId] : [])]);throw new ForbiddenRequestError({diff --git a/backend/src/ee/services/pam-web-access/pam-web-access-service.ts b/backend/src/ee/services/pam-web-access/pam-web-access-service.tsindex 677d03492b..924ee76589 100644--- a/backend/src/ee/services/pam-web-access/pam-web-access-service.ts+++ b/backend/src/ee/services/pam-web-access/pam-web-access-service.ts@@ -193,7 +193,9 @@ export const pamWebAccessServiceFactory = ({let grantRemainingMs: number | null = null;if (requiresApproval) {const grant = await pamAccessRequestService.checkGrant({- userId: actor.id,+ // Web access is JWT-only, so the actor is always a user+ actorId: actor.id,+ actor: ActorType.USER,accountId,accountFolderId: account.folderId,projectId@@ -430,7 +432,8 @@ export const pamWebAccessServiceFactory = ({let sessionDurationCapMs = policyDurationMs || DEFAULT_WEB_SESSION_DURATION_MS;if (requiresApproval) {const grant = await pamAccessRequestService.checkGrant({- userId,+ actorId: userId,+ actor: ActorType.USER,accountId,accountFolderId: account.folderId,projectIddiff --git a/backend/src/ee/services/pam/CLAUDE.md b/backend/src/ee/services/pam/CLAUDE.mdindex 40684ed69c..cf23624443 100644--- a/backend/src/ee/services/pam/CLAUDE.md+++ b/backend/src/ee/services/pam/CLAUDE.md@@ -12,19 +12,19 @@ table) and let the code carry the detail.All PAM services live under `backend/src/ee/services/pam-*/`:-| Directory | Purpose |-|---|---|-| `pam/` | Shared enums, permission helpers (`pam-permission.ts`), validators, policy registry (`pam-policies.ts`), and this file |-| `pam-folder/` | Folder CRUD + folder-level permission checks |-| `pam-account/` | Account CRUD, credential encryption, gateway attachment, SSH CA, account-type config |-| `pam-account-template/` | Account templates (type + policies + settings) |-| `pam-account-rotation/` | Scheduled + on-demand SQL credential rotation |-| `pam-session/` + `pam-web-access/` | Session lifecycle and WebSocket session handlers (Postgres/SSH/RDP) |-| `pam-session-recording/` | Recording chunk storage/retrieval + storage providers |-| `pam-membership/` | Product + resource membership management |-| `pam-project/` | PAM project bootstrap + resolver |-| `pam-access-request/` | Folder approval config, access-request lifecycle, chat notifications |-| `pam-discovery/` | Discovery sources → staged accounts for import |+| Directory | Purpose |+| ---------------------------------- | ---------------------------------------------------------------------------------------------------------------------- |+| `pam/` | Shared enums, permission helpers (`pam-permission.ts`), validators, policy registry (`pam-policies.ts`), and this file |+| `pam-folder/` | Folder CRUD + folder-level permission checks |+| `pam-account/` | Account CRUD, credential encryption, gateway attachment, SSH CA, account-type config |+| `pam-account-template/` | Account templates (type + policies + settings) |+| `pam-account-rotation/` | Scheduled + on-demand SQL credential rotation |+| `pam-session/` + `pam-web-access/` | Session lifecycle and WebSocket session handlers (Postgres/SSH/RDP) |+| `pam-session-recording/` | Recording chunk storage/retrieval + storage providers |+| `pam-membership/` | Product + resource membership management |+| `pam-project/` | PAM project bootstrap + resolver |+| `pam-access-request/` | Folder approval config, access-request lifecycle, chat notifications |+| `pam-discovery/` | Discovery sources → staged accounts for import |Routes: `backend/src/ee/routes/v1/pam-routers/`. DI wiring: `backend/src/server/routes/index.ts` (narrownew deps with `Pick<>`).@@ -38,15 +38,22 @@ use them instead of re-implementing. Every list/mutation endpoint checks an **acmembership. There is **no org-admin fallback**: permission needs project-scoped membership.Gotchas:+- **Audit logs** are served through the shared org audit-log endpoint but scoped by the PAM model(`pam/pam-audit-log-fns.ts`), not the generic project `AuditLogs` permission. Any new account- orfolder-scoped event **must** put `accountId`/`folderId` in its `eventMetadata`, or it lands in theproduct-level bucket and is hidden from resource viewers.- Gated accounts (`requiresApproval`) require `LaunchSessions` **and** a valid approval grant, enforced inboth the session and web-access services.-- PAM endpoints accept JWT + identity tokens, including CLI session launch (`POST /pam/sessions/access`);- web access stays JWT-only, and MFA/approval-gated accounts reject machine actors. Sessions store- `identityId` (not `userId`) for machine actors. Gateway-facing endpoints use `AuthMode.GATEWAY_ACCESS_TOKEN`.+- PAM endpoints accept JWT + identity tokens, including CLI session launch (`POST /pam/sessions/access`)+ and raising access requests (`POST /pam/access-requests`); web access stays JWT-only, as does+ reviewing/revoking (identities are never approvers). MFA-gated accounts still reject machine actors,+ since no machine can satisfy an OTP. Gateway-facing endpoints use `AuthMode.GATEWAY_ACCESS_TOKEN`.+- **Actor columns come in pairs, and every lookup must filter the right one.** Sessions use+ `userId`/`identityId`, approval requests `requesterId`/`machineIdentityId`, grants+ `granteeUserId`/`granteeMachineIdentityId` — exactly one is set per row. `pam-access-request-service.ts`+ centralizes this in `actorRequestFilter` / `actorGrantFilter`; use them instead of hardcoding a column,+ or a machine identity silently reads another actor's rows (or none at all).## PAM Project (consolidated + lazy)diff --git a/backend/src/server/routes/index.ts b/backend/src/server/routes/index.tsindex e23b544dcf..42ba167c9c 100644--- a/backend/src/server/routes/index.ts+++ b/backend/src/server/routes/index.ts@@ -1968,6 +1968,7 @@ export const registerRoutes = async (groupDAL,userGroupMembershipDAL,userDAL,+ identityDAL,pamFolderNotificationConfigDAL,workflowIntegrationDAL,slackIntegrationDAL,diff --git a/frontend/src/hooks/api/pam/types/index.ts b/frontend/src/hooks/api/pam/types/index.tsindex d8be4da56e..2f873fdc7b 100644--- a/frontend/src/hooks/api/pam/types/index.ts+++ b/frontend/src/hooks/api/pam/types/index.ts@@ -650,6 +650,8 @@ export type TPamAccessRequest = {projectId: string;policyId: string;requesterId: string | null;+ // Set instead of requesterId when a machine identity raised the request+ machineIdentityId?: string | null;requesterName: string;requesterEmail: string;type: string;diff --git a/frontend/src/pages/pam/PamApprovalRequestsPage/PamApprovalRequestsPage.tsx b/frontend/src/pages/pam/PamApprovalRequestsPage/PamApprovalRequestsPage.tsxindex 008e819ff1..7dd0df69e4 100644--- a/frontend/src/pages/pam/PamApprovalRequestsPage/PamApprovalRequestsPage.tsx+++ b/frontend/src/pages/pam/PamApprovalRequestsPage/PamApprovalRequestsPage.tsx@@ -60,7 +60,9 @@ const RequestRow = ({<TableCell className="h-[50px]"><div className="flex flex-col"><span className="text-sm">{request.requesterName}</span>- <span className="text-xs text-muted">{request.requesterEmail}</span>+ <span className="text-xs text-muted">+ {request.machineIdentityId ? "Machine Identity" : request.requesterEmail}+ </span></div></TableCell><TableCell className="text-sm">diff --git a/frontend/src/pages/pam/PamApprovalRequestsPage/components/ApprovalRequestDetailSheet.tsx b/frontend/src/pages/pam/PamApprovalRequestsPage/components/ApprovalRequestDetailSheet.tsxindex 6193cf691c..6df8970ca4 100644--- a/frontend/src/pages/pam/PamApprovalRequestsPage/components/ApprovalRequestDetailSheet.tsx+++ b/frontend/src/pages/pam/PamApprovalRequestsPage/components/ApprovalRequestDetailSheet.tsx@@ -117,7 +117,10 @@ export const ApprovalRequestDetailSheet = ({ request, isOpen, onOpenChange }: PrtypeBadge={status.label}metadata={[{ label: "Requester", value: request?.requesterName ?? "-" },- { label: "Email", value: request?.requesterEmail ?? "-" },+ // Machine identities have no email; label the actor kind instead+ request?.machineIdentityId+ ? { label: "Actor", value: "Machine Identity" }+ : { label: "Email", value: request?.requesterEmail ?? "-" },{ label: "Folder", value: request?.folderName ?? "-" },...(request?.host ? [{ label: "Host", value: request.host }] : []),{