GitHub Actions (CI/CD automation)¶
Scope: designing CI/CD and automation workflows on GitHub Actions, including reusable workflows, custom actions and deployments. Workflows run with access to your code, secrets and cloud accounts, so most rules here are about keeping them secure. For general supply-chain rules, see Security.
Entries are sorted by score from 1 to 10 (criteria): 9โ10 start here or strongly recommended, 6โ8 recommended, 1โ5 further reading or conditional.
Adopted references¶
- 9 Secure use reference (GitHub Docs): the baseline for workflow security: third-party actions, script injection,
GITHUB_TOKENpermissions, OIDC, self-hosted runners and CODEOWNERS. - 7 Securely using
pull_request_target(GitHub Docs): when to use the privileged pull request trigger, and how to harden it. - 7 OpenID Connect (GitHub Docs): short-lived cloud credentials instead of stored secrets, with setup guides per cloud provider.
- 7 Reusing workflow configurations (GitHub Docs): reusable workflows, composite actions and workflow templates, and when to use each.
- 7 Deployment environments (GitHub Docs): approvals, branch restrictions and environment secrets for deployment jobs.
Key rules¶
Security¶
- 9
GHA-1Set theGITHUB_TOKENto read-only at the top of each workflow, and grant write permissions only to the jobs that need them. (GitHub, Secure use reference, GitHub, Use GITHUB_TOKEN for authentication) - 9
GHA-2Pin third-party actions and reusable workflows to a full-length commit SHA, or lock them with a workflow dependency lockfile. Tags and branches can be moved to malicious code. Lockfiles are in public preview and also cover transitive dependencies. (GitHub, Using third-party actions, GitHub, Workflow dependency lockfiles) - 9
GHA-3Never expand untrusted input, such as${{ github.event.pull_request.title }}, directly in arun:script. Pass it through an intermediate environment variable. (GitHub, Script injections, GitHub, Secure use reference) - 8
GHA-4Usepull_requestrather thanpull_request_targetunless fork pull requests need secrets or write access, and never execute pull request code in apull_request_targetorworkflow_runworkflow. (GitHub, Securely using pull_request_target, GitHub Security Lab, Preventing pwn requests) - 8
GHA-5Authenticate to cloud providers with OpenID Connect instead of long-lived cloud secrets, and restrict the trust policy to specific repositories, branches or environments. Define at least one condition so that untrusted repositories can't request access tokens. (GitHub, OpenID Connect, GitHub, OpenID Connect reference) - 7
GHA-6Avoid self-hosted runners in public repositories. Where you use them, prefer ephemeral just-in-time runners. A runner that keeps state between jobs can be persistently compromised by untrusted code. (GitHub, Hardening for self-hosted runners) - 7
GHA-7Enable Dependabot version updates for thegithub-actionsecosystem. Dependabot also updates SHA-pinned actions and their version comments. (GitHub, Keeping your actions up to date with Dependabot, GitHub, Dependabot support for GitHub Actions) - 6
GHA-8Treat restored caches as untrusted input: never cache secrets, and write caches only from workflows with trusted triggers. (GitHub, Dependency caching: cache security, GitHub, Dependency caching reference) - 6
GHA-9Require approval from designated code owners for changes to.github/workflows. (GitHub, Using CODEOWNERS to monitor changes) - 5
GHA-10Pass secrets to reusable workflows by name instead of withsecrets: inherit. The called workflow then gets only the secrets it needs. (zizmor, secrets-inherit, GitHub, Reuse workflows)
Reuse and deployment¶
- 7
GHA-11Deploy through environments with protection rules: required reviewers, allowed deployment branches, and secrets scoped to the environment. On GitHub Free, Pro and Team plans, required reviewers work only in public repositories. (GitHub, Deployment environments, GitHub, Deployments and environments reference) - 6
GHA-12Share CI logic through reusable workflows (whole jobs) and composite actions (steps) instead of copying YAML between workflows and repositories. (GitHub, Reusing workflow configurations) - 6
GHA-13Use concurrency groups to cancel superseded runs on the same branch and to stop deployments to the same environment from running at once. (GitHub, Concurrency, GitHub, Control the concurrency of workflows and jobs)
How to enforce¶
Tools that check the key rules above automatically, in CI, the IDE or a commit hook. "Partly" means the tool covers only some of what the rule asks.
- 7 GitHub Actions repository settings: the policy "Require actions to be pinned to a full-length commit SHA" blocks unpinned actions (reusable workflows can still use tags), and the restricted "Workflow permissions" setting makes the
GITHUB_TOKENread-only by default. Partly checksGHA-1andGHA-2. - 6 CodeQL queries for GitHub Actions: code scanning that finds code injection, checkout of untrusted code in a privileged context, cache poisoning, workflows without
permissionsand, in the extended suite, unpinned tags. ChecksGHA-3, and partlyGHA-1,GHA-2,GHA-4andGHA-8. - 6 zizmor audit rules: a static analyser for workflows. Its default audits include
unpinned-uses(since v1.20 it requires SHA pins for all actions),excessive-permissions,template-injection,dangerous-triggers,cache-poisoningandsecrets-inherit.self-hosted-runner(auditor persona) andconcurrency-limits(pedantic persona) are opt-in. ChecksGHA-1,GHA-2,GHA-3,GHA-4andGHA-10, and partlyGHA-6,GHA-8andGHA-13. - 6 OpenSSF Scorecard checks: Token-Permissions looks for read-only top-level permissions, Pinned-Dependencies for actions pinned by hash, and Dangerous-Workflow for untrusted checkouts and script injection. Dependency-Update-Tool only checks that Dependabot or Renovate is enabled. Checks
GHA-1andGHA-2, and partlyGHA-3,GHA-4andGHA-7. - 6 actionlint checks: a workflow linter for CI and editors that flags script injection through untrusted inputs, besides syntax, expression and
shellcheckerrors. ChecksGHA-3. - 5 Dependabot alerts for actions: alert you when an action your workflows use has a reported vulnerability. Partly checks
GHA-7.
Tutorials and further reading¶
- 7 Keeping your GitHub Actions and workflows secure (GitHub Security Lab): a four-part series on pwn requests, untrusted input, trusting your building blocks and newer vulnerability patterns (2025).
- 6 Tutorials for GitHub Actions (GitHub Docs): building and testing per language, creating actions, and publishing packages.
- 6 Automate your workflow with GitHub Actions (Microsoft Learn): a beginner-to-intermediate learning path.