Automation

GitHub Actions Lockfile: Pin Workflow Dependencies Securely

GitHub Actions now refuses to run a workflow that references an action your repository has not locked. The workflow dependency lockfile records the exact commit behind every action ref, so a moved tag or a surprise @main no longer decides what runs in your pipeline.

Original content from computingforgeeks.com - post 186002

Everything below was built and run with gh-actions-lock v0.4.1 against two public test repositories in November 2026, so every command below comes from those runs. You’ll generate .github/workflows/actions.lock with the gh-actions-lock extension, watch a run die when a new action skips the lockfile, and gate pull requests with gh actions-lock --verify.

What the lockfile pins

A generated file at .github/workflows/actions.lock maps each workflow to the actions it uses and pins every one to a commit. You never write it by hand, because the gh-actions-lock extension scans your uses: lines, resolves each ref against the upstream repository, and records what it found. The format in use today is v0.0.3, and the file’s own header warns against hand edits, so every change flows through the tool, including a correction to a pin you got wrong the first time.

One entry per dependency holds four things:

  1. The ref as your workflow spells it, for example v4.4.0.
  2. The commit that ref resolved to when you generated the file, stored as sha1-<40 hex characters>.
  3. The owner and repository IDs, so the same name under a different owner is a different dependency.
  4. The workflow files that use it, so coverage is checked per workflow, not per repository.

Enforcement happens on the runner side, which is what separates this from a linting convention. When a workflow starts, the runner checks each uses: ref against the lockfile entry for that workflow, and a ref that is missing or changed fails the run before any job executes, before a single step even downloads. You see it as a startup_failure, which is what the next sections produce on purpose.

Calls to reusable workflows are the one gap the lockfile leaves open. The lockfile does not pin jobs.<job_id>.uses entries, so pin a reusable workflow by its full-length commit SHA in the workflow file itself. Its own actions are covered by the lockfile of the repository where it is defined, not the caller’s, a split GitHub’s lockfile documentation states outright.

Install the lockfile extension

Tooling ships as a gh CLI extension maintained by GitHub, so you need the GitHub CLI installed first. Then add the extension pinned to a known release:

gh extension install github/gh-actions-lock --pin v0.4.1 # https://github.com/github/gh-actions-lock/releases

Installation is one command. It works on the free plan for public and private repositories alike, and it talks to the GitHub API with the token your gh session already holds, so there is no extra credential to manage.

One naming trap sits next to that install command. The extension this guide uses is github/gh-actions-lock, GitHub’s own, while a similarly named third-party extension, gjtorikian/gh-actions-lockfile, exists for the same problem with its own commands. Everything below only works with GitHub’s extension, so check the owner slug before you install.

Generate the first lockfile

Run it once from the repository root and it scans every workflow, plans a pin for each action, and writes the lockfile:

gh actions-lock

If your workflows call composite actions inside the repository, the plain command refuses to write anything and names the flag. A ./ path depends on the workspace checkout, so the lockfile can’t cover it, which is why --migrate-local-actions rewrites those refs to the $/ form the runner resolves from the same repository at the commit the workflow runs on. The demo repository has one, and its first run used the flag:

gh actions-lock --migrate-local-actions
Scanning 1 workflow
Planning pins
Migrated 1 local action to `$/…`
Pinned 3 actions across 1 workflow
  actions/[email protected] (11d5960)
    └─ .github/workflows/ci.yml
  c4geeks/[email protected] (fc276c9)
    └─ .github/workflows/ci.yml
  actions/[email protected] (49933ea)
    └─ .github/workflows/ci.yml

Commit the lockfile together with any workflow change. The screenshot below is the demo repository’s first run at commit 2b12ef5 (its main branch has moved on since, so browse that commit rather than main), and your output should look the same.

gh actions-lock onboarding output pinning three actions to commit SHAs

Here is what the generated file looks like, with one block per dependency:

cat .github/workflows/actions.lock
# This file is machine-generated by `gh actions-lock`.
# Do not edit by hand; run `gh actions-lock` to update.
# Docs: https://gh.io/actions-lockfile
version: 'v0.0.3'
workflows:
    '.github/workflows/ci.yml':
        - 'actions/[email protected]'
        - 'actions/[email protected]'
        - 'c4geeks/[email protected]'
dependencies:
    'actions/[email protected]':
        ref: 'v4.4.0'
        commit: 'sha1-11d5960a326750d5838078e36cf38b85af677262'
        owner_id: 44036562
        repo_id: 197814629
    'actions/[email protected]':
        ref: 'v4.4.0'
        commit: 'sha1-49933ea5288caeca8642d1e84afbd3f7d6820020'
        owner_id: 44036562
        repo_id: 189476904
    'c4geeks/[email protected]':
        ref: 'v1.0.0'
        commit: 'sha1-fc276c9ae20b0d51e71743cd0e86f2c8de480149'
        owner_id: 276032433
        repo_id: 1450786324

Notice the workflows: section lists the actions per file, and the dependencies: section holds the pins. That split is what lets the runner reject a change to one workflow without caring about the rest of the repository. The gate workflow this guide adds later joins the workflows: section the same way, through one more regeneration rather than a hand edit.

actions.lock contents with pinned commit SHAs per workflow

Reading the file takes seconds once you know the two sections. Every debugging session with this file starts at the workflow whose run just failed, and the next section shows the failure you will meet first.

Add an action without the lockfile

You’ll hit one failure mode more than any other: forgetting the regeneration step. The demo added an artifact upload with actions/upload-artifact@v4, committed it, and pushed, without touching the lockfile. The run never started a job, so the mistake cost seconds of runner time instead of a green checkmark hiding new code:

Error: “Invalid lockfile: .github/workflows/actions.lock#L1”

Expect a startup_failure on the run page, with this annotation:

Invalid lockfile: .github/workflows/actions.lock#L1
The lockfile is missing `actions/upload-artifact@v4`. Regenerate it by running `gh actions-lock`.

GitHub names the exact remedy in that annotation, and it is one command. Running gh actions-lock again picks up the new action, pins it, and stages the lockfile update:

Actions run rejected with startup failure because the lockfile is missing upload-artifact
  1. 1Invalid lockfile: action missing
  2. 2Lockfile view

The rerun output stays short, because only one action was missing from the lockfile. It pins the new dependency and stages the update:

Scanning 1 workflow
Planning pins
Pinned 1 action across 1 workflow
  actions/[email protected] (ea165f8)
    └─ .github/workflows/ci.yml

Commit the lockfile alongside the workflow change and push again. The next run executes normally. The recovery is a three-step loop you’ll repeat until the CI gate automates the check for you:

  1. Run gh actions-lock from the repository root.
  2. Commit the lockfile together with the workflow change.
  3. Push and confirm the run starts.

Package managers taught this habit years ago, and it transfers directly. The lockfile is part of every workflow change, the same way a dependency bump carries its lockfile update, because one that lags behind the code isn’t protecting anything. If you use Dagger pipelines on GitHub Actions, the same loop covers the container actions those workflows pull in.

Move a tag and watch the pin hold

Pinning to a lockfile beats pinning to a version tag, because a tag is just a mutable pointer that anyone with write access can drag. The demo action repository’s v1.0.0 tag was force-moved upstream to a brand new commit while the consumer repository kept its lockfile. The next workflow run stayed green, and the runner log showed why:

Download action repository 'c4geeks/[email protected]' (SHA:fc276c9ae20b0d51e71743cd0e86f2c8de480149)

What the runner downloaded was the commit recorded in the lockfile since the first generation, not the one the tag pointed at after the move. The action’s own version output printed the old version string, proving the old code ran. So a moved tag changes nothing about your pipeline until you choose to repin, which is the property the whole design is built around.

There are two edges where the pin breaks instead of holding. The runner rejects the run when the locked commit is no longer reachable from the branch or tag recorded in the lockfile, and it rejects it the same way when the commit exists only in a fork rather than the action’s own repository. Both failures are the correct signal to look at what happened upstream, since a commit vanishing from a public action’s history is itself worth investigating, and the next section covers the command that handles the first case.

Repin after a force-pushed tag

When you decide a moved tag should flow into your pipeline, --relock is the command. It re-resolves every existing pin against upstream and refuses to guess. With the demo tag force-moved to a commit outside the locked commit’s history, it stopped and wrote nothing:

Error: “Pinned commit not in upstream history”

By this point the demo had already relocked once to 37faf79 after the first tag move. The second move, to the orphan commit c85f7d3, is what made that locked commit unreachable, and running --relock then stopped before the write stage. The terminal showed the refusal:

✗ Pinned commit not in upstream history c4geeks/[email protected]
  locked commit 37faf79198be is not in c4geeks/actions-lockfile-demo-tag's history: it was force-pushed away, or the lockfile was edited; v1.0.0 currently points at c85f7d32529a
  ↳ https://github.com/c4geeks/actions-lockfile-demo-tag/releases
  ! verify it, then run `gh actions-lock --accept-moved`
Nothing was written: fix the errors above and re-run

Refusing is the safety feature, not an obstacle. The error names both commits, links the releases page, and tells you which flag bypasses it, so a repin stays a decision you made with the facts in front of you. The sequence that respects that design runs in order:

  1. Open the release diff and read what the new commit actually changes.
  2. Confirm the change is one you want running in your workflows.
  3. Run gh actions-lock --relock --accept-moved and commit the result.

Once you have verified the change, the acceptance flag re-pins without asking again:

gh actions-lock --relock --accept-moved

Its output records the old and new commits side by side, the line to paste into your PR description so a reviewer sees the jump at a glance. Treat --accept-moved as a reviewed action, never a reflex, because it accepts whatever the ref currently points at. The refusal you just read exists to make that a choice instead of a default.

gh actions-lock relock refusing a force-moved tag and accept-moved repinning it

One repin, one commit, and the consumer is back on a commit you chose. Pinning by hand does not scale across a team, though, so the next step is making CI enforce the lockfile for everyone.

Gate pull requests with –verify

A lockfile that drifts in a pull request fails at run time, which is late, and nobody watches runs overnight. A CI gate catches it in seconds instead, while the pull request is still open and the author still has context. Add a workflow that runs gh actions-lock --verify on any change to the workflows directory:

sudo vim .github/workflows/verify-lockfile.yml

Add this workflow, which is the exact file running on the demo repository:

name: verify-lockfile

on:
  pull_request:
    paths:
      - '.github/workflows/**'
  push:
    branches: [main]
    paths:
      - '.github/workflows/**'

jobs:
  verify:
    runs-on: ubuntu-latest
    permissions:
      contents: read
    steps:
      - uses: actions/[email protected]
      - uses: actions/[email protected]
        with:
          node-version: '22'
      - name: Install the lockfile CLI
        run: gh extension install github/gh-actions-lock --pin v0.4.1
        env:
          GH_TOKEN: ${{ github.token }}
      - name: Verify the lockfile covers every workflow
        run: gh actions-lock --verify
        env:
          GH_TOKEN: ${{ github.token }}

Pin the gate’s own actions to full version tags, because the gate workflow is covered by the same lockfile as everything else. That bit the demo on the first attempt, when the new verify-lockfile.yml workflow failed its own check, and a rerun of gh actions-lock added it. So budget one extra regeneration when you introduce a workflow, not just when you add an action.

With the gate in place, a pull request that adds actions/cache@v4 without regenerating the lockfile fails in under ten seconds:

Pull request checks failing on the verify-lockfile job

Coverage is what the gate verifies, and the repo policy layer can go one step further by requiring SHA pinning outright. A workflow onboarded to the lockfile satisfies that policy even though it still spells tag refs, because the lockfile is what pins it. Setting the policy through the API works on the free plan. Reading it back shows it live:

gh api repos/c4geeks/actions-lockfile-demo/actions/permissions
{"enabled":true,"allowed_actions":"all","sha_pinning_required":true}

--verify-local is the offline sibling, useful when you want a coverage check without API calls. GitHub’s lockfile documentation lists Dependabot version updates as a benefit of the format. Dependabot wasn’t configured on the demo repository, so its regeneration behavior wasn’t tested here, and the CI gate is the enforcement you can rely on. The same verify workflow ports to other GitHub-compatible CI with almost no changes, so the lockfile habit survives a move to Forgejo Actions or a self-hosted runner.

gh actions-lock verify and verify-local passing plus the sha pinning repo policy

Pinning and gating cover what your workflows run, but they do not change how those workflows authenticate. For the credentials side of the same problem, workload identity federation for GitHub Actions removes the long-lived cloud keys. That keeps a leaked token from turning into a full cloud incident.

Lockfile command reference

Every flag the daily workflow needs, in the order you will reach for them:

CommandWhat it does
gh actions-lockScan, pin every action, write the lockfile
gh actions-lock --verifyCheck coverage; the CI gate command
gh actions-lock --verify-localCoverage check with no API calls
gh actions-lock --relockRe-resolve pins; refuses unreachable commits
gh actions-lock --relock --accept-movedAccept a moved ref you have verified
gh actions-lock --migrate-local-actionsRewrite ./ composite actions to $/
gh actions-lock --no-fixReport problems only, change nothing

Start with the generate command on your most-used repository, add the verify workflow the same day, and the lockfile quietly does the rest. The full reference lives in GitHub’s workflow dependency lockfile documentation. The demo repository used throughout this guide is public if you want to compare your output against it. Its main branch has moved on since these captures (ci.yml now calls the tag action at @v1.0.2), so the captures here come from earlier commits in its history, starting with the first lockfile commit 2b12ef5.

Keep reading

Java4Shell (CVE-2026-114938): Find and Patch Vulnerable JVMs Security Java4Shell (CVE-2026-114938): Find and Patch Vulnerable JVMs UFW Firewall Commands with Examples on Ubuntu 26.04 / 24.04 Security UFW Firewall Commands with Examples on Ubuntu 26.04 / 24.04 nginx HTTP/2 RCE CVE-2026-123007: Check, Disable HTTP/2, Patch Security nginx HTTP/2 RCE CVE-2026-123007: Check, Disable HTTP/2, Patch Join Fedora 45 / 44 to FreeIPA: ipa-client-install, SSSD, sudo Fedora Join Fedora 45 / 44 to FreeIPA: ipa-client-install, SSSD, sudo ARTEX AI Penetration Testing: Self-Hosted Install Guide AI ARTEX AI Penetration Testing: Self-Hosted Install Guide Generate Host Overview from Ansible Facts Ansible Generate Host Overview from Ansible Facts

Leave a Comment

Press ESC to close