Exploiting Misconfigured Terraform Cloud OIDC AWS IAM Roles
A misconfigured AWS IAM role trust policy for Terraform Cloud OIDC allowed any Terraform Cloud user to assume the role if the organization name matched a wildcard pattern. An attacker could create a Terraform Cloud organization with a matching name and assume the role, gaining the permissions attached to it.
hackingthe.cloud
Published on hackingthe.cloud
OIDC stands for OpenID Connect and is an identity layer built on top of the OAuth 2.0 protocol. In AWS, OIDC can be used to federate identities from external identity providers, such as Google, Facebook or Terraform, allowing users to access AWS resources using their existing third-party accounts.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
The IAM role's trust policy used a wildcard in the organization name within the subject condition, allowing any Terraform Cloud organization matching the pattern to assume the role.
Impact
An attacker could assume the misconfigured role and gain whatever permissions it has, potentially including administrator access, and then create persistent backdoor roles.
What the attacker needed
A free Terraform Cloud account; knowledge of the target role's ARN; the role's trust policy uses a wildcard in the organization…
The fix
The trust policy should not use wildcards in the organization name; it should specify the exact organization, project, workspace, and run phase, and AWS now enforces this for new roles.
How it was found
- Create a free Terraform Cloud account.
- Create an organization with a name that matches the wildcard pattern.
- Create a project and workspace with the names specified in the trust policy.
- Set the environment variables to enable AWS authentication and specify the target role ARN.
- Write and apply a Terraform configuration that creates a backdoored IAM role with administrator permissions.
- Assume the newly created role from an external AWS account.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
When you let an external service like Terraform Cloud access your AWS account, you set up a trust policy that says who can use a role. If that policy uses a wildcard in the organization name, anyone who creates an organization with a name that fits the pattern can pretend to be that organization and take over the role. This report shows how an attacker can do that and then use the role to create backdoors.
What is Access control?
A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.