Skip to content

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

feat: add gateway pools to org role permissions ui

bernie-g981f4a69f203
diff --git a/frontend/src/pages/organization/RoleByIDPage/components/OrgRoleModifySection.utils.ts b/frontend/src/pages/organization/RoleByIDPage/components/OrgRoleModifySection.utils.ts
index 566a02e45e..187e48f770 100644
--- a/frontend/src/pages/organization/RoleByIDPage/components/OrgRoleModifySection.utils.ts
+++ b/frontend/src/pages/organization/RoleByIDPage/components/OrgRoleModifySection.utils.ts
@@ -4,6 +4,7 @@ import { z } from "zod";
import { OrgPermissionSubjects } from "@app/context";
import {
OrgGatewayPermissionActions,
+ OrgGatewayPoolPermissionActions,
OrgPermissionAppConnectionActions,
OrgPermissionAuditLogsActions,
OrgPermissionBillingActions,
@@ -103,6 +104,16 @@ const orgGatewayPermissionSchema = z
})
.optional();
+const orgGatewayPoolPermissionSchema = z
+ .object({
+ [OrgGatewayPoolPermissionActions.ListGatewayPools]: z.boolean().optional(),
+ [OrgGatewayPoolPermissionActions.CreateGatewayPools]: z.boolean().optional(),
+ [OrgGatewayPoolPermissionActions.EditGatewayPools]: z.boolean().optional(),
+ [OrgGatewayPoolPermissionActions.DeleteGatewayPools]: z.boolean().optional(),
+ [OrgGatewayPoolPermissionActions.AttachGatewayPools]: z.boolean().optional()
+ })
+ .optional();
+
const orgRelayPermissionSchema = z
.object({
[OrgRelayPermissionActions.ListRelays]: z.boolean().optional(),
@@ -189,6 +200,7 @@ export const formSchema = z.object({
"app-connections": appConnectionsPermissionSchema,
kmip: kmipPermissionSchema,
gateway: orgGatewayPermissionSchema,
+ "gateway-pool": orgGatewayPoolPermissionSchema,
relay: orgRelayPermissionSchema,
"machine-identity-auth-template": machineIdentityAuthTemplatePermissionSchema,
"secret-share": secretSharingPermissionSchema,
diff --git a/frontend/src/pages/organization/RoleByIDPage/components/RolePermissionsSection/OrgPermissionGatewayPoolRow.tsx b/frontend/src/pages/organization/RoleByIDPage/components/RolePermissionsSection/OrgPermissionGatewayPoolRow.tsx
new file mode 100644
index 0000000000..5a614e2796
--- /dev/null
+++ b/frontend/src/pages/organization/RoleByIDPage/components/RolePermissionsSection/OrgPermissionGatewayPoolRow.tsx
@@ -0,0 +1,185 @@
+import { useEffect, useMemo } from "react";
+import { Control, Controller, UseFormSetValue, useWatch } from "react-hook-form";
+import { faChevronDown, faChevronRight } from "@fortawesome/free-solid-svg-icons";
+import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
+
+import { createNotification } from "@app/components/notifications";
+import { Checkbox, Select, SelectItem, Td, Tr } from "@app/components/v2";
+import { OrgGatewayPoolPermissionActions } from "@app/context/OrgPermissionContext/types";
+import { useToggle } from "@app/hooks";
+
+import { TFormSchema } from "../OrgRoleModifySection.utils";
+
+type Props = {
+ isEditable: boolean;
+ setValue: UseFormSetValue<TFormSchema>;
+ control: Control<TFormSchema>;
+};
+
+enum Permission {
+ NoAccess = "no-access",
+ ReadOnly = "read-only",
+ FullAccess = "full-access",
+ Custom = "custom"
+}
+
+const PERMISSION_ACTIONS = [
+ { action: OrgGatewayPoolPermissionActions.ListGatewayPools, label: "List Gateway Pools" },
+ { action: OrgGatewayPoolPermissionActions.CreateGatewayPools, label: "Create Gateway Pools" },
+ { action: OrgGatewayPoolPermissionActions.EditGatewayPools, label: "Edit Gateway Pools" },
+ { action: OrgGatewayPoolPermissionActions.DeleteGatewayPools, label: "Delete Gateway Pools" },
+ { action: OrgGatewayPoolPermissionActions.AttachGatewayPools, label: "Attach Gateway Pools" }
+] as const;
+
+export const OrgGatewayPoolPermissionRow = ({ isEditable, control, setValue }: Props) => {
+ const [isRowExpanded, setIsRowExpanded] = useToggle();
+ const [isCustom, setIsCustom] = useToggle();
+
+ const rule = useWatch({
+ control,
+ name: "permissions.gateway-pool"
+ });
+
+ const selectedPermissionCategory = useMemo(() => {
+ const actions = Object.keys(rule || {}) as Array<keyof typeof rule>;
+ const totalActions = PERMISSION_ACTIONS.length;
+ const score = actions.map((key) => (rule?.[key] ? 1 : 0)).reduce((a, b) => a + b, 0 as number);
+
+ if (isCustom) return Permission.Custom;
+ if (score === 0) return Permission.NoAccess;
+ if (score === totalActions) return Permission.FullAccess;
+ if (score === 1 && rule?.[OrgGatewayPoolPermissionActions.ListGatewayPools])
+ return Permission.ReadOnly;
+
+ return Permission.Custom;
+ }, [rule, isCustom]);
+
+ useEffect(() => {
+ if (selectedPermissionCategory === Permission.Custom) setIsCustom.on();
+ else setIsCustom.off();
+ }, [selectedPermissionCategory]);
+
+ useEffect(() => {
+ const isRowCustom = selectedPermissionCategory === Permission.Custom;
+ if (isRowCustom) {
+ setIsRowExpanded.on();
+ }
+ }, []);
+
+ const handlePermissionChange = (val: Permission) => {
+ if (!val) return;
+ if (val === Permission.Custom) {
+ setIsRowExpanded.on();
+ setIsCustom.on();
+ return;
+ }
+ setIsCustom.off();
+
+ switch (val) {
+ case Permission.FullAccess:
+ setValue(
+ "permissions.gateway-pool",
+ {
+ [OrgGatewayPoolPermissionActions.ListGatewayPools]: true,
+ [OrgGatewayPoolPermissionActions.CreateGatewayPools]: true,
+ [OrgGatewayPoolPermissionActions.EditGatewayPools]: true,
+ [OrgGatewayPoolPermissionActions.DeleteGatewayPools]: true,
+ [OrgGatewayPoolPermissionActions.AttachGatewayPools]: true
+ },
+ { shouldDirty: true }
+ );
+ break;
+ case Permission.ReadOnly:
+ setValue(
+ "permissions.gateway-pool",
+ {
+ [OrgGatewayPoolPermissionActions.ListGatewayPools]: true,
+ [OrgGatewayPoolPermissionActions.CreateGatewayPools]: false,
+ [OrgGatewayPoolPermissionActions.EditGatewayPools]: false,
+ [OrgGatewayPoolPermissionActions.DeleteGatewayPools]: false,
+ [OrgGatewayPoolPermissionActions.AttachGatewayPools]: false
+ },
+ { shouldDirty: true }
+ );
+ break;
+
+ case Permission.NoAccess:
+ default:
+ setValue(
+ "permissions.gateway-pool",
+ {
+ [OrgGatewayPoolPermissionActions.ListGatewayPools]: false,
+ [OrgGatewayPoolPermissionActions.CreateGatewayPools]: false,
+ [OrgGatewayPoolPermissionActions.EditGatewayPools]: false,
+ [OrgGatewayPoolPermissionActions.DeleteGatewayPools]: false,
+ [OrgGatewayPoolPermissionActions.AttachGatewayPools]: false
+ },
+ { shouldDirty: true }
+ );
+ }
+ };
+
+ return (
+ <>
+ <Tr
+ className="h-10 cursor-pointer transition-colors duration-100 hover:bg-mineshaft-700"
+ onClick={() => setIsRowExpanded.toggle()}
+ >
+ <Td className="w-4">
+ <FontAwesomeIcon className="w-4" icon={isRowExpanded ? faChevronDown : faChevronRight} />
+ </Td>
+ <Td className="w-full select-none">Gateway Pools</Td>
+ <Td>
+ <Select
+ value={selectedPermissionCategory}
+ className="h-8 w-40 bg-mineshaft-700"
+ dropdownContainerClassName="border text-left border-mineshaft-600 bg-mineshaft-800"
+ onValueChange={handlePermissionChange}
+ isDisabled={!isEditable}
+ position="popper"
+ >
+ <SelectItem value={Permission.NoAccess}>No Access</SelectItem>
+ <SelectItem value={Permission.ReadOnly}>Read Only</SelectItem>
+ <SelectItem value={Permission.FullAccess}>Full Access</SelectItem>
+ <SelectItem value={Permission.Custom}>Custom</SelectItem>
+ </Select>
+ </Td>
+ </Tr>
+ {isRowExpanded && (
+ <Tr>
+ <Td colSpan={3} className="border-mineshaft-500 bg-mineshaft-900 p-8">
+ <div className="flex grow flex-wrap justify-start gap-x-8 gap-y-4">
+ {PERMISSION_ACTIONS.map(({ action, label }) => {
+ return (
+ <Controller
+ name={`permissions.gateway-pool.${action}`}
+ key={`permissions.gateway-pool.${action}`}
+ control={control}
+ render={({ field }) => (
+ <Checkbox
+ isChecked={Boolean(field.value)}
+ onCheckedChange={(e) => {
+ if (!isEditable) {
+ createNotification({
+ type: "error",
+ text: "Failed to update default role"
+ });
+ return;
+ }
+ field.onChange(e);
+ }}
+ id={`permissions.gateway-pool.${action}`}
+ >
+ {label}
+ </Checkbox>
+ )}
+ />
+ );
+ })}
+ </div>
+ </Td>
+ </Tr>
+ )}
+ </>
+ );
+};
diff --git a/frontend/src/pages/organization/RoleByIDPage/components/RolePermissionsSection/RolePermissionRow.tsx b/frontend/src/pages/organization/RoleByIDPage/components/RolePermissionsSection/RolePermissionRow.tsx
index d48ee46fe0..d47a5b2ab9 100644
--- a/frontend/src/pages/organization/RoleByIDPage/components/RolePermissionsSection/RolePermissionRow.tsx
+++ b/frontend/src/pages/organization/RoleByIDPage/components/RolePermissionsSection/RolePermissionRow.tsx
@@ -69,6 +69,7 @@ type Props = {
| "organization-admin-console"
| "kmip"
| "gateway"
+ | "gateway-pool"
| "relay"
| "secret-share"
| "billing"
diff --git a/frontend/src/pages/organization/RoleByIDPage/components/RolePermissionsSection/RolePermissionsSection.tsx b/frontend/src/pages/organization/RoleByIDPage/components/RolePermissionsSection/RolePermissionsSection.tsx
index e30080763c..5487151aa7 100644
--- a/frontend/src/pages/organization/RoleByIDPage/components/RolePermissionsSection/RolePermissionsSection.tsx
+++ b/frontend/src/pages/organization/RoleByIDPage/components/RolePermissionsSection/RolePermissionsSection.tsx
@@ -19,6 +19,7 @@ import { OrgPermissionAdminConsoleRow } from "./OrgPermissionAdminConsoleRow";
import { OrgPermissionAuditLogsRow } from "./OrgPermissionAuditLogsRow";
import { OrgPermissionBillingRow } from "./OrgPermissionBillingRow";
import { OrgPermissionEmailDomainRow } from "./OrgPermissionEmailDomainRow";
+import { OrgGatewayPoolPermissionRow } from "./OrgPermissionGatewayPoolRow";
import { OrgGatewayPermissionRow } from "./OrgPermissionGatewayRow";
import { OrgPermissionGroupRow } from "./OrgPermissionGroupRow";
import { OrgPermissionIdentityRow } from "./OrgPermissionIdentityRow";
@@ -204,6 +205,11 @@ export const RolePermissionsSection = ({ roleId }: Props) => {
setValue={setValue}
isEditable={isCustomRole}
/>
+ <OrgGatewayPoolPermissionRow
+ control={control}
+ setValue={setValue}
+ isEditable={isCustomRole}
+ />
<OrgRelayPermissionRow
control={control}
setValue={setValue}