Skip to content

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

improvement(pam): request access as a detail sheet with approval workflow

bernie-g628c7c38aaa0
diff --git a/backend/src/ee/routes/v1/pam-routers/pam-access-request-router.ts b/backend/src/ee/routes/v1/pam-routers/pam-access-request-router.ts
index 25d607bd8e..d356e5e124 100644
--- a/backend/src/ee/routes/v1/pam-routers/pam-access-request-router.ts
+++ b/backend/src/ee/routes/v1/pam-routers/pam-access-request-router.ts
@@ -169,10 +169,16 @@ export const registerPamAccessRequestRouter = async (server: FastifyZodProvider)
}),
response: {
200: z.object({
- approvers: z.array(
+ steps: z.array(
z.object({
- type: z.nativeEnum(ApproverType),
- name: z.string()
+ requiredApprovals: z.number(),
+ approvers: z.array(
+ z.object({
+ type: z.nativeEnum(ApproverType),
+ name: z.string(),
+ memberCount: z.number().optional()
+ })
+ )
})
)
})
diff --git a/backend/src/ee/services/pam-access-request/pam-access-request-service.ts b/backend/src/ee/services/pam-access-request/pam-access-request-service.ts
index 671eac4fb5..256fb0dc9c 100644
--- a/backend/src/ee/services/pam-access-request/pam-access-request-service.ts
+++ b/backend/src/ee/services/pam-access-request/pam-access-request-service.ts
@@ -1224,28 +1224,46 @@ export const pamAccessRequestServiceFactory = ({
ctx
);
- if (!account.folderId) return { approvers: [] };
+ if (!account.folderId) return { steps: [] };
const policy = await findFolderPolicy(account.folderId);
- if (!policy) return { approvers: [] };
+ if (!policy) return { steps: [] };
- const steps = await approvalPolicyDAL.findStepsByPolicyId(policy.id);
- const approverEntries = steps.flatMap((s) => s.approvers);
+ const policySteps = await approvalPolicyDAL.findStepsByPolicyId(policy.id);
+ const approverEntries = policySteps.flatMap((s) => s.approvers);
const userIds = approverEntries.filter((a) => a.type === ApproverType.User).map((a) => a.id);
const groupIds = approverEntries.filter((a) => a.type === ApproverType.Group).map((a) => a.id);
- const [users, groups] = await Promise.all([
+ const [users, groups, groupMemberships] = await Promise.all([
userIds.length > 0 ? userDAL.find({ $in: { id: userIds } }) : [],
- groupIds.length > 0 ? groupDAL.find({ $in: { id: groupIds } }) : []
+ groupIds.length > 0 ? groupDAL.find({ $in: { id: groupIds } }) : [],
+ groupIds.length > 0 ? userGroupMembershipDAL.find({ $in: { groupId: groupIds } }) : []
]);
+ const userNameById = new Map(
+ users.map((u) => [
+ u.id,
+ [u.firstName, u.lastName].filter(Boolean).join(" ") || u.username || u.email || "Unknown user"
+ ])
+ );
+ const groupNameById = new Map(groups.map((g) => [g.id, g.name]));
+ const groupMemberCounts = new Map<string, number>();
+ groupMemberships.forEach((m) => {
+ if (m.groupId) groupMemberCounts.set(m.groupId, (groupMemberCounts.get(m.groupId) ?? 0) + 1);
+ });
+
return {
- approvers: [
- ...users.map((u) => ({
- type: ApproverType.User,
- name: [u.firstName, u.lastName].filter(Boolean).join(" ") || u.username || u.email || "Unknown user"
- })),
- ...groups.map((g) => ({ type: ApproverType.Group, name: g.name }))
- ]
+ steps: policySteps.map((step) => ({
+ requiredApprovals: step.requiredApprovals,
+ approvers: step.approvers.map((a) =>
+ a.type === ApproverType.User
+ ? { type: ApproverType.User, name: userNameById.get(a.id) ?? "Unknown user" }
+ : {
+ type: ApproverType.Group,
+ name: groupNameById.get(a.id) ?? "Unknown group",
+ memberCount: groupMemberCounts.get(a.id) ?? 0
+ }
+ )
+ }))
};
};
diff --git a/frontend/src/hooks/api/pam/queries.tsx b/frontend/src/hooks/api/pam/queries.tsx
index 57524183ad..882014e541 100644
--- a/frontend/src/hooks/api/pam/queries.tsx
+++ b/frontend/src/hooks/api/pam/queries.tsx
@@ -453,15 +453,20 @@ export const useGetPamAccessCapabilities = () => {
// Access Requests / Approvals
+export type TPamApprovalWorkflowStep = {
+ requiredApprovals: number;
+ approvers: { type: PamApproverType; name: string; memberCount?: number }[];
+};
+
export const useGetPamAccountApprovers = (accountId?: string) => {
return useQuery({
queryKey: pamKeys.accountApprovers(accountId ?? ""),
enabled: Boolean(accountId),
queryFn: async () => {
- const { data } = await apiRequest.get<{
- approvers: { type: PamApproverType; name: string }[];
- }>(`/api/v1/pam/access-requests/accounts/${accountId}/approvers`);
- return data.approvers;
+ const { data } = await apiRequest.get<{ steps: TPamApprovalWorkflowStep[] }>(
+ `/api/v1/pam/access-requests/accounts/${accountId}/approvers`
+ );
+ return data.steps;
}
});
};
diff --git a/frontend/src/pages/pam/PamAccessPage/PamAccessPage.tsx b/frontend/src/pages/pam/PamAccessPage/PamAccessPage.tsx
index 44d5845c24..26ccc1da3a 100644
--- a/frontend/src/pages/pam/PamAccessPage/PamAccessPage.tsx
+++ b/frontend/src/pages/pam/PamAccessPage/PamAccessPage.tsx
@@ -35,7 +35,7 @@ import { ProjectType } from "@app/hooks/api/projects/types";
import { FolderAccountGroup } from "./components/FolderAccountGroup";
import { LaunchSessionSheet } from "./components/LaunchSessionSheet";
-import { RequestAccessModal } from "./components/RequestAccessModal";
+import { RequestAccessSheet } from "./components/RequestAccessSheet";
export const PamAccessPage = () => {
const { t } = useTranslation();
@@ -217,7 +217,7 @@ export const PamAccessPage = () => {
}}
/>
- <RequestAccessModal
+ <RequestAccessSheet
account={requestAccount}
isOpen={!!requestAccount}
onOpenChange={(open) => {
diff --git a/frontend/src/pages/pam/PamAccessPage/components/RequestAccessModal.tsx b/frontend/src/pages/pam/PamAccessPage/components/RequestAccessModal.tsx
deleted file mode 100644
index db3066ccd3..0000000000
--- a/frontend/src/pages/pam/PamAccessPage/components/RequestAccessModal.tsx
+++ /dev/null
@@ -1,224 +0,0 @@
-import { Controller, useForm } from "react-hook-form";
-import { zodResolver } from "@hookform/resolvers/zod";
-import { Clock, Send } from "lucide-react";
-import { z } from "zod";
-
-import { createNotification } from "@app/components/notifications";
-import {
- Badge,
- Button,
- Dialog,
- DialogClose,
- DialogContent,
- DialogFooter,
- DialogHeader,
- DialogTitle,
- Field,
- FieldContent,
- FieldDescription,
- FieldError,
- FieldLabel,
- Select,
- SelectContent,
- SelectItem,
- SelectTrigger,
- SelectValue,
- TextArea
-} from "@app/components/v3";
-import {
- PamAccessStatus,
- PamAccountType,
- TAccessiblePamAccount,
- useCreatePamAccessRequest,
- useGetPamAccountApprovers,
- usePamAccountTypeMap
-} from "@app/hooks/api/pam";
-
-import { AccountPlatformIcon } from "./AccountPlatformIcon";
-
-// Mirrors the membership expiry picker options, capped at the default 7d policy maximum and
-// without "No expiry" since every approved access must be time-boxed.
-const DURATION_OPTIONS = [
- { value: "15m", label: "15 minutes" },
- { value: "1h", label: "1 hour" },
- { value: "4h", label: "4 hours" },
- { value: "1d", label: "1 day" },
- { value: "3d", label: "3 days" },
- { value: "7d", label: "1 week" }
-];
-
-const schema = z.object({
- duration: z.string().min(1, "Required"),
- reason: z.string().min(1, "Required").max(500)
-});
-
-type FormData = z.infer<typeof schema>;
-
-type Props = {
- account: TAccessiblePamAccount | null;
- isOpen: boolean;
- onOpenChange: (open: boolean) => void;
-};
-
-const AccountSummary = ({ account }: { account: TAccessiblePamAccount }) => {
- const { map } = usePamAccountTypeMap();
- const typeName = map[account.accountType as PamAccountType]?.name ?? account.accountType;
-
- return (
- <div className="flex items-start gap-3 rounded-md border border-border bg-container px-4 py-3">
- <div className="flex size-10 shrink-0 items-center justify-center rounded-md border border-border bg-popover">
- <AccountPlatformIcon accountType={account.accountType} size={24} />
- </div>
- <div className="min-w-0">
- <div className="flex items-center gap-2">
- <span className="truncate text-sm font-medium text-foreground">{account.name}</span>
- <Badge variant="neutral">{typeName}</Badge>
- </div>
- {account.folderName && <p className="text-xs text-muted">{account.folderName}</p>}
- {account.description && (
- <p className="mt-1 line-clamp-2 text-xs text-muted">{account.description}</p>
- )}
- </div>
- </div>
- );
-};
-
-const ApproverList = ({ accountId, prefix }: { accountId?: string; prefix: string }) => {
- const { data: approvers } = useGetPamAccountApprovers(accountId);
- if (!approvers?.length) return null;
-
- return (
- <p className="text-xs text-muted">
- {prefix} {approvers.map((a) => a.name).join(", ")}
- </p>
- );
-};
-
-export const RequestAccessModal = ({ account, isOpen, onOpenChange }: Props) => {
- const createRequest = useCreatePamAccessRequest();
- const isPending = account?.accessStatus === PamAccessStatus.Pending;
-
- const { control, handleSubmit, reset } = useForm<FormData>({
- resolver: zodResolver(schema),
- defaultValues: { duration: "1h", reason: "" }
- });
-
- const onSubmit = (data: FormData) => {
- if (!account) return;
- createRequest.mutate(
- {
- accountId: account.id,
- duration: data.duration,
- reason: data.reason
- },
- {
- onSuccess: () => {
- createNotification({ text: "Access request submitted", type: "success" });
- reset();
- onOpenChange(false);
- }
- }
- );
- };
-
- return (
- <Dialog
- open={isOpen}
- onOpenChange={(open) => {
- if (!open) reset();
- onOpenChange(open);
- }}
- >
- <DialogContent className="max-w-md" onOpenAutoFocus={(e) => e.preventDefault()}>
- <DialogHeader>
- <DialogTitle className="flex items-center gap-2">
- <Send className="size-4 text-product-pam" />
- Request Access
- </DialogTitle>
- </DialogHeader>
- {account && <AccountSummary account={account} />}
- {isPending ? (
- <>
- <div className="flex items-center gap-2.5 rounded-md border border-border bg-container px-4 py-3">
- <Clock className="size-4 shrink-0 text-warning" />
- <div>
- <p className="text-sm text-foreground">Your access request is awaiting approval.</p>
- <ApproverList
- accountId={account?.id}
- prefix="You can follow up with an approver:"
- />
- </div>
- </div>
- <DialogFooter>
- <DialogClose asChild>
- <Button type="button" variant="ghost">
- Close
- </Button>
- </DialogClose>
- </DialogFooter>
- </>
- ) : (
- <form onSubmit={handleSubmit(onSubmit)} className="flex flex-col gap-4">
- <Controller
- control={control}
- name="reason"
- render={({ field, fieldState }) => (
- <Field>
- <FieldLabel>
- Reason <span className="text-danger">*</span>
- </FieldLabel>
- <FieldContent>
- <TextArea
- {...field}
- rows={3}
- placeholder="What are you working on?"
- isError={!!fieldState.error}
- />
- <FieldDescription>
- Will be visible to approvers and recorded in audit logs.
- </FieldDescription>
- <FieldError>{fieldState.error?.message}</FieldError>
- </FieldContent>
- </Field>
- )}
- />
- <Controller
- control={control}
- name="duration"
- render={({ field }) => (
- <Field>
- <FieldLabel>Requested duration</FieldLabel>
- <FieldContent>
- <Select value={field.value} onValueChange={field.onChange}>
- <SelectTrigger className="w-full">
- <SelectValue />
- </SelectTrigger>
- <SelectContent position="popper">
- {DURATION_OPTIONS.map((opt) => (
- <SelectItem key={opt.value} value={opt.value}>
- {opt.label}
- </SelectItem>
- ))}
- </SelectContent>
- </Select>
- </FieldContent>
- </Field>
- )}
- />
- <ApproverList accountId={account?.id} prefix="Will be reviewed by:" />
- <DialogFooter>
- <DialogClose asChild>
- <Button type="button" variant="ghost">
- Cancel
- </Button>
- </DialogClose>
- <Button type="submit" variant="pam" isPending={createRequest.isPending}>
- Submit Request
- </Button>
- </DialogFooter>
- </form>
- )}
- </DialogContent>
- </Dialog>
- );
-};
diff --git a/frontend/src/pages/pam/PamAccessPage/components/RequestAccessSheet.tsx b/frontend/src/pages/pam/PamAccessPage/components/RequestAccessSheet.tsx
new file mode 100644
index 0000000000..97dcccb242
--- /dev/null
+++ b/frontend/src/pages/pam/PamAccessPage/components/RequestAccessSheet.tsx
@@ -0,0 +1,259 @@
+import { Controller, useForm } from "react-hook-form";
+import { zodResolver } from "@hookform/resolvers/zod";
+import { Clock, GitBranch, Send, User as UserIcon, Users as UsersIcon } from "lucide-react";
+import { z } from "zod";
+
+import { createNotification } from "@app/components/notifications";
+import {
+ Badge,
+ Button,
+ Field,
+ FieldContent,
+ FieldDescription,
+ FieldError,
+ FieldLabel,
+ Select,
+ SelectContent,
+ SelectItem,
+ SelectTrigger,
+ SelectValue,
+ Tabs,
+ TabsContent,
+ TabsList,
+ TabsTrigger,
+ TextArea
+} from "@app/components/v3";
+import {
+ PamAccessStatus,
+ PamAccountType,
+ PamApproverType,
+ TAccessiblePamAccount,
+ TPamApprovalWorkflowStep,
+ useCreatePamAccessRequest,
+ useGetPamAccountApprovers,
+ usePamAccountTypeMap
+} from "@app/hooks/api/pam";
+
+import { PamDetailSheet } from "../../components/PamDetailSheet";
+
+// Mirrors the membership expiry picker options, capped at the default 7d policy maximum and
+// without "No expiry" since every approved access must be time-boxed.
+const DURATION_OPTIONS = [
+ { value: "15m", label: "15 minutes" },
+ { value: "1h", label: "1 hour" },
+ { value: "4h", label: "4 hours" },
+ { value: "1d", label: "1 day" },
+ { value: "3d", label: "3 days" },
+ { value: "7d", label: "1 week" }
+];
+
+const schema = z.object({
+ duration: z.string().min(1, "Required"),
+ reason: z.string().min(1, "Required").max(500)
+});
+
+type FormData = z.infer<typeof schema>;
+
+type Props = {
+ account: TAccessiblePamAccount | null;
+ isOpen: boolean;
+ onOpenChange: (open: boolean) => void;
+};
+
+const ApproverChip = ({
+ approver
+}: {
+ approver: TPamApprovalWorkflowStep["approvers"][number];
+}) => {
+ const Icon = approver.type === PamApproverType.Group ? UsersIcon : UserIcon;
+ return (
+ <span className="flex items-center gap-1.5 rounded-full border border-border bg-popover px-2.5 py-1 text-xs text-foreground">
+ <Icon className="size-3.5 text-muted" />
+ {approver.name}
+ {approver.type === PamApproverType.Group && approver.memberCount !== undefined && (
+ <span className="text-muted">· {approver.memberCount}</span>
+ )}
+ </span>
+ );
+};
+
+const ApprovalWorkflow = ({ accountId, isPending }: { accountId?: string; isPending: boolean }) => {
+ const { data: steps } = useGetPamAccountApprovers(accountId);
+ if (!steps?.length) return null;
+
+ return (
+ <div>
+ <div className="mb-2 flex items-center gap-2 text-sm font-medium text-foreground">
+ <GitBranch className="size-4 text-muted" />
+ Approval workflow · {steps.length} step{steps.length > 1 ? "s" : ""}
+ </div>
+ <div className="flex flex-col gap-3">
+ {steps.map((step, idx) => (
+ // Steps are ordered and have no natural id; index is the step number
+ // eslint-disable-next-line react/no-array-index-key
+ <div key={idx} className="rounded-md border border-border bg-container p-4">
+ <div className="flex items-center gap-2.5">
+ <span className="text-xs font-semibold tracking-wide text-muted">STEP {idx + 1}</span>
+ {isPending && (
+ <Badge variant="warning">
+ <Clock className="mr-1 size-3" />
+ Awaiting
+ </Badge>
+ )}
+ </div>
+ <p className="mt-1.5 text-xs text-muted">
+ {step.requiredApprovals <= 1
+ ? "any one approves"
+ : `${step.requiredApprovals} approvals required`}
+ </p>
+ <div className="mt-2.5 flex flex-wrap gap-2">
+ {step.approvers.map((approver) => (
+ <ApproverChip key={`${approver.type}-${approver.name}`} approver={approver} />
+ ))}
+ </div>
+ {isPending && (
+ <p className="mt-2.5 text-xs text-muted">Waiting on the approvers above.</p>
+ )}
+ </div>
+ ))}
+ </div>
+ </div>
+ );
+};
+
+export const RequestAccessSheet = ({ account, isOpen, onOpenChange }: Props) => {
+ const { map } = usePamAccountTypeMap();
+ const createRequest = useCreatePamAccessRequest();
+ const isPending = account?.accessStatus === PamAccessStatus.Pending;
+ const typeName = account
+ ? (map[account.accountType as PamAccountType]?.name ?? account.accountType)
+ : undefined;
+
+ const {
+ control,
+ handleSubmit,
+ reset,
+ formState: { isDirty }
+ } = useForm<FormData>({
+ resolver: zodResolver(schema),
+ defaultValues: { duration: "1h", reason: "" }
+ });
+
+ const handleOpenChange = (open: boolean) => {
+ if (!open) reset();
+ onOpenChange(open);
+ };
+
+ const onSubmit = (data: FormData) => {
+ if (!account) return;
+ createRequest.mutate(
+ {
+ accountId: account.id,
+ duration: data.duration,
+ reason: data.reason
+ },
+ {
+ onSuccess: () => {
+ createNotification({ text: "Access request submitted", type: "success" });
+ reset();
+ onOpenChange(false);
+ }
+ }
+ );
+ };
+
+ return (
+ <PamDetailSheet
+ isOpen={isOpen}
+ onOpenChange={handleOpenChange}
+ isLoading={!account}
+ accountType={account?.accountType as PamAccountType}
+ title={account?.name}
+ subtitle={account?.folderName}
+ typeBadge={typeName}
+ metadata={[{ label: "Description", value: account?.description || "—" }]}
+ isDirty={isDirty && !isPending}
+ >
+ <Tabs defaultValue="request" className="flex h-full flex-col">
+ <TabsList variant="pam" className="shrink-0 bg-popover">
+ <TabsTrigger value="request">
+ <Send className="size-4" />
+ Request Access
+ </TabsTrigger>
+ </TabsList>
+ <TabsContent value="request" className="m-0 flex flex-1 flex-col p-6">
+ {isPending ? (
+ <div className="flex flex-1 flex-col gap-6">
+ <div className="flex items-center gap-2.5 rounded-md border border-border bg-container px-4 py-3">
+ <Clock className="size-4 shrink-0 text-warning" />
+ <p className="text-sm text-foreground">Your access request is awaiting approval.</p>
+ </div>
+ <ApprovalWorkflow accountId={account?.id} isPending />
+ </div>
+ ) : (
+ <form onSubmit={handleSubmit(onSubmit)} className="flex flex-1 flex-col">
+ <div className="flex flex-1 flex-col gap-6">
+ <Controller
+ control={control}
+ name="reason"
+ render={({ field, fieldState }) => (
+ <Field>
+ <FieldLabel>
+ Reason <span className="text-danger">*</span>
+ </FieldLabel>
+ <FieldContent>
+ <TextArea
+ {...field}
+ rows={4}
+ placeholder="What are you working on?"
+ isError={!!fieldState.error}
+ />
+ <FieldDescription>
+ Will be visible to approvers and recorded in audit logs.
+ </FieldDescription>
+ <FieldError>{fieldState.error?.message}</FieldError>
+ </FieldContent>
+ </Field>
+ )}
+ />
+ <Controller
+ control={control}
+ name="duration"
+ render={({ field }) => (
+ <Field>
+ <FieldLabel>Requested duration</FieldLabel>
+ <FieldContent>
+ <Select value={field.value} onValueChange={field.onChange}>
+ <SelectTrigger className="w-full">
+ <SelectValue />
+ </SelectTrigger>
+ <SelectContent position="popper">
+ {DURATION_OPTIONS.map((opt) => (
+ <SelectItem key={opt.value} value={opt.value}>
+ {opt.label}
+ </SelectItem>
+ ))}
+ </SelectContent>
+ </Select>
+ </FieldContent>
+ </Field>
+ )}
+ />
+ <ApprovalWorkflow accountId={account?.id} isPending={false} />
+ </div>
+ <div className="flex items-center justify-end gap-2 border-t border-border pt-4">
+ <Button type="button" variant="ghost" onClick={() => handleOpenChange(false)}>
+ Cancel
+ </Button>
+ <Button type="submit" variant="pam" isPending={createRequest.isPending}>
+ <Send className="mr-1.5 size-4" />
+ Submit request
+ </Button>
+ </div>
+ </form>
+ )}
+ </TabsContent>
+ </Tabs>
+ </PamDetailSheet>
+ );
+};