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
address greptile review
Andrey4205e1b413b0
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 411720eae3..5e3c1b20fa 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@@ -22,7 +22,7 @@ import { ORACLE_MAX_PASSWORD_LENGTH } from "../pam-account/pam-account-connectioimport { TPamAccountDALFactory, TPamAccountDetail } from "../pam-account/pam-account-dal";import { validateConnectionDetails, validateCredentials } from "../pam-account/pam-account-schemas";import { TPamAccountDependencyDALFactory } from "../pam-discovery/pam-account-dependency-dal";-import { resolveHostsViaDcDns, winrmRpcWithGateway } from "../pam-discovery/pam-discovery-fns";+import { getCredentialAccountIds, resolveHostsViaDcDns, winrmRpcWithGateway } from "../pam-discovery/pam-discovery-fns";import { TPamDiscoverySourceDALFactory } from "../pam-discovery/pam-discovery-source-dal";import { generateRdsAuthToken } from "../pam-session/aws-iam/aws-iam-federation";import { PamAccountType, PamHeartbeatStatus, PamPostgresAuthMethod, PamProductRole } from "../pam/pam-enums";@@ -405,8 +405,15 @@ export const pamAccountRotationServiceFactory = (deps: TPamAccountRotationServic// 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 externalSources = sources.filter((source) => source.credentialAccountId !== account.id);- const credentialAccountIds = [...new Set(externalSources.map((source) => source.credentialAccountId))];+ const externalCredentials = sources.flatMap((source) =>+ getCredentialAccountIds(+ source.credentialAccountId,+ (source.discoveryConfiguration as Record<string, unknown>) ?? {}+ )+ .filter((credentialAccountId) => credentialAccountId !== account.id)+ .map((credentialAccountId) => ({ credentialAccountId, sourceName: source.name }))+ );+ const credentialAccountIds = [...new Set(externalCredentials.map((c) => c.credentialAccountId))];const credentialAccounts = await pamAccountDAL.findByIdsWithDetails(credentialAccountIds, account.accountType);const matches = (@@ -430,11 +437,9 @@ export const pamAccountRotationServiceFactory = (deps: TPamAccountRotationServic).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 }]- : [];+ const sourceMatches = externalCredentials.flatMap(({ credentialAccountId, sourceName }) => {+ const match = matchingById.get(credentialAccountId);+ return match ? [{ accountId: match.id, accountName: match.name, folderId: match.folderId, sourceName }] : [];});// Merge into one list keyed by account, collecting the discovery sources each is a credential for.@@ -902,6 +907,12 @@ export const pamAccountRotationServiceFactory = (deps: TPamAccountRotationServic};};+ const getSharedIdentity = async ({ accountId, projectId, ...ctx }: TGetPamAccountRotationDTO & TActorContext) => {+ const account = await loadAccountFromPrimary(accountId, projectId);+ await checkAccount(accountId, account.folderId, projectId, ResourcePermissionPamResourceActions.ReadAccounts, ctx);+ return getSharedIdentityReferences(account, projectId, ctx);+ };+const setRotationAccount = async ({accountId,rotationAccountId,@@ -1136,5 +1147,12 @@ export const pamAccountRotationServiceFactory = (deps: TPamAccountRotationServic};};- return { getRotation, setRotationAccount, rotateNow, listRotationCandidates, rotateScheduledAccount };+ return {+ getRotation,+ getSharedIdentity,+ setRotationAccount,+ rotateNow,+ listRotationCandidates,+ rotateScheduledAccount+ };};diff --git a/backend/src/ee/services/pam-discovery/pam-discovery-fns.ts b/backend/src/ee/services/pam-discovery/pam-discovery-fns.tsindex 4d72488c3c..8ff6b092b7 100644--- a/backend/src/ee/services/pam-discovery/pam-discovery-fns.ts+++ b/backend/src/ee/services/pam-discovery/pam-discovery-fns.ts@@ -16,6 +16,13 @@ type TGatewayDep = Pick<TGatewayV2ServiceFactory, "getPlatformConnectionDetailsBexport const DEFAULT_WINRM_PORT = 5985;+export const getCredentialAccountIds = (credentialAccountId: string, configuration: Record<string, unknown>) => {+ const configIds = Array.isArray(configuration.credentialAccountIds)+ ? (configuration.credentialAccountIds as string[])+ : [];+ return Array.from(new Set([credentialAccountId, ...configIds]));+};+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/backend/src/ee/services/pam-discovery/pam-discovery-source-service.ts b/backend/src/ee/services/pam-discovery/pam-discovery-source-service.tsindex acd0863b8b..5f6ad54959 100644--- a/backend/src/ee/services/pam-discovery/pam-discovery-source-service.ts+++ b/backend/src/ee/services/pam-discovery/pam-discovery-source-service.ts@@ -38,6 +38,7 @@ import {PamDiscoveryType} from "./pam-discovery-enums";import { PAM_DISCOVERY_FACTORY_MAP } from "./pam-discovery-factory";+import { getCredentialAccountIds } from "./pam-discovery-fns";import {getCredentialAccountType,getDiscoveryTypeConfig,@@ -65,7 +66,10 @@ type TPamDiscoverySourceServiceFactoryDep = {pamAccountDependencyDAL: TPamAccountDependencyDALFactory;pamAccountDAL: Pick<TPamAccountDALFactory, "findById" | "findByIdWithDetails">;pamAccountService: Pick<TPamAccountServiceFactory, "create">;- pamAccountRotationService: Pick<TPamAccountRotationServiceFactory, "setRotationAccount" | "rotateNow">;+ pamAccountRotationService: Pick<+ TPamAccountRotationServiceFactory,+ "setRotationAccount" | "rotateNow" | "getSharedIdentity"+ >;permissionService: Pick<TPermissionServiceFactory,"getProjectPermission" | "getResourcePermission" | "getOrgPermission"@@ -210,14 +214,6 @@ export const pamDiscoverySourceServiceFactory = (deps: TPamDiscoverySourceServic}};- // unix sources scan with several ssh accounts, stored in the per-type configuration; other types use the single column- const getCredentialAccountIds = (credentialAccountId: string, configuration: Record<string, unknown>) => {- const configIds = Array.isArray(configuration.credentialAccountIds)- ? (configuration.credentialAccountIds as string[])- : [];- return Array.from(new Set([credentialAccountId, ...configIds]));- };-const resolveCredentialAccount = async (projectId: string,discoveryType: PamDiscoveryType,@@ -772,6 +768,14 @@ export const pamDiscoverySourceServiceFactory = (deps: TPamDiscoverySourceServicconst rotateImported = async (accountId: string, accountType: string, rotationAccountId: string) => {let names: { accountName: string; rotationAccountName: string | null };try {+ // the Rotation tab warns before rotating a password another account stores; an import can't ask, so it skips+ const shared = await pamAccountRotationService.getSharedIdentity({ accountId, projectId, ...ctx });+ if (shared.length) {+ return {+ rotationStatus: ROTATION_STATUS.Failed,+ rotationMessage: `Not rotated, because its password is also stored in ${shared.map((ref) => `'${ref.name}'`).join(", ")}`+ };+ }names = await pamAccountRotationService.setRotationAccount({ accountId, rotationAccountId, projectId, ...ctx });} catch (err) {return {