jrjsmrtn/project-orchestration-skills/harden-github-actions

Claude Code and agent skill by jrjsmrtn/project-orchestration-skills

Trust tier 3
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

Harden GitHub Actions CI/CD workflows for supply-chain security — SHA-pin actions, least-privilege token permissions, verified toolchain installs, OpenSSF Scorecard, and SLSA provenance. Use when adding or auditing GitHub Actions workflows, before making a repository public, when a supply-chain review flags CI gaps, or when standardizing CI hardening across GitHub projects. GitHub-specific by design — GitLab CI and Forgejo Actions are out of scope.

Install

npx vskill@latest install jrjsmrtn/project-orchestration-skills/harden-github-actions

SKILL.md

The same SKILL.md was published earlier as jrjsmrtn/project-orchestration-skills/harden-github-actions.

Harden GitHub Actions

Harden GitHub Actions CI/CD workflows against supply-chain attack: pin what runs, minimise what it can do, and verify what it fetches.

GitHub-specific by design. Unlike most orchestration skills, this one is deliberately bound to
one forge. The hardening controls below are not portable concepts wearing GitHub syntax — they are
properties of the GitHub Actions execution model itself: third-party actions resolved by mutable
git ref, an ambient GITHUB_TOKEN with repository-wide default scopes, and OIDC-backed SLSA
provenance. It has a sibling, harden-gitlab-ci, which is not a translation of this skill:
GitLab's risks sit in different places (include:/CI-Catalog components, and a CI_JOB_TOKEN that
defaults to own-project-only — so there the work is keeping it scoped, the opposite posture from
here). Forgejo Actions is Actions-compatible in shape but resolves actions against its instance's
configured registry, so pinning guidance does not transfer unchanged (roadmap H9).

When to Use

  • When adding GitHub Actions workflows to a project (after setup-git-hooks)
  • When auditing existing .github/workflows/ before making a repository public
  • When a supply-chain review (or the supply-chain skill) flags CI hardening gaps
  • When standardising CI hardening across GitHub projects

Not for: GitLab CI — use harden-gitlab-ci. Not for Forgejo/Gitea Actions — the controls do not carry over unchanged. Say so rather than approximating.

This skill hardens CI workflows. validate-quality-config only reads CI to confirm parity with local hooks — it does not check pinning, permissions, or provenance. The two are complementary.

Required Inputs

  1. Workflow files — the project's .github/workflows/*.yml
  2. Release model — does the project publish artifacts/images/packages (needs provenance + signing), or is it internal-only?
  3. Repository visibility — public or private (affects Scorecard publish_results and OSSF publishing)

The Threat

A CI job runs third-party code (actions, installed tools) with a GITHUB_TOKEN and often OIDC. A mutable action tag (@v4) can be repointed to malicious code; an over-privileged token can push commits, publish packages, or exfiltrate secrets; an unverified curl | sh install can be swapped upstream. Hardening closes all three: pin, least-privilege, verify.

Workflow

Step 1: Inventory and triage

Find every workflow and the hardening gaps in it:

bash
ls .github/workflows/
# Mutable action refs (should be zero — all must be SHA-pinned):
grep -rnE 'uses:.*@(v[0-9]|main|master|latest)' .github/workflows/
# Workflows missing a top-level permissions block:
for f in .github/workflows/*.yml; do grep -q '^permissions:' "$f" || echo "no permissions: $f"; done
# Floating tool versions:
grep -rnE 'version:\s*latest|@latest' .github/workflows/

Aim for a clean 3-way split: `ci.yml` (lint/test/build on push + PR), `scorecard.yml` (OpenSSF Scorecard on a schedule), and — only if the project ships artifacts — `release.yml` (SBOM + SLSA provenance + signing).

Step 2: SHA-pin every action

Pin every uses: to a full 40-character commit SHA with a trailing # vX.Y.Z comment for readability. Never rely on a mutable tag.

yaml
# Good — immutable, human-readable, Dependabot-updatable
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- uses: actions/setup-java@ad2b38190b15e4d6bdf0c97fb4fca8412226d287 # v5.3.0
- uses: gradle/actions/setup-gradle@3f131e8634966bd73d06cc69884922b02e6faf92 # v6.2.0
# Bad — mutable tag, can be repointed upstream
- uses: actions/checkout@v4

Resolve a tag to its commit SHA. Ask for the tag, not for commits/<name>: that endpoint also answers for a branch name or a bare SHA, so it cannot show that a name is a tag.

bash
gh api repos/actions/checkout/git/ref/tags/v4.2.2 --jq '.object.type + " " + .object.sha'
# "commit <sha>": pin that SHA.
# "tag <sha>" (an annotated tag): that is the tag object, not the commit. Follow it, and pin what it reaches:
gh api repos/<owner>/<repo>/git/tags/<sha> --jq '.object.type + " " + .object.sha'

Keep pins current automatically with a Dependabot github-actions update block (see bootstrap-project / the dependency-update config).

Dependabot keeps the `# vX.Y.Z` comment as it was — that is the hazard, not a convenience. It is only safe within a major. Observed (August 2026): Dependabot moved a github/codeql-action/upload-sarif pin from a v3 SHA to the SHA that v4.37.6 resolves to, and left the comment reading # v3. The workflow then ran v4 code labelled v3. It is invisible in review — the diff shows a SHA change and an unchanged comment, which is exactly what a normal bump looks like. Only resolving the tag catches it.

So:

  • Label each pin with an exact patch tag (# v4.37.6), not a floating major (# v4). A major alias

moves, so a comment naming it can never be shown wrong.

  • Assert the label is true in CI (Step 2b), rather than trusting a comment.
  • Never write a SHA by hand or from memory. Resolve it with the gh api command above. A wrong SHA

is precisely the failure pinning exists to prevent.

Step 2b: Audit the pin labels

A pin's comment is a claim. This check resolves it: every uses: must be a 40-hex SHA, carry a tag comment, and that tag must resolve to that SHA. The script resolves the comment as a tag (following an annotated tag to its commit), so a comment that repeats the SHA, or names a branch, fails instead of resolving to itself. An earlier version asked commits/<comment>, which passed both.

The script is `scripts/check-action-pins.sh`, in this skill's directory. Copy it into the project as scripts/check-action-pins.sh rather than retyping it, and run it from the repository root.

Run it as a CI job so it gates the merge (it needs gh, which the GitHub-hosted Ubuntu runner image includes):

yaml
action-pins:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@<sha of the exact tag> # vX.Y.Z # resolve it; do not type it
with:
persist-credentials: false
- run: scripts/check-action-pins.sh
env:
GH_TOKEN: ${{ github.token }} # `gh api` resolves each tag to its commit

Exit codes: 0 all pins true; 1 an unpinned, unlabelled or mislabelled action; 2 it could not run (no gh, no auth, no uses: found) — a checker that checked nothing must not pass. A floating-major label is reported as a warning, not an error. It skips local (./) and docker:// references and the SLSA generator, whose tag reference is the sanctioned exception below.

Proven before it was written down, against live GitHub tags: a correct pin → 0; a v3.6.0 SHA labelled v4.2.2 (the Dependabot case) → 1; a mutable tag → 1; no comment → 1; an unresolvable tag → 1; no uses: at all → 2; gh off PATH → 2. Not yet run as a GitHub Actions job.

The one sanctioned exception: reusable workflows that verify their own release tag — notably slsa-framework/slsa-github-generator — must be referenced by semantic version tag, not SHA (see Step 7). Document the exception in an ADR and in a comment on the line.

Step 3: Least-privilege token permissions

Set a read-only default at the top of every workflow, then elevate per job only where a job genuinely needs to write.

yaml
# top of the workflow
permissions:
contents: read

Elevate narrowly, in the specific job:

yaml
jobs:
# OpenSSF Scorecard
analysis:
permissions:
security-events: write # upload the SARIF result
id-token: write # publish results to the OSSF API
contents: read
# Release provenance / publish
provenance:
permissions:
actions: read # read the workflow path
id-token: write # mint the OIDC token for signing
contents: write # attach provenance to the release
# packages: write # add only if publishing to GHCR / a registry

Rule of thumb: default contents: read; add id-token: write only for OIDC signing/publish; add contents: write only for jobs that create releases/tags; add packages: write only for registry publish; add security-events: write only for SARIF upload.

Step 4: Harden the checkout

On any workflow that runs with elevated permissions or handles releases (Scorecard, release), stop the checkout from leaving credentials on disk:

yaml
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
persist-credentials: false
Step 5: Verify what you install

Every tool a job installs is attack surface. In order of preference:

  1. SHA-pinned setup action (best) — toolchains via pinned actions:

```yaml

  • uses: actions/setup-java@ad2b38190b15e4d6bdf0c97fb4fca8412226d287 # v5.3.0

with: { distribution: temurin, java-version: "21" }

  • uses: xu-cheng/texlive-action@22c04326a5d855880f9d39bb955138bf11c6df80 # v3

```

  1. Pinned version + checksum verification for a downloaded binary:

```yaml

  • run: |

curl -fsSL -o tool.tar.gz "https://example.com/tool/v1.2.3/tool.tar.gz" echo "abc123... tool.tar.gz" | sha256sum -c - tar xzf tool.tar.gz ```

  1. Pinned package version for distro/language packages.
  2. Hash-verified install where the ecosystem has one — see below for Python. It is the strongest

form of 3, and the easiest to claim without having.

Python: --require-hashes needs a lockfile you generate

pip install --require-hashes -r requirements-ci.txt is only a control if requirements-ci.txt carries a hash for every package, transitive ones included. A hand-written list of pins is not that, and writing the flag without the file produces a control that does not exist. Measured with pip 26.2.2:

text
$ pip install --require-hashes jsonschema==4.23.0
ERROR: Hashes are required in --require-hashes mode, but they are missing from some requirements.

Generate the file; never write it:

bash
# requirements.in lists your direct dependencies, unpinned.
uv pip compile requirements.in --generate-hashes --universal --no-header -o requirements-ci.txt
python -m pip install --require-hashes -r requirements-ci.txt # in CI

`--universal` matters, and the reason is dependency markers, not wheels. A lockfile compiled for one platform omits the dependencies other platforms need. Measured on ipykernel: the lockfile compiled for x86_64-unknown-linux-gnu had no appnope (a macOS-only dependency), and installing it on macOS failed with "all requirements must have their versions pinned with ==". The --universal file kept appnope under ; sys_platform == 'darwin' and installed cleanly on macOS. Hashes were not the issue: the lockfile hashed every wheel of a release (128 for rpds-py) whether compiled for Linux or universally. Tested on macOS arm64 only; installing the universal file on Linux was not run. uv 0.13.0 was used; pip-compile --generate-hashes from pip-tools is the other common route and was not tested here.

Assert the lockfile is not stale — otherwise it quietly stops matching requirements.in:

bash
cp requirements-ci.txt /tmp/lock.check
uv pip compile requirements.in --generate-hashes --universal --no-header -q -o /tmp/lock.check
diff -q requirements-ci.txt /tmp/lock.check # non-zero (and a message) means regenerate and commit

Compiling into a copy of the existing lockfile keeps its pins, so the diff is empty unless requirements.in changed. Measured: unchanged → exit 0; a dependency added to the .in → non-zero.

This is the start of the file. Read the full SKILL.md on GitHub.

Security

  • Security scanPassed, 95 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

Repository stars
15
7-day trend score
14

Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/jrjsmrtn/project-orchestration-skills/harden-github-actions/badge)](https://verified-skill.com/skills/jrjsmrtn/project-orchestration-skills/harden-github-actions)

Something wrong with this skill or its page? Tell us.