Airlock
Airlock is self-hosted CI on Forgejo Actions. You can accept pull requests from people you don’t fully trust, on the same runners that build your releases, and those pull requests still can’t touch your secrets, your build cache or your signing key.
The problem
Sooner or later most teams let someone from outside push code. It might be a client’s developer, a contractor, a freelancer or an open-source contributor with a fork. Their pull request runs in your CI, on machines that also hold your deploy tokens, your registry credentials and the key that signs what you ship.
The setup most self-hosted teams end up with doesn’t hold up against that.
- Runners use privileged Docker-in-Docker so jobs can build images. A job that escapes its container owns the host and every secret on it.
- Jobs share a Docker daemon and its cache. An untrusted job can leave a poisoned layer or cache entry behind, and the next release build picks it up without anyone noticing.
- Outside contributors get a “restricted” set of secrets, which is still a set of secrets handed to code nobody on your team wrote.
- Nobody can say afterwards what was built from what. When a client asks whether the image they’re running was built from the commit you tested, the honest answer is usually “probably”.
So teams pick between two bad options. They keep outsiders out of CI and review their code by hand, or they let them in and hope.
What Airlock gives you
- Outsiders can contribute without being trusted. A fork’s pull request gets no secrets and no network beyond Forgejo, and its job runs in a pod that’s deleted when it finishes. It can still end up on the trusted runner pool (more on that below), but there’s nothing there for it to take.
- A stolen runner credential is useless. Each runner lives for exactly one job, and its token stops working when the job ends.
- You can prove what a release is. Airlock signs a release only if it’s byte-for-byte the image that passed the tests, and attaches an SBOM and a provenance record of the commit, tag and builder. An unsigned or modified image won’t run. Clients and auditors ask for this kind of evidence more and more.
- Builds stay fast without a shared cache anyone can poison. The Go build cache takes a job from 248 s down to 13 s, and only the trusted push-to-
mainjob can write to it. - When something goes wrong, you get a ticket. A stuck queue, an unhealthy autoscaler, a leftover or unexpected runner, or a failed release each opens a Forgejo issue. For any run,
task observe:what-rantells you which commit and images were involved and who approved it. - It’s cheap and stays on your infrastructure. It runs on a single 3.4 GB VM, scales to zero pods when idle and needs no outside service. One command brings it up from the repo in about 4 minutes, and your code and secrets never leave your machines.
I built it for small teams, agencies and consultancies that host client code, and for anyone on Forgejo or Gitea who wants CI they can open to outside contributors.
Constraints
- One VirtualBox VM with 4 vCPU, 3.4 GB of RAM, no swap, and a 30 GB disk shared with other projects. Kubernetes is k3s inside k3d.
- Jobs get no internet. They can reach DNS and Forgejo and nothing else.
- I’m the only maintainer, so there’s no second reviewer to require.
- I only counted a security claim as true once an actual attack had tested it.
Approach
I started from a threat model with four attackers and ten threats, and built things in the order the threats were ranked.
Every job gets its own pod. KEDA watches Forgejo’s job queue and starts one pod per waiting job. The pod registers an ephemeral runner, takes exactly one job and exits, and Forgejo then deletes the runner. Jobs run directly in the runner pod (Forgejo calls this host mode), so a job can always read its runner’s token. Instead of hiding it, I made the token worthless once the job is over: using it afterwards returns 401 unregistered runner. Pools scale to zero.
Pods have no privileges. They run as non-root with every capability dropped, no_new_privs, the default seccomp profile and no service account token. Images are built with ko, so there’s no daemon, and amd64 and arm64 both build without QEMU. Before ko I tried seven ways of running BuildKit unprivileged. The only one that worked needed three holes in the sandbox.
A job’s credentials depend only on who the job is, because a fork can pick which pool it runs on. I learned that in testing (see below). Both pools get the same network, and every credential is a repository secret, which Forgejo never hands to a fork.
Forks can read the build cache but can’t write to it. The Go build cache lives in Forgejo’s package registry under its own bot user, because a write:package token can write every package its owner has. Only the push-to-main job can save to it, and entries are never overwritten.
Only tested images get signed. A protected v* tag starts a separate release job that never runs project code. It rebuilds the image, refuses to sign unless the digest matches the tested build, and then attaches an SPDX SBOM and an SLSA provenance statement. Releases are verified before they run.
Failures don’t go unnoticed. A small recorder CronJob writes one record per job and opens Forgejo issues for a stuck queue, an unhealthy autoscaler, unexpected or leftover runners, and failed releases. I went with that over Prometheus because a metrics stack wouldn’t fit in the memory that was left.
How it was tested
The attacker is a real read-only account with a fork. Its pull request carries a probe that goes after secrets, runner credentials, the network, the Kubernetes API, the cache and the release path. I approve it through the UI the way a real maintainer would. A report compares every result with written expectations and fails on anything unexpected.
The first run broke the design. I’d read Forgejo’s docs as saying an approved fork runs the base branch’s workflow. It actually runs the fork’s own workflow, so runs-on: trusted put the attacker’s job on the trusted pool, with internet access and the runner’s registration token. Secrets were withheld correctly the whole time. What leaked was everything that wasn’t a secret but was still meant only for trusted jobs. Fixing that gave me the rule about credentials above.
Outcome
Measured on that VM, mostly from one sample or a few:
task up from an empty VM |
233 s, and running it again changes nothing |
| Queued to running, from zero pods | median 6.8 s (4 runs) |
| Job with a cold cache vs a warm one | 247.7 s vs 13.1 s |
| Cache hit rate over the history | 13 of 16, and all three misses were known cold runs |
| Peak memory of a cold build | 508 MiB, so the limits are 1 GiB trusted and 768 MiB untrusted |
| KEDA scaled to 0 with a job waiting | issue opened after 27 s (in an earlier incident, the same failure went unnoticed for 20+ minutes) |
| Final attacker runs | 0 unexpected results |
The first release, v0.1.0, went out unsigned because a cosign flag had changed. The demo deploy (task demo:run) checks signatures and refused to run it, so verification caught a real bad release on day one.
Known gaps
- The runner registrar token can also push code to the repos owned by the
ci-adminaccount, because on Forgejo only a repo’s owner can register runners. It’s the weakest credential left. Moving to an organization with separate bot accounts would fix it. - CoreDNS still forwards external names, so a job can get data out by encoding it in DNS queries.
Five long-lived credentials remain, each scoped as narrowly as Forgejo allows.