AccessDenied Not authorized to perform stsAssumeRoleWithWebIdentity
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Understanding the "AccessDenied: Not authorized to perform sts:AssumeRoleWithWebIdentity" Error
Amazon Web Services (AWS) provides a suite of cloud computing services, including Identity and Access Management (IAM), which allows you to control access to AWS resources securely. One common issue developers encounter is the "AccessDenied: Not authorized to perform sts:AssumeRoleWithWebIdentity" error. This article will delve into what causes this error, its technical implications, and how you can resolve it effectively.
Explanation of the Error
The error message "AccessDenied: Not authorized to perform sts:AssumeRoleWithWebIdentity" indicates that a request to assume an IAM Role via AWS Security Token Service (STS) using Web Identity Federation failed due to insufficient permissions.
Key Terminologies
- STS (Security Token Service): A web service that enables you to request temporary credentials for IAM users or federated users.
- AssumeRoleWithWebIdentity: An API call that returns temporary security credentials for users authenticated via web identity providers like Amazon Cognito, Google, or Facebook.
- IAM Role: An IAM identity that you can create in AWS with specific permissions.
Technical Explanation
What Causes This Error?
- IAM Role Trust Policy Misconfiguration: The IAM Role being assumed does not have a proper trust policy that allows an identity provider(web identity) to assume it.
- Insufficient Permissions: The entity attempting to call `AssumeRoleWithWebIdentity` does not have the necessary permissions attached to it. Specifically, it may lack the `sts:AssumeRoleWithWebIdentity` permission.
- Incorrect Audience: The token provided may not be intended for the service or application making the request, indicated by a mismatch in the intended audience field in the token.
Example Trust Policy
To successfully assume a role using Web Identity, the role's trust policy should allow the specific Identity Provider (IdP) and specify conditions under which the role can be assumed.
Here's an example JSON trust policy for a role that trusts an Amazon Cognito Identity:
- Ensure the IAM Role's trust policy allows the specific Web Identity Provider to assume the role.
- Check if the `StringEquals` condition correctly specifies the audience (`aud`) field.
- Verify that the entity making the `AssumeRoleWithWebIdentity` has the appropriate permissions.
- Attach a policy with the `sts:AssumeRoleWithWebIdentity` action if necessary.
- Ensure the web identity token is not expired and is correctly issued.
- Validate the token's audience matches one expected by your application.
- Use AWS CloudTrail to identify any unauthorized requests or access patterns suggesting permission issues.
- Regular Audits: Perform regular audits on IAM roles and policies to ensure they meet the Principle of Least Privilege.
- Update Tokens: Periodically update and validate tokens to maintain secure access workflows.
- Documentation: Keep IAM and STS documentation handy for quick reference in setup and debugging.
Related reading
- AccessDeniedException User is not authorized to perform lambdaInvokeFunction
- Accessing AWS Lambda environment variables in Java code
- Accessing environment variables in AWS Beanstalk ebextensions
- Accessing kube-dns outside of kubernetes cluster
- Accessing Kafka broker from outside my LAN
- Accessing RDS from within a Docker container not getting through security group?
- Accessing Kubernetes service on port 80
- Accessing Tensorboard on AWS

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.