Sub topic 8
What a top-level pin does not cover: nested actions
This chapter assumes you can read a GitHub Actions workflow, know how SHA pinning works for a uses: step, and know what a composite action is. It covers the references your pin does not control.
The pin stops at the first level
A full-length commit SHA fixes the content of the repository you reference. If that content refers to other actions, those references resolve by whatever the author wrote. Your pin does not rewrite them.
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.The same applies to a third-party composite action. Suppose you pin acme/setup@<sha>. Its action.yml might contain this:
runs:
using: composite
steps:
- uses: some-org/some-action@v1
- run: ./install.sh
shell: bashThe commit of acme/setup never changes. But some-org/some-action@v1 is a tag, so someone who can move that tag changes the code your job runs. The tag move is not visible in your repository and does not show up in your pull requests.
Where nested references come from
Four sources of indirect dependencies are worth checking.
| Source | What it can reference | Who controls the reference |
|---|---|---|
| Composite action | Other actions in `runs.steps[].uses` | The action's author |
| Reusable workflow | Actions in its jobs' steps, and other reusable workflows | The workflow's author |
| Docker action | A base image in the `Dockerfile`, or `docker://` image tags | The action's author |
| JavaScript action | Bundled npm dependencies | The action's author, at build time |
Pinning a reusable workflow to a SHA does freeze its file content. That is better than a tag. The uses: lines inside that file are still whatever the author committed, so pinned content can still point at tags.
How to see what you depend on
You can inspect nested references by hand:
- Open the
action.yml(oraction.yaml) of each action at the pinned SHA. - For composites, read every
uses:underruns.steps. - For reusable workflows, read the called file at the pinned SHA.
- Repeat for each nested action, because the chain can be several levels deep.
You can also search a cloned repository quickly:
grep -rnE 'uses:\s+\S+@' .github/ | grep -vE '@[0-9a-f]{40}'This prints every uses: line in your own workflows that is not pinned to a 40-character hex SHA. It only covers files you have locally. For a third-party action, run the same search on a checkout of the action at the pinned SHA.
What you can do about it
You have a few options, and none of them fixes everything alone.
- Prefer actions whose authors pin their own nested references. Check this before you adopt an action.
- Vendor or fork critical actions. In a fork you control, you can pin nested references yourself and then pin your fork by SHA.
- Replace a thin composite action with inline
run:steps in your own workflow, where you pin everyuses:directly. - Use a workflow dependency lockfile, which records the resolved SHA of every direct and transitive dependency. The next chapters cover it.
Exercise
You pin acme/deploy@<full-sha> in your workflow. Its action.yml is a composite action with a step uses: other-org/helper@v2. Can the code your job runs change without any commit to your repository or to acme/deploy? Why?
Show answer
Yes. The step other-org/helper@v2 uses a tag, and the owner of other-org/helper (or anyone with write access) can move v2 to a different commit. Your pin fixes only acme/deploy, so the nested action can still change.