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
Merge origin/main into bernie/pam-385-implement-heartbeat-feature-to-validate-stored-credentials
bernie-ga85c18977ffa
diff --cc backend/src/ee/services/pam-account/pam-account-service.tsindex 75956004f6,4ed63888ed..f428eb359d--- a/backend/src/ee/services/pam-account/pam-account-service.ts+++ b/backend/src/ee/services/pam-account/pam-account-service.ts@@@ -24,13 -29,8 +29,15 @@@ import { TOrgDALFactory } from "@app/seimport { TUserDALFactory } from "@app/services/user/user-dal";import { testConnectionWithGateway } from "../gateway-v2/gateway-v2-fns";-import { PamAccessStatus, PamAccessType, PamAccountType, PamProductRole, PamSessionStatus } from "../pam/pam-enums";+import {+ PamAccessStatus,++ PamAccessType,+ PamAccountType,+ PamHeartbeatStatus,+ PamProductRole,+ PamSessionStatus+} from "../pam/pam-enums";+ import { enforceMfa } from "../pam/pam-mfa";import {checkAccountAccess,checkFolderPermission,@@@ -278,9 -307,8 +318,10 @@@ export const pamAccountServiceFactoryisAccessible: isAccessible && accessibilityIssues.length === 0,accessibilityIssues,isStale: a.isStale,+ heartbeatStatus: (a.heartbeatStatus as PamHeartbeatStatus | null) ?? null,+ heartbeatEnabled: Boolean(a.heartbeatEnabled),requiresApproval,+ supportsCredentialReveal: revealableById.get(a.id) ?? false,requireReason,accessStatus: requiresApproval ? (statusEntry?.accessStatus ?? PamAccessStatus.None) : PamAccessStatus.None,grantExpiresAt: statusEntry?.grantExpiresAt ?? null,@@@ -338,7 -369,110 +382,110 @@@};};+ const getCredentials = async ({+ accountId,+ projectId,+ actorEmail,+ reason,+ mfaSessionId,+ tokenVersionId,+ ...ctx+ }: TGetPamAccountCredentialsDTO & TActorContext) => {+ await verifyMembership(projectId, ctx);++ const account = await pamAccountDAL.findByIdWithDetails(accountId);+ if (!account || account.projectId !== projectId) {+ throw new NotFoundError({ message: `Account with ID '${accountId}' not found` });+ }++ await checkAccount(+ accountId,+ account.folderId,+ projectId,+ ResourcePermissionPamResourceActions.ViewCredentials,+ ctx+ );++ const accountType = account.accountType as PamAccountType;+ const policy = resolveAccessControls(account.templatePolicies);+ const trimmedReason = reason?.trim() || null;++ let grantExpiresAt: Date | null = null;+ if (policy.requiresApproval) {+ const grant = await deps.pamAccessRequestService.checkGrant({+ actorId: ctx.actorId,+ actor: ctx.actor,+ accountId: account.id,+ accountFolderId: account.folderId,+ projectId,+ accessType: PamAccessType.Credential+ });+ if (!grant) {+ throw new ForbiddenRequestError({+ name: "PAM_APPROVAL_REQUIRED",+ message: "Approval is required to view this account's credentials"+ });+ }++ if (grant.expiresAt) {+ if (new Date(grant.expiresAt).getTime() <= Date.now()) {+ throw new ForbiddenRequestError({+ name: "PAM_GRANT_EXPIRED",+ message: "Your approved credential access has expired"+ });+ }+ grantExpiresAt = new Date(grant.expiresAt);+ }+ }++ if (policy.requireReason && !trimmedReason) {+ throw new BadRequestError({+ name: "PAM_REASON_REQUIRED",+ message: "A reason is required to view this account's credentials"+ });+ }++ if (policy.requireMfa) {+ if (ctx.actor !== ActorType.USER) {+ throw new ForbiddenRequestError({+ message:+ "This account requires MFA verification, which machine identities cannot perform. Remove the MFA policy from the account's template to allow machine identity access."+ });+ }+ await enforceMfa(+ { mfaSessionService, orgDAL, userDAL },+ {+ userId: ctx.actorId,+ orgId: ctx.actorOrgId,+ actorEmail,+ accountId: account.id,+ mfaSessionId,+ tokenVersionId+ }+ );+ }++ const credentials = normalizeCredentialAuthMethod(+ accountType,+ await decrypt(projectId, account.encryptedCredentials)+ );+ if (!hasRevealableCredential(accountType, credentials)) {+ throw new BadRequestError({ message: noRevealableCredentialMessage(account.name) });+ }++ return {+ accountId: account.id,+ accountName: account.name,+ folderName: account.folderName,+ accountType,+ folderId: account.folderId,+ credentials,+ grantExpiresAt,+ reason: trimmedReason+ };+ };+- // throws to block create/update when the account can't reach/authenticate its target+ // Returns whether the credential itself was proven, which is false when the probe only reached the host.const assertConnectionOk = async (accountType: PamAccountType,connectionDetails: Record<string, unknown>,diff --cc frontend/src/hooks/api/pam/mutations.tsxindex f0c4b710ee,b8e8b9b4d6..b744c1b56e--- a/frontend/src/hooks/api/pam/mutations.tsx+++ b/frontend/src/hooks/api/pam/mutations.tsx@@@ -779,23 -781,19 +781,36 @@@ export const useCreatePamAccessRequest});};+export const useCheckPamAccountHeartbeat = () => {+ const queryClient = useQueryClient();+ return useMutation({+ mutationFn: async ({ accountId }: { accountId: string }) => {+ const { data } = await apiRequest.post<{ heartbeatStatus: string; message?: string }>(+ `/api/v1/pam/accounts/${accountId}/health/check`+ );+ return data;+ },+ onSettled: (_, __, { accountId }) => {+ queryClient.invalidateQueries({ queryKey: pamKeys.accountHeartbeat(accountId) });+ // The row badge reads its status from lists keyed by filters this caller doesn't know.+ queryClient.invalidateQueries({ queryKey: pamKeys.account() });+ }+ });+};++ export const usePamAccountCredentials = () => {+ return useMutation({+ meta: { handledErrorCodes: ["SESSION_MFA_REQUIRED"] },+ mutationFn: async ({ accountId, reason, mfaSessionId }: TGetPamAccountCredentialsDTO) => {+ const { data } = await apiRequest.post<TPamAccountCredentials>(+ `/api/v1/pam/accounts/${accountId}/credentials`,+ { reason, mfaSessionId }+ );+ return data;+ }+ });+ };+export const useRotatePamAccount = () => {const queryClient = useQueryClient();return useMutation({diff --cc frontend/src/hooks/api/pam/queries.tsxindex 13e3381288,52cf39bf7b..17a221618b--- a/frontend/src/hooks/api/pam/queries.tsx+++ b/frontend/src/hooks/api/pam/queries.tsx@@@ -12,9 -12,9 +12,10 @@@ import { conditionsMatcher } from "@appimport {PamAccessStatus,+ PamAccessType,PamAccountType,PamApproverType,+ PamHeartbeatStatus,PamResourcePermissionActions,PamResourcePermissionSub} from "./enums";@@@ -212,9 -210,8 +213,10 @@@ export type TPamAccountListItem =accessibilityIssues: PamAccountAccessibilityIssue[];// the latest discovery scan didn't find it. Informational only, nothing about the account is blocked.isStale: boolean;+ heartbeatStatus?: PamHeartbeatStatus | null;+ heartbeatEnabled?: boolean;requiresApproval: boolean;+ supportsCredentialReveal: boolean;requireReason: boolean;accessStatus: PamAccessStatus;grantExpiresAt: string | null;