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
feat: add support for session policies
adilson1830a43dedb7
diff --git a/backend/src/ee/services/dynamic-secret/providers/aws-iam.ts b/backend/src/ee/services/dynamic-secret/providers/aws-iam.tsindex a4890df779..bbdfc1c6d3 100644--- a/backend/src/ee/services/dynamic-secret/providers/aws-iam.ts+++ b/backend/src/ee/services/dynamic-secret/providers/aws-iam.ts@@ -34,6 +34,22 @@ import { generateUsername } from "./templateUtils";// AWS STS duration constants (in seconds)const AWS_STS_MIN_DURATION = 900;+// session policies restrict the assumed role's permissions to the intersection with the given policies; they can never expand them+const getAssumeRoleSessionPolicyParams = (providerInputs: {+ sessionPolicyArns?: string;+ sessionPolicyDocument?: string;+}) => {+ const sessionPolicyArns = providerInputs.sessionPolicyArns+ ?.split(",")+ .map((arn) => arn.trim())+ .filter(Boolean);++ return {+ Policy: providerInputs.sessionPolicyDocument || undefined,+ PolicyArns: sessionPolicyArns?.length ? sessionPolicyArns.map((arn) => ({ arn })) : undefined+ };+};+export const AwsIamProvider = (): TDynamicProviderFns => {const validateProviderInputs = async (inputs: unknown) => {const providerInputs = await DynamicSecretAwsIamSchema.parseAsync(inputs);@@ -144,12 +160,14 @@ export const AwsIamProvider = (): TDynamicProviderFns => {: undefined});+ // include session policies so malformed policy documents/ARNs fail at config time rather than on the first leaseawait stsClient.send(new AssumeRoleCommand({RoleArn: providerInputs.roleArn,RoleSessionName: `infisical-validation-${crypto.nativeCrypto.randomUUID()}`,DurationSeconds: AWS_STS_MIN_DURATION,- ExternalId: projectId+ ExternalId: projectId,+ ...getAssumeRoleSessionPolicyParams(providerInputs)}));return true;@@ -247,7 +265,8 @@ export const AwsIamProvider = (): TDynamicProviderFns => {RoleArn: providerInputs.roleArn,RoleSessionName: `infisical-temp-cred-${crypto.nativeCrypto.randomUUID()}`,DurationSeconds: durationSeconds,- ExternalId: metadata.projectId+ ExternalId: metadata.projectId,+ ...getAssumeRoleSessionPolicyParams(providerInputs)}));diff --git a/backend/src/ee/services/dynamic-secret/providers/models.ts b/backend/src/ee/services/dynamic-secret/providers/models.tsindex 0087766b36..54a67fb4f4 100644--- a/backend/src/ee/services/dynamic-secret/providers/models.ts+++ b/backend/src/ee/services/dynamic-secret/providers/models.ts@@ -270,44 +270,97 @@ export const DynamicSecretAwsIamSchema = z.preprocess(}return val;},- z.discriminatedUnion("method", [- z.object({- method: z.literal(AwsIamAuthType.AccessKey),- credentialType: z.nativeEnum(AwsIamCredentialType).default(AwsIamCredentialType.IamUser),- 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(),- tags: ResourceMetadataNonEncryptionSchema.optional()- }),- z.object({- method: z.literal(AwsIamAuthType.AssumeRole),- credentialType: z.nativeEnum(AwsIamCredentialType).default(AwsIamCredentialType.IamUser),- roleArn: z.string().trim().min(1, "Role ARN required"),- 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(),- tags: ResourceMetadataNonEncryptionSchema.optional()- }),- z.object({- method: z.literal(AwsIamAuthType.IRSA),- credentialType: z.nativeEnum(AwsIamCredentialType).default(AwsIamCredentialType.IamUser),- 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(),- tags: ResourceMetadataNonEncryptionSchema.optional()+ z+ .discriminatedUnion("method", [+ z.object({+ method: z.literal(AwsIamAuthType.AccessKey),+ credentialType: z.nativeEnum(AwsIamCredentialType).default(AwsIamCredentialType.IamUser),+ 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(),+ tags: ResourceMetadataNonEncryptionSchema.optional()+ }),+ z.object({+ method: z.literal(AwsIamAuthType.AssumeRole),+ credentialType: z.nativeEnum(AwsIamCredentialType).default(AwsIamCredentialType.IamUser),+ roleArn: z.string().trim().min(1, "Role ARN required"),+ 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(),+ sessionPolicyArns: z.string().trim().optional(),+ sessionPolicyDocument: z.string().trim().optional(),+ tags: ResourceMetadataNonEncryptionSchema.optional()+ }),+ z.object({+ method: z.literal(AwsIamAuthType.IRSA),+ credentialType: z.nativeEnum(AwsIamCredentialType).default(AwsIamCredentialType.IamUser),+ 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(),+ tags: ResourceMetadataNonEncryptionSchema.optional()+ })+ ])+ .superRefine((data, ctx) => {+ const reject = (path: string, message: string) =>+ ctx.addIssue({ path: [path], code: z.ZodIssueCode.custom, message });+ const countCsvArns = (value: string) => value.split(",").filter((arn) => arn.trim()).length;++ if (data.credentialType === AwsIamCredentialType.TemporaryCredentials) {+ // policyArns/policyDocument grant permissions to created IAM users; temporary credentials are restricted via session policies instead+ if (data.policyArns) {+ reject(+ "policyArns",+ "Policy ARNs only apply to the IAM User credential type. To restrict temporary credentials, use Session Policy ARNs with the Assume Role method."+ );+ }+ if (data.policyDocument) {+ reject(+ "policyDocument",+ "A policy document only applies to the IAM User credential type. To restrict temporary credentials, use a Session Policy Document with the Assume Role method."+ );+ }++ // session policy fields exist only on the AssumeRole member (STS AssumeRole alone supports them; GetSessionToken,+ // used by access key / IRSA, has no Policy/PolicyArns params), so this guard also narrows the type for TS+ if (data.method === AwsIamAuthType.AssumeRole) {+ if (data.sessionPolicyArns && countCsvArns(data.sessionPolicyArns) > 10) {+ reject("sessionPolicyArns", "AWS allows at most 10 managed policy ARNs as session policies");+ }+ // session policies count the full plaintext against the 2,048 character limit+ if (data.sessionPolicyDocument && data.sessionPolicyDocument.length > 2048) {+ reject("sessionPolicyDocument", "AWS limits inline session policies to 2,048 characters of plaintext");+ }+ }+ return;+ }++ // IAM User credential type: session policies have no meaning because no STS session is created+ if (data.method === AwsIamAuthType.AssumeRole) {+ if (data.sessionPolicyArns) {+ reject(+ "sessionPolicyArns",+ "Session policy ARNs only apply to the Temporary Credentials credential type. Use Policy ARNs to grant permissions to created IAM users."+ );+ }+ if (data.sessionPolicyDocument) {+ reject(+ "sessionPolicyDocument",+ "A session policy document only applies to the Temporary Credentials credential type. Use a policy document to grant permissions to created IAM users."+ );+ }+ }})- ]));export const DynamicSecretMongoAtlasSchema = z.object({diff --git a/docs/documentation/platform/dynamic-secrets/aws-iam.mdx b/docs/documentation/platform/dynamic-secrets/aws-iam.mdxindex e3b84e528f..a8cee3fd8a 100644--- a/docs/documentation/platform/dynamic-secrets/aws-iam.mdx+++ b/docs/documentation/platform/dynamic-secrets/aws-iam.mdx@@ -226,11 +226,11 @@ Infisical needs an AWS IAM principal (a user or a role) with the required permis</ParamField><ParamField path="AWS Policy ARNs" type="string">- The AWS IAM managed policies that should be attached to the created users. Multiple values can be provided by separating them with commas.+ The AWS IAM managed policies that should be attached to the created users. Multiple values can be provided by separating them with commas. AWS allows at most 10 managed policies attached to a user.</ParamField><ParamField path="AWS IAM Policy Document" type="string">- The AWS IAM inline policy that should be attached to the created users. Multiple values can be provided by separating them with commas.+ The AWS IAM inline policy (JSON) that should be attached to the created users. Maximum 2,048 non-whitespace characters (AWS excludes whitespace from this quota).</ParamField><DynamicSecretUsernameTemplateParamField />@@ -244,12 +244,23 @@ Infisical needs an AWS IAM principal (a user or a role) with the required permisWhen **Credential Type** is set to **Temporary Credentials**:<Info>- No additional configuration parameters are required. The generated credentials will:- - Inherit the permissions of the assumed role+ The generated credentials will:+ - Inherit the permissions of the assumed role, optionally restricted by the session policies below- Include an AWS Session Token- Be valid for the duration specified in Default TTL</Info>+ <ParamField path="AWS Session Policy ARNs" type="string" optional>+ Comma-separated managed policy ARNs applied as session policies. The generated credentials are limited to the intersection of the assumed role's permissions and these policies. AWS allows up to 10 ARNs.+ </ParamField>+ <ParamField path="AWS Session Policy Document" type="string" optional>+ An inline session policy (JSON) that further restricts the generated credentials. Maximum 2,048 characters of plaintext. AWS additionally enforces a packed-size limit covering the inline policy, managed policy ARNs, and session tags combined.+ </ParamField>++ <Info>+ Session policies can only restrict the assumed role's permissions; they can never grant permissions beyond it.+ </Info>+<Warning>**Duration Limit**: AssumeRole temporary credentials are limited to 1 hour maximum by AWS. TTL values exceeding this limit will be automatically adjusted to 1 hour.</Warning>@@ -408,11 +419,11 @@ Infisical needs an AWS IAM principal (a user or a role) with the required permis</ParamField><ParamField path="AWS Policy ARNs" type="string">- The AWS IAM managed policies that should be attached to the created users. Multiple values can be provided by separating them with commas.+ The AWS IAM managed policies that should be attached to the created users. Multiple values can be provided by separating them with commas. AWS allows at most 10 managed policies attached to a user.</ParamField><ParamField path="AWS IAM Policy Document" type="string">- The AWS IAM inline policy that should be attached to the created users. Multiple values can be provided by separating them with commas.+ The AWS IAM inline policy (JSON) that should be attached to the created users. Maximum 2,048 non-whitespace characters (AWS excludes whitespace from this quota).</ParamField><DynamicSecretUsernameTemplateParamField />@@ -435,6 +446,10 @@ Infisical needs an AWS IAM principal (a user or a role) with the required permis<Note>**Duration Limit**: IRSA temporary credentials support up to 12 hours maximum via GetSessionToken. TTL values exceeding this limit will be automatically adjusted.</Note>++ <Note>+ Session policies (AWS Session Policy ARNs / AWS Session Policy Document) are not supported with the IRSA method: STS GetSessionToken does not accept them. These fields are only available with the Assume Role method.+ </Note></Tab></Tabs></Step>@@ -527,11 +542,11 @@ Infisical needs an AWS IAM principal (a user or a role) with the required permis</ParamField><ParamField path="AWS Policy ARNs" type="string">- The AWS IAM managed policies that should be attached to the created users. Multiple values can be provided by separating them with commas.+ The AWS IAM managed policies that should be attached to the created users. Multiple values can be provided by separating them with commas. AWS allows at most 10 managed policies attached to a user.</ParamField><ParamField path="AWS IAM Policy Document" type="string">- The AWS IAM inline policy that should be attached to the created users. Multiple values can be provided by separating them with commas.+ The AWS IAM inline policy (JSON) that should be attached to the created users. Maximum 2,048 non-whitespace characters (AWS excludes whitespace from this quota).</ParamField><DynamicSecretUsernameTemplateParamField />@@ -554,6 +569,10 @@ Infisical needs an AWS IAM principal (a user or a role) with the required permis<Note>**Duration Limit**: Access Key temporary credentials support up to 12 hours maximum via GetSessionToken. TTL values exceeding this limit will be automatically adjusted.</Note>++ <Note>+ Session policies (AWS Session Policy ARNs / AWS Session Policy Document) are not supported with the Access Key method: STS GetSessionToken does not accept them. These fields are only available with the Assume Role method.+ </Note></Tab></Tabs>diff --git a/frontend/src/hooks/api/dynamicSecret/types.ts b/frontend/src/hooks/api/dynamicSecret/types.tsindex 3fa34400a8..c8b0775683 100644--- a/frontend/src/hooks/api/dynamicSecret/types.ts+++ b/frontend/src/hooks/api/dynamicSecret/types.ts@@ -141,6 +141,8 @@ export type TDynamicSecretProvider =policyDocument?: string;userGroups?: string;policyArns?: string;+ sessionPolicyArns?: string;+ sessionPolicyDocument?: string;}| {method: DynamicSecretAwsIamAuth.AssumeRole;@@ -151,6 +153,8 @@ export type TDynamicSecretProvider =policyDocument?: string;userGroups?: string;policyArns?: string;+ sessionPolicyArns?: string;+ sessionPolicyDocument?: string;}| {method: DynamicSecretAwsIamAuth.IRSA;@@ -160,6 +164,8 @@ export type TDynamicSecretProvider =policyDocument?: string;userGroups?: string;policyArns?: string;+ sessionPolicyArns?: string;+ sessionPolicyDocument?: string;};}| {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.tsxindex e4438d1173..6750ec4afc 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@@ -60,6 +60,8 @@ const formSchema = z.object({policyDocument: z.string().trim().optional(),userGroups: z.string().trim().optional(),policyArns: z.string().trim().optional(),+ sessionPolicyArns: z.string().trim().optional(),+ sessionPolicyDocument: z.string().trim().optional(),tags: z.array(z.object({@@ -153,6 +155,9 @@ export const AwsIamInputForm = ({const createDynamicSecret = useCreateDynamicSecret();const method = watch("provider.method");const credentialType = watch("provider.credentialType");+ const isIamUser = credentialType !== DynamicSecretAwsIamCredentialType.TemporaryCredentials;+ // session policies only apply to temporary credentials issued via STS AssumeRole+ const isSessionPolicySupported = !isIamUser && method === DynamicSecretAwsIamAuth.AssumeRole;const handleCreateDynamicSecret = async ({name,@@ -165,9 +170,16 @@ export const AwsIamInputForm = ({// wait till previous request is finishedif (createDynamicSecret.isPending) return;+ // react-hook-form keeps values of unmounted fields; clear policies that do not apply to the submitted credential type / method combination+ const sanitizedProvider = {+ ...provider,+ ...(!isIamUser && { policyArns: "", policyDocument: "" }),+ ...(!isSessionPolicySupported && { sessionPolicyArns: "", sessionPolicyDocument: "" })+ };+const isDefaultUsernameTemplate = usernameTemplate === "{{randomUsername}}";await createDynamicSecret.mutateAsync({- provider: { type: DynamicSecretProviders.AwsIam, inputs: provider },+ provider: { type: DynamicSecretProviders.AwsIam, inputs: sanitizedProvider },maxTTL,name,path: secretPath,@@ -391,7 +403,7 @@ export const AwsIamInputForm = ({)}/></div>- {credentialType !== DynamicSecretAwsIamCredentialType.TemporaryCredentials && (+ {isIamUser && (<><Controllercontrol={control}@@ -435,7 +447,7 @@ export const AwsIamInputForm = ({isError={Boolean(error?.message)}isOptionalerrorText={error?.message}- helperText="Generated users will get attached to given policy arns."+ helperText="Generated users will get attached to given policy arns. AWS allows at most 10 attached managed policies."><Input{...field}@@ -466,6 +478,49 @@ export const AwsIamInputForm = ({/></>)}+ {isSessionPolicySupported && (+ <>+ <Controller+ control={control}+ name="provider.sessionPolicyArns"+ defaultValue=""+ render={({ field, fieldState: { error } }) => (+ <FormControl+ label="AWS Session Policy ARNs"+ isError={Boolean(error?.message)}+ isOptional+ errorText={error?.message}+ helperText="Session policies: leased credentials are limited to the intersection of the role's permissions and these managed policies. They can only restrict, never add, permissions. Up to 10 ARNs, comma-separated."+ >+ <Input+ {...field}+ placeholder="arn:aws:iam::aws:policy/AmazonEC2ReadOnlyAccess"+ />+ </FormControl>+ )}+ />+ <Controller+ control={control}+ name="provider.sessionPolicyDocument"+ render={({ field, fieldState: { error } }) => (+ <FormControl+ label="AWS Session Policy Document"+ isOptional+ isError={Boolean(error?.message)}+ errorText={error?.message}+ helperText="Inline session policy (JSON) that further restricts the leased temporary credentials. It cannot grant permissions beyond the role's policies. Maximum 2,048 characters."+ >+ <TextArea+ {...field}+ reSize="none"+ rows={3}+ className="border-mineshaft-600 bg-mineshaft-900 text-sm"+ />+ </FormControl>+ )}+ />+ </>+ )}{credentialType !== DynamicSecretAwsIamCredentialType.TemporaryCredentials && (<Controllercontrol={control}diff --git a/frontend/src/pages/secret-manager/SecretDashboardPage/components/DynamicSecretListView/EditDynamicSecretForm/EditDynamicSecretAwsIamForm.tsx b/frontend/src/pages/secret-manager/SecretDashboardPage/components/DynamicSecretListView/EditDynamicSecretForm/EditDynamicSecretAwsIamForm.tsxindex c9c9afb71b..5abac7e15e 100644--- a/frontend/src/pages/secret-manager/SecretDashboardPage/components/DynamicSecretListView/EditDynamicSecretForm/EditDynamicSecretAwsIamForm.tsx+++ b/frontend/src/pages/secret-manager/SecretDashboardPage/components/DynamicSecretListView/EditDynamicSecretForm/EditDynamicSecretAwsIamForm.tsx@@ -47,6 +47,8 @@ const formSchema = z.object({policyDocument: z.string().trim().optional(),userGroups: z.string().trim().optional(),policyArns: z.string().trim().optional(),+ sessionPolicyArns: z.string().trim().optional(),+ sessionPolicyDocument: z.string().trim().optional(),tags: z.array(z.object({ key: z.string().trim().min(1), value: z.string().trim().min(1) })).optional()@@ -128,6 +130,9 @@ export const EditDynamicSecretAwsIamForm = ({});const method = watch("inputs.method");const credentialType = watch("inputs.credentialType");+ const isIamUser = credentialType !== DynamicSecretAwsIamCredentialType.TemporaryCredentials;+ // session policies only apply to temporary credentials issued via STS AssumeRole+ const isSessionPolicySupported = !isIamUser && method === DynamicSecretAwsIamAuth.AssumeRole;const updateDynamicSecret = useUpdateDynamicSecret();@@ -140,6 +145,15 @@ export const EditDynamicSecretAwsIamForm = ({}: TForm) => {// wait till previous request is finishedif (updateDynamicSecret.isPending) return;++ // clear policies that do not apply to the submitted credential type / method combination; explicit "" is required+ // because the update endpoint shallow-merges inputs, so omitted keys would keep their stored values+ const sanitizedInputs = {+ ...inputs,+ ...(!isIamUser && { policyArns: "", policyDocument: "" }),+ ...(!isSessionPolicySupported && { sessionPolicyArns: "", sessionPolicyDocument: "" })+ };+const isDefaultUsernameTemplate = usernameTemplate === "{{randomUsername}}";await updateDynamicSecret.mutateAsync({name: dynamicSecret.name,@@ -149,7 +163,7 @@ export const EditDynamicSecretAwsIamForm = ({data: {maxTTL: maxTTL || undefined,defaultTTL,- inputs,+ inputs: sanitizedInputs,newName: newName === dynamicSecret.name ? undefined : newName,usernameTemplate: !usernameTemplate || isDefaultUsernameTemplate ? null : usernameTemplate}@@ -366,7 +380,7 @@ export const EditDynamicSecretAwsIamForm = ({)}/></div>- {credentialType !== DynamicSecretAwsIamCredentialType.TemporaryCredentials && (+ {isIamUser && (<><Controllercontrol={control}@@ -403,14 +417,14 @@ export const EditDynamicSecretAwsIamForm = ({<Controllercontrol={control}name="inputs.policyArns"- defaultValue="datacenter1"+ defaultValue=""render={({ field, fieldState: { error } }) => (<FormControllabel="AWS Policy ARNs"isError={Boolean(error?.message)}isOptionalerrorText={error?.message}- helperText="Generated users will get attached to given policy arns."+ helperText="Generated users will get attached to given policy arns. AWS allows at most 10 attached managed policies."><Input {...field} /></FormControl>@@ -438,6 +452,46 @@ export const EditDynamicSecretAwsIamForm = ({/></>)}+ {isSessionPolicySupported && (+ <>+ <Controller+ control={control}+ name="inputs.sessionPolicyArns"+ defaultValue=""+ render={({ field, fieldState: { error } }) => (+ <FormControl+ label="AWS Session Policy ARNs"+ isError={Boolean(error?.message)}+ isOptional+ errorText={error?.message}+ helperText="Session policies: leased credentials are limited to the intersection of the role's permissions and these managed policies. They can only restrict, never add, permissions. Up to 10 ARNs, comma-separated."+ >+ <Input {...field} />+ </FormControl>+ )}+ />+ <Controller+ control={control}+ name="inputs.sessionPolicyDocument"+ render={({ field, fieldState: { error } }) => (+ <FormControl+ label="AWS Session Policy Document"+ isOptional+ isError={Boolean(error?.message)}+ errorText={error?.message}+ helperText="Inline session policy (JSON) that further restricts the leased temporary credentials. It cannot grant permissions beyond the role's policies. Maximum 2,048 characters."+ >+ <TextArea+ {...field}+ reSize="none"+ rows={3}+ className="border-mineshaft-600 bg-mineshaft-900 text-sm"+ />+ </FormControl>+ )}+ />+ </>+ )}{credentialType !== DynamicSecretAwsIamCredentialType.TemporaryCredentials && (<Controllercontrol={control}