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
Merge remote-tracking branch 'origin/main' into bernie/pki-516-veria-159-pki-discovery-scans-private-ip-ranges-from
bernie-gdc6f91156f8e
diff --cc backend/src/ee/services/pki-discovery/pki-discovery-scan-fns.tsindex f9e1b84898,90267a0ea9..81161fcfbe--- a/backend/src/ee/services/pki-discovery/pki-discovery-scan-fns.ts+++ b/backend/src/ee/services/pki-discovery/pki-discovery-scan-fns.ts@@@ -21,15 -23,19 +23,25 @@@ import { TTelemetryServiceFactory } froimport { TPkiCertificateInstallationCertDALFactory } from "./pki-certificate-installation-cert-dal";import { TPkiCertificateInstallationDALFactory } from "./pki-certificate-installation-dal";import { TPkiDiscoveryConfigDALFactory } from "./pki-discovery-config-dal";-import { computeLocationFingerprint, resolveDomain, resolveTargets, scanEndpoint } from "./pki-discovery-fns";+import {+ computeLocationFingerprint,+ getPrivateIpRangeError,+ resolveDomain,+ resolveTargets,+ scanEndpoint+} from "./pki-discovery-fns";import { TPkiDiscoveryInstallationDALFactory } from "./pki-discovery-installation-dal";import { TPkiDiscoveryScanHistoryDALFactory } from "./pki-discovery-scan-history-dal";+ import {+ DB_SHORT_VARCHAR_LIMIT,+ DB_VARCHAR_LIMIT,+ discardScanRunIfDeleted,+ failScanRun,+ finishScanRun,+ sendScanCompletedTelemetry,+ startScanRun,+ truncateString+ } from "./pki-discovery-scan-run-fns";import {CertificateSource,PkiDiscoveryScanStatus,@@@ -150,16 -156,8 +162,16 @@@ export const executeScan = async (discogatewayName = gw?.name;}- const targetConfig = discoveryConfig.targetConfig as TPkiDiscoveryTargetConfig;+ const targetConfig = discoveryConfig.targetConfig as TNetworkTargetConfig;const hasGateway = !!effectiveGatewayId;++ // The gateway FK is ON DELETE SET NULL, so a config saved with private ranges can lose its gateway later.+ if (getPrivateIpRangeError(targetConfig.ipRanges, hasGateway)) {+ throw new Error(+ "This job targets private IP addresses but has no gateway attached. Attach a gateway or gateway pool to scan private networks."+ );+ }+const targets = await resolveTargets(targetConfig, hasGateway);const uniqueHosts = new Set(targets.map((t) => t.host)).size;diff --cc backend/src/ee/services/pki-discovery/pki-discovery-service.tsindex f2434904ed,d513562b09..ec9271925f--- a/backend/src/ee/services/pki-discovery/pki-discovery-service.ts+++ b/backend/src/ee/services/pki-discovery/pki-discovery-service.ts@@@ -244,19 -326,30 +326,37 @@@ export const pkiDiscoveryServiceFactorProjectPermissionSub.PkiDiscovery);+ const discoveryType = (discovery.discoveryType as PkiDiscoveryType) || PkiDiscoveryType.Network;- const effectiveHasGateway =- gatewayId !== undefined || gatewayPoolId !== undefined- ? Boolean(gatewayId || gatewayPoolId)- : Boolean(discovery.gatewayId || discovery.gatewayPoolId);+ const gatewayIdValue = gatewayPoolId ? null : gatewayId;+ const gatewayPoolIdValue = gatewayId ? null : gatewayPoolId;++ const isGatewayChanging = gatewayIdValue !== undefined || gatewayPoolIdValue !== undefined;++ const effectiveHasGateway = Boolean(++ (gatewayIdValue === undefined ? discovery.gatewayId : gatewayIdValue) ||++ (gatewayPoolIdValue === undefined ? discovery.gatewayPoolId : gatewayPoolIdValue)++ );- if (targetConfig || gatewayIdValue !== undefined || gatewayPoolIdValue !== undefined) {- const effectiveGatewayId = gatewayIdValue === undefined ? discovery.gatewayId : gatewayIdValue;- const effectiveGatewayPoolId = gatewayPoolIdValue === undefined ? discovery.gatewayPoolId : gatewayPoolIdValue;- validateTargetConfigForType(- (discovery.discoveryType as PkiDiscoveryType) || PkiDiscoveryType.Network,- targetConfig ?? (discovery.targetConfig as TPkiDiscoveryTargetConfig),- Boolean(effectiveGatewayId || effectiveGatewayPoolId)- );+ $assertJobGatewayAllowed(discoveryType, Boolean(gatewayId || gatewayPoolId));++ const existingConnectionIds =+ discoveryType === PkiDiscoveryType.LinuxServer+ ? (discovery.targetConfig as TLinuxServerTargetConfig).connectionIds+ : undefined;++ const validatedTargetConfig = targetConfig+ ? await $validateTarget({+ discoveryType,+ targetConfig,+ hasGateway: effectiveHasGateway,+ projectId: discovery.projectId,+ actor: orgActor,+ existingConnectionIds+ })+ : undefined;+++ if (!targetConfig && isGatewayChanging && discoveryType === PkiDiscoveryType.Network) {++ $validateNetworkTarget(discovery.targetConfig as TPkiDiscoveryTargetConfig, effectiveHasGateway);+ }+if (gatewayId) {const gateway = await gatewayV2DAL.findOne({ id: gatewayId, orgId: actorOrgId });if (!gateway) {