Skip to content

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

improvement(cert-manager): migrate clear PKI overlays to v3 (#8647)

Andrew Huang24ffa20e7c5d
diff --git a/frontend/src/pages/cert-manager/CertificatesPage/components/CertificateTemplateEnrollmentModal.tsx b/frontend/src/pages/cert-manager/CertificatesPage/components/CertificateTemplateEnrollmentModal.tsx
index e0df49061b..652b71fc4a 100644
--- a/frontend/src/pages/cert-manager/CertificatesPage/components/CertificateTemplateEnrollmentModal.tsx
+++ b/frontend/src/pages/cert-manager/CertificatesPage/components/CertificateTemplateEnrollmentModal.tsx
@@ -1,4 +1,4 @@
-import { useEffect } from "react";
+import { useEffect, useId } from "react";
import { Controller, useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
import z from "zod";
@@ -6,15 +6,24 @@ import z from "zod";
import { createNotification } from "@app/components/notifications";
import {
Button,
- FormControl,
+ Field,
+ FieldError,
+ FieldLabel,
Input,
- Modal,
- ModalContent,
Select,
+ SelectContent,
SelectItem,
- Switch,
- TextArea
-} from "@app/components/v2";
+ SelectTrigger,
+ SelectValue,
+ Sheet,
+ SheetClose,
+ SheetContent,
+ SheetFooter,
+ SheetHeader,
+ SheetTitle,
+ TextArea,
+ Toggle
+} from "@app/components/v3";
import { useToggle } from "@app/hooks";
import { useCreateEstConfig, useGetEstConfig, useUpdateEstConfig } from "@app/hooks/api";
import { UsePopUpState } from "@app/hooks/usePopUp";
@@ -42,6 +51,7 @@ const schema = z.object({
export type FormData = z.infer<typeof schema>;
export const CertificateTemplateEnrollmentModal = ({ popUp, handlePopUpToggle }: Props) => {
+ const inputId = useId();
const popUpData = popUp?.enrollmentOptions?.data as {
id: string;
};
@@ -74,6 +84,8 @@ export const CertificateTemplateEnrollmentModal = ({ popUp, handlePopUpToggle }:
}, [disableBootstrapCertValidation]);
useEffect(() => {
+ if (!popUp.enrollmentOptions.isOpen) return;
+
if (data) {
reset({
method: EnrollmentMethod.EST,
@@ -83,12 +95,13 @@ export const CertificateTemplateEnrollmentModal = ({ popUp, handlePopUpToggle }:
});
} else {
reset({
+ method: EnrollmentMethod.EST,
caChain: "",
isEnabled: false,
disableBootstrapCertValidation: false
});
}
- }, [data]);
+ }, [data, popUp.enrollmentOptions.isOpen]);
const onFormSubmit = async ({ caChain, passphrase, isEnabled }: FormData) => {
try {
@@ -129,138 +142,155 @@ export const CertificateTemplateEnrollmentModal = ({ popUp, handlePopUpToggle }:
};
return (
- <Modal
- isOpen={popUp?.enrollmentOptions?.isOpen}
+ <Sheet
+ open={popUp?.enrollmentOptions?.isOpen}
onOpenChange={(isOpen) => {
handlePopUpToggle("enrollmentOptions", isOpen);
reset();
}}
>
- <ModalContent title="Manage Enrollment Options">
- <form onSubmit={handleSubmit(onFormSubmit)}>
- <Controller
- control={control}
- name="method"
- defaultValue={EnrollmentMethod.EST}
- render={({ field: { onChange, ...field }, fieldState: { error } }) => (
- <FormControl
- label="Client Enrollment Method"
- errorText={error?.message}
- isError={Boolean(error)}
- >
- <Select
- defaultValue={field.value}
- {...field}
- onValueChange={(e) => onChange(e)}
- className="w-full"
- >
- <SelectItem value={EnrollmentMethod.EST} key={EnrollmentMethod.EST}>
- EST
- </SelectItem>
- </Select>
- </FormControl>
+ <SheetContent size="form" isPending={isSubmitting}>
+ <SheetHeader>
+ <SheetTitle>Manage Enrollment Options</SheetTitle>
+ </SheetHeader>
+ <form className="flex min-h-0 flex-1 flex-col" onSubmit={handleSubmit(onFormSubmit)}>
+ <div className="flex min-h-0 thin-scrollbar flex-1 flex-col gap-4 overflow-y-auto p-4">
+ <Controller
+ control={control}
+ name="method"
+ defaultValue={EnrollmentMethod.EST}
+ render={({ field, fieldState: { error } }) => (
+ <Field data-invalid={Boolean(error)}>
+ <FieldLabel htmlFor={`${inputId}-method`}>Client Enrollment Method</FieldLabel>
+ <Select value={field.value} onValueChange={field.onChange} name={field.name}>
+ <SelectTrigger
+ id={`${inputId}-method`}
+ ref={field.ref}
+ onBlur={field.onBlur}
+ className="w-full"
+ isError={Boolean(error)}
+ >
+ <SelectValue />
+ </SelectTrigger>
+ <SelectContent>
+ <SelectItem value={EnrollmentMethod.EST} key={EnrollmentMethod.EST}>
+ EST
+ </SelectItem>
+ </SelectContent>
+ </Select>
+ <FieldError>{error?.message}</FieldError>
+ </Field>
+ )}
+ />
+ {data && (
+ <Field>
+ <FieldLabel htmlFor={`${inputId}-est-label`}>EST Label</FieldLabel>
+ <Input id={`${inputId}-est-label`} value={data.certificateTemplateId} disabled />
+ </Field>
)}
- />
- {data && (
- <FormControl label="EST Label">
- <Input
- value={data.certificateTemplateId}
- isDisabled
- className="bg-foreground-inverse/[0.07]"
+ <Controller
+ control={control}
+ name="disableBootstrapCertValidation"
+ render={({ field, fieldState: { error } }) => {
+ return (
+ <Field data-invalid={Boolean(error)}>
+ <Field orientation="horizontal">
+ <Toggle
+ id={`${inputId}-skip-bootstrap-cert-validation`}
+ ref={field.ref}
+ name={field.name}
+ onBlur={field.onBlur}
+ onCheckedChange={field.onChange}
+ checked={field.value}
+ aria-invalid={Boolean(error)}
+ />
+ <FieldLabel htmlFor={`${inputId}-skip-bootstrap-cert-validation`}>
+ Disable Bootstrap Certificate Validation
+ </FieldLabel>
+ </Field>
+ <FieldError>{error?.message}</FieldError>
+ </Field>
+ );
+ }}
+ />
+ {!disableBootstrapCertValidation && (
+ <Controller
+ control={control}
+ name="caChain"
+ disabled={disableBootstrapCertValidation}
+ render={({ field, fieldState: { error } }) => (
+ <Field data-invalid={Boolean(error)}>
+ <FieldLabel htmlFor={`${inputId}-ca-chain`}>
+ Certificate Authority Chain *
+ </FieldLabel>
+ <TextArea
+ {...field}
+ id={`${inputId}-ca-chain`}
+ disabled={disableBootstrapCertValidation}
+ aria-required={!disableBootstrapCertValidation}
+ isError={Boolean(error)}
+ className="resize-none"
+ />
+ <FieldError>{error?.message}</FieldError>
+ </Field>
+ )}
/>
- </FormControl>
- )}
- <Controller
- control={control}
- name="disableBootstrapCertValidation"
- render={({ field, fieldState: { error } }) => {
- return (
- <FormControl isError={Boolean(error)} errorText={error?.message}>
- <Switch
- id="skip-bootstrap-cert-validation"
- onCheckedChange={(value) => field.onChange(value)}
- isChecked={field.value}
- >
- <p className="ml-1 w-full">Disable Bootstrap Certificate Validation</p>
- </Switch>
- </FormControl>
- );
- }}
- />
- {!disableBootstrapCertValidation && (
+ )}
<Controller
control={control}
- name="caChain"
- disabled={disableBootstrapCertValidation}
+ name="passphrase"
render={({ field, fieldState: { error } }) => (
- <FormControl
- label="Certificate Authority Chain"
- isError={Boolean(error)}
- errorText={error?.message}
- isRequired={!disableBootstrapCertValidation}
- >
- <TextArea
+ <Field data-invalid={Boolean(error)}>
+ <FieldLabel htmlFor={`${inputId}-passphrase`}>Passphrase</FieldLabel>
+ <Input
{...field}
- isDisabled={disableBootstrapCertValidation}
- className="min-h-60 border-none bg-surface-base text-muted-cool"
- reSize="none"
+ id={`${inputId}-passphrase`}
+ isError={Boolean(error)}
+ type={isPassphraseFocused ? "text" : "password"}
+ onFocus={() => setIsPassphraseFocused.on()}
+ onBlur={() => {
+ field.onBlur();
+ setIsPassphraseFocused.off();
+ }}
/>
- </FormControl>
+ <FieldError>{error?.message}</FieldError>
+ </Field>
)}
/>
- )}
- <Controller
- control={control}
- name="passphrase"
- render={({ field, fieldState: { error } }) => (
- <FormControl label="Passphrase" isError={Boolean(error)} errorText={error?.message}>
- <Input
- {...field}
- type={isPassphraseFocused ? "text" : "password"}
- onFocus={() => setIsPassphraseFocused.on()}
- onBlur={() => setIsPassphraseFocused.off()}
- />
- </FormControl>
- )}
- />
- <Controller
- control={control}
- name="isEnabled"
- render={({ field, fieldState: { error } }) => {
- return (
- <FormControl isError={Boolean(error)} errorText={error?.message}>
- <Switch
- id="is-active"
- onCheckedChange={(value) => field.onChange(value)}
- isChecked={field.value}
- >
- <p className="ml-1 w-full">EST Enabled</p>
- </Switch>
- </FormControl>
- );
- }}
- />
-
- <div className="mt-8 flex items-center">
- <Button
- className="mr-4"
- size="sm"
- type="submit"
- isLoading={isSubmitting}
- isDisabled={isSubmitting}
- >
+ <Controller
+ control={control}
+ name="isEnabled"
+ render={({ field, fieldState: { error } }) => {
+ return (
+ <Field data-invalid={Boolean(error)}>
+ <Field orientation="horizontal">
+ <Toggle
+ id={`${inputId}-is-active`}
+ ref={field.ref}
+ name={field.name}
+ onBlur={field.onBlur}
+ onCheckedChange={field.onChange}
+ checked={field.value}
+ aria-invalid={Boolean(error)}
+ />
+ <FieldLabel htmlFor={`${inputId}-is-active`}>EST Enabled</FieldLabel>
+ </Field>
+ <FieldError>{error?.message}</FieldError>
+ </Field>
+ );
+ }}
+ />
+ </div>
+ <SheetFooter className="border-t">
+ <SheetClose asChild>
+ <Button variant="ghost">Cancel</Button>
+ </SheetClose>
+ <Button variant="project" size="sm" type="submit" isPending={isSubmitting}>
Save
</Button>
- <Button
- colorSchema="secondary"
- variant="plain"
- onClick={() => handlePopUpToggle("enrollmentOptions", false)}
- >
- Cancel
- </Button>
- </div>
+ </SheetFooter>
</form>
- </ModalContent>
- </Modal>
+ </SheetContent>
+ </Sheet>
);
};
diff --git a/frontend/src/pages/cert-manager/DiscoveryPage/components/DeleteDiscoveryModal.tsx b/frontend/src/pages/cert-manager/DiscoveryPage/components/DeleteDiscoveryModal.tsx
index 2c4f84aecb..de1d211408 100644
--- a/frontend/src/pages/cert-manager/DiscoveryPage/components/DeleteDiscoveryModal.tsx
+++ b/frontend/src/pages/cert-manager/DiscoveryPage/components/DeleteDiscoveryModal.tsx
@@ -1,4 +1,4 @@
-import { DeleteActionModal } from "@app/components/v2";
+import { DeleteConfirmDialog } from "@app/components/v3/platform";
type Props = {
isOpen: boolean;
@@ -9,13 +9,13 @@ type Props = {
export const DeleteDiscoveryModal = ({ isOpen, onOpenChange, onConfirm, discoveryName }: Props) => {
return (
- <DeleteActionModal
+ <DeleteConfirmDialog
isOpen={isOpen}
- onChange={onOpenChange}
+ onOpenChange={onOpenChange}
title={`Delete discovery job "${discoveryName}"?`}
- subTitle="This action will also remove all associated scan history."
- deleteKey="confirm"
- onDeleteApproved={onConfirm}
+ description="This action will also remove all associated scan history."
+ confirmKey="confirm"
+ onConfirm={onConfirm}
/>
);
};
diff --git a/frontend/src/pages/cert-manager/DiscoveryPage/components/DeleteInstallationModal.tsx b/frontend/src/pages/cert-manager/DiscoveryPage/components/DeleteInstallationModal.tsx
index f6f64985cd..dddebf705a 100644
--- a/frontend/src/pages/cert-manager/DiscoveryPage/components/DeleteInstallationModal.tsx
+++ b/frontend/src/pages/cert-manager/DiscoveryPage/components/DeleteInstallationModal.tsx
@@ -1,4 +1,4 @@
-import { DeleteActionModal } from "@app/components/v2";
+import { DeleteConfirmDialog } from "@app/components/v3/platform";
type Props = {
isOpen: boolean;
@@ -14,13 +14,13 @@ export const DeleteInstallationModal = ({
installationName
}: Props) => {
return (
- <DeleteActionModal
+ <DeleteConfirmDialog
isOpen={isOpen}
- onChange={onOpenChange}
+ onOpenChange={onOpenChange}
title={`Delete installation "${installationName}"?`}
- subTitle="This will remove the installation record and its certificate associations."
- deleteKey="confirm"
- onDeleteApproved={onConfirm}
+ description="This will remove the installation record and its certificate associations."
+ confirmKey="confirm"
+ onConfirm={onConfirm}
/>
);
};
diff --git a/frontend/src/pages/cert-manager/PkiCollectionDetailsByIDPage/components/AddPkiCollectionItemModal.tsx b/frontend/src/pages/cert-manager/PkiCollectionDetailsByIDPage/components/AddPkiCollectionItemModal.tsx
index 1fd4d7d995..3942c82d03 100644
--- a/frontend/src/pages/cert-manager/PkiCollectionDetailsByIDPage/components/AddPkiCollectionItemModal.tsx
+++ b/frontend/src/pages/cert-manager/PkiCollectionDetailsByIDPage/components/AddPkiCollectionItemModal.tsx
@@ -1,9 +1,26 @@
+import { useId } from "react";
import { Controller, useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
import { z } from "zod";
import { createNotification } from "@app/components/notifications";
-import { Button, FormControl, Modal, ModalContent, Select, SelectItem } from "@app/components/v2";
+import {
+ Button,
+ Dialog,
+ DialogClose,
+ DialogContent,
+ DialogFooter,
+ DialogHeader,
+ DialogTitle,
+ Field,
+ FieldError,
+ FieldLabel,
+ Select,
+ SelectContent,
+ SelectItem,
+ SelectTrigger,
+ SelectValue
+} from "@app/components/v3";
import { useProject } from "@app/context";
import { CaStatus, useAddItemToPkiCollection, useListWorkspaceCas } from "@app/hooks/api";
import { PkiItemType, pkiItemTypeToNameMap } from "@app/hooks/api/pkiCollections/constants";
@@ -13,7 +30,7 @@ import { UsePopUpState } from "@app/hooks/usePopUp";
const schema = z
.object({
// type: z.nativeEnum(PkiItemType),
- itemId: z.string()
+ itemId: z.string().min(1, "Select an item to add")
})
.required();
@@ -38,6 +55,7 @@ export const AddPkiCollectionItemModal = ({
handlePopUpToggle
}: Props) => {
const { currentProject } = useProject();
+ const itemInputId = useId();
const { data: cas } = useListWorkspaceCas({
projectId: currentProject?.id || "",
@@ -45,7 +63,7 @@ export const AddPkiCollectionItemModal = ({
});
const { data } = useListWorkspaceCertificates({
- projectId: currentProject?.slug || "",
+ projectId: currentProject?.id || "",
offset: 0,
limit: 25
});
@@ -87,62 +105,46 @@ export const AddPkiCollectionItemModal = ({
};
return (
- <Modal
- isOpen={popUp?.addPkiCollectionItem?.isOpen}
+ <Dialog
+ open={popUp?.addPkiCollectionItem?.isOpen}
onOpenChange={(isOpen) => {
handlePopUpToggle("addPkiCollectionItem", isOpen);
reset();
}}
>
- <ModalContent title={`Add ${pkiItemTypeToNameMap[type]} to Collection`}>
- <form onSubmit={handleSubmit(onFormSubmit)}>
- {/* <Controller
- control={control}
- name="type"
- defaultValue={PkiItemType.CA}
- render={({ field: { onChange, ...field }, fieldState: { error } }) => (
- <FormControl label="Item Type" errorText={error?.message} isError={Boolean(error)}>
- <Select
- defaultValue={field.value}
- {...field}
- onValueChange={(e) => onChange(e)}
- className="w-full"
- >
- <SelectItem value={PkiItemType.CA} key="pki-item-type-ca">
- Certificate Authority
- </SelectItem>
- <SelectItem value={PkiItemType.CERTIFICATE} key="pki-item-type-ca">
- Certificate
- </SelectItem>
- </Select>
- </FormControl>
- )}
- /> */}
+ <DialogContent isPending={isSubmitting}>
+ <DialogHeader>
+ <DialogTitle>{`Add ${pkiItemTypeToNameMap[type]} to Collection`}</DialogTitle>
+ </DialogHeader>
+ <form className="flex flex-col gap-6" onSubmit={handleSubmit(onFormSubmit)}>
{type === PkiItemType.CA && (
<Controller
control={control}
name="itemId"
defaultValue=""
- render={({ field: { onChange, ...field }, fieldState: { error } }) => (
- <FormControl
- label={pkiItemTypeToNameMap[type]}
- errorText={error?.message}
- isError={Boolean(error)}
- // className="mt-4"
- >
- <Select
- defaultValue={field.value}
- {...field}
- onValueChange={(e) => onChange(e)}
- className="w-full"
- >
- {(cas || []).map(({ id, dn }) => (
- <SelectItem value={id} key={`pki-item-cert-${id}`}>
- {dn}
- </SelectItem>
- ))}
+ render={({ field, fieldState: { error } }) => (
+ <Field data-invalid={Boolean(error)}>
+ <FieldLabel htmlFor={itemInputId}>{pkiItemTypeToNameMap[type]}</FieldLabel>
+ <Select value={field.value} onValueChange={field.onChange} name={field.name}>
+ <SelectTrigger
+ id={itemInputId}
+ ref={field.ref}
+ onBlur={field.onBlur}
+ className="w-full"
+ isError={Boolean(error)}
+ >
+ <SelectValue placeholder="Select a certificate authority" />
+ </SelectTrigger>
+ <SelectContent>
+ {(cas || []).map(({ id, dn }) => (
+ <SelectItem value={id} key={`pki-item-cert-${id}`}>
+ {dn}
+ </SelectItem>
+ ))}
+ </SelectContent>
</Select>
- </FormControl>
+ <FieldError>{error?.message}</FieldError>
+ </Field>
)}
/>
)}
@@ -151,49 +153,42 @@ export const AddPkiCollectionItemModal = ({
control={control}
name="itemId"
defaultValue=""
- render={({ field: { onChange, ...field }, fieldState: { error } }) => (
- <FormControl
- label="Certificate"
- errorText={error?.message}
- isError={Boolean(error)}
- // className="mt-4"
- >
- <Select
- defaultValue={field.value}
- {...field}
- onValueChange={(e) => onChange(e)}
- className="w-full"
- >
- {(data?.certificates || []).map(({ id, commonName }) => (
- <SelectItem value={id} key={`pki-item-cert-${id}`}>
- {`CN=${commonName}`}
- </SelectItem>
- ))}
+ render={({ field, fieldState: { error } }) => (
+ <Field data-invalid={Boolean(error)}>
+ <FieldLabel htmlFor={itemInputId}>Certificate</FieldLabel>
+ <Select value={field.value} onValueChange={field.onChange} name={field.name}>
+ <SelectTrigger
+ id={itemInputId}
+ ref={field.ref}
+ onBlur={field.onBlur}
+ className="w-full"
+ isError={Boolean(error)}
+ >
+ <SelectValue placeholder="Select a certificate" />
+ </SelectTrigger>
+ <SelectContent>
+ {(data?.certificates || []).map(({ id, commonName }) => (
+ <SelectItem value={id} key={`pki-item-cert-${id}`}>
+ {`CN=${commonName}`}
+ </SelectItem>
+ ))}
+ </SelectContent>
</Select>
- </FormControl>
+ <FieldError>{error?.message}</FieldError>
+ </Field>
)}
/>
)}
- <div className="flex items-center">
- <Button
- className="mr-4"
- size="sm"
- type="submit"
- isLoading={isSubmitting}
- isDisabled={isSubmitting}
- >
+ <DialogFooter>
+ <DialogClose asChild>
+ <Button variant="ghost">Cancel</Button>
+ </DialogClose>
+ <Button variant="project" size="sm" type="submit" isPending={isSubmitting}>
Add
</Button>
- <Button
- colorSchema="secondary"
- variant="plain"
- onClick={() => handlePopUpToggle("addPkiCollectionItem", false)}
- >
- Cancel
- </Button>
- </div>
+ </DialogFooter>
</form>
- </ModalContent>
- </Modal>
+ </DialogContent>
+ </Dialog>
);
};
diff --git a/frontend/src/pages/cert-manager/PkiCollectionDetailsByIDPage/components/PkiCollectionItemsSection.tsx b/frontend/src/pages/cert-manager/PkiCollectionDetailsByIDPage/components/PkiCollectionItemsSection.tsx
index 40c911660c..ee0e99fb1e 100644
--- a/frontend/src/pages/cert-manager/PkiCollectionDetailsByIDPage/components/PkiCollectionItemsSection.tsx
+++ b/frontend/src/pages/cert-manager/PkiCollectionDetailsByIDPage/components/PkiCollectionItemsSection.tsx
@@ -2,7 +2,8 @@ import { faPlus } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { createNotification } from "@app/components/notifications";
-import { DeleteActionModal, IconButton } from "@app/components/v2";
+import { IconButton } from "@app/components/v3";
+import { DeleteConfirmDialog } from "@app/components/v3/platform";
import { useGetPkiCollectionById, useRemoveItemFromPkiCollection } from "@app/hooks/api";
import { PkiItemType } from "@app/hooks/api/pkiCollections/constants";
import { usePopUp } from "@app/hooks/usePopUp";
@@ -49,9 +50,8 @@ export const PkiCollectionItemsSection = ({ collectionId, type }: Props) => {
<div className="flex items-center justify-between border-b border-border-emphasis pb-4">
<h3 className="text-lg font-normal text-foreground">{sectionName}</h3>
<IconButton
- ariaLabel="copy icon"
- variant="plain"
- className="group relative"
+ aria-label={`Add to ${sectionName.toLowerCase()}`}
+ variant="ghost"
onClick={() => {
handlePopUpOpen("addPkiCollectionItem");
}}
@@ -72,12 +72,13 @@ export const PkiCollectionItemsSection = ({ collectionId, type }: Props) => {
popUp={popUp}
handlePopUpToggle={handlePopUpToggle}
/>
- <DeleteActionModal
+ <DeleteConfirmDialog
isOpen={popUp.deletePkiCollectionItem.isOpen}
title={`Are you sure you want to remove the item from the collection ${pkiCollection.name}?`}
- onChange={(isOpen) => handlePopUpToggle("deletePkiCollectionItem", isOpen)}
- deleteKey="confirm"
- onDeleteApproved={() => {
+ description="This action is irreversible."
+ onOpenChange={(isOpen) => handlePopUpToggle("deletePkiCollectionItem", isOpen)}
+ confirmKey="confirm"
+ onConfirm={() => {
const popupData = popUp?.deletePkiCollectionItem?.data as {
itemId: string;
};