Skip to content

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

fix(pam): address heartbeat review feedback

bernie-ga78e5980ecd8
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 ceaff0a24d..056a656054 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
@@ -326,6 +326,12 @@ export const pamAccountHeartbeatServiceFactory = ({
const checkScheduledAccount = async (accountId: string): Promise<TPamHeartbeatResult | null> => {
const account = await pamAccountDAL.findByIdWithDetails(accountId);
if (!account) return null;
+
+ // Settings can change between the scan that queued this and the worker picking it up, and a disabled
+ // feature must not still be signing in to a customer's target.
+ const heartbeat = PamTemplateSettingsSchema.safeParse(account.templateSettings).data?.heartbeat;
+ if (!isHeartbeatScheduled(heartbeat)) return null;
+
return runCheck(account);
};
diff --git a/backend/src/ee/services/pam-account-heartbeat/pam-heartbeat-fns.ts b/backend/src/ee/services/pam-account-heartbeat/pam-heartbeat-fns.ts
index e4a0f75305..e6d8a3b52d 100644
--- a/backend/src/ee/services/pam-account-heartbeat/pam-heartbeat-fns.ts
+++ b/backend/src/ee/services/pam-account-heartbeat/pam-heartbeat-fns.ts
@@ -49,6 +49,13 @@ const TRANSPORT_ERROR_PATTERNS = [
"enotfound",
"eai_again",
"socket hang up",
+ "x509",
+ "tls",
+ "certificate",
+ "service unavailable",
+ "internalfailure",
+ "internal server error",
+ "bad gateway",
"throttl",
"slowdown",
"rate exceeded",
@@ -67,10 +74,33 @@ export const statusForFailureKind = (kind: GatewayFailureKind | null): PamHeartb
return PamHeartbeatStatus.InvalidCredentials;
};
-// Cloud accounts (AWS IAM, GCP, Azure) are brokered by us rather than logged into, so there is no lockout to trigger
-// and a rejection here means access was revoked. Transport failures still have to stay out of that bucket.
+// Cloud accounts (AWS IAM, GCP, Azure) are brokered by us rather than logged into, so there is no lockout to
+// protect against. That inverts the bias used elsewhere: only a recognised rejection stops the schedule, so a
+// provider outage, a throttle, or a TLS failure keeps checking instead of reporting access as revoked.
+const CLOUD_REJECTION_PATTERNS = [
+ "accessdenied",
+ "access denied",
+ "unauthorized",
+ "unauthorised",
+ "invalid_client",
+ "invalid_grant",
+ "invalidclienttokenid",
+ "signaturedoesnotmatch",
+ "expiredtoken",
+ "invalid credentials",
+ "permission denied",
+ "forbidden",
+ "not authorized to perform",
+ "invalid jwt",
+ "is disabled",
+ "has been deleted"
+];
+
export const classifyCloudProbeError = (err: unknown): PamHeartbeatStatus => {
const message = (err instanceof Error ? err.message : String(err)).toLowerCase();
if (TRANSPORT_ERROR_PATTERNS.some((pattern) => message.includes(pattern))) return PamHeartbeatStatus.CannotCheck;
- return PamHeartbeatStatus.InvalidCredentials;
+ if (CLOUD_REJECTION_PATTERNS.some((pattern) => message.includes(pattern))) {
+ return PamHeartbeatStatus.InvalidCredentials;
+ }
+ return PamHeartbeatStatus.CannotCheck;
};
diff --git a/backend/src/ee/services/pam-account-rotation/pam-account-rotation-service.ts b/backend/src/ee/services/pam-account-rotation/pam-account-rotation-service.ts
index 7c75547e31..ce7894fc3f 100644
--- a/backend/src/ee/services/pam-account-rotation/pam-account-rotation-service.ts
+++ b/backend/src/ee/services/pam-account-rotation/pam-account-rotation-service.ts
@@ -16,7 +16,7 @@ import { TMembershipDALFactory } from "@app/services/membership/membership-dal";
import { TMembershipRoleDALFactory } from "@app/services/membership/membership-role-dal";
import { TProjectDALFactory } from "@app/services/project/project-dal";
-import { PamAccountType, PamPostgresAuthMethod, PamProductRole } from "../pam/pam-enums";
+import { PamAccountType, PamHeartbeatStatus, PamPostgresAuthMethod, PamProductRole } from "../pam/pam-enums";
import {
checkAccountAccess,
getResourceIdsWithActions,
@@ -25,6 +25,7 @@ import {
} from "../pam/pam-permission";
import { TPamAccountDALFactory, TPamAccountDetail } from "../pam-account/pam-account-dal";
import { validateConnectionDetails, validateCredentials } from "../pam-account/pam-account-schemas";
+import { computeNextHeartbeatAt, isHeartbeatScheduled } from "../pam-account-heartbeat/pam-heartbeat-fns";
import { PamTemplateSettingsSchema } from "../pam-account-template/pam-account-template-schemas";
import { TPamAccountDependencyDALFactory } from "../pam-discovery/pam-account-dependency-dal";
import { resolveHostsViaDcDns, winrmRpcWithGateway } from "../pam-discovery/pam-discovery-fns";
@@ -162,16 +163,29 @@ export const pamAccountRotationServiceFactory = (deps: TPamAccountRotationServic
return computeNextRotationAt({ anchor: now, intervalSeconds: rotation.intervalSeconds, now });
};
- const markRotated = (account: TPamAccountDetail, encryptedBlob: Buffer, now: Date) =>
- pamAccountDAL.updateById(account.id, {
+ const markRotated = async (account: TPamAccountDetail, encryptedBlob: Buffer, now: Date) => {
+ // Rotation only commits after its own verify step authenticated with the new credential, so this doubles as
+ // a health check: the account is known good right now, and any earlier rejection described a password that
+ // no longer exists. Without this an account stopped for a bad credential would stay stopped and red.
+ const heartbeat = PamTemplateSettingsSchema.safeParse(account.templateSettings).data?.heartbeat;
+
+ await pamAccountDAL.updateById(account.id, {
encryptedCredentials: encryptedBlob,
encryptedPendingCredentials: null,
credentialConfigured: true,
lastRotatedAt: now,
rotationStatus: ROTATION_STATUS.Success,
encryptedLastRotationMessage: null,
- nextRotationAt: nextRotationAfter(account.templateSettings, now)
+ nextRotationAt: nextRotationAfter(account.templateSettings, now),
+ heartbeatStatus: PamHeartbeatStatus.Healthy,
+ lastHeartbeatAt: now,
+ lastHeartbeatHealthyAt: now,
+ encryptedLastHeartbeatMessage: null,
+ nextHeartbeatAt: isHeartbeatScheduled(heartbeat)
+ ? computeNextHeartbeatAt({ anchor: now, intervalSeconds: heartbeat.intervalSeconds as number, now })
+ : null
});
+ };
const resolveConnectionDetails = (
accountType: PamAccountType,