17 of 50 in All Controls
aws

Enforce OIDC for VCS CI/CD Connections to AWS

IDAWS-IAM-005
Severity
critical
Automation
Auto
Category
iam
Enforcementmandatory
Complexity / Impact
low(low impact)
Risk Profile
high likelihood(low residual)
Cloud Scopeaws:account
Environments
productionnon-production
Target Resources
OIDCIAM
Services
iamorganizationssts
Tags
oidccicdvcsgithubgitlabiamcredentialslanding-zone
Frameworks
CIS AWSNIST 800-53ISO 27001PCI DSSSOC 2AWS FSBP
Governance
cloud-security-team (quarterly)
Created
2026-05-03
Last Updated
2026-06-06

Specification & Description

Mandate the use of OIDC federation for all CI/CD pipeline connections from GitHub, GitLab or any other version control system (VCS) to central AWS accounts, eliminating long-lived IAM access keys from VCS secrets entirely.

Technical Specifications

CI/CD pipelines that deploy to or read from central landing zone accounts must authenticate via OIDC rather than static IAM access keys. In the OIDC flow, the VCS provider issues a short-lived JWT to the pipeline job, which exchanges it for temporary STS credentials by assuming an IAM role. The IAM role trust policy must include a condition on the sub claim to restrict which repositories and branches can assume the role - without this condition, any repository in the same GitHub organization or GitLab instance can assume the role. The SCP in enforcement_reference denies iam:CreateAccessKey for any principal that is not an explicitly approved role, preventing pipelines from creating new static credentials as a bypass. Existing access keys stored as VCS secrets must be audited and rotated to OIDC before the SCP Deny takes effect.

Security Rationale

Long-lived IAM access keys stored as VCS secrets are the most common source of AWS credential leaks. They appear in logs, get committed to repositories, are copied between environments, and persist long after the pipeline that needed them is decommissioned. OIDC credentials are valid for 15 minutes by default, are never stored, and are scoped to the specific job that requested them. A leaked OIDC token is worthless seconds after the job completes.

Business & Security Impact

A leaked static access key stored in a VCS secret provides persistent access to the central account until the key is manually rotated. In a landing zone account, this can expose CloudTrail logs, Config history, backup recovery points, and KMS keys. OIDC migration may require pipeline changes in all repositories that currently use static credentials - an inventory and migration plan are required before applying the SCP.

Policy Exceptions (2)

Legacy pipeline tooling that does not support OIDC token exchange may retain a time-limited IAM access key while a migration plan is in progress. The key must have no console access, must be rotated every 90 days, must be scoped to the minimum required permissions, and the exception must be renewed quarterly with documented progress toward OIDC migration.

Self-hosted GitLab instances use a different OIDC URL than gitlab.com. The OIDC provider URL must match the self-hosted instance URL exactly. The thumbprint must be retrieved from the instance's OIDC discovery endpoint and verified independently.

Operational & Implementation Notes

The sub claim is the critical security boundary in OIDC role trust policies. A trust policy that conditions only on aud (audience) allows any repository in the same GitHub organization or GitLab instance to assume the role - this is a common misconfiguration. Always scope sub to the specific repository and branch or environment. Use StringLike with a wildcard only when multiple repositories in the same org legitimately need the same role. For self-hosted GitLab, thumbprint validation is required and the correct value must be retrieved from the instance.

Compliance Framework Mappings (6)

Regulatory baselines and industry standards mapped to this control specification.

Beta
Framework / StandardMapped Requirements & ControlsControls
CIS AWS Foundations Benchmark v3.0CIS AWS
1.14
1
NIST 800-53 Rev 5NIST 800-53
IA-2IA-5
2
ISO 27001:2022ISO 27001
A.8.5
1
PCI DSS v4.0PCI DSS
8.2.1
1
SOC 2SOC 2
CC6.1
1
AWS Foundational Security Best PracticesAWS FSBP
IAM.1
1

* Compliance framework mappings are provided for informational architectural reference. Always verify control alignment against your organization's formal audit requirements.

Automated Detection & Rule Logic

Detection Engine: aws-api • Automated: Yes

Detection operates at two levels. First, verify that OIDC providers for GitHub and GitLab exist in the account. Second, and more critically, scan all IAM roles whose trust policies reference the OIDC providers and verify that each trust policy includes a sub claim condition - a role without this condition allows any repository in the org to assume it. Additionally, scan for active IAM access keys owned by users whose names suggest CI/CD usage (e.g. containing "ci", "deploy", "pipeline") as an indicator that OIDC migration is incomplete.

Verify OIDC Providersbash
# Confirm OIDC providers exist
aws iam list-open-id-connect-providers \
  --query "OpenIDConnectProviderList[*].Arn" \
  --output table

# Find IAM roles that trust the GitHub OIDC provider
# and check whether a sub condition is present
aws iam list-roles \
  --query "Roles[*].{Name:RoleName,Trust:AssumeRolePolicyDocument}" \
  --output json | \
  python3 -c "
import sys, json
roles = json.load(sys.stdin)
for r in roles:
    doc = r['Trust']
    for stmt in doc.get('Statement', []):
        principal = stmt.get('Principal', {})
        federated = principal.get('Federated', '')
        if 'token.actions.githubusercontent.com' in str(federated) or \
           'gitlab.com' in str(federated):
            cond = stmt.get('Condition', {})
            has_sub = any(
                'sub' in str(k).lower()
                for k in cond.get('StringEquals', {}) | cond.get('StringLike', {})
            )
            status = 'SCOPED' if has_sub else 'UNSCOPED (risk)'
            print(f\"{status}: {r['Name']}\")
"

Preventative Enforcement Policies

Deny Access Key Creationjson
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "DenyAccessKeyCreationForCICD",
      "Effect": "Deny",
      "Action": "iam:CreateAccessKey",
      "Resource": "*",
      "Condition": {
        "ArnNotLike": {
          "aws:PrincipalArn": [
            "arn:aws:iam::*:role/LandingZoneAdminRole"
          ]
        }
      }
    }
  ]
}
GitHub OIDC Rolejson
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "AllowGitHubOIDC",
      "Effect": "Allow",
      "Principal": {
        "Federated": "arn:aws:iam::ACCOUNT-ID:oidc-provider/token.actions.githubusercontent.com"
      },
      "Action": "sts:AssumeRoleWithWebIdentity",
      "Condition": {
        "StringEquals": {
          "token.actions.githubusercontent.com:aud": "sts.amazonaws.com"
        },
        "StringLike": {
          "token.actions.githubusercontent.com:sub": [
            "repo:MY-ORG/MY-REPO:ref:refs/heads/main",
            "repo:MY-ORG/MY-REPO:environment:production"
          ]
        }
      }
    }
  ]
}
GitLab OIDC Rolejson
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "AllowGitLabOIDC",
      "Effect": "Allow",
      "Principal": {
        "Federated": "arn:aws:iam::ACCOUNT-ID:oidc-provider/gitlab.com"
      },
      "Action": "sts:AssumeRoleWithWebIdentity",
      "Condition": {
        "StringEquals": {
          "gitlab.com:sub": "project_path:MY-GROUP/MY-PROJECT:ref_type:branch:ref:main",
          "gitlab.com:namespace_id": "12345",
          "gitlab.com:project_id": "12345"
        }
      }
    }
  ]
}

Remediation Guide & Automation

Create the OIDC identity provider in IAM for GitHub and/or GitLab. Create a scoped IAM role with the trust policy from enforcement_reference. Update pipelines to use the OIDC authentication action. Audit and remove all existing static access keys from VCS secrets.

Step-by-Step Instructions

  1. Create the OIDC identity provider in IAM for each VCS in use (GitHub, GitLab, ...).
  2. Create an IAM role with a trust policy scoped to specific repositories and branches using the sub claim condition.
  3. Attach the minimum required IAM policy to the role - never AdministratorAccess.
  4. Update CI/CD pipelines to use OIDC authentication (aws-actions/configure-aws-credentials@v4 for GitHub; id_tokens for GitLab).
  5. Audit all VCS secrets for AWS_ACCESS_KEY_ID values and rotate to OIDC.
  6. Apply the SCP from enforcement_reference after all pipelines are migrated.
Create OIDC Providersbash
# GitHub Actions OIDC provider
aws iam create-open-id-connect-provider \
  --url https://token.actions.githubusercontent.com \
  --client-id-list sts.amazonaws.com \

# GitLab OIDC provider
aws iam create-open-id-connect-provider \
  --url https://gitlab.com \
  --client-id-list https://gitlab.com \

# Verify both providers exist
aws iam list-open-id-connect-providers \
  --output table
OIDC Provider and Scoped Rolehcl
resource "aws_iam_openid_connect_provider" "github" {
  url             = "https://token.actions.githubusercontent.com"
  client_id_list  = ["sts.amazonaws.com"]
  thumbprint_list = ["6938fd4d98bab03faadb97b34396831e3780aea1"]
}

resource "aws_iam_role" "github_cicd" {
  name = "github-cicd-role"

  assume_role_policy = jsonencode({
    Version = "2012-10-17"
    Statement = [{
      Sid    = "AllowGitHubOIDC"
      Effect = "Allow"
      Principal = {
        Federated = aws_iam_openid_connect_provider.github.arn
      }
      Action = "sts:AssumeRoleWithWebIdentity"
      Condition = {
        StringEquals = {
          "token.actions.githubusercontent.com:aud" = "sts.amazonaws.com"
        }
        StringLike = {
          "token.actions.githubusercontent.com:sub" = [
            "repo:${var.github_org}/${var.github_repo}:ref:refs/heads/main",
            "repo:${var.github_org}/${var.github_repo}:environment:production"
          ]
        }
      }
    }]
  })
}
GitHub Actions: OIDC Deployment Pipeline (.github/workflows/deploy.yml)yaml
name: Deploy to AWS via OIDC

on:
  push:
    branches:
      - main

# Mandatory: Grant the workflow permission to request an OIDC JWT from GitHub
permissions:
  id-token: write # Required for requesting the JWT from GitHub Actions
  contents: read  # Required for repository checkout

jobs:
  deploy:
    name: Assume IAM Role and Deploy
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Repository
        uses: actions/checkout@v4

      # Exchange short-lived GitHub OIDC JWT for temporary AWS STS credentials
      - name: Configure AWS Credentials via OIDC
        uses: aws-actions/configure-aws-credentials@v4
        with:
          role-to-assume: arn:aws:iam::111122223333:role/github-cicd-role
          aws-region: us-east-1

      # Verify authenticated IAM identity
      - name: Verify STS Caller Identity
        run: |
          aws sts get-caller-identity

Cross-Cloud Policy Equivalence

Equivalent controls across multi-cloud provider platforms.

We value your privacy

We use analytics cookies to understand how visitors interact with our site and to improve the user experience. You can choose to accept or decline these cookies.