Sub topic 13
Choosing a Strategy: Costs, Limits, and What Pinning Does Not Fix
This chapter assumes you have read the earlier chapters. You should know how uses: references resolve, how to pin to a full-length commit SHA, how Dependabot updates pins, and what a workflow lockfile records. Here you compare the options and learn where each one stops protecting you.
The options side by side
You have four realistic strategies. They differ in what they fix and what they cost.
| Strategy | Protects against retagging | Covers transitive dependencies | Maintenance cost | Readability |
|---|---|---|---|---|
| Tags only (`@v4`) | No | No | Lowest | Best |
| Manual SHA pins with version comments | Yes, for direct references | No | Medium | Good with comments |
| SHA pins plus Dependabot and a policy | Yes, and enforced | No | Low after setup | Good |
| Workflow lockfile | Yes | Yes, if the tool resolves them | Depends on tooling | Needs review of generated data |
The cost of manual pinning is mostly update work. A pin never moves on its own, so you must bring in security fixes deliberately. Dependabot reduces that work but adds a steady stream of pull requests that someone must review.
Matching the strategy to the risk
Ask what a compromised action could do in your pipeline. The answer depends on what the job can reach.
A job that publishes packages, deploys to production, or holds a long-lived cloud credential deserves the strictest option. A job that only runs a linter on a public repository with read-only permissions carries much less risk. A practical rule: pin everything that runs with secrets, and apply the repository policy everywhere so the rule stays simple.
Limits of pinning
Pinning fixes one problem: the code behind a reference changing without your knowledge. It does not fix several others.
- A malicious release you pinned on purpose. If you pin the SHA of a compromised commit, you run compromised code every time. Pinning gives repeatability, not trust.
- Delayed updates. A pinned workflow does not receive a maintainer's security patch until you update the pin.
- Transitive references. As the composite action example showed, a pin on the outer action leaves inner references resolved by their own tags, unless the author pinned them.
- Downloads at run time. An action that fetches a binary or runs
curl | bashcan change behavior even when its own SHA is fixed. - Excess permissions. A pinned action still receives whatever the job's
GITHUB_TOKENand secrets allow.
Because of the last point, pinning works best next to least-privilege settings:
permissions:
contents: read
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2The workflow-level permissions block limits what any step can do with the token, even if a pinned action later proves malicious.
Lockfile versus manual pinning
Manual pins are simple and need no extra tools, but you must audit nested references by hand. A lockfile records every direct and transitive dependency with its resolved SHA, so a reviewer can see the full set in one place. The cost is dependence on tooling and a generated file that reviewers must actually read. A lockfile that nobody reviews adds a file to the repository without adding safety.
A sensible progression is to start with SHA pins, a version comment, Dependabot, and the enforcement policy. Move to a lockfile when nested dependencies matter, for example when you rely on third-party composite actions or reusable workflows.
Exercise
A team pins every action to a full SHA and enables the policy that requires SHA pinning. One workflow still uses a third-party composite action whose own steps reference some-org/some-action@v1. Name one risk that remains and one measure that addresses it.
Show answer
The inner some-org/some-action@v1 is resolved by its tag, so retagging that action can still change what runs. A workflow lockfile that records the transitive SHA, or replacing the composite action with one whose author pins its inner references, addresses this. Setting minimal permissions also limits the damage.