work // ci / networking
A binary cache that isn't on the internet
contents
Every push to celestial builds four NixOS systems on GitHub’s runners. Those closures need to end up in attic, the binary cache in my lab, so the machines can download instead of compile. The obvious way is to put attic on the internet. I didn’t want that.
What I wanted
GitHub’s hosted runners sit in someone else’s datacentre on addresses I don’t control, and they had to reach attic while the rest of the internet couldn’t. I also wanted to keep the real certificate on attic’s usual name rather than pass --insecure or invent a second hostname. Whatever credential the runner holds shouldn’t open anything besides attic.
The shape of it
The runner joins my tailnet for the length of one job, as a short-lived device carrying tag:github-ci. The tailnet policy only lets that tag reach attic on 443, and the device is gone once the job ends.
Joining the tailnet from a runner
Tailscale’s official GitHub Action does the joining. I give it an OAuth client instead of an auth key. Auth keys expire after 90 days and client secrets don’t, and the client can only mint keys for tags it owns.
- name: Join the tailnet
if: inputs.tailscale-client-id != ''
uses: tailscale/github-action@064b10558093f38325e838ddea35486bdc6b1d5c # v4.4.0
with:
oauth-client-id: ${{ inputs.tailscale-client-id }}
oauth-secret: ${{ inputs.tailscale-secret }}
tags: tag:github-ci
ping: attic
The OAuth client is created in the Tailscale admin console with permission to write auth keys for tag:github-ci and nothing else. Its ID and secret go into the repository as TS_OAUTH_CLIENT_ID and TS_OAUTH_SECRET. The ping input makes the step wait until attic answers, so the next step isn’t racing the connection.
On the policy side, attic is tagged tag:attic, and a single grant connects the two tags:
{
"tagOwners": {
"tag:github-ci": ["autogroup:admin"],
"tag:attic": ["autogroup:admin"]
},
"grants": [
{ "src": ["tag:github-ci"], "dst": ["tag:attic"], "ip": ["443"] }
]
}
No other grant mentions tag:github-ci, so a compromised workflow ends up with a device that can talk to a binary cache and nothing more.
Keeping the certificate valid
Attic’s certificate is for attic.cl2.artesia.cloud. On the tailnet the machine is plain attic at a 100.x address, so using that name breaks TLS, and the public name resolves to an address the runner can’t reach.
I fixed it with one line in /etc/hosts. After joining, the action looks up attic’s tailnet address and maps the public name onto it:
host="${PUBLIC_URL#*://}"; host="${host%%/*}"
address="$(tailscale ip -4 "$TAILNET_HOST")"
echo "$address $host" | sudo tee -a /etc/hosts >/dev/null
From then on every tool in the job uses the normal URL and gets the normal certificate, with no idea the traffic is going over WireGuard.
Failing with a reason
The step after that checks the cache answers by fetching nix-cache-info, retrying ten times over the tailnet because a fresh node can take a few seconds to get a direct path. When it fails, the error tells you which layer to look at:
nix-cache-infodid not answer with 200; 401 means the cache is not public, no answer over the tailnet means the ACL does not let the runner’s tag reach attic on 443 or attic’s firewall drops it.
It also warns when Tailscale couldn’t get a direct connection and fell back to a relay, since that turns a ten-minute push into an hour. tailscale ping prints the lab’s public IP and these logs are public, so the action strips the address with sed and only reports whether the path is direct.
Pushing so a half push can’t look complete
scripts/build-hosts.sh skips a host whose system is already in attic, by checking for the toplevel’s .narinfo. That check is only safe if the toplevel arrives last. Attic uploads a closure in no particular order, so a push that dies halfway could leave the toplevel present and its dependencies missing, and the next run would skip it.
So the script pushes everything except the toplevel first, then the toplevel on its own:
nix-store -qR "$out" | grep -vxF -- "$out" | attic push --stdin --no-closure "$CACHE_NAME" \
&& attic push --no-closure "$CACHE_NAME" "$out"
The toplevel’s narinfo now means “this whole system is here”, which the hosts rely on too.
When attic is down
The attic step is continue-on-error. When it fails the hosts keep building and the slow packages still reach cachix, then the job turns red at the end. Pull requests and Dependabot runs have no secrets, so they build without pushing. While attic is up, the runner also reads from it, at priority 45, after cachix: both hold what CI built, but cachix is a CDN and attic shares my home uplink with every other job in the run.
Reading is a different problem
The cache is public to read, so hosts don’t need a token. They do need to reach it. On the lab network the name resolves to attic directly, and everywhere else it only works over the tailnet or through Pangolin, the self-hosted tunnel every host runs. A laptop on hotel wifi without either gets no cache and falls back to cachix and building, because fallback = true and a five-second connect timeout keep an unreachable cache from stalling a switch.
What I’d change
The OAuth secret is the one credential that matters, and it lives in GitHub. Workload identity federation, where the runner proves who it is with GitHub’s OIDC token instead of a stored secret, would remove it; Tailscale supports it now and it’s the next thing to try.
The uplink is the real bottleneck. Four parallel jobs pushing multi-gigabyte closures through a home connection is slow, and the push-skipping only helps once a host is cached. A self-hosted runner inside the lab would remove the tailnet hop entirely, at the cost of running and patching that runner myself.