Sub topic 13
Choosing a strategy: costs, limits, and what pinning does not fix
This chapter assumes you can read a GitHub Actions workflow and know what a uses: reference is. It also assumes you know how tags and commits relate in Git, and that you have seen SHA pinning, Dependabot updates, and the idea of a lockfile in earlier chapters. Here you combine those pieces into a decision. You will also see which risks stay open after you pin.
The options on the table
Most teams end up choosing from four approaches. They differ in who does the resolving and how much of the dependency tree they cover.
| Strategy | What it fixes | What it costs | What it leaves open |
|---|---|---|---|
| Tags only (`@v4`) | Nothing. You get automatic updates. | None up front. | A moved tag runs new code in your pipeline with no review. |
| Manual SHA pinning | Direct actions run the same code on every run. | You resolve SHAs, add version comments, and review updates. | Nested actions inside composite actions and reusable workflows. |
| SHA pinning plus Dependabot and policy | Direct pins stay current and unpinned references are blocked. | Weekly update pull requests, policy setup, and exceptions to manage. | Transitive references and anything the action fetches at runtime. |
| Lockfile | Direct and transitive dependencies are recorded with resolved SHAs. | A new file to generate, review, and keep in sync. | Malicious or vulnerable code at the locked SHA. |
The security gain grows down the table, and so does the process you must maintain. Pick the lowest row whose gaps you can accept. Do not pick the highest row by default.
What each cost looks like in practice
Reviewability
A tag reference such as actions/checkout@v4 reads well but hides the code. A SHA reference shows the exact commit but is unreadable on its own. The version comment bridges the two, and Dependabot rewrites it when it updates the pin. This only works if the comment stays accurate. A comment that says # v4.2.2 next to a SHA from a different release misleads reviewers. Treat a mismatched comment as a defect in code review.
Updates also change what you review. With tags, an update is invisible. With pins, every update is a pull request with a diff of SHAs. Reviewers rarely read the upstream changes behind that diff. The pull request body from Dependabot links to release notes and a commit list, so use it. For high-privilege workflows, such as those that publish packages or deploy, look at the actual upstream diff before merging.
Update lag
Pinning removes silent updates, so you now own the delay between an upstream fix and your adoption of it. If you ignore update pull requests, your pins go stale and you run old code, including old vulnerabilities. A weekly Dependabot schedule is a reasonable default. Daily updates give faster fixes but more review noise.
You can also use the delay on purpose. Dependabot supports a cooldown setting that waits a number of days after a release before proposing it:
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
cooldown:
default-days: 7A short cooldown gives the community time to notice a compromised release before it reaches you. The trade-off is that real security fixes also arrive a week late. Check the current Dependabot documentation for how your configuration treats security updates.
Policy friction
The repository or organization setting that requires full-length SHA pinning makes unpinned uses: references fail. This turns pinning from a habit into a rule. It also breaks workflows that use tags, so roll it out in steps. First inventory the existing references, then pin them, then enable the policy. Decide in advance how to handle actions you cannot pin. Those are mostly local actions referenced by path, which are not pinned because they live in your own repository, and actions you will allow only through an allowlist.
Limits of pinning
Pinning gives you one guarantee: the same reference resolves to the same commit every time. It says nothing about whether that commit is safe. These are the main gaps.
The pinned code can be bad
If you pin a SHA that is already malicious, you have locked in the problem. The same applies if the action has a vulnerability. Pinning protects you from changes after you looked, which is useful only if you looked. Verify the SHA against the intended repository, as covered earlier. Be aware of impostor commits. A commit that exists in a fork network can be addressed through the parent repository's URL, so a SHA that resolves is not proof that it belongs to the upstream project's history.
Transitive references
A pin on an outer action does not control what that action calls. A composite action or reusable workflow can reference other actions by tag, and those inner references resolve by their own rules. If the action's author pinned them, you are covered. If not, a moved inner tag still changes your pipeline. A lockfile addresses this by recording every nested reference with its resolved SHA. Without one, your options are to audit the action's source, to choose actions whose authors pin their dependencies, or to fork the action into your organization and pin the inner references there.
Runtime downloads
An action pinned to a SHA can still fetch code when it runs. It might call curl | bash, run npm install without a lockfile, pull a Docker image by tag, or download a binary from a release page. None of that is covered by the action's SHA. A JavaScript action that bundles its dependencies in dist/ is easier to reason about than one that installs at runtime. For Docker-based actions, check whether the image reference uses a digest (@sha256:...) or a tag.
Permissions and secrets
Pinning does not reduce what a running action can do. A compromised pinned action that you reviewed once still has the permissions of your job. Limit that exposure with the following steps:
- Set
permissions:at the top of the workflow to the minimum, and widen it per job only where needed. - Keep secrets out of jobs that run third-party actions when you can, and scope them to environments.
- Avoid running untrusted pull request code with write tokens or secrets.
name: ci
on:
pull_request:
permissions:
contents: read
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- run: echo "Tests would run here"With contents: read, a compromised action in this job cannot push to the repository or write releases using the default token. The pin and the permission block solve different problems, and you need both.
Script injection and other workflow bugs
Pinning does nothing for flaws in your own workflow. Interpolating untrusted values such as a pull request title directly into a run: script is injection, and it works the same with pinned actions. Pass such values through environment variables and quote them in the shell.
A decision flow
The right level depends on what the workflow can reach. A workflow that lints documentation with a read-only token carries less risk than one that publishes to a package registry.
Even the low-risk branch has conditions. "Trusted publisher" is a judgment about an organization's account security, not a property of the tag. Many teams pin everything anyway, because one consistent rule is easier to enforce than a per-workflow risk judgment.
Manual pinning versus a lockfile
The two approaches differ in where the truth lives. With manual pinning, the truth is scattered across uses: lines, and each line covers one direct dependency. With a lockfile, the truth is one reviewable file that lists every resolved dependency, direct and nested, and a change to that file is a change to your supply chain.
Choose manual pinning plus Dependabot when:
- your workflows use few actions, mostly from large, well-maintained publishers;
- you can read the action source and see its nested references;
- the tooling for lockfiles in your environment is not available or stable.
Choose a lockfile when:
- you depend on composite actions or reusable workflows you do not control;
- you need a single place for auditors to see every dependency;
- you want a CI check that fails when the lockfile and the workflows disagree.
A lockfile carries the same limits as a pin. It records what resolved, not whether it is trustworthy. It also adds a step. Someone must regenerate it when workflows change and review the diff, and the diff is only valuable if people read it.
What to do after you pin
Pinning is the first step. A sensible sequence for a team is:
- Pin every direct action to a full-length SHA with an accurate version comment.
- Enable Dependabot for
github-actionsand decide on a schedule and cooldown. - Turn on the SHA pinning policy once the inventory is clean.
- Set minimal
permissions:in every workflow. - Review the nested references of any composite action or reusable workflow you rely on, or adopt a lockfile.
- Review update pull requests for privileged workflows against the upstream diff.
Exercise
A team pins every direct action to a SHA, enables Dependabot, and turns on the SHA pinning policy. A month later, a composite action they use is compromised because its author moved a tag on an inner action it references. Why did the pins not stop this, and name two measures that could have.
Show answer
The pins only cover the references written in the team's own workflows. The composite action's inner reference resolves by its own tag, so the moved tag changed the code that ran. Two measures that could have helped: using a lockfile that records the nested action's resolved SHA, or forking the composite action into the organization and pinning its inner references. Auditing the action's source before adopting it, or limiting the job's permissions and secrets to reduce the damage, also count.
Exercise
You are deciding between "tags from trusted publishers" and "SHA pins with Dependabot" for two workflows: one lints Markdown with contents: read, and one publishes a package using a registry token. Which strategy would you choose for each, and what is the main cost of your choice for the publishing workflow?
Show answer
The linting workflow can reasonably use tags from trusted publishers, since it has a read-only token and no secrets. Pinning it anyway is also defensible for consistency. The publishing workflow should use SHA pins with Dependabot, because it can reach a registry token. The main cost is the ongoing review of update pull requests and the delay before upstream fixes are adopted, which you can reduce by reviewing the upstream diff for each update and using a short schedule.