Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
fix(dynamic-secret): dedup GCP IAM token scopes and drop FieldValues hack
Tuan Dangd8c8f61c3641
diff --git a/backend/src/ee/services/dynamic-secret/providers/gcp-iam.ts b/backend/src/ee/services/dynamic-secret/providers/gcp-iam.tsindex 9e3dd460ec..4035eaf555 100644--- a/backend/src/ee/services/dynamic-secret/providers/gcp-iam.ts+++ b/backend/src/ee/services/dynamic-secret/providers/gcp-iam.ts@@ -38,7 +38,7 @@ export const GcpIamProvider = (): TDynamicProviderFns => {targetPrincipal: serviceAccountEmail,lifetime: ttl,delegates: [],- targetScopes: tokenScopes+ targetScopes: [...new Set(tokenScopes)]});let tokenResponse: GetAccessTokenResponse | undefined;diff --git a/docs/documentation/platform/dynamic-secrets/gcp-iam.mdx b/docs/documentation/platform/dynamic-secrets/gcp-iam.mdxindex 8f72024f52..f6c8a8746e 100644--- a/docs/documentation/platform/dynamic-secrets/gcp-iam.mdx+++ b/docs/documentation/platform/dynamic-secrets/gcp-iam.mdx@@ -108,7 +108,7 @@ The Infisical GCP IAM dynamic secret allows you to generate GCP service accountThe email tied to the service account created in earlier steps.</ParamField><ParamField path="Token Scopes" type="string[]" default="https://www.googleapis.com/auth/iam, https://www.googleapis.com/auth/cloud-platform">- The OAuth scopes granted to the generated access token. Defaults to the `iam` and `cloud-platform` scopes. Add scopes such as `https://www.googleapis.com/auth/drive.readonly` to access Google APIs outside `cloud-platform`'s coverage.+ The OAuth scopes granted to the generated access token. Defaults to `https://www.googleapis.com/auth/iam` and `https://www.googleapis.com/auth/cloud-platform` scopes. You can add additional scopes such as `https://www.googleapis.com/auth/drive`.</ParamField></Step><Step title="Click `Submit`">diff --git a/frontend/src/pages/secret-manager/SecretDashboardPage/components/ActionBar/CreateDynamicSecretForm/GcpIamInputForm.tsx b/frontend/src/pages/secret-manager/SecretDashboardPage/components/ActionBar/CreateDynamicSecretForm/GcpIamInputForm.tsxindex 98a51f8583..da9e9890d2 100644--- a/frontend/src/pages/secret-manager/SecretDashboardPage/components/ActionBar/CreateDynamicSecretForm/GcpIamInputForm.tsx+++ b/frontend/src/pages/secret-manager/SecretDashboardPage/components/ActionBar/CreateDynamicSecretForm/GcpIamInputForm.tsx@@ -1,4 +1,4 @@-import { Controller, FieldValues, useFieldArray, useForm } from "react-hook-form";+import { Controller, useFieldArray, useForm } from "react-hook-form";import { faPlus, faTrash } from "@fortawesome/free-solid-svg-icons";import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";import { zodResolver } from "@hookform/resolvers/zod";@@ -28,7 +28,9 @@ const formSchema = z.object({provider: z.object({serviceAccountEmail: z.string().email().trim().min(1, "Service account email required"),- tokenScopes: z.array(z.string().trim().min(1)).min(1, "At least one scope is required")+ tokenScopes: z+ .array(z.object({ value: z.string().trim().min(1, "Scope is required") }))+ .min(1, "At least one scope is required")}),defaultTTL: z.string().superRefine(validateTTL),maxTTL: z@@ -44,7 +46,7 @@ const formSchema = zpath: ["maxTTL"],message: "Max TTL must be greater than or equal to Default TTL"});-type TForm = z.infer<typeof formSchema> & FieldValues;+type TForm = z.infer<typeof formSchema>;type Props = {onCompleted: () => void;@@ -73,8 +75,8 @@ export const GcpIamInputForm = ({environment: isSingleEnvironmentMode && environments.length > 0 ? environments[0] : undefined,provider: {tokenScopes: [- "https://www.googleapis.com/auth/iam",- "https://www.googleapis.com/auth/cloud-platform"+ { value: "https://www.googleapis.com/auth/iam" },+ { value: "https://www.googleapis.com/auth/cloud-platform" }]}}@@ -100,7 +102,8 @@ export const GcpIamInputForm = ({provider: {type: DynamicSecretProviders.GcpIam,inputs: {- ...provider+ ...provider,+ tokenScopes: [...new Set(provider.tokenScopes.map((scope) => scope.value))]}},maxTTL,@@ -217,7 +220,7 @@ export const GcpIamInputForm = ({<div className="grow"><Controllercontrol={control}- name={`provider.tokenScopes.${index}`}+ name={`provider.tokenScopes.${index}.value`}render={({ field: itemField, fieldState: { error: itemError } }) => (<FormControlisError={Boolean(itemError?.message)}@@ -247,7 +250,7 @@ export const GcpIamInputForm = ({leftIcon={<FontAwesomeIcon icon={faPlus} />}size="xs"variant="outline_bg"- onClick={() => append("")}+ onClick={() => append({ value: "" })}type="button">Add Scopediff --git a/frontend/src/pages/secret-manager/SecretDashboardPage/components/DynamicSecretListView/EditDynamicSecretForm/EditDynamicSecretGcpIamForm.tsx b/frontend/src/pages/secret-manager/SecretDashboardPage/components/DynamicSecretListView/EditDynamicSecretForm/EditDynamicSecretGcpIamForm.tsxindex f5ab2558b0..c85317ef62 100644--- a/frontend/src/pages/secret-manager/SecretDashboardPage/components/DynamicSecretListView/EditDynamicSecretForm/EditDynamicSecretGcpIamForm.tsx+++ b/frontend/src/pages/secret-manager/SecretDashboardPage/components/DynamicSecretListView/EditDynamicSecretForm/EditDynamicSecretGcpIamForm.tsx@@ -1,4 +1,4 @@-import { Controller, FieldValues, useFieldArray, useForm } from "react-hook-form";+import { Controller, useFieldArray, useForm } from "react-hook-form";import { faPlus, faTrash } from "@fortawesome/free-solid-svg-icons";import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";import { zodResolver } from "@hookform/resolvers/zod";@@ -28,7 +28,9 @@ const formSchema = z.object({inputs: z.object({serviceAccountEmail: z.string().email().trim().min(1, "Service account email required"),- tokenScopes: z.array(z.string().trim().min(1)).min(1, "At least one scope is required")+ tokenScopes: z+ .array(z.object({ value: z.string().trim().min(1, "Scope is required") }))+ .min(1, "At least one scope is required")}),defaultTTL: z.string().superRefine(validateTTL),maxTTL: z@@ -43,7 +45,7 @@ const formSchema = zpath: ["maxTTL"],message: "Max TTL must be greater than or equal to Default TTL"});-type TForm = z.infer<typeof formSchema> & FieldValues;+type TForm = z.infer<typeof formSchema>;type Props = {onClose: () => void;@@ -70,11 +72,14 @@ export const EditDynamicSecretGcpIamForm = ({maxTTL: dynamicSecret.maxTTL,newName: dynamicSecret.name,inputs: {- ...(dynamicSecret.inputs as TForm["inputs"]),- tokenScopes: (dynamicSecret.inputs as TForm["inputs"]).tokenScopes ?? [- "https://www.googleapis.com/auth/iam",- "https://www.googleapis.com/auth/cloud-platform"- ]+ serviceAccountEmail: (dynamicSecret.inputs as { serviceAccountEmail: string })+ .serviceAccountEmail,+ tokenScopes: (+ (dynamicSecret.inputs as { tokenScopes?: string[] }).tokenScopes ?? [+ "https://www.googleapis.com/auth/iam",+ "https://www.googleapis.com/auth/cloud-platform"+ ]+ ).map((value) => ({ value }))}}});@@ -97,7 +102,10 @@ export const EditDynamicSecretGcpIamForm = ({data: {maxTTL: maxTTL || undefined,defaultTTL,- inputs,+ inputs: {+ ...inputs,+ tokenScopes: [...new Set(inputs.tokenScopes.map((scope) => scope.value))]+ },newName: newName === dynamicSecret.name ? undefined : newName}});@@ -194,7 +202,7 @@ export const EditDynamicSecretGcpIamForm = ({<div className="grow"><Controllercontrol={control}- name={`inputs.tokenScopes.${index}`}+ name={`inputs.tokenScopes.${index}.value`}render={({ field: itemField, fieldState: { error: itemError } }) => (<FormControlisError={Boolean(itemError?.message)}@@ -224,7 +232,7 @@ export const EditDynamicSecretGcpIamForm = ({leftIcon={<FontAwesomeIcon icon={faPlus} />}size="xs"variant="outline_bg"- onClick={() => append("")}+ onClick={() => append({ value: "" })}type="button">Add Scope