Post

Lock Your GitHub Actions (Now That Agents Write Workflows)

Alex Garrett-SmithNov 207 min read
Lock Your GitHub Actions (Now That Agents Write Workflows)

A lot of our GitHub Actions workflows are written by agents now, and they're very happy to add another uses: line whenever a job needs one. That's mostly fine, but stolen GitHub tokens have been going after CI this month, so it's a good time to lock things down.

Aikido has been tracking one campaign, wfx-loot, which since 10 November has used stolen tokens with write access to push a secret stealer into tens of thousands of repositories. By Aikido's count, at least 1,835 of them ran the payload. If you want to check your own repos, the post ends with the branch names and commit messages to look for.

There are two changes you can make this afternoon. We'll pin every action your workflows run with a lockfile, so a moved tag can't swap in new code, and then move the secrets that matter somewhere a throwaway branch can't reach them. Let's dive in.

Pin your actions with a lockfile

Here's a step you'll find in most workflows, and probably in a few your agent has written:

Text
-uses:actions/[email protected]

That looks pinned, but it isn't really. GitHub runs whatever commit the v7.0.1 tag points to when the job starts, and tags can move. If an action maintainer's account is compromised and the tag gets repointed, your next run picks up the new code without anything changing in your repo (GitHub Docs).

You might be thinking you could pin a full commit SHA instead. That works for the actions you list yourself, but not for the actions those actions use.

Workflow lockfiles went generally available on 28 October, and they handle both. A lockfile at .github/workflows/actions.lock records a verified commit for every action your workflows use, nested ones included, while your workflow files keep their readable tags. (If you've used GitHub Agentic Workflows, this isn't the .lock.yml file it compiles.)

Create the lockfile

Hugo van Kemenade's walkthrough is the friendliest setup guide I've seen. Install the gh extension, then run it in your repo:

Text
$ gh extension install github/gh-actions-lock
✓ Installed extension github/gh-actions-lock
$ gh actions-lock

✓ All 1 workflows valid

Two things change. Your uses: lines get rewritten to the full version tag it resolved (so @v3 can become @v3.1.0), and a new actions.lock file appears with an entry for each action:

Text
dependencies:
    'actions/[email protected]':
        ref:'v7.0.1'
        commit:'sha1-3d3c42e5aac5ba805825da76410c181273ba90b1'
        owner_id:44036562
        repo_id:197814629

Behind the scenes, GitHub now runs the locked commit, whatever the tag points to today. It also checks that the commit is still reachable from the tag and that owner_id and repo_id still match, so a repointed tag gets you either the code you locked or a failed job.

Check the rewritten tags in the diff, then commit it all.

Fail CI when the lockfile is stale

A lockfile only helps while it matches your workflows, so let's get CI to check it. Copy GitHub's verify-lockfile.yml into .github/workflows/:

Text
name:verify-lockfile

on:
  pull_request:
  push:
    branches:
      -main

permissions:
  contents:read

jobs:
  verify:
    runs-on:ubuntu-latest
    env:
      GH_TOKEN:${{ github.token }}
    steps:
      -uses:actions/[email protected]
        with:
          persist-credentials:false
      -run:gh extension install github/gh-actions-lock --pin v0.4.1
      -run:gh actions-lock --verify

The --verify flag runs the same checks without writing anything, so the job fails if an action is missing from the lockfile or a locked commit no longer verifies upstream.

You know what's coming... this new workflow has its own uses: line, so run gh actions-lock once more to lock it.

Keeping it up to date

When Dependabot bumps a locked action, it regenerates the lockfile entry in the same pull request, and Renovate has experimental support too. For a new workflow or a new uses: line, run gh actions-lock again.

That goes for your agent as well, so add a line like this to its rules file:

Text
After editing anything in .github/workflows, run `gh actions-lock` and commit the updated lockfile.

Or install GitHub's own skill with gh skill install github/gh-actions-lock (from the extension's README). If your agent forgets anyway, the verify job fails on its pull request.

Keep your secrets away from throwaway branches

The wfx-loot payload grabbed every secret the job could see with ${{ toJSON(secrets) }}, along with the GITHUB_TOKEN and credentials for AI tools like Anthropic, OpenAI and Cursor. So your agent's API keys count too.

Anyone with write access to a repo can read all of its secrets (GitHub's security reference), because they can push a workflow that uses them on any branch. One wfx-loot variant did this on a throwaway chore/ branch.

Move the secrets that matter into an environment

An environment is a named set of secrets and protection rules, and its secrets only reach jobs that reference it. Head to Settings > Environments > New environment, call it production, then:

  1. Under Required reviewers, add yourself or your team. If there's more than one of you, tick Prevent self-review too, so whoever triggered a deploy can't approve it.
  2. Set Deployment branches to Selected branches and tags, with a rule for main.
  3. Add your deploy keys, cloud credentials and publishing tokens as environment secrets, then delete the repository copies. What's happening here is that every protection rule has to pass before a job that references the environment is sent to a runner. A workflow on a throwaway branch can say environment: production all it likes, but the job never starts.

Your plan matters for private repos, though. Public repos get all of this on every current plan, but GitHub Free has no environments for private repos, and on Pro and Team, required reviewers only work on public ones (GitHub Docs). On a private Pro or Team repo, the branch rule still keeps throwaway branches away from your secrets.

Start every workflow with zero permissions

Then there's the GITHUB_TOKEN that every job gets. Put permissions: {} at the top of each workflow so that token starts with nothing, then add back only what each job needs. Here's a deploy workflow with both changes in place:

Text
name:Deploy

on:
  push:
    branches: [main]

permissions: {}

jobs:
  deploy:
    runs-on:ubuntu-latest
    environment:production
    permissions:
      contents:read
    steps:
      -uses:actions/[email protected]
        with:
          persist-credentials:false
      -run:./scripts/deploy.sh
        env:
          DEPLOY_TOKEN:${{ secrets.DEPLOY_TOKEN }}

Once you list any permission, everything you didn't list is set to none, so this job's token can read the repo and nothing else. And persist-credentials: false stops checkout keeping the token around for later git commands. It's the same idea as limiting what your agent can reach on your own machine.

If you deploy with OIDC, add id-token: write to the job and scope your cloud role's trust to the environment's subject (like repo:octo-org/octo-repo:environment:production), not the whole repo. The wfx-loot payload minted OIDC tokens for AWS, GCP and Azure, and a role that trusts every branch would accept one from a throwaway branch. Repos created after 15 July 2026 add owner and repo IDs to the subject, so check GitHub's OIDC reference for yours.

pull_request_target changes on 2 December

From 2 December, GitHub blocks pull_request_target by default in public repos unless an Actions event policy allows it, so check any workflow that relies on it.

What these locks won't stop

Neither lock would have stopped wfx-loot outright, since it used real write access. The environment and permissions: {} limit what a stolen token can grab, and the lockfile covers a different attack, where someone moves a tag upstream.

A few more limits to keep in mind:

  • A lockfile doesn't make a dependency safe (GitHub says so too). According to the README, reusable workflows from other repos and container images aren't locked, and a change that moves a floating ref like v4 back to an older commit isn't detected, so glance at lockfile diffs or stick to full version tags.
  • The extension doesn't support GitHub Enterprise Server, and the verify job's gh-actions-lock pin needs bumping now and then.
  • Required reviewers slow deploys a little, and a branch rule only helps if main is protected too, since anyone who can push straight to main can use the environment.
  • Anyone who can edit a workflow can change its permissions, and an admin's stolen token can switch all of this off. So keep as few tokens around as you can, with short expiry dates.

Wrapping up

If I were doing this today, I'd start with the lockfile and that line in your agent's rules file, since it's two commands and one copied workflow. The environment and permissions: {} take a bit longer, but they're what limits the damage from a stolen token.