Skip to content

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

fix(pki-discovery): address review feedback

bernie-geaa758c75515
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 f350c90485..62b4461f26 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
@@ -190,6 +190,18 @@ describe("summarizeWindowsScanIssues", () => {
]);
});
+ test("warns when an issuer store has more certificates than the scan reads", () => {
+ expect(
+ summarizeWindowsScanIssues("web-01", {
+ host: { hostname: "web-01" },
+ certificates: [],
+ truncatedIssuerStores: [WindowsCertificateStore.IntermediateCertificationAuthorities]
+ })
+ ).toEqual([
+ "web-01: Intermediate Certification Authorities holds more certificates than the scan reads for chains, so some certificate chains may be incomplete"
+ ]);
+ });
+
test("reports nothing for a clean scan", () => {
expect(summarizeWindowsScanIssues("web-01", { host: { hostname: "web-01" }, certificates: [] })).toEqual([]);
});
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 5dfce135ea..73fb20215c 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
@@ -77,6 +77,7 @@ export const WindowsCertificateScanResponseSchema = z.object({
certificates: z.array(WindowsStoreCertificateSchema).nullish(),
deniedStores: z.array(z.string()).nullish(),
unreadableIssuerStores: z.array(z.string()).nullish(),
+ truncatedIssuerStores: z.array(z.string()).nullish(),
truncatedReason: z.string().max(64).optional()
});
@@ -350,6 +351,16 @@ export const summarizeWindowsScanIssues = (
.join(", ")}, so some certificate chains may be incomplete`
);
}
+ const truncatedIssuers = response.truncatedIssuerStores ?? [];
+ if (truncatedIssuers.length > 0) {
+ issues.push(
+ `${hostIdentifier}: ${truncatedIssuers
+ .map((store) => STORE_NAMES[store] ?? store)
+ .join(
+ ", "
+ )} holds more certificates than the scan reads for chains, so some certificate chains may be incomplete`
+ );
+ }
if (response.truncatedReason === HostScanTruncationReason.MaxFiles) {
issues.push(
`${hostIdentifier}: The scan stopped after ${MAX_WINDOWS_SCAN_CERTIFICATES.toLocaleString("en-US")} certificates`
diff --git a/docs/documentation/platform/pki/discovery/windows-server.mdx b/docs/documentation/platform/pki/discovery/windows-server.mdx
index fbc09bbdd0..dcb8e3fc20 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, such as the certificates in the two certification authority stores, are skipped unless you turn on **Include CA Certificates**.
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>
- In **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** and **CA Certificate Stores**, select the stores to scan. To also import CA certificates found on their own, turn on **Include CA Certificates**.
</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/DiscoveryTargetSection.tsx b/frontend/src/pages/cert-manager/DiscoveryDetailsByIDPage/components/DiscoveryTargetSection.tsx
index a6281f8394..f444fd06ef 100644
--- a/frontend/src/pages/cert-manager/DiscoveryDetailsByIDPage/components/DiscoveryTargetSection.tsx
+++ b/frontend/src/pages/cert-manager/DiscoveryDetailsByIDPage/components/DiscoveryTargetSection.tsx
@@ -117,7 +117,7 @@ const WindowsServerTargetSection = ({ discovery }: Props) => {
</DetailValue>
</Detail>
<Detail>
- <DetailLabel>Include CA certificates</DetailLabel>
+ <DetailLabel>Include CA Certificates</DetailLabel>
<DetailValue>
<Badge variant={targetConfig.importStandaloneCaCertificates ? "success" : "neutral"}>
{targetConfig.importStandaloneCaCertificates ? "Enabled" : "Disabled"}
diff --git a/frontend/src/pages/cert-manager/DiscoveryPage/components/DiscoveryJobSheet/DiscoveryReviewFields.tsx b/frontend/src/pages/cert-manager/DiscoveryPage/components/DiscoveryJobSheet/DiscoveryReviewFields.tsx
index cd12b8461f..26d16e9059 100644
--- a/frontend/src/pages/cert-manager/DiscoveryPage/components/DiscoveryJobSheet/DiscoveryReviewFields.tsx
+++ b/frontend/src/pages/cert-manager/DiscoveryPage/components/DiscoveryJobSheet/DiscoveryReviewFields.tsx
@@ -124,7 +124,7 @@ export const DiscoveryReviewFields = () => {
label="Certificate Stores"
items={values.certificateStores.map((store) => WindowsCertificateStoreLabels[store])}
/>
- <ReviewDetail label="Include CA certificates">
+ <ReviewDetail label="Include CA Certificates">
<Badge variant={values.importStandaloneCaCertificates ? "success" : "neutral"}>
{values.importStandaloneCaCertificates ? "Enabled" : "Disabled"}
</Badge>
diff --git a/frontend/src/pages/cert-manager/DiscoveryPage/components/DiscoveryJobSheet/HostConnectionsFields.tsx b/frontend/src/pages/cert-manager/DiscoveryPage/components/DiscoveryJobSheet/HostConnectionsFields.tsx
index a255c3e5a6..6689628e0e 100644
--- a/frontend/src/pages/cert-manager/DiscoveryPage/components/DiscoveryJobSheet/HostConnectionsFields.tsx
+++ b/frontend/src/pages/cert-manager/DiscoveryPage/components/DiscoveryJobSheet/HostConnectionsFields.tsx
@@ -14,24 +14,20 @@ import {
TooltipContent,
TooltipTrigger
} from "@app/components/v3";
-import { ProjectPermissionSub, useProject, useProjectPermission } from "@app/context";
-import { ProjectPermissionAppConnectionActions } from "@app/context/ProjectPermissionContext/types";
-import { usePopUp } from "@app/hooks";
+import { useProject } from "@app/context";
import {
TAvailableAppConnection,
useListAvailableAppConnectionsForApps
} from "@app/hooks/api/appConnections";
import { AppConnection } from "@app/hooks/api/appConnections/enums";
import { gatewaysQueryKeys } from "@app/hooks/api/gateways/queries";
-import { AddAppConnectionModal } from "@app/pages/organization/AppConnections/AppConnectionsPage/components";
+import { useConnectionCreation } from "@app/pages/cert-manager/CertificateAuthoritiesPage/components/CaInstallCertModal/useConnectionCreation";
import { THostDiscoveryJobForm } from "./discovery-job-form-schema";
type TConnectionOption = Pick<TAvailableAppConnection, "id" | "name"> &
Partial<TAvailableAppConnection>;
-const CREATE_OPTION_ID = "_create";
-
type Props = {
app: AppConnection.SSH | AppConnection.WinRM;
connectionLabel: string;
@@ -39,10 +35,8 @@ type Props = {
};
export const HostConnectionsFields = ({ app, connectionLabel, capability }: Props) => {
- const { permission } = useProjectPermission();
const { currentProject } = useProject();
const { control, getValues, setValue, setError } = useFormContext<THostDiscoveryJobForm>();
- const { popUp, handlePopUpToggle, handlePopUpOpen } = usePopUp(["addConnection"] as const);
const { connections, isPending } = useListAvailableAppConnectionsForApps(
[app],
@@ -50,11 +44,6 @@ export const HostConnectionsFields = ({ app, connectionLabel, capability }: Prop
);
const { data: gateways } = useQuery(gatewaysQueryKeys.list());
- const canCreateConnection = permission.can(
- ProjectPermissionAppConnectionActions.Create,
- ProjectPermissionSub.AppConnections
- );
-
const incapableGatewayIds = new Set(
(gateways ?? [])
.filter((gateway) => gateway.capabilities?.[capability] !== true)
@@ -65,24 +54,41 @@ export const HostConnectionsFields = ({ app, connectionLabel, capability }: Prop
connections.map((connection) => [connection.id, connection])
);
const resolveOption = (option: TConnectionOption) => connectionsById.get(option.id) ?? option;
- const isMissingGateway = (option: TConnectionOption) => {
- const connection = resolveOption(option);
- return connection.id !== CREATE_OPTION_ID && !connection.gatewayId && !connection.gatewayPoolId;
- };
- const isGatewayOutdated = (option: TConnectionOption) => {
- const connection = resolveOption(option);
- return Boolean(connection.gatewayId) && incapableGatewayIds.has(connection.gatewayId as string);
- };
+ const hasNoGateway = (connection: Pick<TConnectionOption, "gatewayId" | "gatewayPoolId">) =>
+ !connection.gatewayId && !connection.gatewayPoolId;
+ const hasOutdatedGateway = (connection: Pick<TConnectionOption, "gatewayId">) =>
+ Boolean(connection.gatewayId) && incapableGatewayIds.has(connection.gatewayId as string);
+ const isMissingGateway = (option: TConnectionOption) => hasNoGateway(resolveOption(option));
+ const isGatewayOutdated = (option: TConnectionOption) =>
+ hasOutdatedGateway(resolveOption(option));
const isUnusable = (option: TConnectionOption) =>
isMissingGateway(option) || isGatewayOutdated(option);
const connectionOptions: TConnectionOption[] = [
- ...(canCreateConnection
- ? [{ id: CREATE_OPTION_ID, name: `Create ${connectionLabel} Connection` }]
- : []),
...connections.filter((connection) => !isUnusable(connection)),
...connections.filter(isUnusable)
];
+ const creation = useConnectionCreation(app, (connection) => {
+ if (hasNoGateway(connection)) {
+ setError("connections", {
+ message: `${connectionLabel} connection '${connection.name}' has no gateway. Add one to the connection to scan this server.`
+ });
+ return;
+ }
+ if (hasOutdatedGateway(connection)) {
+ setError("connections", {
+ message: `The gateway on ${connectionLabel} connection '${connection.name}' is too old for certificate scanning. Update it to the latest version.`
+ });
+ return;
+ }
+ const existing = getValues("connections") ?? [];
+ if (existing.some((c) => c.id === connection.id)) return;
+ setValue("connections", [...existing, { id: connection.id, name: connection.name }], {
+ shouldDirty: true,
+ shouldValidate: true
+ });
+ });
+
return (
<>
<Controller
@@ -95,13 +101,7 @@ export const HostConnectionsFields = ({ app, connectionLabel, capability }: Prop
<Combobox
multiple
value={value}
- onValueChange={(next) => {
- if (next.some((option) => option.id === CREATE_OPTION_ID)) {
- handlePopUpOpen("addConnection");
- return;
- }
- onChange(next.map(({ id, name }) => ({ id, name })));
- }}
+ onValueChange={(next) => onChange(next.map(({ id, name }) => ({ id, name })))}
isLoading={isPending}
isError={Boolean(error)}
options={connectionOptions}
@@ -109,6 +109,7 @@ export const HostConnectionsFields = ({ app, connectionLabel, capability }: Prop
getOptionLabel={(option) => option.name}
getOptionValue={(option) => option.id}
isOptionDisabled={isUnusable}
+ creation={creation}
renderOption={(option) => {
let unusableLabel: string | null = null;
let unusableHint: string | null = null;
@@ -123,10 +124,6 @@ export const HostConnectionsFields = ({ app, connectionLabel, capability }: Prop
return (
<AppConnectionOptionContent
data={resolveOption(option)}
- createLabel={`Create ${connectionLabel} Connection`}
- isOnlyOption={
- option.id === CREATE_OPTION_ID && connectionOptions.length === 1
- }
label={
unusableLabel && (
<Tooltip>
@@ -155,34 +152,13 @@ export const HostConnectionsFields = ({ app, connectionLabel, capability }: Prop
</Field>
)}
/>
- {!isPending && !connections.length && !canCreateConnection && (
+ {!isPending && !connections.length && !creation && (
<p className="mt-2 flex items-center gap-1.5 text-xs text-warning">
<Info className="size-3.5" />
You do not have access to any {connectionLabel} Connections. Contact an admin to create
one.
</p>
)}
- <AddAppConnectionModal
- isOpen={popUp.addConnection.isOpen}
- onOpenChange={(isOpen) => handlePopUpToggle("addConnection", isOpen)}
- projectType={currentProject.type}
- projectId={currentProject.id}
- app={app}
- onComplete={(connection) => {
- const existing = getValues("connections") ?? [];
- if (existing.some((c) => c.id === connection.id)) return;
- if (!connection.gatewayId && !connection.gatewayPoolId) {
- setError("connections", {
- message: `${connectionLabel} connection '${connection.name}' has no gateway. Add one to the connection to scan this server.`
- });
- return;
- }
- setValue("connections", [...existing, { id: connection.id, name: connection.name }], {
- shouldDirty: true,
- shouldValidate: true
- });
- }}
- />
</>
);
};
diff --git a/frontend/src/pages/cert-manager/DiscoveryPage/components/DiscoveryJobSheet/WindowsServerStoresFields.tsx b/frontend/src/pages/cert-manager/DiscoveryPage/components/DiscoveryJobSheet/WindowsServerStoresFields.tsx
index 86ba2f286e..458a6bb16f 100644
--- a/frontend/src/pages/cert-manager/DiscoveryPage/components/DiscoveryJobSheet/WindowsServerStoresFields.tsx
+++ b/frontend/src/pages/cert-manager/DiscoveryPage/components/DiscoveryJobSheet/WindowsServerStoresFields.tsx
@@ -7,9 +7,9 @@ import {
FieldDescription,
FieldError,
FieldGroup,
- FieldLabel,
FieldLegend,
FieldSet,
+ FieldTitle,
Toggle
} from "@app/components/v3";
import {
@@ -54,6 +54,7 @@ const StoreOptions = ({ stores, value, onChange }: StoreOptionsProps) => (
<Field key={store} orientation="horizontal">
<Checkbox
id={id}
+ aria-labelledby={`${id}-title`}
variant="project"
isChecked={value.includes(store)}
onCheckedChange={(checked) =>
@@ -65,9 +66,7 @@ const StoreOptions = ({ stores, value, onChange }: StoreOptionsProps) => (
}
/>
<FieldContent>
- <FieldLabel htmlFor={id} className="cursor-pointer text-sm font-medium text-foreground">
- {WindowsCertificateStoreLabels[store]}
- </FieldLabel>
+ <FieldTitle id={`${id}-title`}>{WindowsCertificateStoreLabels[store]}</FieldTitle>
<FieldDescription>{STORE_DESCRIPTIONS[store]}</FieldDescription>
</FieldContent>
</Field>
@@ -98,12 +97,7 @@ export const WindowsServerStoresFields = () => {
render={({ field: { value: includeCa, onChange: setIncludeCa } }) => (
<Field orientation="horizontal" className="mt-2">
<FieldContent>
- <FieldLabel
- htmlFor="import-standalone-ca"
- className="cursor-pointer text-sm font-medium text-foreground"
- >
- Include CA certificates
- </FieldLabel>
+ <FieldTitle id="import-standalone-ca-title">Include CA Certificates</FieldTitle>
<FieldDescription>
Import the CA certificates in the selected stores. A leaf certificate always
comes in with its chain.
@@ -111,6 +105,7 @@ export const WindowsServerStoresFields = () => {
</FieldContent>
<Toggle
id="import-standalone-ca"
+ aria-labelledby="import-standalone-ca-title"
variant="project"
checked={includeCa}
onCheckedChange={(checked) => {
diff --git a/frontend/src/pages/cert-manager/DiscoveryPage/components/DiscoveryJobSheet/discovery-job-form-schema.ts b/frontend/src/pages/cert-manager/DiscoveryPage/components/DiscoveryJobSheet/discovery-job-form-schema.ts
index 019e043a8c..ba888c77d5 100644
--- a/frontend/src/pages/cert-manager/DiscoveryPage/components/DiscoveryJobSheet/discovery-job-form-schema.ts
+++ b/frontend/src/pages/cert-manager/DiscoveryPage/components/DiscoveryJobSheet/discovery-job-form-schema.ts
@@ -191,7 +191,7 @@ export const DiscoveryJobFormSchema = z
code: z.ZodIssueCode.custom,
path: ["certificateStores"],
message:
- "These stores only hold CA certificates. Turn on Include CA certificates or select another store."
+ "These stores only hold CA certificates. Turn on Include CA Certificates or select another store."
});
}
});