diff --git a/frontend/src/hooks/api/dynamicSecret/types.ts b/frontend/src/hooks/api/dynamicSecret/types.ts index f9aa6d4d0..9b105cd64 100644 --- a/frontend/src/hooks/api/dynamicSecret/types.ts +++ b/frontend/src/hooks/api/dynamicSecret/types.ts @@ -44,6 +44,11 @@ export enum SqlProviders { MsSQL = "mssql" } +export enum DynamicSecretAwsIamAuth { + AssumeRole = "assume-role", + AccessKey = "access-key" +} + export type TDynamicSecretProvider = | { type: DynamicSecretProviders.SqlDatabase; @@ -78,15 +83,26 @@ export type TDynamicSecretProvider = } | { type: DynamicSecretProviders.AwsIam; - inputs: { - accessKey: string; - secretAccessKey: string; - region: string; - awsPath?: string; - policyDocument?: string; - userGroups?: string; - policyArns?: string; - }; + inputs: + | { + method: DynamicSecretAwsIamAuth.AccessKey; + accessKey: string; + secretAccessKey: string; + region: string; + awsPath?: string; + policyDocument?: string; + userGroups?: string; + policyArns?: string; + } + | { + method: DynamicSecretAwsIamAuth.AssumeRole; + roleArn: string; + region: string; + awsPath?: string; + policyDocument?: string; + userGroups?: string; + policyArns?: string; + }; } | { type: DynamicSecretProviders.Redis; diff --git a/frontend/src/pages/secret-manager/SecretDashboardPage/components/ActionBar/CreateDynamicSecretForm/AwsIamInputForm.tsx b/frontend/src/pages/secret-manager/SecretDashboardPage/components/ActionBar/CreateDynamicSecretForm/AwsIamInputForm.tsx index cd7b330e8..80c80ee61 100644 --- a/frontend/src/pages/secret-manager/SecretDashboardPage/components/ActionBar/CreateDynamicSecretForm/AwsIamInputForm.tsx +++ b/frontend/src/pages/secret-manager/SecretDashboardPage/components/ActionBar/CreateDynamicSecretForm/AwsIamInputForm.tsx @@ -5,22 +5,46 @@ import { z } from "zod"; import { TtlFormLabel } from "@app/components/features"; import { createNotification } from "@app/components/notifications"; -import { Button, FilterableSelect, FormControl, Input, TextArea } from "@app/components/v2"; +import { + Button, + FilterableSelect, + FormControl, + Input, + Select, + SelectItem, + TextArea +} from "@app/components/v2"; import { useCreateDynamicSecret } from "@app/hooks/api"; -import { DynamicSecretProviders } from "@app/hooks/api/dynamicSecret/types"; +import { + DynamicSecretAwsIamAuth, + DynamicSecretProviders +} from "@app/hooks/api/dynamicSecret/types"; import { WorkspaceEnv } from "@app/hooks/api/types"; const formSchema = z.object({ - provider: z.object({ - accessKey: z.string().trim().min(1), - secretAccessKey: z.string().trim().min(1), - region: z.string().trim().min(1), - awsPath: z.string().trim().optional(), - permissionBoundaryPolicyArn: z.string().trim().optional(), - policyDocument: z.string().trim().optional(), - userGroups: z.string().trim().optional(), - policyArns: z.string().trim().optional() - }), + provider: z.discriminatedUnion("method", [ + z.object({ + method: z.literal(DynamicSecretAwsIamAuth.AccessKey), + accessKey: z.string().trim().min(1), + secretAccessKey: z.string().trim().min(1), + region: z.string().trim().min(1), + awsPath: z.string().trim().optional(), + permissionBoundaryPolicyArn: z.string().trim().optional(), + policyDocument: z.string().trim().optional(), + userGroups: z.string().trim().optional(), + policyArns: z.string().trim().optional() + }), + z.object({ + method: z.literal(DynamicSecretAwsIamAuth.AssumeRole), + roleArn: z.string().trim().min(1), + region: z.string().trim().min(1), + awsPath: z.string().trim().optional(), + permissionBoundaryPolicyArn: z.string().trim().optional(), + policyDocument: z.string().trim().optional(), + userGroups: z.string().trim().optional(), + policyArns: z.string().trim().optional() + }) + ]), defaultTTL: z.string().superRefine((val, ctx) => { const valMs = ms(val); if (valMs < 60 * 1000) @@ -67,16 +91,21 @@ export const AwsIamInputForm = ({ const { control, formState: { isSubmitting }, - handleSubmit + handleSubmit, + watch } = useForm({ resolver: zodResolver(formSchema), defaultValues: { environment: isSingleEnvironmentMode ? environments[0] : undefined, - usernameTemplate: "{{randomUsername}}" + usernameTemplate: "{{randomUsername}}", + provider: { + method: DynamicSecretAwsIamAuth.AssumeRole + } } }); const createDynamicSecret = useCreateDynamicSecret(); + const isAccessKeyMethod = watch("provider.method") === DynamicSecretAwsIamAuth.AccessKey; const handleCreateDynamicSecret = async ({ name, @@ -127,7 +156,7 @@ export const AwsIamInputForm = ({ isError={Boolean(error)} errorText={error?.message} > - + )} /> @@ -170,38 +199,82 @@ export const AwsIamInputForm = ({ Configuration
-
- ( - ( + + - - )} - /> - ( - - - - )} - /> -
+ + Assume Role (Recommended) + + Access Key + + + )} + /> + {isAccessKeyMethod ? ( +
+ ( + + + + )} + /> + ( + + + + )} + /> +
+ ) : ( +
+ ( + + + + )} + /> +
+ )}
{ const valMs = ms(val); if (valMs < 60 * 1000) @@ -66,6 +77,7 @@ export const EditDynamicSecretAwsIamForm = ({ }: Props) => { const { control, + watch, formState: { isSubmitting }, handleSubmit } = useForm({ @@ -80,6 +92,7 @@ export const EditDynamicSecretAwsIamForm = ({ } } }); + const isAccessKeyMethod = watch("inputs.method") === DynamicSecretAwsIamAuth.AccessKey; const updateDynamicSecret = useUpdateDynamicSecret(); @@ -173,38 +186,82 @@ export const EditDynamicSecretAwsIamForm = ({
Configuration
-
- ( - ( + + - - )} - /> - ( - - - - )} - /> -
+ + Assume Role (Recommended) + + Access Key + + + )} + /> + {isAccessKeyMethod ? ( +
+ ( + + + + )} + /> + ( + + + + )} + /> +
+ ) : ( +
+ ( + + + + )} + /> +
+ )}