
Trying Out IAM Federation Tips with S3 Bucket Policies
This page has been translated by machine translation. View original
Introduction
With the update on November 29, 2026, analytics and storage services now support trusted identity propagation (TIP) for IAM federation. When you enable TIP in IAM federation, the ID of the user who signed in through the IdP and selected attributes are attached to the IAM role session, and can be used for authorization and CloudTrail auditing.
In this article, I configured TIP in OIDC federation using a Cognito user pool as the IdP, and checked per-user access control with an S3 bucket policy and the CloudTrail records.
Test Environment
- Region: Tokyo (ap-northeast-1)
- AWS CLI: 2.42.6
- IdP: Cognito user pool
- Federation API: AssumeRoleWithWebIdentity
Configuration
Cognito User Pool
I gave the user pool a custom attribute department. In the ID token, it becomes custom:department.
| User | custom:department |
|---|---|
| alice | Finance |
| bob | Marketing |
I used the ID token claims for the following purposes.
- sub: identifying the user
- custom:department: permission based on the attribute
I obtained the ID tokens for both alice and bob.
Commands for creating the user pool and obtaining the ID tokens
<PASSWORD> is a password of 12 or more characters that includes uppercase letters, lowercase letters, and numbers.
aws cognito-idp create-user-pool --pool-name tip-iam-fed-verify \
--admin-create-user-config AllowAdminCreateUserOnly=true \
--schema Name=department,AttributeDataType=String,Mutable=true,Required=false \
--policies 'PasswordPolicy={MinimumLength=12,RequireUppercase=true,RequireLowercase=true,RequireNumbers=true,RequireSymbols=false}'
aws cognito-idp create-user-pool-client --user-pool-id <USER_POOL_ID> --client-name tip-verify-client \
--no-generate-secret --explicit-auth-flows ALLOW_ADMIN_USER_PASSWORD_AUTH ALLOW_REFRESH_TOKEN_AUTH
aws cognito-idp admin-create-user --user-pool-id <USER_POOL_ID> --username alice \
--message-action SUPPRESS --user-attributes Name=custom:department,Value=Finance
aws cognito-idp admin-create-user --user-pool-id <USER_POOL_ID> --username bob \
--message-action SUPPRESS --user-attributes Name=custom:department,Value=Marketing
aws cognito-idp admin-set-user-password --user-pool-id <USER_POOL_ID> --username alice \
--password '<PASSWORD>' --permanent
aws cognito-idp admin-initiate-auth --user-pool-id <USER_POOL_ID> --client-id <APP_CLIENT_ID> \
--auth-flow ADMIN_USER_PASSWORD_AUTH --auth-parameters USERNAME=alice,PASSWORD='<PASSWORD>' \
--query AuthenticationResult.IdToken --output text > alice.jwt
For bob as well, I ran admin-set-user-password and admin-initiate-auth with the user name changed to bob, and saved the ID token as bob.jwt.
<USER_POOL_ID> is the Id in the response of create-user-pool, and <APP_CLIENT_ID> is the ClientId in the response of create-user-pool-client.
The claims of alice's ID token that are used in later configuration were as follows.
{
"sub": "<ALICE_SUB>",
"custom:department": "Finance",
"iss": "https://cognito-idp.ap-northeast-1.amazonaws.com/<USER_POOL_ID>",
"aud": "<APP_CLIENT_ID>"
}
IAM OIDC Provider
To configure TIP on the IAM OIDC provider, I saved the following configuration file as context-provider.json.
{
"SubjectSourceKey": "sub",
"SubjectTypeValue": "user",
"KeyDefinitionList": [
{ "SourceKey": "custom:department", "TargetKey": "department" }
]
}
The configuration makes the sub of the ID token the session's Subject, sets the Subject type to the fixed value user, and makes custom:department an attribute named department. I passed this configuration file to --context-provider and created the OIDC provider.
aws iam create-open-id-connect-provider \
--url https://cognito-idp.ap-northeast-1.amazonaws.com/<USER_POOL_ID> \
--client-id-list <APP_CLIENT_ID> --context-provider file://context-provider.json
Because the creation response contained only the ARN, I used that ARN as <OIDC_PROVIDER_ARN> and checked the TIP configuration with get-open-id-connect-provider.
Command and response for checking the configuration
aws iam get-open-id-connect-provider --open-id-connect-provider-arn <OIDC_PROVIDER_ARN>
The ContextProvider in the response was as follows.
"ContextProvider": {
"KeyDefinitionList": [
{
"SourceKey": "custom:department",
"TargetKey": "department"
}
],
"SubjectSourceKey": "sub",
"SubjectTypeValue": "user"
}
Role
I created one IAM role, tip-verify-shared-role, shared by alice and bob. I did not grant any S3 permissions to the role.
Role creation command and policy
trust-shared-role.json
{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Principal": { "Federated": "arn:aws:iam::<ACCOUNT_ID>:oidc-provider/cognito-idp.ap-northeast-1.amazonaws.com/<USER_POOL_ID>" },
"Action": "sts:AssumeRoleWithWebIdentity",
"Condition": { "StringEquals": { "cognito-idp.ap-northeast-1.amazonaws.com/<USER_POOL_ID>:aud": "<APP_CLIENT_ID>" } }
}]
}
aws iam create-role --role-name tip-verify-shared-role --assume-role-policy-document file://trust-shared-role.json
S3 Bucket Policy
I placed finance/report.txt and marketing/plan.txt in the bucket and configured the bucket policy. The targets and conditions that are allowed are as follows.
| Target | Type | TIP context key | Original ID token claim | Condition value |
|---|---|---|---|---|
| finance/* | User | aws:OriginIdentity/Subject | sub | alice's sub |
| marketing/* | Attribute | aws:TransactionContext/IdentityProvider/department | custom:department | Marketing |
The settings common to both Statements are as follows.
- Principal: the shared role tip-verify-shared-role
- Action: s3:GetObject
- Additional condition: aws:OriginIdentity/Issuer matches the value of this Cognito user pool
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowFinanceToAlice",
"Effect": "Allow",
"Principal": { "AWS": "arn:aws:iam::<ACCOUNT_ID>:role/tip-verify-shared-role" },
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::<BUCKET>/finance/*",
"Condition": {
"StringEquals": {
"aws:OriginIdentity/Issuer": "cognito-idp.ap-northeast-1.amazonaws.com/<USER_POOL_ID>",
"aws:OriginIdentity/Subject": "<ALICE_SUB>"
}
}
},
{
"Sid": "AllowMarketingDepartment",
"Effect": "Allow",
"Principal": { "AWS": "arn:aws:iam::<ACCOUNT_ID>:role/tip-verify-shared-role" },
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::<BUCKET>/marketing/*",
"Condition": {
"StringEquals": {
"aws:OriginIdentity/Issuer": "cognito-idp.ap-northeast-1.amazonaws.com/<USER_POOL_ID>",
"aws:TransactionContext/IdentityProvider/department": "Marketing"
}
}
}
]
}
aws s3api put-bucket-policy --bucket <BUCKET> --policy file://bucket-policy.json
<BUCKET> is the bucket name, and <ALICE_SUB> is the sub of alice's ID token.
Commands for creating the bucket and objects
aws s3api create-bucket --bucket <BUCKET> --create-bucket-configuration LocationConstraint=ap-northeast-1
aws s3api put-object --bucket <BUCKET> --key finance/report.txt --body finance.txt
aws s3api put-object --bucket <BUCKET> --key marketing/plan.txt --body marketing.txt
Verification Results
Session Context
I assumed the shared role with alice's ID token. Because AssumeRoleWithWebIdentity is an API called without an AWS signature, I added --no-sign-request.
aws sts assume-role-with-web-identity --no-sign-request \
--role-arn arn:aws:iam::<ACCOUNT_ID>:role/tip-verify-shared-role \
--role-session-name alice-session --web-identity-token file://alice.jwt
The response included TrustedIdentityPropagationContext, which contained the following ID and attributes.
"TrustedIdentityPropagationContext": {
"OriginIdentity": {
"Subject": "<ALICE_SUB>",
"SubjectType": "user",
"Issuer": "cognito-idp.ap-northeast-1.amazonaws.com/<USER_POOL_ID>",
"FederatedProviderArn": "arn:aws:iam::<ACCOUNT_ID>:oidc-provider/cognito-idp.ap-northeast-1.amazonaws.com/<USER_POOL_ID>"
},
"TransactionContext": {
"IdentityProvider": {
"department": "Finance"
}
}
}
When I assumed the same role with bob's token and the session name bob-session, the TrustedIdentityPropagationContext in the response was as follows.
"TrustedIdentityPropagationContext": {
"OriginIdentity": {
"Subject": "<BOB_SUB>",
"SubjectType": "user",
"Issuer": "cognito-idp.ap-northeast-1.amazonaws.com/<USER_POOL_ID>",
"FederatedProviderArn": "arn:aws:iam::<ACCOUNT_ID>:oidc-provider/cognito-idp.ap-northeast-1.amazonaws.com/<USER_POOL_ID>"
},
"TransactionContext": {
"IdentityProvider": {
"department": "Marketing"
}
}
}
Retrieving Objects
I set the credentials of the alice and bob sessions as environment variables in turn, and ran get-object with each remaining in the shared role session.
export AWS_ACCESS_KEY_ID=<AccessKeyId>
export AWS_SECRET_ACCESS_KEY=<SecretAccessKey>
export AWS_SESSION_TOKEN=<SessionToken>
aws s3api get-object --bucket <BUCKET> --key finance/report.txt out.txt
alice was able to retrieve finance/report.txt.
When alice specified marketing/plan.txt, the session whose department is Finance did not match the marketing/ condition, and the result was AccessDenied.
aws: [ERROR]: An error occurred (AccessDenied) when calling the GetObject operation: User: arn:aws:sts::<ACCOUNT_ID>:assumed-role/tip-verify-shared-role/alice-session is not authorized to perform: s3:GetObject on resource: "arn:aws:s3:::<BUCKET>/marketing/plan.txt" because no identity-based policy allows the s3:GetObject action
bob got the opposite result. He could retrieve marketing/plan.txt, and finance/report.txt returned AccessDenied with a message in the same format.
CloudTrail Records
Because I skipped S3 object logging, I checked not GetObject but the events of aws sts get-caller-identity (GetCallerIdentity) that I ran in each session after get-object.
aws cloudtrail lookup-events --lookup-attributes AttributeKey=EventName,AttributeValue=GetCallerIdentity
Extracting only the type, arn, onBehalfOf, and transactionContext of userIdentity from alice's event's CloudTrailEvent gave the following. The role was recorded in the session's arn, and the user was recorded in onBehalfOf.
"userIdentity": {
"type": "AssumedRole",
"arn": "arn:aws:sts::<ACCOUNT_ID>:assumed-role/tip-verify-shared-role/alice-session",
"onBehalfOf": {
"federatedProviderArn": "arn:aws:iam::<ACCOUNT_ID>:oidc-provider/cognito-idp.ap-northeast-1.amazonaws.com/<USER_POOL_ID>",
"subject": "<ALICE_SUB>",
"subjectType": "user",
"issuer": "cognito-idp.ap-northeast-1.amazonaws.com/<USER_POOL_ID>"
},
"transactionContext": {
"IdentityProvider": {
"department": "Finance"
}
}
}
In bob's event, the session name in the arn was bob-session, the subject in onBehalfOf was bob's sub, and the department was Marketing.
"userIdentity": {
"type": "AssumedRole",
"arn": "arn:aws:sts::<ACCOUNT_ID>:assumed-role/tip-verify-shared-role/bob-session",
"onBehalfOf": {
"federatedProviderArn": "arn:aws:iam::<ACCOUNT_ID>:oidc-provider/cognito-idp.ap-northeast-1.amazonaws.com/<USER_POOL_ID>",
"subject": "<BOB_SUB>",
"subjectType": "user",
"issuer": "cognito-idp.ap-northeast-1.amazonaws.com/<USER_POOL_ID>"
},
"transactionContext": {
"IdentityProvider": {
"department": "Marketing"
}
}
}
Summary
I confirmed that when TIP is enabled in IAM federation, the user's ID and attributes are attached to the shared IAM role session and can be used as access permission conditions in an S3 bucket policy.
In S3, TIP-based control is also possible with things other than bucket policies, such as S3 Access Grants.
Also, beyond S3, if you want to control authorization based on the IdP's registered information in the services that now support TIP, such as SageMaker, Lake Formation, Glue, EMR, Redshift, and MWAA Serverless, please try this update.
