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
fingerprinting + nit
x032205ec2339834ed9
diff --git a/backend/src/db/migrations/20260305073334_pam-discovery-fingerprint.ts b/backend/src/db/migrations/20260305073334_pam-discovery-fingerprint.tsnew file mode 100644index 0000000000..4f89b3c466--- /dev/null+++ b/backend/src/db/migrations/20260305073334_pam-discovery-fingerprint.ts@@ -0,0 +1,35 @@+import { Knex } from "knex";++import { TableName } from "../schemas";++export async function up(knex: Knex): Promise<void> {+ const hasResourceCol = await knex.schema.hasColumn(TableName.PamResource, "discoveryFingerprint");+ if (!hasResourceCol) {+ await knex.schema.alterTable(TableName.PamResource, (t) => {+ t.string("discoveryFingerprint").nullable();+ });+ }++ const hasAccountCol = await knex.schema.hasColumn(TableName.PamAccount, "discoveryFingerprint");+ if (!hasAccountCol) {+ await knex.schema.alterTable(TableName.PamAccount, (t) => {+ t.string("discoveryFingerprint").nullable();+ });+ }+}++export async function down(knex: Knex): Promise<void> {+ const hasResourceCol = await knex.schema.hasColumn(TableName.PamResource, "discoveryFingerprint");+ if (hasResourceCol) {+ await knex.schema.alterTable(TableName.PamResource, (t) => {+ t.dropColumn("discoveryFingerprint");+ });+ }++ const hasAccountCol = await knex.schema.hasColumn(TableName.PamAccount, "discoveryFingerprint");+ if (hasAccountCol) {+ await knex.schema.alterTable(TableName.PamAccount, (t) => {+ t.dropColumn("discoveryFingerprint");+ });+ }+}diff --git a/backend/src/db/schemas/pam-accounts.ts b/backend/src/db/schemas/pam-accounts.tsindex 0dd6b39df2..2f9e6fdb1d 100644--- a/backend/src/db/schemas/pam-accounts.ts+++ b/backend/src/db/schemas/pam-accounts.ts@@ -25,7 +25,8 @@ export const PamAccountsSchema = z.object({rotationStatus: z.string().nullable().optional(),encryptedLastRotationMessage: zodBuffer.nullable().optional(),requireMfa: z.boolean().default(false).nullable().optional(),- metadata: z.unknown().nullable().optional()+ metadata: z.unknown().nullable().optional(),+ discoveryFingerprint: z.string().nullable().optional()});export type TPamAccounts = z.infer<typeof PamAccountsSchema>;diff --git a/backend/src/db/schemas/pam-resources.ts b/backend/src/db/schemas/pam-resources.tsindex a1f2bfa7d8..b77d17eda0 100644--- a/backend/src/db/schemas/pam-resources.ts+++ b/backend/src/db/schemas/pam-resources.ts@@ -20,7 +20,8 @@ export const PamResourcesSchema = z.object({updatedAt: z.date(),encryptedRotationAccountCredentials: zodBuffer.nullable().optional(),encryptedResourceMetadata: zodBuffer.nullable().optional(),- adServerResourceId: z.string().uuid().nullable().optional()+ adServerResourceId: z.string().uuid().nullable().optional(),+ discoveryFingerprint: z.string().nullable().optional()});export type TPamResources = z.infer<typeof PamResourcesSchema>;diff --git a/backend/src/ee/routes/v1/pam-discovery-routers/pam-discovery-endpoints.ts b/backend/src/ee/routes/v1/pam-discovery-routers/pam-discovery-endpoints.tsindex c6c2464f5e..44d022b7ca 100644--- a/backend/src/ee/routes/v1/pam-discovery-routers/pam-discovery-endpoints.ts+++ b/backend/src/ee/routes/v1/pam-discovery-routers/pam-discovery-endpoints.ts@@ -1,7 +1,7 @@import { z } from "zod";import { EventType } from "@app/ee/services/audit-log/audit-log-types";-import { PamDiscoveryType } from "@app/ee/services/pam-discovery/pam-discovery-enums";+import { PAM_DISCOVERY_TYPE_PASCAL_MAP, PamDiscoveryType } from "@app/ee/services/pam-discovery/pam-discovery-enums";import {DiscoveredAccountSchema,DiscoveredResourceSchema@@ -39,12 +39,7 @@ export const registerPamDiscoveryEndpoints = <T extends TPamDiscoverySource>({discoveryResponseSchema: z.ZodTypeAny;discoveryRunResponseSchema: z.ZodTypeAny;}) => {- // Convert discovery type enum value to PascalCase for operation IDs- // e.g., "active-directory" -> "ActiveDirectory"- const discoveryTypeId = discoveryType- .split("-")- .map((word) => word.charAt(0).toUpperCase() + word.slice(1))- .join("");+ const discoveryTypeId = PAM_DISCOVERY_TYPE_PASCAL_MAP[discoveryType];server.route({method: "GET",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 8dc14ed712..a6798a3f83 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@@ -297,10 +297,11 @@ const upsertAdServerResource = async (configuration: TAdDiscoveryConfiguration,gatewayId: string,kmsService: Pick<TKmsServiceFactory, "createCipherPairWithDataKey">,- pamResourceDAL: Pick<TPamResourceDALFactory, "create" | "find">,+ pamResourceDAL: Pick<TPamResourceDALFactory, "create" | "find" | "updateById">,tx: Knex) => {const domainResourceName = toSlugName(configuration.domainFQDN);+ const fingerprint = configuration.domainFQDN.toLowerCase();const encryptedConnectionDetails = await encryptResourceConnectionDetails({projectId,@@ -315,13 +316,20 @@ const upsertAdServerResource = async (const existing = await pamResourceDAL.find({projectId,- resourceType: PamResource.ActiveDirectory+ resourceType: PamResource.ActiveDirectory,+ discoveryFingerprint: fingerprint},{ tx });- const matched = existing.find((r) => r.name === domainResourceName);- if (matched) return { resource: matched, isNew: false };+ if (existing.length > 0) {+ const resource = await pamResourceDAL.updateById(+ existing[0].id,+ { name: domainResourceName, encryptedConnectionDetails },+ tx+ );+ return { resource, isNew: false };+ }const resource = await pamResourceDAL.create({@@ -329,7 +337,8 @@ const upsertAdServerResource = async (name: domainResourceName,resourceType: PamResource.ActiveDirectory,gatewayId,- encryptedConnectionDetails+ encryptedConnectionDetails,+ discoveryFingerprint: fingerprint},tx);@@ -343,11 +352,12 @@ const upsertWindowsServerResource = async (adServerResourceId: string,gatewayId: string,kmsService: Pick<TKmsServiceFactory, "createCipherPairWithDataKey">,- pamResourceDAL: Pick<TPamResourceDALFactory, "create" | "find">,+ pamResourceDAL: Pick<TPamResourceDALFactory, "create" | "find" | "updateById">,tx: Knex) => {const hostname = computer.dNSHostName || computer.cn;const resourceName = toSlugName(hostname);+ const fingerprint = computer.objectGUID;const [encryptedConnectionDetails, encryptedResourceMetadata] = await Promise.all([encryptResourceConnectionDetails({@@ -373,13 +383,20 @@ const upsertWindowsServerResource = async ({projectId,resourceType: PamResource.Windows,- name: resourceName,+ discoveryFingerprint: fingerprint,adServerResourceId},{ tx });- if (existing.length > 0) return { resource: existing[0], isNew: false };+ if (existing.length > 0) {+ const resource = await pamResourceDAL.updateById(+ existing[0].id,+ { name: resourceName, encryptedConnectionDetails, encryptedResourceMetadata },+ tx+ );+ return { resource, isNew: false };+ }const resource = await pamResourceDAL.create({@@ -389,7 +406,8 @@ const upsertWindowsServerResource = async (gatewayId,encryptedConnectionDetails,encryptedResourceMetadata,- adServerResourceId+ adServerResourceId,+ discoveryFingerprint: fingerprint},tx);@@ -402,11 +420,12 @@ const upsertDomainAccount = async (user: TLdapUser,adServerResourceId: string,kmsService: Pick<TKmsServiceFactory, "createCipherPairWithDataKey">,- pamAccountDAL: Pick<TPamAccountDALFactory, "create" | "find">,+ pamAccountDAL: Pick<TPamAccountDALFactory, "create" | "find" | "updateById">,tx: Knex) => {const accountName = user.sAMAccountName;const accountType = isServiceAccount(user) ? "service" : "user";+ const fingerprint = user.objectGUID;const encryptedCredentials = await encryptAccountCredentials({projectId,@@ -438,12 +457,19 @@ const upsertDomainAccount = async (const existing = await pamAccountDAL.find({resourceId: adServerResourceId,- name: accountName+ discoveryFingerprint: fingerprint},{ tx });- if (existing.length > 0) return { account: existing[0], isNew: false };+ if (existing.length > 0) {+ const account = await pamAccountDAL.updateById(+ existing[0].id,+ { name: accountName, encryptedCredentials, metadata },+ tx+ );+ return { account, isNew: false };+ }const account = await pamAccountDAL.create({@@ -451,7 +477,8 @@ const upsertDomainAccount = async (resourceId: adServerResourceId,name: accountName,encryptedCredentials,- metadata+ metadata,+ discoveryFingerprint: fingerprint},tx);diff --git a/backend/src/ee/services/pam-discovery/pam-discovery-enums.ts b/backend/src/ee/services/pam-discovery/pam-discovery-enums.tsindex cf705ad06c..68d67ce2ff 100644--- a/backend/src/ee/services/pam-discovery/pam-discovery-enums.ts+++ b/backend/src/ee/services/pam-discovery/pam-discovery-enums.ts@@ -3,6 +3,10 @@ export enum PamDiscoveryType {ActiveDirectory = "active-directory"}+export const PAM_DISCOVERY_TYPE_PASCAL_MAP: Record<PamDiscoveryType, string> = {+ [PamDiscoveryType.ActiveDirectory]: "ActiveDirectory"+};+export enum PamDiscoverySourceStatus {Active = "active",Paused = "paused",diff --git a/backend/src/ee/services/pam-discovery/pam-discovery-factory.ts b/backend/src/ee/services/pam-discovery/pam-discovery-factory.tsindex 1b4d72bab2..4c6a12110e 100644--- a/backend/src/ee/services/pam-discovery/pam-discovery-factory.ts+++ b/backend/src/ee/services/pam-discovery/pam-discovery-factory.ts@@ -27,8 +27,8 @@ export type TPamDiscoveryScanDeps = {"upsertJunction" | "markStaleForRun">;pamAccountDependenciesDAL: Pick<TPamAccountDependenciesDALFactory, "upsertDependency">;- pamResourceDAL: Pick<TPamResourceDALFactory, "create" | "find" | "findById" | "transaction">;- pamAccountDAL: Pick<TPamAccountDALFactory, "create" | "find" | "transaction">;+ pamResourceDAL: Pick<TPamResourceDALFactory, "create" | "find" | "findById" | "updateById" | "transaction">;+ pamAccountDAL: Pick<TPamAccountDALFactory, "create" | "find" | "updateById" | "transaction">;kmsService: Pick<TKmsServiceFactory, "createCipherPairWithDataKey">;gatewayV2Service: Pick<TGatewayV2ServiceFactory, "getPlatformConnectionDetailsByGatewayId">;gatewayV2DAL: Pick<TGatewayV2DALFactory, "findById">;diff --git a/backend/src/ee/services/pam-discovery/pam-discovery-queue.ts b/backend/src/ee/services/pam-discovery/pam-discovery-queue.tsindex 0d79849da7..f98ad7e845 100644--- a/backend/src/ee/services/pam-discovery/pam-discovery-queue.ts+++ b/backend/src/ee/services/pam-discovery/pam-discovery-queue.ts@@ -27,8 +27,8 @@ type TPamDiscoveryQueueFactoryDep = {"upsertJunction" | "markStaleForRun">;pamAccountDependenciesDAL: Pick<TPamAccountDependenciesDALFactory, "upsertDependency">;- pamResourceDAL: Pick<TPamResourceDALFactory, "create" | "find" | "findById" | "transaction">;- pamAccountDAL: Pick<TPamAccountDALFactory, "create" | "find" | "transaction">;+ pamResourceDAL: Pick<TPamResourceDALFactory, "create" | "find" | "findById" | "updateById" | "transaction">;+ pamAccountDAL: Pick<TPamAccountDALFactory, "create" | "find" | "updateById" | "transaction">;kmsService: Pick<TKmsServiceFactory, "createCipherPairWithDataKey">;queueService: TQueueServiceFactory;gatewayV2Service: Pick<TGatewayV2ServiceFactory, "getPlatformConnectionDetailsByGatewayId">;