Skip to content

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

feat(ui): suggest certificate authority names from CA type, common name, and issuer (#8728)

Andrew Huang6403322f7ec9
diff --git a/frontend/src/pages/cert-manager/CertificateAuthoritiesPage/components/CreateCaWizard/BasicsStep.tsx b/frontend/src/pages/cert-manager/CertificateAuthoritiesPage/components/CreateCaWizard/BasicsStep.tsx
index 6d44d49ce0..6ea0e2f479 100644
--- a/frontend/src/pages/cert-manager/CertificateAuthoritiesPage/components/CreateCaWizard/BasicsStep.tsx
+++ b/frontend/src/pages/cert-manager/CertificateAuthoritiesPage/components/CreateCaWizard/BasicsStep.tsx
@@ -1,4 +1,5 @@
-import { Controller, UseFormReturn } from "react-hook-form";
+import { Controller, UseFormReturn, useWatch } from "react-hook-form";
+import slugify from "@sindresorhus/slugify";
import {
Field,
@@ -23,6 +24,16 @@ type Props = {
};
export const BasicsStep = ({ form }: Props) => {
+ const [type, commonName] = useWatch({ control: form.control, name: ["type", "commonName"] });
+ const commonNameSlug = slugify(commonName ?? "", { lowercase: true, decamelize: false });
+ const suggestedName = (
+ commonNameSlug.split("-").includes(type)
+ ? commonNameSlug
+ : [type, commonNameSlug || "ca"].join("-")
+ )
+ .slice(0, 64)
+ .replace(/-+$/, "");
+
return (
<FieldGroup>
<Controller
@@ -37,6 +48,7 @@ export const BasicsStep = ({ form }: Props) => {
<Input
{...field}
placeholder="my-internal-ca"
+ suggestedValue={suggestedName}
isError={Boolean(error)}
autoComplete="off"
name="certificate-authority-name"
diff --git a/frontend/src/pages/cert-manager/CertificateAuthoritiesPage/components/ExternalCaModal.tsx b/frontend/src/pages/cert-manager/CertificateAuthoritiesPage/components/ExternalCaModal.tsx
index 9749f7a9e4..0e00084f92 100644
--- a/frontend/src/pages/cert-manager/CertificateAuthoritiesPage/components/ExternalCaModal.tsx
+++ b/frontend/src/pages/cert-manager/CertificateAuthoritiesPage/components/ExternalCaModal.tsx
@@ -1,6 +1,7 @@
import { useEffect, useMemo, useRef, useState } from "react";
import { Controller, useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
+import slugify from "@sindresorhus/slugify";
import { ArrowLeftIcon, Loader2Icon, Lock, type LucideIcon, Search } from "lucide-react";
import {
@@ -266,6 +267,35 @@ export const ExternalCaModal = ({ popUp, handlePopUpToggle }: Props) => {
const editCaId = (popUp?.ca?.data as { caId?: string })?.caId;
const isEditMode = Boolean(editCaId);
+ const getSuggestedName = () => {
+ const typeName = caType ? CA_TYPE_NAME[caType] : undefined;
+ if (isEditMode || !typeName) return "";
+
+ let issuer = "";
+ if (configuration && "directoryUrl" in configuration) {
+ try {
+ const { hostname } = new URL(configuration.directoryUrl);
+ if (/[a-z]/i.test(hostname) && !hostname.includes(":")) {
+ const labels = hostname.split(".");
+ if (labels.length > 1) labels.pop();
+ if (labels.length > 1 && /^(ac|co|com|edu|gov|net|org)$/.test(labels[labels.length - 1]))
+ labels.pop();
+ issuer = labels[labels.length - 1];
+ }
+ } catch {
+ issuer = "";
+ }
+ } else if (configuration && "caName" in configuration) {
+ issuer = configuration.caName ?? "";
+ } else if (configuration && "policyDN" in configuration) {
+ issuer = configuration.policyDN.split("\\").filter(Boolean).pop() ?? "";
+ }
+
+ return slugify(`${typeName} ${issuer}`, { lowercase: true, decamelize: false })
+ .slice(0, 64)
+ .replace(/-+$/, "");
+ };
+
const [selectedType, setSelectedType] = useState<CaType | null>(null);
const [search, setSearch] = useState("");
@@ -1044,6 +1074,7 @@ export const ExternalCaModal = ({ popUp, handlePopUpToggle }: Props) => {
<Input
{...field}
placeholder="my-external-ca"
+ suggestedValue={getSuggestedName()}
disabled={Boolean(ca)}
isError={Boolean(error)}
autoComplete="off"