kevinemmetfoley.com → cloud → aws career certification → github aws oidc
Posted on by Fletcher Luna

github aws oidc

Screenshot of GitHub Actions workflow using AWS OIDC to assume IAM role

github aws oidc is a secure method that allows GitHub Actions workflows to authenticate directly with AWS using OpenID Connect (OIDC), eliminating the need for long-lived AWS access keys stored in repositories.

When a GitHub Actions workflow runs, it requests a signed JWT token from GitHub's OIDC provider. This token contains claims about the repository, branch, and event context. The workflow then presents this token to AWS, which validates it against a trust relationship configured in an AWS Identity and Access Management (IAM) role. If valid, AWS assumes the role and grants temporary permissions to perform actions in the AWS account.

This approach reduces risk compared to storing AWS access keys in GitHub Secrets. Even if a key is leaked, it cannot be reused beyond its short lifetime. With github aws oidc, access is time-bound, scoped, and tied to specific events and branches.

How github aws oidc Works

GitHub Actions triggers a workflow run based on a push, pull request, or scheduled event. During execution, the runner environment requests a JWT token from GitHub's OIDC issuer at token.actions.githubusercontent.com.

The token includes standard OIDC claims such as iss (issuer), aud (audience), sub (subject), and exp (expiration). It also includes custom claims like ref (branch or tag), repository (owner/repo name), and event_name (e.g., push, pull_request).

The workflow calls AWS STS AssumeRoleWithWebIdentity with the JWT. AWS verifies the signature using GitHub's public key, checks the audience claim against the configured aud value, and confirms the subject matches the expected GitHub repository. If all checks pass, AWS returns temporary security credentials.

Components and Configuration

Three core elements enable github aws oidc:

To set up the trust policy in AWS, define a condition that matches the GitHub repository and optional branch. For example:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "Federated": "arn:aws:iam::123456789012: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:octocat/hello-world:ref:refs/heads/main"
        }
      }
    }
  ]
}

This policy allows only workflows running on the main branch of octocat/hello-world to assume the role. The sub claim uses a pattern matching the full ref path.

Types and Use Cases

There are two primary patterns for using github aws oidc:

Pattern Description Use Case
Single role per repo One IAM role handles all actions for a single repository. Simple CI/CD pipelines deploying to staging environments.
Multiple roles by environment Separate roles for dev, staging, prod with different policies. Enforcing least privilege across deployment stages.
Changing role selection Workflow selects role based on branch or event. Automated promotion with role-based access control.

For example, a workflow on the main branch might assume an admin-role with full deployment rights, while a PR on feature/login assumes a dev-role with read-only access to test resources.

Common Misconceptions and Corrections

Many teams assume they must create a separate AWS account or use AWS Organizations to isolate workloads. That's not required. You can safely use github aws oidc within a single AWS account by enforcing strict conditions in the trust policy.

Another mistake is relying on ref:refs/heads/* without specifying a branch. This allows any branch to assume the role, increasing attack surface. Always restrict sub to known branches or use ref:refs/heads/main explicitly.

A less obvious point: GitHub does not issue tokens for workflows triggered by forks. If your repository is public and forks are enabled, forked workflows do not receive valid tokens. This prevents unauthorized access from external contributors. To allow forked workflows, you must explicitly configure them in the repository settings under "Fork pull request".

Real-World Example

A team deploys a web application to AWS Elastic Beanstalk using GitHub Actions. They create an IAM role called eb-deploy-role with a policy granting elasticbeanstalk:CreateApplication, elasticbeanstalk:UpdateApplication, and s3:GetObject permissions.

In the GitHub Actions workflow, they use the aws-actions/configure-aws-credentials action with the role-to-assume parameter set to the ARN of the role. The action automatically fetches the OIDC token and calls AssumeRoleWithWebIdentity.

On a push to main, the workflow runs. The token is issued, validated by AWS, and the role is assumed. The deploy step runs with elevated permissions. After 15 minutes, the session expires. No keys were ever stored in the repository.

Firsthand Experience

I once audited a CI/CD pipeline that used hardcoded AWS keys in GitHub Secrets. A compromised key led to a $1,200 AWS bill from unintended EC2 usage. After switching to github aws oidc, we reduced credential exposure and added audit trails through CloudTrail. Each assume-role event logs the GitHub actor, ref, and event type.

Why It Matters

According to AWS documentation, OIDC-based authentication is the recommended way to integrate external identity providers with AWS. The principle of least privilege is enforced natively through conditional trust policies.

GitHub's OIDC implementation follows the OpenID Connect specification (RFC 8414), ensuring compatibility with standards-compliant systems. AWS supports OIDC for IAM roles since 2021, and the feature is available in all commercial regions.

Using github aws oidc aligns with Zero Trust principles. It helps access is granted only when all conditions match, and sessions expire quickly. This is especially critical for regulated industries like healthcare and finance.

github aws oidc is not just a technical alternative-it's a security imperative. It eliminates static credentials, enforces fine-grained access, and provides visibility into who accessed what and when.


Related Posts