Skip to content

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

misc: move identity to sheets

Sheen Capadnganc0f3765c97d7
diff --git a/frontend/src/helpers/roles.ts b/frontend/src/helpers/roles.ts
index 48427fac75..0a3c201afe 100644
--- a/frontend/src/helpers/roles.ts
+++ b/frontend/src/helpers/roles.ts
@@ -17,6 +17,22 @@ export const findOrgMembershipRole = (roles: TOrgRole[], roleIdOrSlug: string) =
? roles.find((r) => r.id === roleIdOrSlug)
: roles.find((r) => r.slug === roleIdOrSlug);
+// PAM has no externally visible project, so the generic project role copy ("...over a project") does
+// not apply. These describe the product roles in PAM's own terms.
+export const PAM_PRODUCT_ROLE_OPTIONS = [
+ {
+ value: ProjectMembershipRole.Admin,
+ label: "Admin",
+ description:
+ "Manage account templates, folders, and product access control. Access to individual accounts and folders is still granted per-resource."
+ },
+ {
+ value: ProjectMembershipRole.Member,
+ label: "Member",
+ description: "Access limited to the folders and accounts they're granted."
+ }
+];
+
export const formatProjectRoleName = (role: string, customRoleName?: string) => {
switch (role) {
case ProjectMembershipRole.Admin:
diff --git a/frontend/src/pages/pam/PamAccessControlPage/components/AddIdentityModal.tsx b/frontend/src/pages/pam/PamAccessControlPage/components/AddIdentityModal.tsx
deleted file mode 100644
index c01734e47f..0000000000
--- a/frontend/src/pages/pam/PamAccessControlPage/components/AddIdentityModal.tsx
+++ /dev/null
@@ -1,243 +0,0 @@
-import { useMemo, useState } from "react";
-import { useQueryClient } from "@tanstack/react-query";
-import { useNavigate } from "@tanstack/react-router";
-
-import { createNotification } from "@app/components/notifications";
-import {
- Button,
- Dialog,
- DialogContent,
- DialogDescription,
- DialogFooter,
- DialogHeader,
- DialogTitle,
- Field,
- FieldLabel,
- FilterableSelect,
- Input,
- Tabs,
- TabsList,
- TabsTrigger
-} from "@app/components/v3";
-import { useOrganization, useProject } from "@app/context";
-import { useGetIdentityMembershipOrgs } from "@app/hooks/api";
-import { UNIVERSAL_AUTH_DEFAULTS, useAddIdentityUniversalAuth } from "@app/hooks/api/identities";
-import { IdentityMembershipOrg } from "@app/hooks/api/identities/types";
-import {
- pamKeys,
- useAddPamProductIdentityMember,
- useListPamProductIdentities
-} from "@app/hooks/api/pam";
-import { useCreateProjectIdentity } from "@app/hooks/api/projectIdentity";
-import { ProjectMembershipRole } from "@app/hooks/api/roles/types";
-
-import { ProductRoleOptionList } from "./ProductRoleOptionList";
-
-enum AddIdentityMode {
- Create = "create",
- Assign = "assign"
-}
-
-type Props = {
- isOpen: boolean;
- onOpenChange: (open: boolean) => void;
-};
-
-export const AddIdentityModal = ({ isOpen, onOpenChange }: Props) => {
- const { currentOrg } = useOrganization();
- const { currentProject } = useProject();
- const navigate = useNavigate();
- const queryClient = useQueryClient();
-
- const { mutate: addIdentity, isPending: isAssigning } = useAddPamProductIdentityMember();
- const { mutate: createProjectIdentity, isPending: isCreating } = useCreateProjectIdentity();
- const { mutate: addUniversalAuth, isPending: isAttachingAuth } = useAddIdentityUniversalAuth();
-
- const [mode, setMode] = useState<AddIdentityMode>(AddIdentityMode.Create);
- const [name, setName] = useState("");
- const [selectedIdentity, setSelectedIdentity] = useState<IdentityMembershipOrg | null>(null);
- const [selectedRole, setSelectedRole] = useState<string>(ProjectMembershipRole.Member);
-
- const isSubmitting = isAssigning || isCreating || isAttachingAuth;
-
- const { data: orgIdentitiesData } = useGetIdentityMembershipOrgs({
- organizationId: currentOrg.id,
- limit: 1000
- });
- const { data: productIdentities } = useListPamProductIdentities();
-
- const availableIdentities = useMemo(() => {
- const assignedIds = new Set((productIdentities ?? []).map((m) => m.identityId).filter(Boolean));
- return (orgIdentitiesData?.identityMemberships || []).filter(
- (m) => !assignedIds.has(m.identity.id)
- );
- }, [orgIdentitiesData, productIdentities]);
-
- const handleClose = () => {
- setMode(AddIdentityMode.Create);
- setName("");
- setSelectedIdentity(null);
- setSelectedRole(ProjectMembershipRole.Member);
- onOpenChange(false);
- };
-
- // Once creation succeeds the identity and its PAM membership already exist, so land on the
- // identity page whether or not auth attached, rather than leaving the user to re-create.
- const finishCreate = (identityId: string, authAttached: boolean) => {
- // The generic create mutation doesn't know about PAM's member list
- queryClient.invalidateQueries({ queryKey: pamKeys.productIdentities() });
-
- createNotification(
- authAttached
- ? { text: "Machine identity created", type: "success" }
- : {
- text: "Machine identity created, but attaching Universal Auth failed. Add an auth method from the identity page.",
- type: "error"
- }
- );
- handleClose();
- navigate({
- to: "/organizations/$orgId/pam/identities/$identityId",
- params: { orgId: currentOrg.id, identityId }
- });
- };
-
- const handleCreate = () => {
- createProjectIdentity(
- {
- name: name.trim(),
- projectId: currentProject.id,
- hasDeleteProtection: true,
- roles: [{ role: selectedRole }]
- },
- {
- onSuccess: (created) => {
- addUniversalAuth(
- { projectId: currentProject.id, identityId: created.id, ...UNIVERSAL_AUTH_DEFAULTS },
- {
- onSuccess: () => finishCreate(created.id, true),
- onError: () => finishCreate(created.id, false)
- }
- );
- }
- }
- );
- };
-
- const handleAssign = () => {
- if (!selectedIdentity) return;
-
- addIdentity(
- {
- identityId: selectedIdentity.identity.id,
- role: selectedRole,
- projectId: currentProject.id
- },
- {
- onSuccess: () => {
- createNotification({ text: "Identity added", type: "success" });
- handleClose();
- }
- }
- );
- };
-
- const handleSubmit = () => {
- if (mode === AddIdentityMode.Create) {
- handleCreate();
- } else {
- handleAssign();
- }
- };
-
- const isSubmitDisabled = mode === AddIdentityMode.Create ? !name.trim() : !selectedIdentity;
-
- return (
- <Dialog open={isOpen} onOpenChange={onOpenChange}>
- <DialogContent className="sm:max-w-xl">
- <DialogHeader>
- <DialogTitle>Add Machine Identity</DialogTitle>
- <DialogDescription>
- Create a new machine identity or assign an existing organization identity.
- </DialogDescription>
- </DialogHeader>
-
- <div className="flex flex-col gap-5">
- <div className="flex flex-col gap-2">
- <Tabs
- className="w-full"
- value={mode}
- onValueChange={(next) => {
- setMode(next as AddIdentityMode);
- if (next === AddIdentityMode.Create) {
- setSelectedIdentity(null);
- } else {
- setName("");
- }
- }}
- >
- <TabsList className="w-full">
- <TabsTrigger value={AddIdentityMode.Create}>Create New</TabsTrigger>
- <TabsTrigger value={AddIdentityMode.Assign}>Assign Existing</TabsTrigger>
- </TabsList>
- </Tabs>
- <p className="text-sm text-muted">
- {mode === AddIdentityMode.Create
- ? "Create a dedicated machine identity managed at the PAM level."
- : "Reuse an existing machine identity from your organization."}
- </p>
- </div>
-
- {mode === AddIdentityMode.Create ? (
- <Field>
- <FieldLabel>
- Name <span className="text-product-pam">*</span>
- </FieldLabel>
- <Input
- value={name}
- onChange={(e) => setName(e.target.value)}
- autoFocus
- placeholder="Machine 1"
- />
- </Field>
- ) : (
- <Field>
- <FieldLabel>
- Identity <span className="text-product-pam">*</span>
- </FieldLabel>
- <FilterableSelect
- value={selectedIdentity}
- onChange={(val) => setSelectedIdentity(val as IdentityMembershipOrg | null)}
- getOptionValue={(option) => option.identity.id}
- getOptionLabel={(option) => option.identity.name}
- options={availableIdentities}
- placeholder="Select identity..."
- />
- </Field>
- )}
-
- <Field>
- <FieldLabel>
- Product role <span className="text-product-pam">*</span>
- </FieldLabel>
- <ProductRoleOptionList value={selectedRole} onChange={setSelectedRole} />
- </Field>
- </div>
-
- <DialogFooter>
- <Button variant="outline" onClick={handleClose}>
- Cancel
- </Button>
- <Button
- variant="pam"
- isDisabled={isSubmitDisabled || isSubmitting}
- isPending={isSubmitting}
- onClick={handleSubmit}
- >
- {mode === AddIdentityMode.Create ? "Create Identity" : "Add Identity"}
- </Button>
- </DialogFooter>
- </DialogContent>
- </Dialog>
- );
-};
diff --git a/frontend/src/pages/pam/PamAccessControlPage/components/IdentitiesTab.tsx b/frontend/src/pages/pam/PamAccessControlPage/components/IdentitiesTab.tsx
index b71de75a43..1ec6ac58d9 100644
--- a/frontend/src/pages/pam/PamAccessControlPage/components/IdentitiesTab.tsx
+++ b/frontend/src/pages/pam/PamAccessControlPage/components/IdentitiesTab.tsx
@@ -52,8 +52,8 @@ import {
import { TPamIdentityMember } from "@app/hooks/api/pam/types";
import { useDeleteProjectIdentity } from "@app/hooks/api/projectIdentity";
import { ProjectMembershipRole } from "@app/hooks/api/roles/types";
+import { CreateProjectIdentitySheet } from "@app/pages/project/AccessControlPage/components/IdentityTab/components/CreateProjectIdentity/CreateProjectIdentitySheet";
-import { AddIdentityModal } from "./AddIdentityModal";
import { IdentityRoleModal } from "./IdentityRoleModal";
export const IdentitiesTab = () => {
@@ -291,7 +291,7 @@ export const IdentitiesTab = () => {
)}
</Card>
- <AddIdentityModal isOpen={isAddIdentityOpen} onOpenChange={setIsAddIdentityOpen} />
+ <CreateProjectIdentitySheet isOpen={isAddIdentityOpen} onOpenChange={setIsAddIdentityOpen} />
<IdentityRoleModal
identity={selectedIdentity}
diff --git a/frontend/src/pages/pam/PamAccessControlPage/components/ProductRoleOptionList.tsx b/frontend/src/pages/pam/PamAccessControlPage/components/ProductRoleOptionList.tsx
index 98a47650e9..f8dcceb458 100644
--- a/frontend/src/pages/pam/PamAccessControlPage/components/ProductRoleOptionList.tsx
+++ b/frontend/src/pages/pam/PamAccessControlPage/components/ProductRoleOptionList.tsx
@@ -1,4 +1,4 @@
-import { PAM_PRODUCT_ROLE_OPTIONS } from "./roleOptions";
+import { PAM_PRODUCT_ROLE_OPTIONS } from "@app/helpers/roles";
type Props = {
value: string;
diff --git a/frontend/src/pages/pam/PamAccessControlPage/components/roleOptions.ts b/frontend/src/pages/pam/PamAccessControlPage/components/roleOptions.ts
deleted file mode 100644
index bae1de27d6..0000000000
--- a/frontend/src/pages/pam/PamAccessControlPage/components/roleOptions.ts
+++ /dev/null
@@ -1,15 +0,0 @@
-import { ProjectMembershipRole } from "@app/hooks/api/roles/types";
-
-export const PAM_PRODUCT_ROLE_OPTIONS = [
- {
- value: ProjectMembershipRole.Admin,
- label: "Admin",
- description:
- "Manage account templates, folders, and product access control. Access to individual accounts and folders is still granted per-resource."
- },
- {
- value: ProjectMembershipRole.Member,
- label: "Member",
- description: "Access limited to the folders and accounts they're granted."
- }
-];
diff --git a/frontend/src/pages/project/AccessControlPage/components/IdentityTab/components/CreateProjectIdentity/CreateProjectIdentityForm.tsx b/frontend/src/pages/project/AccessControlPage/components/IdentityTab/components/CreateProjectIdentity/CreateProjectIdentityForm.tsx
index 2137fe5efc..d0ec739e6f 100644
--- a/frontend/src/pages/project/AccessControlPage/components/IdentityTab/components/CreateProjectIdentity/CreateProjectIdentityForm.tsx
+++ b/frontend/src/pages/project/AccessControlPage/components/IdentityTab/components/CreateProjectIdentity/CreateProjectIdentityForm.tsx
@@ -1,7 +1,7 @@
import { useMemo } from "react";
import { Controller, FormProvider, useForm, useWatch } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
-import { useQuery } from "@tanstack/react-query";
+import { useQuery, useQueryClient } from "@tanstack/react-query";
import { useNavigate } from "@tanstack/react-router";
import { AxiosError } from "axios";
@@ -21,6 +21,7 @@ import {
TabsTrigger
} from "@app/components/v3";
import { getProjectBaseURL } from "@app/helpers/project";
+import { PAM_PRODUCT_ROLE_OPTIONS } from "@app/helpers/roles";
import {
projectIdentityMembershipQuery,
useCreateIdentityProjectAdditionalPrivilege,
@@ -31,6 +32,7 @@ import {
useUpdateProjectIdentityMembership
} from "@app/hooks/api";
import { UNIVERSAL_AUTH_DEFAULTS, useAddIdentityUniversalAuth } from "@app/hooks/api/identities";
+import { pamKeys, useAddPamProductIdentityMember } from "@app/hooks/api/pam";
import { ProjectType } from "@app/hooks/api/projects/types";
import { ProjectMembershipRole } from "@app/hooks/api/roles/types";
import {
@@ -72,6 +74,7 @@ const buildTemplatePermissions = (
type Props = {
projectId: string;
projectType: ProjectType;
+ productLabel: string;
canGrantPrivileges: boolean;
onClose: () => void;
};
@@ -79,17 +82,34 @@ type Props = {
export const CreateProjectIdentityForm = ({
projectId,
projectType,
+ productLabel,
canGrantPrivileges,
onClose
}: Props) => {
const navigate = useNavigate();
+ const queryClient = useQueryClient();
const isCertManager = projectType === ProjectType.CertificateManager;
+ const isPam = projectType === ProjectType.PAM;
- const { data: roles } = useGetProjectRoles(projectId, projectType);
+ const { data: projectRoles } = useGetProjectRoles(projectId, projectType);
- const defaultRole = isCertManager
- ? { slug: ProjectMembershipRole.Member, name: "Member" }
- : { slug: ProjectMembershipRole.NoAccess, name: "No Access" };
+ // PAM product membership is only ever Admin or Member, and PAM has no externally visible project, so
+ // the generic role copy ("...over a project") is replaced with the product's own wording.
+ const roles = useMemo(() => {
+ if (!isPam) return projectRoles;
+
+ return (projectRoles ?? []).flatMap((role) => {
+ const productRole = PAM_PRODUCT_ROLE_OPTIONS.find((option) => option.value === role.slug);
+ if (!productRole) return [];
+
+ return [{ ...role, name: productRole.label, description: productRole.description }];
+ });
+ }, [projectRoles, isPam]);
+
+ const defaultRole =
+ isCertManager || isPam
+ ? { slug: ProjectMembershipRole.Member, name: "Member" }
+ : { slug: ProjectMembershipRole.NoAccess, name: "No Access" };
const form = useForm<TCreateProjectIdentityForm>({
resolver: zodResolver(createProjectIdentitySchema),
@@ -132,22 +152,28 @@ export const CreateProjectIdentityForm = ({
const { mutateAsync: createProjectIdentity } = useCreateProjectIdentity();
const { mutateAsync: updateMembership } = useUpdateProjectIdentityMembership();
const { mutateAsync: createMembership } = useCreateProjectIdentityMembership();
+ const { mutateAsync: addPamProductIdentityMember } = useAddPamProductIdentityMember();
const { mutateAsync: addUniversalAuth } = useAddIdentityUniversalAuth();
const { mutateAsync: createAdditionalPrivilege } = useCreateIdentityProjectAdditionalPrivilege();
const onSubmit = async (data: TCreateProjectIdentityForm) => {
+ let authAttachFailed = false;
+
try {
let identityId: string;
if (data.mode === CreateProjectIdentityMode.Create) {
+ // PAM's membership PATCH takes a single product role rather than the generic roles array, so
+ // the role is set at creation time instead of through a follow-up membership update.
const created = await createProjectIdentity({
name: data.name!.trim(),
projectId,
- hasDeleteProtection: true
+ hasDeleteProtection: true,
+ ...(isPam && data.role?.slug ? { roles: [{ role: data.role.slug }] } : {})
});
identityId = created.id;
- if (data.role?.slug) {
+ if (!isPam && data.role?.slug) {
await updateMembership({
roles: [{ role: data.role.slug }],
identityId,
@@ -156,15 +182,37 @@ export const CreateProjectIdentityForm = ({
});
}
- await addUniversalAuth({ projectId, identityId, ...UNIVERSAL_AUTH_DEFAULTS });
+ // The identity and its membership already exist by now, so a failed auth attach must not be
+ // reported as a failed creation — retrying would just create a duplicate identity.
+ try {
+ await addUniversalAuth({ projectId, identityId, ...UNIVERSAL_AUTH_DEFAULTS });
+ } catch {
+ authAttachFailed = true;
+ }
} else {
identityId = data.identity!.id;
- await createMembership({
- projectId,
- projectType,
- identityId,
- role: data.role?.slug || undefined
- });
+
+ // PAM keeps its own add-member endpoint, which enforces the product-admin check, the
+ // admin/member-only roles, and the rejection of identities scoped to another project.
+ if (isPam) {
+ await addPamProductIdentityMember({
+ projectId,
+ identityId,
+ role: data.role.slug
+ });
+ } else {
+ await createMembership({
+ projectId,
+ projectType,
+ identityId,
+ role: data.role?.slug || undefined
+ });
+ }
+ }
+
+ // The PAM tab reads its own product-membership list, which the generic mutations don't know about.
+ if (isPam) {
+ queryClient.invalidateQueries({ queryKey: pamKeys.productIdentities() });
}
const hasTemplateGrants = data.templateIds.length > 0;
@@ -185,7 +233,12 @@ export const CreateProjectIdentityForm = ({
}
}
- if (grantFailed) {
+ if (authAttachFailed) {
+ createNotification({
+ text: "Machine identity created, but attaching Universal Auth failed. Add an auth method from the identity page.",
+ type: "error"
+ });
+ } else if (grantFailed) {
createNotification({
text: `Machine identity ${
data.mode === CreateProjectIdentityMode.Assign ? "added" : "created"
@@ -255,9 +308,7 @@ export const CreateProjectIdentityForm = ({
<p className="text-sm text-muted">
{mode === CreateProjectIdentityMode.Assign
? "Reuse an existing machine identity from your organization."
- : `Create a dedicated machine identity managed at the ${
- isCertManager ? "Certificate Manager" : "project"
- } level.`}
+ : `Create a dedicated machine identity managed at the ${productLabel} level.`}
</p>
</div>
@@ -337,7 +388,7 @@ export const CreateProjectIdentityForm = ({
<SheetFooter className="border-t">
<Button
type="submit"
- variant="project"
+ variant={isPam ? "pam" : "project"}
isPending={isSubmitting}
isDisabled={isSubmitting}
>
diff --git a/frontend/src/pages/project/AccessControlPage/components/IdentityTab/components/CreateProjectIdentity/CreateProjectIdentitySheet.tsx b/frontend/src/pages/project/AccessControlPage/components/IdentityTab/components/CreateProjectIdentity/CreateProjectIdentitySheet.tsx
index 39c2a7d8ec..4892807317 100644
--- a/frontend/src/pages/project/AccessControlPage/components/IdentityTab/components/CreateProjectIdentity/CreateProjectIdentitySheet.tsx
+++ b/frontend/src/pages/project/AccessControlPage/components/IdentityTab/components/CreateProjectIdentity/CreateProjectIdentitySheet.tsx
@@ -9,6 +9,11 @@ import { ProjectType } from "@app/hooks/api/projects/types";
import { CreateProjectIdentityForm } from "./CreateProjectIdentityForm";
+const PRODUCT_LABELS: Partial<Record<ProjectType, string>> = {
+ [ProjectType.CertificateManager]: "Certificate Manager",
+ [ProjectType.PAM]: "PAM"
+};
+
type Props = {
isOpen: boolean;
onOpenChange: (isOpen: boolean) => void;
@@ -18,15 +23,16 @@ export const CreateProjectIdentitySheet = ({ isOpen, onOpenChange }: Props) => {
const { currentProject } = useProject();
const { permission } = useProjectPermission();
+ // Additional privileges are a Secret Manager concept; the other products grant access per-resource.
const canGrantPrivileges =
+ currentProject.type === ProjectType.SecretManager &&
permission.can(ProjectPermissionIdentityActions.Edit, ProjectPermissionSub.Identity) &&
permission.can(
ProjectPermissionIdentityActions.AssignAdditionalPrivileges,
ProjectPermissionSub.Identity
);
- const productLabel =
- currentProject.type === ProjectType.CertificateManager ? "Certificate Manager" : "Project";
+ const productLabel = PRODUCT_LABELS[currentProject.type] ?? "Project";
return (
<Sheet open={isOpen} onOpenChange={onOpenChange}>
@@ -41,6 +47,7 @@ export const CreateProjectIdentitySheet = ({ isOpen, onOpenChange }: Props) => {
<CreateProjectIdentityForm
projectId={currentProject.id}
projectType={currentProject.type}
+ productLabel={productLabel}
canGrantPrivileges={canGrantPrivileges}
onClose={() => onOpenChange(false)}
/>