Skip to content

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

feat(pam): turn credential health checks on for new templates

bernie-g07f7852013c8
diff --git a/backend/src/ee/services/pam-account-heartbeat/pam-heartbeat-fns.test.ts b/backend/src/ee/services/pam-account-heartbeat/pam-heartbeat-fns.test.ts
index 72e6f7bfc5..a7f6d0fd56 100644
--- a/backend/src/ee/services/pam-account-heartbeat/pam-heartbeat-fns.test.ts
+++ b/backend/src/ee/services/pam-account-heartbeat/pam-heartbeat-fns.test.ts
@@ -1,7 +1,11 @@
import { describe, expect, test } from "vitest";
import { PamHeartbeatStatus } from "../pam/pam-enums";
-import { classifyCloudProbeError } from "./pam-heartbeat-fns";
+import {
+ DEFAULT_HEARTBEAT_CONFIG,
+ PamHeartbeatConfigSchema
+} from "../pam-account-template/pam-account-template-schemas";
+import { classifyCloudProbeError, isHeartbeatScheduled } from "./pam-heartbeat-fns";
// Shapes the three federation helpers actually throw: axios (Azure, GCP) and the AWS SDK.
const axiosError = (status: number) => ({ isAxiosError: true, response: { status } });
@@ -42,3 +46,12 @@ describe("classifyCloudProbeError", () => {
expect(classifyCloudProbeError(wrapped({ code: "ETIMEDOUT" }))).toBe(PamHeartbeatStatus.CannotCheck);
});
});
+
+describe("DEFAULT_HEARTBEAT_CONFIG", () => {
+ // New templates opt in; the interval has to be one the scheduler and the template form both accept.
+ test("is enabled and within the allowed interval range", () => {
+ expect(DEFAULT_HEARTBEAT_CONFIG.enabled).toBe(true);
+ expect(PamHeartbeatConfigSchema.safeParse(DEFAULT_HEARTBEAT_CONFIG).success).toBe(true);
+ expect(isHeartbeatScheduled(DEFAULT_HEARTBEAT_CONFIG)).toBe(true);
+ });
+});
diff --git a/backend/src/ee/services/pam-account-template/pam-account-template-schemas.ts b/backend/src/ee/services/pam-account-template/pam-account-template-schemas.ts
index 604551008c..1e3d459cb4 100644
--- a/backend/src/ee/services/pam-account-template/pam-account-template-schemas.ts
+++ b/backend/src/ee/services/pam-account-template/pam-account-template-schemas.ts
@@ -16,6 +16,9 @@ export const PamHeartbeatConfigSchema = z.object({
intervalSeconds: z.number().int().min(3600).max(31_536_000).nullable() // 1 hour .. 1 year, or null for manual
});
+// Daily, matching the interval the template form offers by default.
+export const DEFAULT_HEARTBEAT_CONFIG: TPamHeartbeatConfig = { enabled: true, intervalSeconds: 86_400 };
+
export const PamRecordingS3ConfigSchema = z.object({
bucket: z.string().trim().min(1),
region: z.nativeEnum(AWSRegion),
diff --git a/backend/src/ee/services/pam-account-template/pam-account-template-service.ts b/backend/src/ee/services/pam-account-template/pam-account-template-service.ts
index 70b45464a7..dc43201c33 100644
--- a/backend/src/ee/services/pam-account-template/pam-account-template-service.ts
+++ b/backend/src/ee/services/pam-account-template/pam-account-template-service.ts
@@ -19,6 +19,7 @@ import { PamRecordingStorageBackend } from "../pam-session-recording/pam-recordi
import { TPamRecordingResolvedConfig } from "../pam-session-recording/pam-recording-storage-types";
import { TPamAccountTemplateDALFactory } from "./pam-account-template-dal";
import {
+ DEFAULT_HEARTBEAT_CONFIG,
PamRecordingS3ConfigSchema,
PamTemplateSettingsSchema,
TPamTemplateSettings
@@ -153,6 +154,13 @@ export const pamAccountTemplateServiceFactory = (deps: TPamAccountTemplateServic
const resolvedS3Config = await validateTemplateRecordingS3Config(recordingConnectionId, settings, ctx);
+ // Credential health checking is on for a new template unless the caller says otherwise. Templates that
+ // predate the feature are left alone, so an upgrade never starts signing in to targets on its own.
+ const seededSettings: TPamTemplateSettings = {
+ ...(settings ?? {}),
+ heartbeat: settings?.heartbeat ?? DEFAULT_HEARTBEAT_CONFIG
+ };
+
try {
const template = await pamAccountTemplateDAL.create({
projectId,
@@ -160,7 +168,7 @@ export const pamAccountTemplateServiceFactory = (deps: TPamAccountTemplateServic
description,
type,
policies: validatedPolicies,
- settings: settings ?? undefined,
+ settings: seededSettings,
gatewayId,
gatewayPoolId,
recordingConnectionId
diff --git a/frontend/src/pages/pam/PamTemplatesPage/components/TemplateDetailSheet.tsx b/frontend/src/pages/pam/PamTemplatesPage/components/TemplateDetailSheet.tsx
index 64997884ff..643cc9e2a7 100644
--- a/frontend/src/pages/pam/PamTemplatesPage/components/TemplateDetailSheet.tsx
+++ b/frontend/src/pages/pam/PamTemplatesPage/components/TemplateDetailSheet.tsx
@@ -346,7 +346,8 @@ const SettingsTab = ({
};
return {
rotationEnabled: rotation.enabled ?? false,
- // Defaulting this on would start scheduled logins for every template that predates the feature.
+ // New templates are seeded on by the API; one with no heartbeat key predates the feature and
+ // must stay off, so an upgrade never starts signing in to targets on its own.
heartbeatEnabled: heartbeat.enabled ?? false,
heartbeatIntervalSeconds: heartbeat.intervalSeconds ?? 86400,
rotationIntervalSeconds: