Sub topic 1
Why stored cloud credentials are a liability
A CI/CD pipeline that deploys to a cloud account needs some way to prove who it is. The most common approach is to create a credential, paste it into a repository secret, and read it from the workflow. This chapter explains why that approach carries risks that grow over time. It also states the properties a better approach needs. The rest of the tutorial shows how OpenID Connect (OIDC) provides them.
Prerequisites
This chapter assumes you already know:
- Basic GitHub Actions workflow syntax: triggers, jobs, and steps.
- What repository secrets and environments are, and how a workflow reads them with
${{ secrets.NAME }}. - What a cloud IAM role or user is, and how a policy grants permissions.
- How HTTP requests and JSON documents work.
You do not need to know anything about OIDC or JSON Web Tokens yet. The next chapter introduces them.
The pattern most teams start with
The usual setup creates an IAM user in the cloud account, generates an access key pair for it, and stores both halves as repository secrets. Here is what the workflow looks like on AWS:
name: deploy
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1
- run: aws sts get-caller-identityThis works and is easy to set up, which is why it is so common. The problems come from what the credential is, not from how the workflow uses it.
What makes a stored credential risky
A stored credential is a bearer secret. Whoever holds the string can act as the identity, from any machine, at any time, until someone revokes it. Five properties make this a liability.
It lives for a long time
An IAM user access key does not expire. A key created three years ago for a pipeline that has since been rewritten still works unless someone deleted it. The longer a credential lives, the more chances it has to leak, and the longer a leaked copy stays useful to an attacker.
It is usually broader than the job needs
Pipelines tend to accumulate permissions. A deploy key that began with access to one bucket gains rights to a container registry, then to a database migration role. Nobody wants to break the deploy by trimming permissions, so they only grow. One credential then serves every workflow and every branch, so its permissions must cover the most demanding job.
It exists in more than one place
The secret is copied into GitHub, and often also into a password manager, a local ~/.aws/credentials file used for testing, a chat message, or a second CI system. Each copy is another place for it to leak, and you cannot see them all. Deleting the repository secret does not delete the other copies.
It is not tied to a context
The cloud provider cannot tell whether a request using the key came from your main branch workflow or from an attacker's laptop. The key proves possession and nothing else. It says nothing about which repository, branch, or workflow is using it.
It makes attribution weak
Audit logs such as AWS CloudTrail record that the IAM user github-deploy made a call. If three repositories share that user, the log cannot say which one acted. Investigating an incident then means correlating timestamps against workflow run history by hand.
How stored credentials leak in practice
A secret in the GitHub secrets store is encrypted at rest, but the workflow must decrypt it to use it. From that moment it is exposed to everything running in the job. Common leak paths include:
- Compromised third-party actions. Every action in a job runs with access to the job's environment and any secret passed to it. A malicious update to a widely used action can read the key and send it elsewhere.
- Workflow edits on other branches. Repository-level secrets are available to workflows on any branch. Anyone with write access can push a branch whose workflow runs
env | base64and read the output. Environments with required reviewers or branch restrictions reduce this risk, but only for secrets stored in the environment. - Pull request workflows. Fork pull requests run without secrets by default. The
pull_request_targettrigger, however, runs in the context of the base repository with secrets available. If such a workflow checks out and runs the pull request's code, it hands the secrets to the author. - Logs and artifacts. GitHub masks the exact secret value in logs. Masking is string matching, so a transformed value is not caught. A base64-encoded, split, or reversed copy appears in plaintext. Secrets can also end up in uploaded artifacts, crash dumps, or debug output.
- Developer machines and backups. The copy used to test the pipeline locally lives in shell history, dotfiles, and laptop backups.
None of these requires breaking GitHub's encryption. They all use the fact that the job legitimately holds the secret.
Operational cost: rotation
The usual defence is to rotate keys on a schedule. AWS allows two active access keys per IAM user precisely so you can rotate without downtime. Rotation means creating a new key, updating every place that stores it, verifying deploys, and deleting the old key.
You can check how stale a key is with the AWS CLI:
aws iam list-access-keys --user-name github-deployThe output includes a CreateDate for each key. To see whether a key is still used at all, ask for its last use:
aws iam get-access-key-last-used --access-key-id AKIAIOSFODNN7EXAMPLEIn practice, rotation is manual, easy to postpone, and hard to enforce across dozens of repositories. A credential that depends on someone remembering a chore will eventually be stale. Rotation also shortens the exposure window only to the rotation interval. A key leaked the day after rotation is still valid for months.
What a better credential looks like
The properties you want are the reverse of the problems above:
| Problem with a stored key | Property you want instead |
|---|---|
| Valid until revoked | Expires within minutes or hours |
| Broad, shared by all jobs | Scoped to a specific repository, branch, or environment |
| Copied into many places | Never stored, created on demand |
| Proves possession only | Proves which workflow is asking |
| Weak audit trail | Each session is attributable to a specific run |
| Needs manual rotation | Nothing to rotate |
A short-lived credential that is issued per job and bound to the workflow's identity meets all of these. The workflow does not hold a secret that outlives the job, because GitHub vouches for the workflow at run time. The cloud provider decides whether to trust that statement.
That is what OIDC federation provides. The following diagram contrasts the two models at a high level. The later chapters fill in each step.
What OIDC does not remove
OIDC replaces the stored secret. It does not remove the need to think about access:
- A badly written trust policy can still allow too many workflows to assume a role. Later chapters cover how to scope it.
- A compromised step in a job can still use the temporary credentials while the job runs. The difference is that they expire soon after, and they cannot be reused from outside the trust conditions.
- You still need least-privilege permissions on the role itself.
Treat OIDC as a way to shrink the blast radius and remove the rotation burden. It does not replace review of what a workflow is allowed to do.
When a static secret is still acceptable
Some systems cannot accept OIDC tokens. This includes certain third-party SaaS APIs and older self-hosted tools. If you must store a static credential, reduce the risk:
- Give it the minimum permissions for a single purpose.
- Store it in an environment with required reviewers or branch restrictions, not as a repository-wide secret.
- Set an expiry where the service supports one, and record an owner and a rotation date.
- Alert on use from unexpected IP ranges or at unexpected times, if the provider logs it.
These measures lower the risk but do not remove it. Where a provider supports OIDC federation, prefer it.
Exercise
A team stores an AWS access key as a repository secret. A contributor with write access pushes a new branch containing a workflow that prints the key base64-encoded. Why does GitHub's log masking fail to hide it, and what does this show about the weakness of stored credentials?
Show answer
Masking only replaces the exact secret string in the logs. A base64-encoded copy is a different string, so it appears in plaintext and can be decoded. This shows that any workflow able to read a stored secret can expose it, and that a long-lived key stays valid after exposure. The key must be revoked in the cloud account, and a credential that expires quickly and is bound to a specific branch or repository would limit the damage.
Exercise
List three differences between a long-lived IAM user access key and a short-lived credential issued per workflow run, and name which one makes an incident investigation easier and why.
Show answer
Possible differences are expiry (never versus minutes or hours), scope (shared across jobs versus tied to a repository, branch, or environment), and storage (copied in several places versus created on demand and never stored). The per-run credential makes investigation easier because each session can be traced to a specific workflow run, while a shared access key appears in logs as the same IAM user for every caller.