Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
refactor(pam): address review feedback (shared helpers, central config, enums)
bernie-gf494f895aa5d
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.tsindex e23d50086f..a9e624f886 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@@ -39,10 +39,12 @@ import {computeNextRotationAt,getRotationReadiness,isRotatableAccountType,+ isSqlRotatableType,isWindowsRotatableType,PamRotationReadinessIssue,redactRotationError,ROTATION_FAILURE_RETRY_CAP_SECONDS,+ toBareAccountName,withGatewayRetry} from "./pam-rotation-fns";import {@@ -68,6 +70,7 @@ type TPamAccountRotationServiceFactoryDep = {TPamAccountDALFactory,| "findById"| "findByIdWithDetails"+ | "findByIdsWithDetails"| "find"| "updateById"| "findRotationCandidates"@@ -197,7 +200,6 @@ export const pamAccountRotationServiceFactory = (deps: TPamAccountRotationServicgatewayId,gatewayPoolId}: TPostRotate) => {- // Dependencies are detected for both domain (WindowsAd) and local (Windows) accounts.if (!isWindowsRotatableType(accountType)) return;const dependencies = await pamAccountDependencyDAL.findByAccountId(accountId);@@ -256,7 +258,7 @@ export const pamAccountRotationServiceFactory = (deps: TPamAccountRotationServicreturn true;}, "dependency sync");await pamAccountDependencyDAL.updateById(dep.id, {- rotationStatus: "success",+ rotationStatus: ROTATION_STATUS.Success,lastRotatedAt: new Date(),encryptedLastRotationMessage: null});@@ -264,7 +266,7 @@ export const pamAccountRotationServiceFactory = (deps: TPamAccountRotationServicconst message = redactRotationError(err, [newPassword, connectAuth.password]);logger.warn(err, `PAM dependency sync failed [accountId=${accountId}] [dependencyId=${dep.id}]`);await pamAccountDependencyDAL.updateById(dep.id, {- rotationStatus: "failed",+ rotationStatus: ROTATION_STATUS.Failed,encryptedLastRotationMessage: encryptor({ plainText: Buffer.from(message) }).cipherTextBlob});}@@ -273,15 +275,6 @@ export const pamAccountRotationServiceFactory = (deps: TPamAccountRotationServic);};- // Strip a domain qualifier (DOMAIN\user or user@domain) to a bare, case-insensitive sAMAccountName, so two- // accounts can be compared for being the same directory identity.- const bareUsername = (username: string): string => {- let bare = username;- if (username.includes("\\")) bare = username.split("\\").pop() ?? username;- else if (username.includes("@")) [bare] = username.split("@");- return bare.toLowerCase();- };-// A delegated rotator must sit on the same resource as its target so its credential can reach it: same// host for SQL / local Windows, same domain controller for Windows AD.const isSameResource = (@@ -309,7 +302,7 @@ export const pamAccountRotationServiceFactory = (deps: TPamAccountRotationServic// Stable key for the identity an account authenticates as, to detect two PAM objects on the same credential:// domain accounts on domain, local Windows on host, SQL on host+port, all on the bare name. Null if not rotatable.const identityKey = (accountType: PamAccountType, conn: Record<string, unknown>, username: string): string | null => {- const user = bareUsername(username);+ const user = toBareAccountName(username).toLowerCase();if (accountType === PamAccountType.WindowsAd) {const domain = (conn.domain as string | undefined)?.toLowerCase();return domain ? `ad|${domain}|${user}` : null;@@ -318,11 +311,7 @@ export const pamAccountRotationServiceFactory = (deps: TPamAccountRotationServicconst host = (conn.host as string | undefined)?.toLowerCase();return host ? `win|${host}|${user}` : null;}- if (- accountType === PamAccountType.Postgres ||- accountType === PamAccountType.MySQL ||- accountType === PamAccountType.MsSQL- ) {+ if (isSqlRotatableType(accountType)) {const host = (conn.host as string | undefined)?.toLowerCase();return host ? `sql|${host}|${String(conn.port)}|${user}` : null;}@@ -354,14 +343,17 @@ export const pamAccountRotationServiceFactory = (deps: TPamAccountRotationServic: [];// A source whose credential is the account itself is fine (it updates in place); only a *different*- // same-identity account breaks. A credential we can't decrypt/parse can't be compared, so it drops out.+ // same-identity account breaks. Only a same-type credential can share this identity (identityKey is+ // type-prefixed), so filter by type in the query and decrypt each distinct credential account at most once.const sources = await pamDiscoverySourceDAL.find({ projectId });- const sourceMatches = (+ const externalSources = sources.filter((source) => source.credentialAccountId !== account.id);+ const credentialAccountIds = [...new Set(externalSources.map((source) => source.credentialAccountId))];+ const credentialAccounts = await pamAccountDAL.findByIdsWithDetails(credentialAccountIds, account.accountType);++ const matches = (await Promise.all(- sources.map(async (source) => {- if (source.credentialAccountId === account.id) return null;- const cred = await pamAccountDAL.findByIdWithDetails(source.credentialAccountId).catch(() => null);- if (!cred || !isRotatableAccountType(cred.accountType)) return null;+ credentialAccounts.map(async (cred) => {+ if (!isRotatableAccountType(cred.accountType)) return null;try {const credCreds = await decryptSqlCredentials(projectId, cred.accountType, cred.encryptedCredentials);const credConn = resolveConnectionDetails(@@ -369,13 +361,22 @@ export const pamAccountRotationServiceFactory = (deps: TPamAccountRotationServicawait decrypt(projectId, cred.encryptedConnectionDetails));if (identityKey(cred.accountType, credConn, credCreds.username) !== key) return null;- return { accountId: cred.id, accountName: cred.name, folderId: cred.folderId, sourceName: source.name };+ return { id: cred.id, name: cred.name, folderId: cred.folderId ?? null };} catch {+ // a credential we can't decrypt/parse can't be compared, so it drops outreturn null;}}))- ).filter((m): m is { accountId: string; accountName: string; folderId: string; sourceName: string } => m !== null);+ ).filter((c): c is { id: string; name: string; folderId: string | null } => c !== null);+ const matchingById = new Map(matches.map((c) => [c.id, c]));++ const sourceMatches = externalSources.flatMap((source) => {+ const match = matchingById.get(source.credentialAccountId);+ return match+ ? [{ accountId: match.id, accountName: match.name, folderId: match.folderId, sourceName: source.name }]+ : [];+ });// Merge into one list keyed by account, collecting the discovery sources each is a credential for.const byAccount = new Map<@@ -848,7 +849,10 @@ export const pamAccountRotationServiceFactory = (deps: TPamAccountRotationServicaccount.accountType,rotator.encryptedCredentials);- if (bareUsername(rotatorCredentials.username) === bareUsername(targetCredentials.username)) {+ if (+ toBareAccountName(rotatorCredentials.username).toLowerCase() ===+ toBareAccountName(targetCredentials.username).toLowerCase()+ ) {throw new BadRequestError({message:"Rotation account is the same identity as this account, so rotating it would invalidate its own credential. Set this account to rotate itself, or choose a different privileged account."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.tsindex 9c1b8428bb..c664b38658 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@@ -2,12 +2,45 @@ import { logger } from "@app/lib/logger";import { AppConnection } from "@app/services/app-connection/app-connection-enums";import { PamAccountType } from "../pam/pam-enums";+import {+ isRotatableAccountType,+ isSqlRotatableType,+ isWindowsRotatableType,+ ROTATABLE_ACCOUNT_TYPES,+ SQL_ROTATABLE_ACCOUNT_TYPES,+ TRotatableType,+ TSqlRotatableType,+ TWindowsRotatableType,+ WINDOWS_ROTATABLE_ACCOUNT_TYPES+} from "../pam-account/pam-account-schemas";++// Rotatable-account-type sets and guards live with the central account-type config; re-exported here so the+// rotation module's existing consumers keep importing them from one place.+export {+ isRotatableAccountType,+ isSqlRotatableType,+ isWindowsRotatableType,+ ROTATABLE_ACCOUNT_TYPES,+ SQL_ROTATABLE_ACCOUNT_TYPES,+ TRotatableType,+ TSqlRotatableType,+ TWindowsRotatableType,+ WINDOWS_ROTATABLE_ACCOUNT_TYPES+};const sleep = (ms: number) =>new Promise<void>((resolve) => {setTimeout(resolve, ms);});+// Strip a domain qualifier (DOMAIN\user or user@domain) to the bare sAMAccountName. Case is preserved; callers+// that need a case-insensitive comparison lowercase the result themselves.+export const toBareAccountName = (username: string): string => {+ if (username.includes("\\")) return username.split("\\").pop() ?? username;+ if (username.includes("@")) return username.split("@")[0];+ return username;+};+// Rotation talks to the target through a gateway tunnel; a transient tunnel/TLS/auth blip is not a real failure,// so the probe throws on those and we retry, short-circuiting on a definitive result. Last error propagates.export const GATEWAY_RETRY_ATTEMPTS = 3;@@ -37,28 +70,6 @@ export const withGatewayRetry = async (throw lastErr;};-export const SQL_ROTATABLE_ACCOUNT_TYPES = [- PamAccountType.Postgres,- PamAccountType.MySQL,- PamAccountType.MsSQL-] as const;--// Windows accounts rotate over WinRM through the gateway: local accounts on their host, domain accounts-// on the DC. They do not use the SQL rotation path.-export const WINDOWS_ROTATABLE_ACCOUNT_TYPES = [PamAccountType.Windows, PamAccountType.WindowsAd] as const;--export const ROTATABLE_ACCOUNT_TYPES = [...SQL_ROTATABLE_ACCOUNT_TYPES, ...WINDOWS_ROTATABLE_ACCOUNT_TYPES] as const;--export type TSqlRotatableType = (typeof SQL_ROTATABLE_ACCOUNT_TYPES)[number];-export type TWindowsRotatableType = (typeof WINDOWS_ROTATABLE_ACCOUNT_TYPES)[number];-export type TRotatableType = (typeof ROTATABLE_ACCOUNT_TYPES)[number];--export const isRotatableAccountType = (accountType: PamAccountType | string): accountType is TRotatableType =>- (ROTATABLE_ACCOUNT_TYPES as readonly string[]).includes(accountType);--export const isWindowsRotatableType = (accountType: PamAccountType | string): accountType is TWindowsRotatableType =>- (WINDOWS_ROTATABLE_ACCOUNT_TYPES as readonly string[]).includes(accountType);-// PamAccountType -> AppConnection, so we can reuse the per-dialect ALTER statement map keyed by AppConnection.export const PAM_ROTATION_APP_MAP: Record<TSqlRotatableType,diff --git a/backend/src/ee/services/pam-account-rotation/pam-rotation-handlers.ts b/backend/src/ee/services/pam-account-rotation/pam-rotation-handlers.tsindex 3b262f6309..771d783eb6 100644--- a/backend/src/ee/services/pam-account-rotation/pam-rotation-handlers.ts+++ b/backend/src/ee/services/pam-account-rotation/pam-rotation-handlers.ts@@ -7,10 +7,12 @@ import {} from "@app/services/app-connection/shared/sql";import { PamAccountType } from "../pam/pam-enums";-import { ldapBindCheckViaGateway, winrmRpcWithGateway } from "../pam-discovery/pam-discovery-fns";+import { TWindowsAdConnectionDetails, TWindowsConnectionDetails } from "../pam-account/pam-account-schemas";+import { DEFAULT_WINRM_PORT, ldapBindCheckViaGateway, winrmRpcWithGateway } from "../pam-discovery/pam-discovery-fns";import {PAM_ROTATION_APP_MAP,redactRotationError,+ toBareAccountName,TRotatableType,TSqlRotatableType,withGatewayRetry@@ -109,29 +111,6 @@ const sqlRotationHandler: TPamRotationHandler = {}};-// Default when an account carries no explicit WinRM port (e.g. an older imported/manual account).-const DEFAULT_WINRM_PORT = 5985;--// WinRM connection settings live on the account's connection details, populated from the discovery source on-// import (or set manually), so rotation and dependency sync honor HTTPS / a custom port / a pinned CA.-type TWinrmConnSettings = {- winrmPort?: number;- useWinrmHttps?: boolean;- winrmRejectUnauthorized?: boolean;- winrmCaCert?: string;-};--type TWindowsConnDetails = TWinrmConnSettings & { host?: string };-type TWindowsAdConnDetails = TWinrmConnSettings & {- domain?: string;- dcAddress?: string;- port?: number;- useLdaps?: boolean;- ldapRejectUnauthorized?: boolean;- ldapCaCert?: string;- ldapTlsServerName?: string;-};-export const winrmPortFromConn = (conn: Record<string, unknown>): number =>typeof conn.winrmPort === "number" ? conn.winrmPort : DEFAULT_WINRM_PORT;@@ -150,13 +129,13 @@ export const winrmTransportFromConn = (// Local accounts rotate on their own host; domain accounts rotate on the DC (which has the AD tooling).const winrmRotationTargetHost = (accountType: TRotatableType, connectionDetails: Record<string, unknown>): string => {if (accountType === PamAccountType.WindowsAd) {- const conn = connectionDetails as TWindowsAdConnDetails;+ const conn = connectionDetails as TWindowsAdConnectionDetails;if (!conn.dcAddress) {throw new BadRequestError({ message: "Windows AD account is missing a domain controller address" });}return conn.dcAddress;}- const conn = connectionDetails as TWindowsConnDetails;+ const conn = connectionDetails as TWindowsConnectionDetails;if (!conn.host) throw new BadRequestError({ message: "Windows account is missing a host" });return conn.host;};@@ -175,12 +154,6 @@ const resolveRotationGatewayId = async (// Set-ADAccountPassword -Identity and Set-LocalUser -Name want a bare sAMAccountName, not DOMAIN\user or a// UPN (both accepted by the account schema), so strip any domain qualifier before building the rotate script.-const toBareAccountName = (username: string): string => {- if (username.includes("\\")) return username.split("\\").pop() ?? username;- if (username.includes("@")) return username.split("@")[0];- return username;-};-// The identity WinRM connects AS must be domain-qualified for a domain rotator: NTLM resolves a bare name// against the target's local SAM (and 401s), so qualify to a UPN. Local accounts stay bare.export const winrmConnectUsername = (@@ -190,7 +163,7 @@ export const winrmConnectUsername = (): string => {if (accountType !== PamAccountType.WindowsAd) return username;if (username.includes("\\") || username.includes("@")) return username;- const { domain } = connectionDetails as TWindowsAdConnDetails;+ const { domain } = connectionDetails as TWindowsAdConnectionDetails;return domain ? `${username}@${domain}` : username;};@@ -234,7 +207,7 @@ const windowsRotationHandler: TPamRotationHandler = {if (accountType === PamAccountType.WindowsAd) {// A domain service account usually can't WinRM to the DC, but an LDAP bind needs only the credential.- const conn = connectionDetails as TWindowsAdConnDetails;+ const conn = connectionDetails as TWindowsAdConnectionDetails;const { dcAddress, domain } = conn;if (!dcAddress || !domain) return false;const bindDn =diff --git a/backend/src/ee/services/pam-account/pam-account-dal.ts b/backend/src/ee/services/pam-account/pam-account-dal.tsindex b1c5695707..ae585cf9b2 100644--- a/backend/src/ee/services/pam-account/pam-account-dal.ts+++ b/backend/src/ee/services/pam-account/pam-account-dal.ts@@ -212,6 +212,20 @@ export const pamAccountDALFactory = (db: TDbClient) => {return rows[0] || null;};+ const findByIdsWithDetails = async (+ accountIds: string[],+ accountType: string,+ tx?: Knex+ ): Promise<TPamAccountDetail[]> => {+ if (!accountIds.length) return [];+ return (await (tx || db.replicaNode())(TableName.PamAccount)+ .join(TableName.PamAccountTemplate, `${TableName.PamAccount}.templateId`, `${TableName.PamAccountTemplate}.id`)+ .leftJoin(TableName.PamFolder, `${TableName.PamAccount}.folderId`, `${TableName.PamFolder}.id`)+ .whereIn(`${TableName.PamAccount}.id`, accountIds)+ .where(`${TableName.PamAccountTemplate}.type`, accountType)+ .select(detailSelect)) as unknown as TPamAccountDetail[];+ };+// Due, rotatable, enabled; excludes soft-deleted projects (rotating their accounts is a side effect during cleanup).const dueRotationQuery = (now: Date, tx?: Knex) =>(tx || db.replicaNode())(TableName.PamAccount)@@ -353,6 +367,7 @@ export const pamAccountDALFactory = (db: TDbClient) => {...orm,findAccessible,findByIdWithDetails,+ findByIdsWithDetails,findAccountsToRotate,countAccountsToRotate,findRotationCandidates,diff --git a/backend/src/ee/services/pam-account/pam-account-schemas.ts b/backend/src/ee/services/pam-account/pam-account-schemas.tsindex fbbaf3328c..8431954e08 100644--- a/backend/src/ee/services/pam-account/pam-account-schemas.ts+++ b/backend/src/ee/services/pam-account/pam-account-schemas.ts@@ -648,6 +648,38 @@ export const ACCOUNT_TYPE_CONFIGS = {type TSupportedAccountType = keyof typeof ACCOUNT_TYPE_CONFIGS;+export type TWindowsConnectionDetails = z.infer<+ (typeof ACCOUNT_TYPE_CONFIGS)[PamAccountType.Windows]["connectionDetails"]+>;+export type TWindowsAdConnectionDetails = z.infer<+ (typeof ACCOUNT_TYPE_CONFIGS)[PamAccountType.WindowsAd]["connectionDetails"]+>;++export const SQL_ROTATABLE_ACCOUNT_TYPES = [+ PamAccountType.Postgres,+ PamAccountType.MySQL,+ PamAccountType.MsSQL+] as const;++// Windows accounts rotate over WinRM through the gateway: local accounts on their host, domain accounts+// on the DC. They do not use the SQL rotation path.+export const WINDOWS_ROTATABLE_ACCOUNT_TYPES = [PamAccountType.Windows, PamAccountType.WindowsAd] as const;++export const ROTATABLE_ACCOUNT_TYPES = [...SQL_ROTATABLE_ACCOUNT_TYPES, ...WINDOWS_ROTATABLE_ACCOUNT_TYPES] as const;++export type TSqlRotatableType = (typeof SQL_ROTATABLE_ACCOUNT_TYPES)[number];+export type TWindowsRotatableType = (typeof WINDOWS_ROTATABLE_ACCOUNT_TYPES)[number];+export type TRotatableType = (typeof ROTATABLE_ACCOUNT_TYPES)[number];++export const isRotatableAccountType = (accountType: PamAccountType | string): accountType is TRotatableType =>+ (ROTATABLE_ACCOUNT_TYPES as readonly string[]).includes(accountType);++export const isWindowsRotatableType = (accountType: PamAccountType | string): accountType is TWindowsRotatableType =>+ (WINDOWS_ROTATABLE_ACCOUNT_TYPES as readonly string[]).includes(accountType);++export const isSqlRotatableType = (accountType: PamAccountType | string): accountType is TSqlRotatableType =>+ (SQL_ROTATABLE_ACCOUNT_TYPES as readonly string[]).includes(accountType);+const getAccountTypeConfig = (accountType: PamAccountType | string) => {const config = ACCOUNT_TYPE_CONFIGS[accountType as TSupportedAccountType];if (!config) {@@ -899,6 +931,7 @@ export const PamAccountTypeMetadataSchema = z.object({icon: z.string(),supportsWebAccess: z.boolean(),requiresGateway: z.boolean(),+ supportsDependencies: z.boolean(),connectionFields: z.array(PamFieldDescriptorSchema),credentialFields: z.array(PamFieldDescriptorSchema),applicablePolicies: z.array(PamPolicyDescriptorSchema)@@ -1055,6 +1088,7 @@ export const buildPamAccountTypeMetadata = (webAccessSupportedTypes: Set<PamAccoicon: config.icon,supportsWebAccess: webAccessSupportedTypes.has(type),requiresGateway: accountTypeRequiresGateway(type),+ supportsDependencies: isWindowsRotatableType(type),connectionFields: fieldsFromSchema(config.connectionDetails, config.ui),credentialFields: fieldsFromSchema(config.credentials, config.ui),applicablePolicies: getApplicablePolicies(type)diff --git a/backend/src/ee/services/pam-discovery/active-directory/active-directory-discovery-factory.ts b/backend/src/ee/services/pam-discovery/active-directory/active-directory-discovery-factory.tsindex 2c254f0029..de6a4594bd 100644--- a/backend/src/ee/services/pam-discovery/active-directory/active-directory-discovery-factory.ts+++ b/backend/src/ee/services/pam-discovery/active-directory/active-directory-discovery-factory.ts@@ -11,7 +11,7 @@ import { logger } from "@app/lib/logger";import { TGatewayV2ServiceFactory } from "../../gateway-v2/gateway-v2-service";import { PamAccountType } from "../../pam/pam-enums";import { isDomainQualifiedUsername, toNetbiosUsername } from "../../pam-account/pam-account-schemas";-import { executeWithGateway, winrmRpcWithGateway } from "../pam-discovery-fns";+import { DEFAULT_WINRM_PORT, executeWithGateway, winrmRpcWithGateway } from "../pam-discovery-fns";import {TDiscoveredAccount,TDiscoveredDependency,@@ -381,7 +381,7 @@ export const activeDirectoryDiscoveryFactory: TPamDiscoveryFactory = ({// Carry the source's WinRM settings onto imported accounts so rotation and dependency sync honor HTTPS /// a custom port / a pinned CA (the account connection schema has no separate WinRM discovery step).const winrmConnDetails = {- winrmPort: config.winrmPort ?? 5985,+ winrmPort: config.winrmPort ?? DEFAULT_WINRM_PORT,useWinrmHttps: config.useWinrmHttps ?? false,winrmRejectUnauthorized: config.winrmRejectUnauthorized ?? true,...(config.winrmCaCert ? { winrmCaCert: config.winrmCaCert } : {})@@ -411,7 +411,7 @@ export const activeDirectoryDiscoveryFactory: TPamDiscoveryFactory = ({}const winrm: TWinrmConfig = {- port: config.winrmPort ?? 5985,+ port: config.winrmPort ?? DEFAULT_WINRM_PORT,useHttps: config.useWinrmHttps ?? false,rejectUnauthorized: config.winrmRejectUnauthorized ?? true,caCert: config.winrmCaCertdiff --git a/backend/src/ee/services/pam-discovery/pam-discovery-fns.ts b/backend/src/ee/services/pam-discovery/pam-discovery-fns.tsindex 13bd22ca2c..47e5f4c39d 100644--- a/backend/src/ee/services/pam-discovery/pam-discovery-fns.ts+++ b/backend/src/ee/services/pam-discovery/pam-discovery-fns.ts@@ -12,6 +12,8 @@ import { resolveDnsTcp } from "./active-directory/dns-over-dc";type TGatewayDep = Pick<TGatewayV2ServiceFactory, "getPlatformConnectionDetailsByGatewayId">;+export const DEFAULT_WINRM_PORT = 5985;+const SWEEP_RESPONSE_TIMEOUT_MS = 10 * 60 * 1000;// runs a command on the target via the gateway's ssh-exec handler; the gateway performs the ssh login (any authdiff --git a/frontend/src/hooks/api/pam/enums.ts b/frontend/src/hooks/api/pam/enums.tsindex c7ea53e713..2c5ce30e90 100644--- a/frontend/src/hooks/api/pam/enums.ts+++ b/frontend/src/hooks/api/pam/enums.ts@@ -36,9 +36,10 @@ export const ROTATABLE_PAM_ACCOUNT_TYPES = [export const isRotatablePamAccountType = (type: PamAccountType | string) =>(ROTATABLE_PAM_ACCOUNT_TYPES as string[]).includes(type);-// Windows accounts (domain and local) are the ones whose run-as dependencies discovery detects and syncs.-export const supportsPamDependencies = (type: PamAccountType | string) =>- type === PamAccountType.WindowsAd || type === PamAccountType.Windows;+export enum PamRotationStatus {+ Success = "success",+ Failed = "failed"+}export const PAM_ROTATION_INTERVAL_OPTIONS: { seconds: number; label: string }[] = [{ seconds: 3600, label: "1 hour" },diff --git a/frontend/src/hooks/api/pam/mutations.tsx b/frontend/src/hooks/api/pam/mutations.tsxindex 85510d5edf..1cc635c7d2 100644--- a/frontend/src/hooks/api/pam/mutations.tsx+++ b/frontend/src/hooks/api/pam/mutations.tsx@@ -787,7 +787,6 @@ export const useRotatePamAccount = () => {onSettled: (_, __, { accountId }) => {queryClient.invalidateQueries({ queryKey: pamKeys.accountRotation(accountId) });queryClient.invalidateQueries({ queryKey: pamKeys.getAccount(accountId) });- // Dependency sync runs as part of rotation, so refresh the Dependencies tab's badges too.queryClient.invalidateQueries({ queryKey: pamKeys.accountDependencies(accountId) });}});diff --git a/frontend/src/hooks/api/pam/types/index.ts b/frontend/src/hooks/api/pam/types/index.tsindex 8b935b97df..b575d3fab7 100644--- a/frontend/src/hooks/api/pam/types/index.ts+++ b/frontend/src/hooks/api/pam/types/index.ts@@ -12,6 +12,7 @@ import {PamPolicyType,PamResourcePermissionActions,PamResourcePermissionSub,+ PamRotationStatus,PamSessionStatus,SessionChannelType} from "../enums";@@ -75,7 +76,7 @@ export type TPamDiscoveredAccount = {export type TPamAccountDependency = TPamDependency & {data: Record<string, unknown> | null;- rotationStatus: string | null;+ rotationStatus: PamRotationStatus | null;lastRotatedAt: string | null;lastRotationMessage: string | null;};@@ -154,6 +155,7 @@ export type TPamAccountTypeMetadata = {icon: string;supportsWebAccess: boolean;requiresGateway: boolean;+ supportsDependencies: boolean;connectionFields: TPamFieldDescriptor[];credentialFields: TPamFieldDescriptor[];applicablePolicies: TPamPolicyDescriptor[];@@ -612,7 +614,7 @@ export type TPamAccountRotation = {rotationAccountId: string | null;rotationAccountName: string | null;lastRotatedAt: string | null;- rotationStatus: string | null;+ rotationStatus: PamRotationStatus | null;lastRotationError: string | null;isReady: boolean;sharedIdentity: { id: string; name: string; discoverySources: string[] }[];diff --git a/frontend/src/pages/pam/PamAccountsPage/components/AccountDetailSheet.tsx b/frontend/src/pages/pam/PamAccountsPage/components/AccountDetailSheet.tsxindex d6376a3436..00edb545c1 100644--- a/frontend/src/pages/pam/PamAccountsPage/components/AccountDetailSheet.tsx+++ b/frontend/src/pages/pam/PamAccountsPage/components/AccountDetailSheet.tsx@@ -917,7 +917,13 @@ export const AccountDetailSheet = ({ isOpen, accountId, onOpenChange }: Props) =<EditAccountForm accountId={accountId} onDirtyChange={setIsFormDirty} />) : null,[PamSheetTab.Rotation]: accountId ? (- <RotationTab accountId={accountId} onDirtyChange={setIsFormDirty} />+ <RotationTab+ accountId={accountId}+ supportsDependencies={+ accountType ? (accountTypeMap[accountType]?.supportsDependencies ?? false) : false+ }+ onDirtyChange={setIsFormDirty}+ />) : null,[PamSheetTab.Advanced]: accountId ? (<SettingsTab accountId={accountId} onDirtyChange={setIsFormDirty} />diff --git a/frontend/src/pages/pam/PamAccountsPage/components/DependenciesSection.tsx b/frontend/src/pages/pam/PamAccountsPage/components/DependenciesSection.tsxindex 09a6027e92..0e414711ed 100644--- a/frontend/src/pages/pam/PamAccountsPage/components/DependenciesSection.tsx+++ b/frontend/src/pages/pam/PamAccountsPage/components/DependenciesSection.tsx@@ -17,7 +17,11 @@ import {TooltipProvider,TooltipTrigger} from "@app/components/v3/generic/Tooltip";-import { TPamAccountDependency, useListPamAccountDependencies } from "@app/hooks/api/pam";+import {+ PamRotationStatus,+ TPamAccountDependency,+ useListPamAccountDependencies+} from "@app/hooks/api/pam";const TYPE_LABELS: Record<string, string> = {"windows-service": "Windows Service",@@ -38,9 +42,9 @@ const TYPE_DETAIL_FIELDS: Record<string, { key: string; label: string }[]> = {};const StatusBadge = ({ dep }: { dep: TPamAccountDependency }) => {- if (dep.rotationStatus === "success") return <Badge variant="success">Rotated</Badge>;- if (dep.rotationStatus === "pending") return <Badge variant="warning">Pending</Badge>;- if (dep.rotationStatus === "failed") {+ if (dep.rotationStatus === PamRotationStatus.Success)+ return <Badge variant="success">Rotated</Badge>;+ if (dep.rotationStatus === PamRotationStatus.Failed) {return (<TooltipProvider><Tooltip>@@ -96,7 +100,7 @@ const DependencyDetail = ({ dep }: { dep: TPamAccountDependency }) => {})}<DetailRow label="Last rotation" value={lastRotated} /></div>- {dep.rotationStatus === "failed" && dep.lastRotationMessage && (+ {dep.rotationStatus === PamRotationStatus.Failed && dep.lastRotationMessage && (<div className="rounded-md border border-danger/40 bg-danger/10 px-3 py-2 text-xs text-danger">{dep.lastRotationMessage}</div>diff --git a/frontend/src/pages/pam/PamAccountsPage/components/RotationTab.tsx b/frontend/src/pages/pam/PamAccountsPage/components/RotationTab.tsxindex 07afb779d0..e13e100f4c 100644--- a/frontend/src/pages/pam/PamAccountsPage/components/RotationTab.tsx+++ b/frontend/src/pages/pam/PamAccountsPage/components/RotationTab.tsx@@ -20,7 +20,11 @@ import {PopoverTrigger} from "@app/components/v3";import { Skeleton } from "@app/components/v3/generic/Skeleton";-import { formatRotationInterval, PamResourcePermissionActions } from "@app/hooks/api/pam";+import {+ formatRotationInterval,+ PamResourcePermissionActions,+ PamRotationStatus+} from "@app/hooks/api/pam";import { useRotatePamAccount, useUpdatePamAccountRotation } from "@app/hooks/api/pam/mutations";import {useGetPamAccountRotation,@@ -33,7 +37,11 @@ import { formatDetailDate } from "../../components/PamDetailSheet";import { SheetSaveBar } from "../../components/SheetSaveBar";import { DependenciesSection } from "./DependenciesSection";-type Props = { accountId: string; onDirtyChange?: (isDirty: boolean) => void };+type Props = {+ accountId: string;+ supportsDependencies?: boolean;+ onDirtyChange?: (isDirty: boolean) => void;+};type RotationForm = { rotationAccountId: string | null };@@ -140,7 +148,7 @@ const RotationAccountPicker = ({);};-export const RotationTab = ({ accountId, onDirtyChange }: Props) => {+export const RotationTab = ({ accountId, supportsDependencies, onDirtyChange }: Props) => {const { data: rotation, isPending } = useGetPamAccountRotation(accountId);const { can } = usePamAccountActions(accountId);const canManage = can(PamResourcePermissionActions.ManageRotation);@@ -193,7 +201,8 @@ export const RotationTab = ({ accountId, onDirtyChange }: Props) => {);}- const hasFailure = rotation.rotationStatus === "failed" && Boolean(rotation.lastRotationError);+ const hasFailure =+ rotation.rotationStatus === PamRotationStatus.Failed && Boolean(rotation.lastRotationError);return (<form onSubmit={handleSubmit(onSubmit)} className="flex flex-1 flex-col gap-4 p-4">@@ -301,7 +310,7 @@ export const RotationTab = ({ accountId, onDirtyChange }: Props) => {</p></div>- <DependenciesSection accountId={accountId} />+ {supportsDependencies && <DependenciesSection accountId={accountId} />}{!rotation.isReady && (<Alert variant="warning">