Cybersecurity

Secure GitHub Actions with OIDC: Stop Storing Long-Lived Cloud Keys in Secrets

Replace static cloud credentials in CI with short-lived identity tokens, trust policies and auditable deployment permissions.

Sunil Kumar5 min read
Developer workstation displaying code for secure CI and deployment workflows

Many CI pipelines still store cloud access keys as repository or organization secrets. Those keys can remain valid for months, may be copied into logs by mistake and can be difficult to scope to one workflow. OpenID Connect (OIDC) lets a workflow request a short-lived identity token and exchange it for temporary cloud credentials.

Understand the trust relationship

Your CI provider issues a signed token containing claims about the repository, branch, workflow and execution context. The cloud identity provider validates that token against a trust policy. The policy should name the exact repository and expected branch or deployment environment rather than trusting every workflow from an organization.

Grant only the required permissions

In GitHub Actions, add the minimum workflow permission needed to request an OIDC token. Configure the cloud role with only the actions required for the deployment, such as publishing an image to one registry or updating one application. Avoid broad administrator roles. Separate roles for development, staging and production.

Protect production environments

Use protected GitHub environments for production deployments. Require reviewers where appropriate, restrict which branches can deploy and make the cloud trust policy check the environment claim. This prevents a pull request from an untrusted branch from obtaining production credentials simply because it can run a workflow.

Validate claims carefully

Review the issuer, audience and subject claims in the token. Configure the cloud provider to accept only the intended audience and repository identity. Be precise about reusable workflows and tags; a policy that is too broad can allow an attacker to run a modified workflow under a trusted identity.

Test the failure cases

Confirm that a forked pull request, an unapproved branch and a workflow without the expected environment cannot assume the role. Confirm that the issued credentials expire and that deployment logs do not print tokens. Remove the old static keys only after the OIDC path has passed a controlled deployment test.

Audit and rotate the remaining secrets

Review repository secrets, organization secrets and environment secrets for unused cloud keys. Revoke obsolete credentials and inspect audit logs for unexpected use. Keep non-cloud secrets in a dedicated secret manager and scope access to the workflow that needs them.

Why it matters: OIDC reduces the lifetime and distribution of cloud credentials. It does not make a workflow automatically safe; the trust policy, workflow permissions and deployment approvals still determine who can access production.

Reference: GitHub documentation, OpenID Connect — https://docs.github.com/actions/security-for-github-actions/security-hardening-your-deployments/about-security-hardening-with-openid-connect

Understand the token exchange from workflow to cloud

OIDC-based deployment replaces a stored cloud access key with a short-lived token issued for a particular workflow run. The CI platform signs claims describing the repository, branch, workflow and sometimes the protected environment. The cloud identity provider checks the issuer and audience, then evaluates a trust policy before issuing temporary credentials for a role. This chain matters because a weak trust condition can allow an untrusted workflow to impersonate a trusted deployment. Document the expected claims and test them in a non-production role before attaching permissions to production resources.

Write narrow trust conditions

Do not trust every repository in an organization simply because it belongs to the same company. Bind the trust relationship to the exact repository and, where possible, a protected branch or environment. Review how reusable workflows, tags and pull requests are represented in the subject claim. A policy that accepts any ref may allow a contributor to create a branch and obtain credentials intended only for releases. Prefer explicit allowlists and keep the audience value fixed to the cloud provider’s expected identifier. Review trust policies whenever repository names or deployment processes change.

Separate build and deployment identities

A build workflow often needs permission to read source code, run tests and publish an artifact, while a deployment workflow needs permission to update a particular environment. These should not automatically share one broad role. Use separate identities for development, staging and production, each with distinct resource scopes. If an attacker compromises a test workflow, the credentials should not grant access to customer-facing infrastructure. Avoid wildcard permissions where resource-level restrictions are available, and review whether the role can create new identities or change its own access policy.

Protect the workflow definition itself

Cloud trust is only as strong as the workflow that requests the token. Protect workflow files with code review, branch protection and ownership rules. Pin third-party actions to reviewed immutable commit references where practical, and keep dependencies updated through a controlled process. Do not execute untrusted pull-request code in a privileged deployment context. Use environment protection rules and required reviewers for production. Keep the OIDC permission scoped to the job that needs it rather than granting token-request permission to every job in the workflow.

Test negative authorization cases

Security testing should prove that an unauthorized branch, forked pull request, renamed repository or unexpected environment cannot assume the role. Test both the positive deployment path and the expected denials. Inspect cloud audit logs to confirm which identity was assumed, what session name was recorded and which permissions were used. A deployment that succeeds is not sufficient evidence that the trust policy is narrow; the same workflow should fail when one required claim is changed. Keep these tests as part of the CI security regression suite.

Handle artifacts and secrets separately

OIDC reduces the need for static cloud keys, but it does not remove every secret from CI. Package registries, signing services and application APIs may still require credentials. Store those in an approved secret manager, limit access to specific jobs and avoid printing environment variables. Protect build artifacts from tampering and verify their provenance before deployment. A secure pipeline should promote the same tested artifact through environments rather than rebuilding different binaries with different dependencies at each stage.

Plan for expiration and incident response

Temporary credentials should expire automatically, and workflows should not attempt to persist them beyond their intended job. If a repository or runner is compromised, know how to disable the trust relationship, revoke sessions where supported and pause deployments. Review cloud audit logs for unusual role assumptions, unexpected regions or actions outside normal deployment windows. Keep a documented owner for each role and remove unused trust relationships. The short lifetime of OIDC credentials limits exposure, but rapid detection and revocation remain important.

Adopt OIDC through a controlled migration

Choose one low-risk repository, create a narrowly scoped role and run a test deployment. Compare the resulting cloud permissions with the old static key’s permissions, then reduce them before expanding. Once the workflow is stable, revoke the old key and search other repositories for copies or similarly named secrets. Document the trust conditions, role owner and rollback procedure. Repeat the process for each environment instead of creating one organization-wide role. This turns credential modernization into a verifiable security improvement rather than a simple configuration change.

Share this article

Written by

Sunil Kumar

Founder of FutureTechie and BoltPane. Writes clear explainers on AI, cybersecurity, gadgets and developer tools for curious readers who want signal over hype.

106 articles View profile

Get the tech briefing

AI, gadgets, software and cybersecurity — distilled into one short briefing every weekday.

Leave a Reply

Your email address will not be published. Required fields are marked *