Skip to main content

Adding sts:* to an Identity-Perimeter RCP Stops GitLab CI Jobs Assuming AWS Roles Through OIDC

High severityAmazon Web Services About 20 minutes to fix

Overview

Federated GitLab jobs carry no aws:PrincipalOrgID, so an RCP that denies sts:* to outsiders denies them too. Narrow the actions and add OIDC checks in one update.

At a glance

Symptom
Every job that assumes a role through GitLab's ID token fails at the aws sts assume-role-with-web-identity step, in every account the RCP covers.
Likely cause
A federated OIDC caller never has aws:PrincipalOrgID in its request, so a StringNotEqualsIfExists deny on that key matches it every time.
Impact
With sts:* in the statement, every web identity and SAML federation into roles in the accounts under the RCP stops, not only GitLab.
Verification signal
A retried GitLab job gets credentials, and the policy still denies STS to principals outside the organization.
Safe correction
Replace the policy in a single update that narrows the organization statement and adds the OIDC checks together.
Rollback or recovery
Put the saved content back with one command if the new version denies something it should not: aws organizations update-policy --policy-id p-examplepolicyid456 --content file://rcp-before.json.

If GitLab CI jobs stopped getting AWS credentials soon after someone tightened a resource control policy (RCP), check whether the policy’s organization-ID statement denies sts:* or names sts:AssumeRoleWithWebIdentity. That statement denies any request whose aws:PrincipalOrgID is not yours, and a GitLab job federating through OIDC has no organization ID at all, so the deny applies to it. The fix is to list STS actions in that statement explicitly, leaving out AssumeRoleWithWebIdentity, AssumeRoleWithSAML, SetSourceIdentity and TagSession, and to cover web identity with statements that trust only your OIDC provider and your GitLab group. Make both changes in one policy update, so no version of the policy leaves web identity unrestricted.

Symptom

Every job that assumes a role through GitLab’s ID token fails at the aws sts assume-role-with-web-identity step, in every account the RCP covers. The step reports AccessDenied on the AssumeRoleWithWebIdentity operation, in the form GitLab’s troubleshooting page shows:

An error occurred (AccessDenied) when calling the AssumeRoleWithWebIdentity operation:
Not authorized to perform sts:AssumeRoleWithWebIdentity

Nothing changed in the project, the .gitlab-ci.yml, the IAM OIDC provider or the role’s trust policy. Workloads in the same accounts that authenticate as members of your organization carry on working, which makes the pipeline look like the odd one out.

Why the wider action list looks safe

The statement already denied sts:AssumeRole to principals outside the organization, and adding the rest of STS reads as closing an obvious gap. The GitLab CI role sits in one of your own accounts, so it feels like an insider. But the condition is about who makes the request, not where the role lives, and the job calling STS is a GitLab pipeline, not an AWS principal. The GitLab error list adds to the confusion: it names a missing OIDC setup, a branch or tag the trust policy doesn’t allow, and StringEquals used with a wildcard, all of which send you to a trust policy that has nothing wrong with it.

Root Cause

A federated OIDC caller never has aws:PrincipalOrgID in its request, so a StringNotEqualsIfExists deny on that key matches it every time. AWS documents the key as present only when the principal is a member of an organization, and its data perimeter examples state that federated users are not. IAM evaluates a missing key under an ...IfExists operator as true, and its documentation adds that a Deny with a negated operator such as StringNotEqualsIfExists still denies when the key is absent. RCPs apply to STS, and to every principal reaching a resource in an account they cover, whichever organization it comes from. A statement like this one blocks the job:

{
  "Sid": "EnforceOrgIdentities",
  "Effect": "Deny",
  "Principal": "*",
  "Action": ["s3:*", "sts:*", "kms:*"],
  "Resource": "*",
  "Condition": {
    "StringNotEqualsIfExists": { "aws:PrincipalOrgID": "o-exampleorgid" },
    "BoolIfExists": { "aws:PrincipalIsAWSService": "false" }
  }
}

AWS’s own identity-perimeter example lists its STS actions one by one for this reason. Its notes say sts:AssumeRoleWithSAML and sts:AssumeRoleWithWebIdentity are left out because federated users carry no organization ID, and sts:SetSourceIdentity and sts:TagSession are left out so that federation calls that set a source identity or pass session tags keep working.

Impact

With sts:* in the statement, every web identity and SAML federation into roles in the accounts under the RCP stops, not only GitLab. Deployments from other OIDC providers and AssumeRoleWithSAML calls hit the same deny. RCPs do not restrict resources in the management account, so a CI role kept there still works, which can make the cause look account-specific. The management account exemption for SCPs works the same way and catches people for the same reason.

The quick fixes under pressure all cost more than the outage. Detaching the RCP removes the identity perimeter from every resource it protected. Tagging the CI role to exclude it, where the policy has an exclusion tag like the example’s dp:exclude:identity, drops that role out of the organization check for sts:AssumeRole as well. Going back to access keys in GitLab CI/CD variables brings back the long-lived secret that OIDC federation exists to remove.

How to confirm the RCP is the cause

Run these from the management account or a delegated administrator, which is where Organizations allows them. None of them changes anything. Find where the CI account sits, then list the RCPs on the account and on each parent up to the root, since a deny attached at any level applies:

aws organizations list-parents --child-id 111122223333
aws organizations list-policies-for-target --target-id 111122223333 --filter RESOURCE_CONTROL_POLICY
aws organizations list-policies-for-target --target-id ou-exam-ple12345 --filter RESOURCE_CONTROL_POLICY
aws organizations describe-policy --policy-id p-examplepolicyid456 --query Policy.Content --output text

Ignore RCPFullAWSAccess, which Organizations attaches everywhere when RCPs are enabled and which allows everything through. In the others, look for a deny on sts:*, or on sts:AssumeRoleWithWebIdentity by name, conditioned on aws:PrincipalOrgID. Then, in the CI account, look up recent attempts:

aws cloudtrail lookup-events --region us-east-1 \
  --lookup-attributes AttributeKey=EventName,AttributeValue=AssumeRoleWithWebIdentity --max-results 20

Calls to the global endpoint, sts.amazonaws.com, are logged in US East (N. Virginia); calls to a Regional STS endpoint are logged in that Region, so change --region to match the job. Look for AccessDenied errors on those events, which is how AWS suggests judging an RCP’s effect. When an error message names a resource control policy, with or without its ARN, the case is closed; when it doesn’t, AWS’s guidance is still to check your RCPs for a matching deny.

Correction

Replace the policy in a single update that narrows the organization statement and adds the OIDC checks together. Before you start, save the current content (the describe-policy command above, redirected to rcp-before.json) and list the OIDC providers in every account the RCP covers:

aws iam list-open-id-connect-providers
  1. Change the organization statement’s action list to name STS actions individually, as AWS’s example does: sts:AssumeRole, sts:DecodeAuthorizationMessage, sts:GetAccessKeyInfo, sts:GetFederationToken, sts:GetServiceBearerToken, sts:GetSessionToken and sts:SetContext.
  2. Add a statement that denies sts:AssumeRoleWithWebIdentity when the token is from none of your trusted providers. Every provider you found in the previous step must be in its Null block, or its federation breaks next.
  3. Add a statement that denies tokens from GitLab.com unless the subject is in your group. GitLab.com is a multi-tenant provider, and its default subject is project_path:{group}/{project}:ref_type:{type}:ref:{branch_name}.
  4. Apply it with aws organizations update-policy --policy-id p-examplepolicyid456 --content file://rcp-after.json.
{
  "Sid": "EnforceTrustedOIDCProviders",
  "Effect": "Deny",
  "Principal": "*",
  "Action": "sts:AssumeRoleWithWebIdentity",
  "Resource": "*",
  "Condition": { "Null": { "gitlab.com:sub": "true" } }
},
{
  "Sid": "EnforceTrustedGitLabGroup",
  "Effect": "Deny",
  "Principal": "*",
  "Action": "sts:AssumeRoleWithWebIdentity",
  "Resource": "*",
  "Condition": {
    "StringNotLikeIfExists": { "gitlab.com:sub": "project_path:mygroup/*" },
    "Null": { "gitlab.com:sub": "false" }
  }
}

For GitLab Self-Managed or Dedicated the key is your instance’s host, for example gitlab.example.com:sub. These statements are a ceiling. The role’s trust policy still decides which project and branch may assume it. On GitLab.com, GitLab advises adding conditions on stable identifiers such as project_id, which stays the same through renames and transfers.

Validation

A retried GitLab job gets credentials, and the policy still denies STS to principals outside the organization. Check both:

  • Re-run the failed job. The aws sts get-caller-identity line from GitLab’s example prints the assumed-role ARN of the CI role.
  • Run lookup-events again. New AssumeRoleWithWebIdentity events for the role have no error code.
  • Read the updated content with describe-policy and confirm the organization statement no longer contains sts:* or AssumeRoleWithWebIdentity.
  • Watch CloudTrail for new AccessDenied errors across the covered accounts for the rest of the day.

Rollback

Put the saved content back with one command if the new version denies something it should not: aws organizations update-policy --policy-id p-examplepolicyid456 --content file://rcp-before.json. That brings back the original deny, and with it the GitLab outage, so treat it as a holding position while you correct the new statements, not as the fix. Stop and roll back if another team’s OIDC federation starts failing after the update; the most likely reason is a provider missing from the Null block.

Stop it happening on the next policy edit

AWS recommends attaching a changed RCP to test accounts first, then lower OUs, and moving up the tree only after CloudTrail shows no unexpected denials. Keep a test account with a GitLab project that federates through OIDC, so a pipeline run becomes part of that test. Never put a service wildcard in a statement conditioned on aws:PrincipalOrgID without checking which of its actions can be called by a principal that has no organization. Where other SCP and RCP traps apply, such as the root-specific deny that SCPs need, review them in the same change.

3

Apply the safer control

Before you change production

Confirm the affected scope, export the current configuration, and test the replacement control in a non-production environment first.

Fix commands and configuration

sts:*
sts:AssumeRoleWithWebIdentity
aws:PrincipalOrgID
4

When to escalate

Validation and rollback are covered in the sections above.

Escalate

Escalate when the blast radius is uncertain, the control cannot be tested safely, or remediation requires an outage or security exception.

The KBY Brief

Fixed? Get the next one before it hits you: The KBY Brief

Practical fixes for the systems you run, by email about twice a week. Unsubscribe at any time.

About this page

Credited to

Dates

Published

Corrections

No corrections are listed for this page. Some review sweeps corrected pages without naming each one; those are in the corrections log.

Was this useful?

Reports go to the site owner and are used to correct pages. Corrections are listed at /corrections.

After remediation

Further reading stays below the corrective workflow and is selected by platform, category and shared technical keywords.

More from KBY that goes with this config trap.

Discover more

Connected KBY resources