Skip to content
Go back

Creating an AWS IAM Role with GitHub as a Web Identity Provider

Published:  at  09:30 AM

To enable your GitHub Actions workflows to securely interact with AWS services, you can set up OIDC (OpenID Connect) authentication. By configuring GitHub as a Web Identity Provider, you can create an IAM role that GitHub Actions can assume without needing AWS credentials. Here’s how you can set this up.

Step 1: Sign in to AWS Management Console

Step 2: Navigate to Identity Providers

Step 3: Add a New Identity Provider

Step 4: Create an IAM Role for GitHub Actions

Step 4: Define the Trust Relationship for the Role

Here’s an example trust policy:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": "sts:AssumeRoleWithWebIdentity",
            "Principal": {
                "Federated": "arn:aws:iam::<account-id>:oidc-provider/token.actions.githubusercontent.com"
            },
            "Condition": {
                "StringEquals": {
                    "token.actions.githubusercontent.com:aud": [
                        "sts.amazonaws.com"
                    ]
                },
                "StringLike": {
                    "token.actions.githubusercontent.com:sub": [
                        "repo:<owner>/<repo>"
                    ]
                }
            }
        }
    ]
}

Step 5: Attach Permissions to the IAM Role

Step 6: Review and Create the Role

Step 7: Configure GitHub Actions Workflow

Here’s an example of the step to configure AWS credentials:

- name: Configure AWS credentials
  uses: aws-actions/configure-aws-credentials@v4
  with:
    role-to-assume: arn:aws:iam::<account-id>:role/<role-name>
    role-duration-seconds: 3600
    aws-region: <aws-region>

Conclusion

Now your GitHub Actions workflow can securely interact with AWS services using OIDC authentication, eliminating the need for static access keys. By following these steps, you’ll enhance security and streamline the process of automating deployments and other tasks.

Happy provisioning!


Suggest Changes

Previous Post
Easily Publish Private Packages to AWS CodeArtifact via GitHub Actions Workflow
Next Post
What Happens to sessionStorage When You Duplicate a Tab?