Skip to content

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

improvement: refactor ip address whitelist to single component and add ip valdiation

Scott Wilsonea50bb700a44
diff --git a/frontend/src/helpers/identityAuthSchemas.ts b/frontend/src/helpers/identityAuthSchemas.ts
index 9abba65049..735ba583ba 100644
--- a/frontend/src/helpers/identityAuthSchemas.ts
+++ b/frontend/src/helpers/identityAuthSchemas.ts
@@ -1,6 +1,9 @@
import { z } from "zod";
+import { IdentityTrustedIp } from "@app/hooks/api/identities/types";
+
import { SECONDS_PER_DAY } from "./datetime";
+import { isValidIpOrCidr } from "./ip";
// Fallback used by identity auth forms when the server's configured
// `MAX_MACHINE_IDENTITY_TOKEN_AGE` is unavailable (e.g. server status hasn't
@@ -13,3 +16,23 @@ export const accessTokenTtlSchema = (maxTTL: number, label: string) =>
z.string().refine((val) => !val || Number(val) <= maxTTL, {
message: `${label} cannot exceed ${Math.floor(maxTTL / SECONDS_PER_DAY)} days`
});
+
+// Trusted-IP constraint fields shared by every identity auth method form
+// (access token trusted IPs, plus client secret trusted IPs for Universal Auth).
+export const trustedIpsSchema = z
+ .object({
+ ipAddress: z
+ .string()
+ .max(50)
+ .refine(isValidIpOrCidr, "The IP is not a valid IPv4, IPv6, or CIDR block")
+ })
+ .array()
+ .min(1);
+
+export const DEFAULT_TRUSTED_IPS = [{ ipAddress: "0.0.0.0/0" }, { ipAddress: "::/0" }];
+
+// Collapses the server's { ipAddress, prefix } shape back into CIDR notation for the form.
+export const mapTrustedIpsFromServer = (trustedIps: IdentityTrustedIp[]) =>
+ trustedIps.map(({ ipAddress, prefix }) => ({
+ ipAddress: `${ipAddress}${prefix !== undefined ? `/${prefix}` : ""}`
+ }));
diff --git a/frontend/src/helpers/ip.ts b/frontend/src/helpers/ip.ts
new file mode 100644
index 0000000000..bbeb8c673d
--- /dev/null
+++ b/frontend/src/helpers/ip.ts
@@ -0,0 +1,68 @@
+// Browser-side mirror of the backend's `backend/src/lib/ip/index.ts`, which relies
+// on Node's `net.isIPv4` / `net.isIPv6`. The IPv4/IPv6 regexes below are copied
+// verbatim from Node's internal `lib/internal/net.js`, so this validator accepts and
+// rejects exactly what the backend's `isValidIpOrCidr` does — keeping client-side form
+// validation in lockstep with the server.
+
+const v4Seg = "(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])";
+const v4Str = `(?:${v4Seg}[.]){3}${v4Seg}`;
+const IPv4Reg = new RegExp(`^${v4Str}$`);
+
+const v6Seg = "(?:[0-9a-fA-F]{1,4})";
+const IPv6Reg = new RegExp(
+ "^(?:" +
+ `(?:${v6Seg}:){7}(?:${v6Seg}|:)|` +
+ `(?:${v6Seg}:){6}(?:${v4Str}|:${v6Seg}|:)|` +
+ `(?:${v6Seg}:){5}(?::${v4Str}|(?::${v6Seg}){1,2}|:)|` +
+ `(?:${v6Seg}:){4}(?:(?::${v6Seg}){0,1}:${v4Str}|(?::${v6Seg}){1,3}|:)|` +
+ `(?:${v6Seg}:){3}(?:(?::${v6Seg}){0,2}:${v4Str}|(?::${v6Seg}){1,4}|:)|` +
+ `(?:${v6Seg}:){2}(?:(?::${v6Seg}){0,3}:${v4Str}|(?::${v6Seg}){1,5}|:)|` +
+ `(?:${v6Seg}:){1}(?:(?::${v6Seg}){0,4}:${v4Str}|(?::${v6Seg}){1,6}|:)|` +
+ `(?::(?:(?::${v6Seg}){0,5}:${v4Str}|(?::${v6Seg}){1,7}|:))` +
+ ")(?:%[0-9a-zA-Z]{1,})?$"
+);
+
+export const isIPv4 = (ip: string): boolean => IPv4Reg.test(ip);
+
+export const isIPv6 = (ip: string): boolean => IPv6Reg.test(ip);
+
+/**
+ * Checks if a given string is a valid IPv4/IPv6 address in CIDR notation.
+ * The prefix length must be 0-32 for IPv4 and 0-128 for IPv6.
+ */
+export const isValidCidr = (cidr: string): boolean => {
+ const [ip, prefix] = cidr.split("/");
+
+ const prefixNum = parseInt(prefix, 10);
+
+ // ensure prefix exists and is a number within the appropriate range for each IP version
+ if (
+ !prefix ||
+ Number.isNaN(prefixNum) ||
+ (isIPv4(ip) && (prefixNum < 0 || prefixNum > 32)) ||
+ (isIPv6(ip) && (prefixNum < 0 || prefixNum > 128))
+ ) {
+ return false;
+ }
+
+ // ensure the IP portion of the CIDR block is a valid IPv4 or IPv6 address
+ if (!isIPv4(ip) && !isIPv6(ip)) {
+ return false;
+ }
+
+ return true;
+};
+
+/**
+ * Checks if a given string is a valid IPv4/IPv6 address or a valid CIDR block.
+ * Mirrors the backend's `isValidIpOrCidr`.
+ */
+export const isValidIpOrCidr = (ip: string): boolean => {
+ // if the string contains a slash, treat it as a CIDR block
+ if (ip.includes("/")) {
+ return isValidCidr(ip);
+ }
+
+ // otherwise, treat it as a standalone IP address (either IPv4 or IPv6)
+ return isIPv4(ip) || isIPv6(ip);
+};
diff --git a/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityAliCloudAuthForm.tsx b/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityAliCloudAuthForm.tsx
index 3e22c3d9a9..3934c6186f 100644
--- a/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityAliCloudAuthForm.tsx
+++ b/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityAliCloudAuthForm.tsx
@@ -1,19 +1,17 @@
import { useEffect, useMemo, useState } from "react";
-import { Controller, useFieldArray, useForm } from "react-hook-form";
+import { Controller, useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
import { useParams } from "@tanstack/react-router";
-import { InfoIcon, PlusIcon, XIcon } from "lucide-react";
+import { InfoIcon } from "lucide-react";
import { z } from "zod";
import { createNotification } from "@app/components/notifications";
import {
- Button,
Field,
FieldDescription,
FieldError,
FieldGroup,
FieldLabel,
- IconButton,
Input,
Tabs,
TabsContent,
@@ -25,16 +23,21 @@ import {
} from "@app/components/v3";
import { useOrganization, useSubscription } from "@app/context";
import { SECONDS_PER_DAY } from "@app/helpers/datetime";
-import { accessTokenTtlSchema } from "@app/helpers/identityAuthSchemas";
+import {
+ accessTokenTtlSchema,
+ DEFAULT_TRUSTED_IPS,
+ mapTrustedIpsFromServer,
+ trustedIpsSchema
+} from "@app/helpers/identityAuthSchemas";
import { useScopeVariant } from "@app/hooks";
import {
useAddIdentityAliCloudAuth,
useGetIdentityAliCloudAuth,
useUpdateIdentityAliCloudAuth
} from "@app/hooks/api";
-import { IdentityTrustedIp } from "@app/hooks/api/identities/types";
import { UsePopUpState } from "@app/hooks/usePopUp";
+import { TrustedIpsField } from "./shared/TrustedIpsField";
import { IDENTITY_AUTH_FORM_ID, IdentityFormTab } from "./types";
const buildSchema = (maxAccessTokenTTL: number) =>
@@ -44,12 +47,7 @@ const buildSchema = (maxAccessTokenTTL: number) =>
accessTokenTTL: accessTokenTtlSchema(maxAccessTokenTTL, "Access Token TTL"),
accessTokenMaxTTL: accessTokenTtlSchema(maxAccessTokenTTL, "Access Token Max TTL"),
accessTokenNumUsesLimit: z.string(),
- accessTokenTrustedIps: z
- .object({
- ipAddress: z.string().max(50)
- })
- .array()
- .min(1)
+ accessTokenTrustedIps: trustedIpsSchema
})
.required();
@@ -107,16 +105,10 @@ export const IdentityAliCloudAuthForm = ({
accessTokenTTL: "2592000",
accessTokenMaxTTL: "2592000",
accessTokenNumUsesLimit: "",
- accessTokenTrustedIps: [{ ipAddress: "0.0.0.0/0" }, { ipAddress: "::/0" }]
+ accessTokenTrustedIps: DEFAULT_TRUSTED_IPS
}
});
- const {
- fields: accessTokenTrustedIpsFields,
- append: appendAccessTokenTrustedIp,
- remove: removeAccessTokenTrustedIp
- } = useFieldArray({ control, name: "accessTokenTrustedIps" });
-
useEffect(() => {
if (data) {
reset({
@@ -126,13 +118,7 @@ export const IdentityAliCloudAuthForm = ({
accessTokenNumUsesLimit: data.accessTokenNumUsesLimit
? String(data.accessTokenNumUsesLimit)
: "",
- accessTokenTrustedIps: data.accessTokenTrustedIps.map(
- ({ ipAddress, prefix }: IdentityTrustedIp) => {
- return {
- ipAddress: `${ipAddress}${prefix !== undefined ? `/${prefix}` : ""}`
- };
- }
- )
+ accessTokenTrustedIps: mapTrustedIpsFromServer(data.accessTokenTrustedIps)
});
} else {
reset({
@@ -140,7 +126,7 @@ export const IdentityAliCloudAuthForm = ({
accessTokenTTL: "2592000",
accessTokenMaxTTL: "2592000",
accessTokenNumUsesLimit: "",
- accessTokenTrustedIps: [{ ipAddress: "0.0.0.0/0" }, { ipAddress: "::/0" }]
+ accessTokenTrustedIps: DEFAULT_TRUSTED_IPS
});
}
}, [data]);
@@ -308,78 +294,15 @@ export const IdentityAliCloudAuthForm = ({
</TabsContent>
<TabsContent value={IdentityFormTab.Advanced}>
<FieldGroup>
- <div className="flex flex-col gap-3">
- {accessTokenTrustedIpsFields.map(({ id }, index) => (
- <div className="flex items-start gap-2" key={id}>
- <Controller
- control={control}
- name={`accessTokenTrustedIps.${index}.ipAddress`}
- defaultValue="0.0.0.0/0"
- render={({ field, fieldState: { error } }) => (
- <Field className="flex-1">
- {index === 0 && (
- <FieldLabel htmlFor={`trustedIp-${index}`}>
- Access Token Trusted IPs
- </FieldLabel>
- )}
- <Input
- id={`trustedIp-${index}`}
- value={field.value}
- onChange={(e) => {
- if (subscription?.ipAllowlisting) {
- field.onChange(e);
- return;
- }
- handlePopUpOpen("upgradePlan", {
- featureName: "IP allowlisting"
- });
- }}
- placeholder="123.456.789.0"
- isError={Boolean(error)}
- />
- <FieldError>{error?.message}</FieldError>
- </Field>
- )}
- />
- <IconButton
- type="button"
- variant="ghost"
- size="sm"
- aria-label="Remove trusted IP"
- className={index === 0 ? "mt-[1.625rem]" : "mt-0.5"}
- onClick={() => {
- if (subscription?.ipAllowlisting) {
- removeAccessTokenTrustedIp(index);
- return;
- }
- handlePopUpOpen("upgradePlan", {
- featureName: "IP allowlisting"
- });
- }}
- >
- <XIcon />
- </IconButton>
- </div>
- ))}
- <Button
- type="button"
- variant="outline"
- size="xs"
- className="w-fit"
- onClick={() => {
- if (subscription?.ipAllowlisting) {
- appendAccessTokenTrustedIp({ ipAddress: "0.0.0.0/0" });
- return;
- }
- handlePopUpOpen("upgradePlan", {
- featureName: "IP allowlisting"
- });
- }}
- >
- <PlusIcon />
- Add IP Address
- </Button>
- </div>
+ <TrustedIpsField
+ control={control}
+ name="accessTokenTrustedIps"
+ label="Access Token Trusted IPs"
+ isAllowed={Boolean(subscription?.ipAllowlisting)}
+ onUpgradeRequired={() =>
+ handlePopUpOpen("upgradePlan", { featureName: "IP allowlisting" })
+ }
+ />
</FieldGroup>
</TabsContent>
</Tabs>
diff --git a/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityAwsAuthForm.tsx b/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityAwsAuthForm.tsx
index 15f860d1f1..60d0e4190e 100644
--- a/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityAwsAuthForm.tsx
+++ b/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityAwsAuthForm.tsx
@@ -1,19 +1,17 @@
import { useEffect, useMemo, useState } from "react";
-import { Controller, useFieldArray, useForm } from "react-hook-form";
+import { Controller, useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
import { useParams } from "@tanstack/react-router";
-import { InfoIcon, PlusIcon, XIcon } from "lucide-react";
+import { InfoIcon } from "lucide-react";
import { z } from "zod";
import { createNotification } from "@app/components/notifications";
import {
- Button,
Field,
FieldDescription,
FieldError,
FieldGroup,
FieldLabel,
- IconButton,
Input,
Tabs,
TabsContent,
@@ -25,16 +23,21 @@ import {
} from "@app/components/v3";
import { useOrganization, useSubscription } from "@app/context";
import { SECONDS_PER_DAY } from "@app/helpers/datetime";
-import { accessTokenTtlSchema } from "@app/helpers/identityAuthSchemas";
+import {
+ accessTokenTtlSchema,
+ DEFAULT_TRUSTED_IPS,
+ mapTrustedIpsFromServer,
+ trustedIpsSchema
+} from "@app/helpers/identityAuthSchemas";
import { useScopeVariant } from "@app/hooks";
import {
useAddIdentityAwsAuth,
useGetIdentityAwsAuth,
useUpdateIdentityAwsAuth
} from "@app/hooks/api";
-import { IdentityTrustedIp } from "@app/hooks/api/identities/types";
import { UsePopUpState } from "@app/hooks/usePopUp";
+import { TrustedIpsField } from "./shared/TrustedIpsField";
import { IDENTITY_AUTH_FORM_ID, IdentityFormTab } from "./types";
const buildSchema = (maxAccessTokenTTL: number) =>
@@ -46,12 +49,7 @@ const buildSchema = (maxAccessTokenTTL: number) =>
accessTokenTTL: accessTokenTtlSchema(maxAccessTokenTTL, "Access Token TTL"),
accessTokenMaxTTL: accessTokenTtlSchema(maxAccessTokenTTL, "Access Token Max TTL"),
accessTokenNumUsesLimit: z.string(),
- accessTokenTrustedIps: z
- .object({
- ipAddress: z.string().max(50)
- })
- .array()
- .min(1)
+ accessTokenTrustedIps: trustedIpsSchema
})
.required();
@@ -111,16 +109,10 @@ export const IdentityAwsAuthForm = ({
accessTokenTTL: "2592000",
accessTokenMaxTTL: "2592000",
accessTokenNumUsesLimit: "",
- accessTokenTrustedIps: [{ ipAddress: "0.0.0.0/0" }, { ipAddress: "::/0" }]
+ accessTokenTrustedIps: DEFAULT_TRUSTED_IPS
}
});
- const {
- fields: accessTokenTrustedIpsFields,
- append: appendAccessTokenTrustedIp,
- remove: removeAccessTokenTrustedIp
- } = useFieldArray({ control, name: "accessTokenTrustedIps" });
-
useEffect(() => {
if (data) {
reset({
@@ -132,13 +124,7 @@ export const IdentityAwsAuthForm = ({
accessTokenNumUsesLimit: data.accessTokenNumUsesLimit
? String(data.accessTokenNumUsesLimit)
: "",
- accessTokenTrustedIps: data.accessTokenTrustedIps.map(
- ({ ipAddress, prefix }: IdentityTrustedIp) => {
- return {
- ipAddress: `${ipAddress}${prefix !== undefined ? `/${prefix}` : ""}`
- };
- }
- )
+ accessTokenTrustedIps: mapTrustedIpsFromServer(data.accessTokenTrustedIps)
});
} else {
reset({
@@ -148,7 +134,7 @@ export const IdentityAwsAuthForm = ({
accessTokenTTL: "2592000",
accessTokenMaxTTL: "2592000",
accessTokenNumUsesLimit: "",
- accessTokenTrustedIps: [{ ipAddress: "0.0.0.0/0" }, { ipAddress: "::/0" }]
+ accessTokenTrustedIps: DEFAULT_TRUSTED_IPS
});
}
}, [data]);
@@ -356,78 +342,15 @@ export const IdentityAwsAuthForm = ({
</TabsContent>
<TabsContent value={IdentityFormTab.Advanced}>
<FieldGroup>
- <div className="flex flex-col gap-3">
- {accessTokenTrustedIpsFields.map(({ id }, index) => (
- <div className="flex items-start gap-2" key={id}>
- <Controller
- control={control}
- name={`accessTokenTrustedIps.${index}.ipAddress`}
- defaultValue="0.0.0.0/0"
- render={({ field, fieldState: { error } }) => (
- <Field className="flex-1">
- {index === 0 && (
- <FieldLabel htmlFor={`trustedIp-${index}`}>
- Access Token Trusted IPs
- </FieldLabel>
- )}
- <Input
- id={`trustedIp-${index}`}
- value={field.value}
- onChange={(e) => {
- if (subscription?.ipAllowlisting) {
- field.onChange(e);
- return;
- }
- handlePopUpOpen("upgradePlan", {
- featureName: "IP allowlisting"
- });
- }}
- placeholder="123.456.789.0"
- isError={Boolean(error)}
- />
- <FieldError>{error?.message}</FieldError>
- </Field>
- )}
- />
- <IconButton
- type="button"
- variant="ghost"
- size="sm"
- aria-label="Remove trusted IP"
- className={index === 0 ? "mt-[1.625rem]" : "mt-0.5"}
- onClick={() => {
- if (subscription?.ipAllowlisting) {
- removeAccessTokenTrustedIp(index);
- return;
- }
- handlePopUpOpen("upgradePlan", {
- featureName: "IP allowlisting"
- });
- }}
- >
- <XIcon />
- </IconButton>
- </div>
- ))}
- <Button
- type="button"
- variant="outline"
- size="xs"
- className="w-fit"
- onClick={() => {
- if (subscription?.ipAllowlisting) {
- appendAccessTokenTrustedIp({ ipAddress: "0.0.0.0/0" });
- return;
- }
- handlePopUpOpen("upgradePlan", {
- featureName: "IP allowlisting"
- });
- }}
- >
- <PlusIcon />
- Add IP Address
- </Button>
- </div>
+ <TrustedIpsField
+ control={control}
+ name="accessTokenTrustedIps"
+ label="Access Token Trusted IPs"
+ isAllowed={Boolean(subscription?.ipAllowlisting)}
+ onUpgradeRequired={() =>
+ handlePopUpOpen("upgradePlan", { featureName: "IP allowlisting" })
+ }
+ />
</FieldGroup>
</TabsContent>
</Tabs>
diff --git a/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityAzureAuthForm.tsx b/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityAzureAuthForm.tsx
index 4fdf926515..29a773b950 100644
--- a/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityAzureAuthForm.tsx
+++ b/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityAzureAuthForm.tsx
@@ -1,19 +1,17 @@
import { useEffect, useMemo, useState } from "react";
-import { Controller, useFieldArray, useForm } from "react-hook-form";
+import { Controller, useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
import { useParams } from "@tanstack/react-router";
-import { InfoIcon, PlusIcon, XIcon } from "lucide-react";
+import { InfoIcon } from "lucide-react";
import { z } from "zod";
import { createNotification } from "@app/components/notifications";
import {
- Button,
Field,
FieldDescription,
FieldError,
FieldGroup,
FieldLabel,
- IconButton,
Input,
Tabs,
TabsContent,
@@ -25,16 +23,21 @@ import {
} from "@app/components/v3";
import { useOrganization, useSubscription } from "@app/context";
import { SECONDS_PER_DAY } from "@app/helpers/datetime";
-import { accessTokenTtlSchema } from "@app/helpers/identityAuthSchemas";
+import {
+ accessTokenTtlSchema,
+ DEFAULT_TRUSTED_IPS,
+ mapTrustedIpsFromServer,
+ trustedIpsSchema
+} from "@app/helpers/identityAuthSchemas";
import { useScopeVariant } from "@app/hooks";
import {
useAddIdentityAzureAuth,
useGetIdentityAzureAuth,
useUpdateIdentityAzureAuth
} from "@app/hooks/api";
-import { IdentityTrustedIp } from "@app/hooks/api/identities/types";
import { UsePopUpState } from "@app/hooks/usePopUp";
+import { TrustedIpsField } from "./shared/TrustedIpsField";
import { IDENTITY_AUTH_FORM_ID, IdentityFormTab } from "./types";
const buildSchema = (maxAccessTokenTTL: number) =>
@@ -46,13 +49,7 @@ const buildSchema = (maxAccessTokenTTL: number) =>
accessTokenTTL: accessTokenTtlSchema(maxAccessTokenTTL, "Access Token TTL"),
accessTokenMaxTTL: accessTokenTtlSchema(maxAccessTokenTTL, "Access Token Max TTL"),
accessTokenNumUsesLimit: z.string(),
- accessTokenTrustedIps: z
- .array(
- z.object({
- ipAddress: z.string().max(50)
- })
- )
- .min(1)
+ accessTokenTrustedIps: trustedIpsSchema
})
.required();
@@ -113,16 +110,10 @@ export const IdentityAzureAuthForm = ({
accessTokenTTL: "2592000",
accessTokenMaxTTL: "2592000",
accessTokenNumUsesLimit: "",
- accessTokenTrustedIps: [{ ipAddress: "0.0.0.0/0" }, { ipAddress: "::/0" }]
+ accessTokenTrustedIps: DEFAULT_TRUSTED_IPS
}
});
- const {
- fields: accessTokenTrustedIpsFields,
- append: appendAccessTokenTrustedIp,
- remove: removeAccessTokenTrustedIp
- } = useFieldArray({ control, name: "accessTokenTrustedIps" });
-
useEffect(() => {
if (data) {
reset({
@@ -134,13 +125,7 @@ export const IdentityAzureAuthForm = ({
accessTokenNumUsesLimit: data.accessTokenNumUsesLimit
? String(data.accessTokenNumUsesLimit)
: "",
- accessTokenTrustedIps: data.accessTokenTrustedIps.map(
- ({ ipAddress, prefix }: IdentityTrustedIp) => {
- return {
- ipAddress: `${ipAddress}${prefix !== undefined ? `/${prefix}` : ""}`
- };
- }
- )
+ accessTokenTrustedIps: mapTrustedIpsFromServer(data.accessTokenTrustedIps)
});
} else {
reset({
@@ -150,7 +135,7 @@ export const IdentityAzureAuthForm = ({
accessTokenTTL: "2592000",
accessTokenMaxTTL: "2592000",
accessTokenNumUsesLimit: "",
- accessTokenTrustedIps: [{ ipAddress: "0.0.0.0/0" }, { ipAddress: "::/0" }]
+ accessTokenTrustedIps: DEFAULT_TRUSTED_IPS
});
}
}, [data]);
@@ -360,78 +345,15 @@ export const IdentityAzureAuthForm = ({
</TabsContent>
<TabsContent value={IdentityFormTab.Advanced}>
<FieldGroup>
- <div className="flex flex-col gap-3">
- {accessTokenTrustedIpsFields.map(({ id }, index) => (
- <div className="flex items-start gap-2" key={id}>
- <Controller
- control={control}
- name={`accessTokenTrustedIps.${index}.ipAddress`}
- defaultValue="0.0.0.0/0"
- render={({ field, fieldState: { error } }) => (
- <Field className="flex-1">
- {index === 0 && (
- <FieldLabel htmlFor={`trustedIp-${index}`}>
- Access Token Trusted IPs
- </FieldLabel>
- )}
- <Input
- id={`trustedIp-${index}`}
- value={field.value}
- onChange={(e) => {
- if (subscription?.ipAllowlisting) {
- field.onChange(e);
- return;
- }
- handlePopUpOpen("upgradePlan", {
- featureName: "IP allowlisting"
- });
- }}
- placeholder="123.456.789.0"
- isError={Boolean(error)}
- />
- <FieldError>{error?.message}</FieldError>
- </Field>
- )}
- />
- <IconButton
- type="button"
- variant="ghost"
- size="sm"
- aria-label="Remove trusted IP"
- className={index === 0 ? "mt-[1.625rem]" : "mt-0.5"}
- onClick={() => {
- if (subscription?.ipAllowlisting) {
- removeAccessTokenTrustedIp(index);
- return;
- }
- handlePopUpOpen("upgradePlan", {
- featureName: "IP allowlisting"
- });
- }}
- >
- <XIcon />
- </IconButton>
- </div>
- ))}
- <Button
- type="button"
- variant="outline"
- size="xs"
- className="w-fit"
- onClick={() => {
- if (subscription?.ipAllowlisting) {
- appendAccessTokenTrustedIp({ ipAddress: "0.0.0.0/0" });
- return;
- }
- handlePopUpOpen("upgradePlan", {
- featureName: "IP allowlisting"
- });
- }}
- >
- <PlusIcon />
- Add IP Address
- </Button>
- </div>
+ <TrustedIpsField
+ control={control}
+ name="accessTokenTrustedIps"
+ label="Access Token Trusted IPs"
+ isAllowed={Boolean(subscription?.ipAllowlisting)}
+ onUpgradeRequired={() =>
+ handlePopUpOpen("upgradePlan", { featureName: "IP allowlisting" })
+ }
+ />
</FieldGroup>
</TabsContent>
</Tabs>
diff --git a/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityGcpAuthForm.tsx b/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityGcpAuthForm.tsx
index b241f55a4a..2135af6501 100644
--- a/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityGcpAuthForm.tsx
+++ b/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityGcpAuthForm.tsx
@@ -1,19 +1,17 @@
import { useEffect, useMemo, useState } from "react";
-import { Controller, useFieldArray, useForm } from "react-hook-form";
+import { Controller, useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
import { useParams } from "@tanstack/react-router";
-import { InfoIcon, PlusIcon, XIcon } from "lucide-react";
+import { InfoIcon } from "lucide-react";
import { z } from "zod";
import { createNotification } from "@app/components/notifications";
import {
- Button,
Field,
FieldDescription,
FieldError,
FieldGroup,
FieldLabel,
- IconButton,
Input,
Select,
SelectContent,
@@ -30,16 +28,21 @@ import {
} from "@app/components/v3";
import { useOrganization, useSubscription } from "@app/context";
import { SECONDS_PER_DAY } from "@app/helpers/datetime";
-import { accessTokenTtlSchema } from "@app/helpers/identityAuthSchemas";
+import {
+ accessTokenTtlSchema,
+ DEFAULT_TRUSTED_IPS,
+ mapTrustedIpsFromServer,
+ trustedIpsSchema
+} from "@app/helpers/identityAuthSchemas";
import { useScopeVariant } from "@app/hooks";
import {
useAddIdentityGcpAuth,
useGetIdentityGcpAuth,
useUpdateIdentityGcpAuth
} from "@app/hooks/api";
-import { IdentityTrustedIp } from "@app/hooks/api/identities/types";
import { UsePopUpState } from "@app/hooks/usePopUp";
+import { TrustedIpsField } from "./shared/TrustedIpsField";
import { IDENTITY_AUTH_FORM_ID, IdentityFormTab } from "./types";
const buildSchema = (maxAccessTokenTTL: number) =>
@@ -52,13 +55,7 @@ const buildSchema = (maxAccessTokenTTL: number) =>
accessTokenTTL: accessTokenTtlSchema(maxAccessTokenTTL, "Access Token TTL"),
accessTokenMaxTTL: accessTokenTtlSchema(maxAccessTokenTTL, "Access Token Max TTL"),
accessTokenNumUsesLimit: z.string(),
- accessTokenTrustedIps: z
- .array(
- z.object({
- ipAddress: z.string().max(50)
- })
- )
- .min(1)
+ accessTokenTrustedIps: trustedIpsSchema
})
.required();
@@ -120,18 +117,12 @@ export const IdentityGcpAuthForm = ({
accessTokenTTL: "2592000",
accessTokenMaxTTL: "2592000",
accessTokenNumUsesLimit: "",
- accessTokenTrustedIps: [{ ipAddress: "0.0.0.0/0" }, { ipAddress: "::/0" }]
+ accessTokenTrustedIps: DEFAULT_TRUSTED_IPS
}
});
const watchedType = watch("type");
- const {
- fields: accessTokenTrustedIpsFields,
- append: appendAccessTokenTrustedIp,
- remove: removeAccessTokenTrustedIp
- } = useFieldArray({ control, name: "accessTokenTrustedIps" });
-
useEffect(() => {
if (data) {
reset({
@@ -144,13 +135,7 @@ export const IdentityGcpAuthForm = ({
accessTokenNumUsesLimit: data.accessTokenNumUsesLimit
? String(data.accessTokenNumUsesLimit)
: "",
- accessTokenTrustedIps: data.accessTokenTrustedIps.map(
- ({ ipAddress, prefix }: IdentityTrustedIp) => {
- return {
- ipAddress: `${ipAddress}${prefix !== undefined ? `/${prefix}` : ""}`
- };
- }
- )
+ accessTokenTrustedIps: mapTrustedIpsFromServer(data.accessTokenTrustedIps)
});
} else {
reset({
@@ -161,7 +146,7 @@ export const IdentityGcpAuthForm = ({
accessTokenTTL: "2592000",
accessTokenMaxTTL: "2592000",
accessTokenNumUsesLimit: "",
- accessTokenTrustedIps: [{ ipAddress: "0.0.0.0/0" }, { ipAddress: "::/0" }]
+ accessTokenTrustedIps: DEFAULT_TRUSTED_IPS
});
}
}, [data]);
@@ -400,78 +385,15 @@ export const IdentityGcpAuthForm = ({
</TabsContent>
<TabsContent value={IdentityFormTab.Advanced}>
<FieldGroup>
- <div className="flex flex-col gap-3">
- {accessTokenTrustedIpsFields.map(({ id }, index) => (
- <div className="flex items-start gap-2" key={id}>
- <Controller
- control={control}
- name={`accessTokenTrustedIps.${index}.ipAddress`}
- defaultValue="0.0.0.0/0"
- render={({ field, fieldState: { error } }) => (
- <Field className="flex-1">
- {index === 0 && (
- <FieldLabel htmlFor={`trustedIp-${index}`}>
- Access Token Trusted IPs
- </FieldLabel>
- )}
- <Input
- id={`trustedIp-${index}`}
- value={field.value}
- onChange={(e) => {
- if (subscription?.ipAllowlisting) {
- field.onChange(e);
- return;
- }
- handlePopUpOpen("upgradePlan", {
- featureName: "IP allowlisting"
- });
- }}
- placeholder="123.456.789.0"
- isError={Boolean(error)}
- />
- <FieldError>{error?.message}</FieldError>
- </Field>
- )}
- />
- <IconButton
- type="button"
- variant="ghost"
- size="sm"
- aria-label="Remove trusted IP"
- className={index === 0 ? "mt-[1.625rem]" : "mt-0.5"}
- onClick={() => {
- if (subscription?.ipAllowlisting) {
- removeAccessTokenTrustedIp(index);
- return;
- }
- handlePopUpOpen("upgradePlan", {
- featureName: "IP allowlisting"
- });
- }}
- >
- <XIcon />
- </IconButton>
- </div>
- ))}
- <Button
- type="button"
- variant="outline"
- size="xs"
- className="w-fit"
- onClick={() => {
- if (subscription?.ipAllowlisting) {
- appendAccessTokenTrustedIp({ ipAddress: "0.0.0.0/0" });
- return;
- }
- handlePopUpOpen("upgradePlan", {
- featureName: "IP allowlisting"
- });
- }}
- >
- <PlusIcon />
- Add IP Address
- </Button>
- </div>
+ <TrustedIpsField
+ control={control}
+ name="accessTokenTrustedIps"
+ label="Access Token Trusted IPs"
+ isAllowed={Boolean(subscription?.ipAllowlisting)}
+ onUpgradeRequired={() =>
+ handlePopUpOpen("upgradePlan", { featureName: "IP allowlisting" })
+ }
+ />
</FieldGroup>
</TabsContent>
</Tabs>
diff --git a/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityJwtAuthForm.tsx b/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityJwtAuthForm.tsx
index 2f80997a4e..9fbeee5e5f 100644
--- a/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityJwtAuthForm.tsx
+++ b/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityJwtAuthForm.tsx
@@ -32,25 +32,24 @@ import {
} from "@app/components/v3";
import { useOrganization, useSubscription } from "@app/context";
import { SECONDS_PER_DAY } from "@app/helpers/datetime";
-import { accessTokenTtlSchema } from "@app/helpers/identityAuthSchemas";
+import {
+ accessTokenTtlSchema,
+ DEFAULT_TRUSTED_IPS,
+ mapTrustedIpsFromServer,
+ trustedIpsSchema
+} from "@app/helpers/identityAuthSchemas";
import { useScopeVariant } from "@app/hooks";
import { useAddIdentityJwtAuth, useUpdateIdentityJwtAuth } from "@app/hooks/api";
import { IdentityJwtConfigurationType } from "@app/hooks/api/identities/enums";
import { useGetIdentityJwtAuth } from "@app/hooks/api/identities/queries";
-import { IdentityTrustedIp } from "@app/hooks/api/identities/types";
import { UsePopUpState } from "@app/hooks/usePopUp";
+import { TrustedIpsField } from "./shared/TrustedIpsField";
import { IDENTITY_AUTH_FORM_ID, IdentityFormTab } from "./types";
const buildSchema = (maxAccessTokenTTL: number) => {
const common = z.object({
- accessTokenTrustedIps: z
- .array(
- z.object({
- ipAddress: z.string().max(50)
- })
- )
- .min(1),
+ accessTokenTrustedIps: trustedIpsSchema,
accessTokenTTL: accessTokenTtlSchema(maxAccessTokenTTL, "Access Token TTL"),
accessTokenMaxTTL: accessTokenTtlSchema(maxAccessTokenTTL, "Access Token Max TTL"),
accessTokenNumUsesLimit: z.string(),
@@ -150,7 +149,7 @@ export const IdentityJwtAuthForm = ({
accessTokenTTL: "2592000",
accessTokenMaxTTL: "2592000",
accessTokenNumUsesLimit: "",
- accessTokenTrustedIps: [{ ipAddress: "0.0.0.0/0" }, { ipAddress: "::/0" }],
+ accessTokenTrustedIps: DEFAULT_TRUSTED_IPS,
configurationType: IdentityJwtConfigurationType.JWKS
}
});
@@ -175,12 +174,6 @@ export const IdentityJwtAuthForm = ({
name: "boundClaims"
});
- const {
- fields: accessTokenTrustedIpsFields,
- append: appendAccessTokenTrustedIp,
- remove: removeAccessTokenTrustedIp
- } = useFieldArray({ control, name: "accessTokenTrustedIps" });
-
useEffect(() => {
if (data) {
reset({
@@ -202,13 +195,7 @@ export const IdentityJwtAuthForm = ({
accessTokenNumUsesLimit: data.accessTokenNumUsesLimit
? String(data.accessTokenNumUsesLimit)
: "",
- accessTokenTrustedIps: data.accessTokenTrustedIps.map(
- ({ ipAddress, prefix }: IdentityTrustedIp) => {
- return {
- ipAddress: `${ipAddress}${prefix !== undefined ? `/${prefix}` : ""}`
- };
- }
- )
+ accessTokenTrustedIps: mapTrustedIpsFromServer(data.accessTokenTrustedIps)
});
} else {
reset({
@@ -222,7 +209,7 @@ export const IdentityJwtAuthForm = ({
accessTokenTTL: "2592000",
accessTokenMaxTTL: "2592000",
accessTokenNumUsesLimit: "",
- accessTokenTrustedIps: [{ ipAddress: "0.0.0.0/0" }, { ipAddress: "::/0" }]
+ accessTokenTrustedIps: DEFAULT_TRUSTED_IPS
});
}
}, [data]);
@@ -683,78 +670,15 @@ export const IdentityJwtAuthForm = ({
</TabsContent>
<TabsContent value={IdentityFormTab.Advanced}>
<FieldGroup>
- <div className="flex flex-col gap-3">
- {accessTokenTrustedIpsFields.map(({ id }, index) => (
- <div className="flex items-start gap-2" key={id}>
- <Controller
- control={control}
- name={`accessTokenTrustedIps.${index}.ipAddress`}
- defaultValue="0.0.0.0/0"
- render={({ field, fieldState: { error } }) => (
- <Field className="flex-1">
- {index === 0 && (
- <FieldLabel htmlFor={`trustedIp-${index}`}>
- Access Token Trusted IPs
- </FieldLabel>
- )}
- <Input
- id={`trustedIp-${index}`}
- value={field.value}
- onChange={(e) => {
- if (subscription?.ipAllowlisting) {
- field.onChange(e);
- return;
- }
- handlePopUpOpen("upgradePlan", {
- featureName: "IP allowlisting"
- });
- }}
- placeholder="123.456.789.0"
- isError={Boolean(error)}
- />
- <FieldError>{error?.message}</FieldError>
- </Field>
- )}
- />
- <IconButton
- type="button"
- variant="ghost"
- size="sm"
- aria-label="Remove trusted IP"
- className={index === 0 ? "mt-[1.625rem]" : "mt-0.5"}
- onClick={() => {
- if (subscription?.ipAllowlisting) {
- removeAccessTokenTrustedIp(index);
- return;
- }
- handlePopUpOpen("upgradePlan", {
- featureName: "IP allowlisting"
- });
- }}
- >
- <XIcon />
- </IconButton>
- </div>
- ))}
- <Button
- type="button"
- variant="outline"
- size="xs"
- className="w-fit"
- onClick={() => {
- if (subscription?.ipAllowlisting) {
- appendAccessTokenTrustedIp({ ipAddress: "0.0.0.0/0" });
- return;
- }
- handlePopUpOpen("upgradePlan", {
- featureName: "IP allowlisting"
- });
- }}
- >
- <PlusIcon />
- Add IP Address
- </Button>
- </div>
+ <TrustedIpsField
+ control={control}
+ name="accessTokenTrustedIps"
+ label="Access Token Trusted IPs"
+ isAllowed={Boolean(subscription?.ipAllowlisting)}
+ onUpgradeRequired={() =>
+ handlePopUpOpen("upgradePlan", { featureName: "IP allowlisting" })
+ }
+ />
</FieldGroup>
</TabsContent>
</Tabs>
diff --git a/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityKubernetesAuthForm.tsx b/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityKubernetesAuthForm.tsx
index 227bd123b2..5294a4eb3b 100644
--- a/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityKubernetesAuthForm.tsx
+++ b/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityKubernetesAuthForm.tsx
@@ -1,8 +1,8 @@
import { useEffect, useMemo, useState } from "react";
-import { Controller, useFieldArray, useForm } from "react-hook-form";
+import { Controller, useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
import { useParams } from "@tanstack/react-router";
-import { HelpCircleIcon, InfoIcon, PlusIcon, XIcon } from "lucide-react";
+import { HelpCircleIcon, InfoIcon } from "lucide-react";
import { z } from "zod";
import { createNotification } from "@app/components/notifications";
@@ -15,7 +15,6 @@ import {
FieldGroup,
FieldLabel,
GatewayPicker,
- IconButton,
Input,
Select,
SelectContent,
@@ -38,7 +37,12 @@ import {
OrgPermissionSubjects
} from "@app/context/OrgPermissionContext/types";
import { SECONDS_PER_DAY } from "@app/helpers/datetime";
-import { accessTokenTtlSchema } from "@app/helpers/identityAuthSchemas";
+import {
+ accessTokenTtlSchema,
+ DEFAULT_TRUSTED_IPS,
+ mapTrustedIpsFromServer,
+ trustedIpsSchema
+} from "@app/helpers/identityAuthSchemas";
import { useScopeVariant } from "@app/hooks";
import {
useAddIdentityKubernetesAuth,
@@ -50,14 +54,12 @@ import {
useListAppConnections,
useListAvailableAppConnections
} from "@app/hooks/api/appConnections/queries";
-import {
- IdentityKubernetesAuthTokenReviewMode,
- IdentityTrustedIp
-} from "@app/hooks/api/identities/types";
+import { IdentityKubernetesAuthTokenReviewMode } from "@app/hooks/api/identities/types";
import { VaultKubernetesAuthRole } from "@app/hooks/api/migration/types";
import { useCanUseOrgAppConnectionImport } from "@app/hooks/useCanUseAppConnectionImport";
import { usePopUp, UsePopUpState } from "@app/hooks/usePopUp";
+import { TrustedIpsField } from "./shared/TrustedIpsField";
import { IDENTITY_AUTH_FORM_ID, IdentityFormTab } from "./types";
import { VaultKubernetesAuthImportModal } from "./VaultKubernetesAuthImportModal";
@@ -79,13 +81,7 @@ const buildSchema = (maxAccessTokenTTL: number) =>
accessTokenTTL: accessTokenTtlSchema(maxAccessTokenTTL, "Access Token TTL"),
accessTokenMaxTTL: accessTokenTtlSchema(maxAccessTokenTTL, "Access Token Max TTL"),
accessTokenNumUsesLimit: z.string(),
- accessTokenTrustedIps: z
- .array(
- z.object({
- ipAddress: z.string().max(50)
- })
- )
- .min(1)
+ accessTokenTrustedIps: trustedIpsSchema
})
.superRefine((data, ctx) => {
if (
@@ -221,16 +217,10 @@ export const IdentityKubernetesAuthForm = ({
accessTokenTTL: "2592000",
accessTokenMaxTTL: "2592000",
accessTokenNumUsesLimit: "",
- accessTokenTrustedIps: [{ ipAddress: "0.0.0.0/0" }, { ipAddress: "::/0" }]
+ accessTokenTrustedIps: DEFAULT_TRUSTED_IPS
}
});
- const {
- fields: accessTokenTrustedIpsFields,
- append: appendAccessTokenTrustedIp,
- remove: removeAccessTokenTrustedIp
- } = useFieldArray({ control, name: "accessTokenTrustedIps" });
-
useEffect(() => {
if (data) {
reset({
@@ -249,13 +239,7 @@ export const IdentityKubernetesAuthForm = ({
accessTokenNumUsesLimit: data.accessTokenNumUsesLimit
? String(data.accessTokenNumUsesLimit)
: "",
- accessTokenTrustedIps: data.accessTokenTrustedIps.map(
- ({ ipAddress, prefix }: IdentityTrustedIp) => {
- return {
- ipAddress: `${ipAddress}${prefix !== undefined ? `/${prefix}` : ""}`
- };
- }
- )
+ accessTokenTrustedIps: mapTrustedIpsFromServer(data.accessTokenTrustedIps)
});
} else {
reset({
@@ -270,7 +254,7 @@ export const IdentityKubernetesAuthForm = ({
accessTokenTTL: "2592000",
accessTokenMaxTTL: "2592000",
accessTokenNumUsesLimit: "",
- accessTokenTrustedIps: [{ ipAddress: "0.0.0.0/0" }, { ipAddress: "::/0" }]
+ accessTokenTrustedIps: DEFAULT_TRUSTED_IPS
});
}
}, [data]);
@@ -1000,91 +984,16 @@ export const IdentityKubernetesAuthForm = ({
/>
</>
)}
- <div className="flex flex-col gap-3">
- {accessTokenTrustedIpsFields.map(({ id }, index) => (
- <div className="flex items-start gap-2" key={id}>
- <Controller
- control={control}
- name={`accessTokenTrustedIps.${index}.ipAddress`}
- defaultValue="0.0.0.0/0"
- render={({ field, fieldState: { error } }) => (
- <Field className="flex-1">
- {index === 0 && (
- <FieldLabel
- htmlFor={`trustedIp-${index}`}
- className="inline-flex items-center gap-1.5"
- >
- Access Token Trusted IPs
- <Tooltip>
- <TooltipTrigger asChild>
- <InfoIcon className="size-3.5 text-muted" />
- </TooltipTrigger>
- <TooltipContent>
- The IPs or CIDR ranges that access tokens can be used from. By
- default, each token is given the 0.0.0.0/0, allowing usage from any
- network address.
- </TooltipContent>
- </Tooltip>
- </FieldLabel>
- )}
- <Input
- id={`trustedIp-${index}`}
- value={field.value}
- onChange={(e) => {
- if (subscription?.ipAllowlisting) {
- field.onChange(e);
- return;
- }
- handlePopUpOpen("upgradePlan", {
- featureName: "IP allowlisting"
- });
- }}
- placeholder="123.456.789.0"
- isError={Boolean(error)}
- />
- <FieldError>{error?.message}</FieldError>
- </Field>
- )}
- />
- <IconButton
- type="button"
- variant="ghost"
- size="sm"
- aria-label="Remove trusted IP"
- className={index === 0 ? "mt-[1.625rem]" : "mt-0.5"}
- onClick={() => {
- if (subscription?.ipAllowlisting) {
- removeAccessTokenTrustedIp(index);
- return;
- }
- handlePopUpOpen("upgradePlan", {
- featureName: "IP allowlisting"
- });
- }}
- >
- <XIcon />
- </IconButton>
- </div>
- ))}
- <Button
- type="button"
- variant="outline"
- size="xs"
- className="w-fit"
- onClick={() => {
- if (subscription?.ipAllowlisting) {
- appendAccessTokenTrustedIp({ ipAddress: "0.0.0.0/0" });
- return;
- }
- handlePopUpOpen("upgradePlan", {
- featureName: "IP allowlisting"
- });
- }}
- >
- <PlusIcon />
- Add IP Address
- </Button>
- </div>
+ <TrustedIpsField
+ control={control}
+ name="accessTokenTrustedIps"
+ label="Access Token Trusted IPs"
+ isAllowed={Boolean(subscription?.ipAllowlisting)}
+ onUpgradeRequired={() =>
+ handlePopUpOpen("upgradePlan", { featureName: "IP allowlisting" })
+ }
+ tooltip="The IPs or CIDR ranges that access tokens can be used from. By default, each token is given the 0.0.0.0/0, allowing usage from any network address."
+ />
</FieldGroup>
</TabsContent>
</Tabs>
diff --git a/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityLdapAuthForm.tsx b/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityLdapAuthForm.tsx
index eb0ba4f7b4..a4416c6203 100644
--- a/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityLdapAuthForm.tsx
+++ b/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityLdapAuthForm.tsx
@@ -36,7 +36,12 @@ import {
OrgPermissionSubjects
} from "@app/context/OrgPermissionContext/types";
import { getObjectFromSeconds, SECONDS_PER_DAY } from "@app/helpers/datetime";
-import { accessTokenTtlSchema } from "@app/helpers/identityAuthSchemas";
+import {
+ accessTokenTtlSchema,
+ DEFAULT_TRUSTED_IPS,
+ mapTrustedIpsFromServer,
+ trustedIpsSchema
+} from "@app/helpers/identityAuthSchemas";
import { useScopeVariant } from "@app/hooks";
import {
MachineIdentityAuthMethod,
@@ -44,12 +49,12 @@ import {
useGetIdentityLdapAuth,
useUpdateIdentityLdapAuth
} from "@app/hooks/api";
-import { IdentityTrustedIp } from "@app/hooks/api/identities/types";
import { useGetAvailableTemplates } from "@app/hooks/api/identityAuthTemplates/queries";
import { UsePopUpState } from "@app/hooks/usePopUp";
import { LockoutTab } from "./lockout/LockoutTab";
import { superRefineLockout } from "./lockout/super-refine";
+import { TrustedIpsField } from "./shared/TrustedIpsField";
import { IDENTITY_AUTH_FORM_ID, IdentityFormTab } from "./types";
const buildSchema = (maxAccessTokenTTL: number) =>
@@ -80,13 +85,7 @@ const buildSchema = (maxAccessTokenTTL: number) =>
accessTokenTTL: accessTokenTtlSchema(maxAccessTokenTTL, "Access Token TTL"),
accessTokenMaxTTL: accessTokenTtlSchema(maxAccessTokenTTL, "Access Token Max TTL"),
accessTokenNumUsesLimit: z.string(),
- accessTokenTrustedIps: z
- .array(
- z.object({
- ipAddress: z.string().max(50)
- })
- )
- .min(1),
+ accessTokenTrustedIps: trustedIpsSchema,
lockoutEnabled: z.boolean().default(true),
lockoutThreshold: z
@@ -221,7 +220,7 @@ export const IdentityLdapAuthForm = ({
accessTokenTTL: "2592000",
accessTokenMaxTTL: "2592000",
accessTokenNumUsesLimit: "",
- accessTokenTrustedIps: [{ ipAddress: "0.0.0.0/0" }, { ipAddress: "::/0" }],
+ accessTokenTrustedIps: DEFAULT_TRUSTED_IPS,
lockoutEnabled: true,
lockoutThreshold: "3",
lockoutDurationValue: "5",
@@ -240,12 +239,6 @@ export const IdentityLdapAuthForm = ({
const lockoutCounterResetValueWatch = watch("lockoutCounterResetValue");
const lockoutCounterResetUnitWatch = watch("lockoutCounterResetUnit");
- const {
- fields: accessTokenTrustedIpsFields,
- append: appendAccessTokenTrustedIp,
- remove: removeAccessTokenTrustedIp
- } = useFieldArray({ control, name: "accessTokenTrustedIps" });
-
const {
fields: allowedFieldsFields,
append: appendAllowedField,
@@ -284,13 +277,7 @@ export const IdentityLdapAuthForm = ({
accessTokenNumUsesLimit: data.accessTokenNumUsesLimit
? String(data.accessTokenNumUsesLimit)
: "",
- accessTokenTrustedIps: data.accessTokenTrustedIps.map(
- ({ ipAddress, prefix }: IdentityTrustedIp) => {
- return {
- ipAddress: `${ipAddress}${prefix !== undefined ? `/${prefix}` : ""}`
- };
- }
- ),
+ accessTokenTrustedIps: mapTrustedIpsFromServer(data.accessTokenTrustedIps),
lockoutEnabled: data.lockoutEnabled,
lockoutThreshold: String(data.lockoutThreshold),
lockoutDurationValue: String(lockoutDurationObj.value),
@@ -314,7 +301,7 @@ export const IdentityLdapAuthForm = ({
accessTokenTTL: "2592000",
accessTokenMaxTTL: "2592000",
accessTokenNumUsesLimit: "",
- accessTokenTrustedIps: [{ ipAddress: "0.0.0.0/0" }, { ipAddress: "::/0" }],
+ accessTokenTrustedIps: DEFAULT_TRUSTED_IPS,
lockoutEnabled: true,
lockoutThreshold: "3",
lockoutDurationValue: "5",
@@ -915,91 +902,16 @@ export const IdentityLdapAuthForm = ({
)}
/>
- <div className="flex flex-col gap-3">
- {accessTokenTrustedIpsFields.map(({ id }, index) => (
- <div className="flex items-start gap-2" key={id}>
- <Controller
- control={control}
- name={`accessTokenTrustedIps.${index}.ipAddress`}
- defaultValue="0.0.0.0/0"
- render={({ field, fieldState: { error } }) => (
- <Field className="flex-1">
- {index === 0 && (
- <FieldLabel
- htmlFor={`trustedIp-${index}`}
- className="inline-flex items-center gap-1.5"
- >
- Access Token Trusted IPs
- <Tooltip>
- <TooltipTrigger asChild>
- <InfoIcon className="size-3.5 text-muted" />
- </TooltipTrigger>
- <TooltipContent>
- The IPs or CIDR ranges that access tokens can be used from. By
- default, each token is given the 0.0.0.0/0, allowing usage from any
- network address.
- </TooltipContent>
- </Tooltip>
- </FieldLabel>
- )}
- <Input
- id={`trustedIp-${index}`}
- value={field.value}
- onChange={(e) => {
- if (subscription?.ipAllowlisting) {
- field.onChange(e);
- return;
- }
- handlePopUpOpen("upgradePlan", {
- featureName: "IP allowlisting"
- });
- }}
- placeholder="123.456.789.0"
- isError={Boolean(error)}
- />
- <FieldError>{error?.message}</FieldError>
- </Field>
- )}
- />
- <IconButton
- type="button"
- variant="ghost"
- size="sm"
- aria-label="Remove trusted IP"
- className={index === 0 ? "mt-[1.625rem]" : "mt-0.5"}
- onClick={() => {
- if (subscription?.ipAllowlisting) {
- removeAccessTokenTrustedIp(index);
- return;
- }
- handlePopUpOpen("upgradePlan", {
- featureName: "IP allowlisting"
- });
- }}
- >
- <XIcon />
- </IconButton>
- </div>
- ))}
- <Button
- type="button"
- variant="outline"
- size="xs"
- className="w-fit"
- onClick={() => {
- if (subscription?.ipAllowlisting) {
- appendAccessTokenTrustedIp({ ipAddress: "0.0.0.0/0" });
- return;
- }
- handlePopUpOpen("upgradePlan", {
- featureName: "IP allowlisting"
- });
- }}
- >
- <PlusIcon />
- Add IP Address
- </Button>
- </div>
+ <TrustedIpsField
+ control={control}
+ name="accessTokenTrustedIps"
+ label="Access Token Trusted IPs"
+ isAllowed={Boolean(subscription?.ipAllowlisting)}
+ onUpgradeRequired={() =>
+ handlePopUpOpen("upgradePlan", { featureName: "IP allowlisting" })
+ }
+ tooltip="The IPs or CIDR ranges that access tokens can be used from. By default, each token is given the 0.0.0.0/0, allowing usage from any network address."
+ />
</FieldGroup>
</TabsContent>
</Tabs>
diff --git a/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityOciAuthForm.tsx b/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityOciAuthForm.tsx
index 1f68ae4dc6..8443b4f4b1 100644
--- a/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityOciAuthForm.tsx
+++ b/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityOciAuthForm.tsx
@@ -1,19 +1,17 @@
import { useEffect, useMemo, useState } from "react";
-import { Controller, useFieldArray, useForm } from "react-hook-form";
+import { Controller, useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
import { useParams } from "@tanstack/react-router";
-import { InfoIcon, PlusIcon, XIcon } from "lucide-react";
+import { InfoIcon } from "lucide-react";
import { z } from "zod";
import { createNotification } from "@app/components/notifications";
import {
- Button,
Field,
FieldDescription,
FieldError,
FieldGroup,
FieldLabel,
- IconButton,
Input,
Tabs,
TabsContent,
@@ -25,16 +23,21 @@ import {
} from "@app/components/v3";
import { useOrganization, useSubscription } from "@app/context";
import { SECONDS_PER_DAY } from "@app/helpers/datetime";
-import { accessTokenTtlSchema } from "@app/helpers/identityAuthSchemas";
+import {
+ accessTokenTtlSchema,
+ DEFAULT_TRUSTED_IPS,
+ mapTrustedIpsFromServer,
+ trustedIpsSchema
+} from "@app/helpers/identityAuthSchemas";
import { useScopeVariant } from "@app/hooks";
import {
useAddIdentityOciAuth,
useGetIdentityOciAuth,
useUpdateIdentityOciAuth
} from "@app/hooks/api";
-import { IdentityTrustedIp } from "@app/hooks/api/identities/types";
import { UsePopUpState } from "@app/hooks/usePopUp";
+import { TrustedIpsField } from "./shared/TrustedIpsField";
import { IDENTITY_AUTH_FORM_ID, IdentityFormTab } from "./types";
const buildSchema = (maxAccessTokenTTL: number) =>
@@ -52,12 +55,7 @@ const buildSchema = (maxAccessTokenTTL: number) =>
accessTokenTTL: accessTokenTtlSchema(maxAccessTokenTTL, "Access Token TTL"),
accessTokenMaxTTL: accessTokenTtlSchema(maxAccessTokenTTL, "Access Token Max TTL"),
accessTokenNumUsesLimit: z.string(),
- accessTokenTrustedIps: z
- .object({
- ipAddress: z.string().max(50)
- })
- .array()
- .min(1)
+ accessTokenTrustedIps: trustedIpsSchema
})
.required();
@@ -116,16 +114,10 @@ export const IdentityOciAuthForm = ({
accessTokenTTL: "2592000",
accessTokenMaxTTL: "2592000",
accessTokenNumUsesLimit: "",
- accessTokenTrustedIps: [{ ipAddress: "0.0.0.0/0" }, { ipAddress: "::/0" }]
+ accessTokenTrustedIps: DEFAULT_TRUSTED_IPS
}
});
- const {
- fields: accessTokenTrustedIpsFields,
- append: appendAccessTokenTrustedIp,
- remove: removeAccessTokenTrustedIp
- } = useFieldArray({ control, name: "accessTokenTrustedIps" });
-
useEffect(() => {
if (data) {
reset({
@@ -136,13 +128,7 @@ export const IdentityOciAuthForm = ({
accessTokenNumUsesLimit: data.accessTokenNumUsesLimit
? String(data.accessTokenNumUsesLimit)
: "",
- accessTokenTrustedIps: data.accessTokenTrustedIps.map(
- ({ ipAddress, prefix }: IdentityTrustedIp) => {
- return {
- ipAddress: `${ipAddress}${prefix !== undefined ? `/${prefix}` : ""}`
- };
- }
- )
+ accessTokenTrustedIps: mapTrustedIpsFromServer(data.accessTokenTrustedIps)
});
} else {
reset({
@@ -151,7 +137,7 @@ export const IdentityOciAuthForm = ({
accessTokenTTL: "2592000",
accessTokenMaxTTL: "2592000",
accessTokenNumUsesLimit: "",
- accessTokenTrustedIps: [{ ipAddress: "0.0.0.0/0" }, { ipAddress: "::/0" }]
+ accessTokenTrustedIps: DEFAULT_TRUSTED_IPS
});
}
}, [data]);
@@ -337,78 +323,15 @@ export const IdentityOciAuthForm = ({
</TabsContent>
<TabsContent value={IdentityFormTab.Advanced}>
<FieldGroup>
- <div className="flex flex-col gap-3">
- {accessTokenTrustedIpsFields.map(({ id }, index) => (
- <div className="flex items-start gap-2" key={id}>
- <Controller
- control={control}
- name={`accessTokenTrustedIps.${index}.ipAddress`}
- defaultValue="0.0.0.0/0"
- render={({ field, fieldState: { error } }) => (
- <Field className="flex-1">
- {index === 0 && (
- <FieldLabel htmlFor={`trustedIp-${index}`}>
- Access Token Trusted IPs
- </FieldLabel>
- )}
- <Input
- id={`trustedIp-${index}`}
- value={field.value}
- onChange={(e) => {
- if (subscription?.ipAllowlisting) {
- field.onChange(e);
- return;
- }
- handlePopUpOpen("upgradePlan", {
- featureName: "IP allowlisting"
- });
- }}
- placeholder="123.456.789.0"
- isError={Boolean(error)}
- />
- <FieldError>{error?.message}</FieldError>
- </Field>
- )}
- />
- <IconButton
- type="button"
- variant="ghost"
- size="sm"
- aria-label="Remove trusted IP"
- className={index === 0 ? "mt-[1.625rem]" : "mt-0.5"}
- onClick={() => {
- if (subscription?.ipAllowlisting) {
- removeAccessTokenTrustedIp(index);
- return;
- }
- handlePopUpOpen("upgradePlan", {
- featureName: "IP allowlisting"
- });
- }}
- >
- <XIcon />
- </IconButton>
- </div>
- ))}
- <Button
- type="button"
- variant="outline"
- size="xs"
- className="w-fit"
- onClick={() => {
- if (subscription?.ipAllowlisting) {
- appendAccessTokenTrustedIp({ ipAddress: "0.0.0.0/0" });
- return;
- }
- handlePopUpOpen("upgradePlan", {
- featureName: "IP allowlisting"
- });
- }}
- >
- <PlusIcon />
- Add IP Address
- </Button>
- </div>
+ <TrustedIpsField
+ control={control}
+ name="accessTokenTrustedIps"
+ label="Access Token Trusted IPs"
+ isAllowed={Boolean(subscription?.ipAllowlisting)}
+ onUpgradeRequired={() =>
+ handlePopUpOpen("upgradePlan", { featureName: "IP allowlisting" })
+ }
+ />
</FieldGroup>
</TabsContent>
</Tabs>
diff --git a/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityOidcAuthForm.tsx b/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityOidcAuthForm.tsx
index 9a62a793f8..e051918d2f 100644
--- a/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityOidcAuthForm.tsx
+++ b/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityOidcAuthForm.tsx
@@ -27,24 +27,23 @@ import {
} from "@app/components/v3";
import { useOrganization, useSubscription } from "@app/context";
import { SECONDS_PER_DAY } from "@app/helpers/datetime";
-import { accessTokenTtlSchema } from "@app/helpers/identityAuthSchemas";
+import {
+ accessTokenTtlSchema,
+ DEFAULT_TRUSTED_IPS,
+ mapTrustedIpsFromServer,
+ trustedIpsSchema
+} from "@app/helpers/identityAuthSchemas";
import { useScopeVariant } from "@app/hooks";
import { useAddIdentityOidcAuth, useUpdateIdentityOidcAuth } from "@app/hooks/api";
import { useGetIdentityOidcAuth } from "@app/hooks/api/identities/queries";
-import { IdentityTrustedIp } from "@app/hooks/api/identities/types";
import { UsePopUpState } from "@app/hooks/usePopUp";
+import { TrustedIpsField } from "./shared/TrustedIpsField";
import { IDENTITY_AUTH_FORM_ID, IdentityFormTab } from "./types";
const buildSchema = (maxAccessTokenTTL: number) =>
z.object({
- accessTokenTrustedIps: z
- .array(
- z.object({
- ipAddress: z.string().max(50)
- })
- )
- .min(1),
+ accessTokenTrustedIps: trustedIpsSchema,
accessTokenTTL: accessTokenTtlSchema(maxAccessTokenTTL, "Access Token TTL"),
accessTokenMaxTTL: accessTokenTtlSchema(maxAccessTokenTTL, "Access Token Max TTL"),
accessTokenNumUsesLimit: z.string(),
@@ -131,7 +130,7 @@ export const IdentityOidcAuthForm = ({
accessTokenTTL: "2592000",
accessTokenMaxTTL: "2592000",
accessTokenNumUsesLimit: "",
- accessTokenTrustedIps: [{ ipAddress: "0.0.0.0/0" }, { ipAddress: "::/0" }],
+ accessTokenTrustedIps: DEFAULT_TRUSTED_IPS,
boundClaims: [],
claimMetadataMapping: []
}
@@ -154,12 +153,6 @@ export const IdentityOidcAuthForm = ({
name: "claimMetadataMapping"
});
- const {
- fields: accessTokenTrustedIpsFields,
- append: appendAccessTokenTrustedIp,
- remove: removeAccessTokenTrustedIp
- } = useFieldArray({ control, name: "accessTokenTrustedIps" });
-
useEffect(() => {
if (data) {
reset({
@@ -183,13 +176,7 @@ export const IdentityOidcAuthForm = ({
accessTokenNumUsesLimit: data.accessTokenNumUsesLimit
? String(data.accessTokenNumUsesLimit)
: "",
- accessTokenTrustedIps: data.accessTokenTrustedIps.map(
- ({ ipAddress, prefix }: IdentityTrustedIp) => {
- return {
- ipAddress: `${ipAddress}${prefix !== undefined ? `/${prefix}` : ""}`
- };
- }
- )
+ accessTokenTrustedIps: mapTrustedIpsFromServer(data.accessTokenTrustedIps)
});
} else {
reset({
@@ -202,7 +189,7 @@ export const IdentityOidcAuthForm = ({
accessTokenTTL: "2592000",
accessTokenMaxTTL: "2592000",
accessTokenNumUsesLimit: "",
- accessTokenTrustedIps: [{ ipAddress: "0.0.0.0/0" }, { ipAddress: "::/0" }],
+ accessTokenTrustedIps: DEFAULT_TRUSTED_IPS,
claimMetadataMapping: []
});
}
@@ -661,78 +648,15 @@ export const IdentityOidcAuthForm = ({
</Button>
</div>
- <div className="flex flex-col gap-3">
- {accessTokenTrustedIpsFields.map(({ id }, index) => (
- <div className="flex items-start gap-2" key={id}>
- <Controller
- control={control}
- name={`accessTokenTrustedIps.${index}.ipAddress`}
- defaultValue="0.0.0.0/0"
- render={({ field, fieldState: { error } }) => (
- <Field className="flex-1">
- {index === 0 && (
- <FieldLabel htmlFor={`trustedIp-${index}`}>
- Access Token Trusted IPs
- </FieldLabel>
- )}
- <Input
- id={`trustedIp-${index}`}
- value={field.value}
- onChange={(e) => {
- if (subscription?.ipAllowlisting) {
- field.onChange(e);
- return;
- }
- handlePopUpOpen("upgradePlan", {
- featureName: "IP allowlisting"
- });
- }}
- placeholder="123.456.789.0"
- isError={Boolean(error)}
- />
- <FieldError>{error?.message}</FieldError>
- </Field>
- )}
- />
- <IconButton
- type="button"
- variant="ghost"
- size="sm"
- aria-label="Remove trusted IP"
- className={index === 0 ? "mt-[1.625rem]" : "mt-0.5"}
- onClick={() => {
- if (subscription?.ipAllowlisting) {
- removeAccessTokenTrustedIp(index);
- return;
- }
- handlePopUpOpen("upgradePlan", {
- featureName: "IP allowlisting"
- });
- }}
- >
- <XIcon />
- </IconButton>
- </div>
- ))}
- <Button
- type="button"
- variant="outline"
- size="xs"
- className="w-fit"
- onClick={() => {
- if (subscription?.ipAllowlisting) {
- appendAccessTokenTrustedIp({ ipAddress: "0.0.0.0/0" });
- return;
- }
- handlePopUpOpen("upgradePlan", {
- featureName: "IP allowlisting"
- });
- }}
- >
- <PlusIcon />
- Add IP Address
- </Button>
- </div>
+ <TrustedIpsField
+ control={control}
+ name="accessTokenTrustedIps"
+ label="Access Token Trusted IPs"
+ isAllowed={Boolean(subscription?.ipAllowlisting)}
+ onUpgradeRequired={() =>
+ handlePopUpOpen("upgradePlan", { featureName: "IP allowlisting" })
+ }
+ />
</FieldGroup>
</TabsContent>
</Tabs>
diff --git a/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentitySpiffeAuthForm.tsx b/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentitySpiffeAuthForm.tsx
index efb012683f..c97ee56420 100644
--- a/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentitySpiffeAuthForm.tsx
+++ b/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentitySpiffeAuthForm.tsx
@@ -1,19 +1,17 @@
import { useEffect, useMemo, useState } from "react";
-import { Controller, useFieldArray, useForm } from "react-hook-form";
+import { Controller, useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
import { useParams } from "@tanstack/react-router";
-import { InfoIcon, PlusIcon, XIcon } from "lucide-react";
+import { InfoIcon } from "lucide-react";
import { z } from "zod";
import { createNotification } from "@app/components/notifications";
import {
- Button,
Field,
FieldDescription,
FieldError,
FieldGroup,
FieldLabel,
- IconButton,
Input,
Select,
SelectContent,
@@ -31,14 +29,19 @@ import {
} from "@app/components/v3";
import { useOrganization, useSubscription } from "@app/context";
import { SECONDS_PER_DAY } from "@app/helpers/datetime";
-import { accessTokenTtlSchema } from "@app/helpers/identityAuthSchemas";
+import {
+ accessTokenTtlSchema,
+ DEFAULT_TRUSTED_IPS,
+ mapTrustedIpsFromServer,
+ trustedIpsSchema
+} from "@app/helpers/identityAuthSchemas";
import { useScopeVariant } from "@app/hooks";
import { useAddIdentitySpiffeAuth, useUpdateIdentitySpiffeAuth } from "@app/hooks/api";
import { SpiffeTrustBundleProfile } from "@app/hooks/api/identities/enums";
import { useGetIdentitySpiffeAuth } from "@app/hooks/api/identities/queries";
-import { IdentityTrustedIp } from "@app/hooks/api/identities/types";
import { UsePopUpState } from "@app/hooks/usePopUp";
+import { TrustedIpsField } from "./shared/TrustedIpsField";
import { IDENTITY_AUTH_FORM_ID, IdentityFormTab } from "./types";
const trustBundleDistributionSchema = z.discriminatedUnion("profile", [
@@ -59,13 +62,7 @@ const buildSchema = (maxAccessTokenTTL: number) => {
trustDomain: z.string().trim().min(1, "Trust domain is required"),
allowedSpiffeIds: z.string().trim().min(1, "Allowed SPIFFE IDs are required"),
allowedAudiences: z.string().trim().min(1, "Allowed audiences are required"),
- accessTokenTrustedIps: z
- .array(
- z.object({
- ipAddress: z.string().max(50)
- })
- )
- .min(1),
+ accessTokenTrustedIps: trustedIpsSchema,
accessTokenTTL: accessTokenTtlSchema(maxAccessTokenTTL, "Access Token TTL"),
accessTokenMaxTTL: accessTokenTtlSchema(maxAccessTokenTTL, "Access Token Max TTL"),
accessTokenNumUsesLimit: z.string()
@@ -134,18 +131,12 @@ export const IdentitySpiffeAuthForm = ({
accessTokenTTL: "2592000",
accessTokenMaxTTL: "2592000",
accessTokenNumUsesLimit: "",
- accessTokenTrustedIps: [{ ipAddress: "0.0.0.0/0" }, { ipAddress: "::/0" }]
+ accessTokenTrustedIps: DEFAULT_TRUSTED_IPS
}
});
const selectedProfile = watch("trustBundleDistribution.profile");
- const {
- fields: accessTokenTrustedIpsFields,
- append: appendAccessTokenTrustedIp,
- remove: removeAccessTokenTrustedIp
- } = useFieldArray({ control, name: "accessTokenTrustedIps" });
-
useEffect(() => {
if (data) {
const dist = data.trustBundleDistribution;
@@ -183,13 +174,7 @@ export const IdentitySpiffeAuthForm = ({
accessTokenNumUsesLimit: data.accessTokenNumUsesLimit
? String(data.accessTokenNumUsesLimit)
: "",
- accessTokenTrustedIps: data.accessTokenTrustedIps.map(
- ({ ipAddress, prefix }: IdentityTrustedIp) => {
- return {
- ipAddress: `${ipAddress}${prefix !== undefined ? `/${prefix}` : ""}`
- };
- }
- )
+ accessTokenTrustedIps: mapTrustedIpsFromServer(data.accessTokenTrustedIps)
});
}
}, [data]);
@@ -524,78 +509,15 @@ export const IdentitySpiffeAuthForm = ({
</TabsContent>
<TabsContent value={IdentityFormTab.Advanced}>
<FieldGroup>
- <div className="flex flex-col gap-3">
- {accessTokenTrustedIpsFields.map(({ id }, index) => (
- <div className="flex items-start gap-2" key={id}>
- <Controller
- control={control}
- name={`accessTokenTrustedIps.${index}.ipAddress`}
- defaultValue="0.0.0.0/0"
- render={({ field, fieldState: { error } }) => (
- <Field className="flex-1">
- {index === 0 && (
- <FieldLabel htmlFor={`trustedIp-${index}`}>
- Access Token Trusted IPs
- </FieldLabel>
- )}
- <Input
- id={`trustedIp-${index}`}
- value={field.value}
- onChange={(e) => {
- if (subscription?.ipAllowlisting) {
- field.onChange(e);
- return;
- }
- handlePopUpOpen("upgradePlan", {
- featureName: "IP allowlisting"
- });
- }}
- placeholder="123.456.789.0"
- isError={Boolean(error)}
- />
- <FieldError>{error?.message}</FieldError>
- </Field>
- )}
- />
- <IconButton
- type="button"
- variant="ghost"
- size="sm"
- aria-label="Remove trusted IP"
- className={index === 0 ? "mt-[1.625rem]" : "mt-0.5"}
- onClick={() => {
- if (subscription?.ipAllowlisting) {
- removeAccessTokenTrustedIp(index);
- return;
- }
- handlePopUpOpen("upgradePlan", {
- featureName: "IP allowlisting"
- });
- }}
- >
- <XIcon />
- </IconButton>
- </div>
- ))}
- <Button
- type="button"
- variant="outline"
- size="xs"
- className="w-fit"
- onClick={() => {
- if (subscription?.ipAllowlisting) {
- appendAccessTokenTrustedIp({ ipAddress: "0.0.0.0/0" });
- return;
- }
- handlePopUpOpen("upgradePlan", {
- featureName: "IP allowlisting"
- });
- }}
- >
- <PlusIcon />
- Add IP Address
- </Button>
- </div>
+ <TrustedIpsField
+ control={control}
+ name="accessTokenTrustedIps"
+ label="Access Token Trusted IPs"
+ isAllowed={Boolean(subscription?.ipAllowlisting)}
+ onUpgradeRequired={() =>
+ handlePopUpOpen("upgradePlan", { featureName: "IP allowlisting" })
+ }
+ />
</FieldGroup>
</TabsContent>
</Tabs>
diff --git a/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityTlsCertAuthForm.tsx b/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityTlsCertAuthForm.tsx
index 31f7cc94f0..311a299443 100644
--- a/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityTlsCertAuthForm.tsx
+++ b/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityTlsCertAuthForm.tsx
@@ -1,19 +1,17 @@
import { useEffect, useMemo, useState } from "react";
-import { Controller, useFieldArray, useForm } from "react-hook-form";
+import { Controller, useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
import { useParams } from "@tanstack/react-router";
-import { InfoIcon, PlusIcon, XIcon } from "lucide-react";
+import { InfoIcon } from "lucide-react";
import { z } from "zod";
import { createNotification } from "@app/components/notifications";
import {
- Button,
Field,
FieldDescription,
FieldError,
FieldGroup,
FieldLabel,
- IconButton,
Input,
Tabs,
TabsContent,
@@ -26,16 +24,21 @@ import {
} from "@app/components/v3";
import { useOrganization, useSubscription } from "@app/context";
import { SECONDS_PER_DAY } from "@app/helpers/datetime";
-import { accessTokenTtlSchema } from "@app/helpers/identityAuthSchemas";
+import {
+ accessTokenTtlSchema,
+ DEFAULT_TRUSTED_IPS,
+ mapTrustedIpsFromServer,
+ trustedIpsSchema
+} from "@app/helpers/identityAuthSchemas";
import { useScopeVariant } from "@app/hooks";
import {
useAddIdentityTlsCertAuth,
useGetIdentityTlsCertAuth,
useUpdateIdentityTlsCertAuth
} from "@app/hooks/api";
-import { IdentityTrustedIp } from "@app/hooks/api/identities/types";
import { UsePopUpState } from "@app/hooks/usePopUp";
+import { TrustedIpsField } from "./shared/TrustedIpsField";
import { IDENTITY_AUTH_FORM_ID, IdentityFormTab } from "./types";
const buildSchema = (maxAccessTokenTTL: number) =>
@@ -45,13 +48,7 @@ const buildSchema = (maxAccessTokenTTL: number) =>
accessTokenTTL: accessTokenTtlSchema(maxAccessTokenTTL, "Access Token TTL"),
accessTokenMaxTTL: accessTokenTtlSchema(maxAccessTokenTTL, "Access Token Max TTL"),
accessTokenNumUsesLimit: z.string(),
- accessTokenTrustedIps: z
- .array(
- z.object({
- ipAddress: z.string().max(50)
- })
- )
- .min(1)
+ accessTokenTrustedIps: trustedIpsSchema
});
export type FormData = z.infer<ReturnType<typeof buildSchema>>;
@@ -108,16 +105,10 @@ export const IdentityTlsCertAuthForm = ({
accessTokenTTL: "2592000",
accessTokenMaxTTL: "2592000",
accessTokenNumUsesLimit: "",
- accessTokenTrustedIps: [{ ipAddress: "0.0.0.0/0" }, { ipAddress: "::/0" }]
+ accessTokenTrustedIps: DEFAULT_TRUSTED_IPS
}
});
- const {
- fields: accessTokenTrustedIpsFields,
- append: appendAccessTokenTrustedIp,
- remove: removeAccessTokenTrustedIp
- } = useFieldArray({ control, name: "accessTokenTrustedIps" });
-
useEffect(() => {
if (data) {
reset({
@@ -128,13 +119,7 @@ export const IdentityTlsCertAuthForm = ({
accessTokenNumUsesLimit: data.accessTokenNumUsesLimit
? String(data.accessTokenNumUsesLimit)
: "",
- accessTokenTrustedIps: data.accessTokenTrustedIps.map(
- ({ ipAddress, prefix }: IdentityTrustedIp) => {
- return {
- ipAddress: `${ipAddress}${prefix !== undefined ? `/${prefix}` : ""}`
- };
- }
- )
+ accessTokenTrustedIps: mapTrustedIpsFromServer(data.accessTokenTrustedIps)
});
} else {
reset({
@@ -142,7 +127,7 @@ export const IdentityTlsCertAuthForm = ({
accessTokenTTL: "2592000",
accessTokenMaxTTL: "2592000",
accessTokenNumUsesLimit: "",
- accessTokenTrustedIps: [{ ipAddress: "0.0.0.0/0" }, { ipAddress: "::/0" }]
+ accessTokenTrustedIps: DEFAULT_TRUSTED_IPS
});
}
}, [data]);
@@ -364,91 +349,16 @@ export const IdentityTlsCertAuthForm = ({
</TabsContent>
<TabsContent value={IdentityFormTab.Advanced}>
<FieldGroup>
- <div className="flex flex-col gap-3">
- {accessTokenTrustedIpsFields.map(({ id }, index) => (
- <div className="flex items-start gap-2" key={id}>
- <Controller
- control={control}
- name={`accessTokenTrustedIps.${index}.ipAddress`}
- defaultValue="0.0.0.0/0"
- render={({ field, fieldState: { error } }) => (
- <Field className="flex-1">
- {index === 0 && (
- <FieldLabel
- htmlFor={`trustedIp-${index}`}
- className="inline-flex items-center gap-1.5"
- >
- Access Token Trusted IPs
- <Tooltip>
- <TooltipTrigger asChild>
- <InfoIcon className="size-3.5 text-muted" />
- </TooltipTrigger>
- <TooltipContent>
- The IPs or CIDR ranges that access tokens can be used from. By
- default, each token is given the 0.0.0.0/0, allowing usage from any
- network address.
- </TooltipContent>
- </Tooltip>
- </FieldLabel>
- )}
- <Input
- id={`trustedIp-${index}`}
- value={field.value}
- onChange={(e) => {
- if (subscription?.ipAllowlisting) {
- field.onChange(e);
- return;
- }
- handlePopUpOpen("upgradePlan", {
- featureName: "IP allowlisting"
- });
- }}
- placeholder="123.456.789.0"
- isError={Boolean(error)}
- />
- <FieldError>{error?.message}</FieldError>
- </Field>
- )}
- />
- <IconButton
- type="button"
- variant="ghost"
- size="sm"
- aria-label="Remove trusted IP"
- className={index === 0 ? "mt-[1.625rem]" : "mt-0.5"}
- onClick={() => {
- if (subscription?.ipAllowlisting) {
- removeAccessTokenTrustedIp(index);
- return;
- }
- handlePopUpOpen("upgradePlan", {
- featureName: "IP allowlisting"
- });
- }}
- >
- <XIcon />
- </IconButton>
- </div>
- ))}
- <Button
- type="button"
- variant="outline"
- size="xs"
- className="w-fit"
- onClick={() => {
- if (subscription?.ipAllowlisting) {
- appendAccessTokenTrustedIp({ ipAddress: "0.0.0.0/0" });
- return;
- }
- handlePopUpOpen("upgradePlan", {
- featureName: "IP allowlisting"
- });
- }}
- >
- <PlusIcon />
- Add IP Address
- </Button>
- </div>
+ <TrustedIpsField
+ control={control}
+ name="accessTokenTrustedIps"
+ label="Access Token Trusted IPs"
+ isAllowed={Boolean(subscription?.ipAllowlisting)}
+ onUpgradeRequired={() =>
+ handlePopUpOpen("upgradePlan", { featureName: "IP allowlisting" })
+ }
+ tooltip="The IPs or CIDR ranges that access tokens can be used from. By default, each token is given the 0.0.0.0/0, allowing usage from any network address."
+ />
</FieldGroup>
</TabsContent>
</Tabs>
diff --git a/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityTokenAuthForm.tsx b/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityTokenAuthForm.tsx
index 9d25165940..edbb4b71dd 100644
--- a/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityTokenAuthForm.tsx
+++ b/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityTokenAuthForm.tsx
@@ -1,19 +1,17 @@
import { useEffect, useMemo, useState } from "react";
-import { Controller, useFieldArray, useForm } from "react-hook-form";
+import { Controller, useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
import { useParams } from "@tanstack/react-router";
-import { InfoIcon, PlusIcon, XIcon } from "lucide-react";
+import { InfoIcon } from "lucide-react";
import { z } from "zod";
import { createNotification } from "@app/components/notifications";
import {
- Button,
Field,
FieldDescription,
FieldError,
FieldGroup,
FieldLabel,
- IconButton,
Input,
Tabs,
TabsContent,
@@ -25,16 +23,21 @@ import {
} from "@app/components/v3";
import { useOrganization, useSubscription } from "@app/context";
import { SECONDS_PER_DAY } from "@app/helpers/datetime";
-import { accessTokenTtlSchema } from "@app/helpers/identityAuthSchemas";
+import {
+ accessTokenTtlSchema,
+ DEFAULT_TRUSTED_IPS,
+ mapTrustedIpsFromServer,
+ trustedIpsSchema
+} from "@app/helpers/identityAuthSchemas";
import { useScopeVariant } from "@app/hooks";
import {
useAddIdentityTokenAuth,
useGetIdentityTokenAuth,
useUpdateIdentityTokenAuth
} from "@app/hooks/api";
-import { IdentityTrustedIp } from "@app/hooks/api/identities/types";
import { UsePopUpState } from "@app/hooks/usePopUp";
+import { TrustedIpsField } from "./shared/TrustedIpsField";
import { IDENTITY_AUTH_FORM_ID, IdentityFormTab } from "./types";
const buildSchema = (maxAccessTokenTTL: number) =>
@@ -43,13 +46,7 @@ const buildSchema = (maxAccessTokenTTL: number) =>
accessTokenTTL: accessTokenTtlSchema(maxAccessTokenTTL, "Access Token TTL"),
accessTokenMaxTTL: accessTokenTtlSchema(maxAccessTokenTTL, "Access Token Max TTL"),
accessTokenNumUsesLimit: z.string(),
- accessTokenTrustedIps: z
- .array(
- z.object({
- ipAddress: z.string().max(50)
- })
- )
- .min(1)
+ accessTokenTrustedIps: trustedIpsSchema
})
.required();
@@ -106,16 +103,10 @@ export const IdentityTokenAuthForm = ({
accessTokenTTL: "2592000",
accessTokenMaxTTL: "2592000",
accessTokenNumUsesLimit: "",
- accessTokenTrustedIps: [{ ipAddress: "0.0.0.0/0" }, { ipAddress: "::/0" }]
+ accessTokenTrustedIps: DEFAULT_TRUSTED_IPS
}
});
- const {
- fields: accessTokenTrustedIpsFields,
- append: appendAccessTokenTrustedIp,
- remove: removeAccessTokenTrustedIp
- } = useFieldArray({ control, name: "accessTokenTrustedIps" });
-
useEffect(() => {
if (data) {
reset({
@@ -124,20 +115,14 @@ export const IdentityTokenAuthForm = ({
accessTokenNumUsesLimit: data.accessTokenNumUsesLimit
? String(data.accessTokenNumUsesLimit)
: "",
- accessTokenTrustedIps: data.accessTokenTrustedIps.map(
- ({ ipAddress, prefix }: IdentityTrustedIp) => {
- return {
- ipAddress: `${ipAddress}${prefix !== undefined ? `/${prefix}` : ""}`
- };
- }
- )
+ accessTokenTrustedIps: mapTrustedIpsFromServer(data.accessTokenTrustedIps)
});
} else {
reset({
accessTokenTTL: "2592000",
accessTokenMaxTTL: "2592000",
accessTokenNumUsesLimit: "",
- accessTokenTrustedIps: [{ ipAddress: "0.0.0.0/0" }, { ipAddress: "::/0" }]
+ accessTokenTrustedIps: DEFAULT_TRUSTED_IPS
});
}
}, [data]);
@@ -286,78 +271,15 @@ export const IdentityTokenAuthForm = ({
</TabsContent>
<TabsContent value={IdentityFormTab.Advanced}>
<FieldGroup>
- <div className="flex flex-col gap-3">
- {accessTokenTrustedIpsFields.map(({ id }, index) => (
- <div className="flex items-start gap-2" key={id}>
- <Controller
- control={control}
- name={`accessTokenTrustedIps.${index}.ipAddress`}
- defaultValue="0.0.0.0/0"
- render={({ field, fieldState: { error } }) => (
- <Field className="flex-1">
- {index === 0 && (
- <FieldLabel htmlFor={`trustedIp-${index}`}>
- Access Token Trusted IPs
- </FieldLabel>
- )}
- <Input
- id={`trustedIp-${index}`}
- value={field.value}
- onChange={(e) => {
- if (subscription?.ipAllowlisting) {
- field.onChange(e);
- return;
- }
- handlePopUpOpen("upgradePlan", {
- featureName: "IP allowlisting"
- });
- }}
- placeholder="123.456.789.0"
- isError={Boolean(error)}
- />
- <FieldError>{error?.message}</FieldError>
- </Field>
- )}
- />
- <IconButton
- type="button"
- variant="ghost"
- size="sm"
- aria-label="Remove trusted IP"
- className={index === 0 ? "mt-[1.625rem]" : "mt-0.5"}
- onClick={() => {
- if (subscription?.ipAllowlisting) {
- removeAccessTokenTrustedIp(index);
- return;
- }
- handlePopUpOpen("upgradePlan", {
- featureName: "IP allowlisting"
- });
- }}
- >
- <XIcon />
- </IconButton>
- </div>
- ))}
- <Button
- type="button"
- variant="outline"
- size="xs"
- className="w-fit"
- onClick={() => {
- if (subscription?.ipAllowlisting) {
- appendAccessTokenTrustedIp({ ipAddress: "0.0.0.0/0" });
- return;
- }
- handlePopUpOpen("upgradePlan", {
- featureName: "IP allowlisting"
- });
- }}
- >
- <PlusIcon />
- Add IP Address
- </Button>
- </div>
+ <TrustedIpsField
+ control={control}
+ name="accessTokenTrustedIps"
+ label="Access Token Trusted IPs"
+ isAllowed={Boolean(subscription?.ipAllowlisting)}
+ onUpgradeRequired={() =>
+ handlePopUpOpen("upgradePlan", { featureName: "IP allowlisting" })
+ }
+ />
</FieldGroup>
</TabsContent>
</Tabs>
diff --git a/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityUniversalAuthForm.tsx b/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityUniversalAuthForm.tsx
index 2e4468e413..ae8198a222 100644
--- a/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityUniversalAuthForm.tsx
+++ b/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityUniversalAuthForm.tsx
@@ -1,20 +1,18 @@
import { useEffect, useMemo, useState } from "react";
-import { Controller, useFieldArray, useForm } from "react-hook-form";
+import { Controller, useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
import { useParams } from "@tanstack/react-router";
-import { InfoIcon, PlusIcon, XIcon } from "lucide-react";
+import { InfoIcon } from "lucide-react";
import ms from "ms";
import { z } from "zod";
import { createNotification } from "@app/components/notifications";
import {
- Button,
Field,
FieldDescription,
FieldError,
FieldGroup,
FieldLabel,
- IconButton,
Input,
Tabs,
TabsContent,
@@ -26,18 +24,23 @@ import {
} from "@app/components/v3";
import { useOrganization, useSubscription } from "@app/context";
import { getObjectFromSeconds, SECONDS_PER_DAY } from "@app/helpers/datetime";
-import { accessTokenTtlSchema } from "@app/helpers/identityAuthSchemas";
+import {
+ accessTokenTtlSchema,
+ DEFAULT_TRUSTED_IPS,
+ mapTrustedIpsFromServer,
+ trustedIpsSchema
+} from "@app/helpers/identityAuthSchemas";
import { useScopeVariant } from "@app/hooks";
import {
useAddIdentityUniversalAuth,
useGetIdentityUniversalAuth,
useUpdateIdentityUniversalAuth
} from "@app/hooks/api";
-import { IdentityTrustedIp } from "@app/hooks/api/identities/types";
import { UsePopUpState } from "@app/hooks/usePopUp";
import { LockoutTab } from "./lockout/LockoutTab";
import { superRefineLockout } from "./lockout/super-refine";
+import { TrustedIpsField } from "./shared/TrustedIpsField";
import { IDENTITY_AUTH_FORM_ID, IdentityFormTab } from "./types";
const buildSchema = (maxAccessTokenTTL: number) =>
@@ -47,18 +50,8 @@ const buildSchema = (maxAccessTokenTTL: number) =>
accessTokenMaxTTL: accessTokenTtlSchema(maxAccessTokenTTL, "Access Token Max TTL"),
accessTokenPeriod: accessTokenTtlSchema(maxAccessTokenTTL, "Access Token Period").optional(),
accessTokenNumUsesLimit: z.string(),
- clientSecretTrustedIps: z
- .object({
- ipAddress: z.string().max(50)
- })
- .array()
- .min(1),
- accessTokenTrustedIps: z
- .object({
- ipAddress: z.string().max(50)
- })
- .array()
- .min(1),
+ clientSecretTrustedIps: trustedIpsSchema,
+ accessTokenTrustedIps: trustedIpsSchema,
lockoutEnabled: z.boolean().default(true),
lockoutThreshold: z
.string()
@@ -132,8 +125,8 @@ export const IdentityUniversalAuthForm = ({
accessTokenTTL: "2592000",
accessTokenMaxTTL: "2592000",
accessTokenNumUsesLimit: "",
- clientSecretTrustedIps: [{ ipAddress: "0.0.0.0/0" }, { ipAddress: "::/0" }],
- accessTokenTrustedIps: [{ ipAddress: "0.0.0.0/0" }, { ipAddress: "::/0" }],
+ clientSecretTrustedIps: DEFAULT_TRUSTED_IPS,
+ accessTokenTrustedIps: DEFAULT_TRUSTED_IPS,
accessTokenPeriod: "0",
lockoutEnabled: true,
lockoutThreshold: "3",
@@ -153,17 +146,6 @@ export const IdentityUniversalAuthForm = ({
const lockoutCounterResetValueWatch = watch("lockoutCounterResetValue");
const lockoutCounterResetUnitWatch = watch("lockoutCounterResetUnit");
- const {
- fields: clientSecretTrustedIpsFields,
- append: appendClientSecretTrustedIp,
- remove: removeClientSecretTrustedIp
- } = useFieldArray({ control, name: "clientSecretTrustedIps" });
- const {
- fields: accessTokenTrustedIpsFields,
- append: appendAccessTokenTrustedIp,
- remove: removeAccessTokenTrustedIp
- } = useFieldArray({ control, name: "accessTokenTrustedIps" });
-
useEffect(() => {
if (data) {
const lockoutDurationObj = getObjectFromSeconds(data.lockoutDurationSeconds);
@@ -176,20 +158,8 @@ export const IdentityUniversalAuthForm = ({
? String(data.accessTokenNumUsesLimit)
: "",
accessTokenPeriod: String(data.accessTokenPeriod),
- clientSecretTrustedIps: data.clientSecretTrustedIps.map(
- ({ ipAddress, prefix }: IdentityTrustedIp) => {
- return {
- ipAddress: `${ipAddress}${prefix !== undefined ? `/${prefix}` : ""}`
- };
- }
- ),
- accessTokenTrustedIps: data.accessTokenTrustedIps.map(
- ({ ipAddress, prefix }: IdentityTrustedIp) => {
- return {
- ipAddress: `${ipAddress}${prefix !== undefined ? `/${prefix}` : ""}`
- };
- }
- ),
+ clientSecretTrustedIps: mapTrustedIpsFromServer(data.clientSecretTrustedIps),
+ accessTokenTrustedIps: mapTrustedIpsFromServer(data.accessTokenTrustedIps),
lockoutEnabled: data.lockoutEnabled,
lockoutThreshold: String(data.lockoutThreshold),
lockoutDurationValue: String(lockoutDurationObj.value),
@@ -203,8 +173,8 @@ export const IdentityUniversalAuthForm = ({
accessTokenMaxTTL: "2592000",
accessTokenNumUsesLimit: "",
accessTokenPeriod: "0",
- clientSecretTrustedIps: [{ ipAddress: "0.0.0.0/0" }, { ipAddress: "::/0" }],
- accessTokenTrustedIps: [{ ipAddress: "0.0.0.0/0" }, { ipAddress: "::/0" }],
+ clientSecretTrustedIps: DEFAULT_TRUSTED_IPS,
+ accessTokenTrustedIps: DEFAULT_TRUSTED_IPS,
lockoutEnabled: true,
lockoutThreshold: "3",
lockoutDurationValue: "5",
@@ -441,150 +411,24 @@ export const IdentityUniversalAuthForm = ({
/>
<TabsContent value={IdentityFormTab.Advanced}>
<FieldGroup>
- <div className="flex flex-col gap-3">
- {clientSecretTrustedIpsFields.map(({ id }, index) => (
- <div className="flex items-start gap-2" key={id}>
- <Controller
- control={control}
- name={`clientSecretTrustedIps.${index}.ipAddress`}
- defaultValue="0.0.0.0/0"
- render={({ field, fieldState: { error } }) => (
- <Field className="flex-1">
- {index === 0 && (
- <FieldLabel htmlFor={`clientSecretTrustedIp-${index}`}>
- Client Secret Trusted IPs
- </FieldLabel>
- )}
- <Input
- id={`clientSecretTrustedIp-${index}`}
- value={field.value}
- onChange={(e) => {
- if (subscription?.ipAllowlisting) {
- field.onChange(e);
- return;
- }
- handlePopUpOpen("upgradePlan", {
- featureName: "IP allowlisting"
- });
- }}
- placeholder="123.456.789.0"
- isError={Boolean(error)}
- />
- <FieldError>{error?.message}</FieldError>
- </Field>
- )}
- />
- <IconButton
- type="button"
- variant="ghost"
- size="sm"
- aria-label="Remove trusted IP"
- className={index === 0 ? "mt-[1.625rem]" : "mt-0.5"}
- onClick={() => {
- if (subscription?.ipAllowlisting) {
- removeClientSecretTrustedIp(index);
- return;
- }
- handlePopUpOpen("upgradePlan", {
- featureName: "IP allowlisting"
- });
- }}
- >
- <XIcon />
- </IconButton>
- </div>
- ))}
- <Button
- type="button"
- variant="outline"
- size="xs"
- className="w-fit"
- onClick={() => {
- if (subscription?.ipAllowlisting) {
- appendClientSecretTrustedIp({ ipAddress: "0.0.0.0/0" });
- return;
- }
- handlePopUpOpen("upgradePlan", {
- featureName: "IP allowlisting"
- });
- }}
- >
- <PlusIcon />
- Add IP Address
- </Button>
- </div>
- <div className="flex flex-col gap-3">
- {accessTokenTrustedIpsFields.map(({ id }, index) => (
- <div className="flex items-start gap-2" key={id}>
- <Controller
- control={control}
- name={`accessTokenTrustedIps.${index}.ipAddress`}
- defaultValue="0.0.0.0/0"
- render={({ field, fieldState: { error } }) => (
- <Field className="flex-1">
- {index === 0 && (
- <FieldLabel htmlFor={`accessTokenTrustedIp-${index}`}>
- Access Token Trusted IPs
- </FieldLabel>
- )}
- <Input
- id={`accessTokenTrustedIp-${index}`}
- value={field.value}
- onChange={(e) => {
- if (subscription?.ipAllowlisting) {
- field.onChange(e);
- return;
- }
- handlePopUpOpen("upgradePlan", {
- featureName: "IP allowlisting"
- });
- }}
- placeholder="123.456.789.0"
- isError={Boolean(error)}
- />
- <FieldError>{error?.message}</FieldError>
- </Field>
- )}
- />
- <IconButton
- type="button"
- variant="ghost"
- size="sm"
- aria-label="Remove trusted IP"
- className={index === 0 ? "mt-[1.625rem]" : "mt-0.5"}
- onClick={() => {
- if (subscription?.ipAllowlisting) {
- removeAccessTokenTrustedIp(index);
- return;
- }
- handlePopUpOpen("upgradePlan", {
- featureName: "IP allowlisting"
- });
- }}
- >
- <XIcon />
- </IconButton>
- </div>
- ))}
- <Button
- type="button"
- variant="outline"
- size="xs"
- className="w-fit"
- onClick={() => {
- if (subscription?.ipAllowlisting) {
- appendAccessTokenTrustedIp({ ipAddress: "0.0.0.0/0" });
- return;
- }
- handlePopUpOpen("upgradePlan", {
- featureName: "IP allowlisting"
- });
- }}
- >
- <PlusIcon />
- Add IP Address
- </Button>
- </div>
+ <TrustedIpsField
+ control={control}
+ name="clientSecretTrustedIps"
+ label="Client Secret Trusted IPs"
+ isAllowed={Boolean(subscription?.ipAllowlisting)}
+ onUpgradeRequired={() =>
+ handlePopUpOpen("upgradePlan", { featureName: "IP allowlisting" })
+ }
+ />
+ <TrustedIpsField
+ control={control}
+ name="accessTokenTrustedIps"
+ label="Access Token Trusted IPs"
+ isAllowed={Boolean(subscription?.ipAllowlisting)}
+ onUpgradeRequired={() =>
+ handlePopUpOpen("upgradePlan", { featureName: "IP allowlisting" })
+ }
+ />
</FieldGroup>
</TabsContent>
</Tabs>
diff --git a/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/shared/TrustedIpsField.tsx b/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/shared/TrustedIpsField.tsx
new file mode 100644
index 0000000000..31ac688eb4
--- /dev/null
+++ b/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/shared/TrustedIpsField.tsx
@@ -0,0 +1,116 @@
+import { ReactNode } from "react";
+import { Control, Controller, useFieldArray } from "react-hook-form";
+import { InfoIcon, PlusIcon, XIcon } from "lucide-react";
+
+import {
+ Button,
+ Field,
+ FieldError,
+ FieldLabel,
+ IconButton,
+ Input,
+ Tooltip,
+ TooltipContent,
+ TooltipTrigger
+} from "@app/components/v3";
+
+type Props = {
+ control: Control<any>;
+ /** The field-array name on the form (e.g. "accessTokenTrustedIps"). */
+ name: string;
+ /** Label rendered above the first row. */
+ label: string;
+ /** Whether the IP allowlisting feature is available on the current plan. */
+ isAllowed: boolean;
+ /** Invoked when a gated action is attempted without the feature (opens the upgrade prompt). */
+ onUpgradeRequired: () => void;
+ /** Optional info tooltip shown next to the label. */
+ tooltip?: ReactNode;
+};
+
+/**
+ * Shared editor for an identity auth method's trusted-IP constraints. Every auth
+ * method supports `accessTokenTrustedIps`; Universal Auth additionally renders
+ * `clientSecretTrustedIps` by using a second instance of this component.
+ */
+export const TrustedIpsField = ({
+ control,
+ name,
+ label,
+ isAllowed,
+ onUpgradeRequired,
+ tooltip
+}: Props) => {
+ const { fields, append, remove } = useFieldArray({ control, name });
+
+ // IP allowlisting is a paid feature, so every mutation is gated behind the upgrade prompt.
+ const guard = (action: () => void) => {
+ if (isAllowed) {
+ action();
+ return;
+ }
+ onUpgradeRequired();
+ };
+
+ return (
+ <div className="flex flex-col gap-3">
+ {fields.map(({ id }, index) => (
+ <div className="flex items-start gap-2" key={id}>
+ <Controller
+ control={control}
+ name={`${name}.${index}.ipAddress`}
+ defaultValue="0.0.0.0/0"
+ render={({ field, fieldState: { error } }) => (
+ <Field className="flex-1">
+ {index === 0 && (
+ <FieldLabel
+ htmlFor={`${name}-${index}`}
+ className={tooltip ? "inline-flex items-center gap-1.5" : undefined}
+ >
+ {label}
+ {tooltip && (
+ <Tooltip>
+ <TooltipTrigger asChild>
+ <InfoIcon className="size-3.5 text-muted" />
+ </TooltipTrigger>
+ <TooltipContent>{tooltip}</TooltipContent>
+ </Tooltip>
+ )}
+ </FieldLabel>
+ )}
+ <Input
+ id={`${name}-${index}`}
+ value={field.value}
+ onChange={(e) => guard(() => field.onChange(e))}
+ placeholder="123.456.789.0"
+ isError={Boolean(error)}
+ />
+ <FieldError>{error?.message}</FieldError>
+ </Field>
+ )}
+ />
+ <IconButton
+ type="button"
+ variant="ghost"
+ size="sm"
+ aria-label="Remove trusted IP"
+ className={index === 0 ? "mt-[1.625rem]" : "mt-0.5"}
+ onClick={() => guard(() => remove(index))}
+ >
+ <XIcon />
+ </IconButton>
+ </div>
+ ))}
+ <Button
+ type="button"
+ variant="outline"
+ size="xs"
+ className="w-fit"
+ onClick={() => guard(() => append({ ipAddress: "0.0.0.0/0" }))}
+ >
+ <PlusIcon />
+ Add IP Address
+ </Button>
+ </div>
+ );
+};