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 PR comments
Carlos Monastyrski9cec645cd743
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.tsindex cf9b76e10e..6755d67656 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@@ -9,7 +9,9 @@ import { TGatewayV2DALFactory } from "@app/ee/services/gateway-v2/gateway-v2-dalimport { TGatewayV2ServiceFactory } from "@app/ee/services/gateway-v2/gateway-v2-service";import { TKeyStoreFactory } from "@app/keystore/keystore";import { delay } from "@app/lib/delay";+import { DatabaseErrorCode } from "@app/lib/error-codes";import { BadRequestError, GatewayTransportError, NotFoundError } from "@app/lib/errors";+import { hasPostgresErrorCode } from "@app/lib/errors/postgres";import { callCertificateScan, TCertificateScanRequest } from "@app/lib/gateway-v2/certificate-scan-rpc";import { getMissingGatewayMessage } from "@app/lib/gateway-v2/gateway-errors";import { withGatewayV2Proxy } from "@app/lib/gateway-v2/gateway-v2";@@ -395,19 +397,32 @@ const upsertInstallationWithLinks = async (};if (!installation) {- installation = await deps.pkiCertificateInstallationDAL.create(- {- projectId: ctx.projectId,- locationType,- locationDetails,- locationFingerprint: fingerprint,- name: buildHostInstallationName(host.hostIdentifier, host.hostname, file.realPath),- type: PkiInstallationType.Server,- metadata,- lastSeenAt: ctx.scanTime- },- tx- );+ try {+ installation = await tx.transaction((sp) =>+ deps.pkiCertificateInstallationDAL.create(+ {+ projectId: ctx.projectId,+ locationType,+ locationDetails,+ locationFingerprint: fingerprint,+ name: buildHostInstallationName(host.hostIdentifier, host.hostname, file.realPath),+ type: PkiInstallationType.Server,+ metadata,+ lastSeenAt: ctx.scanTime+ },+ sp+ )+ );+ } catch (error) {+ if (!hasPostgresErrorCode(error, DatabaseErrorCode.UniqueViolation)) throw error;+ installation = await findTargetInstallation(ctx, fingerprint, deps, tx);+ if (!installation) throw error;+ await deps.pkiCertificateInstallationDAL.updateById(+ installation.id,+ { lastSeenAt: ctx.scanTime, locationDetails, locationType, metadata },+ tx+ );+ }} else {await deps.pkiCertificateInstallationDAL.updateById(installation.id,@@ -519,10 +534,18 @@ const scanConnection = async (await run.writeLimit(async () => {for (const file of response.files) {- // eslint-disable-next-line no-await-in-loop- const result = await writeHostFile({ ...host, hostname: response.host.hostname }, file, run.ctx, deps);- if (result.installationId) run.installationIds.add(result.installationId);- result.certificateIds.forEach((id) => run.certificateIds.add(id));+ try {+ // eslint-disable-next-line no-await-in-loop+ const result = await writeHostFile({ ...host, hostname: response.host.hostname }, file, run.ctx, deps);+ if (result.installationId) run.installationIds.add(result.installationId);+ result.certificateIds.forEach((id) => run.certificateIds.add(id));+ } catch (error) {+ const message = toHostScanErrorMessage(+ error,+ `Linux Server discovery file import failed [discoveryId=${run.discoveryId}] [host=${host.hostIdentifier}] [file=${file.realPath}]`+ );+ issues.push(`${host.hostIdentifier} (${file.realPath}): ${message}`);+ }}});return { issues };diff --git a/docs/documentation/platform/pki/discovery/linux-server.mdx b/docs/documentation/platform/pki/discovery/linux-server.mdxindex d161c7be22..fd789a9ca1 100644--- a/docs/documentation/platform/pki/discovery/linux-server.mdx+++ b/docs/documentation/platform/pki/discovery/linux-server.mdx@@ -19,7 +19,7 @@ Linux Server discovery finds the certificates stored in files and keystores on yEach certificate file becomes an installation named after the server's hostname and the file path, for example `web-01:/etc/nginx/ssl/fullchain.pem`.-A leaf certificate is imported with the CA certificates in the same file. Files that hold only CA certificates, such as trust bundles, are skipped unless you turn on **Import CA Certificates Found on Their Own**.+A leaf certificate is imported with the CA certificates in the same file. Files that hold only CA certificates, such as trust bundles, are skipped unless you turn on **Include trust stores and CA bundles**.Scans only open files with these extensions: `.pem`, `.crt`, `.cer`, `.cert`, `.der`, `.p7b`, `.p7c`, `.pfx`, `.p12`, `.jks`, `.keystore`, `.truststore`, `.jceks`, `.ks`, and files named `cacerts`.diff --git a/frontend/src/pages/cert-manager/DiscoveryDetailsByIDPage/components/DiscoveryScanLogsSection.tsx b/frontend/src/pages/cert-manager/DiscoveryDetailsByIDPage/components/DiscoveryScanLogsSection.tsxindex aacfe9cf09..a04351266f 100644--- a/frontend/src/pages/cert-manager/DiscoveryDetailsByIDPage/components/DiscoveryScanLogsSection.tsx+++ b/frontend/src/pages/cert-manager/DiscoveryDetailsByIDPage/components/DiscoveryScanLogsSection.tsx@@ -112,11 +112,11 @@ export const DiscoveryScanLogsSection = ({{scans.map((scan) => {const duration =scan.completedAt && scan.startedAt- ? Math.round(+ ? ((new Date(scan.completedAt).getTime() -new Date(scan.startedAt).getTime()) /- 1000- )+ 1000+ ).toFixed(1): null;return (diff --git a/frontend/src/pages/cert-manager/DiscoveryDetailsByIDPage/components/DiscoveryTargetSection.tsx b/frontend/src/pages/cert-manager/DiscoveryDetailsByIDPage/components/DiscoveryTargetSection.tsxindex 23894c6e0d..ad4967ff48 100644--- a/frontend/src/pages/cert-manager/DiscoveryDetailsByIDPage/components/DiscoveryTargetSection.tsx+++ b/frontend/src/pages/cert-manager/DiscoveryDetailsByIDPage/components/DiscoveryTargetSection.tsx@@ -68,11 +68,7 @@ const LinuxServerTargetSection = ({ discovery }: Props) => {<DetailValue>{targetConfig.maxFolderDepth}</DetailValue></Detail><Detail>- <DetailLabel>Largest File</DetailLabel>- <DetailValue>{targetConfig.maxFileSizeKb} KB</DetailValue>- </Detail>- <Detail>- <DetailLabel>Import CA Certificates Found on Their Own</DetailLabel>+ <DetailLabel>Include trust stores and CA bundles</DetailLabel><DetailValue><Badge variant={targetConfig.importStandaloneCaCertificates ? "success" : "neutral"}>{targetConfig.importStandaloneCaCertificates ? "Enabled" : "Disabled"}diff --git a/frontend/src/pages/cert-manager/DiscoveryPage/components/DiscoveryJobSheet/DiscoveryJobForm.tsx b/frontend/src/pages/cert-manager/DiscoveryPage/components/DiscoveryJobSheet/DiscoveryJobForm.tsxindex 1086bf0b5e..09f01abdb0 100644--- a/frontend/src/pages/cert-manager/DiscoveryPage/components/DiscoveryJobSheet/DiscoveryJobForm.tsx+++ b/frontend/src/pages/cert-manager/DiscoveryPage/components/DiscoveryJobSheet/DiscoveryJobForm.tsx@@ -98,7 +98,7 @@ const STEP_FIELDS: Record<DiscoveryJobStep, FieldPath<TDiscoveryJobForm>[]> = {[DiscoveryJobStep.Targets]: ["targets", "ports", "gatewayId", "gatewayPoolId"],[DiscoveryJobStep.Hosts]: ["connections"],[DiscoveryJobStep.Folders]: ["searchFolderPaths", "skipFolderPaths"],- [DiscoveryJobStep.Options]: ["maxFolderDepth", "maxFileSizeKb", "importStandaloneCaCertificates"],+ [DiscoveryJobStep.Options]: ["maxFolderDepth", "importStandaloneCaCertificates"],[DiscoveryJobStep.Details]: ["name", "description", "isAutoScanEnabled", "scanIntervalDays"],[DiscoveryJobStep.Review]: []};@@ -156,11 +156,16 @@ export const DiscoveryJobForm = ({const { handleSubmit, trigger, formState } = formMethods;const isPending = createDiscovery.isPending || updateDiscovery.isPending;- const steps = getSteps(discoveryType);+ const steps = isEditing+ ? getSteps(discoveryType).filter((step) => step !== DiscoveryJobStep.Review)+ : getSteps(discoveryType);const currentKey = steps[stepIndex];const currentStep = STEP_META[currentKey];const isFinalStep = stepIndex === steps.length - 1;+ let footerStatus = `${PKI_DISCOVERY_TYPE_MAP[discoveryType].name} · Step ${stepIndex + 1} of ${steps.length}`;+ if (isEditing) footerStatus = formState.isDirty ? "Unsaved changes" : "";+useEffect(() => {onDirtyChange(formState.isDirty);}, [formState.isDirty]);@@ -223,13 +228,14 @@ export const DiscoveryJobForm = ({<div className="flex min-h-0 flex-1 overflow-hidden"><aside className="flex w-60 shrink-0 flex-col border-r border-border px-5 py-6"><p className="mb-5 text-[11px] font-medium tracking-wider text-muted uppercase">- Setup steps+ {isEditing ? "Sections" : "Setup steps"}</p><StepperactiveStep={stepIndex}orientation="vertical"+ nonLinear={isEditing}onStepChange={(index) => {- if (index < stepIndex) setStepIndex(index);+ if (isEditing || index < stepIndex) setStepIndex(index);}}><StepperList>@@ -278,24 +284,39 @@ export const DiscoveryJobForm = ({</FormProvider><div className="flex shrink-0 items-center justify-between gap-3 border-t border-border px-6 py-4">- <span className="text-xs text-muted">- {PKI_DISCOVERY_TYPE_MAP[discoveryType].name} · Step {stepIndex + 1} of {steps.length}- </span>- <div className="flex items-center gap-3">- <Button type="button" variant="outline" onClick={handleBack}>- {stepIndex === 0 ? "Cancel" : "Back"}- </Button>- <Button- type="button"- variant="project"- onClick={handleNext}- isPending={isFinalStep && isPending}- isDisabled={isFinalStep && isPending}- >- {!isFinalStep && "Continue"}- {isFinalStep && (isEditing ? "Save Changes" : "Create Job")}- </Button>- </div>+ <span className="text-xs text-muted">{footerStatus}</span>+ {isEditing ? (+ <div className="flex items-center gap-3">+ <Button type="button" variant="outline" onClick={onCancel}>+ Cancel+ </Button>+ <Button+ type="button"+ variant="project"+ onClick={() => handleSubmit(onSubmit)().catch(() => undefined)}+ isPending={isPending}+ isDisabled={!formState.isDirty || isPending}+ >+ Save Changes+ </Button>+ </div>+ ) : (+ <div className="flex items-center gap-3">+ <Button type="button" variant="outline" onClick={handleBack}>+ {stepIndex === 0 ? "Cancel" : "Back"}+ </Button>+ <Button+ type="button"+ variant="project"+ onClick={handleNext}+ isPending={isFinalStep && isPending}+ isDisabled={isFinalStep && isPending}+ >+ {!isFinalStep && "Continue"}+ {isFinalStep && "Create Job"}+ </Button>+ </div>+ )}</div></form>);diff --git a/frontend/src/pages/cert-manager/DiscoveryPage/components/DiscoveryJobSheet/DiscoveryReviewFields.tsx b/frontend/src/pages/cert-manager/DiscoveryPage/components/DiscoveryJobSheet/DiscoveryReviewFields.tsxindex e7bef72a8a..b5aaf607ba 100644--- a/frontend/src/pages/cert-manager/DiscoveryPage/components/DiscoveryJobSheet/DiscoveryReviewFields.tsx+++ b/frontend/src/pages/cert-manager/DiscoveryPage/components/DiscoveryJobSheet/DiscoveryReviewFields.tsx@@ -1,5 +1,6 @@import { ReactNode } from "react";import { useFormContext } from "react-hook-form";+import { useQuery } from "@tanstack/react-query";import {Badge,@@ -11,6 +12,8 @@ import {OverflowBadgeList} from "@app/components/v3";import { PKI_DISCOVERY_TYPE_MAP } from "@app/helpers/pkiDiscovery";+import { gatewayPoolsQueryKeys } from "@app/hooks/api/gateway-pools/queries";+import { gatewaysQueryKeys } from "@app/hooks/api/gateways/queries";import { PkiDiscoveryType } from "@app/hooks/api/pkiDiscovery/types";import { getItemLabel } from "@app/pages/cert-manager/pki-discovery-utils";@@ -48,10 +51,25 @@ export const DiscoveryReviewFields = () => {const { watch } = useFormContext<TDiscoveryJobForm>();const values = watch();+ const isNetwork = values.discoveryType === PkiDiscoveryType.Network;+ const { data: gateways } = useQuery({+ ...gatewaysQueryKeys.list(),+ enabled: isNetwork && Boolean(values.gatewayId)+ });+ const { data: pools } = useQuery({+ ...gatewayPoolsQueryKeys.list(),+ enabled: isNetwork && Boolean(values.gatewayPoolId)+ });+let gatewayLabel: string | undefined;- if (values.discoveryType === PkiDiscoveryType.Network) {- if (values.gatewayPoolId) gatewayLabel = "Gateway pool";- else if (values.gatewayId) gatewayLabel = "Gateway";+ if (isNetwork) {+ if (values.gatewayPoolId) {+ gatewayLabel =+ pools?.find((pool) => pool.id === values.gatewayPoolId)?.name ?? "Gateway pool";+ } else if (values.gatewayId) {+ gatewayLabel =+ gateways?.find((gateway) => gateway.id === values.gatewayId)?.name ?? "Gateway";+ }}const networkTargets =@@ -85,8 +103,7 @@ export const DiscoveryReviewFields = () => {</ReviewGroup><ReviewGroup title="Options"><ReviewDetail label="Folder Depth">{String(values.maxFolderDepth)}</ReviewDetail>- <ReviewDetail label="Largest File">{`${values.maxFileSizeKb} KB`}</ReviewDetail>- <ReviewDetail label="Import CA Certificates Found on Their Own">+ <ReviewDetail label="Include trust stores and CA bundles"><Badge variant={values.importStandaloneCaCertificates ? "success" : "neutral"}>{values.importStandaloneCaCertificates ? "Enabled" : "Disabled"}</Badge>diff --git a/frontend/src/pages/cert-manager/DiscoveryPage/components/DiscoveryJobSheet/LinuxServerHostsFields.tsx b/frontend/src/pages/cert-manager/DiscoveryPage/components/DiscoveryJobSheet/LinuxServerHostsFields.tsxindex c59b63ca3d..b39511751b 100644--- a/frontend/src/pages/cert-manager/DiscoveryPage/components/DiscoveryJobSheet/LinuxServerHostsFields.tsx+++ b/frontend/src/pages/cert-manager/DiscoveryPage/components/DiscoveryJobSheet/LinuxServerHostsFields.tsx@@ -1,4 +1,5 @@import { Controller, useFormContext } from "react-hook-form";+import { useQuery } from "@tanstack/react-query";import { Info } from "lucide-react";import { AppConnectionOptionContent } from "@app/components/app-connections";@@ -18,6 +19,7 @@ import {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 { TLinuxServerDiscoveryJobForm } from "./discovery-job-form-schema";@@ -37,12 +39,19 @@ export const LinuxServerHostsFields = () => {[AppConnection.SSH],currentProject.id);+ const { data: gateways } = useQuery(gatewaysQueryKeys.list());const canCreateConnection = permission.can(ProjectPermissionAppConnectionActions.Create,ProjectPermissionSub.AppConnections);+ const incapableGatewayIds = new Set(+ (gateways ?? [])+ .filter((gateway) => gateway.capabilities?.certificateScan !== true)+ .map((gateway) => gateway.id)+ );+const connectionsById = new Map<string, TConnectionOption>(connections.map((connection) => [connection.id, connection]));@@ -51,10 +60,16 @@ export const LinuxServerHostsFields = () => {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 isUnusable = (option: TConnectionOption) =>+ isMissingGateway(option) || isGatewayOutdated(option);const connectionOptions: TConnectionOption[] = [...(canCreateConnection ? [{ id: CREATE_OPTION_ID, name: "Create SSH Connection" }] : []),- ...connections.filter((connection) => !isMissingGateway(connection)),- ...connections.filter(isMissingGateway)+ ...connections.filter((connection) => !isUnusable(connection)),+ ...connections.filter(isUnusable)];return (@@ -82,26 +97,32 @@ export const LinuxServerHostsFields = () => {placeholder="Select connections..."getOptionLabel={(option) => option.name}getOptionValue={(option) => option.id}- isOptionDisabled={isMissingGateway}- renderOption={(option) => (- <AppConnectionOptionContent- data={resolveOption(option)}- createLabel="Create SSH Connection"- isOnlyOption={option.id === CREATE_OPTION_ID && connectionOptions.length === 1}- label={- isMissingGateway(option) && (- <span className="mr-2 shrink-0 text-xs text-muted">No gateway</span>- )- }- />- )}+ isOptionDisabled={isUnusable}+ renderOption={(option) => {+ let unusableLabel: string | null = null;+ if (isMissingGateway(option)) unusableLabel = "No gateway";+ else if (isGatewayOutdated(option)) unusableLabel = "Update gateway";+ return (+ <AppConnectionOptionContent+ data={resolveOption(option)}+ createLabel="Create SSH Connection"+ isOnlyOption={+ option.id === CREATE_OPTION_ID && connectionOptions.length === 1+ }+ label={+ unusableLabel && (+ <span className="mr-2 shrink-0 text-xs text-muted">{unusableLabel}</span>+ )+ }+ />+ );+ }}includeMissingSelectedOptionsmodal/>{!error?.message && (<FieldDescription>- Each connection is one server. It must use a gateway, and the scan runs from that- gateway.+ One connection per server. Only connections that use a gateway can be selected</FieldDescription>)}<FieldError errors={[error]} />diff --git a/frontend/src/pages/cert-manager/DiscoveryPage/components/DiscoveryJobSheet/LinuxServerOptionsFields.tsx b/frontend/src/pages/cert-manager/DiscoveryPage/components/DiscoveryJobSheet/LinuxServerOptionsFields.tsxindex 6d16553255..502d26a00e 100644--- a/frontend/src/pages/cert-manager/DiscoveryPage/components/DiscoveryJobSheet/LinuxServerOptionsFields.tsx+++ b/frontend/src/pages/cert-manager/DiscoveryPage/components/DiscoveryJobSheet/LinuxServerOptionsFields.tsx@@ -10,63 +10,46 @@ import {Label,Toggle} from "@app/components/v3";-import { MAX_FILE_SIZE_KB, MAX_FOLDER_DEPTH } from "@app/helpers/pkiDiscovery";+import { MAX_FOLDER_DEPTH } from "@app/helpers/pkiDiscovery";import { TLinuxServerDiscoveryJobForm } from "./discovery-job-form-schema";-const NUMBER_FIELDS = [- {- name: "maxFolderDepth",- label: "Folder Depth",- max: MAX_FOLDER_DEPTH,- description: "How many levels below each search folder"- },- {- name: "maxFileSizeKb",- label: "Largest File (KB)",- max: MAX_FILE_SIZE_KB,- description: "Bigger files are skipped and listed in the scan."- }-] as const;-export const LinuxServerOptionsFields = () => {const { control } = useFormContext<TLinuxServerDiscoveryJobForm>();return (<>- <div className="mb-4 grid grid-cols-2 gap-4">- {NUMBER_FIELDS.map(({ name, label, max, description }) => (- <Controller- key={name}- control={control}- name={name}- render={({ field: { value, onChange }, fieldState: { error } }) => (- <Field>- <FieldLabel>{label}</FieldLabel>- <Input- type="number"- min={1}- max={max}- value={value ?? ""}- onChange={(e) => onChange(e.target.value === "" ? null : Number(e.target.value))}- isError={Boolean(error)}- />- {!error?.message && <FieldDescription>{description}</FieldDescription>}- <FieldError errors={[error]} />- </Field>+ <Controller+ control={control}+ name="maxFolderDepth"+ render={({ field: { value, onChange }, fieldState: { error } }) => (+ <Field className="mb-4">+ <FieldLabel>Folder Depth</FieldLabel>+ <Input+ type="number"+ min={1}+ max={MAX_FOLDER_DEPTH}+ value={value ?? ""}+ onChange={(e) => onChange(e.target.value === "" ? null : Number(e.target.value))}+ isError={Boolean(error)}+ />+ {!error?.message && (+ <FieldDescription>+ How many subfolders deep to search. 1 checks only the files directly inside each+ search folder.+ </FieldDescription>)}- />- ))}- </div>+ <FieldError errors={[error]} />+ </Field>+ )}+ /><Controllercontrol={control}name="importStandaloneCaCertificates"render={({ field: { value, onChange } }) => (<Field orientation="horizontal" className="mb-4"><FieldContent>- <Label htmlFor="import-standalone-ca">- Import CA Certificates Found on Their Own- </Label>+ <Label htmlFor="import-standalone-ca">Include trust stores and CA bundles</Label><FieldDescription>A leaf certificate always comes in with its chain. Turn this on to also import CAcertificates from files that hold no leaf, such as trust bundles.