Sub topic 1
Why long-lived access keys are a problem in CI
Prerequisites
This chapter assumes you know basic GitHub Actions workflows (jobs, steps, triggers), AWS IAM concepts (users, roles, policies), and basic AWS CLI usage. You should also be able to read YAML and JSON.
The usual setup
Many pipelines deploy to AWS with an IAM user's access key stored in GitHub secrets. The workflow reads the key and exports it as environment variables:
name: deploy-with-static-keys
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Deploy site
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: us-east-1
run: aws s3 sync ./site s3://my-example-bucket --deleteThis works, which is why it is common. The problems show up later.
Where the risk comes from
An access key is a bearer credential. Whoever holds the two strings can act as the IAM user, from any machine, at any time.
- No expiry. The key stays valid until someone deactivates it. A key leaked a year ago still works today.
- Exposure to everything in the job. Every step can read the environment variables. A compromised third-party action or build dependency can send the key to an attacker.
- Copies. Teams paste the same key into several repositories, local profiles, and chat messages. You cannot tell where all the copies are.
- No binding to the workflow. AWS cannot tell whether a request came from your
mainbranch workflow or from an attacker's laptop. CloudTrail shows only the IAM user. - Over-broad permissions. A shared key tends to collect permissions over time, so a leak exposes more than one deployment needs.
- Manual rotation. Rotating a key means creating a new one, updating every secret, and deleting the old one. Teams skip this, so keys get old.
What you want instead
The problems above point to three requirements:
- Short-lived credentials. A leaked credential should stop working within minutes or hours.
- Identity tied to the workflow. AWS should be able to check which repository, branch, or environment is asking.
- Nothing stored. If no secret sits in GitHub, no secret can leak from it.
The next chapters build this with OpenID Connect (OIDC) federation and IAM roles. GitHub vouches for each job, and AWS issues temporary credentials in return.
Exercise
A team stores an IAM user's access key in a repository secret. Name two reasons this is riskier than temporary credentials, and one thing CloudTrail cannot tell you about requests made with that key.
Show answer
The key never expires, and any step in the job (including a compromised third-party action) can read it. Other valid reasons are copies in many places, over-broad permissions, and manual rotation. CloudTrail shows only the IAM user, so it cannot tell you whether a request came from your workflow or from someone using a leaked copy elsewhere.