Skip to content

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

fix(pki-discovery): address review feedback

bernie-g032df1fbc2ff
diff --git a/backend/src/ee/services/pki-discovery/pki-discovery-host-scan-fns.ts b/backend/src/ee/services/pki-discovery/pki-discovery-host-scan-fns.ts
index 88adc73766..480595cc44 100644
--- a/backend/src/ee/services/pki-discovery/pki-discovery-host-scan-fns.ts
+++ b/backend/src/ee/services/pki-discovery/pki-discovery-host-scan-fns.ts
@@ -628,6 +628,7 @@ type THostScanTargetConfig = { connectionIds: string[]; importStandaloneCaCertif
export type THostScanDefinition<TConfig extends THostScanTargetConfig = THostScanTargetConfig> = THostScanType & {
schema: z.ZodTypeAny;
+ hostConcurrency?: number;
scanConnection: (
connection: TAppConnectionRow | undefined,
label: string,
@@ -708,7 +709,7 @@ export const executeHostScan = async <TConfig extends THostScanTargetConfig>(
scanHistoryId = await startScanRun(discoveryId, startedAt, deps);
- const hostLimit = pLimit(HOST_CONCURRENCY);
+ const hostLimit = pLimit(definition.hostConcurrency ?? HOST_CONCURRENCY);
const run: THostScanRun<TConfig> = {
discoveryId,
projectId: discoveryConfig.projectId,
diff --git a/backend/src/ee/services/pki-discovery/pki-discovery-schemas.ts b/backend/src/ee/services/pki-discovery/pki-discovery-schemas.ts
index 7aa37d0171..3fe9d90018 100644
--- a/backend/src/ee/services/pki-discovery/pki-discovery-schemas.ts
+++ b/backend/src/ee/services/pki-discovery/pki-discovery-schemas.ts
@@ -90,7 +90,9 @@ export const WindowsServerTargetConfigSchema = z
.min(1, "Select at least one certificate store")
.refine((stores) => new Set(stores).size === stores.length, "Each certificate store can be listed once")
.default(DEFAULT_WINDOWS_CERTIFICATE_STORES)
- .describe("LocalMachine certificate stores to read."),
+ .describe(
+ "LocalMachine certificate stores to read. CA and Root can be selected only when importStandaloneCaCertificates is true."
+ ),
importStandaloneCaCertificates: z
.boolean()
.default(false)
@@ -103,12 +105,12 @@ export const CA_ONLY_WINDOWS_STORES: readonly WindowsCertificateStore[] = [
WindowsCertificateStore.TrustedRootCertificationAuthorities
];
-export const importsNothingFromWindowsStores = (config: {
+export const selectsCaStoresWithoutImport = (config: {
certificateStores: WindowsCertificateStore[];
importStandaloneCaCertificates: boolean;
}) =>
!config.importStandaloneCaCertificates &&
- config.certificateStores.every((store) => CA_ONLY_WINDOWS_STORES.includes(store));
+ config.certificateStores.some((store) => CA_ONLY_WINDOWS_STORES.includes(store));
// The type-specific schema re-validates on the service; this only keeps the router's shared fields neutral.
export const DiscoveryTargetConfigInputSchema = NetworkTargetConfigSchema.partial()
diff --git a/backend/src/ee/services/pki-discovery/pki-discovery-service.ts b/backend/src/ee/services/pki-discovery/pki-discovery-service.ts
index a9b3d69f05..7289fabbc3 100644
--- a/backend/src/ee/services/pki-discovery/pki-discovery-service.ts
+++ b/backend/src/ee/services/pki-discovery/pki-discovery-service.ts
@@ -30,8 +30,8 @@ import { LINUX_SERVER_SCAN } from "./pki-discovery-host-scan-fns";
import { TPkiDiscoveryScanHistoryDALFactory } from "./pki-discovery-scan-history-dal";
import {
formatTargetConfigIssue,
- importsNothingFromWindowsStores,
- NetworkTargetConfigSchema
+ NetworkTargetConfigSchema,
+ selectsCaStoresWithoutImport
} from "./pki-discovery-schemas";
import {
PkiDiscoveryScanStatus,
@@ -153,11 +153,11 @@ export const pkiDiscoveryServiceFactory = ({
);
if (
discoveryType === PkiDiscoveryType.WindowsServer &&
- importsNothingFromWindowsStores(config as TWindowsServerTargetConfig)
+ selectsCaStoresWithoutImport(config as TWindowsServerTargetConfig)
) {
throw new BadRequestError({
message:
- "The Intermediate and Trusted Root stores only hold CA certificates. Turn on importStandaloneCaCertificates or select another store."
+ "The Intermediate and Trusted Root stores only hold CA certificates. Turn on importStandaloneCaCertificates or remove them from certificateStores."
});
}
const connectionWithoutGateway = connections.find(
diff --git a/backend/src/ee/services/pki-discovery/pki-discovery-windows-scan-fns.test.ts b/backend/src/ee/services/pki-discovery/pki-discovery-windows-scan-fns.test.ts
index 54e59a685c..f6cd80d2ac 100644
--- a/backend/src/ee/services/pki-discovery/pki-discovery-windows-scan-fns.test.ts
+++ b/backend/src/ee/services/pki-discovery/pki-discovery-windows-scan-fns.test.ts
@@ -1,6 +1,6 @@
import { computeLocationFingerprint } from "./pki-discovery-fns";
import { normalizeHostIdentifier } from "./pki-discovery-host-fns";
-import { importsNothingFromWindowsStores, WindowsServerTargetConfigSchema } from "./pki-discovery-schemas";
+import { selectsCaStoresWithoutImport, WindowsServerTargetConfigSchema } from "./pki-discovery-schemas";
import {
HostCertificateChainKind,
HostCertificateFileStatus,
@@ -41,24 +41,22 @@ describe("WindowsServerTargetConfigSchema", () => {
});
});
-describe("importsNothingFromWindowsStores", () => {
- test("flags CA-only store selections without CA import", () => {
- const caOnly = [
- WindowsCertificateStore.IntermediateCertificationAuthorities,
- WindowsCertificateStore.TrustedRootCertificationAuthorities
- ];
- expect(importsNothingFromWindowsStores({ certificateStores: caOnly, importStandaloneCaCertificates: false })).toBe(
+describe("selectsCaStoresWithoutImport", () => {
+ test("flags any CA store selected without CA import", () => {
+ const personal = WindowsCertificateStore.Personal;
+ const root = WindowsCertificateStore.TrustedRootCertificationAuthorities;
+ expect(selectsCaStoresWithoutImport({ certificateStores: [root], importStandaloneCaCertificates: false })).toBe(
true
);
- expect(importsNothingFromWindowsStores({ certificateStores: caOnly, importStandaloneCaCertificates: true })).toBe(
- false
- );
expect(
- importsNothingFromWindowsStores({
- certificateStores: [WindowsCertificateStore.Personal, ...caOnly],
- importStandaloneCaCertificates: false
- })
+ selectsCaStoresWithoutImport({ certificateStores: [personal, root], importStandaloneCaCertificates: false })
+ ).toBe(true);
+ expect(
+ selectsCaStoresWithoutImport({ certificateStores: [personal, root], importStandaloneCaCertificates: true })
).toBe(false);
+ expect(selectsCaStoresWithoutImport({ certificateStores: [personal], importStandaloneCaCertificates: false })).toBe(
+ false
+ );
});
});
diff --git a/backend/src/ee/services/pki-discovery/pki-discovery-windows-scan-fns.ts b/backend/src/ee/services/pki-discovery/pki-discovery-windows-scan-fns.ts
index 6e9f30a145..527eb23726 100644
--- a/backend/src/ee/services/pki-discovery/pki-discovery-windows-scan-fns.ts
+++ b/backend/src/ee/services/pki-discovery/pki-discovery-windows-scan-fns.ts
@@ -43,6 +43,8 @@ const MAX_WINDOWS_SCAN_RESPONSE_BYTES = 24 * 1024 * 1024;
const DEFAULT_WINRM_HTTP_PORT = 5985;
const DEFAULT_WINRM_HTTPS_PORT = 5986;
const MAX_WINDOWS_SCAN_CERTIFICATES = 5000;
+// Matches the gateway's Windows scan slots, so one job never queues past them and reads as busy.
+const WINDOWS_HOST_CONCURRENCY = 4;
const WindowsStoreCertificateSchema = z.object({
store: z.string().max(64),
@@ -367,5 +369,6 @@ const scanWindowsConnection = async (
export const WINDOWS_SERVER_SCAN: THostScanDefinition<TWindowsServerTargetConfig> = {
...WINDOWS_SERVER_SCAN_TYPE,
schema: WindowsServerTargetConfigSchema,
+ hostConcurrency: WINDOWS_HOST_CONCURRENCY,
scanConnection: scanWindowsConnection
};
diff --git a/docs/documentation/platform/pki/discovery/windows-server.mdx b/docs/documentation/platform/pki/discovery/windows-server.mdx
index 42deb5ebd2..46d0d91bf2 100644
--- a/docs/documentation/platform/pki/discovery/windows-server.mdx
+++ b/docs/documentation/platform/pki/discovery/windows-server.mdx
@@ -25,7 +25,7 @@ You choose which stores to scan:
| Intermediate Certification Authorities | No | Intermediate CA certificates |
| Trusted Root Certification Authorities | No | Root CAs the server trusts, including the public ones built into Windows |
-A leaf certificate is imported with its chain, built from the intermediate and root certificates on the server. CA certificates found on their own, such as the certificates in the two certification authority stores, are skipped unless you turn on **Include CA Certificates**.
+A leaf certificate is imported with its chain, built from the intermediate and root certificates on the server. CA certificates found on their own are skipped unless you turn on **Include CA Certificates**. The two certification authority stores hold only CA certificates, so you can select them only when that setting is on.
If the connection's account can't open a store, the scan completes and the job lists the stores it couldn't open.
@@ -41,7 +41,7 @@ If the connection's account can't open a store, the scan completes and the job l
In **Windows (WinRM) Connections**, select the connection for each server to scan.
</Step>
<Step>
- Under **Server Certificate Stores** and **CA Certificate Stores**, select the stores to scan. To also import CA certificates found on their own, turn on **Include CA Certificates**.
+ Under **Server Certificate Stores**, select the stores to scan. To also import CA certificates found on their own, turn on **Include CA Certificates** under **CA Certificate Stores**, then select the CA stores to scan.
</Step>
<Step>
Enter a **Name** and an optional **Description**. To run the job on a schedule, turn on **Scan on a Schedule** and pick a **Scan Interval**.
diff --git a/frontend/src/pages/cert-manager/DiscoveryDetailsByIDPage/components/DiscoveryInstallationsSection.tsx b/frontend/src/pages/cert-manager/DiscoveryDetailsByIDPage/components/DiscoveryInstallationsSection.tsx
index ceb54bed3b..747647ee9a 100644
--- a/frontend/src/pages/cert-manager/DiscoveryDetailsByIDPage/components/DiscoveryInstallationsSection.tsx
+++ b/frontend/src/pages/cert-manager/DiscoveryDetailsByIDPage/components/DiscoveryInstallationsSection.tsx
@@ -1,4 +1,5 @@
import { useState } from "react";
+import { Link } from "@tanstack/react-router";
import { format } from "date-fns";
import {
@@ -106,7 +107,16 @@ export const DiscoveryInstallationsSection = ({ discoveryId, projectId, isScanRu
{installation.primaryCertName ? (
<Tooltip>
<TooltipTrigger asChild>
- <span className="block truncate">{installation.primaryCertName}</span>
+ <Link
+ {...getInstancePinningLink(
+ currentProject.orgId,
+ currentProject,
+ `discovery/installations/${installation.id}`
+ )!}
+ className="block truncate"
+ >
+ {installation.primaryCertName}
+ </Link>
</TooltipTrigger>
<TooltipContent>{installation.primaryCertName}</TooltipContent>
</Tooltip>
diff --git a/frontend/src/pages/cert-manager/DiscoveryPage/components/InstallationsTab.tsx b/frontend/src/pages/cert-manager/DiscoveryPage/components/InstallationsTab.tsx
index 6563f8f8c8..a5ee7cf97c 100644
--- a/frontend/src/pages/cert-manager/DiscoveryPage/components/InstallationsTab.tsx
+++ b/frontend/src/pages/cert-manager/DiscoveryPage/components/InstallationsTab.tsx
@@ -1,4 +1,5 @@
import { useEffect, useState } from "react";
+import { Link } from "@tanstack/react-router";
import { format } from "date-fns";
import { MoreHorizontalIcon, SearchIcon } from "lucide-react";
@@ -209,7 +210,16 @@ export const InstallationsTab = ({ projectId }: Props) => {
{installation.primaryCertName ? (
<Tooltip>
<TooltipTrigger asChild>
- <span className="block truncate">{installation.primaryCertName}</span>
+ <Link
+ {...getInstancePinningLink(
+ currentProject.orgId,
+ currentProject,
+ `discovery/installations/${installation.id}`
+ )!}
+ className="block truncate"
+ >
+ {installation.primaryCertName}
+ </Link>
</TooltipTrigger>
<TooltipContent>{installation.primaryCertName}</TooltipContent>
</Tooltip>