Skip to content

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

fix(pam): stop heartbeat from locking out or stranding accounts

bernie-g13019aa7a4bd
diff --git a/backend/src/ee/routes/v1/pam-routers/pam-account-router.ts b/backend/src/ee/routes/v1/pam-routers/pam-account-router.ts
index fe0c3649fd..b143042cf8 100644
--- a/backend/src/ee/routes/v1/pam-routers/pam-account-router.ts
+++ b/backend/src/ee/routes/v1/pam-routers/pam-account-router.ts
@@ -2,7 +2,7 @@ import z from "zod";
import { PamAccountsSchema } from "@app/db/schemas";
import { EventType } from "@app/ee/services/audit-log/audit-log-types";
-import { PamAccessStatus, PamAccountType } from "@app/ee/services/pam/pam-enums";
+import { PamAccessStatus, PamAccountType, PamHeartbeatStatus } from "@app/ee/services/pam/pam-enums";
import {
ACCOUNT_TYPE_CONFIGS,
buildPamAccountTypeMetadata,
@@ -57,10 +57,13 @@ const PamAccountListItemSchema = SanitizedAccountListItemSchema.extend({
.describe("Reasons the account cannot launch a session, if any"),
isStale: z.boolean().describe("Whether the discovery source's latest scan no longer found this account."),
heartbeatStatus: z
- .string()
+ .nativeEnum(PamHeartbeatStatus)
.nullable()
.optional()
.describe("Result of the most recent credential health check, if one has run."),
+ heartbeatEnabled: z
+ .boolean()
+ .describe("Whether the account's template has scheduled credential health checks turned on."),
requiresApproval: z.boolean().describe("Whether this account requires approval before launching a session"),
requireReason: z.boolean().describe("Whether the account's template requires a reason for access"),
accessStatus: z.nativeEnum(PamAccessStatus).describe("Current approval status for the caller"),
@@ -640,7 +643,7 @@ export const registerPamAccountRouter = async (server: FastifyZodProvider) => {
heartbeat: z.object({
enabled: z.boolean(),
intervalSeconds: z.number().nullable(),
- status: z.string().nullable(),
+ status: z.nativeEnum(PamHeartbeatStatus).nullable().describe("Most recent check result"),
lastCheckedAt: z.date().nullable(),
lastHealthyAt: z.date().nullable(),
nextCheckAt: z.date().nullable(),
diff --git a/backend/src/ee/services/pam-account-heartbeat/pam-account-heartbeat-service.ts b/backend/src/ee/services/pam-account-heartbeat/pam-account-heartbeat-service.ts
index 866405fa04..ceaff0a24d 100644
--- a/backend/src/ee/services/pam-account-heartbeat/pam-account-heartbeat-service.ts
+++ b/backend/src/ee/services/pam-account-heartbeat/pam-account-heartbeat-service.ts
@@ -200,6 +200,14 @@ export const pamAccountHeartbeatServiceFactory = ({
} catch (err) {
const kind = (err as { gatewayFailureKind?: GatewayFailureKind | null }).gatewayFailureKind ?? null;
if (kind === "auth") {
+ // A delegated check signs in as the rotation account, so a refused login there says nothing about
+ // this account's credential. Blaming the target would mark every account the rotator verifies.
+ if (verifyVia) {
+ return {
+ status: PamHeartbeatStatus.CannotCheck,
+ message: "The rotation account could not sign in to the host, so this credential was not checked"
+ };
+ }
return {
status: PamHeartbeatStatus.InvalidCredentials,
message: "The target rejected this credential"
diff --git a/backend/src/ee/services/pam-account-rotation/pam-rotation-fns.test.ts b/backend/src/ee/services/pam-account-rotation/pam-rotation-fns.test.ts
index 1001ca2da2..314255e55e 100644
--- a/backend/src/ee/services/pam-account-rotation/pam-rotation-fns.test.ts
+++ b/backend/src/ee/services/pam-account-rotation/pam-rotation-fns.test.ts
@@ -1,13 +1,18 @@
-import { describe, expect, test } from "vitest";
+import { describe, expect, test, vi } from "vitest";
import { PamAccountType } from "../pam/pam-enums";
import {
computeNextRotationAt,
getRotationReadiness,
isRotatableAccountType,
- PamRotationReadinessIssue
+ PamRotationReadinessIssue,
+ withGatewayRetry
} from "./pam-rotation-fns";
+vi.mock("@app/lib/logger", () => ({
+ logger: { info: vi.fn(), error: vi.fn(), warn: vi.fn(), debug: vi.fn() }
+}));
+
describe("isRotatableAccountType", () => {
test("accepts the three SQL types", () => {
expect(isRotatableAccountType(PamAccountType.Postgres)).toBe(true);
@@ -97,3 +102,39 @@ describe("computeNextRotationAt", () => {
}
});
});
+
+describe("withGatewayRetry", () => {
+ test("retries a transport failure", async () => {
+ let attempts = 0;
+ const result = await withGatewayRetry(
+ async () => {
+ attempts += 1;
+ if (attempts < 3) throw new Error("dial tcp: i/o timeout");
+ return true;
+ },
+ "verify",
+ { baseDelayMs: 0 }
+ );
+
+ expect(result).toBe(true);
+ expect(attempts).toBe(3);
+ });
+
+ // Every retry of a refused credential is another failed logon counting toward the target's lockout.
+ test("gives up immediately when the target rejected the credential", async () => {
+ let attempts = 0;
+ const authErr = Object.assign(new Error("WinRM authentication failed"), { gatewayFailureKind: "auth" });
+
+ await expect(
+ withGatewayRetry(
+ async () => {
+ attempts += 1;
+ throw authErr;
+ },
+ "verify",
+ { baseDelayMs: 0 }
+ )
+ ).rejects.toThrow("WinRM authentication failed");
+ expect(attempts).toBe(1);
+ });
+});
diff --git a/backend/src/ee/services/pam-account-rotation/pam-rotation-fns.ts b/backend/src/ee/services/pam-account-rotation/pam-rotation-fns.ts
index 326e09d6f7..230ea78d83 100644
--- a/backend/src/ee/services/pam-account-rotation/pam-rotation-fns.ts
+++ b/backend/src/ee/services/pam-account-rotation/pam-rotation-fns.ts
@@ -59,6 +59,9 @@ export const withGatewayRetry = async (
err instanceof Error ? err.message : String(err)
}]`
);
+ // A target that rejected the credential will reject it again, and each retry is another failed logon
+ // counting toward the account's lockout threshold. Only transport failures are worth retrying.
+ if ((err as { gatewayFailureKind?: string }).gatewayFailureKind === "auth") throw err;
// eslint-disable-next-line no-await-in-loop
if (attempt < maxAttempts) await sleep(baseDelayMs * attempt);
}
diff --git a/backend/src/ee/services/pam-account/pam-account-dal.ts b/backend/src/ee/services/pam-account/pam-account-dal.ts
index 94faf694e8..eb2ae21ce2 100644
--- a/backend/src/ee/services/pam-account/pam-account-dal.ts
+++ b/backend/src/ee/services/pam-account/pam-account-dal.ts
@@ -111,6 +111,7 @@ export type TPamAccountListItem = Pick<
templateName: string;
folderName: string | null;
isStale: boolean;
+ heartbeatEnabled: boolean;
};
export type TPamAccountDetail = TPamAccounts &
@@ -204,6 +205,9 @@ export const pamAccountDALFactory = (db: TDbClient) => {
`${TableName.PamAccountTemplate}.recordingConnectionId as templateRecordingConnectionId`,
`${TableName.PamFolder}.name as folderName`,
`${TableName.PamAccount}.heartbeatStatus`,
+ db.raw(
+ `("${TableName.PamAccountTemplate}"."settings"->'heartbeat'->>'enabled' = 'true') as "heartbeatEnabled"`
+ ),
db.raw(`${staleAccountExistsSql(TableName.PamAccount)} as "isStale"`)
)
.orderBy(`${TableName.PamFolder}.name`, "asc")
diff --git a/backend/src/ee/services/pam-account/pam-account-service.ts b/backend/src/ee/services/pam-account/pam-account-service.ts
index 41fefcc66e..36b458bc65 100644
--- a/backend/src/ee/services/pam-account/pam-account-service.ts
+++ b/backend/src/ee/services/pam-account/pam-account-service.ts
@@ -278,7 +278,8 @@ export const pamAccountServiceFactory = (deps: TPamAccountServiceFactoryDep) =>
isAccessible: isAccessible && accessibilityIssues.length === 0,
accessibilityIssues,
isStale: a.isStale,
- heartbeatStatus: a.heartbeatStatus ?? null,
+ heartbeatStatus: (a.heartbeatStatus as PamHeartbeatStatus | null) ?? null,
+ heartbeatEnabled: Boolean(a.heartbeatEnabled),
requiresApproval,
requireReason,
accessStatus: requiresApproval ? (statusEntry?.accessStatus ?? PamAccessStatus.None) : PamAccessStatus.None,
@@ -765,14 +766,18 @@ export const pamAccountServiceFactory = (deps: TPamAccountServiceFactoryDep) =>
);
}
- // The health shown on the account describes the credential that was just replaced, so a corrected password
- // would otherwise keep its "out of sync" badge until the next scheduled check.
- if (credentials && credentialVerified) {
- const verifiedAt = new Date();
- updateData.heartbeatStatus = PamHeartbeatStatus.Healthy;
- updateData.lastHeartbeatAt = verifiedAt;
- updateData.lastHeartbeatHealthyAt = verifiedAt;
+ // A stored verdict describes the credential that was just replaced, so it cannot stand once the credential
+ // changes. Clearing it is what lets checking resume: several account types (Windows, SSH certificates,
+ // MSSQL Windows auth) cannot be verified on this path, and leaving them rejected would strand them stopped
+ // with a badge telling the user to do the very thing they just did.
+ if (credentials) {
+ updateData.heartbeatStatus = credentialVerified ? PamHeartbeatStatus.Healthy : null;
updateData.encryptedLastHeartbeatMessage = null;
+ if (credentialVerified) {
+ const verifiedAt = new Date();
+ updateData.lastHeartbeatAt = verifiedAt;
+ updateData.lastHeartbeatHealthyAt = verifiedAt;
+ }
}
try {
diff --git a/frontend/src/hooks/api/pam/queries.tsx b/frontend/src/hooks/api/pam/queries.tsx
index 0e0fed9680..839c4ef40b 100644
--- a/frontend/src/hooks/api/pam/queries.tsx
+++ b/frontend/src/hooks/api/pam/queries.tsx
@@ -213,6 +213,7 @@ export type TPamAccountListItem = {
// 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;
requireReason: boolean;
accessStatus: PamAccessStatus;
diff --git a/frontend/src/pages/pam/PamAccountsPage/components/CredentialHealthSection.tsx b/frontend/src/pages/pam/PamAccountsPage/components/CredentialHealthSection.tsx
index e920bdc534..fd599e9b43 100644
--- a/frontend/src/pages/pam/PamAccountsPage/components/CredentialHealthSection.tsx
+++ b/frontend/src/pages/pam/PamAccountsPage/components/CredentialHealthSection.tsx
@@ -2,7 +2,7 @@ import { formatDistanceToNow } from "date-fns";
import { createNotification } from "@app/components/notifications";
import { Button } from "@app/components/v3";
-import { PamHeartbeatStatus } from "@app/hooks/api/pam/enums";
+import { formatRotationInterval, PamHeartbeatStatus } from "@app/hooks/api/pam/enums";
import { useCheckPamAccountHeartbeat } from "@app/hooks/api/pam/mutations";
import { useGetPamAccountHeartbeat } from "@app/hooks/api/pam/queries";
@@ -62,7 +62,9 @@ export const CredentialHealthSection = ({ accountId }: Props) => {
if (!accountId || isPending || !heartbeat) return null;
const status = heartbeat.status ?? PamHeartbeatStatus.Unknown;
- const { label, indicator, className, reasonClassName } = STATUS[status];
+ // An unrecognised status must not take the tab down with it.
+ const { label, indicator, className, reasonClassName } =
+ STATUS[status] ?? STATUS[PamHeartbeatStatus.Unknown];
const isHealthy = status === PamHeartbeatStatus.Healthy;
const reason = !isHealthy && heartbeat.lastMessage ? heartbeat.lastMessage : null;
@@ -80,13 +82,24 @@ export const CredentialHealthSection = ({ accountId }: Props) => {
<div className="mb-2 flex items-center justify-between">
<div>
<h3 className="text-sm font-semibold text-foreground">Credential health</h3>
- <p className="text-xs text-muted">Whether this credential still signs in.</p>
+ <p className="text-xs text-muted">
+ {heartbeat.enabled
+ ? `Checked every ${formatRotationInterval(heartbeat.intervalSeconds)}, from ${heartbeat.templateName}.`
+ : `Scheduled checks are off for ${heartbeat.templateName}.`}
+ </p>
</div>
<span className={`text-xs font-medium ${className}`}>
{indicator} {label}
</span>
</div>
+ {!heartbeat.enabled && status !== PamHeartbeatStatus.Unknown && (
+ <DetailRow label="Result">
+ <span className="text-sm text-muted">
+ From the last check, before checking was turned off
+ </span>
+ </DetailRow>
+ )}
<DetailRow label="Last checked">
<span className="text-sm text-muted">{relative(heartbeat.lastCheckedAt)}</span>
</DetailRow>
diff --git a/frontend/src/pages/pam/PamAccountsPage/components/FolderAccountRow.tsx b/frontend/src/pages/pam/PamAccountsPage/components/FolderAccountRow.tsx
index 7f42ecbcdf..cedc93ea5f 100644
--- a/frontend/src/pages/pam/PamAccountsPage/components/FolderAccountRow.tsx
+++ b/frontend/src/pages/pam/PamAccountsPage/components/FolderAccountRow.tsx
@@ -85,7 +85,7 @@ export const FolderAccountRow = ({
issues={account.accessibilityIssues}
/>
<AccountStaleBadge isStale={account.isStale} />
- <AccountHealthBadge status={account.heartbeatStatus} />
+ <AccountHealthBadge status={account.heartbeatStatus} enabled={account.heartbeatEnabled} />
</>
}
actions={
diff --git a/frontend/src/pages/pam/components/AccountHealthBadge.tsx b/frontend/src/pages/pam/components/AccountHealthBadge.tsx
index 1b662b934b..cf401b24a8 100644
--- a/frontend/src/pages/pam/components/AccountHealthBadge.tsx
+++ b/frontend/src/pages/pam/components/AccountHealthBadge.tsx
@@ -32,8 +32,15 @@ const BADGE: Partial<
// The row only calls out what needs attention, like the stale badge. Healthy is silent, and so is an account
// nobody has checked yet: the schedule will get to it, and one with no credential already has its own badge.
-export const AccountHealthBadge = ({ status }: { status?: string | null }) => {
- const presentation = status ? BADGE[status as PamHeartbeatStatus] : undefined;
+// A stored result also stops being a claim about the present once checking is off, so the badge goes with it.
+export const AccountHealthBadge = ({
+ status,
+ enabled = true
+}: {
+ status?: string | null;
+ enabled?: boolean;
+}) => {
+ const presentation = enabled && status ? BADGE[status as PamHeartbeatStatus] : undefined;
if (!presentation) return null;
const { label, variant, icon: Icon, tooltip } = presentation;