Hardening GitHub Actions Against Insider Threats
A practical guide to securing CI/CD pipelines against stolen credentials, covering GitHub Actions, trusted publishing, release approvals, and revocation.
- Karlo Zanki

Part one of this series covered attackers with no credential for your organization, who reach the pipeline through a pull request, a dependency or a third-party action. Those controls are largely deterministic. Pin an action to a commit SHA and a retagged action cannot run.
This post covers the other half, and it behaves differently. Here the attacker presents a valid credential. Either a maintainer's account, token or session has been stolen, or a person with legitimate access is acting against the project.
Several of the largest incidents of 2026 fall into this category, and they didn't need to exploit a vulnerability to gain access.
To GitHub, npm, and your cloud provider, the attacker's requests were indistinguishable from normal work. No input validation would have rejected them, because nothing about them was malformed.
That changes what the controls in this post can promise. They cannot prevent every maintainer account takeover — chapter 10's phishing-resistant factors do break one common entry route, but nothing here stops a credential that leaks some other way. What these ten chapters do is shrink the blast radius, raise the number of independently protected things an attacker must compromise, and shorten the time between the first malicious action and revocation.
Read this half as containment and detection rather than prevention, and treat the revocation drill in chapter 19 as essential rather than optional.
The threat model. A phished or malware-infected maintainer, a stolen personal access token, OAuth token, SSH key or session, or a departing insider. They push a workflow to a new branch, publish a release, add a deploy key, relax a ruleset, flip a repository public, or approve their own deployment — every one an ordinary operation performed by an authenticated principal. What works against that: phishing-resistant factors, no standing privilege, two independent humans on the release path, and fast revocation.
The organizing principle is a single question: how many separately protected things must be compromised for a malicious release to ship? One account should never be enough — and “separately protected” is the key phrase. If one administrator can reach the credentials for all three accounts, they are really just a single point of failure.
The LiteLLM incident in October 2026 shows why that qualifier matters. The attacker appeared as three accounts — one overrode the protection, one approved the release, one deleted the evidence — but the completed investigation describes a single cascading compromise rather than three breached boundaries. A publicly committed administrative key exposed an organization owner's GitHub CLI token, and that access was used to plant workflows and take the other engineers' tokens. The owner's token could have removed the approval restriction outright; splitting the work across accounts appears to have served detection avoidance rather than being necessary to defeat the gate. So the number to raise is the count of independently protected credentials, not of identities: two approval accounts whose tokens the same compromised administrator can read are one. That is why this post starts at the account and its credentials rather than at the pipeline.
Where your team is too small for genuine separation, lean harder on chapters 15 and 19: a staged release that a human must approve under a security key, and an alert that fires the moment a configuration event looks wrong.
Chapter 10: Make the Accounts Themselves Hard to Take Over
#The mistake
#Treating "we have 2FA" as settled because everyone uses an authenticator app.
App codes and SMS are phishable in real time. A proxy login page relays the code to the real site inside its validity window, and the attacker ends up with a live session. The second mistake is leaving 2FA to individual choice rather than enforcing it at organization level. The third is long-lived browser sessions that survive a password reset.
Observed in the wild
#npm author Qix, 8 September 2025, is the cleanest case. No code bug, no misconfiguration — an email from npmjs.help, a look-alike domain registered three days earlier, warning that the maintainer's two-factor setup was out of date, and a cloned login page that captured the credentials and the code typed into it. With the account the attacker published malicious versions of chalk, debug and more than a dozen related packages, together two to three billion downloads a week. npm removed them within about ninety minutes. From the registry's point of view, every one of those publishes was the maintainer. Counts vary between sources, from eighteen packages to around twenty-five.
What to do
#- Require phishing-resistant factors. WebAuthn security keys or passkeys are bound to the origin, so a proxy page cannot relay them. This is the control that breaks the entry flow above, and TOTP is not a substitute — a relayed code is exactly what the cloned page collected. Enroll at least two keys per maintainer so a lost key is not an outage. GitHub will not enforce it for you: its Only allow secure two-factor methods setting counts authenticator apps and the GitHub Mobile app as secure alongside passkeys and security keys. Where you have an identity provider, enforce phishing-resistant authentication there; on GitHub alone this stays a team policy you verify by inspection.
- Enforce at organization level, not per person. Without enforcement you discover the gaps during the incident.
- Shorten the session. Use SSO with conditional access where you have it, cap session lifetime, and revoke active sessions on any role change or suspected compromise. A stolen session cookie needs no second factor at all.
- Treat recovery codes as credentials. They are a 2FA bypass by design. Store them where you store secrets.
- Narrow the publish path. npm 2FA on publish helps, and trusted publishing (chapter 14) is better still. Keep in mind that trusted publishing proves which workflow in which repository published. It does not prove the published content is good. Neither closes the maintainer's own interactive route to the registry; chapter 14 covers what the package settings do and do not close. And as long as releases publish straight from CI, an unattended pipeline reaches every consumer at once: whoever can influence what it runs — through a workflow edit, a dependency or an action — reaches the registry with it. Use staged publishing where the ecosystem supports it (chapter 15); where it does not, consider an approval-gated alternative to publishing from CI.
Security keys do not defeat device-code phishing, where the attacker initiates an OAuth device flow, sends the victim the user code, and the victim enters it on the real site and completes their own genuine MFA. Nothing is relayed, so no authentication method blocks it, FIDO included. Blocking the device flow is effective but breaks legitimate CLI and developer tooling, so most teams carry this risk and compensate with chapter 11 and chapter 19.
Note also what 2FA does not reach at all: a personal access token, an SSH key or a deploy key authenticates with no second factor, from anywhere, for as long as it lives. That is the next chapter.
Configuration
## Org Settings -> Authentication security
# [x] Require two-factor authentication for everyone in your organization
# [x] Only allow secure two-factor methods
# NB: "secure" here includes authenticator apps and GitHub Mobile,
# not passkeys and security keys only. There is no security-key-only
# setting; enforce phishing-resistant auth at the IdP if you have one.
# [x] Require SAML SSO authentication (if you have an IdP)# Verify enrolment rather than assuming it. This lists members with no 2FA
# at all - it does not report which factor anyone enrolled, so it cannot
# prove security-key or passkey coverage.
gh api /orgs/acme/members --paginate --jq '.[].login' > all.txt
gh api '/orgs/acme/members?filter=2fa_disabled' --jq '.[].login' > no2fa.txt
# What an org owner can revoke (GHEC with SAML SSO), and what they cannot:
# People -> (user) : the member's active SAML session, through
# their linked identity. Not a sign-out of
# their GitHub account.
# Authentication security : Revoke SSO authorizations - removes a PAT or
# SSH key's access to THIS org. The credential
# itself survives and still works elsewhere.
# "Delete keys and tokens" does destroy it,
# but is Enterprise Managed Users only.
# That is organization containment. Account-wide revocation belongs to the
# account holder, or an EMU admin; chapter 11's token sweep is separate.Chapter 11: Remove Standing Privilege and Long-Lived Tokens
#The mistake
#Classic personal access tokens with repo and workflow scope and no expiry, created once for an automation job and never revisited.
They outlive the task, survive a password reset, are unaffected by 2FA, and sit in plaintext in ~/.npmrc, ~/.netrc, CI variables and shell history. The organizational version is granting broad write or admin roles permanently because narrowing them is inconvenient.
A subtler one: assuming offboarding closes everything. Removing a member revokes their organization access, but a deploy key belongs to the repository rather than the person, so it survives their departure untouched.
Observed in the wild
#This is what the malware is built to collect: the tj-actions payload scanned runner process memory specifically for personal access tokens, npm tokens and private keys.
GhostAction ran on nothing else. Reporting indicates initial access came from personal access tokens lifted from infostealer logs, and from a phishing site harvesting OAuth tokens carrying repo, workflow and read:org. In none of these did the attacker need the victim's password.
What to do
#- Set an organization PAT policy, both halves. Require approval for fine-grained tokens that access the organization, and separately restrict classic PATs. This catches people out: classic tokens are not subject to the fine-grained approval flow, so by default any classic PAT reaches organization resources with no approval at all. Two settings, two tabs.
- Cap token lifetimes. The organization default maximum for fine-grained tokens is 366 days, which is weak for this purpose — a year is long enough for a stolen token to outlive the incident that leaked it, so set it to the shortest period your workflows tolerate. Classic PATs carry no maximum-lifetime requirement by default, though an organization can enforce one; that they default to none is a second reason to restrict them outright.
- Restrict which third-party OAuth Apps can reach the organization. App access restrictions are on by default for new organizations and let owners approve each app individually. This is the control that counters a phishing site harvesting an OAuth token — a flow a security key does not stop, because the victim completes a genuine authorization. Enabling restrictions on an existing organization revokes every previously authorized app and SSH key, so plan the rollout rather than clicking it on a Friday. One exception matters here: GitHub's own privileged OAuth apps, GitHub CLI among them, can still reach organization data despite these restrictions, and the authorization of such an app lands in the user's security log rather than the organization or enterprise audit log. That is a gap in seeing the app authorized, not a cloak over every repository operation later performed with its token — but it is the credential class the LiteLLM chain ran on.
- Replace personal tokens in automation with a GitHub App, scoped to the repositories and permissions it needs. Installation tokens are short-lived and the App does not disappear when a person leaves.
- Audit who can write workflows. A token-authenticated push to
.github/workflows/needsworkflowscope orWorkflows: read and write, and most automation has no reason to hold either. Withholding it narrows that credential rather than closing the path, though: SSH keys and deploy keys are a separate write route that these scopes do not govern, so inventory them alongside the tokens. - Inventory deploy keys and SSH keys separately from members, on a schedule. They are the credentials offboarding misses.
If your organization is owned by an enterprise, the enterprise policy wins and you cannot loosen it locally. Worth knowing before planning a rollout the enterprise has already decided.
Configuration
## Org Settings -> Personal access tokens -> Fine-grained tokens
# Access: [x] Require administrator approval
# Maximum lifetime: 30 days (default is 366 - lower it)
#
# Org Settings -> Personal access tokens -> Tokens (classic)
# [x] Restrict access by personal access tokens (classic)
# SEPARATE SETTING - the approval flow above does not cover classic PATs# Standing inventory: the keys offboarding does not remove. Both halves
# need their page limits raised, or the inventory quietly stops short of
# whatever you are looking for.
for r in $(gh repo list acme --limit 5000 --json name --jq '.[].name'); do
gh api --paginate "/repos/acme/$r/keys" \
--jq ".[] | {repo: \"$r\", title, read_only, created_at}"
done
# Apps and their permissions, including who can write workflows
gh api --paginate /orgs/acme/installations --jq '.installations[]
| {app: .app_slug, workflows: .permissions.workflows,
contents: .permissions.contents}'Chapter 12: Lock Down Who Can Change Workflow Files
#The mistake
#Protecting only the default branch.
Branch protection and CODEOWNERS fire on pull requests into main. A direct push to refs/heads/anything-else is unreviewed, and an on: push trigger written into the attacker's own YAML runs it on that branch at once. The second form of this mistake is treating CODEOWNERS over .github/workflows/ as the control. It requires review on a pull request; it does not restrict who may push.
Observed in the wild
#Shai-Hulud, 2025–2026. Using stolen tokens the worm pushed a workflow file into victim repositories, triggered it on push, enumerated every repository secret with ${{ toJSON(secrets) }}, uploaded them as an artifact, then deleted the branch and the workflow to cover its tracks. No pull request was ever opened, so no review control saw any of it.
GhostAction, 2025–2026. A campaign built on nothing else. The attacker authenticates with a stolen maintainer credential, reads the repository's existing workflows to learn which secret names it references, then pushes a new workflow — often under a commit message posing as a security improvement, such as "Add Github Actions Security workflow" — that hardcodes those names and posts the values to a fixed address. GitGuardian put the first wave at 817 repositories and 3,325 stolen secrets, and a second wave through September 2026 at 772 repositories. Figures vary between sources. No vulnerability was exploited at any point.
LiteLLM, 21 October 2026. Branch protection rejected an unauthorized modification to the private release workflow because it had not passed the required pull request and status check process. Five seconds later a credential associated with a privileged developer account overrode those protections and applied the modified workflow.
The protection was configured correctly and fired correctly. It was defeated by an account that held bypass rights, and five seconds indicates a scripted, pre-planned override rather than exploration.
What to do
#No single setting covers this. Layer five, in this order.
- A push ruleset restricting
.github/workflows/**. This blocks the push itself, at the server, on every branch including ones that do not exist yet. Bypass restricted to a named team. Two things to plan for. Push rules need at least a GitHub Team plan, are available for private and internal repositories only, and extend across the repository's fork network — they are not available on public repositories. And a restricted path blocks ordinary workflow edits as well as hostile ones, so pick the bypass setting deliberately: an empty list freezes the path for everyone, while a named team keeps authorized changes possible and becomes the control you are then relying on. - Keep the bypass list empty, or as close to empty as the organization allows. Branch protection does not apply to repository administrators by default, which is the mechanism behind the LiteLLM override. This is the layer that would have mattered there, and it has to be set before the incident, not during it.An empty bypass list only constrains who walks through the rule, not who can edit or disable it. An organization owner can change the organization ruleset itself; for that tier there is no configuration answer here, only chapter 19's alerting on ruleset changes.
- Branch rulesets, scoped to what each rule is for. Require a pull request and Code Owner review on the default and release branches, where merges actually happen — applying them to every branch taxes ordinary work and does nothing against a planted workflow, which never opens a pull request. Add
Restrict deletionson all branches: the worm deleted its branch to hide, and this blocks that. Prefer organization-managed rulesets, which combine restrictions and stop repository administrators weakening them; multiple rulesets apply to the same branch at once, so these can be two. - Token scope hygiene. A token-authenticated push to
.github/workflows/requiresworkflowscope on a classic PAT, or Workflows: read and write for a GitHub App. Withholding it narrows that credential rather than closing the path — SSH and deploy keys are the other route, which is why chapter 11's inventory of them matters here too. - Block Actions from creating and approving pull requests. A workflow that can approve its own pull request removes the human from the merge step, which is how a planted change reaches the branch a release later runs from. GitHub's guidance is that allowing workflows “or any other automation” to create or approve pull requests is a risk wherever the result gets merged without oversight. The setting exists at enterprise, organization and repository level; turn it off at the highest level you control.
Because the push ruleset is unavailable on public repositories, detection fills the gap there. Alert on any push touching .github/workflows/** that did not arrive through a merged pull request, on branch deletions shortly after a workflow run, and on the string toJSON(secrets) anywhere in the repository — no legitimate workflow serializes the entire secret set. Chapter 19 covers the alerting.
Configuration
## 1) Private/internal: Settings -> Rules -> New ruleset -> New push ruleset
# Enforcement: Active
# Bypass list: @acme/platform-security (empty = applies to everyone)
# Push rules -> Restrict file paths:
# .github/workflows/**
# .github/actions/**
# 2) New branch ruleset # review, where merges land
# Target branches: Default branch, release/*
# Rules: Require a pull request before merging
# Require review from Code Owners
# 3) New branch ruleset # deletion, everywhere
# Target branches: All branches (fnmatch **)
# Rules: Restrict deletions # blocks the cover-tracks step# Audit which credentials can write workflow files at all
gh api --paginate /orgs/acme/installations --jq '.installations[]
| select(.permissions.workflows == "write")
| {app: .app_slug, workflows: .permissions.workflows}'Chapter 13: Turn On Workflow Execution Protections
#The mistake
#Treating "can open a pull request" as equivalent to "can run our CI."
By default any actor whose event matches a trigger starts a run. Teams also leave workflow_dispatch broadly available on deployment workflows, so anyone with write access can deploy regardless of who reviewed the code.
Observed in the wild
#The PyTorch runner compromise turned on exactly this gap. Approval was gated on previous-contributor status, so the researchers landed a one-character typo fix, became previous contributors, and then triggered workflows on self-hosted runners. Cryptomining abuse of workflow_dispatch and fork pull request triggers on public repositories is the volume case rather than the headline one.
What to do
#Configure execution protections at enterprise, organization or repository level, under Settings then Actions then Policies. Two rule types combine:
- Actor rules control who may trigger: named users, repository roles, GitHub Apps, Copilot, Dependabot. This separates who contributes code from who runs CI.
- Event rules control which events may trigger:
push,pull_request,pull_request_target,workflow_dispatch.
The September 2026 general availability added three things worth using. Workflow file targeting lets deploy.yml be restricted to a release team while CI workflows stay open to all contributors. Insights show how rules would evaluate before you enforce them. A REST API manages rules as code.
Where you have it, roll out in evaluate mode first, read the insights, then enforce — the same sequencing GitHub is using for its own pull_request_target default. Evaluate is a GitHub Enterprise Cloud option, so on other plans the choice is between not having the rule and enforcing it directly; stage that by targeting a few repositories before widening the policy.
One limit to plan around: execution-protection insights are surfaced for enterprise accounts. Organizations and repositories can configure and enforce rules, but the cross-repository reporting view is an enterprise feature.
A date. GitHub already adds a default event policy blocking pull_request_target on public repositories that have no applicable policy of their own, and enforcement of it begins 2 December 2026. If a public repository depends on that trigger, add an explicit event policy before the date. Actions policies are available on all public repositories, so plan is no obstacle — but they exist only at enterprise, organization and repository level, so a personal account has to set one on each repository.
Configuration
#Repository: acme/payments-api
Rule A workflow: .github/workflows/deploy.yml
events: workflow_dispatch
actors: team:release-engineering
mode: enforce
Rule B workflow: .github/workflows/ci.yml
events: pull_request, push
actors: any
mode: enforce
Rule C workflow: .github/workflows/renovate.yml
events: pull_request_target # explicit allow, before 02-Dec-2026
actors: app:renovate
mode: enforceChapter 14: Replace Publish Tokens With OIDC Trusted Publishing
#The mistake
#Storing NPM_TOKEN, PYPI_API_TOKEN or static cloud keys as repository secrets.
A publish token stored as a secret is a bearer credential that remains usable until it expires or is revoked, subject to its restrictions, for anyone who reads it once. The secondary mistake is exposing it to jobs with no business publishing: a test job with NPM_TOKEN in scope means any dependency's postinstall script can read it.
Observed in the wild
#Nx s1ngularity. The stolen artifact was a static npm token, and stealing it once was enough to publish. That is precisely the primitive the Shai-Hulud worm consumed at scale, harvesting credentials from developer machines and CI and publishing infected versions of every package its victims maintained.
What to do
#Configure trusted publishing on the registry, bind it to the specific repository, workflow file and environment, and delete the stored token. npm trusted publishing with OIDC reached general availability on 31 July 2025; PyPI has offered the equivalent since 2023. The workflow requests an OIDC token with id-token: write and never handles a long-lived secret.
npm now supports multiple trusted publishing configurations per package, from September 2026, for projects releasing from more than one workflow, and opt-in dist-tag permissions so a publisher can be restricted from moving latest.
Trusted publishing proves which workflow in which repository published. It does not prove the published content is good. And it removes the need for a stealable credential rather than removing the credentials themselves: configuring a publisher revokes nothing, so every existing token stays valid until you sweep them. Be exact about what the package-level Require two-factor authentication and disallow tokens setting then does. It closes the token route — granular access tokens cannot publish, whatever their bypass-2FA setting — and it leaves both other routes open. Trusted publishing is untouched, because it uses OIDC rather than traditional token authentication. Manual publishing remains as an additional route, requiring interactive 2FA. Chapters 12, 13, 15 and 16 are what stop a compromised workflow from abusing the identity it leaves behind.
Scope the permission itself, too. id-token: write applies to the whole job, so a build step sharing that job can request the same identity, and --ignore-scripts does not stop code that runs during the build. Grant it on a narrow publish job that runs no project code, and keep the install and build in a separate job. That protects the credential boundary; it does not establish that the artifact passing between the two is safe, which is what the build's own review path is for.
For cloud deploys the same pattern replaces static AWS, Azure and GCP keys. Since 15 July 2026 new repositories get immutable identifiers in the default OIDC subject claim — repo:octo-org@123456/octo-repo@456789:…, not available on GitHub Enterprise Server — so a recycled namespace cannot inherit a trust policy written for the original repository. The names stay in the subject alongside the IDs, so a policy matching the full string still needs updating after a rename. Repositories created before that date keep the previous format unless you opt in, and renames and transfers after it move to the new one, so check which format each trust policy is written against.
Configuration
## Vulnerable: a long-lived, replayable bearer credential
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}# Hardened: build and publish are separate jobs, and only the publish
# job can mint an OIDC token.
permissions: {}
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read # no id-token here
steps:
- uses: actions/checkout@<sha>
with: { persist-credentials: false }
- uses: actions/setup-node@<sha>
with: { node-version: 24 }
- run: npm ci --ignore-scripts
- run: npm run build # third-party code runs HERE, not in publish
- run: npm pack # the exact tarball that will be published
- uses: actions/upload-artifact@<sha>
with: { name: package-tarball, path: "*.tgz" }
publish:
needs: build
runs-on: ubuntu-latest
environment: release # scopes the trusted publisher binding
permissions:
id-token: write # minted here, and nowhere else
steps:
# No checkout at all: the privileged job never holds project source,
# so it needs no contents: read either.
- uses: actions/download-artifact@<sha>
with: { name: package-tarball, path: out }
- uses: actions/setup-node@<sha>
with:
node-version: 24
registry-url: <https://registry.npmjs.org>
# Publishing the prepared tarball, not a working directory: npm runs
# prepublishOnly only for directory publishes, so no project code runs
# here at all. --ignore-scripts keeps that true if this ever changes.
- run: npm publish ./out/*.tgz --ignore-scriptsChapter 15: Gate Releases Behind npm Staged Publishing
#The mistake
#A tag push that runs straight through to a live, installable version with no human in the loop.
Teams reason that since OIDC removed the stealable token, the path is safe. But an injected or modified workflow still runs as the trusted publisher, and the resulting package is indistinguishable from a real release.
Observed in the wild
#Nx had roughly four hours of malicious versions live before anyone noticed. The team's own postmortem lists trusted publishing plus manual release approval as the remediation.
TanStack shipped 84 malicious versions through an automated release path.
What to do
#Staged publishing went generally available on 22 May 2026 and needs npm CLI 11.15.0 or newer. The workflow runs npm stage publish, which uploads the tarball to a stage queue instead of the registry. A maintainer with publish access then approves it, which requires a 2FA challenge.
OIDC tokens issued through trusted publishing cannot approve from the stage queue. That is what preserves the human gate even when the CI identity itself is abused. Staged versions generate the same provenance as direct publishes, and can be configured to be approvable only once malware scanning completes.
Then close the bypass. Set the trusted publisher configuration to stage-only, which makes the registry reject a plain npm publish from that workflow. Without it, an attacker who modifies the workflow simply drops the stage and publishes directly. Note the scope of that: stage-only constrains that CI publisher. A maintainer publishing interactively from their own account is a separate route, left open by design and gated by the 2FA prompt from chapter 14's package settings rather than by the stage queue.
The equivalent elsewhere. PyPI has no staging queue, so use a GitHub Environment with required reviewers (chapter 16) in front of the publish job. For container registries, push to a staging tag and promote after verification. The LiteLLM release was a PyPI one, so an environment approval stood in for staging — which is why chapter 16, not this chapter, enforces that gate.
Configuration
## Vulnerable: live to every consumer, no human gate
- run: npm publish# Hardened: lands in the stage queue, waits for a human
- run: npm stage publish# npmjs.com -> package -> Trusted publisher -> "Stage only"
# A plain `npm publish` from this workflow is now rejected by the registry.
#
# Maintainer, from a 2FA-enabled account:
# npm stage list
# approve in the npmjs.com UI or via CLI
# (an OIDC token cannot give this approval)Chapter 16: Require a Second Human at the Deploy Boundary
#The mistake
#Keeping production credentials as repository-level secrets, so every workflow in the repository — including one added on a branch nobody watches — can reference them.
Then, having moved to environments, adding required reviewers and leaving Prevent self-review off. A maintainer who triggers a deployment and approves it themselves has added a dialog box, not a control, and that is precisely the configuration a compromised account walks through.
Observed in the wild
#Repository-scoped secrets are the common amplifier across the pwn-request incidents. In Nx the npm token was reachable from the compromised workflow because nothing scoped it to a gated environment.
LiteLLM, 21 October 2026 shows the limit of this control rather than its absence. The project had an approval gate, and at 11:11:18 UTC a credential associated with a second developer account satisfied the production approval. The completed investigation describes that credential as having been taken using access the attacker already held, so the gate was never independent of the account it was meant to check. An approval gate is worth the independence of the credentials behind it.
Prevent self-review stops one identity approving its own run. It does nothing against two.
What to do
#- One environment per deployment target, with secrets attached there rather than at repository level. A workflow job cannot access environment secrets until a reviewer grants approval.
- Required reviewers plus Prevent self-review, shipped October 2023. Without that toggle the rule is self-service.
- Disable Allow administrators to bypass configured protection rules. By default, administrators can bypass the protection rules and force a deployment to the environment, which makes the reviewer requirement above advisory for anyone holding admin. Configure the environment to disallow bypassing for all deployments to it. Two caveats: on Free, Pro and Team the bypass option is only available for public repositories, and disabling it does not close the boundary — an administrator who can edit the environment's configuration can still remove the requirement, which is why chapter 19 alerts on environment changes.
- Deployment branch and tag restrictions, so only the default branch or release tags can deploy. This is what makes a tampered workflow on a throwaway branch useless. A pattern such as
v*establishes that the deployment ran from a reference matching that name, not that the commit behind it passed review: anyone who can create or move a release tag can point one at an arbitrary commit, so protect tag creation and updates with a ruleset alongside the environment restriction. - A wait timer on the most sensitive targets, which buys chapter 19's detection time to fire before the change lands.
- Combine with execution protections (chapter 13) so only the release team can dispatch the workflow at all. Triggering and approving are separate controls and a compromised account should fail both.
Three limits to plan around. On Free, Pro and Team plans, required reviewers and wait timers are available only on public repositories; deployment branch policies do work on private repositories with Pro or Team, so set those up even if the approval gate needs Enterprise. Only one of up to six listed reviewers needs to approve — there is no native two-approver rule. And Prevent self-review keys on the initiator, which for a scheduled or bot-triggered release may be whoever last edited the cron schedule rather than whoever is accountable for the release: choose that identity deliberately instead of assuming the gate holds.
Configuration
## Settings -> Environments -> production
# Required reviewers : @acme/release-engineering
# [x] Prevent self-review <- without this it is self-service
# [ ] Allow administrators to bypass configured protection rules
# <- UNCHECKED; otherwise admins skip
# every requirement above
# Wait timer : 10 minutes
# Deployment branches and tags: Selected -> main, v*jobs:
deploy:
runs-on: ubuntu-latest
environment:
name: production
url: <https://acme.example>
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@<sha>
with: { persist-credentials: false }
- uses: aws-actions/configure-aws-credentials@<sha>
with:
role-to-assume: arn:aws:iam::111122223333:role/deploy
aws-region: eu-west-1 # OIDC; no static keys anywhereChapter 17: Block Secrets at the Push and Gate the Bypass
#The mistakes
#There are two mistakes, and the second is the expensive one.
First, assuming push protection is already on. Three different things share the name. Secret scanning runs automatically on public repositories — all of them, not only new ones. Push protection for repositories requires GitHub Secret Protection and is off until a repository administrator, organization owner, security manager or enterprise owner switches it on. Push protection for users is on by default but covers only your own pushes to public repositories, and raises no bypass alert unless repository-level protection is on as well. So a team can be scanned, personally protected, and still have no enforced block on the private repository where the release credentials live.
Second, enabling push protection and leaving bypass unrestricted. Any developer can clear a block themselves by picking a reason such as "it's a test credential," so the control decays into a dialog people dismiss. A bypass nobody reviews is not a control.
A third, quieter mistake: treating a blocked push as the end of the incident. A rejected push does not establish remote exposure. An accepted secret stays in the remote history, and in clones and forks containing the affected history, after the file is deleted. Rotate exposed credentials; removing the file is insufficient.
Observed in the wild
#Codecov, 2021 shows both the shape and the limit of this chapter's main control. The attacker extracted a Google Cloud Storage HMAC key from a layer of Codecov's own public Docker image, and that single credential was enough to modify the Bash Uploader served to 23,000 customers. The key was baked into a published image, not committed in a file. Git push protection is a pre-receive check and does not read container layers, so it would not have seen this one — hence the bullet below on scanning what you publish.
GhostAction, 2026. The later variants made the history itself the target. Instead of reading only the repository's Actions secrets, the planted workflow sweeps the checked-out working tree and the full git history for cloud and AI provider keys, matching prefixes such as sk-ant-, sk-proj- and sk-. A key committed two years ago and deleted the following day is still in the pack files, still in clones and forks containing the affected history, and still perfectly valid if nobody rotated it. Deleting the line removed the secret from HEAD; it never removed it from the repository.
What to do
#- Turn protections on everywhere, not just where it defaults on. Organization Settings, Code security, global settings: enable secret protection and push protection for all repositories, plus the "enable for new repositories" toggle. Push protection on public repositories is free for everyone; private repositories need GitHub Secret Protection.
- Enable delegated bypass. This is the setting that turns push protection from a speed bump into an authorization control. Name the teams or roles allowed to bypass; everyone else files a request that a reviewer approves or denies, and the push stays blocked until they do. It covers browser file uploads as well as git pushes.
- Choose which patterns block. Since June 2025 you can configure which secret scanning patterns participate in push protection. Select the generic patterns alongside the partner ones, and add custom patterns for your own internal token formats — a service token in a shape nobody has written a pattern for is invisible until you define it.
- Sweep the history you already have. Push protection is a pre-receive check: it only ever sees new pushes, so on its own it does nothing about what is already committed. Secret scanning alerts are the half that scans the existing history across all branches, and that is the half an attacker reading pack files is working against. Enable both, and work the historical alerts as a backlog.
- Scan what you publish, not just what you push. Push protection and secret scanning read Git history; they do not read container layers, release assets or built packages. A credential can reach a published image through a build argument, a copied file or an intermediate layer without ever appearing in a commit — which is exactly the Codecov shape. Run a secret scan over image layers and release artifacts in the release pipeline and fail the build on a hit, so the last thing checked is the thing you actually ship.
- Rotate anything that got through. A bypassed or pre-existing secret is compromised regardless of whether the repository is private. Treat rotation as the default response and removal from history as cleanup, never the reverse —
filter-repocannot reach the forks.
One limit, and one note for the automation below. The limit is coverage rather than shape. Partner, generic and custom patterns are separate capabilities, each enabled separately — generic patterns, which cover private keys and database connection strings, also have to be selected in the organization's push-protection pattern configuration — and AI detection of unstructured secrets is a billed public preview that does not apply to REST API or MCP pushes. What gets through is whatever no enabled pattern matches: a format nobody has written a pattern for, or a credential split, encoded or otherwise transformed so that it no longer looks like one.
On the API: it takes fine-grained PATs and GitHub App installation tokens as well as a classic PAT with security_events — read on Secret scanning alerts plus read on the bypass-request permission to list them, and write on that permission to approve or deny. Mind the default window. The listing endpoints filter to the past 24 hours unless you pass time_period, so an open request from last week is absent however many pages you fetch.
Configuration
## Org Settings -> Code security -> Global settings
# Secret scanning : Enable for all repositories [x] new repos
# Push protection : Enable for all repositories [x] new repos
# Repo or org Settings -> Code security -> Push protection
# Delegated bypass : Enabled
# Bypass list : @acme/security-oncall # reviewers only
# Settings -> Code security -> Secret scanning -> Custom patterns
# Pattern : acme_(live|test)_[A-Za-z0-9]{32}
# [x] Use this pattern for push protection# Pull pending bypass requests into your own triage. Filter server-side:
# request_status defaults to "all" and time_period to "day", so the
# unfiltered call returns yesterday's noise and hides last week's backlog.
gh api --paginate \
'/repos/acme/payments-api/bypass-requests/secret-scanning?request_status=open&time_period=month' \
--jq '.[] | {requester: .requester.actor_name, created: .created_at}'
# Org-wide view
gh api --paginate \
'/orgs/acme/bypass-requests/secret-scanning?request_status=open&time_period=month'Chapter 18: Record How Releases Were Built, and Verify It
#The mistake
#Generating attestations and never verifying them.
An unverified attestation is documentation, not a control. The second mistake is leaving release assets mutable, so a tag or a binary can be swapped after publication and after review.
Observed in the wild
#Codecov ran for two months because nobody compared the served file against the published hash. SolarWinds, in 2020, remains the canonical build-system compromise: the source was clean and the build output was not. Provenance would at least have given consumers something to check, which is more than they had — but an attestation signed inside a compromised build asserts only what that build chose to record, so it is the trustworthiness of the builder that decides whether the record means anything.
LiteLLM, 21 October 2026. The modified release workflow started an official staging run using the attacker-controlled source repository Berri-AI/litellm, one hyphen away from the legitimate BerriAI/litellm. The official 1.107.0 source tag did not contain the malicious files.
Source and artifact diverged, which is the gap attestation exists to expose. What a verifier actually sees is narrower than that, though: the certificate records the repository and workflow that signed, and here those were the official ones, while the predicate — where a build's source inputs are recorded — is written by the workflow itself. Checking out a different repository does not of itself make the attestation describe that checkout; only a builder that constrains and records its own inputs does that. Checking that an attestation carries the expected repository and workflow identity does not, on its own, establish that the workflow built approved source. Provenance made the divergence recordable, not automatically visible.
Note also what this says about reviewers. Nobody reads BerriAI versus Berri-AI any more reliably than they read a 40-character SHA.
What to do
#Generate SLSA-style build provenance with actions/attest-build-provenance, generally available since June 2024. It is available to public repositories without additional cost, but it is not automatic: a workflow produces an attestation only once you add the step and grant it attestations: write. (npm trusted publishing generates package provenance on publish — that is a separate mechanism, not this one.) Then verify it in the consuming pipeline with gh attestation verify, asserting the expected repository and workflow. Know what that assertion covers: GitHub's own CLI documentation warns that only the certificate and the verified timestamps hold values that cannot be manipulated by the workflow that produced the attestation, while the predicate — where the build's source inputs are recorded — can be falsified by anyone who reaches that workflow's execution context. Its recommendation is a trusted builder: have the build and the attestation signing happen in a reusable workflow whose execution the caller cannot influence. Verification is worth exactly as much as the builder behind it.
Turn on immutable releases. A published release's assets and its associated Git tag are locked to a commit: the tag cannot be moved, and cannot be deleted while the release exists Deleting the release does not unlock the tag — it only makes the tag deletable, and once deleted the name can never be reused, in that repository or a recreated one. Only the assets and tag are locked; title and notes stay editable. If you publish actions, this protects consumers who pin to that release tag. It does not freeze a separate moving alias such as v1: GitHub's own guidance is to keep major and minor aliases outside releases precisely so they can be force-pushed forward, so those stay as rewritable as part one described.
Publish with registry-native provenance where your ecosystem offers it, and use the attestation step above for everything else — it attests any artifact by path, whatever registry it ends up in. Know the edges before treating a provenance badge as a verdict. Taking npm's documentation as the clearest statement of them: established provenance does not guarantee the package has no malicious code — it is a verifiable link to the source and build instructions, for a human to audit; generating it needs a cloud-hosted runner and a public source repository, which rules out self-hosted builds and private-source projects; the build metadata is signed into a permanent public transparency log; and verification is not automatic, since installing checks nothing and a separate audit command is what validates attestations.
Verification is what turns provenance from a label into a check — against a builder you trust to constrain and record what it builds.
Configuration
## Producing - the attestation step and its permissions, in context
jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
attestations: write # required; without it there is no attestation
steps:
# ...build steps produce dist/*.tgz...
- uses: actions/attest-build-provenance@<sha>
with:
subject-path: dist/*.tgz# Consuming - the half that is usually skipped.
# --repo asserts which repository's workflow signed the attestation. It
# does not inspect what that workflow actually checked out and built.
gh attestation verify ./app.tgz \
--repo acme/payments-api \
--signer-workflow acme/payments-api/.github/workflows/release.ymlChapter 19: Detect, Revoke, and Rehearse
#The mistake
#Monitoring code and ignoring identity.
Teams alert on test failures and dependency CVEs while the events that actually signal a compromised maintainer — a new token, a new deploy key, a repository turning public, a ruleset quietly relaxed — go to an audit log nobody streams anywhere. The companion mistake is having no revocation runbook, so the first rehearsal happens live, at speed, with the wrong people awake.
Observed in the wild
#Nx's second wave announced itself as a configuration event, not a code event: private repositories flipping to public, roughly 6,700 of them. Anyone alerting on visibility changes would have seen it immediately.
Codecov ran undetected from January to April 2021 and was found by a customer comparing a hash, not by Codecov.
LiteLLM supplies a direct example: at 11:53:49–11:54:01 UTC, credentials associated with a third developer account were used to delete the production and staging workflow records, limiting the logs available for investigation.
What to do
#- Stream the organization audit log off GitHub and alert on identity and configuration events, not just code: a new personal access token or SSH key, a new deploy key, a new App installation, an organization role change, a repository visibility change, a ruleset or branch-protection edit, an environment reviewer change, and every secret-scanning bypass approval.
- Page on a protection being overridden, not merely changed. This is the highest-value signal here and the one teams most often lack. A ruleset edit is a configuration event you are probably watching; an override of a rule that fired is a separate class, because the rule worked and someone with bypass rights walked through it anyway. Branch protection does not apply to repository administrators by default, so this needs no exploit. Watch
protected_branch.policy_overrideand its siblings. Five seconds between rejection and override, as in chapter 12, is not a gap any response window closes: the alert timestamps the start of the incident, and the prevention is an empty bypass list set beforehand. - Alert on the destruction of your own evidence. Workflow run records are deletable by anyone with write access, and deleting them is a deliberate step rather than a side effect. Watch
workflows.delete_workflow_run, and weigh it in proportion to how little legitimate reason there is to fire it. This is also the argument for getting the records off the platform in the first place: run records can be destroyed from inside GitHub, and a copy held elsewhere is outside the reach of the account that deleted them. That is a property of the destination rather than of the export — it holds only if the destination has its own access controls and retention policy, and an attacker who also reaches your log store is back to deleting evidence. - Alert on workflow-file pushes outside a merged pull request (chapter 12), on branch deletions shortly after a run, and on
toJSON(secrets)appearing anywhere in the repository. - Keep the configuration from drifting. Run
zizmorandactionlinton every pull request touching.github/, track OpenSSF Scorecard, require review on workflow files via CODEOWNERS, and set an organization Actions policy allowlist. A control removed quietly is an insider action too. - Write the revocation runbook and rehearse it. For one named account: revoke sessions, revoke tokens, revoke OAuth app authorizations, remove SSH and deploy keys, rotate every secret that account could reach, invalidate in-flight releases, and check the npm stage queue for anything awaiting approval. Time it. The first attempt always takes longer than anyone predicts.
- Know your blast radius in advance. For each maintainer, which packages, environments and cloud roles does that identity reach? If you cannot answer in a minute, you cannot scope an incident in an hour.
Two details worth carrying into the runbook. Revoking an OAuth app authorization is a separate action from revoking personal access tokens, and a stolen OAuth token produces no creation event, so an alert keyed on "new PAT created" will never fire for it. And if trusted publishing is your release path, the publisher binding is itself a credential to revoke — LiteLLM's response included removing the trusted links to its GitHub organization.
Audit-log streaming to a SIEM is a GitHub Enterprise Cloud capability — and so is the audit-log API, so “poll it on a schedule instead” is not the fallback it sounds like. On Free, Pro and Team the REST and GraphQL audit-log endpoints are not available. What you have is the web interface and the JSON/CSV export, both manual, plus webhooks, which GitHub offers as an alternative for logging that certain events occurred rather than as an equivalent feed: they cover the events you subscribe to, not the audit log's full set. Whatever you use, get the history off the platform deliberately. Retention is not one number — web events are held 180 days, Git events only seven — and which events each access method carries differs, so check GitHub's coverage table against the events you want to alert on. The web view also shows three months unless you specify a date range, and an attacker who reaches organization admin sees what you see.
Configuration
## Audit-log events worth a page, not a dashboard tile
# protected_branch.policy_override <- a rule fired and lost
# protected_branch.required_status_override
# protected_branch.review_policy_override
# workflows.delete_workflow_run <- evidence destruction
# repo.access (private -> public)
# org.update_member (role escalation)
# personal_access_token.* (created / access granted)
# repo.create_deploy_key, public_key.create
# integration_installation.create
# repository_ruleset.*, environment.*# Example: repositories that changed visibility
gh api '/orgs/acme/audit-log?phrase=action:repo.access' \
--jq '.[] | {actor, repo, visibility, created_at}'# Stop the configuration drifting back
# .github/workflows/audit.yml
on:
pull_request:
paths: ['.github/**']
jobs:
audit:
runs-on: ubuntu-latest
permissions: { contents: read, security-events: write }
steps:
- uses: actions/checkout@<sha>
with: { persist-credentials: false }
- uses: zizmorcore/zizmor-action@<sha>What This Half Achieves, and Where It Stops
#Chapters 10 and 11 are configuration changes measured in hours, and they do the most work, because every control after them assumes the credential presenting itself belongs to the person it names. Chapters 12 through 16 harden the write and release path. Chapters 17 through 19 are containment: keep credentials out of the repository, make artifacts tamper-evident, and shorten the time to revocation.
LiteLLM had separation of duty on paper. What the completed investigation shows is that the three accounts behind it were not three compromises: a publicly committed administrative key handed the attacker an organization owner's GitHub CLI token, and everything after it followed from that one credential.
So the measure to track is not whether you have an approval gate, nor how many accounts stand behind it. It is how many independently protected credentials an attacker would need, and whether holding any one of them reaches the rest — through a key in a repository, a token on a shared machine, or admin rights that read both. An approval gate backed by two accounts that one administrator can impersonate has one lock on it.
That vector lands earlier in this post than the approval machinery does. The investigation records that the key was noticed and removed shortly after it was committed, but never revoked — so chapter 17 addresses the earliest documented failure, not by assuming the key would have been detected, but because its rotation requirement treats an exposed credential as compromised whether or not anything flagged it. Chapter 11 addresses the same stretch from the other side: an organization owner's personal credential should not have been what the automation was holding.
The strongest release boundary is one the build pipeline cannot cross alone. Where practical, let CI build, test and stage the package, then require an independently protected human identity to authorize publication with phishing-resistant 2FA. Before approving, scan the release artifact for malware and exposed secrets, inspect unexpected changes, and verify that its contents match the intended source and build inputs. Approve the exact artifact that will ship, without rebuilding it afterward. Trusted publishing and provenance remain useful parts of this process, but neither establishes that the contents deserve release. A compromised pipeline should be able to produce a suspicious candidate, not silently deliver it to every downstream user.
Sources
#- LiteLLM 1.107.0, 21 October 2026 — Socket. The maintainers' own completed attack-chain investigation is the source here for the single cascading compromise, the committed key, the override and the run deletion; it supersedes their earlier preliminary timeline.
- npm author Qix, 8 September 2025 — Socket.
- GhostAction — Socket. Victim and secret counts vary between sources, so treat the figures as provisional.
- Shai-Hulud — Socket.
- Nx
s1ngularity— Socket. - TanStack Router — Socket.
- tj-actions/changed-files — Socket.
- Codecov Bash Uploader — Codecov's post-mortem, the source for the 23,000 customers and the January–April 2021 window.
- Workflow execution protections, generally available September 2026 — GitHub changelog.
- npm staged publishing, 22 May 2026, npm CLI 11.15.0 or newer — GitHub changelog.
- npm trusted publishing with OIDC, generally available 31 July 2025 — GitHub changelog.
- What disallowing tokens does and does not block — npm's trusted publishers.
- Prevent self-review for environment approvals, October 2023 — GitHub changelog.
- Immutable OIDC subject claims, the default for new repositories from 15 July 2026 — subject-format reference.
- Immutable releases, and what they do and do not lock — GitHub Docs.
- Push protection, and which pattern types it covers — GitHub Docs.
- Delegated-bypass REST endpoints — GitHub Docs.
- Organization personal access token policy — GitHub Docs.
- OAuth App access restrictions, and the privileged OAuth apps that are exempt from them.
- Audit log events, access methods and retention — GitHub Docs.
- Secure use reference — GitHub Docs.




