Skip to content

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

fix(pam): gate manual health checks on credential access

bernie-gbcfaab59b514
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 b143042cf8..18e7b1a5b5 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
@@ -705,6 +705,7 @@ export const registerPamAccountRouter = async (server: FastifyZodProvider) => {
type: EventType.PAM_ACCOUNT_HEARTBEAT,
metadata: {
accountId: req.params.accountId,
+ accountName: result.accountName,
accountType: result.accountType,
heartbeatStatus: result.status,
manual: true,
@@ -713,7 +714,6 @@ export const registerPamAccountRouter = async (server: FastifyZodProvider) => {
}
});
- // A failed check is a recorded result, not a failed request: the caller asked us to check, and we did.
return { heartbeatStatus: result.status, ...(result.message ? { message: result.message } : {}) };
}
});
diff --git a/backend/src/ee/services/audit-log/audit-log-types.ts b/backend/src/ee/services/audit-log/audit-log-types.ts
index fdc31c1f9d..f0b329913b 100644
--- a/backend/src/ee/services/audit-log/audit-log-types.ts
+++ b/backend/src/ee/services/audit-log/audit-log-types.ts
@@ -6057,6 +6057,7 @@ interface PamAccountHeartbeatEvent {
type: EventType.PAM_ACCOUNT_HEARTBEAT;
metadata: {
accountId: string;
+ accountName: string;
accountType: string;
heartbeatStatus: string;
manual: boolean;
diff --git a/backend/src/ee/services/pam-account-heartbeat/pam-account-heartbeat-queue.ts b/backend/src/ee/services/pam-account-heartbeat/pam-account-heartbeat-queue.ts
index 06e3e0b5a1..4e16ebe61d 100644
--- a/backend/src/ee/services/pam-account-heartbeat/pam-account-heartbeat-queue.ts
+++ b/backend/src/ee/services/pam-account-heartbeat/pam-account-heartbeat-queue.ts
@@ -54,6 +54,7 @@ export const pamAccountHeartbeatQueueServiceFactory = async ({
type: EventType.PAM_ACCOUNT_HEARTBEAT,
metadata: {
accountId: job.data.accountId,
+ accountName: result.accountName,
accountType: result.accountType,
heartbeatStatus: result.status,
manual: false,
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 056a656054..94087ce3e5 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
@@ -75,8 +75,6 @@ export const pamAccountHeartbeatServiceFactory = ({
return encryptor({ plainText: Buffer.from(JSON.stringify({ message })) }).cipherTextBlob;
};
- // Certificate accounts hold no long-lived secret: what can break is the host no longer trusting our CA, or the
- // principal no longer existing. Minting a very short-lived certificate and logging in tests exactly that.
const mintEphemeralSshCertificate = async (
account: TPamAccountDetail,
credentials: Record<string, unknown>
@@ -105,8 +103,6 @@ export const pamAccountHeartbeatServiceFactory = ({
return { ...credentials, privateKey: clientPrivateKey, certificate: signedPublicKey };
};
- // A delegated Windows local account usually cannot WinRM in as itself, so the rotator validates its credential on
- // the box the same way rotation does. AD binds with its own credential, so it never needs this.
const resolveWindowsVerifier = async (
account: TPamAccountDetail,
accountType: PamAccountType
@@ -126,9 +122,6 @@ export const pamAccountHeartbeatServiceFactory = ({
return { username: rotatorCredentials.username, password: rotatorCredentials.password };
};
- // Runs the account's own auth probe and classifies the outcome. Never throws for a target-side problem: a thrown
- // error from here means we could not run the check at all, which is not a statement about the credential.
- // Collected as the probe decrypts them, so any message we persist can be scrubbed of the credential itself.
const probe = async (
account: TPamAccountDetail,
usedSecrets: string[]
@@ -167,8 +160,7 @@ export const pamAccountHeartbeatServiceFactory = ({
}
}
- // Windows and AD have a real credential probe already (WinRM, or an LDAP bind for AD), but only through the
- // rotation handlers; the shared connection test still falls back to a TCP check for them.
+ // The shared connection test only reaches these over TCP; the rotation handlers hold the real probe.
if (isWindowsRotatableType(accountType)) {
const handler = rotationHandlers[accountType as TRotatableType];
const { username, password } = credentials as { username: string; password?: string };
@@ -179,8 +171,7 @@ export const pamAccountHeartbeatServiceFactory = ({
const verifyVia = await resolveWindowsVerifier(account, accountType);
if (verifyVia?.password) usedSecrets.push(verifyVia.password);
- // A self-checked Windows account surfaces a rejected password as a thrown 401 rather than `false`, so
- // without this branch it would read as unreachable and keep retrying into a lockout.
+ // WinRM throws a 401 instead of returning false, which would otherwise read as unreachable and retry.
let authenticated: boolean;
try {
authenticated = await handler.testCredential(
@@ -200,8 +191,7 @@ 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.
+ // The rotator's own login was refused, which says nothing about this account's credential.
if (verifyVia) {
return {
status: PamHeartbeatStatus.CannotCheck,
@@ -231,9 +221,7 @@ export const pamAccountHeartbeatServiceFactory = ({
return { status: PamHeartbeatStatus.Unknown, message: "This account type cannot be checked yet" };
}
- // Every account type has a login-based check, so a TCP fallback here means the stored credential is incomplete
- // (an SSH certificate account with no CA, a Kubernetes account missing its auth fields). Reaching the host proves
- // nothing about the credential, so it can never read as Healthy.
+ // Every type has a login-based check, so a TCP fallback means the credential is incomplete, not healthy.
if (test.request.mode === TestConnectionMode.Tcp) {
return {
status: PamHeartbeatStatus.Unknown,
@@ -261,7 +249,6 @@ export const pamAccountHeartbeatServiceFactory = ({
HEARTBEAT_TIMEOUT_MS
);
- // A null result is our own gateway failing to answer, never the target refusing the credential.
if (!result) {
return { status: PamHeartbeatStatus.CannotCheck, message: "The gateway could not be reached" };
}
@@ -295,8 +282,7 @@ export const pamAccountHeartbeatServiceFactory = ({
const runCheck = async (account: TPamAccountDetail): Promise<TPamHeartbeatResult> => {
const now = new Date();
- // A target can echo the credential back in its error (the WinRM path interpolates it into a script), and
- // this message is persisted and audited, so everything the probe used gets scrubbed out of it.
+ // A target can echo the credential back in its error, and this message is persisted and audited.
const usedSecrets: string[] = [];
let outcome: { status: PamHeartbeatStatus; message?: string };
try {
@@ -316,6 +302,7 @@ export const pamAccountHeartbeatServiceFactory = ({
return {
accountId: account.id,
+ accountName: account.name,
projectId: account.projectId as string,
accountType: account.accountType as PamAccountType,
status: outcome.status,
@@ -327,8 +314,7 @@ export const pamAccountHeartbeatServiceFactory = ({
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.
+ // Settings can change between the scan that queued this and the worker picking it up.
const heartbeat = PamTemplateSettingsSchema.safeParse(account.templateSettings).data?.heartbeat;
if (!isHeartbeatScheduled(heartbeat)) return null;
@@ -341,12 +327,14 @@ export const pamAccountHeartbeatServiceFactory = ({
throw new NotFoundError({ message: `Account with ID '${accountId}' not found` });
}
+ // ViewCredentials, not EditAccounts: this sends the stored credential to whatever target the account
+ // points at, so an editor who can re-point the host must not be able to trigger it.
await checkAccountAccess(
permissionService,
account.id,
account.folderId,
projectId,
- ResourcePermissionPamResourceActions.EditAccounts,
+ ResourcePermissionPamResourceActions.ViewCredentials,
ctx
);
diff --git a/backend/src/ee/services/pam-account-heartbeat/pam-account-heartbeat-types.ts b/backend/src/ee/services/pam-account-heartbeat/pam-account-heartbeat-types.ts
index d771b2cc8e..264f5d5164 100644
--- a/backend/src/ee/services/pam-account-heartbeat/pam-account-heartbeat-types.ts
+++ b/backend/src/ee/services/pam-account-heartbeat/pam-account-heartbeat-types.ts
@@ -2,6 +2,7 @@ import { PamAccountType, PamHeartbeatStatus } from "../pam/pam-enums";
export type TPamHeartbeatResult = {
accountId: string;
+ accountName: string;
projectId: string;
accountType: PamAccountType;
status: PamHeartbeatStatus;
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 e6d8a3b52d..b8599c1d9a 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
@@ -5,11 +5,9 @@ import { TPamHeartbeatConfig } from "../pam-account-template/pam-account-templat
export const HEARTBEAT_TIMEOUT_MS = 15_000;
-// The check issues a genuinely usable certificate, so it lives only as long as the probe itself needs.
export const HEARTBEAT_SSH_CERT_TTL_SECONDS = 60;
-// A heartbeat is a real login attempt, so a whole template's accounts must not fire at the same instant against
-// one domain controller. Same shape as rotation's jitter: a fraction of the interval, capped.
+// Spreads a template's accounts so they don't all log in to one domain controller at the same instant.
export const HEARTBEAT_JITTER_FACTOR = 0.1;
export const HEARTBEAT_JITTER_CAP_SECONDS = 30 * 60;
@@ -35,9 +33,7 @@ export const computeNextHeartbeatAt = ({
export const isHeartbeatScheduled = (heartbeat: TPamHeartbeatConfig | undefined): heartbeat is TPamHeartbeatConfig =>
heartbeat?.enabled === true && heartbeat.intervalSeconds != null;
-// A rejected credential takes the account off the schedule entirely: retrying a wrong password is how a monitoring
-// feature locks out a customer's privileged account. A person clears it by fixing the credential, running a manual
-// check, or rotating.
+// Retrying a rejected credential is how a monitoring feature locks out a privileged account.
export const stopsSchedule = (status: PamHeartbeatStatus) => status === PamHeartbeatStatus.InvalidCredentials;
const TRANSPORT_ERROR_PATTERNS = [
@@ -66,17 +62,13 @@ const TRANSPORT_ERROR_PATTERNS = [
"tunnel"
];
-// The gateway classifies the failure where the driver error still exists. An unclassified failure (an older
-// gateway, or one the gateway could not place) resolves to a rejected credential, matching the rule that an
-// ambiguous result costs a false alarm rather than a retry loop into a lockout.
+// Unclassified resolves to rejected on purpose: an ambiguous result costs a false alarm, not a lockout.
export const statusForFailureKind = (kind: GatewayFailureKind | null): PamHeartbeatStatus => {
if (kind === "transport") return PamHeartbeatStatus.CannotCheck;
return PamHeartbeatStatus.InvalidCredentials;
};
-// 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.
+// Cloud accounts have no lockout, so the bias inverts: only a recognised rejection stops the schedule.
const CLOUD_REJECTION_PATTERNS = [
"accessdenied",
"access denied",
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 ce7894fc3f..dafec60f31 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
@@ -164,9 +164,8 @@ export const pamAccountRotationServiceFactory = (deps: TPamAccountRotationServic
};
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.
+ // Rotation commits only after authenticating with the new credential, so an account stopped for a
+ // rejected password resumes checking here instead of staying stopped and red.
const heartbeat = PamTemplateSettingsSchema.safeParse(account.templateSettings).data?.heartbeat;
await pamAccountDAL.updateById(account.id, {
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 230ea78d83..6d255ef343 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,8 +59,7 @@ 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.
+ // Each retry of a rejected credential is another failed logon counting toward lockout.
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-connection-test.ts b/backend/src/ee/services/pam-account/pam-account-connection-test.ts
index 37a5adb716..0630325c3f 100644
--- a/backend/src/ee/services/pam-account/pam-account-connection-test.ts
+++ b/backend/src/ee/services/pam-account/pam-account-connection-test.ts
@@ -96,9 +96,8 @@ export const buildGatewayConnectionTest = async (
connectionDetails: Record<string, unknown>,
credentials: Record<string, unknown> | null,
orgId: string,
- // Windows-auth MSSQL needs a gateway that routes it through the WinRM-capable proxy handshake. Callers that
- // must not fail against an older gateway (account create and update) leave this off and get a reachability
- // check for those logins, exactly as before.
+ // Off for account create and update, which must not start failing against a gateway that predates the
+ // Windows-auth proxy handshake.
opts?: { allowWindowsAuthSql?: boolean }
): Promise<{ host: string; port: number; request: TestConnectionRequest } | null> => {
const creds = credentials && isCredentialConfigured(accountType, credentials) ? credentials : null;
@@ -163,7 +162,6 @@ export const buildGatewayConnectionTest = async (
sslEnabled: cd.sslEnabled,
sslRejectUnauthorized: cd.sslRejectUnauthorized,
sslCertificate: cd.sslCertificate,
- // MSSQL Windows-auth logins carry the domain or realm the gateway needs to complete the handshake.
...(accountType === PamAccountType.MsSQL
? {
authMethod: c.authMethod,
@@ -289,7 +287,6 @@ export const buildGatewayConnectionTest = async (
privateKey?: string;
certificate?: string;
} | null;
- // Certificate accounts store no long-lived secret; the caller mints a short-lived cert and passes it here.
if (!c || (c.authMethod === PamSshAuthMethod.Certificate && !c.certificate)) return tcp(host, port);
return {
host,
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 eb2ae21ce2..ad203f9063 100644
--- a/backend/src/ee/services/pam-account/pam-account-dal.ts
+++ b/backend/src/ee/services/pam-account/pam-account-dal.ts
@@ -287,7 +287,6 @@ export const pamAccountDALFactory = (db: TDbClient) => {
return Number(result[0]?.count ?? 0);
};
- // Due and enabled. Mirrors dueRotationQuery, minus the rotatable-type filter: heartbeat covers every account type.
const dueHeartbeatQuery = (now: Date, tx?: Knex) =>
(tx || db.replicaNode())(TableName.PamAccount)
.join(TableName.PamAccountTemplate, `${TableName.PamAccount}.templateId`, `${TableName.PamAccountTemplate}.id`)
@@ -310,8 +309,7 @@ export const pamAccountDALFactory = (db: TDbClient) => {
return Number(result[0]?.count ?? 0);
};
- // Bulk reschedule when a template's heartbeat settings change. Accounts already stopped by a rejected credential
- // stay stopped: a settings change is not the human event that clears that.
+ // Accounts stopped by a rejected credential stay stopped: a settings change is not what clears that.
const reconcileHeartbeatScheduleForTemplate = async (
templateId: string,
opts?: { rescheduleAll?: boolean },
@@ -336,7 +334,7 @@ export const pamAccountDALFactory = (db: TDbClient) => {
const { intervalSeconds } = heartbeat;
const jitterCapSeconds = heartbeatJitterCapSeconds(intervalSeconds);
- // NULL-safe on purpose: an account that has never been checked has a null status, and `whereNot` would drop it.
+ // NULL-safe on purpose: a never-checked account has a null status, which `whereNot` would drop.
const update = dbClient(TableName.PamAccount)
.where({ templateId })
.whereRaw(`("heartbeatStatus" is null or "heartbeatStatus" <> ?)`, [PamHeartbeatStatus.InvalidCredentials]);
@@ -362,7 +360,6 @@ export const pamAccountDALFactory = (db: TDbClient) => {
if (!heartbeat?.enabled || heartbeat.intervalSeconds == null) {
nextHeartbeatAt = null;
} else if (!current && account.heartbeatStatus === PamHeartbeatStatus.InvalidCredentials) {
- // Stopped for a rejected credential. Only a credential change clears that, not a gateway or template edit.
nextHeartbeatAt = null;
} else if (!current) {
nextHeartbeatAt = computeNextHeartbeatAt({
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 36b458bc65..71225f3dd8 100644
--- a/backend/src/ee/services/pam-account/pam-account-service.ts
+++ b/backend/src/ee/services/pam-account/pam-account-service.ts
@@ -338,8 +338,7 @@ export const pamAccountServiceFactory = (deps: TPamAccountServiceFactoryDep) =>
};
};
- // 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 could only reach the host.
+ // 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>,
@@ -391,7 +390,6 @@ export const pamAccountServiceFactory = (deps: TPamAccountServiceFactoryDep) =>
throw new BadRequestError({ message: `Connection test failed: ${result.errorMessage}` });
}
- // A TCP probe only proves the host answered, so it cannot stand in for a verified credential.
return Boolean(result?.ok) && test.request.mode !== TestConnectionMode.Tcp;
};
@@ -504,8 +502,6 @@ export const pamAccountServiceFactory = (deps: TPamAccountServiceFactoryDep) =>
const encryptedConnectionDetails = await encrypt(projectId, validatedConnectionDetails);
const encryptedCredentials = await encrypt(projectId, validatedCredentials);
- // Only a probe that authenticated proves the credential; discovery imports skip the test entirely, and some
- // account types can only be reached, not logged into. Those start unverified.
const credentialProvenAt = credentialVerified ? new Date() : null;
try {
@@ -766,10 +762,8 @@ export const pamAccountServiceFactory = (deps: TPamAccountServiceFactoryDep) =>
);
}
- // 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.
+ // Clearing the old verdict is what resumes checking: the types that cannot be verified on this path would
+ // otherwise stay stopped, telling the user to do the very thing they just did.
if (credentials) {
updateData.heartbeatStatus = credentialVerified ? PamHeartbeatStatus.Healthy : null;
updateData.encryptedLastHeartbeatMessage = null;
diff --git a/backend/src/ee/services/pam-discovery/pam-discovery-fns.ts b/backend/src/ee/services/pam-discovery/pam-discovery-fns.ts
index 6bb1a81858..38e2155c5b 100644
--- a/backend/src/ee/services/pam-discovery/pam-discovery-fns.ts
+++ b/backend/src/ee/services/pam-discovery/pam-discovery-fns.ts
@@ -236,8 +236,6 @@ export const winrmRpcWithGateway = async <T>({
);
if (!response.ok) {
- // Carries the gateway's classification so a caller can tell a rejected credential from an unreachable
- // host without re-parsing the message.
const err = new BadRequestError({
message: `WinRM gateway operation failed: ${response.errorMessage ?? ""}`
}) as BadRequestError & { gatewayFailureKind?: GatewayFailureKind | null };
diff --git a/backend/src/lib/gateway-v2/test-connection-rpc.ts b/backend/src/lib/gateway-v2/test-connection-rpc.ts
index a0bff3cf7a..d8ead5ad38 100644
--- a/backend/src/lib/gateway-v2/test-connection-rpc.ts
+++ b/backend/src/lib/gateway-v2/test-connection-rpc.ts
@@ -1,7 +1,6 @@
import { postGatewayRpc } from "./gateway-rpc";
-// The gateway classifies a probe failure at the source, where the driver error still exists. Older gateways
-// send no kind, which the caller must treat as unclassified rather than as either outcome.
+// Older gateways send no kind, which the caller must treat as unclassified rather than as either outcome.
export type GatewayFailureKind = "auth" | "transport" | "unknown";
export type TestConnectionResponse =
diff --git a/frontend/src/hooks/api/pam/mutations.tsx b/frontend/src/hooks/api/pam/mutations.tsx
index b0a56a6beb..7fc7504e39 100644
--- a/frontend/src/hooks/api/pam/mutations.tsx
+++ b/frontend/src/hooks/api/pam/mutations.tsx
@@ -790,8 +790,7 @@ export const useCheckPamAccountHeartbeat = () => {
},
onSettled: (_, __, { accountId }) => {
queryClient.invalidateQueries({ queryKey: pamKeys.accountHeartbeat(accountId) });
- // The row badge reads its status from the account lists, which are keyed by filters this caller
- // doesn't know, so invalidate the whole account namespace rather than guess them.
+ // The row badge reads its status from lists keyed by filters this caller doesn't know.
queryClient.invalidateQueries({ queryKey: pamKeys.account() });
}
});
diff --git a/frontend/src/pages/pam/PamAccountsPage/components/CredentialHealthSection.tsx b/frontend/src/pages/pam/PamAccountsPage/components/CredentialHealthSection.tsx
index fd599e9b43..cc21b99393 100644
--- a/frontend/src/pages/pam/PamAccountsPage/components/CredentialHealthSection.tsx
+++ b/frontend/src/pages/pam/PamAccountsPage/components/CredentialHealthSection.tsx
@@ -2,15 +2,18 @@ import { formatDistanceToNow } from "date-fns";
import { createNotification } from "@app/components/notifications";
import { Button } from "@app/components/v3";
-import { formatRotationInterval, PamHeartbeatStatus } from "@app/hooks/api/pam/enums";
+import {
+ formatRotationInterval,
+ PamHeartbeatStatus,
+ PamResourcePermissionActions
+} from "@app/hooks/api/pam/enums";
import { useCheckPamAccountHeartbeat } from "@app/hooks/api/pam/mutations";
-import { useGetPamAccountHeartbeat } from "@app/hooks/api/pam/queries";
+import { useGetPamAccountHeartbeat, usePamAccountActions } from "@app/hooks/api/pam/queries";
type StatusPresentation = {
label: string;
indicator: string;
className: string;
- // Tint for the reason box, matching how a failed dependency sync is shown.
reasonClassName: string;
};
@@ -57,12 +60,14 @@ type Props = {
export const CredentialHealthSection = ({ accountId }: Props) => {
const { data: heartbeat, isPending } = useGetPamAccountHeartbeat(accountId);
+ const { can } = usePamAccountActions(accountId ?? "", Boolean(accountId));
const checkNow = useCheckPamAccountHeartbeat();
if (!accountId || isPending || !heartbeat) return null;
+ const canCheckNow = can(PamResourcePermissionActions.ViewCredentials);
+
const status = heartbeat.status ?? PamHeartbeatStatus.Unknown;
- // 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;
@@ -120,6 +125,7 @@ export const CredentialHealthSection = ({ accountId }: Props) => {
type="button"
variant="pam"
className="mt-4 w-full"
+ isDisabled={!canCheckNow}
isPending={checkNow.isPending}
onClick={handleCheckNow}
>
diff --git a/frontend/src/pages/pam/PamTemplatesPage/components/TemplateDetailSheet.tsx b/frontend/src/pages/pam/PamTemplatesPage/components/TemplateDetailSheet.tsx
index 6f440e573f..64997884ff 100644
--- a/frontend/src/pages/pam/PamTemplatesPage/components/TemplateDetailSheet.tsx
+++ b/frontend/src/pages/pam/PamTemplatesPage/components/TemplateDetailSheet.tsx
@@ -346,8 +346,7 @@ const SettingsTab = ({
};
return {
rotationEnabled: rotation.enabled ?? false,
- // Absent means a template that predates credential health. Defaulting it on here would turn
- // scheduled logins on for its accounts the next time anything else on this form is saved.
+ // Defaulting this on would start scheduled logins for every template that predates the feature.
heartbeatEnabled: heartbeat.enabled ?? false,
heartbeatIntervalSeconds: heartbeat.intervalSeconds ?? 86400,
rotationIntervalSeconds:
diff --git a/frontend/src/pages/pam/components/AccountHealthBadge.tsx b/frontend/src/pages/pam/components/AccountHealthBadge.tsx
index cf401b24a8..c470d25a62 100644
--- a/frontend/src/pages/pam/components/AccountHealthBadge.tsx
+++ b/frontend/src/pages/pam/components/AccountHealthBadge.tsx
@@ -30,9 +30,7 @@ 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.
-// A stored result also stops being a claim about the present once checking is off, so the badge goes with it.
+// A stored result stops being a claim about the present once checking is off, so the badge goes with it.
export const AccountHealthBadge = ({
status,
enabled = true