Sub topic 9
Workflow Dependency Lockfiles: The Idea
This chapter assumes you can read a GitHub Actions workflow and know what uses: does. It also assumes you know that a Git tag is a movable label and a commit SHA is a fixed identifier. You should have met a lockfile such as package-lock.json or poetry.lock. Earlier chapters showed how to pin direct references by hand. This chapter explains why that is not enough and what a lockfile adds.
The gap that manual pinning leaves
Pinning actions/checkout to a full-length commit SHA fixes the code that step runs. It fixes nothing the action itself refers to. Composite actions and reusable workflows can call other actions, and each inner uses: is resolved the way its author wrote it. If the author wrote some-org/some-action@v1, the tag v1 is resolved at run time, however carefully you pinned the outer action.
Your workflow therefore has two kinds of dependency:
- Direct dependencies are the references written in your own workflow files. You control these.
- Transitive dependencies are the references inside those actions, and inside the actions they call, to any depth. You do not write them and cannot edit them without forking.
A lockfile is a way to cover the second kind.
What a lockfile records
A dependency lockfile is a committed file that records, for every dependency in the whole graph, the exact immutable version that was resolved. For workflows, that means a commit SHA for each action and reusable workflow. It may also hold a digest for each container image, and it can include the transitive references too.
The idea is the same as in npm or pip:
- You declare what you want in a human-friendly form, such as
actions/checkout@v4. - A tool resolves that request, and everything beneath it, into exact versions.
- The result is written to a file in the repository.
- Later runs use the recorded versions and do not resolve again.
The key property is that resolution happens once, at a moment you choose, and the result is reviewable. Between those moments, a moved tag has no effect on your pipeline.
What the file looks like
Tooling and platform support for workflow lockfiles is still developing, and formats differ between tools. The file below is an illustration of the information a lockfile holds, not the format of any specific tool. The SHAs other than the first are placeholders.
# Illustrative lockfile. Field names vary between tools.
version: 1
dependencies:
- requested: actions/checkout@v4
resolved: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
dependencies: []
- requested: ./.github/actions/setup-tools
resolved: ./.github/actions/setup-tools
dependencies:
- requested: some-org/some-action@v1
resolved: some-org/some-action@0123456789abcdef0123456789abcdef01234567
dependencies:
- requested: docker://example/tool:1.4
resolved: docker://example/tool@sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaThree things are worth noticing:
- Each entry keeps both the requested reference and the resolved one. The requested form tells a human what was intended and gives an update tool something to re-resolve.
- Entries nest. The inner
some-org/some-action@v1appears becausesetup-toolsuses it, and the lockfile pins it even though you never wrote it. - Containers are recorded by digest, since a Docker tag is as movable as a Git tag.
Lockfile versus manual pinning
Manual pinning and lockfiles protect against the same thing, a reference that changes meaning without your knowledge. They differ in where the pin is stored and how far it reaches.
| Aspect | Manual SHA pinning | Lockfile |
|---|---|---|
| Where the pin lives | Inside each `uses:` line | In a separate committed file |
| What you write in workflows | A SHA plus a version comment | A readable reference such as `@v4` |
| Direct dependencies | Covered | Covered |
| Transitive dependencies | Not covered unless each action's author pinned them | Covered, recorded in the file |
| Readability of workflow files | Lower, 40-character hashes | Higher, tags stay visible |
| Review of an update | One line changes per action | One file shows the full set of changes |
| Updating | Edit by hand or with Dependabot | Re-run the resolver and commit the result |
| Enforcement by platform policy | Available as a SHA-pinning requirement | Depends on tool or platform support |
The two approaches are not exclusive. Many teams pin directly now and plan to move to a lockfile when their tooling supports it.
What a lockfile guarantees, and what it does not
A lockfile guarantees reproducibility of references: the same recorded SHAs run each time. That removes the attack where a tag is moved after you reviewed an action.
It does not make the code safe. If you lock a commit that already contains malicious code, you have locked malicious code. Some limits to keep in mind:
- Review is the control. A lockfile turns "which code runs" into a diff a person can read. The protection only exists if someone reads that diff, including the transitive entries.
- Staleness. A locked dependency does not receive security fixes. A lockfile needs a regular update cycle, such as scheduled pull requests, or it will keep running vulnerable versions indefinitely.
- Resolution time is the trust point. The resolver trusts whatever a tag points to on the day you run it. A tag already moved to a bad commit before that day gets locked as is.
- Impostor commits. A SHA from a fork can resolve through the parent repository's network. A resolver should check that the commit is reachable from the intended repository. A lockfile that records the SHA does not prove this by itself.
- Mutable inputs elsewhere. Actions often download tools at run time, for example with
curlor a package install. A lockfile of workflow dependencies does not cover those downloads.
Edge cases to plan for
Reusable workflows. A job-level uses: org/repo/.github/workflows/build.yml@v2 is a dependency with its own steps, and those steps have their own references. A complete lockfile walks into it the same way it walks into a composite action.
Local actions. A reference starting with ./ points at files in your own repository, at the commit being run. It has no separate version to lock. Its contents are still checked in with your code, but the remote actions it calls need entries, as the illustration above shows.
Version ranges. A requested @v4 can match many commits over time. The lockfile freezes one of them. Updating means asking the resolver for the newest commit that matches v4 and committing the new SHA.
Merge conflicts. If two branches update different dependencies, the lockfile can conflict. Treat it like package-lock.json: resolve by re-running the tool, and do not edit the SHAs by hand.
Drift between file and workflows. If someone adds a uses: line without updating the lockfile, the workflow and the file disagree. A good setup fails the build in that case, so check for a verification mode in your tooling and run it in CI.
Seeing your direct dependencies
Before adopting a lockfile tool, you can inventory what you have. The script below scans the workflow files in a repository and classifies each uses: reference. It needs PyYAML (pip install pyyaml). It sees only direct references. It cannot look inside actions, which is the gap a lockfile resolver closes.
import re
import sys
from pathlib import Path
import yaml
SHA = re.compile(r"^[0-9a-f]{40}$")
def refs(workflow):
"""Yield (job name, uses value) for job-level and step-level references."""
for job_name, job in (workflow.get("jobs") or {}).items():
if "uses" in job:
yield job_name, job["uses"]
for step in job.get("steps") or []:
if "uses" in step:
yield job_name, step["uses"]
def classify(ref):
if ref.startswith("./"):
return "local"
if ref.startswith("docker://"):
return "digest" if "@sha256:" in ref else "docker-tag"
_, _, version = ref.partition("@")
return "sha" if SHA.match(version) else "mutable"
def main():
root = Path(sys.argv[1] if len(sys.argv) > 1 else ".")
counts = {}
for path in sorted((root / ".github" / "workflows").glob("*.y*ml")):
workflow = yaml.safe_load(path.read_text()) or {}
for job, ref in refs(workflow):
kind = classify(ref)
counts[kind] = counts.get(kind, 0) + 1
print(f"{kind:10} {path.name}:{job}: {ref}")
print("summary:", counts)
if __name__ == "__main__":
main()Run it from the repository root with python scan_uses.py. Every line labelled mutable or docker-tag is a direct reference that a lockfile, or a manual pin, would need to fix. Lines labelled sha or digest are direct pins, but their transitive references are still unknown to this script.
Choosing when to adopt one
A lockfile pays off most when many workflows share many actions, when composite actions and reusable workflows are common, or when reviewers need one place to see all third-party code. For a repository with three workflows that use only well-known actions, direct SHA pinning with Dependabot may be enough, and the extra file adds little. The strategy chapter at the end of this tutorial returns to this decision.
Exercise
Your workflow pins acme/deploy@<full SHA>. The acme/deploy action is a composite action whose action.yml contains uses: other-org/helper@v2. A maintainer of other-org/helper moves the v2 tag to a new commit. Does your pipeline run the new commit? What would a lockfile change here?
Show answer
Yes. Pinning acme/deploy fixes only that action's own files. The inner reference other-org/helper@v2 is resolved by tag when the action runs, so the moved tag takes effect. A lockfile would record other-org/helper as a nested dependency of acme/deploy, with its resolved commit SHA. Runs would then use that recorded commit, and the new commit would only appear after someone re-resolved and reviewed the lockfile diff.
Exercise
A teammate says that once a lockfile is committed, the workflows are safe. Give two reasons this is wrong.
Show answer
Any two of these: a lockfile freezes whatever the tag pointed to at resolution time, which may already be malicious. It does not provide security updates, so locked versions go stale. It does not cover files that actions download at run time. It does not prove that a SHA belongs to the intended repository unless the resolver checks that. It only protects if someone reviews the diff, including the transitive entries.