Orchestrating Secure AWS Identity for GitHub Actions CI/CD Pipelines

Integrating Amazon Web Services with GitHub Actions requires a robust mechanism for handling authentication credentials within continuous integration and continuous deployment pipelines. The primary objective is to enable automated workflows to authenticate against AWS services—such as S3, EC2, and Lambda—without exposing sensitive static credentials in repository code. The aws-actions/configure-aws-credentials action serves as the foundational tool for this integration, configuring environment variables that are automatically detected by the AWS Software Development Kits (SDKs) and the AWS Command Line Interface (CLI). This configuration determines the specific credentials and AWS region used for subsequent API calls, ensuring that deployments, testing, and other automated tasks execute securely and seamlessly across diverse cloud environments.

Authentication Mechanisms and Credential Strategies

The action supports multiple authentication strategies, ranging from legacy IAM user credentials to modern, secure Identity Provider (IdP) integrations. Understanding the nuances of each method is critical for maintaining security hygiene and adhering to least-privilege principles.

OpenID Connect (OIDC) and Role Assumption

The most secure and recommended approach involves assuming an IAM role directly using the GitHub OIDC provider. This method eliminates the need for long-lived IAM user credentials entirely. When configured this way, the action loads the OIDC token from a GitHub-provided environment variable and uses it to assume a specific role. The workflow requires specific permissions to interact with GitHub's OIDC Token endpoint, namely id-token: write and contents: read.

  • name: Configure AWS Credentials
    uses: aws-actions/configure-aws-credentials@v1
    with:
    aws-region: us-east-2
    role-to-assume: arn:aws:iam::123456789100:role/my-github-actions-role
    role-session-name: MySessionName

In this configuration, the action assumes the role specified by the ARN (e.g., arn:aws:iam::123456789100:role/my-github-actions-role) and assigns a session name. This approach is ideal for production environments where credential rotation is managed automatically by the identity provider rather than through manual secret updates.

IAM User Credentials and External IDs

For scenarios where direct OIDC is not feasible, the action supports authentication via IAM user credentials. These credentials must be stored as GitHub repository secrets, specifically AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY. Best practices dictate that these credentials be granted least privilege and never stored directly in the repository code.

  • name: Configure AWS Credentials
    uses: aws-actions/configure-aws-credentials@v1
    with:
    aws-access-key-id: ${{ secrets.AWSACCESSKEYID }}
    aws-secret-access-key: ${{ secrets.AWS
    SECRETACCESSKEY }}
    aws-region: us-east-2
    role-to-assume: ${{ secrets.AWSROLETOASSUME }}
    role-external-id: ${{ secrets.AWS
    ROLEEXTERNALID }}
    role-duration-seconds: 1200
    role-session-name: MySessionName

This configuration allows for the assumption of a role using existing IAM user credentials, often enhanced with an external ID for added security. The role-duration-seconds parameter permits the specification of a custom session duration, such as 1200 seconds, allowing for temporary, time-bound access that reduces the risk of credential compromise.

Web Identity Token Files

In containerized environments, such as Amazon Elastic Kubernetes Service (EKS), pods running on worker nodes that do not operate as root can utilize a web identity token file to assume a role. This is particularly relevant for self-hosted runners or hybrid cloud setups where the runner executes within an EKS cluster.

  • name: Configure AWS Credentials
    uses: aws-actions/configure-aws-credentials@v1
    with:
    aws-region: us-east-2
    role-to-assume: my-github-actions-role
    web-identity-token-file: /var/run/secrets/eks.amazonaws.com/serviceaccount/token

This method leverages the service account token mounted in the pod, enabling secure role assumption without the need for static credentials or OIDC providers configured at the GitHub organization level.

Multi-Account and Multi-Region Workflows

One of the significant advantages of the configure-aws-credentials action is its ability to be invoked multiple times within a single GitHub Actions workflow job. This capability is essential for multi-account deployments or scenarios requiring interaction with different AWS environments—such as testing and production—without interrupting the workflow.

The action configures environment variables that are detected by subsequent steps. Therefore, re-running the action with different parameters effectively switches the context for all following AWS CLI commands or SDK calls.

jobs:
deploy:
name: Upload to Amazon S3
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Configure AWS credentials from Test account
uses: aws-actions/configure-aws-credentials@v1
with:
role-to-assume: arn:aws:iam::111111111111:role/my-github-actions-role-test
aws-region: us-east-1
- name: Copy files to the test website with the AWS CLI
run: |
aws s3 sync . s3://my-s3-test-website-bucket
- name: Configure AWS credentials from Production account
uses: aws-actions/configure-aws-credentials@v1
with:
role-to-assume: arn:aws:iam::222222222222:role/my-github-actions-role-prod
aws-region: us-west-2
- name: Copy files to the production website with the AWS CLI
run: |
aws s3 sync . s3://my-s3-prod-website-bucket

In this example, the workflow first configures credentials for a test environment in the us-east-1 region, deploys to a test S3 bucket, re-configures credentials for a production environment in the us-west-2 region, and finally deploys to the production S3 bucket. This sequential reconfiguration allows for complex, multi-stage deployments within a single job, streamlining the CI/CD pipeline structure.

Workflow Configuration and Secret Management

Proper setup of GitHub Actions secrets is a prerequisite for using IAM user credentials. The process involves creating a repository, navigating to the "Secrets and Variables" section under repository settings, selecting "Actions," and creating new repository secrets. Common secrets include AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_ROLE_TO_ASSUME, and AWS_ROLE_EXTERNAL_ID.

A basic workflow file demonstrating the use of these secrets for deployment is as follows:

name: AWS Deployment
on:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Deploy to AWS
run: |
aws configure set awsaccesskeyid ${{ secrets.AWSACCESSKEYID }}
aws configure set awssecretaccesskey ${{ secrets.AWSSECRETACCESSKEY }}
aws s3 cp ./dist s3://example-bucket --recursive

While this manual configuration using aws configure set works, it is generally less preferred than using the dedicated configure-aws-credentials action, which manages the environment variables more cleanly and supports additional features like role assumption and OIDC. However, it illustrates the fundamental mechanism of injecting secrets into the runner environment to authenticate AWS CLI commands.

Versioning, Licensing, and Security Considerations

Starting with version 5.0.0, the action utilizes semantic-style release tags and immutable releases. A floating version tag (e.g., vN) is provided for convenience, pointing to the latest major version, though pinning to specific immutable versions is recommended for production stability to prevent unexpected breaking changes. The code is distributed under the MIT license.

Security is paramount when dealing with cloud credentials. The action is not certified by GitHub but is provided by a third party, governed by separate terms of service and privacy policies. Users are advised to follow Amazon IAM best practices, including:

  • Do not store credentials in the repository code.
  • Grant least privilege to the credentials used in GitHub Actions workflows.
  • Report potential security issues directly through AWS security channels or the project's vulnerability reporting page, rather than creating public GitHub issues.

It is also important to note that the action does not install the AWS CLI into the environment. While most GitHub-hosted runner environments include the AWS CLI by default, self-hosted runners must ensure the CLI is installed prior to executing AWS commands.

Conclusion

The configure-aws-credentials action provides a flexible and secure foundation for integrating AWS services into GitHub Actions workflows. By supporting OIDC role assumption, IAM user credentials, and web identity tokens, it caters to a wide range of deployment architectures, from simple single-account setups to complex multi-account, multi-region environments. The ability to reconfigure credentials within a single job allows for streamlined CI/CD pipelines that can deploy to multiple environments without additional complexity. Adhering to security best practices, such as using least-privilege roles, leveraging OIDC to avoid static credentials, and properly managing secrets, ensures that these automated processes remain secure and reliable. As the action evolves with semantic versioning and immutable releases, developers can maintain stable and secure integrations with confidence.

Sources

  1. Configure AWS Credentials V2 Action for GitHub Actions
  2. Setting AWS Credentials in GitHub Actions
  3. Configure AWS Credentials Action for GitHub Actions

Related Posts