Deploying from GitHub Actions
This page covers GitHub Actions workflows that deploy an application or service to a cloud provider or another environment. For publishing packages and images, see the CI/CD language pages. For project websites, see Project Documentation.
Log in with OpenID Connect, not stored keys
Avoid storing long-lived cloud credentials, such as an AWS_SECRET_ACCESS_KEY, as repository secrets. Instead, configure the cloud provider to trust GitHub's OpenID Connect (OIDC) tokens. The workflow then gets short-lived credentials for each run, and there is no key to leak or rotate.
The job that logs in needs permissions: id-token: write. GitHub documents the setup for each provider:
- Amazon Web Services, with
aws-actions/configure-aws-credentials - Azure, with
azure/login - Google Cloud, with
google-github-actions/auth
When you set up the trust on the cloud side, restrict it to your repository and, for production, to a specific environment (see below), so that a workflow in another repository or branch cannot assume the same role.
FINOS examples that log in to AWS, Azure and Google Cloud with OIDC include tracdap and common-cloud-controls.
Protect production with environments
A job that sets environment: runs in a GitHub deployment environment. Environments can have protection rules, such as required reviewers, a wait timer, or a list of branches allowed to deploy, and can hold their own secrets and variables, which only jobs in that environment can read. Use a protected environment for production deployments.
Avoid overlapping deployments with concurrency:
Set concurrency: so that only one deployment to an environment runs at a time. With cancel-in-progress: false, a newer run waits for the current deployment to finish instead of cancelling it partway through.
Example
The following workflow deploys to AWS when a change is pushed to main. It runs in a production environment, logs in with OIDC, and never runs two deployments at once:
name: Deploy
on:
push:
branches: [main]
permissions:
contents: read
concurrency:
group: deploy-production
cancel-in-progress: false
jobs:
deploy:
runs-on: ubuntu-latest
environment: production
permissions:
contents: read
id-token: write # OIDC login to AWS
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@45666896f5d8e0f10ae255413f3a4cdd03bdc8f5 # v6.3.1
with:
role-to-assume: ${{ vars.AWS_DEPLOY_ROLE_ARN }}
aws-region: us-east-1
- name: Deploy
run: ./scripts/deploy.sh # replace with your project's deploy command
The IAM role's trust policy can then require the token's sub claim to be repo:finos/<repository>:environment:production.