Skip to content

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

refactor(pam): rename the credential health endpoint to /health

bernie-g9c22271fa166
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 18e7b1a5b5..eb844c7dc5 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
@@ -632,7 +632,7 @@ export const registerPamAccountRouter = async (server: FastifyZodProvider) => {
server.route({
method: "GET",
- url: "/:accountId/heartbeat",
+ url: "/:accountId/health",
schema: {
operationId: "getPamAccountCredentialHealth",
description: "Get a PAM account's credential health",
@@ -671,7 +671,7 @@ export const registerPamAccountRouter = async (server: FastifyZodProvider) => {
server.route({
method: "POST",
- url: "/:accountId/heartbeat/check",
+ url: "/:accountId/health/check",
schema: {
operationId: "checkPamAccountCredentialHealth",
description: "Run a credential health check on a PAM account now",
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 7171d03c95..2d7eb2510c 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
@@ -32,6 +32,7 @@ import { TCheckAccountHeartbeatDTO, TPamHeartbeatResult } from "./pam-account-he
import {
classifyCloudProbeError,
computeNextHeartbeatAt,
+ describeFailure,
HEARTBEAT_SSH_CERT_TTL_SECONDS,
HEARTBEAT_TIMEOUT_MS,
isHeartbeatScheduled,
@@ -253,7 +254,10 @@ export const pamAccountHeartbeatServiceFactory = ({
return { status: PamHeartbeatStatus.CannotCheck, message: "The gateway could not be reached" };
}
if (!result.ok) {
- return { status: statusForFailureKind(result.kind), message: result.errorMessage };
+ return {
+ status: statusForFailureKind(result.kind),
+ message: describeFailure(result.kind, result.errorMessage)
+ };
}
return { status: PamHeartbeatStatus.Healthy };
};
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 a7f6d0fd56..f878176258 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
@@ -5,7 +5,12 @@ import {
DEFAULT_HEARTBEAT_CONFIG,
PamHeartbeatConfigSchema
} from "../pam-account-template/pam-account-template-schemas";
-import { classifyCloudProbeError, isHeartbeatScheduled } from "./pam-heartbeat-fns";
+import {
+ classifyCloudProbeError,
+ describeFailure,
+ isHeartbeatScheduled,
+ UNCLASSIFIED_FAILURE_NOTE
+} 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 } });
@@ -55,3 +60,17 @@ describe("DEFAULT_HEARTBEAT_CONFIG", () => {
expect(isHeartbeatScheduled(DEFAULT_HEARTBEAT_CONFIG)).toBe(true);
});
});
+
+describe("describeFailure", () => {
+ test("leaves a classified failure's message alone", () => {
+ expect(describeFailure("auth", "password authentication failed")).toBe("password authentication failed");
+ expect(describeFailure("transport", "connection refused")).toBe("connection refused");
+ });
+
+ // An old gateway sends no kind, so every failure it reports lands on invalid-credentials.
+ test("says why an unclassified failure reads as a rejection", () => {
+ expect(describeFailure(null, "something went wrong")).toContain(UNCLASSIFIED_FAILURE_NOTE);
+ expect(describeFailure(null, "something went wrong")).toContain("something went wrong");
+ expect(describeFailure(null, undefined)).toBe(UNCLASSIFIED_FAILURE_NOTE);
+ });
+});
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 878e6b9efb..d10ea3e27c 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
@@ -42,6 +42,17 @@ export const statusForFailureKind = (kind: GatewayFailureKind | null): PamHeartb
return PamHeartbeatStatus.InvalidCredentials;
};
+// A gateway from before this feature reports no kind at all, so every one of its failures reads as a rejected
+// credential. The status stays on the safe side, but the reason has to say the verdict is the gateway's age
+// rather than an answer from the target.
+export const UNCLASSIFIED_FAILURE_NOTE =
+ "This gateway is too old to tell a rejected credential from an unreachable target. Update the gateway for an accurate result.";
+
+export const describeFailure = (kind: GatewayFailureKind | null, message?: string): string | undefined => {
+ if (kind !== null) return message;
+ return message ? `${message}\n\n${UNCLASSIFIED_FAILURE_NOTE}` : UNCLASSIFIED_FAILURE_NOTE;
+};
+
// Cloud accounts are brokered over HTTP, so the provider's status says what its prose only hints at. A status
// at all means the request was answered and the credential judged; 5xx, 408, and 429 are the provider having a
// bad day rather than a verdict on the credential.
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 dc43201c33..af0253ce38 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
@@ -154,8 +154,7 @@ 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.
+ // Credential health checking is on for a new template unless the caller says otherwise.
const seededSettings: TPamTemplateSettings = {
...(settings ?? {}),
heartbeat: settings?.heartbeat ?? DEFAULT_HEARTBEAT_CONFIG
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 ad203f9063..ad1a422b38 100644
--- a/backend/src/ee/services/pam-account/pam-account-dal.ts
+++ b/backend/src/ee/services/pam-account/pam-account-dal.ts
@@ -206,7 +206,8 @@ export const pamAccountDALFactory = (db: TDbClient) => {
`${TableName.PamFolder}.name as folderName`,
`${TableName.PamAccount}.heartbeatStatus`,
db.raw(
- `("${TableName.PamAccountTemplate}"."settings"->'heartbeat'->>'enabled' = 'true') as "heartbeatEnabled"`
+ `("${TableName.PamAccountTemplate}"."settings"->'heartbeat'->>'enabled' = 'true'
+ and "${TableName.PamAccountTemplate}"."settings"->'heartbeat'->>'intervalSeconds' is not null) as "heartbeatEnabled"`
),
db.raw(`${staleAccountExistsSql(TableName.PamAccount)} as "isStale"`)
)
@@ -294,7 +295,9 @@ export const pamAccountDALFactory = (db: TDbClient) => {
.whereNull(`${TableName.Project}.deleteAfter`)
.whereNotNull(`${TableName.PamAccount}.nextHeartbeatAt`)
.where(`${TableName.PamAccount}.nextHeartbeatAt`, "<=", now)
- .whereRaw(`"${TableName.PamAccountTemplate}"."settings"->'heartbeat'->>'enabled' = 'true'`);
+ // Both halves of isHeartbeatScheduled: an enabled config with no interval is manual-only.
+ .whereRaw(`"${TableName.PamAccountTemplate}"."settings"->'heartbeat'->>'enabled' = 'true'`)
+ .whereRaw(`"${TableName.PamAccountTemplate}"."settings"->'heartbeat'->>'intervalSeconds' is not null`);
const findAccountsToHeartbeat = async (now: Date, limit: number, tx?: Knex): Promise<TPamAccountDetail[]> => {
return (await dueHeartbeatQuery(now, tx)
diff --git a/frontend/src/hooks/api/pam/mutations.tsx b/frontend/src/hooks/api/pam/mutations.tsx
index 7fc7504e39..f0c4b710ee 100644
--- a/frontend/src/hooks/api/pam/mutations.tsx
+++ b/frontend/src/hooks/api/pam/mutations.tsx
@@ -784,7 +784,7 @@ export const useCheckPamAccountHeartbeat = () => {
return useMutation({
mutationFn: async ({ accountId }: { accountId: string }) => {
const { data } = await apiRequest.post<{ heartbeatStatus: string; message?: string }>(
- `/api/v1/pam/accounts/${accountId}/heartbeat/check`
+ `/api/v1/pam/accounts/${accountId}/health/check`
);
return data;
},
diff --git a/frontend/src/hooks/api/pam/queries.tsx b/frontend/src/hooks/api/pam/queries.tsx
index 839c4ef40b..13e3381288 100644
--- a/frontend/src/hooks/api/pam/queries.tsx
+++ b/frontend/src/hooks/api/pam/queries.tsx
@@ -320,7 +320,7 @@ export const useGetPamAccountHeartbeat = (accountId?: string, options?: { enable
queryKey: pamKeys.accountHeartbeat(accountId || ""),
queryFn: async () => {
const { data } = await apiRequest.get<{ heartbeat: TPamAccountHeartbeat }>(
- `/api/v1/pam/accounts/${accountId}/heartbeat`
+ `/api/v1/pam/accounts/${accountId}/health`
);
return data.heartbeat;
},
diff --git a/frontend/src/pages/pam/PamTemplatesPage/components/TemplateDetailSheet.tsx b/frontend/src/pages/pam/PamTemplatesPage/components/TemplateDetailSheet.tsx
index 643cc9e2a7..1c3f634391 100644
--- a/frontend/src/pages/pam/PamTemplatesPage/components/TemplateDetailSheet.tsx
+++ b/frontend/src/pages/pam/PamTemplatesPage/components/TemplateDetailSheet.tsx
@@ -346,8 +346,6 @@ const SettingsTab = ({
};
return {
rotationEnabled: rotation.enabled ?? false,
- // 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: