AWS
STS
AssumeRoleWithWebIdentity
Error 403
Cloud Security

Not authorized to perform stsAssumeRoleWithWebIdentity- 403

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

Understanding the `sts:AssumeRoleWithWebIdentity` Error 403

When working with AWS Security Token Service (STS) and utilizing Web Identity Federation, a common issue that may arise is the 403 `Not authorized to perform sts:AssumeRoleWithWebIdentity` error. It is essential to understand this error to implement a solution efficiently.

What is `sts:AssumeRoleWithWebIdentity`?

The `sts:AssumeRoleWithWebIdentity` is an AWS Security Token Service (STS) API operation that allows you to obtain temporary security credentials for an IAM role. This method is generally used in web applications, mobile apps, or any other use case where the application needs to access AWS resources without embedding AWS credentials.

Causes of `403 Not authorized to perform sts:AssumeRoleWithWebIdentity`

The `403` error is an HTTP status indicating that access is forbidden due to insufficient permissions or misconfigurations. Below are some common reasons and their explanations:

  1. IAM Role Misconfiguration:
    • The IAM role might not trust the Web Identity Provider.
    • The specified role should contain a trust policy that allows the specified identity provider.
  2. Incorrect Role ARN or Provider:
    • Ensure that the role ARN and identity provider's ARN in the trust policy are correctly specified.
    • Any mistake in these ARNs can result in authorization failure.
  3. Missing or Misconfigured Policies:
    • An IAM role may not have the necessary policies to perform actions on behalf of the federated user.
    • Policies attached to the role need to be comprehensive to allow the necessary actions.
  4. Expired or Invalid Tokens:
    • Tokens provided by identity providers (e.g., OIDC tokens) must be valid and unexpired.
    • An expired or malformed token can cause authorization to fail.

Example Trust Policy

Here is an example of a trust policy that can be attached to an IAM role:

  • Use Temporary Credentials: Always prefer temporary credentials over long-term AWS credentials.
  • Principle of Least Privilege: Grant only the permissions necessary for roles to perform their tasks.
  • Regularly Rotate Credentials: Implement routine rotation of any long-term credentials or keys.
  • Implement Logging and Monitoring: Enable AWS CloudWatch and CloudTrail to keep track of authentication and authorization activities.

Related reading
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track 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.

Practice system design

All Rights Reserved.