Sub topic 8
What a top-level pin does not cover: nested actions
This chapter assumes you can read a GitHub Actions workflow and know what a uses: step is. It also assumes you have already pinned an action to a full-length commit SHA, as in the earlier chapters. You should be comfortable with Git tags and commits.
A SHA pin fixes one commit of the action you name. It does not fix anything that commit refers to by a mutable name. Many actions refer to other things: other actions, reusable workflows, container images, and files downloaded at run time. This chapter shows where those references appear, how to find them, and what you can do about them.
How nesting works
Three kinds of reference can sit below your uses: line.
- Composite actions declare
runs.using: compositeand list steps. Each step can have its ownuses:. - Reusable workflows are called with
jobs.<id>.uses:. The called workflow file has jobs, and those jobs have steps withuses:. - Docker container actions build or pull an image, and the image can be named by tag.
In each case, GitHub fetches your pinned commit, reads the file in it, and then resolves whatever that file mentions. The pin controls the first fetch. The nested reference is resolved by its own rules.
Composite actions
Here is a small composite action. Suppose it lives at some-org/setup-tools and you pin it by SHA.
# action.yml in some-org/setup-tools
name: Setup tools
description: Install the toolchain used by our builds
runs:
using: composite
steps:
- uses: some-org/some-action@v1
- run: ./install.sh
shell: bashYour workflow pins only the outer action:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: some-org/setup-tools@0123456789abcdef0123456789abcdef01234567 # v2.3.0The content of action.yml is now fixed. It still says some-org/some-action@v1, and that tag is resolved each time the job runs. If someone moves v1 to a different commit, your job runs the new code. Your own workflow file did not change, and nothing in your repository's history shows it.
The same applies to a local composite action in your own repository. A local action is versioned with your repository, so its file is under your control. If it contains uses: some-org/some-action@v1, that inner reference is as mutable as one in a workflow file. Local actions also need pinned inner references.
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: ./.github/actions/setup-tools # local composite action
# If setup-tools internally uses: some-org/some-action@v1,
# that inner reference is resolved by its own tag, not by a pin here.Composite actions can also nest. An inner action can itself be composite, and its steps can reference further actions. Each level has the same question: is this reference a SHA or a mutable name?
Reusable workflows
A reusable workflow is called at the job level:
jobs:
call-build:
uses: some-org/shared-workflows/.github/workflows/build.yml@7f2c1a9e5b8d4c3a2e1f0a9b8c7d6e5f4a3b2c1d # v1.4.0
with:
node-version: "20"Pinning the called workflow fixes build.yml as it exists in that commit. The steps inside it may contain uses: actions/checkout@v4 or similar. Those references are resolved when the job runs, so the same gap exists.
A reusable workflow has an extra property. It runs in the context of the caller, and you can pass it secrets, either explicitly or with secrets: inherit. A moved tag on an action inside the workflow could therefore reach secrets you handed to the workflow. Treat what you pass to a reusable workflow as available to every action it uses, at any depth.
Container and runtime dependencies
Pins also stop short of what an action does at run time.
- Docker actions. An action with
runs.using: dockerandimage: Dockerfilebuilds an image during your job. The Dockerfile'sFROM node:20is a tag, and it can change. An action withimage: docker://alpine:3.19pulls by tag. Only a digest,docker://alpine@sha256:..., fixes the image. The earlier chapter on pinning by digest covers the syntax. - JavaScript actions. Most JavaScript actions commit their bundled dependencies (often under
dist/) in the repository. The pinned commit therefore contains that bundle. Some actions instead runnpm installat run time, which fetches packages by version range. - Downloaded tools. Setup-style actions often download a binary or script from a URL, sometimes
latest. The action's SHA does not fix what that URL returns unless the action verifies a checksum.
You cannot see these from your workflow file. You find them by reading the action's source at the pinned commit.
Finding nested references
Before you trust a pinned action, list what it references. For a composite action, fetch its action.yml at the pinned SHA and search for uses:. This script does that for one action. It checks both file names the platform accepts, action.yml and action.yaml.
#!/usr/bin/env bash
# usage: ./nested-uses.sh OWNER/REPO SHA [SUBDIRECTORY]
set -euo pipefail
repo="$1"
sha="$2"
dir="${3:-}"
base="https://raw.githubusercontent.com/${repo}/${sha}${dir:+/${dir}}"
for name in action.yml action.yaml; do
if body=$(curl -fsSL "${base}/${name}"); then
echo "== ${repo}@${sha} (${name})"
printf '%s\n' "$body" | grep -nE '^\s*-?\s*(uses|image):' || echo "no uses: or image: lines"
exit 0
fi
done
echo "no action.yml or action.yaml found" >&2
exit 1Run it like this:
./nested-uses.sh actions/checkout 11bd71901bbe5b1630ceea73d27597364c9af683For each line that prints, check whether the reference after @ is a 40-character hexadecimal SHA. Anything else, such as v1, main, or a Docker tag, is mutable. Then repeat for each nested action that is itself composite. For a reusable workflow, open the workflow file at the pinned SHA and read its uses: lines the same way.
What you can do about it
There are several options, with different costs.
| Option | What it fixes | Cost |
|---|---|---|
| Ask the maintainer to pin their inner references | Everyone who uses the action | Depends on the maintainer. You must then update your own pin to the fixed release. |
| Fork the action, pin its inner references, and use your fork by SHA | Your pipelines | You maintain the fork and must merge upstream changes. |
| Copy the steps into your own workflow or local action and pin each one | Your pipelines | You lose the abstraction and take on the update work. |
| Replace the action with a `run:` step that calls a tool you version yourself | Your pipelines | More shell to write, test, and maintain. |
| Use a workflow dependency lockfile | Direct and transitive references, recorded together | You need tooling that supports it. The next chapters cover this. |
Forking has a trap. If you fork an action and pin to a commit in your fork, you are trusting your fork. Keep the fork's inner references pinned too, or you have only moved the problem.
Policy enforcement and nested references
Repository and organization policy can require full-length SHA pinning. That policy is a check on references that GitHub evaluates for your workflows. Do not assume it also rewrites or blocks every unpinned reference that a third-party action makes internally. Test it with a deliberately unpinned inner reference in a scratch repository, and read the current GitHub documentation for the scope of the setting. If the check does not cover nested references, your audit of the action's source is still your only control.
A review routine
When you add or update a third-party action, follow these steps.
- Pin the action to a full-length SHA with a version comment.
- Fetch its
action.ymlat that SHA and list everyuses:andimage:line. - For each nested reference, note whether it is a SHA, a tag, a branch, or a Docker tag.
- For each mutable nested reference, record your decision: accept the risk, fork, vendor, or replace.
- Check whether the action downloads anything at run time, and whether it verifies a checksum.
- Repeat the check when Dependabot proposes a new SHA. A new version can add or change nested references.
Step 6 matters because a version bump is the moment the inner references change. A pull request that only changes a SHA and a comment hides a possibly large change in what runs. Open the diff of the action between the old and new SHA, and look at action.yml and any workflow files first.
Limits of what you learned here
Finding nested references by hand scales poorly. A workflow with fifteen actions, several of them composite, means many files to read, and the picture goes stale at every update. The core problem is that your repository records only the top level of the dependency tree. Package managers solved this long ago with lockfiles, which record every direct and transitive dependency with a resolved version. The next chapters show the same idea applied to workflows.
Exercise
A workflow uses some-org/setup-tools@<40-character SHA> # v2.3.0. The action's action.yml at that SHA is a composite action containing uses: some-org/some-action@v1. A maintainer of some-action moves the v1 tag to a new commit. Does your next run use the new code? Name one way to find this exposure before it happens, and one way to remove it.
Show answer
Yes. The SHA fixes the content of setup-tools' action.yml, but the inner @v1 tag is resolved at run time, so the next run uses the commit that v1 now points to. You can find the exposure by fetching action.yml at the pinned SHA and listing its uses: lines, checking each reference for a full SHA. You can remove it by asking the maintainer to pin the inner reference, forking setup-tools and pinning the inner reference there, copying the steps into your own pinned workflow, or using a lockfile that records the resolved inner SHA.
Exercise
You call a reusable workflow with uses: some-org/shared-workflows/.github/workflows/build.yml@<40-character SHA> and secrets: inherit. Why does an unpinned uses: some-org/some-action@v1 inside build.yml matter more than it would in a workflow with no secrets?
Show answer
The reusable workflow runs with the secrets you pass or inherit. If the v1 tag is moved to malicious code, that code runs in a job that can read those secrets, even though your own file and the called workflow's SHA did not change.