DEV Community

Cover image for One Stolen Token Should Not Ship Your App: A Two-Person Release Gate in GitHub Actions
cynthia wahome
cynthia wahome

Posted on

One Stolen Token Should Not Ship Your App: A Two-Person Release Gate in GitHub Actions

One Stolen Token Should Not Ship Your App

An attacker got hold of one admin's access token. Within minutes they had pushed a workflow file into every repository in the organisation, each one tailored to that repo, each one written to read the repo's secrets and send them out.

We contained it. Tokens revoked, secrets rotated, signatures enforced. I've written about that part separately.

This post is about the question that stayed with me afterwards, looking at our mobile repo:

If one token can push code, and pushing code can publish to the Play Store, then one token can ship an app to our users.

That had to stop being true. This is the release gate I built so that it takes two named humans, and so that a merge is no longer a release.

The problem, in two parts

One: a merge was a release. Merging to main built and published both of our Android apps (two apps, one codebase). A fix for one app forced a rebuild and store resubmission of the other, in the middle of its review, for nothing.

Two: one person was enough. Anyone with write access, or anything holding their token, could start the publish.

I wanted three properties:

  1. "Code is merged" and "this app is released" are different events.
  2. A release needs a request from one person and an approval from a different, named person.
  3. There is exactly one door to the store credentials, and it cannot be opened from outside.

The template is cooked and now in GitHub 🚀

check it out here

Monkey bath

The design: three workflows

1. Request

Run manually. It publishes nothing and builds nothing for the store. It only:

  • writes a small JSON file (which app, which store track, who asked) into a release-requests/ folder on a new branch, and
  • opens a pull request into a dedicated branch called release-gate.

The important detail: the pull request is opened by the automation, not by the person.

2. Approve

Runs whenever a review is submitted anywhere in the repo, then narrows down hard. It continues only if all of these hold:

  • the pull request targets release-gate;
  • the review is an approval, not a comment;
  • the pull request was authored by the automation;
  • the approver is on a fixed list of names;
  • the approver is not the person named in the request file.

Anything it cannot read is a "no". A missing file, a malformed file, a missing field: stop, comment on the pull request, publish nothing. Fail closed, not open.

3. Publish

The only workflow that touches signing keys and store credentials. It has exactly one trigger:

on:
  workflow_call:
Enter fullscreen mode Exit fullscreen mode

workflow_call means "another workflow may call me". There is no manual-run button, no push trigger, no pull-request trigger. The only caller is the Approve workflow, after its checks pass.

Why the request must be authored by the bot

This was the hole I found while designing it.

Without that rule, anyone with write access could open their own pull request into release-gate, with a hand-written request file naming someone else as the requester, and then approve it themselves. The self-approval check would pass, because it trusts the file.

The file is only trustworthy if our own script wrote it. Our script only ever runs when the automation opens the pull request. So "authored by the bot" is what makes "approver is not requester" mean anything.

The alarm that guards the door

The whole design rests on Publish having one trigger. One well-meaning edit ("let me add a manual trigger for a quick test") would add a second door that skips approval, and nothing would look broken.

So normal CI, on every pull request, reads that file's on: block and fails unless the only trigger is workflow_call:

triggers="$(awk '/^on:/{flag=1; next} /^[a-zA-Z]/{flag=0} flag && /^  [a-zA-Z_]+:/{print}' "$file" \
  | sed 's/^  //;s/:.*//')"

if [[ "$triggers" != "workflow_call" ]]; then
  echo "::error::$file must have ONLY 'workflow_call' as a trigger."
  exit 1
fi
Enter fullscreen mode Exit fullscreen mode

It looks only at keys indented exactly two spaces under on:, so the inputs declared inside workflow_call are not mistaken for triggers. It is a hard failure on purpose.

The approver list is hard-coded, on purpose

The list of who may approve lives inside the workflow file, not read from CODEOWNERS at run time. If it were read live, a quiet edit to one file would change who can release to the store. Keeping it in the workflow means changing the approvers is a visible diff in the most scrutinised file in the repo.

Four bugs I only found by running it

Reading the YAML told me it was correct. Running it told me otherwise.

1. The reusable workflow could not be found. I referenced Publish by a relative path. On a review event, GitHub resolves that path against the pull request's merge ref, and the frozen release-gate branch has no such file. Result: the run failed at start-up with no jobs. Fix: reference it by repository and branch explicitly.

2. Permissions are capped by the caller. Publish asked for write permissions; the calling job declared none, so it had read-only defaults, and GitHub rejected the whole workflow. A called workflow can never have more permission than the job that calls it.

3. It read the wrong file. I took "the first changed file" in the pull request as the request file. Because release-gate is a stale branch, every file changed since shows up in the diff, and the first one alphabetically was not my JSON. Fix: select by path prefix, and page through the full file list.

4. A failed publish burned a valid approval. The first real release died on runner disk space. My workflow closed the request anyway, so two people had to go through the whole cycle again for an infrastructure hiccup. Now a failed publish leaves the request open. Re-running replays the same approval against the same commit, so it can only publish what was already approved.

And one for humans: someone merged a request in good faith and nothing happened, because merging does nothing here. A workflow that never runs cannot explain itself. So there is now a tiny workflow whose only job is to comment: "merging does not publish; approve the request instead".

What this stops, and what it does not

Honesty section. A gate you overestimate is worse than no gate.

It stops:

  • an accidental release from a merge;
  • one person, or one stolen token, starting a store publish through the pipeline;
  • self-approval, including the forged-request variant.

It does not stop, on its own:

  • someone with write access editing the workflows themselves. The trigger guard and code review make that visible; branch protection with required code-owner review on the workflows folder is what makes it enforceable.
  • a workflow pushed to another branch reading repository-level secrets. If your signing keys are plain repository secrets, any workflow in the repo can ask for them.

What I'd add next

The plan for the template version of this:

  1. Move store and signing secrets into a GitHub Environment (a named group of secrets with its own rules), restricted to the protected branch. Then the secrets are not available to a workflow on an arbitrary branch.
  2. Require code-owner review for anything under .github/workflows/.
  3. Compare with GitHub's built-in environment reviewers. If your plan includes them for your repo type, use them, and keep the bot-authored request as the audit trail. Check GitHub's current documentation for what your plan allows on private repositories.

Checklist: a two-person release gate

  1. Separate "merge" from "release". A merge publishes nothing.
  2. One publish workflow, one trigger: workflow_call.
  3. A CI check that fails if that file gains another trigger.
  4. Release requests are pull requests opened by the automation, carrying a small metadata file.
  5. Approval checks: right branch, real approval, bot author, named approver, approver is not requester.
  6. Fail closed on anything unreadable.
  7. Pass user inputs to scripts as environment variables, never pasted into the script text.
  8. Leave a failed publish retryable without a new approval.
  9. Tell humans what merging does not do.
  10. Put the secrets behind an environment, and protect the workflows folder.

FAQ

What is a two-person rule in CI/CD?
A control where a sensitive action, such as publishing to an app store, needs one person to request it and a different authorised person to approve it. No single account, or single stolen credential, can complete it alone.

What does workflow_call do in GitHub Actions?
It makes a workflow reusable: other workflows can call it with uses:. If it is the only trigger, the workflow cannot be started by a push, a pull request or the manual-run button.

Can someone approve their own release with this design?
No. The approval step compares the approver with the requester recorded in a file that only the automation writes, and it ignores pull requests that a human opened directly.

Why not just protect the main branch?
Branch protection controls what gets merged. It does not separate "merged" from "released", and it does not decide who may publish which app to which store track.

Does this replace GitHub Environments with required reviewers?
No, they work together. Environments restrict who can reach the secrets; this design adds a request record, a self-approval check and per-app releases. Where environment reviewers are available on your plan, use both.

How do you release one app from a two-app codebase without rebuilding the other?
Make the app an input of the release request. The publish workflow receives that single value and builds only that app.

What happens if the publish fails after approval?
The request stays open. Re-running the failed run replays the same approval on the same commit, so nothing new can slip in, and nobody has to approve twice.


Backend engineer. I write about systems, architecture, and what I learn by poking at things. Portfolio

Top comments (7)

Collapse
 
cryptostrapon profile image
cryptostrapon •

Since the incident started with an admin token, two environment settings matter here: turn on "Prevent self-review" so the requester cannot approve their own release, and untick "Allow administrators to bypass configured protection rules", otherwise an admin token can still walk straight through the gate.

Collapse
 
wamzii profile image
cynthia wahome •

Great points, and I'd turn both on if I could 🌚

This pipeline lived in a private repo on GitHub's free tier, and those protections only apply to public repos, so I built the equivalent into the workflow.

Collapse
 
cryptostrapon profile image
cryptostrapon •

Thanks, that makes sense: on a private repo on the free tier the gate has to live in the workflow. Since the incident began with an admin token, I'd still check whether that token can commit to the request file directly, because then it could write a fake requester.

Thread Thread
 
wamzii profile image
cynthia wahome •

Oh that's a good catch, thank you! I think you're right: my "authored by the bot" check looks at who opened the PR, not who last touched the request file, so a write-access token could push a commit and change the requester. I haven't tested that yet; I'll try it from a second account in a scratch repo and report back.

Would you bind approval to the head SHA, or require every commit on the PR to be bot-authored?

Thread Thread
 
cryptostrapon profile image
cryptostrapon •

I'd do both, but bind to the head SHA first. Commit author fields are plain text that anyone with push access can set, so "bot-authored" only holds if you also require signed commits. If the approval records the exact head SHA and the publish job checks out that SHA and refuses when the branch has moved, any push after approval voids it, the same idea as GitHub's "dismiss stale approvals". Curious what the scratch-repo test shows.

Collapse
 
parasraju profile image
Paras •

Built plumber-linter to catch risky workflow permissions like these.

Collapse
 
wamzii profile image
cynthia wahome •

drop the link, would love to check it out 🥳