DEV Community

OnaEiuspkz
OnaEiuspkz

Posted on

GitHub Actions Supply Chain Risk: Pinning, OIDC and Least-Privilege Tokens

GitHub Actions Supply Chain Risk: Pinning, OIDC and Least-Privilege Tokens

A CI/CD pipeline is a place where code from many sources meets credentials that can deploy to production. That combination is why build systems keep appearing in incident reports, and why a small number of controls matters more than a long policy document.

Why the reader needs this

Workflows commonly run third-party actions, check out code from pull requests, and hold a token that can write to the repository or to a cloud account. Each of those is a trust decision. When they are combined without thought, a single compromised dependency or a single malicious pull request can reach production.

Technical context

Three mechanisms drive most of the risk.

  • Third-party actions are referenced by tag, and tags are mutable. A tag that pointed at a safe commit can later point at a malicious one.
  • The default GITHUB_TOKEN carries permissions that many workflows do not need, and it is available to every step.
  • Long-lived cloud credentials stored as secrets can be exfiltrated by any step that can read them.

Explanation: the controls that actually change the outcome

Pinning third-party actions to a full commit SHA removes the mutable-tag problem. It is a small change with a large effect, and it can be enforced by policy rather than by review.

Setting explicit permissions at the workflow level, defaulting to read-only, removes most of the value of a compromised step. A token that cannot write cannot push.

Replacing stored cloud credentials with OIDC federation means the workflow exchanges a short-lived identity token for cloud access. There is no long-lived secret to steal, and the cloud side can restrict which repository and branch may assume the role.

The event that triggered the workflow also matters. pull_request_target runs with repository secrets and should be used with care, because it can be triggered by code the attacker controls.

Defensive implications

  • Pin third-party actions to commit SHAs and review changes to those pins.
  • Set workflow-level permissions to the minimum, and grant write permissions only to the specific job that needs them.
  • Use OIDC for cloud access instead of stored credentials, and scope the trust policy to a repository and branch.
  • Require approval for workflows triggered from forks, and avoid checking out untrusted code in a job that holds secrets.
  • Monitor for changes to workflow files and for new self-hosted runners.

Limitations are real. SHA pinning creates maintenance work, and OIDC requires the cloud provider to support it. The trade-off is worth stating explicitly rather than leaving the default in place.

References

  • GitHub Docs, Security hardening for GitHub Actions.
  • GitHub Docs, About security hardening with OpenID Connect.
  • GitHub Docs, Permissions for the GITHUB_TOKEN.

Top comments (0)