Skip to content

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

feat(pki): inline connection creation and clearer acme dns fields

bernie-gb05ea2d59954
diff --git a/backend/src/services/certificate-authority/acme/dns-providers/gcp-cloud-dns.test.ts b/backend/src/services/certificate-authority/acme/dns-providers/gcp-cloud-dns.test.ts
index 981540ac27..536d1c2bd8 100644
--- a/backend/src/services/certificate-authority/acme/dns-providers/gcp-cloud-dns.test.ts
+++ b/backend/src/services/certificate-authority/acme/dns-providers/gcp-cloud-dns.test.ts
@@ -105,7 +105,7 @@ describe("gcpCloudDnsInsertTxtRecord", () => {
postMock.mockRejectedValueOnce(axiosError(404, "The managed zone does not exist."));
await expect(gcpCloudDnsInsertTxtRecord(connection, ZONE, RECORD, '"token-a"')).rejects.toThrow(
- "Google Cloud DNS request failed: The managed zone does not exist."
+ "Failed to update Google Cloud DNS TXT record '_acme-challenge.example.com.' in zone 'example-zone': The managed zone does not exist."
);
expect(postMock).toHaveBeenCalledTimes(1);
});
@@ -177,7 +177,7 @@ describe("gcpCloudDnsInsertTxtRecord", () => {
getMock.mockRejectedValueOnce(axiosError(400));
await expect(gcpCloudDnsInsertTxtRecord(connection, ZONE, RECORD, '"token-a"')).rejects.toThrow(
- "Google Cloud DNS request failed: status 400"
+ "Failed to update Google Cloud DNS TXT record '_acme-challenge.example.com.' in zone 'example-zone': status 400"
);
});
});
diff --git a/backend/src/services/certificate-authority/acme/dns-providers/gcp-cloud-dns.ts b/backend/src/services/certificate-authority/acme/dns-providers/gcp-cloud-dns.ts
index 8caa911c6d..64613467e6 100644
--- a/backend/src/services/certificate-authority/acme/dns-providers/gcp-cloud-dns.ts
+++ b/backend/src/services/certificate-authority/acme/dns-providers/gcp-cloud-dns.ts
@@ -20,6 +20,7 @@ type TGcpResourceRecordSet = {
const TXT_RECORD_TTL_SECONDS = 60;
const MAX_CHANGE_ATTEMPTS = 5;
const CHANGE_RETRY_DELAY_MS = 1000;
+const REQUEST_TIMEOUT_MS = 30_000;
const QUOTES_REGEX = new RE2('"', "g");
export const validateGcpCloudDnsZone = (hostedZoneId: string) => {
@@ -52,7 +53,7 @@ const isServiceDisabledError = (body: TGoogleApiErrorBody | undefined, message:
Boolean(body?.error?.errors?.some((err) => err.reason === "accessNotConfigured")) ||
message.includes("has not been used in project");
-const toGcpDnsError = (error: unknown, hostedZoneId: string) => {
+const toGcpDnsError = (error: unknown, hostedZoneId: string, fqdn: string) => {
if (isAxiosError(error)) {
const body = error.response?.data as TGoogleApiErrorBody | undefined;
const message = body?.error?.message || error.message || "Unknown error";
@@ -69,7 +70,8 @@ const toGcpDnsError = (error: unknown, hostedZoneId: string) => {
);
}
- return new Error(`Google Cloud DNS request failed: ${message}`);
+ const [, , , zoneName] = hostedZoneId.split("/");
+ return new Error(`Failed to update Google Cloud DNS TXT record '${fqdn}' in zone '${zoneName}': ${message}`);
}
return error;
};
@@ -84,7 +86,8 @@ const isConflictError = (error: unknown, changeHadDeletions: boolean) =>
const getTxtRecordSet = async (zoneUrl: string, accessToken: string, fqdn: string) => {
try {
const { data } = await request.get<TGcpResourceRecordSet>(`${zoneUrl}/rrsets/${encodeURIComponent(fqdn)}/TXT`, {
- headers: { Authorization: `Bearer ${accessToken}`, Accept: "application/json" }
+ headers: { Authorization: `Bearer ${accessToken}`, Accept: "application/json" },
+ timeout: REQUEST_TIMEOUT_MS
});
return data;
} catch (error) {
@@ -99,7 +102,8 @@ const submitChange = async (
change: { additions?: TGcpResourceRecordSet[]; deletions?: TGcpResourceRecordSet[] }
) => {
await request.post(`${zoneUrl}/changes`, change, {
- headers: { Authorization: `Bearer ${accessToken}`, "Content-Type": "application/json", Accept: "application/json" }
+ headers: { Authorization: `Bearer ${accessToken}`, "Content-Type": "application/json", Accept: "application/json" },
+ timeout: REQUEST_TIMEOUT_MS
});
};
@@ -130,7 +134,7 @@ const applyTxtRecordChange = async (
return;
} catch (error) {
if (!isConflictError(error, changeHadDeletions) || attempt === MAX_CHANGE_ATTEMPTS) {
- throw toGcpDnsError(error, hostedZoneId);
+ throw toGcpDnsError(error, hostedZoneId, fqdn);
}
// eslint-disable-next-line no-await-in-loop
await delay(CHANGE_RETRY_DELAY_MS);
diff --git a/frontend/src/pages/cert-manager/CertificateAuthoritiesPage/components/ExternalCaFields/AcmeFields.tsx b/frontend/src/pages/cert-manager/CertificateAuthoritiesPage/components/ExternalCaFields/AcmeFields.tsx
index 900acefe4a..71f3490e09 100644
--- a/frontend/src/pages/cert-manager/CertificateAuthoritiesPage/components/ExternalCaFields/AcmeFields.tsx
+++ b/frontend/src/pages/cert-manager/CertificateAuthoritiesPage/components/ExternalCaFields/AcmeFields.tsx
@@ -51,6 +51,7 @@ type Props = {
powerDnsZones: TPowerDnsZone[];
isPowerDnsZonesPending: boolean;
onDnsSelectionChange: () => void;
+ onDnsProviderChange: () => void;
};
export const AcmeFields = ({
@@ -69,7 +70,8 @@ export const AcmeFields = ({
isAzureDNSZonesPending,
powerDnsZones,
isPowerDnsZonesPending,
- onDnsSelectionChange
+ onDnsSelectionChange,
+ onDnsProviderChange
}: Props) => (
<>
<Controller
@@ -83,7 +85,7 @@ export const AcmeFields = ({
value={value}
onValueChange={(val) => {
onChange(val);
- onDnsSelectionChange();
+ onDnsProviderChange();
}}
disabled={isExistingCa}
>
@@ -108,6 +110,7 @@ export const AcmeFields = ({
label="DNS App Connection"
onAfterChange={onDnsSelectionChange}
options={availableConnections}
+ createApp={dnsProvider ? ACME_DNS_PROVIDER_APP_CONNECTION_MAP[dnsProvider] : undefined}
isLoading={isPending}
tooltip={
dnsProvider
@@ -260,6 +263,15 @@ export const AcmeFields = ({
<Field className="mb-4">
<FieldLabel>
Directory URL <span className="text-danger">*</span>
+ <Tooltip>
+ <TooltipTrigger asChild>
+ <Info />
+ </TooltipTrigger>
+ <TooltipContent className="max-w-md">
+ The ACME directory of the CA that issues your certificates, such as Let&apos;s
+ Encrypt or ZeroSSL.
+ </TooltipContent>
+ </Tooltip>
</FieldLabel>
<Input
{...field}
diff --git a/frontend/src/pages/cert-manager/CertificateAuthoritiesPage/components/ExternalCaFields/AppConnectionSelectField.tsx b/frontend/src/pages/cert-manager/CertificateAuthoritiesPage/components/ExternalCaFields/AppConnectionSelectField.tsx
index 424108959f..e2ff9296db 100644
--- a/frontend/src/pages/cert-manager/CertificateAuthoritiesPage/components/ExternalCaFields/AppConnectionSelectField.tsx
+++ b/frontend/src/pages/cert-manager/CertificateAuthoritiesPage/components/ExternalCaFields/AppConnectionSelectField.tsx
@@ -1,5 +1,6 @@
-import { ReactNode } from "react";
-import { Control, Controller, FieldPath } from "react-hook-form";
+import { ReactNode, useState } from "react";
+import { Control, FieldPath, useController } from "react-hook-form";
+import { SingleValue } from "react-select";
import { Info } from "lucide-react";
import { AppConnectionOption } from "@app/components/app-connections";
@@ -12,12 +13,19 @@ import {
TooltipContent,
TooltipTrigger
} from "@app/components/v3";
+import { ProjectPermissionSub, useProject, useProjectPermission } from "@app/context";
+import { ProjectPermissionAppConnectionActions } from "@app/context/ProjectPermissionContext/types";
+import { APP_CONNECTION_MAP } from "@app/helpers/appConnections";
import { TAvailableAppConnection } from "@app/hooks/api/appConnections";
+import { AppConnection } from "@app/hooks/api/appConnections/enums";
+import { AddAppConnectionModal } from "@app/pages/organization/AppConnections/AppConnectionsPage/components";
import { FormData } from "./schema";
type AppConnectionValue = { id: string; name: string };
+const CREATE_CONNECTION_OPTION_PREFIX = "_create:";
+
type Props = {
control: Control<FormData>;
name: FieldPath<FormData>;
@@ -28,6 +36,7 @@ type Props = {
required?: boolean;
menuPlacement?: "top" | "bottom" | "auto";
onAfterChange?: () => void;
+ createApp?: AppConnection;
};
export const AppConnectionSelectField = ({
@@ -39,12 +48,39 @@ export const AppConnectionSelectField = ({
isLoading,
required,
menuPlacement,
- onAfterChange
-}: Props) => (
- <Controller
- control={control}
- name={name}
- render={({ field: { value, onChange }, fieldState: { error } }) => (
+ onAfterChange,
+ createApp
+}: Props) => {
+ const { currentProject } = useProject();
+ const { permission } = useProjectPermission();
+ const [isCreateModalOpen, setIsCreateModalOpen] = useState(false);
+
+ const {
+ field: { value, onChange },
+ fieldState: { error }
+ } = useController({ control, name });
+
+ const canCreateConnection =
+ Boolean(createApp) &&
+ permission.can(
+ ProjectPermissionAppConnectionActions.Create,
+ ProjectPermissionSub.AppConnections
+ );
+
+ const selectOptions: AppConnectionValue[] = [
+ ...(canCreateConnection && createApp
+ ? [
+ {
+ id: `${CREATE_CONNECTION_OPTION_PREFIX}${createApp}`,
+ name: `Create ${APP_CONNECTION_MAP[createApp].name} Connection`
+ }
+ ]
+ : []),
+ ...options
+ ];
+
+ return (
+ <>
<Field className="mb-4">
<FieldLabel>
{label} {required && <span className="text-danger">*</span>}
@@ -59,11 +95,19 @@ export const AppConnectionSelectField = ({
{...(menuPlacement ? { menuPlacement } : {})}
value={(value as AppConnectionValue)?.id ? (value as AppConnectionValue) : null}
onChange={(newValue) => {
+ if (
+ (newValue as SingleValue<AppConnectionValue>)?.id?.startsWith(
+ CREATE_CONNECTION_OPTION_PREFIX
+ )
+ ) {
+ setIsCreateModalOpen(true);
+ return;
+ }
onChange(newValue);
onAfterChange?.();
}}
isLoading={isLoading}
- options={options}
+ options={selectOptions}
placeholder="Select connection..."
getOptionLabel={(option) => option.name}
getOptionValue={(option) => option.id}
@@ -72,6 +116,23 @@ export const AppConnectionSelectField = ({
/>
<FieldError errors={[error]} />
</Field>
- )}
- />
-);
+ {createApp && (
+ // the modal portals out of the DOM but React still bubbles its submit to the CA form
+ <div className="contents" onSubmit={(e) => e.stopPropagation()}>
+ <AddAppConnectionModal
+ isOpen={isCreateModalOpen}
+ onOpenChange={setIsCreateModalOpen}
+ projectType={currentProject.type}
+ projectId={currentProject.id}
+ app={createApp}
+ onComplete={(connection) => {
+ if (!connection) return;
+ onChange({ id: connection.id, name: connection.name });
+ onAfterChange?.();
+ }}
+ />
+ </div>
+ )}
+ </>
+ );
+};
diff --git a/frontend/src/pages/cert-manager/CertificateAuthoritiesPage/components/ExternalCaFields/GcpCloudDnsZoneFields.tsx b/frontend/src/pages/cert-manager/CertificateAuthoritiesPage/components/ExternalCaFields/GcpCloudDnsZoneFields.tsx
index 595b66e458..b67dbd1a55 100644
--- a/frontend/src/pages/cert-manager/CertificateAuthoritiesPage/components/ExternalCaFields/GcpCloudDnsZoneFields.tsx
+++ b/frontend/src/pages/cert-manager/CertificateAuthoritiesPage/components/ExternalCaFields/GcpCloudDnsZoneFields.tsx
@@ -2,8 +2,17 @@ import { useState } from "react";
import { Control, Controller } from "react-hook-form";
import { SingleValue } from "react-select";
import { AxiosError } from "axios";
+import { Info } from "lucide-react";
-import { Field, FieldError, FieldLabel, FilterableSelect } from "@app/components/v3";
+import {
+ Field,
+ FieldError,
+ FieldLabel,
+ FilterableSelect,
+ Tooltip,
+ TooltipContent,
+ TooltipTrigger
+} from "@app/components/v3";
import {
useGcpConnectionListCloudDnsProjects,
useGcpConnectionListCloudDnsZones
@@ -56,6 +65,15 @@ const GcpCloudDnsZoneSelect = ({
<Field className="mb-4">
<FieldLabel>
Zone <span className="text-danger">*</span>
+ <Tooltip>
+ <TooltipTrigger asChild>
+ <Info />
+ </TooltipTrigger>
+ <TooltipContent className="max-w-md">
+ The public Cloud DNS zone where Infisical creates the challenge TXT records. It must
+ contain the domains you request certificates for.
+ </TooltipContent>
+ </Tooltip>
</FieldLabel>
<FilterableSelect
isLoading={isZonesPending && Boolean(connectionId) && Boolean(gcpProjectId)}
@@ -107,6 +125,16 @@ export const GcpCloudDnsZoneFields = ({ control, connectionId }: Props) => {
<Field className="mb-4">
<FieldLabel>
GCP Project <span className="text-danger">*</span>
+ <Tooltip>
+ <TooltipTrigger asChild>
+ <Info />
+ </TooltipTrigger>
+ <TooltipContent className="max-w-md">
+ The Google Cloud project that holds your DNS zone. Only projects that the
+ connection&apos;s service account can see and that have the Cloud DNS API
+ enabled are listed.
+ </TooltipContent>
+ </Tooltip>
</FieldLabel>
<FilterableSelect
isLoading={isProjectsPending && Boolean(connectionId)}
diff --git a/frontend/src/pages/cert-manager/CertificateAuthoritiesPage/components/ExternalCaModal.tsx b/frontend/src/pages/cert-manager/CertificateAuthoritiesPage/components/ExternalCaModal.tsx
index 8422babd8c..2fb7e2ab4e 100644
--- a/frontend/src/pages/cert-manager/CertificateAuthoritiesPage/components/ExternalCaModal.tsx
+++ b/frontend/src/pages/cert-manager/CertificateAuthoritiesPage/components/ExternalCaModal.tsx
@@ -1018,6 +1018,16 @@ export const ExternalCaModal = ({ popUp, handlePopUpToggle }: Props) => {
shouldDirty: true
})
}
+ onDnsProviderChange={() => {
+ setValue(
+ "configuration.dnsAppConnection",
+ { id: "", name: "" },
+ { shouldDirty: true }
+ );
+ setValue("configuration.dnsProviderConfig.hostedZoneId", "", {
+ shouldDirty: true
+ });
+ }}
/>
)}
{caType === CaType.AZURE_AD_CS && (