Deploy from GitHub Actions without storing cloud keys
Short answer: Instead of saving a cloud access key and secret in your GitHub repository's secrets, set up a trust between your cloud account and GitHub using OpenID Connect (OIDC). Each workflow run then gets a short-lived token, valid for that job only, and exchanges it for temporary cloud credentials, and only if the run comes from the repository, branch or environment you allowed. Nothing long-lived sits in GitHub to leak. Add id-token: write to the workflow's permissions, create a role in your cloud account that trusts GitHub's token issuer with tight conditions, and delete the old keys.
The problem with stored keys
Many deploy pipelines started with a quick fix: create a cloud user, generate an access key, paste it into GitHub as AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY. Those keys:
- never expire unless someone rotates them, and rarely does
- often have far more permissions than deploying needs
- can be exposed by a compromised workflow, a malicious dependency, a misconfigured fork or a careless log line
- are hard to trace when several repositories share them
If they leak, someone has standing access to your cloud account until you notice.
How OIDC works, in plain terms
GitHub's documentation explains the flow:
- You set up a trust relationship in your cloud provider that allows specific GitHub workflows to request access to a particular role.
- Each time a job runs, GitHub's OIDC provider creates a token containing claims about that run: which repository, which branch or environment, and more.
- The workflow presents the token to the cloud provider.
- The cloud provider checks the claims against the conditions you configured. If they match, it issues a short-lived access token.
GitHub lists the benefits: no cloud secrets duplicated as long-lived GitHub secrets, more granular control using your cloud provider's own access tools, and credentials that are valid for a single job and then expire automatically.
The approach works with major clouds, including AWS, Azure and Google Cloud, and tools such as HashiCorp Vault.
Setting it up (AWS example)
GitHub's guide for AWS covers the pieces:
1. Add GitHub as an identity provider in AWS. Use the provider URL https://token.actions.githubusercontent.com, and sts.amazonaws.com as the audience if you're using the official credentials action.
2. Create a role with a trust policy. The trust policy's conditions decide which workflows may use the role. GitHub's examples check the audience and the subject claim, for example allowing only a specific repository's prod environment:
"token.actions.githubusercontent.com:sub": "repo:your-org/your-repo:environment:prod"
Use exact matches where you can. Wildcards that allow any branch of a repository, or any repository in your organisation, are convenient and much weaker.
3. Give the role only what deploying needs, such as uploading to one bucket and invalidating one CDN distribution, not full admin access.
4. Update the workflow. Add a permissions block:
permissions:
id-token: write
contents: read
GitHub's docs point out that id-token: write doesn't let the workflow modify anything by itself; it only allows the job to request an OIDC token. Then use your cloud's official login action with the role to assume.
5. Remove the old keys from GitHub secrets and deactivate them in your cloud account once deploys work.
A detail to check: the subject format
GitHub's AWS guide notes that repositories created after July 15, 2026, or that have opted in, use immutable subject claims that include owner and repository IDs rather than only names. That protects against someone recreating a renamed or deleted repository with the same name. Check which format your repository uses and make sure your trust policy matches it, or tokens will be rejected.
Pair it with environments
Use GitHub environments, such as staging and prod, and reference the environment in the trust condition. Then only jobs running in the prod environment can assume the production role, and you can add protection rules to that environment, such as required approvals before deploying.
Keep an eye on what the role does
Your cloud provider's activity logs record each time the role is assumed and what it did, including which repository and run requested it. Review them occasionally, and set an alert for the role being used outside your normal deploy times or for actions it shouldn't need. If a workflow is ever compromised, the narrow role and these logs limit and reveal the damage.
Other clouds
Azure uses federated credentials on an app registration or managed identity; Google Cloud uses workload identity federation. The idea is the same: trust GitHub's token issuer, restrict by repository and branch or environment, and grant a narrowly scoped role.
Common errors
- "Not authorized to perform sts:AssumeRoleWithWebIdentity": the token's claims don't match the trust policy. Compare the repository, branch or environment in the policy with the actual run.
- "Unable to get OIDC token": the workflow or job is missing
id-token: write. - Pull requests from forks can't use the role if your conditions are tight, which is what you want.
A worked example
An illustrative Limerick e-commerce agency deployed client sites from GitHub Actions to cloud storage using one set of admin keys stored in every repository. After a dependency incident elsewhere prompted a review, they created a deploy role per client with access to only that client's bucket and CDN, trusted only the prod environment of that client's repository, switched workflows to OIDC and deleted the shared keys. Each deploy now uses credentials that expire after the job.
FAQ
Does this cost anything?
OIDC itself is part of GitHub Actions and the cloud providers' identity features.
Can I use this for staging too?
Yes. Create a separate role and trust condition for the staging environment.
What if I deploy to a VPS, not a cloud provider?
OIDC needs a service that can verify GitHub's tokens. For plain servers, use a dedicated deploy key with minimal access.
How do I know the old keys aren't used anymore?
Check your cloud account's access logs for the old key's last use before deleting it.
If your pipelines still rely on long-lived cloud keys, tell us where you deploy and we'll help you switch to short-lived credentials.