Mobile Testing & Security

Self-hosted runner security and the problem with persistent runners

On a persistent self-hosted GitHub Actions runner, an attacker who gets one job running can take more than that job's secrets. The GitHub account hijacking campaign that started on November 10, 2026 shows how. 4,837 hijacked accounts targeted 61,764 repositories with a script that collected secrets and cloud credentials from the runner, and Aikido, who found the wfx-loot campaign, counted at least 1,806 repositories that ran it. The attack would have worked on any runner. On one that keeps its state between jobs, though, the script could also reach credentials left behind by other repos, and afterwards you can't easily tell whether the machine is still clean.

If a malicious workflow ran on your runners

Expect the evidence to be thin. This attacker reverted each change within about a minute and deleted the workflow run and its logs. Start here:

  1. Look for workflow changes nobody on your team made, and for skipped workflow run numbers. Then check your organization's audit log, which records deleted workflow runs, and any logs you send off the runner.
  2. If malicious code ran, rotate every secret that workflow could read and every cloud role it could assume through OIDC. Then check your cloud audit logs for new access keys, changed trust policies and new federated credentials, because that’s where the November campaign’s payload tried to keep access.
  3. Wipe and reinstall any persistent runner it ran on. With the logs gone, you can't show the machine is clean.

The third step only applies to self-hosted runners, and it's what the rest of this post is about.

Ephemeral runners wouldn't have protected the job's own secrets

The attacker had valid tokens with write access, so they could push a workflow change to any repository the token reached. The malicious job then got whatever that workflow normally gets: GitHub Actions secrets, a GITHUB_TOKEN, and the ability to request OIDC tokens for your cloud accounts. None of that depends on where the job runs. A VM created five seconds ago receives the same secrets as a build machine that's been in the rack for three years.

What the attacker's job can read: on a persistent self-hosted runner and on an ephemeral runner, GitHub gives the job its own secrets (Actions secrets, GITHUB_TOKEN, cloud access through OIDC). Only the persistent runner also holds cloud credentials, signing keys, other repos' code and registry tokens left by earlier jobs; on the ephemeral runner nothing is left, because the VM is new for every job.

In that campaign, the payload's long-term access lived in the cloud too: long-lived access keys, a cloud role changed so any account could assume it, and new federated credentials. If an attack like this reaches you, most of your cleanup is in those accounts.

A persistent runner exposes other jobs' credentials

Self-hosted runners keep their state between jobs unless you set them up otherwise. After a few months, a self-hosted macOS runner usually holds things nobody meant to leave on it. Places worth checking:

  • Cloud credential files that a deploy job’s CLI saved to the home folder and never cleaned up
  • Package manager config files that hold registry tokens
  • Signing keys and certificates, in the macOS keychain or a keystore file, which stay unless the workflow removes them
  • ~/.zsh_history or ~/.bash_history, sometimes with a token someone pasted while debugging
  • Tokens set as environment variables in shell profiles like ~/.zshrc, or in the runner's own .env file
  • The runner's _work folder, with checkouts and caches from every repo that used the machine
  • Other runner instances' folders, if several run under the same user account

The payload went looking for exactly this kind of thing: cloud credential files, shell history, runtime tokens, API keys for AI tools, and tokens it could read from the memory of running processes. If the job runs on a VM created for it, the script mostly finds that job's own secrets. A Mac that has built a dozen repos for a year can hand it credentials from jobs unrelated to the repo the attacker came in through. Say your open-source SDK and your main app share a runner. Someone who gets into the SDK repo could leave with the app’s store publishing key, for App Store Connect or Google Play.

Four jobs in a row on the same runner: an app release build, a tools repo cloud deploy, an app store upload, then the attacker's job in the SDK repo. On a persistent self-hosted runner the attacker's job reads all four: the signing key, the cloud credentials, the store publishing key and its own secrets. On an ephemeral runner, where each job gets a new VM that is deleted when the job ends, it reads only its own secrets.

You can find out how much of this is on your machines by logging in to one runner and going through the list above.

Persistence also makes the cleanup harder. Because the attacker deleted runs and logs, you can't easily tell, unless you keep copies of your logs somewhere the job can't reach, whether the script changed anything on the machine itself, such as a new launch agent or a modified binary on the PATH. The researchers found this payload's persistence in cloud accounts, but trusting that it stopped there is a gamble, which is why the response steps at the top include reimaging. On a fleet of Macs, that means a lot of reinstalling. With runners that are thrown away after each job, there's nothing to reinstall.

The same build-up causes a second problem that has nothing to do with attackers: environment drift. Each job can leave a runner slightly different, through an updated tool, a changed setting or a cache that no longer matches. Say one Mac in a fleet of twenty ends up with a broken environment. Every job it picks up fails, while the same jobs pass on the other nineteen, so the failures look random and it can take a while to trace them to one machine. Ephemeral runners avoid this for the same reason they avoid leftover credentials: every job starts from the same image.

Ephemeral self-hosted runners still need a clean machine

According to GitHub’s secure use reference, self-hosted runners come with no guarantee of a clean environment for each job, untrusted code in a workflow can compromise them persistently, and a runner shared across an organization can take jobs from many repositories, so one compromise can reach all of them. GitHub says they should almost never be used with public repositories and recommends ephemeral GitHub Actions runners that take a single job instead. Register a runner with --ephemeral, or create a just-in-time runner through GitHub’s API, and it runs at most one job before it’s removed.

Removing the registration doesn’t touch the machine, and reusing the same hardware can expose what an earlier job left behind. For a clean environment you still need something that destroys the VM or container after each job and creates a fresh one, plus a place outside the machine to keep logs, since they disappear with it. Ideally that's write-once storage with a retention period, so a compromised job can't delete them either.

Three ways to stop runners keeping state

OptionUpkeepThe catchSuits
Harden your current runnersLow, but every workflow has to clean up after itself, even when a job failsWhatever a missed cleanup step leaves stays on the machineA few private repos and no outside contributors
Build ephemeral runners yourselfHigh: a new base image for every Xcode releaseEngineering timeTeams whose platform group already runs this kind of infrastructure
Use managed ephemeral runnersLow: the provider maintains the machines and images. Setup is a runs-on label changeLess control over hardware and network placement, and you're trusting a vendorTeams that want ephemeral Mac runners without running Mac infrastructure

On Linux, building your own is easier, since Actions Runner Controller on Kubernetes does most of the job. On Mac, tools like Tart or Anka handle the virtualization, but expect the base image to turn into somebody’s part-time job unless a platform team already owns this kind of work.

For the managed option, Bitrise Build Hub, which we make, is one choice, and we’ve compared it with other managed runners in our runner roundup. Your workflows stay in GitHub Actions, and with ephemeral pools each build gets a freshly provisioned VM from a clean snapshot, which is destroyed when the build finishes. Build Hub offers persistent VMs too, so check that your pool is ephemeral. We maintain the images and ship new Xcode versions within 24 hours of Apple's release. The machines run in our data centers, not on your network. Fork approval and runner groups still matter on managed instances.

If we were choosing, the first option gets a team with only private, in-house repos a long way. Once outside contributors or lots of repos share the same Macs, we'd get rid of persistence, and then it's mostly a question of whether you want to maintain the images yourself. A quick way to tell which group you're in: if one runner turned up credentials from more than one team when you went through the list above, you're past the first option.

Self-hosted runner security best practices

If you're keeping your current runners, these apply whether or not you’ve been hit.

  1. Set permissions: explicitly in every workflow and default to read-only, so a compromised job gets as little as possible from GITHUB_TOKEN.
  2. Keep self-hosted runners away from public repositories, and require approval before workflows from forks or outside collaborators run.
  3. Use runner groups so repos with different levels of trust don't share machines, and run each runner instance under its own user account.
  4. End every job that creates credentials with a cleanup step that runs even when the job fails or is cancelled (if: always()), and keep signing certificates in a temporary keychain that you delete at the end. A crash or restart can still skip that step, so add a scheduled sweep that removes anything left behind, and treat reimaging as the only cleanup you can fully rely on.
  5. Limit outbound traffic from your runners. Record which hosts, ports and protocols your builds actually need, then block everything else, allowing by hostname since registries and CDNs change addresses. This payload sent everything over HTTP POST to two servers, which an allowlist would have blocked. Tools like StepSecurity’s Harden-Runner monitor this on self-hosted runners as well as GitHub-hosted and Build Hub ones, though private repositories need its paid tier.
  6. Keep logs where a job can't delete them. Send the runner's _diag logs and system logs to a log server, or to write-once storage with a retention period, so a deleted workflow run still leaves a trace.
  7. Where you can, register runners with --ephemeral and rebuild the machine between jobs.

Check one of your runners

Pick one of your self-hosted runners and work out two things: which repositories can run code on it, and what that code would find on the disk. If the answers are "most of them" and "credentials from several teams", we'd deal with persistence first, whichever option you go for.

If you'd rather not build and maintain ephemeral Mac runners yourself, Build Hub runs them for you.

Last updated:
December 3, 2026
contents

Get started for free

Get a 30-day free trial and join the 400,000+ mobile developers who already love Bitrise.

Start free trial

More from the blog