Skip to main content

AWS CDK Github OpenID Connect

cdk-support release codecov


AWS CDK constructs that define:

  • Github Actions as OpenID Connect Identity Provider into AWS IAM
  • IAM Roles that can be assumed by Github Actions workflows

These constructs allows you to harden your AWS deployment security by removing the need to create long-term access keys for Github Actions and instead use OpenID Connect to Authenticate your Github Action workflow with AWS IAM.

Background information

github-aws-oidc


Getting started

pnpm add -D aws-cdk-github-oidc

OpenID Connect Identity Provider trust for AWS IAM

To create a new Github OIDC provider configuration into AWS IAM:

import { GithubActionsIdentityProvider } from "aws-cdk-github-oidc";

const provider = new GithubActionsIdentityProvider(scope, "GithubProvider");

In the background this creates an OIDC provider trust configuration into AWS IAM with an issuer URL of https://token.actions.githubusercontent.com and audiences (client IDs) configured as ['sts.amazonaws.com'] (which matches the aws-actions/configure-aws-credentials implementation).


Retrieving a reference to an existing Github OIDC provider configuration

Remember, there can be only one (Github OIDC provider per AWS Account), so to retrieve a reference to existing Github OIDC provider use fromAccount static method:

import { GithubActionsIdentityProvider } from "aws-cdk-github-oidc";

const provider = GithubActionsIdentityProvider.fromAccount(
  scope,
  "GithubProvider"
);

Defining a role for Github Actions workflow to assume

import { GithubActionsRole } from "aws-cdk-github-oidc";

const uploadRole = new GithubActionsRole(scope, "UploadRole", {
  provider: provider, // reference into the OIDC provider
  owner: "octo-org", // your repository owner (organization or user) name
  repo: "octo-repo", // your repository name (without the owner name)
  filter: "ref:refs/tags/v*", // JWT sub suffix filter, defaults to '*'
});

// use it like any other role, for example grant S3 bucket write access:
myBucket.grantWrite(uploadRole);

You may pass in any iam.RoleProps into the construct's props, except assumedBy which will be defined by this construct (CDK will fail if you do):

const deployRole = new GithubActionsRole(scope, "DeployRole", {
  provider: provider,
  owner: "octo-org",
  repo: "octo-repo",
  roleName: "MyDeployRole",
  description: "This role deploys stuff to AWS",
  maxSessionDuration: cdk.Duration.hours(2),
});

// You may also use various "add*" policy methods!
// "AdministratorAccess" not really a good idea, just for an example here:
deployRole.addManagedPolicy(
  iam.ManagedPolicy.fromAwsManagedPolicyName("AdministratorAccess")
);

Subject Filter

By default the value of filter property will be '*' which means any workflow (from given repository) from any branch, tag, environment or pull request can assume this role. To further stricten the OIDC trust policy on the role, you may adjust the subject filter as seen on the examples in Github Docs; For example:

filter value Descrition
'ref:refs/tags/v*' Allow only tags with prefix of v
'ref:refs/heads/demo-branch' Allow only from branch demo-branch
'pull_request' Allow only from pull request
'environment:Production' Allow only from Production environment

Immutable Subject

Give both ownerId and repoId to form the trust policy with an immutable subject:

const deployRole = new GithubActionsRole(scope, "DeployRole", {
  provider: provider,
  owner: "octo-org",
  repo: "octo-repo",
  ownerId: "123456", // your repository owner ID
  repoId: "456789", // your repository ID
  filter: "ref:refs/tags/v*",
});

Which results in a subject condition of repo:octo-org@123456/octo-repo@456789:ref:refs/tags/v* instead of repo:octo-org/octo-repo:ref:refs/tags/v*. Both properties must be given together, as CDK will fail if you only provide one of them.


Github Actions Workflow

To actually utilize this in your Github Actions workflow, use aws-actions/configure-aws-credentials to assume a role.

jobs:
  whoami:
    name: Who Am I
    runs-on: ubuntu-latest
    permissions:
      id-token: write # needed to interact with GitHub's OIDC Token endpoint.
    steps:
      - name: Configure AWS credentials
        uses: aws-actions/configure-aws-credentials@d979d5b3a71173a29b74b5b88418bfda9437d885 # v6.1.1
        with:
          role-to-assume: arn:aws:iam::123456789012:role/MyUploadRole
          #role-session-name: MySessionName # Optional
          aws-region: us-east-1
      - name: Get Caller Identity
        run: |
          aws sts get-caller-identity

Migration Guide

v2→v3

  1. Install AWS CDK version v2.237.0 or newer required (due to support of OIDC provider removal policy):

    pnpm add -D aws-cdk-lib@^2.237.0
    
  2. Install v3.1.0 (or newer v3 release) of this library:

    pnpm add -D aws-cdk-github-oidc@^3.1
    
  3. No additional steps required, as the v3 major version does not introduce any breaking changes (just a lot of internal tooling changes).

v3→v4

  1. Ensure you are running v3.1.0 (or newer v3 release) of this library, see v2→v3.

  2. Configure RETAIN removal policy for the provider:

    const provider = new GithubActionsIdentityProvider(this, "GithubProvider", {
    +  removalPolicy: cdk.RemovalPolicy.RETAIN,
    });
    
  3. Run pnpm exec cdk diff, which will show an output similar to:

    Resources
    [~] Custom::AWSCDKOpenIdConnectProvider GithubProvider/Resource GithubProvider1CDE27EB
    ├─ [~] DeletionPolicy
    │   ├─ [-] Delete
    │   └─ [+] Retain
    └─ [~] UpdateReplacePolicy
        ├─ [-] Delete
        └─ [+] Retain
    
  4. Deploy the changes pnpm exec cdk deploy

  5. Once the RETAIN removal policy has been successfully deployed, upgrade this library to v4.2 (or newer v4 release):

    pnpm add -D aws-cdk-github-oidc@^4.2
    
  6. Temporarily change from provider initializion to provider lookup:

    - const provider = new GithubActionsIdentityProvider(this, "GithubProvider", {
    -  removalPolicy: cdk.RemovalPolicy.RETAIN,
    - });
    + const provider = GithubActionsIdentityProvider.fromAccount(this, "GithubProviderReference"); // NOTICE the different construct ID
    

    ⚠️ Notice the different construct ID (in the example GithubProviderReference instead of GithubProvider). This is required so that the CDK treats the GitHub OIDC provider lookup as a different "thing" and does not try to change the type of existing construct.

  7. Check pnpm exec cdk diff which should look similar to:

    Resources
    [-] Custom::AWSCDKOpenIdConnectProvider GithubProvider/Resource GithubProvider1CDE27EB orphan
    [-] AWS::IAM::Role Custom::AWSCDKOpenIdConnectProviderCustomResourceProvider/Role CustomAWSCDKOpenIdConnectProviderCustomResourceProviderRole517FED65 destroy
    [-] AWS::Lambda::Function Custom::AWSCDKOpenIdConnectProviderCustomResourceProvider/Handler CustomAWSCDKOpenIdConnectProviderCustomResourceProviderHandlerF2C543E0 destroy
    
  8. Deploy the changes with pnpm exec cdk deploy

  9. Once the deployment has succeeded, remove the provider lookup and replace it with the original provider initialization:

    - const provider = GithubActionsIdentityProvider.fromAccount(this, "GithubProviderReference");
    + const provider = new GithubActionsIdentityProvider(this, "GithubProvider", {
    +  removalPolicy: cdk.RemovalPolicy.RETAIN,
    + });
    
  10. Copy the ARN of the existing OIDC provider, it will be in the format of:

    arn:aws:iam::123456789012:oidc-provider/token.actions.githubusercontent.com # REPLACE with your account ID
    
  11. Use cdk import:

    pnpm exec cdk import <YOUR_STACK_NAME>
    

    ... and when asked, input the provider ARN you copied in step 10:

    <YOUR_STACK_NAME>/GithubProvider/Resource (AWS::IAM::OIDCProvider): enter Arn (empty to skip)
    
  12. You should be done now, but you may want to perform manual verification in addition to drift detection and/or `cdk diff`` to verify.

Metadata

Release files for aws-cdk-github-oidc 5.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aws-cdk-github-oidc 5.1.1
File Size Uploaded
aws_cdk_github_oidc-5.1.1.tar.gz 127.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for aws-cdk-github-oidc 5.1.1
File Interpreter ABI Platform
aws_cdk_github_oidc-5.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 252.0 kB

Release files / aws_cdk_github_oidc-5.1.1.tar.gz

Download URL aws_cdk_github_oidc-5.1.1.tar.gz
Size 127.0 kB
Tags Source
SHA-256 checksum
How to use checksums
3edac2f3b765a299db0d7d39a76d61fef73a41f8912f6e3275b5fee7287d3f27
BLAKE2b-256 checksum
How to use checksums
7a9d5a940a46ba3d919e79abe7c530f7e0719ac727c64c47daffb255b0f9f7d4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.14.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 23, 2026.

Transparency log

Release files / aws_cdk_github_oidc-5.1.1-py3-none-any.whl

Download URL aws_cdk_github_oidc-5.1.1-py3-none-any.whl
Size 125.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2bcf43980b7d548f3d84438ba907298ddfa164668469010db89de9311d3dcb3f
BLAKE2b-256 checksum
How to use checksums
e47ea23ffeb2d7bbc9b7d28251940c0ffa1a38118e7f42a44116d1730039f78c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.14.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 23, 2026.

Transparency log

Release history Release notifications | RSS feed

5.2.0

2 release files

This release

5.1.1 This release

2 release files

5.1.0

2 release files

5.0.2

2 release files

5.0.1

2 release files

5.0.0

2 release files

4.2.6

2 release files

4.2.5

2 release files

4.2.4

2 release files

4.2.3

2 release files

4.2.2

2 release files

4.2.1

2 release files

4.2.0

2 release files

4.1.2

2 release files

4.1.1

2 release files

4.1.0

2 release files

4.0.0

2 release files

3.1.1

2 release files

3.1.0

2 release files

3.0.0

2 release files

2.4.1

2 release files

2.4.0

2 release files

2.3.5

2 release files

2.3.4

2 release files

2.3.3

2 release files

2.3.2

1 release file

2.3.1

2 release files

2.2.1

2 release files

2.2.0

2 release files

2.1.0

2 release files

2.0.0

2 release files

1.1.0

2 release files

1.0.0

2 release files

0.0.23

2 release files

0.0.22

2 release files

0.0.21

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.6

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page