Skip to content

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

improvement(frontend): migrate kmip server details page to v3 (#8067)

claude[bot]b0f3b03bfb0f
diff --git a/frontend/src/hooks/api/kmipServers/mutations.tsx b/frontend/src/hooks/api/kmipServers/mutations.tsx
index 216163d3bf..e607cbd785 100644
--- a/frontend/src/hooks/api/kmipServers/mutations.tsx
+++ b/frontend/src/hooks/api/kmipServers/mutations.tsx
@@ -61,9 +61,14 @@ export const useUpdateKmipServer = () => {
);
return data;
},
- onSuccess: (_, { kmipServerId }) => {
+ onSuccess: (_, { kmipServerId, authMethod }) => {
queryClient.invalidateQueries({ queryKey: kmipServerQueryKeys.byId(kmipServerId) });
queryClient.invalidateQueries({ queryKey: kmipServerQueryKeys.list() });
+ // Changing the auth method deletes the server's token-auth record, so any minted enrollment
+ // command is no longer valid.
+ if (authMethod !== undefined) {
+ queryClient.setQueryData(kmipServerQueryKeys.enrollment(kmipServerId), null);
+ }
}
});
};
@@ -91,6 +96,7 @@ export const useRevokeKmipServerAccess = () => {
onSuccess: (_, { kmipServerId }) => {
queryClient.invalidateQueries({ queryKey: kmipServerQueryKeys.byId(kmipServerId) });
queryClient.invalidateQueries({ queryKey: kmipServerQueryKeys.list() });
+ queryClient.setQueryData(kmipServerQueryKeys.enrollment(kmipServerId), null);
}
});
};
diff --git a/frontend/src/hooks/api/kmipServers/queries.tsx b/frontend/src/hooks/api/kmipServers/queries.tsx
index 175a494bc0..b9cad0387a 100644
--- a/frontend/src/hooks/api/kmipServers/queries.tsx
+++ b/frontend/src/hooks/api/kmipServers/queries.tsx
@@ -6,7 +6,8 @@ import { TKmipServer, TKmipServerWithAuthMethod } from "./types";
export const kmipServerQueryKeys = {
list: () => ["kmip-servers"] as const,
- byId: (kmipServerId: string) => [{ kmipServerId }, "kmip-server"] as const
+ byId: (kmipServerId: string) => [{ kmipServerId }, "kmip-server"] as const,
+ enrollment: (kmipServerId: string) => [{ kmipServerId }, "kmip-server-enrollment"] as const
};
const fetchKmipServers = async (): Promise<TKmipServer[]> => {
diff --git a/frontend/src/pages/organization/KmipServersPage/KmipServerDetailsByIDPage/KmipServerDetailsByIDPage.tsx b/frontend/src/pages/organization/KmipServersPage/KmipServerDetailsByIDPage/KmipServerDetailsByIDPage.tsx
index d485b18930..cf1e88551c 100644
--- a/frontend/src/pages/organization/KmipServersPage/KmipServerDetailsByIDPage/KmipServerDetailsByIDPage.tsx
+++ b/frontend/src/pages/organization/KmipServersPage/KmipServerDetailsByIDPage/KmipServerDetailsByIDPage.tsx
@@ -1,11 +1,19 @@
import { Helmet } from "react-helmet";
import { useTranslation } from "react-i18next";
import { Link, useParams } from "@tanstack/react-router";
-import { ChevronLeftIcon } from "lucide-react";
+import { ChevronLeftIcon, ServerIcon } from "lucide-react";
import { OrgPermissionCan } from "@app/components/permissions";
-import { EmptyState } from "@app/components/v2";
-import { PageLoader } from "@app/components/v3";
+import {
+ Button,
+ Empty,
+ EmptyContent,
+ EmptyDescription,
+ EmptyHeader,
+ EmptyMedia,
+ EmptyTitle,
+ PageLoader
+} from "@app/components/v3";
import { ROUTE_PATHS } from "@app/const/routes";
import { useOrganization } from "@app/context";
import {
@@ -31,7 +39,26 @@ const Page = () => {
}
if (!kmipServer) {
- return <EmptyState title="KMIP server not found" />;
+ return (
+ <Empty className="border">
+ <EmptyHeader>
+ <EmptyMedia variant="icon">
+ <ServerIcon />
+ </EmptyMedia>
+ <EmptyTitle>KMIP server not found</EmptyTitle>
+ <EmptyDescription>
+ It may have been deleted. Return to the list to pick another KMIP server.
+ </EmptyDescription>
+ </EmptyHeader>
+ <EmptyContent>
+ <Button asChild variant="outline" size="sm">
+ <Link to="/organizations/$orgId/projects/kms/kmip-servers" params={{ orgId }}>
+ Back to KMIP Servers
+ </Link>
+ </Button>
+ </EmptyContent>
+ </Empty>
+ );
}
return (
@@ -39,17 +66,17 @@ const Page = () => {
<Link
to="/organizations/$orgId/projects/kms/kmip-servers"
params={{ orgId }}
- className="mb-4 flex w-fit items-center gap-x-1 text-sm text-mineshaft-400 transition hover:text-mineshaft-400/80"
+ className="mb-4 flex w-fit items-center gap-x-1 text-sm text-muted transition hover:text-label"
>
<ChevronLeftIcon size={16} />
KMIP Servers
</Link>
<KmipServerPageHeader kmipServer={kmipServer} orgId={orgId} />
- <div className="flex flex-col gap-5 lg:flex-row">
- <div className="flex w-full flex-col gap-y-5 lg:max-w-[24rem]">
+ <div className="flex flex-col gap-8 lg:flex-row">
+ <div className="w-full min-w-0 shrink-0 lg:w-96">
<KmipServerDetailsCard kmipServer={kmipServer} />
</div>
- <div className="flex flex-1 flex-col gap-y-5">
+ <div className="flex min-w-0 flex-1 flex-col gap-y-8">
<KmipServerDeploySection
kmipServerId={kmipServerId}
kmipServerName={kmipServer.name}
diff --git a/frontend/src/pages/organization/KmipServersPage/KmipServerDetailsByIDPage/components/KmipServerAuthMethod/KmipServerAuthMethodModal.tsx b/frontend/src/pages/organization/KmipServersPage/KmipServerDetailsByIDPage/components/KmipServerAuthMethod/KmipServerAuthMethodModal.tsx
index 652f61ccf7..736a4365e9 100644
--- a/frontend/src/pages/organization/KmipServersPage/KmipServerDetailsByIDPage/components/KmipServerAuthMethod/KmipServerAuthMethodModal.tsx
+++ b/frontend/src/pages/organization/KmipServersPage/KmipServerDetailsByIDPage/components/KmipServerAuthMethod/KmipServerAuthMethodModal.tsx
@@ -7,29 +7,34 @@ import { createNotification } from "@app/components/notifications";
import {
Button,
Dialog,
+ DialogClose,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
Field,
- FieldContent,
+ FieldDescription,
FieldError,
FieldLabel,
- FilterableSelect,
- Input
+ Input,
+ Select,
+ SelectContent,
+ SelectItem,
+ SelectTrigger,
+ SelectValue
} from "@app/components/v3";
-import { useOrganization } from "@app/context";
+import { useScopeVariant } from "@app/hooks";
import { useUpdateKmipServer } from "@app/hooks/api/kmipServers";
import { TKmipServerAuthMethodView } from "@app/hooks/api/kmipServers/types";
-type SettableMethod = "aws" | "token";
-
const METHOD_OPTIONS: { value: SettableMethod; label: string }[] = [
{ value: "token", label: "Token Auth" },
{ value: "aws", label: "AWS Auth" }
];
+const DEFAULT_STS_ENDPOINT = "https://sts.amazonaws.com/";
+
const schema = z
.object({
method: z.enum(["aws", "token"]),
@@ -59,13 +64,14 @@ const schema = z
}
});
-type FormData = z.infer<typeof schema>;
-
-type Props = {
- isOpen: boolean;
- onOpenChange: (isOpen: boolean) => void;
- kmipServerId: string;
- currentMethod: TKmipServerAuthMethodView;
+const toFormDefaults = (currentMethod: TKmipServerAuthMethodView): FormData => {
+ const aws = currentMethod.method === "aws" ? currentMethod.config : null;
+ return {
+ method: currentMethod.method === "aws" ? "aws" : "token",
+ stsEndpoint: aws?.stsEndpoint ?? DEFAULT_STS_ENDPOINT,
+ allowedPrincipalArns: aws?.allowedPrincipalArns ?? "",
+ allowedAccountIds: aws?.allowedAccountIds ?? ""
+ };
};
export const KmipServerAuthMethodModal = ({
@@ -75,10 +81,7 @@ export const KmipServerAuthMethodModal = ({
currentMethod
}: Props) => {
const { mutateAsync: updateKmipServer, isPending } = useUpdateKmipServer();
- const { isSubOrganization } = useOrganization();
-
- const initialMethod: SettableMethod = currentMethod.method === "aws" ? "aws" : "token";
- const initialAws = currentMethod.method === "aws" ? currentMethod.config : null;
+ const scopeVariant = useScopeVariant();
const {
control,
@@ -88,23 +91,11 @@ export const KmipServerAuthMethodModal = ({
formState: { isSubmitting, isDirty }
} = useForm<FormData>({
resolver: zodResolver(schema),
- defaultValues: {
- method: initialMethod,
- stsEndpoint: initialAws?.stsEndpoint ?? "https://sts.amazonaws.com/",
- allowedPrincipalArns: initialAws?.allowedPrincipalArns ?? "",
- allowedAccountIds: initialAws?.allowedAccountIds ?? ""
- }
+ defaultValues: toFormDefaults(currentMethod)
});
useEffect(() => {
- if (isOpen) {
- reset({
- method: initialMethod,
- stsEndpoint: initialAws?.stsEndpoint ?? "https://sts.amazonaws.com/",
- allowedPrincipalArns: initialAws?.allowedPrincipalArns ?? "",
- allowedAccountIds: initialAws?.allowedAccountIds ?? ""
- });
- }
+ if (isOpen) reset(toFormDefaults(currentMethod));
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [isOpen]);
@@ -128,46 +119,45 @@ export const KmipServerAuthMethodModal = ({
createNotification({ type: "success", text: "Auth method updated" });
onOpenChange(false);
} catch {
- createNotification({ type: "error", text: "Failed to update auth method" });
+ // MutationCache.onError already surfaces the API error.
}
};
return (
<Dialog open={isOpen} onOpenChange={onOpenChange}>
- <DialogContent className="max-w-lg">
+ <DialogContent>
<DialogHeader>
<DialogTitle>Edit Auth Method</DialogTitle>
<DialogDescription>
Switch the KMIP server&apos;s auth method or update the current method&apos;s config.
</DialogDescription>
</DialogHeader>
- <form onSubmit={handleSubmit(onSubmit)} className="space-y-4">
+ <form onSubmit={handleSubmit(onSubmit)} className="flex flex-col gap-4">
<Controller
control={control}
name="method"
- render={({ field }) => {
- const selected =
- METHOD_OPTIONS.find((o) => o.value === field.value) ?? METHOD_OPTIONS[0];
- return (
- <Field>
- <FieldLabel>Method</FieldLabel>
- <FieldContent>
- <FilterableSelect
- value={selected}
- onChange={(opt) => {
- const next = opt as { value: SettableMethod } | null;
- if (next) field.onChange(next.value);
- }}
- options={METHOD_OPTIONS}
- isSearchable={false}
- isClearable={false}
- getOptionLabel={(o) => o.label}
- getOptionValue={(o) => o.value}
- />
- </FieldContent>
- </Field>
- );
- }}
+ render={({ field: { onChange, value }, fieldState: { error } }) => (
+ <Field data-invalid={Boolean(error)}>
+ <FieldLabel htmlFor="kmip-server-auth-method">Method</FieldLabel>
+ <Select value={value} onValueChange={onChange}>
+ <SelectTrigger
+ id="kmip-server-auth-method"
+ isError={Boolean(error)}
+ className="w-full"
+ >
+ <SelectValue />
+ </SelectTrigger>
+ <SelectContent>
+ {METHOD_OPTIONS.map((option) => (
+ <SelectItem key={option.value} value={option.value}>
+ {option.label}
+ </SelectItem>
+ ))}
+ </SelectContent>
+ </Select>
+ <FieldError>{error?.message}</FieldError>
+ </Field>
+ )}
/>
{method === "aws" && (
@@ -176,16 +166,21 @@ export const KmipServerAuthMethodModal = ({
control={control}
name="allowedPrincipalArns"
render={({ field, fieldState: { error } }) => (
- <Field>
- <FieldLabel>Allowed Principal ARNs</FieldLabel>
- <FieldContent>
- <Input
- {...field}
- isError={Boolean(error)}
- placeholder="arn:aws:iam::123456789012:role/MyRoleName, arn:aws:iam::123456789012:user/MyUserName..."
- />
- <FieldError errors={[error]} />
- </FieldContent>
+ <Field data-invalid={Boolean(error)}>
+ <FieldLabel htmlFor="kmip-server-allowed-principal-arns">
+ Allowed Principal ARNs
+ </FieldLabel>
+ <Input
+ {...field}
+ id="kmip-server-allowed-principal-arns"
+ isError={Boolean(error)}
+ placeholder="arn:aws:iam::123456789012:role/MyRoleName, arn:aws:iam::123456789012:user/MyUserName"
+ />
+ <FieldDescription>
+ Comma-separated. Set at least one of allowed principal ARNs or allowed account
+ IDs.
+ </FieldDescription>
+ <FieldError>{error?.message}</FieldError>
</Field>
)}
/>
@@ -193,12 +188,17 @@ export const KmipServerAuthMethodModal = ({
control={control}
name="allowedAccountIds"
render={({ field, fieldState: { error } }) => (
- <Field>
- <FieldLabel>Allowed Account IDs</FieldLabel>
- <FieldContent>
- <Input {...field} isError={Boolean(error)} placeholder="123456789012, ..." />
- <FieldError errors={[error]} />
- </FieldContent>
+ <Field data-invalid={Boolean(error)}>
+ <FieldLabel htmlFor="kmip-server-allowed-account-ids">
+ Allowed Account IDs
+ </FieldLabel>
+ <Input
+ {...field}
+ id="kmip-server-allowed-account-ids"
+ isError={Boolean(error)}
+ placeholder="123456789012, 210987654321"
+ />
+ <FieldError>{error?.message}</FieldError>
</Field>
)}
/>
@@ -206,33 +206,34 @@ export const KmipServerAuthMethodModal = ({
control={control}
name="stsEndpoint"
render={({ field, fieldState: { error } }) => (
- <Field>
- <FieldLabel>STS Endpoint</FieldLabel>
- <FieldContent>
- <Input
- {...field}
- isError={Boolean(error)}
- placeholder="https://sts.amazonaws.com/"
- />
- <FieldError errors={[error]} />
- </FieldContent>
+ <Field data-invalid={Boolean(error)}>
+ <FieldLabel htmlFor="kmip-server-sts-endpoint">STS Endpoint</FieldLabel>
+ <Input
+ {...field}
+ id="kmip-server-sts-endpoint"
+ isError={Boolean(error)}
+ placeholder={DEFAULT_STS_ENDPOINT}
+ />
+ <FieldError>{error?.message}</FieldError>
</Field>
)}
/>
</>
)}
- <DialogFooter className="gap-2 sm:gap-2">
- <Button type="button" variant="ghost" onClick={() => onOpenChange(false)}>
- Cancel
- </Button>
+ <DialogFooter>
+ <DialogClose asChild>
+ <Button type="button" variant="ghost">
+ Cancel
+ </Button>
+ </DialogClose>
<Button
type="submit"
- variant={isSubOrganization ? "sub-org" : "org"}
+ variant={scopeVariant}
isPending={isSubmitting || isPending}
isDisabled={isSubmitting || isPending || !isDirty}
>
- Update
+ Update Auth Method
</Button>
</DialogFooter>
</form>
@@ -240,3 +241,14 @@ export const KmipServerAuthMethodModal = ({
</Dialog>
);
};
+
+type SettableMethod = "aws" | "token";
+
+type FormData = z.infer<typeof schema>;
+
+type Props = {
+ isOpen: boolean;
+ onOpenChange: (isOpen: boolean) => void;
+ kmipServerId: string;
+ currentMethod: TKmipServerAuthMethodView;
+};
diff --git a/frontend/src/pages/organization/KmipServersPage/KmipServerDetailsByIDPage/components/KmipServerCertConfig/KmipServerCertConfigModal.tsx b/frontend/src/pages/organization/KmipServersPage/KmipServerDetailsByIDPage/components/KmipServerCertConfig/KmipServerCertConfigModal.tsx
index c32cc4db04..610fd6a14b 100644
--- a/frontend/src/pages/organization/KmipServersPage/KmipServerDetailsByIDPage/components/KmipServerCertConfig/KmipServerCertConfigModal.tsx
+++ b/frontend/src/pages/organization/KmipServersPage/KmipServerDetailsByIDPage/components/KmipServerCertConfig/KmipServerCertConfigModal.tsx
@@ -7,19 +7,24 @@ import { createNotification } from "@app/components/notifications";
import {
Button,
Dialog,
+ DialogClose,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
Field,
- FieldContent,
+ FieldDescription,
FieldError,
FieldLabel,
- FilterableSelect,
- Input
+ Input,
+ Select,
+ SelectContent,
+ SelectItem,
+ SelectTrigger,
+ SelectValue
} from "@app/components/v3";
-import { useOrganization } from "@app/context";
+import { useScopeVariant } from "@app/hooks";
import {
certKeyAlgorithms,
certKeyAlgorithmToNameMap,
@@ -29,9 +34,7 @@ import { CertKeyAlgorithm } from "@app/hooks/api/certificates/enums";
import { useUpdateKmipServer } from "@app/hooks/api/kmipServers";
import { TKmipServerWithAuthMethod } from "@app/hooks/api/kmipServers/types";
-const keyAlgorithmOptions = certKeyAlgorithms
- .filter(({ value }) => !isPqcAlgorithm(value))
- .map(({ value }) => ({ value, label: certKeyAlgorithmToNameMap[value] }));
+const keyAlgorithmOptions = certKeyAlgorithms.filter(({ value }) => !isPqcAlgorithm(value));
const schema = z.object({
hostnamesOrIps: z
@@ -42,22 +45,14 @@ const schema = z.object({
keyAlgorithm: z.nativeEnum(CertKeyAlgorithm)
});
-type FormData = z.infer<typeof schema>;
-
-type Props = {
- isOpen: boolean;
- onOpenChange: (isOpen: boolean) => void;
- kmipServer: TKmipServerWithAuthMethod;
-};
+const toFormDefaults = (kmipServer: TKmipServerWithAuthMethod): FormData => ({
+ hostnamesOrIps: kmipServer.hostnamesOrIps ?? "",
+ keyAlgorithm: (kmipServer.keyAlgorithm as CertKeyAlgorithm) ?? CertKeyAlgorithm.RSA_2048
+});
export const KmipServerCertConfigModal = ({ isOpen, onOpenChange, kmipServer }: Props) => {
const { mutateAsync: updateKmipServer, isPending } = useUpdateKmipServer();
- const { isSubOrganization } = useOrganization();
-
- const defaults: FormData = {
- hostnamesOrIps: kmipServer.hostnamesOrIps ?? "",
- keyAlgorithm: (kmipServer.keyAlgorithm as CertKeyAlgorithm) ?? CertKeyAlgorithm.RSA_2048
- };
+ const scopeVariant = useScopeVariant();
const {
control,
@@ -66,11 +61,11 @@ export const KmipServerCertConfigModal = ({ isOpen, onOpenChange, kmipServer }:
formState: { isSubmitting, isDirty }
} = useForm<FormData>({
resolver: zodResolver(schema),
- defaultValues: defaults
+ defaultValues: toFormDefaults(kmipServer)
});
useEffect(() => {
- if (isOpen) reset(defaults);
+ if (isOpen) reset(toFormDefaults(kmipServer));
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [isOpen]);
@@ -87,13 +82,13 @@ export const KmipServerCertConfigModal = ({ isOpen, onOpenChange, kmipServer }:
});
onOpenChange(false);
} catch {
- createNotification({ type: "error", text: "Failed to update certificate configuration" });
+ // MutationCache.onError already surfaces the API error.
}
};
return (
<Dialog open={isOpen} onOpenChange={onOpenChange}>
- <DialogContent className="max-w-lg">
+ <DialogContent>
<DialogHeader>
<DialogTitle>Edit Certificate Configuration</DialogTitle>
<DialogDescription>
@@ -101,63 +96,76 @@ export const KmipServerCertConfigModal = ({ isOpen, onOpenChange, kmipServer }:
apply them immediately.
</DialogDescription>
</DialogHeader>
- <form onSubmit={handleSubmit(onSubmit)} className="space-y-4">
+ <form onSubmit={handleSubmit(onSubmit)} className="flex flex-col gap-4">
<Controller
control={control}
name="hostnamesOrIps"
render={({ field, fieldState: { error } }) => (
- <Field>
- <FieldLabel>Hostnames or IPs</FieldLabel>
- <FieldContent>
- <Input
- {...field}
- isError={Boolean(error)}
- placeholder="kmip.example.com, 10.0.0.5"
- />
- <FieldError errors={[error]} />
- </FieldContent>
+ <Field data-invalid={Boolean(error)}>
+ <FieldLabel htmlFor="kmip-server-cert-hostnames">
+ Hostnames or IPs
+ <span aria-hidden className="text-danger">
+ *
+ </span>
+ </FieldLabel>
+ <Input
+ {...field}
+ id="kmip-server-cert-hostnames"
+ placeholder="kmip.example.com, 10.0.0.5"
+ aria-required
+ isError={Boolean(error)}
+ />
+ <FieldDescription>
+ Comma-separated list of the hostnames or IPs that KMIP clients will use to reach
+ this server. These become the server certificate&apos;s subject alternative names.
+ </FieldDescription>
+ <FieldError>{error?.message}</FieldError>
</Field>
)}
/>
<Controller
control={control}
name="keyAlgorithm"
- render={({ field }) => {
- const selected =
- keyAlgorithmOptions.find((o) => o.value === field.value) ?? keyAlgorithmOptions[0];
- return (
- <Field>
- <FieldLabel>Key Algorithm</FieldLabel>
- <FieldContent>
- <FilterableSelect
- value={selected}
- onChange={(opt) => {
- const next = opt as { value: CertKeyAlgorithm } | null;
- if (next) field.onChange(next.value);
- }}
- options={keyAlgorithmOptions}
- isSearchable={false}
- isClearable={false}
- getOptionLabel={(o) => o.label}
- getOptionValue={(o) => String(o.value)}
- />
- </FieldContent>
- </Field>
- );
- }}
+ render={({ field: { onChange, value }, fieldState: { error } }) => (
+ <Field data-invalid={Boolean(error)}>
+ <FieldLabel htmlFor="kmip-server-cert-key-algorithm">Key algorithm</FieldLabel>
+ <Select value={value} onValueChange={onChange}>
+ <SelectTrigger
+ id="kmip-server-cert-key-algorithm"
+ isError={Boolean(error)}
+ className="w-full"
+ >
+ <SelectValue />
+ </SelectTrigger>
+ <SelectContent>
+ {keyAlgorithmOptions.map(({ value: algorithm }) => (
+ <SelectItem value={algorithm} key={algorithm}>
+ {certKeyAlgorithmToNameMap[algorithm]}
+ </SelectItem>
+ ))}
+ </SelectContent>
+ </Select>
+ <FieldDescription>
+ Key algorithm used to sign the server certificate.
+ </FieldDescription>
+ <FieldError>{error?.message}</FieldError>
+ </Field>
+ )}
/>
- <DialogFooter className="gap-2 sm:gap-2">
- <Button type="button" variant="ghost" onClick={() => onOpenChange(false)}>
- Cancel
- </Button>
+ <DialogFooter>
+ <DialogClose asChild>
+ <Button type="button" variant="ghost">
+ Cancel
+ </Button>
+ </DialogClose>
<Button
type="submit"
- variant={isSubOrganization ? "sub-org" : "org"}
+ variant={scopeVariant}
isPending={isSubmitting || isPending}
isDisabled={isSubmitting || isPending || !isDirty}
>
- Update
+ Update Certificate Configuration
</Button>
</DialogFooter>
</form>
@@ -165,3 +173,11 @@ export const KmipServerCertConfigModal = ({ isOpen, onOpenChange, kmipServer }:
</Dialog>
);
};
+
+type FormData = z.infer<typeof schema>;
+
+type Props = {
+ isOpen: boolean;
+ onOpenChange: (isOpen: boolean) => void;
+ kmipServer: TKmipServerWithAuthMethod;
+};
diff --git a/frontend/src/pages/organization/KmipServersPage/KmipServerDetailsByIDPage/components/KmipServerClientsSection/KmipServerClientsSection.tsx b/frontend/src/pages/organization/KmipServersPage/KmipServerDetailsByIDPage/components/KmipServerClientsSection/KmipServerClientsSection.tsx
index 475b99773e..89bbd6dd10 100644
--- a/frontend/src/pages/organization/KmipServersPage/KmipServerDetailsByIDPage/components/KmipServerClientsSection/KmipServerClientsSection.tsx
+++ b/frontend/src/pages/organization/KmipServersPage/KmipServerDetailsByIDPage/components/KmipServerClientsSection/KmipServerClientsSection.tsx
@@ -1,9 +1,14 @@
-import { ArrowUpRightIcon, BookOpenIcon } from "lucide-react";
-
-import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@app/components/v3";
+import {
+ Card,
+ CardContent,
+ CardDescription,
+ CardHeader,
+ CardTitle,
+ DocumentationLinkBadge
+} from "@app/components/v3";
const STEPS = [
- "Deploy this KMIP server on a target host (see Deployment above).",
+ "Deploy this KMIP server on a target host using the Deployment card above.",
"Create a KMIP client in a KMS project's KMIP settings.",
"Generate a client certificate for that client.",
"Point your KMIP application at the server address using the client certificate."
@@ -11,37 +16,28 @@ const STEPS = [
export const KmipServerClientsSection = () => {
return (
- <Card className="w-full">
+ <Card className="min-w-0" aria-labelledby="kmip-server-clients-title">
<CardHeader>
- <CardTitle>Connecting KMIP Clients</CardTitle>
+ <CardTitle>
+ <h2 id="kmip-server-clients-title">Connecting KMIP Clients</h2>
+ <DocumentationLinkBadge href="https://infisical.com/docs/documentation/platform/kms/kmip" />
+ </CardTitle>
<CardDescription>
KMIP clients authenticate to this server with a client certificate to run key operations.
- Clients are managed per-project from a KMS project&apos;s KMIP settings.
+ Clients are managed per project from a KMS project&apos;s KMIP settings.
</CardDescription>
</CardHeader>
<CardContent>
<ol className="flex flex-col gap-y-3">
{STEPS.map((step, idx) => (
- <li key={step} className="flex items-start gap-x-3 text-sm text-mineshaft-300">
- <span className="flex size-5 shrink-0 items-center justify-center rounded-full bg-mineshaft-600 text-xs font-medium text-mineshaft-200">
+ <li key={step} className="flex items-start gap-x-3 text-sm text-label">
+ <span className="flex size-5 shrink-0 items-center justify-center rounded-full border border-border bg-container text-xs font-medium text-foreground">
{idx + 1}
</span>
<span>{step}</span>
</li>
))}
</ol>
- <div className="mt-5 flex flex-wrap items-center gap-x-6 gap-y-2">
- <a
- href="https://infisical.com/docs/documentation/platform/kms/kmip"
- target="_blank"
- rel="noreferrer"
- className="flex items-center gap-x-2 text-sm text-mineshaft-300 transition-colors hover:text-mineshaft-100"
- >
- <BookOpenIcon className="size-4" />
- View docs
- <ArrowUpRightIcon className="size-3" />
- </a>
- </div>
</CardContent>
</Card>
);
diff --git a/frontend/src/pages/organization/KmipServersPage/KmipServerDetailsByIDPage/components/KmipServerDeploySection/AwsStartCommandContent.tsx b/frontend/src/pages/organization/KmipServersPage/KmipServerDetailsByIDPage/components/KmipServerDeploySection/AwsStartCommandContent.tsx
new file mode 100644
index 0000000000..7630a7400d
--- /dev/null
+++ b/frontend/src/pages/organization/KmipServersPage/KmipServerDetailsByIDPage/components/KmipServerDeploySection/AwsStartCommandContent.tsx
@@ -0,0 +1,31 @@
+import { CodeBlock, TabsContent } from "@app/components/v3";
+
+import { getKmipServerSiteUrl, KMIP_START_SERVICE_COMMAND } from "./commands";
+
+export const AwsStartCommandContent = ({ kmipServerId, kmipServerName }: Props) => {
+ const siteURL = getKmipServerSiteUrl();
+ const enrollArgs = `--enroll-method=aws --kmip-server-id=${kmipServerId} --domain=${siteURL}`;
+ const cliCommand = `infisical kmip start ${kmipServerName} ${enrollArgs}`;
+ const systemdInstallCommand = `sudo infisical kmip systemd install ${kmipServerName} ${enrollArgs}`;
+
+ return (
+ <div className="min-w-0 space-y-4">
+ <TabsContent value="cli" className="min-w-0">
+ <CodeBlock value={cliCommand} label="Command" />
+ </TabsContent>
+ <TabsContent value="systemd" className="min-w-0 space-y-4">
+ <CodeBlock value={systemdInstallCommand} label="Install service" />
+ <CodeBlock value={KMIP_START_SERVICE_COMMAND} label="Start service" />
+ </TabsContent>
+ <p className="text-xs text-muted">
+ The host needs AWS credentials whose principal matches the allowlist. The certificate config
+ (hostnames or IPs, TTL, key algorithm) is read from this server&apos;s settings.
+ </p>
+ </div>
+ );
+};
+
+type Props = {
+ kmipServerId: string;
+ kmipServerName: string;
+};
diff --git a/frontend/src/pages/organization/KmipServersPage/KmipServerDetailsByIDPage/components/KmipServerDeploySection/EnrollmentTokenContent.tsx b/frontend/src/pages/organization/KmipServersPage/KmipServerDetailsByIDPage/components/KmipServerDeploySection/EnrollmentTokenContent.tsx
new file mode 100644
index 0000000000..aef7b6d761
--- /dev/null
+++ b/frontend/src/pages/organization/KmipServersPage/KmipServerDetailsByIDPage/components/KmipServerDeploySection/EnrollmentTokenContent.tsx
@@ -0,0 +1,66 @@
+import { useEffect, useState } from "react";
+
+import { Badge, CodeBlock, TabsContent } from "@app/components/v3";
+
+import { getKmipServerSiteUrl, KMIP_START_SERVICE_COMMAND } from "./commands";
+
+const formatTimeRemaining = (expiresAt: string, now: number) => {
+ const remainingSeconds = Math.max(0, Math.ceil((new Date(expiresAt).getTime() - now) / 1000));
+ if (remainingSeconds === 0) return "Expired";
+
+ const hours = Math.floor(remainingSeconds / 3600);
+ const minutes = Math.floor((remainingSeconds % 3600) / 60);
+ const seconds = remainingSeconds % 60;
+
+ if (hours > 0) return `${hours}h ${minutes}m remaining`;
+ return `${minutes}m ${seconds}s remaining`;
+};
+
+export const EnrollmentTokenContent = ({ kmipServerName, enrollmentToken, expiresAt }: Props) => {
+ const siteURL = getKmipServerSiteUrl();
+ const [now, setNow] = useState(Date.now());
+
+ useEffect(() => {
+ const timer = window.setInterval(() => setNow(Date.now()), 1000);
+ return () => window.clearInterval(timer);
+ }, []);
+
+ const expiryLabel = formatTimeRemaining(expiresAt, now);
+ const isExpired = expiryLabel === "Expired";
+ const enrollArgs = `--enroll-method=token --token=${enrollmentToken} --domain=${siteURL}`;
+ const cliCommand = `infisical kmip start ${kmipServerName} ${enrollArgs}`;
+ const systemdInstallCommand = `sudo infisical kmip systemd install ${kmipServerName} ${enrollArgs}`;
+
+ const labelWithExpiry = (label: string) => (
+ <span className="flex w-full items-center justify-between gap-2">
+ <span>{label}</span>
+ <Badge variant={isExpired ? "danger" : "neutral"}>{expiryLabel}</Badge>
+ </span>
+ );
+
+ return (
+ <div className="min-w-0 space-y-4">
+ <TabsContent value="cli" className="min-w-0">
+ <CodeBlock value={cliCommand} label={labelWithExpiry("Command")} isCopyable={!isExpired} />
+ </TabsContent>
+ <TabsContent value="systemd" className="min-w-0 space-y-4">
+ <CodeBlock
+ value={systemdInstallCommand}
+ label={labelWithExpiry("Install service")}
+ isCopyable={!isExpired}
+ />
+ <CodeBlock value={KMIP_START_SERVICE_COMMAND} label="Start service" />
+ </TabsContent>
+ <p className="text-xs text-muted">
+ The enrollment token can be used once. The certificate config (hostnames or IPs, TTL, key
+ algorithm) is read from this server&apos;s settings.
+ </p>
+ </div>
+ );
+};
+
+type Props = {
+ kmipServerName: string;
+ enrollmentToken: string;
+ expiresAt: string;
+};
diff --git a/frontend/src/pages/organization/KmipServersPage/KmipServerDetailsByIDPage/components/KmipServerDeploySection/KmipServerDeployCommandDialog.tsx b/frontend/src/pages/organization/KmipServersPage/KmipServerDetailsByIDPage/components/KmipServerDeploySection/KmipServerDeployCommandDialog.tsx
deleted file mode 100644
index 430b540c71..0000000000
--- a/frontend/src/pages/organization/KmipServersPage/KmipServerDetailsByIDPage/components/KmipServerDeploySection/KmipServerDeployCommandDialog.tsx
+++ /dev/null
@@ -1,154 +0,0 @@
-import { useMemo } from "react";
-import { faCopy, faUpRightFromSquare } from "@fortawesome/free-solid-svg-icons";
-import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
-
-import { createNotification } from "@app/components/notifications";
-import {
- Button,
- FormLabel,
- IconButton,
- Input,
- Modal,
- ModalClose,
- ModalContent,
- Tab,
- TabList,
- TabPanel,
- Tabs
-} from "@app/components/v2";
-import { Badge } from "@app/components/v3/generic/Badge";
-
-type Props = {
- isOpen: boolean;
- onOpenChange: (isOpen: boolean) => void;
- kmipServerId: string;
- kmipServerName: string;
- authMethod: "token" | "aws";
- enrollmentToken: string | null;
-};
-
-export const KmipServerDeployCommandDialog = ({
- isOpen,
- onOpenChange,
- kmipServerId,
- kmipServerName,
- authMethod,
- enrollmentToken
-}: Props) => {
- const { protocol, hostname, port } = window.location;
- const portSuffix = port && port !== "80" ? `:${port}` : "";
- const siteURL = `${protocol}//${hostname}${portSuffix}`;
-
- const cliCommand = useMemo(() => {
- const common = `--domain=${siteURL}`;
- if (authMethod === "aws") {
- return `infisical kmip start ${kmipServerName} --enroll-method=aws --kmip-server-id=${kmipServerId} ${common}`;
- }
- return `infisical kmip start ${kmipServerName} --enroll-method=token --token=${enrollmentToken} ${common}`;
- }, [kmipServerName, kmipServerId, enrollmentToken, authMethod, siteURL]);
-
- const systemdInstallCommand = useMemo(() => {
- const common = `--domain=${siteURL}`;
- if (authMethod === "aws") {
- return `sudo infisical kmip systemd install ${kmipServerName} --enroll-method=aws --kmip-server-id=${kmipServerId} ${common}`;
- }
- return `sudo infisical kmip systemd install ${kmipServerName} --enroll-method=token --token=${enrollmentToken} ${common}`;
- }, [kmipServerName, kmipServerId, enrollmentToken, authMethod, siteURL]);
-
- const startServiceCommand = "sudo systemctl start infisical-kmip";
-
- const copy = (text: string, label: string) => {
- navigator.clipboard.writeText(text);
- createNotification({ type: "info", text: `${label} copied to clipboard` });
- };
-
- const badgeLabel = authMethod === "aws" ? "AWS Auth" : "Token Auth";
- const helperText =
- authMethod === "aws"
- ? "The host must have AWS credentials whose principal matches your allowlist. The certificate config (hostnames/IPs, TTL, key algorithm) is read from the server's settings."
- : "The enrollment token expires in 1 hour and can only be used once. The certificate config (hostnames/IPs, TTL, key algorithm) is read from the server's settings.";
-
- return (
- <Modal isOpen={isOpen} onOpenChange={onOpenChange}>
- <ModalContent
- className="max-w-2xl"
- title={`Deploy command for ${kmipServerName}`}
- subTitle="Run the following command on the machine where you want to deploy the KMIP server."
- bodyClassName="overflow-visible"
- >
- <div className="mb-4">
- <div className="mb-0.5 flex items-center gap-2">
- <FormLabel label="Auth Method" className="mb-0 text-foreground" />
- <Badge variant="info">{badgeLabel}</Badge>
- </div>
- <p className="mt-1 text-xs text-mineshaft-400">{helperText}</p>
- </div>
-
- <Tabs defaultValue="cli" className="mt-2">
- <TabList>
- <Tab value="cli">CLI</Tab>
- <Tab value="systemd">CLI (systemd)</Tab>
- </TabList>
- <TabPanel value="cli">
- <div className="flex gap-2">
- <Input value={cliCommand} isDisabled />
- <IconButton
- ariaLabel="copy"
- variant="outline_bg"
- colorSchema="secondary"
- onClick={() => copy(cliCommand, "Command")}
- className="w-10"
- >
- <FontAwesomeIcon icon={faCopy} />
- </IconButton>
- </div>
- </TabPanel>
- <TabPanel value="systemd">
- <FormLabel label="Installation Command" />
- <div className="flex gap-2">
- <Input value={systemdInstallCommand} isDisabled />
- <IconButton
- ariaLabel="copy install"
- variant="outline_bg"
- colorSchema="secondary"
- onClick={() => copy(systemdInstallCommand, "Installation command")}
- className="w-10"
- >
- <FontAwesomeIcon icon={faCopy} />
- </IconButton>
- </div>
- <FormLabel label="Start the KMIP Server Service" className="mt-4" />
- <div className="flex gap-2">
- <Input value={startServiceCommand} isDisabled />
- <IconButton
- ariaLabel="copy start"
- variant="outline_bg"
- colorSchema="secondary"
- onClick={() => copy(startServiceCommand, "Start command")}
- className="w-10"
- >
- <FontAwesomeIcon icon={faCopy} />
- </IconButton>
- </div>
- </TabPanel>
- </Tabs>
- <a
- href="https://infisical.com/docs/cli/overview"
- target="_blank"
- rel="noreferrer"
- className="mt-2 flex h-4 w-fit items-center gap-2 border-b border-mineshaft-400 text-sm text-mineshaft-400 transition-colors hover:border-yellow-400 hover:text-yellow-400"
- >
- <span>Install the Infisical CLI</span>
- <FontAwesomeIcon icon={faUpRightFromSquare} className="size-3" />
- </a>
- <div className="mt-6 flex items-center">
- <ModalClose asChild>
- <Button className="mr-4" size="sm" colorSchema="secondary">
- Done
- </Button>
- </ModalClose>
- </div>
- </ModalContent>
- </Modal>
- );
-};
diff --git a/frontend/src/pages/organization/KmipServersPage/KmipServerDetailsByIDPage/components/KmipServerDeploySection/KmipServerDeploySection.tsx b/frontend/src/pages/organization/KmipServersPage/KmipServerDetailsByIDPage/components/KmipServerDeploySection/KmipServerDeploySection.tsx
index 98717acf8a..33f473fb96 100644
--- a/frontend/src/pages/organization/KmipServersPage/KmipServerDetailsByIDPage/components/KmipServerDeploySection/KmipServerDeploySection.tsx
+++ b/frontend/src/pages/organization/KmipServersPage/KmipServerDetailsByIDPage/components/KmipServerDeploySection/KmipServerDeploySection.tsx
@@ -1,97 +1,170 @@
-import { useState } from "react";
-import { RocketIcon } from "lucide-react";
+import { useLayoutEffect, useRef, useState } from "react";
+import { useQuery, useQueryClient } from "@tanstack/react-query";
+import { LockKeyholeIcon, RefreshCwIcon, RocketIcon } from "lucide-react";
-import { createNotification } from "@app/components/notifications";
-import { OrgPermissionCan } from "@app/components/permissions";
import {
+ Alert,
+ AlertDescription,
+ AlertTitle,
Button,
Card,
CardAction,
+ CardContent,
CardDescription,
CardHeader,
- CardTitle
+ CardTitle,
+ DocumentationLinkBadge,
+ Tabs,
+ TabsList,
+ TabsTrigger
} from "@app/components/v3";
+import { useOrgPermission } from "@app/context";
import {
OrgKmipServerPermissionActions,
OrgPermissionSubjects
} from "@app/context/OrgPermissionContext/types";
-import { useGenerateKmipServerEnrollmentToken } from "@app/hooks/api/kmipServers";
+import {
+ kmipServerQueryKeys,
+ useGenerateKmipServerEnrollmentToken
+} from "@app/hooks/api/kmipServers";
import { TKmipServerAuthMethodView } from "@app/hooks/api/kmipServers/types";
-import { KmipServerDeployCommandDialog } from "./KmipServerDeployCommandDialog";
+import { AwsStartCommandContent } from "./AwsStartCommandContent";
+import { createKmipEnrollmentMintCommit } from "./enrollmentMintGuard";
+import { EnrollmentTokenContent } from "./EnrollmentTokenContent";
-type Props = {
- kmipServerId: string;
- kmipServerName: string;
- authMethod: TKmipServerAuthMethodView;
-};
+const DEPLOYMENT_TABS = ["cli", "systemd"];
export const KmipServerDeploySection = ({ kmipServerId, kmipServerName, authMethod }: Props) => {
- const [showDialog, setShowDialog] = useState(false);
- const [enrollmentToken, setEnrollmentToken] = useState<string | null>(null);
+ const [deploymentMethod, setDeploymentMethod] = useState("");
+ const queryClient = useQueryClient();
+ const enrollmentQueryKey = kmipServerQueryKeys.enrollment(kmipServerId);
+ // The minted command lives in the query cache so the auth-method and revoke mutations can drop
+ // it: both delete the server's token-auth record, which makes the command invalid.
+ const { data: enrollment } = useQuery<MintedEnrollment | null>({
+ queryKey: enrollmentQueryKey,
+ enabled: false,
+ gcTime: 0,
+ staleTime: Infinity
+ });
const { mutateAsync: mint, isPending: isMinting } = useGenerateKmipServerEnrollmentToken();
+ const lifecycleRevisionRef = useRef(0);
+ const { permission } = useOrgPermission();
+ const canEditKmipServer = permission.can(
+ OrgKmipServerPermissionActions.EditKmipServers,
+ OrgPermissionSubjects.KmipServer
+ );
+
+ useLayoutEffect(() => {
+ lifecycleRevisionRef.current += 1;
+
+ return () => {
+ lifecycleRevisionRef.current += 1;
+ };
+ }, [kmipServerId, authMethod.method]);
if (authMethod.method === "identity") return null;
- const handleClick = async () => {
- if (authMethod.method === "token") {
- try {
- const result = await mint({ kmipServerId });
- setEnrollmentToken(result.token);
- setShowDialog(true);
- } catch {
- createNotification({ type: "error", text: "Failed to generate enrollment token" });
- }
- } else {
- setShowDialog(true);
+ const showDeploymentControls = authMethod.method === "aws" || Boolean(enrollment);
+ const activeTab = DEPLOYMENT_TABS.includes(deploymentMethod)
+ ? deploymentMethod
+ : DEPLOYMENT_TABS[0];
+
+ const handleGenerate = async () => {
+ const commitMint = createKmipEnrollmentMintCommit(
+ queryClient,
+ enrollmentQueryKey,
+ lifecycleRevisionRef.current
+ );
+
+ try {
+ const result = await mint({ kmipServerId });
+ commitMint(result, lifecycleRevisionRef.current);
+ } catch {
+ // MutationCache.onError already surfaces the API error.
}
};
return (
- <>
- <Card className="w-full">
+ <Tabs value={activeTab} onValueChange={setDeploymentMethod} className="min-w-0">
+ <Card className="min-w-0" aria-labelledby="kmip-server-deployment-title">
<CardHeader>
- <CardTitle>Deployment</CardTitle>
- <CardDescription>Launch this KMIP server on a target host</CardDescription>
- <CardAction>
- <OrgPermissionCan
- I={OrgKmipServerPermissionActions.EditKmipServers}
- a={OrgPermissionSubjects.KmipServer}
- >
- {(isAllowed) => {
- return (
+ <CardTitle>
+ <h2 id="kmip-server-deployment-title">Deployment</h2>
+ <DocumentationLinkBadge href="https://infisical.com/docs/cli/overview" />
+ </CardTitle>
+ <CardDescription>Run this KMIP server on a target host.</CardDescription>
+ {canEditKmipServer && showDeploymentControls && (
+ <CardAction>
+ <TabsList variant="filled" aria-label="Deployment method">
+ <TabsTrigger value="cli">CLI</TabsTrigger>
+ <TabsTrigger value="systemd">System Service</TabsTrigger>
+ </TabsList>
+ </CardAction>
+ )}
+ </CardHeader>
+ <CardContent className="space-y-4">
+ {!canEditKmipServer ? (
+ <Alert variant="warning" appearance="borderless">
+ <LockKeyholeIcon />
+ <AlertTitle>Access restricted</AlertTitle>
+ <AlertDescription>
+ You don&apos;t have permission to generate KMIP server deployment commands.
+ </AlertDescription>
+ </Alert>
+ ) : (
+ <>
+ {authMethod.method === "aws" && (
+ <AwsStartCommandContent
+ kmipServerId={kmipServerId}
+ kmipServerName={kmipServerName}
+ />
+ )}
+
+ {authMethod.method === "token" && !enrollment && (
+ <Button
+ variant="neutral"
+ size="sm"
+ isPending={isMinting}
+ isDisabled={isMinting}
+ onClick={handleGenerate}
+ >
+ <RocketIcon />
+ Generate Deploy Command
+ </Button>
+ )}
+
+ {authMethod.method === "token" && enrollment && (
+ <>
+ <EnrollmentTokenContent
+ kmipServerName={kmipServerName}
+ enrollmentToken={enrollment.token}
+ expiresAt={enrollment.expiresAt}
+ />
<Button
variant="neutral"
size="sm"
isPending={isMinting}
- isDisabled={!isAllowed || isMinting}
- onClick={handleClick}
+ isDisabled={isMinting}
+ onClick={handleGenerate}
>
- <RocketIcon className="size-4" />
- Show deploy command
+ <RefreshCwIcon />
+ Regenerate Command
</Button>
- );
- }}
- </OrgPermissionCan>
- </CardAction>
- </CardHeader>
+ </>
+ )}
+ </>
+ )}
+ </CardContent>
</Card>
-
- {showDialog && (
- <KmipServerDeployCommandDialog
- isOpen
- onOpenChange={(open) => {
- if (!open) {
- setShowDialog(false);
- setEnrollmentToken(null);
- }
- }}
- kmipServerId={kmipServerId}
- kmipServerName={kmipServerName}
- authMethod={authMethod.method as "token" | "aws"}
- enrollmentToken={enrollmentToken}
- />
- )}
- </>
+ </Tabs>
);
};
+
+type Props = {
+ kmipServerId: string;
+ kmipServerName: string;
+ authMethod: TKmipServerAuthMethodView;
+};
+
+type MintedEnrollment = { token: string; expiresAt: string };
diff --git a/frontend/src/pages/organization/KmipServersPage/KmipServerDetailsByIDPage/components/KmipServerDeploySection/commands.ts b/frontend/src/pages/organization/KmipServersPage/KmipServerDetailsByIDPage/components/KmipServerDeploySection/commands.ts
new file mode 100644
index 0000000000..77e5aba71c
--- /dev/null
+++ b/frontend/src/pages/organization/KmipServersPage/KmipServerDetailsByIDPage/components/KmipServerDeploySection/commands.ts
@@ -0,0 +1,7 @@
+export const KMIP_START_SERVICE_COMMAND = "sudo systemctl start infisical-kmip";
+
+export const getKmipServerSiteUrl = () => {
+ const { protocol, hostname, port } = window.location;
+ const portSuffix = port && port !== "80" ? `:${port}` : "";
+ return `${protocol}//${hostname}${portSuffix}`;
+};
diff --git a/frontend/src/pages/organization/KmipServersPage/KmipServerDetailsByIDPage/components/KmipServerDeploySection/enrollmentMintGuard.test.ts b/frontend/src/pages/organization/KmipServersPage/KmipServerDetailsByIDPage/components/KmipServerDeploySection/enrollmentMintGuard.test.ts
new file mode 100644
index 0000000000..43fb64b71b
--- /dev/null
+++ b/frontend/src/pages/organization/KmipServersPage/KmipServerDetailsByIDPage/components/KmipServerDeploySection/enrollmentMintGuard.test.ts
@@ -0,0 +1,76 @@
+import { QueryClient } from "@tanstack/react-query";
+import assert from "node:assert/strict";
+import { describe, it } from "node:test";
+
+import { createKmipEnrollmentMintCommit } from "./enrollmentMintGuard";
+
+const queryKey = [{ kmipServerId: "server-id" }, "kmip-server-enrollment"] as const;
+const firstEnrollment = { token: "first-token", expiresAt: "2026-09-10T12:00:00.000Z" };
+const secondEnrollment = { token: "second-token", expiresAt: "2026-09-10T13:00:00.000Z" };
+
+describe("KMIP enrollment mint lifecycle guard", () => {
+ it("commits an initial enrollment when its lifecycle and cache remain current", () => {
+ const queryClient = new QueryClient();
+ const commitMint = createKmipEnrollmentMintCommit(queryClient, queryKey, 1);
+
+ assert.equal(commitMint(firstEnrollment, 1), true);
+ assert.deepEqual(queryClient.getQueryData(queryKey), firstEnrollment);
+ });
+
+ it("preserves valid regeneration when the existing enrollment remains current", () => {
+ const queryClient = new QueryClient();
+ queryClient.setQueryData(queryKey, firstEnrollment);
+ const commitMint = createKmipEnrollmentMintCommit(queryClient, queryKey, 1);
+
+ assert.equal(commitMint(secondEnrollment, 1), true);
+ assert.deepEqual(queryClient.getQueryData(queryKey), secondEnrollment);
+ });
+
+ it("rejects a delayed enrollment after the cache is cleared from null to null", () => {
+ const queryClient = new QueryClient();
+ queryClient.setQueryData(queryKey, null);
+ const commitMint = createKmipEnrollmentMintCommit(queryClient, queryKey, 1);
+
+ queryClient.setQueryData(queryKey, null);
+
+ assert.equal(commitMint(firstEnrollment, 1), false);
+ assert.equal(queryClient.getQueryData(queryKey), null);
+ });
+
+ it("rejects a delayed enrollment after an existing enrollment is cleared", () => {
+ const queryClient = new QueryClient();
+ queryClient.setQueryData(queryKey, firstEnrollment);
+ const commitMint = createKmipEnrollmentMintCommit(queryClient, queryKey, 1);
+
+ queryClient.setQueryData(queryKey, null);
+
+ assert.equal(commitMint(secondEnrollment, 1), false);
+ assert.equal(queryClient.getQueryData(queryKey), null);
+ });
+
+ it("rejects a delayed initial enrollment after the empty cache is cleared", () => {
+ const queryClient = new QueryClient();
+ const commitMint = createKmipEnrollmentMintCommit(queryClient, queryKey, 1);
+
+ queryClient.setQueryData(queryKey, null);
+
+ assert.equal(commitMint(firstEnrollment, 1), false);
+ assert.equal(queryClient.getQueryData(queryKey), null);
+ });
+
+ it("rejects a delayed enrollment after the auth method changes away and back", () => {
+ const queryClient = new QueryClient();
+ const commitMint = createKmipEnrollmentMintCommit(queryClient, queryKey, 1);
+
+ assert.equal(commitMint(firstEnrollment, 3), false);
+ assert.equal(queryClient.getQueryData(queryKey), undefined);
+ });
+
+ it("rejects a delayed enrollment after navigation or unmount advances the lifecycle", () => {
+ const queryClient = new QueryClient();
+ const commitMint = createKmipEnrollmentMintCommit(queryClient, queryKey, 1);
+
+ assert.equal(commitMint(firstEnrollment, 2), false);
+ assert.equal(queryClient.getQueryData(queryKey), undefined);
+ });
+});
diff --git a/frontend/src/pages/organization/KmipServersPage/KmipServerDetailsByIDPage/components/KmipServerDeploySection/enrollmentMintGuard.ts b/frontend/src/pages/organization/KmipServersPage/KmipServerDetailsByIDPage/components/KmipServerDeploySection/enrollmentMintGuard.ts
new file mode 100644
index 0000000000..8ef279dd88
--- /dev/null
+++ b/frontend/src/pages/organization/KmipServersPage/KmipServerDetailsByIDPage/components/KmipServerDeploySection/enrollmentMintGuard.ts
@@ -0,0 +1,25 @@
+import { QueryClient, QueryKey } from "@tanstack/react-query";
+
+type MintedEnrollment = { token: string; expiresAt: string };
+
+export const createKmipEnrollmentMintCommit = (
+ queryClient: QueryClient,
+ queryKey: QueryKey,
+ lifecycleRevision: number
+) => {
+ const cacheUpdateCount = queryClient.getQueryState(queryKey)?.dataUpdateCount ?? 0;
+
+ return (result: MintedEnrollment, currentLifecycleRevision: number) => {
+ const currentCacheUpdateCount = queryClient.getQueryState(queryKey)?.dataUpdateCount ?? 0;
+
+ if (
+ currentLifecycleRevision !== lifecycleRevision ||
+ currentCacheUpdateCount !== cacheUpdateCount
+ ) {
+ return false;
+ }
+
+ queryClient.setQueryData<MintedEnrollment>(queryKey, result);
+ return true;
+ };
+};
diff --git a/frontend/src/pages/organization/KmipServersPage/KmipServerDetailsByIDPage/components/KmipServerDetailsCard/KmipServerDetailsCard.tsx b/frontend/src/pages/organization/KmipServersPage/KmipServerDetailsByIDPage/components/KmipServerDetailsCard/KmipServerDetailsCard.tsx
index e953a3deef..37e8eeca11 100644
--- a/frontend/src/pages/organization/KmipServersPage/KmipServerDetailsByIDPage/components/KmipServerDetailsCard/KmipServerDetailsCard.tsx
+++ b/frontend/src/pages/organization/KmipServersPage/KmipServerDetailsByIDPage/components/KmipServerDetailsCard/KmipServerDetailsCard.tsx
@@ -19,7 +19,10 @@ import {
DetailLabel,
DetailValue,
IconButton,
- Separator
+ Separator,
+ Tooltip,
+ TooltipContent,
+ TooltipTrigger
} from "@app/components/v3";
import { useOrganization } from "@app/context";
import {
@@ -43,11 +46,7 @@ const AuthMethodBadge = ({ method }: { method: TKmipServerAuthMethodView["method
return <Badge variant="warning">Machine Identity</Badge>;
};
-export const KmipServerDetailsCard = ({
- kmipServer
-}: {
- kmipServer: TKmipServerWithAuthMethod;
-}) => {
+export const KmipServerDetailsCard = ({ kmipServer }: Props) => {
const [, isCopyingId, setCopyTextId] = useTimedReset<string>({
initialState: "Copy ID to clipboard"
});
@@ -72,17 +71,22 @@ export const KmipServerDetailsCard = ({
<DetailLabel>ID</DetailLabel>
<DetailValue className="flex items-center gap-x-1">
<span className="font-mono text-xs">{kmipServer.id}</span>
- <IconButton
- aria-label="copy kmip server id"
- onClick={() => {
- navigator.clipboard.writeText(kmipServer.id);
- setCopyTextId("Copied");
- }}
- variant="ghost"
- size="xs"
- >
- {isCopyingId ? <CheckIcon /> : <ClipboardListIcon className="text-label" />}
- </IconButton>
+ <Tooltip>
+ <TooltipTrigger asChild>
+ <IconButton
+ aria-label="copy kmip server id"
+ onClick={() => {
+ navigator.clipboard.writeText(kmipServer.id);
+ setCopyTextId("Copied");
+ }}
+ variant="ghost"
+ size="xs"
+ >
+ {isCopyingId ? <CheckIcon /> : <ClipboardListIcon className="text-label" />}
+ </IconButton>
+ </TooltipTrigger>
+ <TooltipContent>Copy KMIP server ID to clipboard</TooltipContent>
+ </Tooltip>
</DetailValue>
</Detail>
<Detail>
@@ -240,3 +244,7 @@ export const KmipServerDetailsCard = ({
</>
);
};
+
+type Props = {
+ kmipServer: TKmipServerWithAuthMethod;
+};
diff --git a/frontend/src/pages/organization/KmipServersPage/KmipServerDetailsByIDPage/components/KmipServerPageHeader/KmipServerPageHeader.tsx b/frontend/src/pages/organization/KmipServersPage/KmipServerDetailsByIDPage/components/KmipServerPageHeader/KmipServerPageHeader.tsx
index a3c9750816..4e57ab5941 100644
--- a/frontend/src/pages/organization/KmipServersPage/KmipServerDetailsByIDPage/components/KmipServerPageHeader/KmipServerPageHeader.tsx
+++ b/frontend/src/pages/organization/KmipServersPage/KmipServerDetailsByIDPage/components/KmipServerPageHeader/KmipServerPageHeader.tsx
@@ -3,14 +3,26 @@ import { BanIcon, CopyIcon, EllipsisIcon, TrashIcon } from "lucide-react";
import { createNotification } from "@app/components/notifications";
import { OrgPermissionCan } from "@app/components/permissions";
-import { DeleteActionModal, PageHeader } from "@app/components/v2";
import {
+ Alert,
+ AlertDescription,
+ AlertDialog,
+ AlertDialogAction,
+ AlertDialogCancel,
+ AlertDialogContent,
+ AlertDialogDescription,
+ AlertDialogFooter,
+ AlertDialogHeader,
+ AlertDialogTitle,
Button,
+ DeleteConfirmDialog,
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
- DropdownMenuTrigger
+ DropdownMenuTrigger,
+ PageHeader
} from "@app/components/v3";
+import { useOrganization } from "@app/context";
import {
OrgKmipServerPermissionActions,
OrgPermissionSubjects
@@ -19,16 +31,11 @@ import { usePopUp } from "@app/hooks";
import { useDeleteKmipServerById, useRevokeKmipServerAccess } from "@app/hooks/api/kmipServers";
import { TKmipServerWithAuthMethod } from "@app/hooks/api/kmipServers/types";
-export const KmipServerPageHeader = ({
- kmipServer,
- orgId
-}: {
- kmipServer: TKmipServerWithAuthMethod;
- orgId: string;
-}) => {
+export const KmipServerPageHeader = ({ kmipServer, orgId }: Props) => {
const navigate = useNavigate();
- const { mutateAsync: deleteKmipServer } = useDeleteKmipServerById();
- const { mutateAsync: revokeKmipServer } = useRevokeKmipServerAccess();
+ const { isSubOrganization } = useOrganization();
+ const { mutateAsync: deleteKmipServer, isPending: isDeleting } = useDeleteKmipServerById();
+ const { mutateAsync: revokeKmipServer, isPending: isRevoking } = useRevokeKmipServerAccess();
const { popUp, handlePopUpOpen, handlePopUpToggle } = usePopUp([
"deleteKmipServer",
"revokeKmipServer"
@@ -49,7 +56,7 @@ export const KmipServerPageHeader = ({
createNotification({ type: "success", text: "KMIP server access revoked" });
handlePopUpToggle("revokeKmipServer", false);
} catch {
- createNotification({ type: "error", text: "Failed to revoke KMIP server access" });
+ // MutationCache.onError already surfaces the API error.
}
};
@@ -58,7 +65,7 @@ export const KmipServerPageHeader = ({
return (
<>
<PageHeader
- scope="org"
+ scope={isSubOrganization ? "namespace" : "org"}
title={kmipServer.name}
description="KMIP server configuration and authentication"
>
@@ -115,22 +122,56 @@ export const KmipServerPageHeader = ({
</DropdownMenu>
</PageHeader>
- <DeleteActionModal
+ <DeleteConfirmDialog
isOpen={popUp.deleteKmipServer.isOpen}
- title={`Delete KMIP server "${kmipServer.name}"?`}
- onChange={(isOpen) => handlePopUpToggle("deleteKmipServer", isOpen)}
- deleteKey="confirm"
- onDeleteApproved={onDelete}
- />
- <DeleteActionModal
- isOpen={popUp.revokeKmipServer.isOpen}
- title={`Revoke access for KMIP server "${kmipServer.name}"?`}
- subTitle="The KMIP server will be disconnected and any active tokens will be invalidated. The server will need to re-authenticate to reconnect."
- onChange={(isOpen) => handlePopUpToggle("revokeKmipServer", isOpen)}
- deleteKey="confirm"
- buttonText="Revoke access"
- onDeleteApproved={onRevoke}
+ onOpenChange={(isOpen) => handlePopUpToggle("deleteKmipServer", isOpen)}
+ title={`Delete KMIP Server ${kmipServer.name}?`}
+ description={
+ <Alert variant="danger" appearance="borderless">
+ <AlertDescription>
+ This permanently removes the KMIP server {kmipServer.name} from your organization.
+ Deployed instances lose access and KMIP clients can no longer reach it. This cannot be
+ undone.
+ </AlertDescription>
+ </Alert>
+ }
+ confirmKey={kmipServer.name}
+ confirmLabel="Delete KMIP Server"
+ isPending={isDeleting}
+ onConfirm={onDelete}
/>
+ <AlertDialog
+ open={popUp.revokeKmipServer.isOpen}
+ onOpenChange={(open) => handlePopUpToggle("revokeKmipServer", open)}
+ >
+ <AlertDialogContent>
+ <AlertDialogHeader>
+ <AlertDialogTitle>Revoke Access for KMIP Server {kmipServer.name}?</AlertDialogTitle>
+ <AlertDialogDescription>
+ The KMIP server is disconnected and its active tokens are invalidated. It must
+ re-authenticate to reconnect.
+ </AlertDialogDescription>
+ </AlertDialogHeader>
+ <AlertDialogFooter>
+ <AlertDialogCancel isDisabled={isRevoking}>Cancel</AlertDialogCancel>
+ <AlertDialogAction
+ variant="danger"
+ isPending={isRevoking}
+ onClick={(event) => {
+ event.preventDefault();
+ onRevoke();
+ }}
+ >
+ Revoke Access
+ </AlertDialogAction>
+ </AlertDialogFooter>
+ </AlertDialogContent>
+ </AlertDialog>
</>
);
};
+
+type Props = {
+ kmipServer: TKmipServerWithAuthMethod;
+ orgId: string;
+};