Skip to content

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

feat: allow creation of cert profiles from inside applications

Sheen Capadngan57d378b2f67c
diff --git a/frontend/src/pages/cert-manager/ApplicationDetailsByIDPage/ApplicationDetailsByIDPage.tsx b/frontend/src/pages/cert-manager/ApplicationDetailsByIDPage/ApplicationDetailsByIDPage.tsx
index 6f3f6208ae..253626f18b 100644
--- a/frontend/src/pages/cert-manager/ApplicationDetailsByIDPage/ApplicationDetailsByIDPage.tsx
+++ b/frontend/src/pages/cert-manager/ApplicationDetailsByIDPage/ApplicationDetailsByIDPage.tsx
@@ -51,6 +51,7 @@ import { ApplicationMembersTab } from "./components/ApplicationMembersTab";
import { ApplicationRequestsTab } from "./components/ApplicationRequestsTab";
import { ApplicationSettingsTab } from "./components/ApplicationSettingsTab";
import { ApplicationSyncsTab } from "./components/ApplicationSyncsTab";
+import { ApplicationTab } from "./application-tabs";
type PermissionedTabProps = {
value: string;
@@ -260,7 +261,7 @@ export const ApplicationDetailsByIDPage = () => {
applicationName: application.name
},
search: {
- selectedTab: v as "certificates" | "requests" | "syncs" | "members" | "settings"
+ selectedTab: v as ApplicationTab
}
})
}
diff --git a/frontend/src/pages/cert-manager/ApplicationDetailsByIDPage/application-tabs.ts b/frontend/src/pages/cert-manager/ApplicationDetailsByIDPage/application-tabs.ts
new file mode 100644
index 0000000000..9f506e88e6
--- /dev/null
+++ b/frontend/src/pages/cert-manager/ApplicationDetailsByIDPage/application-tabs.ts
@@ -0,0 +1,7 @@
+export enum ApplicationTab {
+ Certificates = "certificates",
+ Requests = "requests",
+ Syncs = "syncs",
+ Members = "members",
+ Settings = "settings"
+}
diff --git a/frontend/src/pages/cert-manager/ApplicationDetailsByIDPage/components/ApplicationRequestsTab.tsx b/frontend/src/pages/cert-manager/ApplicationDetailsByIDPage/components/ApplicationRequestsTab.tsx
index 2f44bf74e2..510f9f60d3 100644
--- a/frontend/src/pages/cert-manager/ApplicationDetailsByIDPage/components/ApplicationRequestsTab.tsx
+++ b/frontend/src/pages/cert-manager/ApplicationDetailsByIDPage/components/ApplicationRequestsTab.tsx
@@ -1,6 +1,7 @@
import { useNavigate, useParams } from "@tanstack/react-router";
import { CertificateRequestsSection } from "../../CertificateRequestsPage/components/CertificateRequestsSection";
+import { ApplicationTab } from "../application-tabs";
type Props = {
applicationId: string;
@@ -20,7 +21,7 @@ export const ApplicationRequestsTab = ({ applicationId, applicationName }: Props
projectId: projectId ?? "",
applicationName
},
- search: { selectedTab: "certificates", search: certificateId }
+ search: { selectedTab: ApplicationTab.Certificates, search: certificateId }
});
};
diff --git a/frontend/src/pages/cert-manager/ApplicationDetailsByIDPage/components/ApplicationSettingsTab.tsx b/frontend/src/pages/cert-manager/ApplicationDetailsByIDPage/components/ApplicationSettingsTab.tsx
index 25d405ee4b..1c021e004f 100644
--- a/frontend/src/pages/cert-manager/ApplicationDetailsByIDPage/components/ApplicationSettingsTab.tsx
+++ b/frontend/src/pages/cert-manager/ApplicationDetailsByIDPage/components/ApplicationSettingsTab.tsx
@@ -1,4 +1,5 @@
-import { ReactNode, useMemo, useState } from "react";
+import { ReactNode, useCallback, useMemo, useState } from "react";
+import { components, MenuListProps } from "react-select";
import { faPlus } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { useQuery } from "@tanstack/react-query";
@@ -55,6 +56,11 @@ import {
TooltipContent,
TooltipTrigger
} from "@app/components/v3";
+import { useProjectPermission } from "@app/context";
+import {
+ ProjectPermissionCertificateProfileActions,
+ ProjectPermissionSub
+} from "@app/context/ProjectPermissionContext/types";
import { usePopUp } from "@app/hooks";
import {
approvalPolicyQuery,
@@ -82,6 +88,7 @@ import {
useGetPkiApplicationPermissions
} from "@app/hooks/api/pkiApplications";
import { PolicyModal } from "@app/pages/cert-manager/ApprovalsPage/components/PolicyTab/components/PolicyModal";
+import { CreateProfileModal } from "@app/pages/cert-manager/PoliciesPage/components/CertificateProfilesTab/CreateProfileModal";
import { CreatePkiAlertV2Modal } from "@app/views/PkiAlertsV2Page/components/CreatePkiAlertV2Modal";
import { ViewPkiAlertV2Modal } from "@app/views/PkiAlertsV2Page/components/ViewPkiAlertV2Modal";
import {
@@ -98,6 +105,8 @@ import {
type Props = { application: TPkiApplication; profiles: TPkiApplicationProfile[] };
+type TProfileOption = { value: string; label: string };
+
const methodBadges = (p: TPkiApplicationProfile) => {
const methods: EnrollmentMethod[] = [];
if (p.apiConfigId) methods.push("api");
@@ -399,7 +408,8 @@ export const ApplicationSettingsTab = ({ application, profiles }: Props) => {
appAbility?.can(PkiApplicationResourceActions.Delete, PkiApplicationResourceSub.PkiAlerts)
);
const [isAttachOpen, setIsAttachOpen] = useState(false);
- const [profilesToAttach, setProfilesToAttach] = useState<{ value: string; label: string }[]>([]);
+ const [isCreateProfileOpen, setIsCreateProfileOpen] = useState(false);
+ const [profilesToAttach, setProfilesToAttach] = useState<TProfileOption[]>([]);
const [profileToDetach, setProfileToDetach] = useState<TPkiApplicationProfile | null>(null);
const [profileToConfigure, setProfileToConfigure] = useState<TPkiApplicationProfile | null>(null);
const [enrollmentMethodToOpen, setEnrollmentMethodToOpen] = useState<EnrollmentMethod>();
@@ -409,6 +419,12 @@ export const ApplicationSettingsTab = ({ application, profiles }: Props) => {
setProfileToConfigure(profile);
};
+ const { permission } = useProjectPermission();
+ const canCreateProfile = permission.can(
+ ProjectPermissionCertificateProfileActions.Create,
+ ProjectPermissionSub.CertificateProfiles
+ );
+
const { data: profileList } = useListCertificateProfiles({ limit: 100 });
const attachMutation = useAttachPkiApplicationProfiles();
const detachMutation = useDetachPkiApplicationProfile();
@@ -481,26 +497,36 @@ export const ApplicationSettingsTab = ({ application, profiles }: Props) => {
[profileList, attachedIds]
);
const totalProfileCount = profileList?.certificateProfiles?.length ?? 0;
+ const hasAttachableProfiles = availableProfiles.length > 0;
let attachDisabledReason: ReactNode | null = null;
- if (availableProfiles.length === 0) {
+ if (!hasAttachableProfiles && !canCreateProfile) {
attachDisabledReason =
- totalProfileCount === 0 ? (
- <span>
- No certificate profiles exist yet. Create one in{" "}
- <Link
- to="/organizations/$orgId/projects/cert-manager/$projectId/certificate-profiles"
- params={{ orgId: orgId ?? "", projectId: projectId ?? "" }}
- className="text-primary underline hover:text-primary/80"
- >
- Certificate Profiles
- </Link>{" "}
- first.
- </span>
- ) : (
- "All certificate profiles are already attached."
- );
+ totalProfileCount === 0
+ ? "No certificate profiles exist yet, and you do not have permission to create one."
+ : "All certificate profiles are already attached.";
}
+ // Pinned above the scrolling option list, so creating a profile is not a selectable option
+ // masquerading as one.
+ const ProfileMenuList = useCallback(
+ (menuProps: MenuListProps<TProfileOption, true>) => (
+ <>
+ {canCreateProfile ? (
+ <button
+ type="button"
+ onClick={() => setIsCreateProfileOpen(true)}
+ className="flex w-full cursor-pointer items-center gap-x-1.5 rounded-sm px-2 py-1.5 text-sm text-muted hover:bg-foreground/5"
+ >
+ <PlusIcon className="size-4 shrink-0" />
+ Add Certificate Profile
+ </button>
+ ) : null}
+ <components.MenuList {...menuProps} />
+ </>
+ ),
+ [canCreateProfile]
+ );
+
const handleAttach = async () => {
if (profilesToAttach.length === 0) return;
try {
@@ -566,9 +592,14 @@ export const ApplicationSettingsTab = ({ application, profiles }: Props) => {
</TooltipContent>
</Tooltip>
) : (
- <Button variant="outline" onClick={() => setIsAttachOpen(true)}>
+ <Button
+ variant="outline"
+ onClick={() =>
+ hasAttachableProfiles ? setIsAttachOpen(true) : setIsCreateProfileOpen(true)
+ }
+ >
<PlusIcon />
- Attach Profile
+ {hasAttachableProfiles ? "Attach Profile" : "Create Profile"}
</Button>
)}
</CardAction>
@@ -580,8 +611,9 @@ export const ApplicationSettingsTab = ({ application, profiles }: Props) => {
<EmptyHeader>
<EmptyTitle>No profiles attached</EmptyTitle>
<EmptyDescription>
- Attach a certificate profile, then configure how this application enrolls against
- it.
+ {totalProfileCount === 0
+ ? "Create a certificate profile, then configure how this application enrolls against it."
+ : "Attach a certificate profile, then configure how this application enrolls against it."}
</EmptyDescription>
</EmptyHeader>
</Empty>
@@ -866,10 +898,9 @@ export const ApplicationSettingsTab = ({ application, profiles }: Props) => {
<FilterableSelect
isMulti
value={profilesToAttach}
- onChange={(val) =>
- setProfilesToAttach((val ?? []) as { value: string; label: string }[])
- }
+ onChange={(val) => setProfilesToAttach((val ?? []) as TProfileOption[])}
options={availableProfiles}
+ components={{ MenuList: ProfileMenuList }}
placeholder="Select profiles..."
/>
</div>
@@ -900,6 +931,28 @@ export const ApplicationSettingsTab = ({ application, profiles }: Props) => {
onDeleteApproved={handleDetach}
/>
+ <CreateProfileModal
+ isOpen={isCreateProfileOpen}
+ onClose={() => setIsCreateProfileOpen(false)}
+ onComplete={(createdProfile) => {
+ setIsCreateProfileOpen(false);
+ // Created from inside the attach dialog: add it to the pending selection so it is
+ // attached alongside whatever else was picked. Created straight from the card, there is
+ // no selection to submit, so attach it now.
+ if (isAttachOpen) {
+ setProfilesToAttach((prev) => [
+ ...prev,
+ { value: createdProfile.id, label: createdProfile.slug }
+ ]);
+ return;
+ }
+ attachMutation.mutate({
+ applicationId: application.id,
+ profileIds: [createdProfile.id]
+ });
+ }}
+ />
+
<ConfigureEnrollmentModal
isOpen={Boolean(profileToConfigure)}
onOpenChange={(open) => {
diff --git a/frontend/src/pages/cert-manager/ApplicationDetailsByIDPage/route.tsx b/frontend/src/pages/cert-manager/ApplicationDetailsByIDPage/route.tsx
index 5c75793918..fb4916f404 100644
--- a/frontend/src/pages/cert-manager/ApplicationDetailsByIDPage/route.tsx
+++ b/frontend/src/pages/cert-manager/ApplicationDetailsByIDPage/route.tsx
@@ -2,9 +2,10 @@ import { createFileRoute, stripSearchParams } from "@tanstack/react-router";
import { zodValidator } from "@tanstack/zod-adapter";
import { z } from "zod";
+import { ApplicationTab } from "./application-tabs";
import { ApplicationDetailsByIDPage } from "./ApplicationDetailsByIDPage";
-const ApplicationTabSchema = z.enum(["certificates", "requests", "syncs", "members", "settings"]);
+const ApplicationTabSchema = z.nativeEnum(ApplicationTab);
const SearchSchema = z.object({
selectedTab: ApplicationTabSchema.optional(),
@@ -16,7 +17,7 @@ export const Route = createFileRoute(
)({
component: ApplicationDetailsByIDPage,
validateSearch: zodValidator(SearchSchema),
- search: { middlewares: [stripSearchParams({ selectedTab: "certificates" })] },
+ search: { middlewares: [stripSearchParams({ selectedTab: ApplicationTab.Certificates })] },
beforeLoad: ({ context }) => ({
breadcrumbs: [...context.breadcrumbs, { label: "Applications" }, { label: "Application" }]
})
diff --git a/frontend/src/pages/cert-manager/ApplicationsPage/components/PkiApplicationModal.tsx b/frontend/src/pages/cert-manager/ApplicationsPage/components/PkiApplicationModal.tsx
index 800c7ddece..7ca446176a 100644
--- a/frontend/src/pages/cert-manager/ApplicationsPage/components/PkiApplicationModal.tsx
+++ b/frontend/src/pages/cert-manager/ApplicationsPage/components/PkiApplicationModal.tsx
@@ -1,7 +1,7 @@
import { useEffect, useMemo } from "react";
import { Controller, useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
-import { Link, useParams } from "@tanstack/react-router";
+import { useNavigate, useParams } from "@tanstack/react-router";
import { z } from "zod";
import { createNotification } from "@app/components/notifications";
@@ -29,6 +29,7 @@ import {
useUpdatePkiApplication
} from "@app/hooks/api/pkiApplications";
import { UsePopUpState } from "@app/hooks/usePopUp";
+import { ApplicationTab } from "@app/pages/cert-manager/ApplicationDetailsByIDPage/application-tabs";
const SLUG_REGEX = /^[a-z0-9-]+$/;
@@ -52,13 +53,12 @@ type Props = {
export const PkiApplicationModal = ({ popUp, handlePopUpToggle }: Props) => {
const { projectId, orgId } = useParams({ strict: false });
+ const navigate = useNavigate();
const editing = (popUp?.application?.data as TPkiApplication | undefined) ?? null;
const create = useCreatePkiApplication();
const update = useUpdatePkiApplication();
- const { data: profilesData, isPending: profilesLoading } = useListCertificateProfiles({
- limit: 100
- });
+ const { data: profilesData } = useListCertificateProfiles({ limit: 100 });
const profileOptions = useMemo(
() =>
@@ -102,12 +102,25 @@ export const PkiApplicationModal = ({ popUp, handlePopUpToggle }: Props) => {
createNotification({ type: "success", text: "Application updated" });
} else {
const selectedIds = (data.profileIds ?? []).map((p) => p.value);
- await create.mutateAsync({
+ const created = await create.mutateAsync({
name: data.name,
description: data.description,
profileIds: selectedIds
});
createNotification({ type: "success", text: "Application created" });
+ handlePopUpToggle("application", false);
+ // Land on Settings rather than the empty inventory: attaching a profile is the next step
+ // before the application can issue anything.
+ navigate({
+ to: "/organizations/$orgId/projects/cert-manager/$projectId/applications/$applicationName",
+ params: {
+ orgId: orgId ?? "",
+ projectId: projectId ?? "",
+ applicationName: created.name
+ },
+ search: { selectedTab: ApplicationTab.Settings }
+ });
+ return;
}
handlePopUpToggle("application", false);
} catch (err) {
@@ -161,7 +174,7 @@ export const PkiApplicationModal = ({ popUp, handlePopUpToggle }: Props) => {
</Field>
)}
/>
- {!editing ? (
+ {!editing && profileOptions.length > 0 ? (
<Controller
control={control}
name="profileIds"
@@ -180,16 +193,8 @@ export const PkiApplicationModal = ({ popUp, handlePopUpToggle }: Props) => {
/>
</FieldContent>
<FieldDescription>
- Select the profiles this application can issue certificates from.{" "}
- {!profilesLoading && !profileOptions.length && (
- <Link
- to="/organizations/$orgId/projects/cert-manager/$projectId/certificate-profiles"
- params={{ orgId: orgId ?? "", projectId: projectId ?? "" }}
- className="underline hover:text-yellow-400"
- >
- Create one in Certificate Profiles
- </Link>
- )}
+ Select the profiles this application can issue certificates from. You can also
+ attach them later from the application&apos;s settings.
</FieldDescription>
{error ? <FieldError>{error.message}</FieldError> : null}
</Field>
diff --git a/frontend/src/pages/cert-manager/PoliciesPage/components/CertificateProfilesTab/CreateProfileModal.tsx b/frontend/src/pages/cert-manager/PoliciesPage/components/CertificateProfilesTab/CreateProfileModal.tsx
index 747e7c2cca..fc45414ff5 100644
--- a/frontend/src/pages/cert-manager/PoliciesPage/components/CertificateProfilesTab/CreateProfileModal.tsx
+++ b/frontend/src/pages/cert-manager/PoliciesPage/components/CertificateProfilesTab/CreateProfileModal.tsx
@@ -51,6 +51,7 @@ import {
} from "@app/hooks/api/certificatePolicies";
import {
IssuerType,
+ TCertificateProfile,
TCertificateProfileDefaults,
TCertificateProfileWithDetails,
TCreateCertificateProfileDTO,
@@ -463,9 +464,16 @@ interface Props {
onClose: () => void;
profile?: TCertificateProfileWithDetails;
mode?: "create" | "edit" | "clone";
+ onComplete?: (profile: TCertificateProfile) => void;
}
-export const CreateProfileModal = ({ isOpen, onClose, profile, mode = "create" }: Props) => {
+export const CreateProfileModal = ({
+ isOpen,
+ onClose,
+ profile,
+ mode = "create",
+ onComplete
+}: Props) => {
const { currentProject } = useProject();
const { permission } = useProjectPermission();
const { orgId, projectId } = useParams({ strict: false }) as {
@@ -798,7 +806,8 @@ export const CreateProfileModal = ({ isOpen, onClose, profile, mode = "create" }
createData.defaults = serializedDefaults;
}
- await createProfile.mutateAsync(createData);
+ const createdProfile = await createProfile.mutateAsync(createData);
+ onComplete?.(createdProfile);
}
createNotification({