Dev.to Security πŸ” Cybersecurity πŸ‘ 0 πŸ“– 13 min read

GitHub Actions security hardening checklist

Originally published on the ClearPath Security site: https://clearpathsecurity.co.uk/github-actions-security-hardening-checklist/ GitHub Actions is often where code changes become build artefacts, deployment packages, c

Originally published on the ClearPath Security site: https://clearpathsecurity.co.uk/github-actions-security-hardening-checklist/

GitHub Actions is often where code changes become build artefacts, deployment packages, container images, or release notes. That makes it a high-value control point in the software delivery chain, not just another automation tool. If an attacker can alter a workflow, steal a token, or abuse a pull request path, they may be able to move from source code access to release integrity, secret exposure, or production impact.

For UK SMEs, the goal is not to make GitHub Actions perfect. It is to reduce the chance that a routine pipeline becomes a route into your repositories, cloud accounts, or production systems. A sensible baseline is to treat workflow files, runner configuration, secrets, and third-party actions as part of your security boundary. That framing aligns well with broader software supply chain assurance, as discussed in our software supply chain assurance controls guidance.

Key takeaways

  • Treat GitHub Actions as part of your software supply chain, not just a build tool, and protect workflow files, runners, tokens, and secrets accordingly.
  • Set default permissions to read-only, then grant elevated access only to the specific jobs that need it.
  • Pin third-party actions to commit SHAs, review their trustworthiness, and avoid relying on mutable tags in critical workflows.
  • Keep untrusted pull request handling separate from privileged release jobs, and never execute untrusted input in a high-privilege context.

Why GitHub Actions needs a hardening baseline

GitHub Actions introduces several trust boundaries that are easy to overlook. A workflow triggered by a trusted branch is not the same as one triggered by an external contributor. A reusable action maintained by a third party is not the same as a script you control in your own repository. A job that only builds code is not the same as a job that can publish packages, deploy infrastructure, or write to cloud storage.

The main risk areas are predictable:

  • workflow file tampering, especially when changes are merged without strong review;
  • token over-permissioning, where the default job token can do more than the job needs;
  • secret exposure through logs, environment variables, or unsafe shell usage;
  • untrusted pull request content reaching privileged jobs;
  • third-party action compromise or misuse;
  • runner persistence, where one job can influence the next.

These are supply chain issues as much as they are CI/CD issues. A compromised workflow can alter what you ship, what you sign, or what you trust. If you are already thinking about build provenance, dependency integrity, or release assurance, GitHub Actions should be in scope.

Start with repository and organisation settings

The first layer of hardening is governance. If the wrong people can change workflows, approve them too easily, or bypass branch controls, the rest of the checklist becomes less effective.

Start by limiting who can create and modify workflow files. In practice, that means reviewing repository roles, branch protection, and the ability to approve pull requests that touch .github/workflows. For higher-risk repositories, require at least one review from someone who understands the pipeline, not just the application code.

Use branch protection rules on your main release branches. Require status checks, require reviews, and block direct pushes where possible. If your organisation uses environments for deployment, enable environment protection rules so that production deployments need explicit approval and cannot be triggered casually from any branch.

For teams with multiple repositories, standardise these settings. Inconsistent controls create weak links. A single less-protected repository can become the easiest route to a release compromise.

Reduce the blast radius of workflow permissions

GitHub provides a default token to each workflow run. That token is useful, but it should not be treated as harmless. If it can write contents, create releases, or access packages when the job does not need those rights, then a compromised step has more room to move.

Set the default GITHUB_TOKEN permissions to read-only wherever possible. Then grant elevated permissions only to the specific jobs that need them. A build job may need read access to the repository and packages, while a release job may need write access to create tags or publish artefacts. Those should not be the same permission set.

A practical pattern is to define the minimum permissions at workflow level, then override them only for the job that needs more. For example:

permissions:
  contents: read

jobs:
  build:
    permissions:
      contents: read
  release:
    permissions:
      contents: write
      packages: write

That pattern is simple, but it materially reduces the impact of a compromised build step. It also makes permission drift easier to spot during review.

Pin and verify third-party actions

Third-party actions are convenient, but they are also a dependency you do not fully control. If you reference a mutable version tag such as v3, you are trusting the maintainer to keep that tag stable and safe. If the action is updated maliciously or compromised upstream, your workflow may inherit that change without any local code review.

Pin actions to a commit SHA instead of a mutable tag. This is one of the most important GitHub Actions hardening measures you can apply. It does not remove all risk, but it gives you a fixed reference point and makes unexpected changes easier to detect. If you need to update the action, review the new commit deliberately rather than drifting with the tag.

When reviewing an action, consider three things:

  • provenance, meaning who published it and how it is maintained;
  • update cadence, meaning whether it is actively maintained or stale;
  • scope, meaning whether it needs broad permissions or just a narrow task.

If an action is doing something simple, such as checking out code or setting up a runtime, prefer the smallest trusted dependency that meets the need. Where possible, reduce the number of external actions in your critical release workflows. This is especially relevant if you are already using controls such as SAST, DAST, or dependency scanning in the pipeline, because those jobs often run with access to sensitive build context. Our GitHub Actions SAST and DAST guidance covers how those checks fit into a pipeline without overexposing the job.

Control secrets and sensitive outputs

Secrets are often the most valuable thing a workflow can touch. API keys, signing credentials, cloud tokens, and package publish credentials should be treated as high-impact assets. The mistake many teams make is to make them available too widely, then assume masking will solve the problem.

Masking helps, but it is not a complete control. Use it as a last line of defence, not the main one. The stronger control is to scope secrets tightly and only expose them to trusted branches, protected environments, and jobs that genuinely need them.

Prefer environment secrets for deployment jobs, especially where production access is involved. That way, a build or test job does not inherit the same secret set. If a workflow only needs a secret for one step, avoid passing it through the entire job. Keep the secret in the narrowest possible scope and avoid echoing it into logs, files, or command output.

Be careful with derived values too. A secret can leak indirectly through debug output, error messages, or a script that prints environment variables. If you need to log a value for troubleshooting, log a non-sensitive identifier instead. For example, log the last four characters of an internal reference, not the full token or connection string.

For organisations already dealing with secret sprawl, it is worth aligning GitHub Actions secret handling with your wider secrets management approach. That usually means central vaulting, short-lived credentials where possible, and a clear rule that secrets are never embedded in repository files. Our article on preventing secret leakage in CI/CD environments is a useful companion if you want to tighten this area further.

Harden workflow triggers and pull request handling

Trigger choice matters. The same workflow logic can be safe in one context and unsafe in another. In particular, pull_request and pull_request_target behave differently, and that difference is often misunderstood.

Use pull_request for untrusted contributions when you want the workflow to run against the contributor’s changes without granting elevated repository privileges. Be cautious with pull_request_target, because it runs in the context of the base repository and can access secrets and write permissions if you configure it that way. That makes it useful for some review automation, but dangerous if you check out and execute untrusted code without strict controls.

A safe pattern is to separate validation from privileged actions. Let untrusted pull requests run linting, unit tests, and static checks in a low-privilege context. Keep deployment, release, and secret-bearing jobs for trusted branches or protected environments only.

Also avoid unsafe checkout and script execution on untrusted input. Do not interpolate pull request titles, branch names, or issue content directly into shell commands. Treat all external input as untrusted, even if it appears to come from a familiar contributor. If you need to process metadata, validate it first and use defensive quoting in shell scripts.

Secure runners and execution environments

Runner choice is a major design decision. GitHub-hosted runners are convenient because they are ephemeral and managed for you. Self-hosted runners give you more control, but they also increase your responsibility for isolation, patching, and cleanup.

For most UK SMEs, GitHub-hosted runners are the safer default for general build and test work. They reduce the risk of residual state between jobs and remove the burden of maintaining the host. Use self-hosted runners only when you have a clear need, such as access to internal networks, specialised hardware, or regulated build environments.

If you do use self-hosted runners, isolate them carefully. Do not share runners across unrelated repositories or trust levels unless you have strong segmentation and cleanup controls. Treat each runner as a potentially exposed execution environment. Remove persistent state after each job, rotate credentials regularly, and make sure the runner cannot retain artefacts, caches, or tokens that a later job could reuse.

It is also worth considering network egress. A compromised job should not be able to reach everything on your internal network. Restrict outbound access where possible, especially from self-hosted runners that can access sensitive systems. If the runner does not need internet access beyond package repositories, limit it accordingly.

Build safer job and step patterns

Many workflow weaknesses come from small implementation choices rather than headline misconfigurations. Shell interpolation, broad environment variables, and mixed-trust jobs are common examples.

Minimise shell interpolation and avoid building commands from untrusted strings. Use explicit arguments rather than concatenated command lines. Where possible, prefer action inputs over raw shell scripting. If you must use shell, quote variables carefully and keep the script short enough to review easily.

Split build, test, and release jobs to separate trust levels. A build job should not automatically become a release job just because it succeeded. Release steps should be gated by branch protection, environment approvals, and explicit permission changes. This separation makes it easier to reason about where secrets are available and where artefacts can be published.

Keep job outputs narrow as well. Outputs are useful for passing data between jobs, but they can become an accidental data channel if you place sensitive values in them. Pass only what is needed for the next stage, and avoid using outputs as a general-purpose storage mechanism.

For teams that want to go further, it is useful to map workflow steps to threat scenarios. For example, ask what happens if a contributor manipulates a build parameter, if a dependency update changes the behaviour of a third-party action, or if a compromised runner attempts to exfiltrate a token. That style of analysis fits well with the threat modelling approach used in our supply chain attack modelling article.

Add supply chain checks into the pipeline

GitHub Actions hardening is not only about preventing misuse. It is also about making the pipeline more trustworthy. That means adding checks that help you understand what is being built, what is being shipped, and whether the artefact matches the source you reviewed.

At a minimum, combine static analysis, dependency scanning, and artefact or container scanning where relevant. These controls do not replace workflow hardening, but they help catch issues before release. If you build containers, scan the image for vulnerabilities and misconfigurations. If you publish packages, scan dependencies and lockfiles. If you produce signed artefacts, make sure the signing step is isolated and controlled.

Where it adds value, generate build provenance and an SBOM, or software bill of materials. Provenance helps you show how an artefact was built. An SBOM helps you understand what components are inside it. For technical teams, these are useful evidence artefacts when you need to investigate a release issue or answer supplier assurance questions. Our posts on build provenance and SBOM generation cover the mechanics in more detail.

If you already use Trivy, Semgrep, or similar tools, keep them in the lowest-privilege jobs that still give useful results. Security tooling should not force you to grant broad write access to the repository or deployment environment.

Detect abuse and monitor for suspicious workflow activity

Hardening is stronger when it is paired with monitoring. You want to know when workflow files change, when permissions drift, and when a job behaves in a way that does not fit the normal pattern.

Alert on changes to workflow files, especially when they introduce new third-party actions, new permissions, or new secret usage. Also watch for changes to branch protection, environment rules, and repository settings that affect who can approve or deploy. These are often the precursor to a more serious issue.

Review logs for indicators of exfiltration or unexpected outbound connections. A job that suddenly reaches out to unfamiliar domains, downloads unusual binaries, or writes large amounts of data to external endpoints deserves attention. The same applies to repeated token failures, unexpected use of deployment credentials, or jobs that run outside normal release windows.

If you have central logging, include GitHub audit events and workflow run metadata in your monitoring scope. That gives you a better chance of spotting permission changes, runner registration events, and unusual administrative activity. For teams already building detection content, it is sensible to treat GitHub audit data as part of the same monitoring model you use for identity, endpoint, and cloud events.

Create a practical operating model for ongoing maintenance

GitHub Actions hardening is not a one-off task. Workflows drift, actions are deprecated, permissions expand, and teams add shortcuts under delivery pressure. Without ownership, the baseline erodes.

Assign clear ownership for workflow reviews, action updates, and exception handling. Someone should be responsible for checking whether a new workflow follows your baseline, whether an existing workflow still needs its current permissions, and whether a third-party action is still trusted. This does not need to be a separate team, but it does need to be explicit.

Set a regular cadence for reviewing deprecated actions and permission drift. A monthly or quarterly review is usually enough for smaller teams, provided the release pipeline is not changing daily. During that review, check for:

  • actions pinned to tags rather than commit SHAs;
  • jobs with unnecessary write permissions;
  • secrets available to more branches or environments than needed;
  • self-hosted runners that have not been patched or cleaned up;
  • workflow files that have grown complex without a clear owner.

Where exceptions are necessary, document them. For example, a legacy release job may need broader permissions for a short period while you refactor it. That can be acceptable if the exception is time-bound, reviewed, and tracked.

Checklist summary for teams to implement first

If you want a practical order of operations, start with the controls that reduce the biggest risks fastest. First, lock down repository and branch settings so workflow changes are reviewed properly. Second, reduce default token permissions and grant write access only where it is genuinely needed. Third, pin third-party actions to commit SHAs and review them before updating. Fourth, scope secrets to trusted branches and protected environments. Fifth, separate untrusted pull request validation from privileged release jobs.

After that, improve runner hygiene, add provenance and SBOM evidence where it helps, and bring workflow activity into your monitoring and review process. That sequence gives you a meaningful reduction in risk without forcing a complete redesign of your delivery pipeline.

If you are already working on broader secure development or supplier assurance improvements, GitHub Actions is a sensible place to start because it affects both code integrity and release integrity. It is also a good candidate for evidence-led improvement, which fits well with an ISO 27001-aligned approach to risk treatment and operational control.

If you would like help reviewing your CI/CD controls, tightening workflow permissions, or aligning pipeline hardening with a wider security programme, Speak to a consultant.

Frequently asked questions

Should all GitHub Actions be pinned to a commit SHA?

Yes, for production and release-critical workflows that is the safest default. Pinning to a commit SHA reduces the risk of a mutable tag changing underneath you, although you still need to review updates before you move to a new commit.

What is the safest way to handle secrets in GitHub Actions?

Scope secrets as narrowly as possible, use protected environments for deployment jobs, and avoid exposing secrets to untrusted pull request runs. Keep secrets out of logs, avoid passing them through unnecessary steps, and prefer short-lived credentials where your platform supports them.

πŸ“° Read the original article on Dev.to Security

Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.