Addressed AWS defaults risks: OIDC, Terraform and Anonymous to AdministratorAccess
AWS IAM roles created for Terraform Cloud via OIDC lacked a subject condition in their trust policy, allowing any Terraform Cloud organisation to assume the role. An attacker could gain administrator access to the AWS account if they knew the account ID and role name.
Published on hacktodef.com
The article brings to light another story about a possible cloud mass exploitation, but this time mistakes are easier to make when administrators overlook the implications of these configurations. The result?
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 trust policy for the OIDC provider only checked the audience condition and omitted the subject condition, so any identity from that provider could assume the role.
Impact
An attacker could gain AdministratorAccess to the AWS account, but only if they know the AWS account ID and the role name; AWS has since improved defaults and contacted affected customers.
What the attacker needed
Knowledge of AWS account ID; knowledge of role name; Terraform Cloud account
The fix
AWS implemented improvements in the default Terraform OIDC trust policy and added a mandatory organisation field in the web portal; the article also suggests a Lambda function to check trust policies for the subject condition.
How it was found
- Create an organisation in Terraform Cloud.
- Configure a workspace with environment variables to assume the target AWS role.
- Authenticate from local Terraform CLI to Terraform Cloud and run a Terraform script that uses the assumed role.
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 connect an external service like Terraform Cloud to AWS, you set up a trust policy that says who can use a role. If you forget to restrict which organisation can use it, anyone with a Terraform Cloud account can pretend to be you and get the same permissions, which in this case were full admin rights.
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.