Exploiting Misconfigured GitLab OIDC AWS IAM Roles
AWS IAM roles configured to trust GitLab's OIDC provider without a condition on the subject claim can be assumed by any GitLab.com user. An attacker can create a GitLab project, obtain a valid OIDC token, and use it to assume the vulnerable role, gaining its permissions.
hackingthe.cloud
Published on hackingthe.cloud
OpenID Connect (OIDC) is a common technology used to authorize services outside of AWS to assume IAM roles. As has been shown many times in the past (examples: one, two, and three), these roles can be misconfigured, permitting anyone in the world the ability to assume a vulnerable role.
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 lacks a condition on the 'sub' (subject) claim, so any GitLab.com user's token is accepted.
Impact
An attacker with any GitLab.com account could assume the misconfigured IAM role and obtain its temporary AWS credentials, gaining whatever permissions the role has.
What the attacker needed
A free GitLab.com account; the vulnerable role's ARN; ability to create a GitLab project
The fix
Add a condition on the 'sub' claim to the trust policy to restrict which GitLab projects or branches can assume the role, or use a Resource Control Policy to block untrusted OIDC providers.
How it was found
- Create or use an existing account on gitlab.com.
- Create a new project and add a .gitlab-ci.yml file that requests an OIDC token with the audience https://gitlab.com and prints it base64-encoded.
- Run the CI job and view its output to obtain the base64-encoded token.
- Decode the base64 value to get the JWT.
- Use the AWS CLI to call sts:AssumeRoleWithWebIdentity with the role ARN and the JWT.
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 a cloud service like AWS trusts an outside login system (here GitLab) to let people in, it checks a token that says who the person is. If the check only confirms the token came from GitLab but does not check which GitLab project or user it belongs to, then anyone with a free GitLab account can make a token and get in. This article shows how that happens and how to fix it.
What is Misconfiguration?
Settings left unsafe: exposed panels, open storage buckets, debug modes, default credentials.