Skip to content

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

feat(ui): machine identity creation sheet with policy templates (#7386)

Saif Ur Rahmanceb1aed912e2
diff --git a/docs/documentation/platform/agent-proxy/overview.mdx b/docs/documentation/platform/agent-proxy/overview.mdx
index cfeb54ca66..84e040cf87 100644
--- a/docs/documentation/platform/agent-proxy/overview.mdx
+++ b/docs/documentation/platform/agent-proxy/overview.mdx
@@ -40,7 +40,7 @@ Start by configuring the resources Agent Proxy needs within Infisical to broker
2. Configure a [proxied service](/documentation/platform/agent-proxy/proxied-services) in Infisical. This defines the external service (e.g. `api.anthropic.com`, `api.github.com`, `slack.com`, etc.) that Agent Proxy can broker access to using the credential.
-3. Configure a [machine identity](/documentation/platform/identities/machine-identities) for Agent Proxy using [Universal Auth](/documentation/platform/identities/universal-auth) and another one for your agent.
+3. Configure a [machine identity](/documentation/platform/identities/machine-identities) for Agent Proxy and another one for your agent, each with [Universal Auth](/documentation/platform/identities/universal-auth). When creating them, grant their permissions in one step with the built-in **Agent Proxy Policies** and **Agent Policies** templates under Additional Privileges.
Next, set up an instance of Agent Proxy on a separate host machine:
diff --git a/docs/documentation/platform/agent-proxy/quickstart.mdx b/docs/documentation/platform/agent-proxy/quickstart.mdx
index 0fcd1f1b57..4919caf992 100644
--- a/docs/documentation/platform/agent-proxy/quickstart.mdx
+++ b/docs/documentation/platform/agent-proxy/quickstart.mdx
@@ -71,13 +71,27 @@ A proxied service maps a host to the secret the proxy applies. In the same folde
The proxy and the agent authenticate as **two separate machine identities with opposite access**. That split is the whole security model: the proxy can read your secrets, the agent never can.
+<Note>
+ The two templates have similar names but are for different identities: use **Agent Proxy Policies** for the proxy (this step) and **Agent Policies** for the agent (next step). Pick the one that matches the identity you are creating.
+</Note>
+
**The proxy identity reads the secrets.**
<Steps>
<Step title="Create the identity">
- In your project, go to **Access Control → Machine Identities** and click **Add Machine Identity to Project → Create New**. Name it (for example `agent-proxy`) and create it.
+ In your project, go to **Access Control → Machine Identities** and click **Add Machine Identity to Project → Create New**. Name it (for example `agent-proxy`), leave the **Role** as **No Access**, select the **Agent Proxy Policies** template under **Additional Privileges**, and create it.
+
+ ![Creating the agent-proxy identity with the Agent Proxy Policies template selected under Additional Privileges](/images/platform/agent-proxy/quickstart-create-identity.png)
- ![The create machine identity prompt with the name agent-proxy](/images/platform/agent-proxy/quickstart-create-identity.png)
+ <Note>
+ **Agent Proxy Policies** grants the proxy these permissions, project-wide:
+
+ - `Read Value` and `Describe Secret` on **Secrets**: fetch real secret values
+ - `Lease` on **Dynamic Secrets**: mint credentials for brokered [dynamic secrets](/documentation/platform/agent-proxy/proxied-services#using-dynamic-secrets)
+ - `Report Usage` on **Proxied Services**: report service usage back to Infisical
+
+ This template is the identity's entire access, so its project **Role** stays **No Access**. For a production deployment, grant these scoped to your services' environments and paths with a [custom role](/documentation/platform/access-controls/role-based-access-controls) or a conditional [additional privilege](/documentation/platform/access-controls/additional-privileges). See [Permissions](/documentation/platform/agent-proxy/security#permissions).
+ </Note>
</Step>
<Step title="Generate a Client Secret">
Open the identity and go to its [Universal Auth](/documentation/platform/identities/universal-auth) authentication method.
@@ -90,17 +104,6 @@ The proxy and the agent authenticate as **two separate machine identities with o
Save the **Client ID** and the **Client Secret**; you will pass both to the proxy in step 5.
</Step>
- <Step title="Grant it read access to the secrets">
- Grant it `Read Value` and `Describe Secret` on **Secrets** for the secrets your services reference. The quickest way is an [additional privilege](/documentation/platform/access-controls/additional-privileges) directly on the identity: open it and click **Add Additional Privileges**.
-
- ![The Add Additional Privileges button on the machine identity page](/images/platform/agent-proxy/quickstart-add-additional-privileges.png)
-
- Add a **Secrets** policy allowing both `Read Value` and `Describe Secret`. A [custom role](/documentation/platform/access-controls/role-based-access-controls) with the same policy, assigned to the identity, works too.
-
- If you plan to broker [dynamic secrets](/documentation/platform/agent-proxy/proxied-services#using-dynamic-secrets) later, also allow `Manage Leases` on **Dynamic Secrets** while you are here. Only the proxy identity gets it; the agent identity never should.
-
- ![The proxy identity's additional privileges: Read Value and Describe Secret on Secrets, and Manage Leases on Dynamic Secrets](/images/platform/agent-proxy/quickstart-proxy-identity-role.png)
- </Step>
</Steps>
## 4. Create the agent identity
@@ -109,18 +112,21 @@ The proxy and the agent authenticate as **two separate machine identities with o
<Steps>
<Step title="Create the identity">
- In your project, go to **Access Control → Machine Identities** and click **Add Machine Identity to Project → Create New**. Name it (for example `agent`) and create it.
+ In your project, go to **Access Control → Machine Identities** and click **Add Machine Identity to Project → Create New**. Name it (for example `agent`), leave the **Role** as **No Access**, select the **Agent Policies** template under **Additional Privileges**, and create it.
+
+ ![Creating the agent identity with the Agent Policies template selected under Additional Privileges](/images/platform/agent-proxy/quickstart-create-agent-identity.png)
- ![The create machine identity prompt with the name agent](/images/platform/agent-proxy/quickstart-create-agent-identity.png)
+ <Note>
+ **Agent Policies** grants the agent one permission, project-wide:
+
+ - `Proxy` on **Proxied Services**: route traffic and have credentials applied, with no secret read access
+
+ This template is the identity's entire access, so its project **Role** stays **No Access**. For a production deployment, grant it scoped to your services' environments and paths with a [custom role](/documentation/platform/access-controls/role-based-access-controls) or a conditional [additional privilege](/documentation/platform/access-controls/additional-privileges). See [Permissions](/documentation/platform/agent-proxy/security#permissions).
+ </Note>
</Step>
<Step title="Generate a Client Secret">
Open the identity and add a **Client Secret** under Universal Auth, exactly as in the previous step. Save the **Client ID** and the **Client Secret**; you will pass both to the agent in step 6.
</Step>
- <Step title="Grant it the Proxy permission">
- Grant it only `Proxy` on **Proxied Services**, scoped to the environment and path where your services live, the same way you granted the proxy identity's permissions.
-
- ![The agent identity's additional privilege with only the Proxy action on Proxied Services](/images/platform/agent-proxy/quickstart-agent-identity-role.png)
- </Step>
</Steps>
## 5. Start the agent proxy
diff --git a/docs/documentation/platform/agent-proxy/security.mdx b/docs/documentation/platform/agent-proxy/security.mdx
index 61afe3bd18..b9ce512623 100644
--- a/docs/documentation/platform/agent-proxy/security.mdx
+++ b/docs/documentation/platform/agent-proxy/security.mdx
@@ -38,12 +38,12 @@ Proxied services have their own project-level permission subject. Alongside the
### Roles
-Grant each identity the minimum permissions it needs with a [custom role](/documentation/platform/access-controls/role-based-access-controls) or an [additional privilege](/documentation/platform/access-controls/additional-privileges), scoped to the environments and paths its services live in. This is the minimum each identity needs:
+Grant each identity the minimum permissions it needs with a [custom role](/documentation/platform/access-controls/role-based-access-controls) or an [additional privilege](/documentation/platform/access-controls/additional-privileges), scoped to the environments and paths its services live in. The **Agent Proxy Policies** and **Agent Policies** templates (offered under Additional Privileges when creating an identity) apply these permissions in a single step and are the fastest way to get started, but they grant them project-wide. For production use, prefer a custom role or additional privilege scoped with conditions to the environments and paths your services occupy. This is the minimum each identity needs:
| Identity | Minimum permissions | Notes |
| --- | --- | --- |
| **Agent** | `Proxy` on **Proxied Services**, scoped to the environments and paths where its services live | This alone lets it route traffic and have credentials applied. It does not need to read any secret. |
-| **Agent Proxy** | `Read Value` and `Describe Secret` on **Secrets**, covering every secret the services reference; plus `Manage Leases` on **Dynamic Secrets** for any dynamic secret a service brokers | This is the identity that actually fetches the real values and mints leases. `Describe Secret` determines whether a secret is visible to the identity at all, `Read Value` reveals its value, and `Manage Leases` lets it mint a brokered dynamic secret. It needs no proxied-service permission. |
+| **Agent Proxy** | `Read Value` and `Describe Secret` on **Secrets**, covering every secret the services reference; `Manage Leases` on **Dynamic Secrets** for any dynamic secret a service brokers; and `Report Usage` on **Proxied Services** | This is the identity that fetches the real values, mints leases, and records service usage. `Describe Secret` determines whether a secret is visible to the identity at all, `Read Value` reveals its value, `Manage Leases` lets it mint a brokered dynamic secret, and `Report Usage` lets it stamp a service's "last used" time. It never holds `Proxy`; routing traffic is the agent's job alone. |
<Note>
An agent identity should be scoped to just the **Proxy** permission, with no secret read access. If an agent also needs real values in its environment, grant its identity **Read Value** on those specific secrets. Avoid granting folder-wide read access to an agent identity: that would also expose the brokered secrets and defeat the purpose of brokering them.
@@ -53,6 +53,8 @@ The key thing to get right for the Agent Proxy: it needs **Read Value on every s
For a service that brokers a [dynamic secret](/documentation/platform/agent-proxy/proxied-services#using-dynamic-secrets), the Agent Proxy identity needs `Manage Leases` on that dynamic secret. The agent identity must **not** have `Manage Leases` on it, or `agent-proxy connect` refuses to start.
+The Agent Proxy also records each time it brokers a service, which surfaces as a "last used" time on the proxied service. This is why it needs `Report Usage`. Usage is always reported by the Agent Proxy identity, never the agent's: the agent runs in an untrusted environment, so letting it report would allow a compromised agent to forge usage. The proxy is the trusted observer.
+
## Next steps
<CardGroup cols={2}>
diff --git a/docs/images/platform/agent-proxy/quickstart-add-additional-privileges.png b/docs/images/platform/agent-proxy/quickstart-add-additional-privileges.png
deleted file mode 100644
index 74411f71ae..0000000000
Binary files a/docs/images/platform/agent-proxy/quickstart-add-additional-privileges.png and /dev/null differ
diff --git a/docs/images/platform/agent-proxy/quickstart-agent-identity-role.png b/docs/images/platform/agent-proxy/quickstart-agent-identity-role.png
deleted file mode 100644
index 786f44e9d0..0000000000
Binary files a/docs/images/platform/agent-proxy/quickstart-agent-identity-role.png and /dev/null differ
diff --git a/docs/images/platform/agent-proxy/quickstart-create-agent-identity.png b/docs/images/platform/agent-proxy/quickstart-create-agent-identity.png
index ec13ccb7cc..b7c617f2fe 100644
Binary files a/docs/images/platform/agent-proxy/quickstart-create-agent-identity.png and b/docs/images/platform/agent-proxy/quickstart-create-agent-identity.png differ
diff --git a/docs/images/platform/agent-proxy/quickstart-create-identity.png b/docs/images/platform/agent-proxy/quickstart-create-identity.png
index 907b591e50..f2338bde76 100644
Binary files a/docs/images/platform/agent-proxy/quickstart-create-identity.png and b/docs/images/platform/agent-proxy/quickstart-create-identity.png differ
diff --git a/docs/images/platform/agent-proxy/quickstart-proxy-identity-role.png b/docs/images/platform/agent-proxy/quickstart-proxy-identity-role.png
deleted file mode 100644
index b9c806bcff..0000000000
Binary files a/docs/images/platform/agent-proxy/quickstart-proxy-identity-role.png and /dev/null differ
diff --git a/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/CreateOrgIdentitySheet.tsx b/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/CreateOrgIdentitySheet.tsx
new file mode 100644
index 0000000000..c1a15fa269
--- /dev/null
+++ b/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/CreateOrgIdentitySheet.tsx
@@ -0,0 +1,238 @@
+import { useEffect, useState } from "react";
+import { Controller, useForm } from "react-hook-form";
+import { zodResolver } from "@hookform/resolvers/zod";
+import { useNavigate } from "@tanstack/react-router";
+import { z } from "zod";
+
+import { UpgradePlanModal } from "@app/components/license/UpgradePlanModal";
+import { createNotification } from "@app/components/notifications";
+import { RoleOption } from "@app/components/roles";
+import {
+ Button,
+ Field,
+ FieldContent,
+ FieldError,
+ FieldLabel,
+ FilterableSelect,
+ Input,
+ Sheet,
+ SheetContent,
+ SheetDescription,
+ SheetFooter,
+ SheetHeader,
+ SheetTitle,
+ Tabs,
+ TabsList,
+ TabsTrigger
+} from "@app/components/v3";
+import { useOrganization, useSubscription } from "@app/context";
+import { findOrgMembershipRole, isCustomOrgRole } from "@app/helpers/roles";
+import { useCreateOrgIdentity, useGetOrgRoles } from "@app/hooks/api";
+import { useAddIdentityUniversalAuth } from "@app/hooks/api/identities";
+import { usePopUp } from "@app/hooks/usePopUp";
+
+import { OrgIdentityLinkForm } from "./OrgIdentityLinkForm";
+
+enum IdentityWizardSteps {
+ CreateIdentity = "create-identity",
+ LinkIdentity = "link-identity"
+}
+
+const schema = z.object({
+ name: z.string().min(1, "Required"),
+ role: z.object({ slug: z.string(), name: z.string() })
+});
+
+type FormData = z.infer<typeof schema>;
+
+type Props = {
+ isOpen: boolean;
+ onOpenChange: (isOpen: boolean) => void;
+};
+
+const CreateOrgIdentityForm = ({ onClose }: { onClose: () => void }) => {
+ const navigate = useNavigate();
+ const { currentOrg } = useOrganization();
+ const orgId = currentOrg?.id || "";
+ const { subscription } = useSubscription();
+ const {
+ popUp: upgradePlanPopUp,
+ handlePopUpOpen: handleUpgradePlanPopUpOpen,
+ handlePopUpToggle: handleUpgradePlanPopUpToggle
+ } = usePopUp(["upgradePlan"] as const);
+
+ const { data: roles } = useGetOrgRoles(orgId);
+
+ const { mutateAsync: createMutateAsync } = useCreateOrgIdentity();
+ const { mutateAsync: addMutateAsync } = useAddIdentityUniversalAuth();
+
+ const {
+ control,
+ handleSubmit,
+ reset,
+ formState: { isSubmitting }
+ } = useForm<FormData>({
+ resolver: zodResolver(schema),
+ defaultValues: { name: "" }
+ });
+
+ useEffect(() => {
+ if (!roles?.length) return;
+ reset({
+ name: "",
+ role: findOrgMembershipRole(roles, currentOrg!.defaultMembershipRole)
+ });
+ }, [roles]);
+
+ const onFormSubmit = async ({ name, role }: FormData) => {
+ if (role?.slug && isCustomOrgRole(role.slug) && subscription && !subscription?.rbac) {
+ handleUpgradePlanPopUpOpen("upgradePlan");
+ return;
+ }
+
+ const { id: createdId } = await createMutateAsync({
+ name,
+ role: role.slug || undefined,
+ hasDeleteProtection: true,
+ organizationId: orgId
+ });
+
+ await addMutateAsync({
+ organizationId: orgId,
+ identityId: createdId,
+ clientSecretTrustedIps: [{ ipAddress: "0.0.0.0/0" }, { ipAddress: "::/0" }],
+ accessTokenTrustedIps: [{ ipAddress: "0.0.0.0/0" }, { ipAddress: "::/0" }],
+ accessTokenTTL: 2592000,
+ accessTokenMaxTTL: 2592000,
+ accessTokenNumUsesLimit: 0,
+ accessTokenPeriod: 0,
+ lockoutEnabled: true,
+ lockoutThreshold: 3,
+ lockoutDurationSeconds: 300,
+ lockoutCounterResetSeconds: 30
+ });
+
+ createNotification({
+ text: "Successfully created machine identity",
+ type: "success"
+ });
+
+ reset();
+ onClose();
+ navigate({
+ to: "/organizations/$orgId/identities/$identityId",
+ params: { identityId: createdId, orgId }
+ });
+ };
+
+ return (
+ <form onSubmit={handleSubmit(onFormSubmit)} className="flex flex-1 flex-col overflow-hidden">
+ <div className="flex thin-scrollbar flex-1 flex-col gap-4 overflow-y-auto p-4">
+ <Controller
+ control={control}
+ defaultValue=""
+ name="name"
+ render={({ field, fieldState: { error } }) => (
+ <Field>
+ <FieldLabel>Name</FieldLabel>
+ <FieldContent>
+ <Input {...field} autoFocus placeholder="Machine 1" isError={Boolean(error)} />
+ </FieldContent>
+ {error && <FieldError>{error.message}</FieldError>}
+ </Field>
+ )}
+ />
+ <Controller
+ control={control}
+ name="role"
+ render={({ field: { onChange, value }, fieldState: { error } }) => (
+ <Field>
+ <FieldLabel>Role</FieldLabel>
+ <FieldContent>
+ <FilterableSelect
+ placeholder="Select role..."
+ options={roles}
+ onChange={onChange}
+ value={value}
+ getOptionValue={(option) => option.slug}
+ getOptionLabel={(option) => option.name}
+ components={{ Option: RoleOption }}
+ isError={Boolean(error)}
+ />
+ </FieldContent>
+ {error && <FieldError>{error.message}</FieldError>}
+ </Field>
+ )}
+ />
+ </div>
+ <SheetFooter className="border-t">
+ <Button type="submit" variant="org" isPending={isSubmitting} isDisabled={isSubmitting}>
+ Create
+ </Button>
+ <Button type="button" variant="outline" onClick={onClose}>
+ Cancel
+ </Button>
+ </SheetFooter>
+ <UpgradePlanModal
+ isOpen={upgradePlanPopUp.upgradePlan.isOpen}
+ onOpenChange={(isOpen) => handleUpgradePlanPopUpToggle("upgradePlan", isOpen)}
+ text="Assigning custom roles to machine identities can be unlocked if you upgrade to Infisical Enterprise plan."
+ isEnterpriseFeature
+ />
+ </form>
+ );
+};
+
+export const CreateOrgIdentitySheet = ({ isOpen, onOpenChange }: Props) => {
+ const { isSubOrganization } = useOrganization();
+ const [wizardStep, setWizardStep] = useState(IdentityWizardSteps.CreateIdentity);
+
+ const handleOpenChange = (open: boolean) => {
+ onOpenChange(open);
+ if (!open) setWizardStep(IdentityWizardSteps.CreateIdentity);
+ };
+
+ return (
+ <Sheet open={isOpen} onOpenChange={handleOpenChange}>
+ <SheetContent side="right" className="flex flex-col gap-0 sm:max-w-lg">
+ <SheetHeader className="border-b">
+ <SheetTitle>
+ {isSubOrganization
+ ? "Add Machine Identity to Sub-Organization"
+ : "Create Organization Machine Identity"}
+ </SheetTitle>
+ <SheetDescription>
+ {isSubOrganization
+ ? "Create a new machine identity or assign an existing one"
+ : "Create a new machine identity in the organization"}
+ </SheetDescription>
+ </SheetHeader>
+ {isSubOrganization && (
+ <div className="flex shrink-0 flex-col gap-2 px-4 pt-4">
+ <Tabs
+ className="w-full"
+ value={wizardStep}
+ onValueChange={(value) => setWizardStep(value as IdentityWizardSteps)}
+ >
+ <TabsList className="w-full">
+ <TabsTrigger value={IdentityWizardSteps.CreateIdentity}>Create New</TabsTrigger>
+ <TabsTrigger value={IdentityWizardSteps.LinkIdentity}>Assign Existing</TabsTrigger>
+ </TabsList>
+ </Tabs>
+ <p className="text-sm text-muted">
+ {wizardStep === IdentityWizardSteps.LinkIdentity
+ ? "Reuse an existing machine identity from your parent organization."
+ : "Create a dedicated machine identity managed at the sub-organization level."}
+ </p>
+ </div>
+ )}
+ {wizardStep === IdentityWizardSteps.CreateIdentity && (
+ <CreateOrgIdentityForm onClose={() => handleOpenChange(false)} />
+ )}
+ {wizardStep === IdentityWizardSteps.LinkIdentity && (
+ <OrgIdentityLinkForm onClose={() => handleOpenChange(false)} />
+ )}
+ </SheetContent>
+ </Sheet>
+ );
+};
diff --git a/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentitySection.tsx b/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentitySection.tsx
index 67a14a3f50..b929cb6ef9 100644
--- a/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentitySection.tsx
+++ b/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentitySection.tsx
@@ -1,5 +1,4 @@
-import { useState } from "react";
-import { InfoIcon, PlusIcon } from "lucide-react";
+import { PlusIcon } from "lucide-react";
import { UpgradePlanModal } from "@app/components/license/UpgradePlanModal";
import { createNotification } from "@app/components/notifications";
@@ -13,18 +12,7 @@ import {
CardDescription,
CardHeader,
CardTitle,
- Dialog,
- DialogContent,
- DialogDescription,
- DialogHeader,
- DialogTitle,
- DocumentationLinkBadge,
- Tabs,
- TabsList,
- TabsTrigger,
- Tooltip,
- TooltipContent,
- TooltipTrigger
+ DocumentationLinkBadge
} from "@app/components/v3";
import {
OrgPermissionIdentityActions,
@@ -39,18 +27,12 @@ import { useDeleteIdentityAuthTemplate } from "@app/hooks/api/identityAuthTempla
import { SubscriptionPlanTypes } from "@app/hooks/api/subscriptions/types";
import { usePopUp } from "@app/hooks/usePopUp";
+import { CreateOrgIdentitySheet } from "./CreateOrgIdentitySheet";
import { IdentityAuthTemplateModal } from "./IdentityAuthTemplateModal";
import { IdentityAuthTemplatesTable } from "./IdentityAuthTemplatesTable";
import { IdentityTable } from "./IdentityTable";
import { IdentityTokenAuthTokenModal } from "./IdentityTokenAuthTokenModal";
import { MachineAuthTemplateUsagesModal } from "./MachineAuthTemplateUsagesModal";
-import { OrgIdentityLinkForm } from "./OrgIdentityLinkForm";
-import { OrgIdentityModal } from "./OrgIdentityModal";
-
-enum IdentityWizardSteps {
- CreateIdentity = "create-identity",
- LinkIdentity = "link-identity"
-}
export const IdentitySection = withPermission(
() => {
@@ -58,8 +40,6 @@ export const IdentitySection = withPermission(
const { currentOrg, isSubOrganization } = useOrganization();
const orgId = currentOrg?.id || "";
- const [wizardStep, setWizardStep] = useState(IdentityWizardSteps.CreateIdentity);
-
const { mutateAsync: deleteMutateAsync } = useDeleteOrgIdentity();
const { mutateAsync: deleteTemplateMutateAsync } = useDeleteIdentityAuthTemplate();
const { popUp, handlePopUpOpen, handlePopUpClose, handlePopUpToggle } = usePopUp([
@@ -142,10 +122,6 @@ export const IdentitySection = withPermission(
return;
}
- if (!isSubOrganization) {
- setWizardStep(IdentityWizardSteps.CreateIdentity);
- }
-
handlePopUpOpen("identity");
}}
isDisabled={!isAllowed}
@@ -218,81 +194,10 @@ export const IdentitySection = withPermission(
}
/>
<IdentityTokenAuthTokenModal popUp={popUp} handlePopUpToggle={handlePopUpToggle} />
- <Dialog
- open={popUp.identity.isOpen}
- onOpenChange={(open) => {
- handlePopUpToggle("identity", open);
- if (!open) {
- setWizardStep(IdentityWizardSteps.CreateIdentity);
- }
- }}
- >
- <DialogContent className="max-w-xl overflow-visible">
- <DialogHeader>
- <DialogTitle>
- {isSubOrganization
- ? "Add Machine Identity to Sub-Organization"
- : "Create Organization Machine Identity"}
- </DialogTitle>
- <DialogDescription>
- {isSubOrganization
- ? "Create a new machine identity or assign an existing one"
- : "Create a new machine identity in the organization"}
- </DialogDescription>
- </DialogHeader>
- {isSubOrganization && (
- <div className="mx-auto flex items-center gap-2">
- <Tabs
- value={wizardStep}
- onValueChange={(value) => setWizardStep(value as IdentityWizardSteps)}
- >
- <TabsList className="w-fit">
- <TabsTrigger value={IdentityWizardSteps.CreateIdentity}>Create New</TabsTrigger>
- <TabsTrigger value={IdentityWizardSteps.LinkIdentity}>
- Assign Existing
- </TabsTrigger>
- </TabsList>
- </Tabs>
- <Tooltip>
- <TooltipTrigger>
- <InfoIcon size={16} className="text-mineshaft-400" />
- </TooltipTrigger>
- <TooltipContent side="right" align="start" className="max-w-sm">
- <p className="mb-2 text-mineshaft-300">
- You can add machine identities to your sub-organization in one of two ways:
- </p>
- <ul className="ml-3.5 flex list-disc flex-col gap-y-4">
- <li className="text-mineshaft-200">
- <strong className="font-medium text-mineshaft-100">Create New</strong> -
- Create a new machine identity specifically for this sub-organization. This
- machine identity will be managed at the sub-organization level.
- <p className="mt-2">
- This method is recommended for autonomous teams that need to manage
- machine identity authentication.
- </p>
- </li>
- <li>
- <strong className="font-medium text-mineshaft-100">Assign Existing</strong>{" "}
- Assign an existing machine identity from your parent organization. The
- machine identity will continue to be managed at its original scope.
- <p className="mt-2">
- This method is recommended for organizations that need to maintain
- centralized control.
- </p>
- </li>
- </ul>
- </TooltipContent>
- </Tooltip>
- </div>
- )}
- {wizardStep === IdentityWizardSteps.CreateIdentity && (
- <OrgIdentityModal popUp={popUp} handlePopUpToggle={handlePopUpToggle} />
- )}
- {wizardStep === IdentityWizardSteps.LinkIdentity && (
- <OrgIdentityLinkForm onClose={() => handlePopUpClose("identity")} />
- )}
- </DialogContent>
- </Dialog>
+ <CreateOrgIdentitySheet
+ isOpen={popUp.identity.isOpen}
+ onOpenChange={(open) => handlePopUpToggle("identity", open)}
+ />
<DeleteActionModal
isOpen={popUp.deleteIdentity.isOpen}
title={`Are you sure you want to delete ${
diff --git a/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/OrgIdentityLinkForm.tsx b/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/OrgIdentityLinkForm.tsx
index 654aa04c02..6ee97788da 100644
--- a/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/OrgIdentityLinkForm.tsx
+++ b/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/OrgIdentityLinkForm.tsx
@@ -12,7 +12,8 @@ import {
FieldContent,
FieldError,
FieldLabel,
- FilterableSelect
+ FilterableSelect,
+ SheetFooter
} from "@app/components/v3";
import { useOrganization } from "@app/context";
import { useGetOrgRoles } from "@app/hooks/api";
@@ -81,61 +82,63 @@ export const OrgIdentityLinkForm = ({ onClose }: Props) => {
};
return (
- <form onSubmit={handleSubmit(onFormSubmit)} className="flex flex-col gap-4">
- <Controller
- control={control}
- name="identity"
- render={({ field: { onChange, value }, fieldState: { error } }) => (
- <Field>
- <FieldLabel>Machine Identity</FieldLabel>
- <FieldContent>
- <FilterableSelect
- value={value}
- onChange={onChange}
- placeholder="Select machine identity..."
- // onInputChange={setSearchValue}
- autoFocus
- options={rootOrgIdentities}
- getOptionValue={(option) => option.id}
- getOptionLabel={(option) => option.name}
- isLoading={isRootOrgLoading}
- isError={Boolean(error)}
- />
- </FieldContent>
- {error && <FieldError>{error.message}</FieldError>}
- </Field>
- )}
- />
- <Controller
- control={control}
- name="role"
- render={({ field: { onChange, value }, fieldState: { error } }) => (
- <Field>
- <FieldLabel>Role</FieldLabel>
- <FieldContent>
- <FilterableSelect
- value={value}
- onChange={onChange}
- options={roles}
- placeholder="Select role..."
- getOptionValue={(option) => option.slug}
- getOptionLabel={(option) => option.name}
- components={{ Option: RoleOption }}
- isError={Boolean(error)}
- />
- </FieldContent>
- {error && <FieldError>{error.message}</FieldError>}
- </Field>
- )}
- />
- <div className="flex items-center justify-end gap-2">
- <Button type="button" variant="outline" onClick={() => onClose()}>
- Cancel
- </Button>
+ <form onSubmit={handleSubmit(onFormSubmit)} className="flex flex-1 flex-col overflow-hidden">
+ <div className="flex thin-scrollbar flex-1 flex-col gap-4 overflow-y-auto p-4">
+ <Controller
+ control={control}
+ name="identity"
+ render={({ field: { onChange, value }, fieldState: { error } }) => (
+ <Field>
+ <FieldLabel>Machine Identity</FieldLabel>
+ <FieldContent>
+ <FilterableSelect
+ value={value}
+ onChange={onChange}
+ placeholder="Select machine identity..."
+ // onInputChange={setSearchValue}
+ autoFocus
+ options={rootOrgIdentities}
+ getOptionValue={(option) => option.id}
+ getOptionLabel={(option) => option.name}
+ isLoading={isRootOrgLoading}
+ isError={Boolean(error)}
+ />
+ </FieldContent>
+ {error && <FieldError>{error.message}</FieldError>}
+ </Field>
+ )}
+ />
+ <Controller
+ control={control}
+ name="role"
+ render={({ field: { onChange, value }, fieldState: { error } }) => (
+ <Field>
+ <FieldLabel>Role</FieldLabel>
+ <FieldContent>
+ <FilterableSelect
+ value={value}
+ onChange={onChange}
+ options={roles}
+ placeholder="Select role..."
+ getOptionValue={(option) => option.slug}
+ getOptionLabel={(option) => option.name}
+ components={{ Option: RoleOption }}
+ isError={Boolean(error)}
+ />
+ </FieldContent>
+ {error && <FieldError>{error.message}</FieldError>}
+ </Field>
+ )}
+ />
+ </div>
+ <SheetFooter className="border-t">
<Button type="submit" variant="sub-org" isPending={isSubmitting} isDisabled={isSubmitting}>
Assign to Sub-Organization
</Button>
- </div>
+ <Button type="button" variant="outline" onClick={() => onClose()}>
+ Cancel
+ </Button>
+ </SheetFooter>
</form>
);
};
diff --git a/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/OrgIdentityModal.tsx b/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/OrgIdentityModal.tsx
index 98f38ebed7..c0a4e24108 100644
--- a/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/OrgIdentityModal.tsx
+++ b/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/OrgIdentityModal.tsx
@@ -1,7 +1,6 @@
import { useEffect } from "react";
import { Controller, useFieldArray, useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
-import { useNavigate } from "@tanstack/react-router";
import { PlusIcon, TrashIcon } from "lucide-react";
import { twMerge } from "tailwind-merge";
import { z } from "zod";
@@ -24,8 +23,7 @@ import {
} from "@app/components/v3";
import { useOrganization, useSubscription } from "@app/context";
import { findOrgMembershipRole, isCustomOrgRole } from "@app/helpers/roles";
-import { useCreateOrgIdentity, useGetOrgRoles, useUpdateOrgIdentity } from "@app/hooks/api";
-import { useAddIdentityUniversalAuth } from "@app/hooks/api/identities";
+import { useGetOrgRoles, useUpdateOrgIdentity } from "@app/hooks/api";
import { usePopUp, UsePopUpState } from "@app/hooks/usePopUp";
const schema = z
@@ -52,7 +50,6 @@ type Props = {
};
export const OrgIdentityModal = ({ popUp, handlePopUpToggle }: Props) => {
- const navigate = useNavigate();
const { currentOrg, isSubOrganization } = useOrganization();
const orgId = currentOrg?.id || "";
const { subscription } = useSubscription();
@@ -65,9 +62,7 @@ export const OrgIdentityModal = ({ popUp, handlePopUpToggle }: Props) => {
const { data: roles } = useGetOrgRoles(orgId);
const isOrgIdentity = popUp?.identity?.data ? orgId === popUp?.identity?.data?.orgId : true;
- const { mutateAsync: createMutateAsync } = useCreateOrgIdentity();
const { mutateAsync: updateMutateAsync } = useUpdateOrgIdentity();
- const { mutateAsync: addMutateAsync } = useAddIdentityUniversalAuth();
const {
control,
@@ -131,57 +126,19 @@ export const OrgIdentityModal = ({ popUp, handlePopUpToggle }: Props) => {
orgId: string;
};
- if (identity) {
- // update
-
- await updateMutateAsync({
- identityId: identity.identityId,
- name,
- role: role.slug || undefined,
- hasDeleteProtection,
- organizationId: orgId,
- metadata
- });
-
- handlePopUpToggle("identity", false);
- } else {
- // create
-
- const { id: createdId } = await createMutateAsync({
- name,
- role: role.slug || undefined,
- hasDeleteProtection,
- organizationId: orgId,
- metadata
- });
-
- await addMutateAsync({
- organizationId: orgId,
- identityId: createdId,
- clientSecretTrustedIps: [{ ipAddress: "0.0.0.0/0" }, { ipAddress: "::/0" }],
- accessTokenTrustedIps: [{ ipAddress: "0.0.0.0/0" }, { ipAddress: "::/0" }],
- accessTokenTTL: 2592000,
- accessTokenMaxTTL: 2592000,
- accessTokenNumUsesLimit: 0,
- accessTokenPeriod: 0,
- lockoutEnabled: true,
- lockoutThreshold: 3,
- lockoutDurationSeconds: 300,
- lockoutCounterResetSeconds: 30
- });
+ await updateMutateAsync({
+ identityId: identity.identityId,
+ name,
+ role: role.slug || undefined,
+ hasDeleteProtection,
+ organizationId: orgId,
+ metadata
+ });
- handlePopUpToggle("identity", false);
- navigate({
- to: "/organizations/$orgId/identities/$identityId",
- params: {
- identityId: createdId,
- orgId
- }
- });
- }
+ handlePopUpToggle("identity", false);
createNotification({
- text: `Successfully ${popUp?.identity?.data ? "updated" : "created"} machine identity`,
+ text: "Successfully updated machine identity",
type: "success"
});
@@ -336,7 +293,7 @@ export const OrgIdentityModal = ({ popUp, handlePopUpToggle }: Props) => {
isPending={isSubmitting}
isDisabled={isSubmitting}
>
- {popUp?.identity?.data ? "Update" : "Create"}
+ Update
</Button>
</div>
<UpgradePlanModal
diff --git a/frontend/src/pages/project/AccessControlPage/components/IdentityTab/IdentityTab.tsx b/frontend/src/pages/project/AccessControlPage/components/IdentityTab/IdentityTab.tsx
index fc86436a5f..2f1b25093d 100644
--- a/frontend/src/pages/project/AccessControlPage/components/IdentityTab/IdentityTab.tsx
+++ b/frontend/src/pages/project/AccessControlPage/components/IdentityTab/IdentityTab.tsx
@@ -28,11 +28,6 @@ import {
CardDescription,
CardHeader,
CardTitle,
- Dialog,
- DialogContent,
- DialogDescription,
- DialogHeader,
- DialogTitle,
DocumentationLinkBadge,
DropdownMenu,
DropdownMenuCheckboxItem,
@@ -63,9 +58,6 @@ import {
TableHead,
TableHeader,
TableRow,
- Tabs,
- TabsList,
- TabsTrigger,
Tooltip,
TooltipContent,
TooltipTrigger
@@ -98,15 +90,9 @@ import { OrderByDirection } from "@app/hooks/api/generic/types";
import { ProjectIdentityOrderBy, ProjectType } from "@app/hooks/api/projects/types";
import { usePopUp } from "@app/hooks/usePopUp";
import { IdentityAuthMethodModal } from "@app/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityAuthMethodModal";
-import { ProjectIdentityModal } from "@app/pages/project/AccessControlPage/components/IdentityTab/components/ProjectIdentityModal";
import { IdentityAuthMethodSheet } from "@app/views/IdentityAuthMethods";
-import { ProjectLinkIdentityModal } from "./components/ProjectLinkIdentityModal";
-
-enum AddIdentityType {
- CreateNew = "create-new",
- AssignExisting = "assign-existing"
-}
+import { CreateProjectIdentitySheet } from "./components/CreateProjectIdentity/CreateProjectIdentitySheet";
export const IdentityTab = withProjectPermission(
() => {
@@ -116,10 +102,6 @@ export const IdentityTab = withProjectPermission(
const isCertManager = currentProject?.type === ProjectType.CertificateManager;
const productLabel = isCertManager ? "Certificate Manager" : "Project";
- const [addMachineIdentityType, setAddMachineIdentityType] = useState<AddIdentityType>(
- AddIdentityType.CreateNew
- );
-
const {
offset,
limit,
@@ -642,75 +624,10 @@ export const IdentityTab = withProjectPermission(
</div>
</CardContent>
</Card>
- <Dialog
- open={popUp.createIdentity.isOpen}
- onOpenChange={(open) => {
- handlePopUpToggle("createIdentity", open);
- if (!open) {
- setAddMachineIdentityType(AddIdentityType.CreateNew);
- }
- }}
- >
- <DialogContent className="max-w-xl overflow-visible">
- <DialogHeader>
- <DialogTitle>{`Add Machine Identity to ${productLabel}`}</DialogTitle>
- <DialogDescription>
- Create a new machine identity or assign an existing one
- </DialogDescription>
- </DialogHeader>
- <div className="mx-auto flex items-center gap-2">
- <Tabs
- value={addMachineIdentityType}
- onValueChange={(value) => setAddMachineIdentityType(value as AddIdentityType)}
- >
- <TabsList>
- <TabsTrigger value={AddIdentityType.CreateNew}>Create New</TabsTrigger>
- <TabsTrigger value={AddIdentityType.AssignExisting}>Assign Existing</TabsTrigger>
- </TabsList>
- </Tabs>
- <Tooltip>
- <TooltipTrigger>
- <InfoIcon size={16} className="text-mineshaft-400" />
- </TooltipTrigger>
- <TooltipContent side="right" align="start" className="max-w-sm">
- <p className="mb-2 text-mineshaft-300">
- You can add machine identities to your{" "}
- {isCertManager ? "Certificate Manager" : "project"} in one of two ways:
- </p>
- <ul className="ml-3.5 flex list-disc flex-col gap-y-4">
- <li className="text-mineshaft-200">
- <strong className="font-medium text-mineshaft-100">Create New</strong> -
- Create a dedicated machine identity managed at the{" "}
- {isCertManager ? "Certificate Manager-level" : "project-level"}.
- <p className="mt-2">
- This method is recommended for autonomous teams that need to manage machine
- identity authentication.
- </p>
- </li>
- <li>
- <strong className="font-medium text-mineshaft-100">Assign Existing</strong> -
- Assign an existing machine identity from your organization.
- <p className="mt-2">
- This method is recommended for organizations that need to maintain
- centralized control.
- </p>
- </li>
- </ul>
- </TooltipContent>
- </Tooltip>
- </div>
- {addMachineIdentityType === AddIdentityType.CreateNew && (
- <ProjectIdentityModal
- onClose={() => {
- handlePopUpClose("createIdentity");
- }}
- />
- )}
- {addMachineIdentityType === AddIdentityType.AssignExisting && (
- <ProjectLinkIdentityModal handlePopUpToggle={handlePopUpToggle} />
- )}
- </DialogContent>
- </Dialog>
+ <CreateProjectIdentitySheet
+ isOpen={popUp.createIdentity.isOpen}
+ onOpenChange={(open) => handlePopUpToggle("createIdentity", open)}
+ />
<DeleteActionModal
isOpen={popUp.deleteIdentity.isOpen}
title={`Are you sure you want to remove ${
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
new file mode 100644
index 0000000000..0cf4eab5cf
--- /dev/null
+++ b/frontend/src/pages/project/AccessControlPage/components/IdentityTab/components/CreateProjectIdentity/CreateProjectIdentityForm.tsx
@@ -0,0 +1,366 @@
+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 { useNavigate } from "@tanstack/react-router";
+import { AxiosError } from "axios";
+
+import { createNotification } from "@app/components/notifications";
+import { RoleOption } from "@app/components/roles";
+import {
+ Button,
+ Field,
+ FieldContent,
+ FieldError,
+ FieldLabel,
+ FilterableSelect,
+ Input,
+ SheetFooter,
+ Tabs,
+ TabsList,
+ TabsTrigger
+} from "@app/components/v3";
+import { getProjectBaseURL } from "@app/helpers/project";
+import {
+ projectIdentityMembershipQuery,
+ useCreateIdentityProjectAdditionalPrivilege,
+ useCreateProjectIdentity,
+ useCreateProjectIdentityMembership,
+ useGetProjectRoles,
+ useListProjectIdentityMemberships,
+ useUpdateProjectIdentityMembership
+} from "@app/hooks/api";
+import { useAddIdentityUniversalAuth } from "@app/hooks/api/identities";
+import { ProjectType } from "@app/hooks/api/projects/types";
+import { ProjectMembershipRole } from "@app/hooks/api/roles/types";
+import {
+ formRolePermission2API,
+ RoleTemplates,
+ TFormSchema
+} from "@app/pages/project/RoleDetailsBySlugPage/components/ProjectRoleModifySection.utils";
+
+import { PolicyTemplateSelect } from "./PolicyTemplateSelect";
+import {
+ CreateProjectIdentityMode,
+ createProjectIdentitySchema,
+ TCreateProjectIdentityForm
+} from "./schema";
+
+const UNIVERSAL_AUTH_DEFAULTS = {
+ clientSecretTrustedIps: [{ ipAddress: "0.0.0.0/0" }, { ipAddress: "::/0" }],
+ accessTokenTrustedIps: [{ ipAddress: "0.0.0.0/0" }, { ipAddress: "::/0" }],
+ accessTokenTTL: 2592000,
+ accessTokenMaxTTL: 2592000,
+ accessTokenNumUsesLimit: 0,
+ accessTokenPeriod: 0,
+ lockoutEnabled: true,
+ lockoutThreshold: 3,
+ lockoutDurationSeconds: 300,
+ lockoutCounterResetSeconds: 30
+};
+
+const buildTemplatePermissions = (
+ projectType: ProjectType,
+ templateIds: string[]
+): TFormSchema["permissions"] => {
+ const templates = (RoleTemplates[projectType ?? ProjectType.SecretManager] ?? []).filter(
+ (template) => templateIds.includes(template.id)
+ );
+
+ const merged: Record<string, Record<string, boolean>> = {};
+ templates.forEach((template) => {
+ template.permissions.forEach(({ subject, actions }) => {
+ merged[subject] = merged[subject] ?? {};
+ actions.forEach((action) => {
+ merged[subject][action] = true;
+ });
+ });
+ });
+
+ return Object.fromEntries(
+ Object.entries(merged).map(([subject, actions]) => [subject, [actions]])
+ ) as TFormSchema["permissions"];
+};
+
+type Props = {
+ projectId: string;
+ projectType: ProjectType;
+ canGrantPrivileges: boolean;
+ onClose: () => void;
+};
+
+export const CreateProjectIdentityForm = ({
+ projectId,
+ projectType,
+ canGrantPrivileges,
+ onClose
+}: Props) => {
+ const navigate = useNavigate();
+ const isCertManager = projectType === ProjectType.CertificateManager;
+
+ const { data: roles } = useGetProjectRoles(projectId, projectType);
+
+ const defaultRole = isCertManager
+ ? { slug: ProjectMembershipRole.Member, name: "Member" }
+ : { slug: ProjectMembershipRole.NoAccess, name: "No Access" };
+
+ const form = useForm<TCreateProjectIdentityForm>({
+ resolver: zodResolver(createProjectIdentitySchema),
+ defaultValues: {
+ mode: CreateProjectIdentityMode.Create,
+ name: "",
+ role: defaultRole,
+ templateIds: []
+ }
+ });
+
+ const {
+ control,
+ handleSubmit,
+ setValue,
+ formState: { isSubmitting }
+ } = form;
+
+ const mode = useWatch({ control, name: "mode" });
+
+ const { data: availableData, isPending: isAvailableLoading } = useQuery({
+ ...projectIdentityMembershipQuery.listAvailable({ projectId, projectType }),
+ placeholderData: (prev) => prev,
+ enabled: mode === CreateProjectIdentityMode.Assign
+ });
+ const { data: membershipsData } = useListProjectIdentityMemberships(
+ { projectId, projectType, limit: 1000 },
+ { enabled: mode === CreateProjectIdentityMode.Assign }
+ );
+
+ const assignableIdentities = useMemo(() => {
+ const alreadyMembers = new Set(
+ (membershipsData?.identityMemberships ?? []).map((m) => m.identity.id)
+ );
+ return (availableData ?? [])
+ .filter((i) => !alreadyMembers.has(i.id))
+ .map((i) => ({ id: i.id, name: i.name }));
+ }, [availableData, membershipsData]);
+
+ const { mutateAsync: createProjectIdentity } = useCreateProjectIdentity();
+ const { mutateAsync: updateMembership } = useUpdateProjectIdentityMembership();
+ const { mutateAsync: createMembership } = useCreateProjectIdentityMembership();
+ const { mutateAsync: addUniversalAuth } = useAddIdentityUniversalAuth();
+ const { mutateAsync: createAdditionalPrivilege } = useCreateIdentityProjectAdditionalPrivilege();
+
+ const onSubmit = async (data: TCreateProjectIdentityForm) => {
+ try {
+ let identityId: string;
+
+ if (data.mode === CreateProjectIdentityMode.Create) {
+ const created = await createProjectIdentity({
+ name: data.name!.trim(),
+ projectId,
+ hasDeleteProtection: true
+ });
+ identityId = created.id;
+
+ if (data.role?.slug) {
+ await updateMembership({
+ roles: [{ role: data.role.slug }],
+ identityId,
+ projectId,
+ projectType
+ });
+ }
+
+ await addUniversalAuth({ projectId, identityId, ...UNIVERSAL_AUTH_DEFAULTS });
+ } else {
+ identityId = data.identity!.id;
+ await createMembership({
+ projectId,
+ projectType,
+ identityId,
+ role: data.role?.slug || undefined
+ });
+ }
+
+ const hasTemplateGrants = data.templateIds.length > 0;
+ let grantFailed = false;
+
+ if (hasTemplateGrants && canGrantPrivileges) {
+ try {
+ await createAdditionalPrivilege({
+ identityId,
+ projectId,
+ permissions: formRolePermission2API(
+ buildTemplatePermissions(projectType, data.templateIds)
+ ),
+ type: { isTemporary: false as const }
+ });
+ } catch {
+ grantFailed = true;
+ }
+ }
+
+ if (grantFailed) {
+ createNotification({
+ text: `Machine identity ${
+ data.mode === CreateProjectIdentityMode.Assign ? "added" : "created"
+ }, but applying the policy grant failed. You can add it from the identity page.`,
+ type: "error"
+ });
+ } else {
+ createNotification({
+ text: `Successfully ${
+ data.mode === CreateProjectIdentityMode.Assign ? "added" : "created"
+ } machine identity`,
+ type: "success"
+ });
+ }
+
+ onClose();
+
+ if (data.mode === CreateProjectIdentityMode.Create || (hasTemplateGrants && !grantFailed)) {
+ navigate({
+ to: `${getProjectBaseURL(projectType)}/identities/$identityId`,
+ params: { identityId }
+ });
+ }
+ } catch (err) {
+ const message = (err as AxiosError<{ message?: string }>)?.response?.data?.message;
+ createNotification({
+ text:
+ message ??
+ (data.mode === CreateProjectIdentityMode.Assign
+ ? "Failed to add machine identity"
+ : "Failed to create machine identity"),
+ type: "error"
+ });
+ }
+ };
+
+ return (
+ <FormProvider {...form}>
+ <form onSubmit={handleSubmit(onSubmit)} className="flex flex-1 flex-col overflow-hidden">
+ <div className="flex thin-scrollbar flex-1 flex-col gap-4 overflow-y-auto p-4">
+ <div className="flex flex-col gap-2">
+ <Controller
+ control={control}
+ name="mode"
+ render={({ field: { value, onChange } }) => (
+ <Tabs
+ className="w-full"
+ value={value}
+ onValueChange={(next) => {
+ onChange(next as CreateProjectIdentityMode);
+ if (next === CreateProjectIdentityMode.Create) {
+ setValue("identity", undefined);
+ } else {
+ setValue("name", "");
+ }
+ }}
+ >
+ <TabsList className="w-full">
+ <TabsTrigger value={CreateProjectIdentityMode.Create}>Create New</TabsTrigger>
+ <TabsTrigger value={CreateProjectIdentityMode.Assign}>
+ Assign Existing
+ </TabsTrigger>
+ </TabsList>
+ </Tabs>
+ )}
+ />
+ <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.`}
+ </p>
+ </div>
+
+ {mode === CreateProjectIdentityMode.Create ? (
+ <Controller
+ control={control}
+ name="name"
+ render={({ field, fieldState: { error } }) => (
+ <Field>
+ <FieldLabel>Name</FieldLabel>
+ <FieldContent>
+ <Input {...field} autoFocus placeholder="Machine 1" isError={Boolean(error)} />
+ </FieldContent>
+ {error && <FieldError>{error.message}</FieldError>}
+ </Field>
+ )}
+ />
+ ) : (
+ <Controller
+ control={control}
+ name="identity"
+ render={({ field: { value, onChange }, fieldState: { error } }) => (
+ <Field>
+ <FieldLabel>Machine Identity</FieldLabel>
+ <FieldContent>
+ <FilterableSelect
+ value={value || null}
+ onChange={(newValue) => onChange(newValue || undefined)}
+ isLoading={isAvailableLoading}
+ placeholder="Select machine identity..."
+ options={assignableIdentities}
+ getOptionValue={(option) => option.id}
+ getOptionLabel={(option) => option.name}
+ isError={Boolean(error)}
+ />
+ </FieldContent>
+ {error && <FieldError>{error.message}</FieldError>}
+ </Field>
+ )}
+ />
+ )}
+
+ <Controller
+ control={control}
+ name="role"
+ render={({ field: { value, onChange }, fieldState: { error } }) => (
+ <Field>
+ <FieldLabel>Role</FieldLabel>
+ <FieldContent>
+ <FilterableSelect
+ value={value}
+ onChange={onChange}
+ options={roles}
+ placeholder="Select role..."
+ getOptionValue={(option) => option.slug}
+ getOptionLabel={(option) => option.name}
+ components={{ Option: RoleOption }}
+ isError={Boolean(error)}
+ />
+ </FieldContent>
+ {error && <FieldError>{error.message}</FieldError>}
+ </Field>
+ )}
+ />
+
+ {canGrantPrivileges && (
+ <Field>
+ <FieldLabel>
+ Additional Privileges <span className="text-muted">(optional)</span>
+ </FieldLabel>
+ <FieldContent>
+ <PolicyTemplateSelect projectType={projectType} />
+ </FieldContent>
+ </Field>
+ )}
+ </div>
+ <SheetFooter className="border-t">
+ <Button
+ type="submit"
+ variant="project"
+ isPending={isSubmitting}
+ isDisabled={isSubmitting}
+ >
+ {mode === CreateProjectIdentityMode.Assign ? "Add" : "Create"}
+ </Button>
+ <Button type="button" variant="outline" onClick={onClose} isDisabled={isSubmitting}>
+ Cancel
+ </Button>
+ </SheetFooter>
+ </form>
+ </FormProvider>
+ );
+};
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
new file mode 100644
index 0000000000..39c2a7d8ec
--- /dev/null
+++ b/frontend/src/pages/project/AccessControlPage/components/IdentityTab/components/CreateProjectIdentity/CreateProjectIdentitySheet.tsx
@@ -0,0 +1,51 @@
+import { Sheet, SheetContent, SheetDescription, SheetHeader, SheetTitle } from "@app/components/v3";
+import {
+ ProjectPermissionIdentityActions,
+ ProjectPermissionSub,
+ useProject,
+ useProjectPermission
+} from "@app/context";
+import { ProjectType } from "@app/hooks/api/projects/types";
+
+import { CreateProjectIdentityForm } from "./CreateProjectIdentityForm";
+
+type Props = {
+ isOpen: boolean;
+ onOpenChange: (isOpen: boolean) => void;
+};
+
+export const CreateProjectIdentitySheet = ({ isOpen, onOpenChange }: Props) => {
+ const { currentProject } = useProject();
+ const { permission } = useProjectPermission();
+
+ const canGrantPrivileges =
+ permission.can(ProjectPermissionIdentityActions.Edit, ProjectPermissionSub.Identity) &&
+ permission.can(
+ ProjectPermissionIdentityActions.AssignAdditionalPrivileges,
+ ProjectPermissionSub.Identity
+ );
+
+ const productLabel =
+ currentProject.type === ProjectType.CertificateManager ? "Certificate Manager" : "Project";
+
+ return (
+ <Sheet open={isOpen} onOpenChange={onOpenChange}>
+ <SheetContent side="right" className="flex flex-col gap-0 sm:max-w-lg">
+ <SheetHeader className="border-b">
+ <SheetTitle>{`Add Machine Identity to ${productLabel}`}</SheetTitle>
+ <SheetDescription>
+ Create a new machine identity or assign an existing one
+ </SheetDescription>
+ </SheetHeader>
+ {isOpen && (
+ <CreateProjectIdentityForm
+ projectId={currentProject.id}
+ projectType={currentProject.type}
+ canGrantPrivileges={canGrantPrivileges}
+ onClose={() => onOpenChange(false)}
+ />
+ )}
+ </SheetContent>
+ </Sheet>
+ );
+};
diff --git a/frontend/src/pages/project/AccessControlPage/components/IdentityTab/components/CreateProjectIdentity/PolicyTemplateSelect.tsx b/frontend/src/pages/project/AccessControlPage/components/IdentityTab/components/CreateProjectIdentity/PolicyTemplateSelect.tsx
new file mode 100644
index 0000000000..91248d129f
--- /dev/null
+++ b/frontend/src/pages/project/AccessControlPage/components/IdentityTab/components/CreateProjectIdentity/PolicyTemplateSelect.tsx
@@ -0,0 +1,110 @@
+import { useFormContext, useWatch } from "react-hook-form";
+import { components, OptionProps } from "react-select";
+import { CheckIcon, InfoIcon } from "lucide-react";
+
+import { FilterableSelect, Tooltip, TooltipContent, TooltipTrigger } from "@app/components/v3";
+import { ProjectPermissionSub } from "@app/context";
+import { ProjectType } from "@app/hooks/api/projects/types";
+import {
+ PROJECT_PERMISSION_OBJECT,
+ RoleTemplates
+} from "@app/pages/project/RoleDetailsBySlugPage/components/ProjectRoleModifySection.utils";
+
+import { TCreateProjectIdentityForm } from "./schema";
+
+type TemplatePermission = { subject: ProjectPermissionSub; actions: string[] };
+type TemplateOption = {
+ id: string;
+ name: string;
+ description: string;
+ permissions: TemplatePermission[];
+};
+
+const PermissionsTooltip = ({ permissions }: { permissions: TemplatePermission[] }) => (
+ <div className="flex flex-col gap-2">
+ {permissions
+ .map((permission) => ({
+ ...permission,
+ object: PROJECT_PERMISSION_OBJECT[permission.subject]
+ }))
+ .sort((a, b) => a.object.title.localeCompare(b.object.title))
+ .map(({ subject, actions, object }) => (
+ <div key={subject}>
+ <div className="text-xs font-medium text-label">{object.title}</div>
+ <div className="text-sm">
+ {actions
+ .map((action) => object.actions.find((a) => a.value === action)?.label ?? action)
+ .join(", ")}
+ </div>
+ </div>
+ ))}
+ </div>
+);
+
+const TemplateOptionRow = ({ isSelected, children, ...props }: OptionProps<TemplateOption>) => (
+ <components.Option isSelected={isSelected} {...props}>
+ <div className="flex flex-row items-center justify-between gap-2">
+ <div className="min-w-0 flex-1">
+ <p className="truncate">{children}</p>
+ <p className="text-xs leading-4 break-words whitespace-normal text-muted">
+ {props.data.description}
+ </p>
+ </div>
+ <div className="flex shrink-0 items-center gap-2">
+ <span className="flex size-4 items-center justify-center">
+ {isSelected && <CheckIcon className="size-4" />}
+ </span>
+ <Tooltip>
+ <TooltipTrigger
+ type="button"
+ onClick={(e) => {
+ e.preventDefault();
+ e.stopPropagation();
+ }}
+ >
+ <InfoIcon className="size-4 text-muted hover:text-foreground" />
+ </TooltipTrigger>
+ <TooltipContent side="left" align="start" className="max-w-sm">
+ <PermissionsTooltip permissions={props.data.permissions} />
+ </TooltipContent>
+ </Tooltip>
+ </div>
+ </div>
+ </components.Option>
+);
+
+type Props = {
+ projectType: ProjectType;
+};
+
+export const PolicyTemplateSelect = ({ projectType }: Props) => {
+ const { control, setValue } = useFormContext<TCreateProjectIdentityForm>();
+ const templateIds = useWatch({ control, name: "templateIds" }) ?? [];
+
+ const options: TemplateOption[] = (
+ RoleTemplates[projectType ?? ProjectType.SecretManager] ?? []
+ ).map(({ id, name, description, permissions }) => ({ id, name, description, permissions }));
+
+ if (!options.length) return null;
+
+ const value = options.filter((option) => templateIds.includes(option.id));
+
+ return (
+ <FilterableSelect
+ isMulti
+ value={value}
+ options={options}
+ placeholder="Select additional privileges..."
+ getOptionValue={(option) => option.id}
+ getOptionLabel={(option) => option.name}
+ components={{ Option: TemplateOptionRow }}
+ onChange={(newValue) =>
+ setValue(
+ "templateIds",
+ (newValue as TemplateOption[]).map((option) => option.id),
+ { shouldDirty: true }
+ )
+ }
+ />
+ );
+};
diff --git a/frontend/src/pages/project/AccessControlPage/components/IdentityTab/components/CreateProjectIdentity/schema.ts b/frontend/src/pages/project/AccessControlPage/components/IdentityTab/components/CreateProjectIdentity/schema.ts
new file mode 100644
index 0000000000..fe108ebcfe
--- /dev/null
+++ b/frontend/src/pages/project/AccessControlPage/components/IdentityTab/components/CreateProjectIdentity/schema.ts
@@ -0,0 +1,28 @@
+import { z } from "zod";
+
+export enum CreateProjectIdentityMode {
+ Create = "create",
+ Assign = "assign"
+}
+
+export const createProjectIdentitySchema = z
+ .object({
+ mode: z.nativeEnum(CreateProjectIdentityMode),
+ name: z.string().optional(),
+ identity: z.preprocess(
+ (val) => (val && typeof val === "object" ? val : undefined),
+ z.object({ id: z.string(), name: z.string() }).optional()
+ ),
+ role: z.object({ slug: z.string(), name: z.string() }),
+ templateIds: z.array(z.string()).default([])
+ })
+ .superRefine((data, ctx) => {
+ if (data.mode === CreateProjectIdentityMode.Create && !data.name?.trim()) {
+ ctx.addIssue({ code: z.ZodIssueCode.custom, path: ["name"], message: "Required" });
+ }
+ if (data.mode === CreateProjectIdentityMode.Assign && !data.identity?.id) {
+ ctx.addIssue({ code: z.ZodIssueCode.custom, path: ["identity"], message: "Required" });
+ }
+ });
+
+export type TCreateProjectIdentityForm = z.infer<typeof createProjectIdentitySchema>;
diff --git a/frontend/src/pages/project/AccessControlPage/components/IdentityTab/components/ProjectIdentityModal.tsx b/frontend/src/pages/project/AccessControlPage/components/IdentityTab/components/ProjectIdentityModal.tsx
index e8a5849820..d87ba30250 100644
--- a/frontend/src/pages/project/AccessControlPage/components/IdentityTab/components/ProjectIdentityModal.tsx
+++ b/frontend/src/pages/project/AccessControlPage/components/IdentityTab/components/ProjectIdentityModal.tsx
@@ -1,12 +1,10 @@
import { Controller, useFieldArray, useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
-import { useNavigate } from "@tanstack/react-router";
import { PlusIcon, TrashIcon } from "lucide-react";
import { twMerge } from "tailwind-merge";
import { z } from "zod";
import { createNotification } from "@app/components/notifications";
-import { RoleOption } from "@app/components/roles";
import {
Button,
Field,
@@ -14,29 +12,17 @@ import {
FieldDescription,
FieldError,
FieldLabel,
- FilterableSelect,
IconButton,
Input,
Label,
Switch
} from "@app/components/v3";
import { useProject } from "@app/context";
-import { getProjectBaseURL } from "@app/helpers/project";
-import {
- TProjectIdentity,
- useCreateProjectIdentity,
- useGetProjectRoles,
- useUpdateProjectIdentity,
- useUpdateProjectIdentityMembership
-} from "@app/hooks/api";
-import { useAddIdentityUniversalAuth } from "@app/hooks/api/identities";
-import { ProjectType } from "@app/hooks/api/projects/types";
-import { ProjectMembershipRole } from "@app/hooks/api/roles/types";
+import { TProjectIdentity, useUpdateProjectIdentity } from "@app/hooks/api";
const schema = z.object({
name: z.string().min(1, "Required"),
hasDeleteProtection: z.boolean(),
- role: z.object({ slug: z.string(), name: z.string() }).optional(),
metadata: z
.object({
key: z.string().trim().min(1),
@@ -50,28 +36,13 @@ export type FormData = z.infer<typeof schema>;
type ContentProps = {
onClose: () => void;
- identity?: TProjectIdentity;
+ identity: TProjectIdentity;
};
export const ProjectIdentityModal = ({ onClose, identity }: ContentProps) => {
- const navigate = useNavigate();
-
const { currentProject } = useProject();
- const isCertManager = currentProject.type === ProjectType.CertificateManager;
-
- const isUpdate = Boolean(identity);
- // Roles list is sourced product-aware (cert-manager filters to Admin + Member server-side).
- const { data: roles } = useGetProjectRoles(currentProject.id, currentProject.type);
- // For cert-manager, default to Member instead of No Access (No Access is filtered out server-side).
- const defaultRole = isCertManager
- ? { slug: ProjectMembershipRole.Member, name: "Member" }
- : { slug: ProjectMembershipRole.NoAccess, name: "No Access" };
-
- const { mutateAsync: createMutateAsync } = useCreateProjectIdentity();
const { mutateAsync: updateMutateAsync } = useUpdateProjectIdentity();
- const { mutateAsync: addMutateAsync } = useAddIdentityUniversalAuth();
- const { mutateAsync: updateMembershipMutateAsync } = useUpdateProjectIdentityMembership();
const {
control,
@@ -83,8 +54,7 @@ export const ProjectIdentityModal = ({ onClose, identity }: ContentProps) => {
defaultValues: {
name: identity?.name ?? "",
hasDeleteProtection: identity?.hasDeleteProtection ?? true,
- metadata: identity?.metadata ?? [],
- role: isUpdate ? undefined : defaultRole
+ metadata: identity?.metadata ?? []
}
});
@@ -93,63 +63,20 @@ export const ProjectIdentityModal = ({ onClose, identity }: ContentProps) => {
name: "metadata"
});
- const onFormSubmit = async ({ name, role, metadata, hasDeleteProtection }: FormData) => {
+ const onFormSubmit = async ({ name, metadata, hasDeleteProtection }: FormData) => {
try {
- if (identity) {
- // update
- await updateMutateAsync({
- identityId: identity.id,
- name,
- hasDeleteProtection,
- projectId: currentProject.id,
- metadata
- });
-
- onClose();
- } else {
- const created = await createMutateAsync({
- name,
- projectId: currentProject.id,
- hasDeleteProtection,
- metadata
- });
- const createdId = created.id;
-
- if (role) {
- await updateMembershipMutateAsync({
- roles: [{ role: role.slug }],
- identityId: createdId,
- projectId: currentProject.id,
- projectType: currentProject.type
- });
- }
-
- await addMutateAsync({
- projectId: currentProject.id,
- identityId: createdId,
- clientSecretTrustedIps: [{ ipAddress: "0.0.0.0/0" }, { ipAddress: "::/0" }],
- accessTokenTrustedIps: [{ ipAddress: "0.0.0.0/0" }, { ipAddress: "::/0" }],
- accessTokenTTL: 2592000,
- accessTokenMaxTTL: 2592000,
- accessTokenNumUsesLimit: 0,
- accessTokenPeriod: 0,
- lockoutEnabled: true,
- lockoutThreshold: 3,
- lockoutDurationSeconds: 300,
- lockoutCounterResetSeconds: 30
- });
+ await updateMutateAsync({
+ identityId: identity.id,
+ name,
+ hasDeleteProtection,
+ projectId: currentProject.id,
+ metadata
+ });
- onClose();
- navigate({
- to: `${getProjectBaseURL(currentProject.type)}/identities/$identityId`,
- params: {
- identityId: createdId
- }
- });
- }
+ onClose();
createNotification({
- text: `Successfully ${isUpdate ? "updated" : "created"} machine identity`,
+ text: "Successfully updated machine identity",
type: "success"
});
@@ -157,9 +84,7 @@ export const ProjectIdentityModal = ({ onClose, identity }: ContentProps) => {
} catch (err) {
console.error(err);
const error = err as any;
- const text =
- error?.response?.data?.message ??
- `Failed to ${isUpdate ? "update" : "create"} machine identity`;
+ const text = error?.response?.data?.message ?? "Failed to update machine identity";
createNotification({
text,
@@ -184,30 +109,6 @@ export const ProjectIdentityModal = ({ onClose, identity }: ContentProps) => {
</Field>
)}
/>
- {!isUpdate && (
- <Controller
- control={control}
- name="role"
- render={({ field: { onChange, value }, fieldState: { error } }) => (
- <Field>
- <FieldLabel>Role</FieldLabel>
- <FieldContent>
- <FilterableSelect
- placeholder="Select role..."
- options={roles}
- onChange={onChange}
- value={value}
- getOptionValue={(option) => option.slug}
- getOptionLabel={(option) => option.name}
- components={{ Option: RoleOption }}
- isError={Boolean(error)}
- />
- </FieldContent>
- {error && <FieldError>{error.message}</FieldError>}
- </Field>
- )}
- />
- )}
<Controller
control={control}
name="hasDeleteProtection"
@@ -303,7 +204,7 @@ export const ProjectIdentityModal = ({ onClose, identity }: ContentProps) => {
Cancel
</Button>
<Button type="submit" variant="project" isPending={isSubmitting} isDisabled={isSubmitting}>
- {isUpdate ? "Update" : "Create"}
+ Update
</Button>
</div>
</form>
diff --git a/frontend/src/pages/project/AccessControlPage/components/IdentityTab/components/ProjectLinkIdentityModal.tsx b/frontend/src/pages/project/AccessControlPage/components/IdentityTab/components/ProjectLinkIdentityModal.tsx
deleted file mode 100644
index c39394c6aa..0000000000
--- a/frontend/src/pages/project/AccessControlPage/components/IdentityTab/components/ProjectLinkIdentityModal.tsx
+++ /dev/null
@@ -1,184 +0,0 @@
-import { useMemo } from "react";
-import { Controller, useForm } from "react-hook-form";
-import { zodResolver } from "@hookform/resolvers/zod";
-import { useQuery } from "@tanstack/react-query";
-import { z } from "zod";
-
-import { createNotification } from "@app/components/notifications";
-import { RoleOption } from "@app/components/roles";
-import {
- Button,
- Field,
- FieldContent,
- FieldError,
- FieldLabel,
- FilterableSelect
-} from "@app/components/v3";
-import { useProject } from "@app/context";
-import {
- projectIdentityMembershipQuery,
- useCreateProjectIdentityMembership,
- useGetProjectRoles,
- useListProjectIdentityMemberships
-} from "@app/hooks/api";
-import { UsePopUpState } from "@app/hooks/usePopUp";
-
-const schema = z.object({
- identity: z.object({
- name: z.string(),
- id: z.string()
- }),
- role: z.object({ name: z.string(), slug: z.string() })
-});
-
-export type FormData = z.infer<typeof schema>;
-
-type Props = {
- handlePopUpToggle: (popUpName: keyof UsePopUpState<["createIdentity"]>, state?: boolean) => void;
-};
-
-export const ProjectLinkIdentityModal = ({ handlePopUpToggle }: Props) => {
- const { projectId, currentProject } = useProject();
-
- // const [searchValue, setSearchValue] = useState("");
-
- // const [debouncedSearchValue] = useDebounce(searchValue);
-
- // TODO: name search needs to be implemented on the backend
- const { data: identityMembershipOrgs, isPending: isMembershipsLoading } = useQuery({
- ...projectIdentityMembershipQuery.listAvailable({
- projectId,
- projectType: currentProject?.type
- // identityName: debouncedSearchValue
- }),
- placeholderData: (prev) => prev
- });
-
- const { data: identityMembershipsData } = useListProjectIdentityMemberships({
- projectId,
- projectType: currentProject?.type,
- limit: 1000 // TODO: this is temp to preserve functionality for larger projects, will optimize in PR referenced above
- });
- const identityMemberships = identityMembershipsData?.identityMemberships;
-
- const { data: roles, isPending: isRolesLoading } = useGetProjectRoles(
- projectId,
- currentProject?.type
- );
-
- const { mutateAsync: createProjectIdentityMembershipMutateAsync } =
- useCreateProjectIdentityMembership();
-
- const filteredIdentityMembershipOrgs = useMemo(() => {
- const wsIdentityIds = new Map();
-
- identityMemberships?.forEach((identityMembership) => {
- wsIdentityIds.set(identityMembership.identity.id, true);
- });
-
- return (identityMembershipOrgs || []).filter((i) => !wsIdentityIds.has(i.id));
- }, [identityMembershipOrgs, identityMemberships]);
-
- const {
- control,
- handleSubmit,
- reset,
- formState: { isSubmitting }
- } = useForm<FormData>({
- resolver: zodResolver(schema)
- });
-
- const onFormSubmit = async ({ identity, role }: FormData) => {
- await createProjectIdentityMembershipMutateAsync({
- projectId,
- projectType: currentProject?.type,
- identityId: identity.id,
- role: role.slug || undefined
- });
-
- createNotification({
- text: "Successfully added machine identity to project",
- type: "success"
- });
-
- const nextAvailableMembership = filteredIdentityMembershipOrgs.filter(
- (membership) => membership.id !== identity.id
- )[0];
-
- // prevents combobox from displaying previously added identity
- reset({
- identity: {
- name: nextAvailableMembership?.name,
- id: nextAvailableMembership?.id
- }
- });
- handlePopUpToggle("createIdentity", false);
- };
-
- return (
- <form onSubmit={handleSubmit(onFormSubmit)} className="flex flex-col gap-4">
- <Controller
- control={control}
- name="identity"
- render={({ field: { onChange, value }, fieldState: { error } }) => (
- <Field>
- <FieldLabel>Machine Identity</FieldLabel>
- <FieldContent>
- <FilterableSelect
- value={value}
- onChange={onChange}
- isLoading={isMembershipsLoading}
- placeholder="Select machine identity..."
- autoFocus
- // onInputChange={setSearchValue}
- options={filteredIdentityMembershipOrgs.map((membership) => ({
- name: membership.name,
- id: membership.id
- }))}
- getOptionValue={(option) => option.id}
- getOptionLabel={(option) => option.name}
- isError={Boolean(error)}
- />
- </FieldContent>
- {error && <FieldError>{error.message}</FieldError>}
- </Field>
- )}
- />
- <Controller
- control={control}
- name="role"
- render={({ field: { onChange, value }, fieldState: { error } }) => (
- <Field>
- <FieldLabel>Role</FieldLabel>
- <FieldContent>
- <FilterableSelect
- value={value}
- isLoading={isRolesLoading}
- onChange={onChange}
- options={roles}
- placeholder="Select role..."
- getOptionValue={(option) => option.slug}
- getOptionLabel={(option) => option.name}
- components={{ Option: RoleOption }}
- isError={Boolean(error)}
- />
- </FieldContent>
- {error && <FieldError>{error.message}</FieldError>}
- </Field>
- )}
- />
- <div className="flex items-center justify-end gap-2">
- <Button
- type="button"
- variant="outline"
- onClick={() => handlePopUpToggle("createIdentity", false)}
- >
- Cancel
- </Button>
- <Button type="submit" variant="project" isPending={isSubmitting} isDisabled={isSubmitting}>
- Assign to Project
- </Button>
- </div>
- </form>
- );
-};
diff --git a/frontend/src/pages/project/RoleDetailsBySlugPage/components/ProjectRoleModifySection.utils.tsx b/frontend/src/pages/project/RoleDetailsBySlugPage/components/ProjectRoleModifySection.utils.tsx
index 44e48395d2..a044f71de9 100644
--- a/frontend/src/pages/project/RoleDetailsBySlugPage/components/ProjectRoleModifySection.utils.tsx
+++ b/frontend/src/pages/project/RoleDetailsBySlugPage/components/ProjectRoleModifySection.utils.tsx
@@ -4060,8 +4060,7 @@ export const RoleTemplates: Record<ProjectType, RoleTemplate[]> = {
{
id: "agent-proxy",
name: "Agent Proxy Policies",
- description:
- "For the Agent Proxy identity: reads brokered secret values and mints dynamic-secret leases",
+ description: "Reads secret values, mints dynamic secret leases, and reports service usage",
permissions: [
{
subject: ProjectPermissionSub.Secrets,
@@ -4073,14 +4072,17 @@ export const RoleTemplates: Record<ProjectType, RoleTemplate[]> = {
{
subject: ProjectPermissionSub.DynamicSecrets,
actions: [ProjectPermissionDynamicSecretActions.Lease]
+ },
+ {
+ subject: ProjectPermissionSub.ProxiedServices,
+ actions: [ProjectPermissionProxiedServiceActions.ReportUsage]
}
]
},
{
id: "agent",
name: "Agent Policies",
- description:
- "For an agent identity: routes traffic through proxied services without reading secrets",
+ description: "Routes traffic through proxied services",
permissions: [
{
subject: ProjectPermissionSub.ProxiedServices,