Nix binary cache (cache.gewis.nl)¶
niks3 serves the Nix binary cache at
https://cache.gewis.nl. NARs and narinfos live in the SeaweedFS bucket niks3;
niks3 keeps track of what is in it, and of what each path references, in the
Postgres database niks3, which is what its garbage collection works from.
flowchart LR
gha[GitHub Actions] -->|OIDC, request upload| niks3[niks3]
gha -->|presigned PUT| s3[s3-public.gewis.nl, bucket niks3]
niks3 --> pg[(Postgres niks3)]
niks3 -->|sign narinfo| bao[OpenBao transit/niks3]
nix[Nix clients] -->|narinfo| niks3
niks3 -.->|307 to presigned NAR| nix
| Piece | Where |
|---|---|
Bucket niks3, no off-site copy |
terraform/40_seaweedfs-buckets |
Database niks3 |
terraform/40_databases |
transit mount |
terraform/40_openbao-config |
| Signing key, token role, policies, the public key files | terraform/50_niks3-signing |
| Chart, secrets, route | flux/50_apps/niks3/ |
s3-public.gewis.nl route |
flux/40_services/s3/ingressroute.yaml |
Both cache.gewis.nl and s3-public.gewis.nl target the TU/e WAF
(waf.gewis.nl), not router02, because GitHub's runners and off-campus clients
must reach them; see router02.
niks3 itself talks to S3 at s3.gewis.nl; s3.publicURL makes it put the WAF
name in the presigned URLs it hands out.
Reading¶
Anyone can read. The bucket is private, so niks3 runs its read proxy: it serves
narinfos itself and answers NAR requests with a 307 to a presigned
s3-public.gewis.nl URL that is valid for 15 minutes, so NAR bytes go straight from
SeaweedFS to the client.
The public key is flux/50_apps/niks3/signing/public-key. No host trusts it
yet; pushers fetch it from /api/cache-config.
Pushing¶
Nothing pushes yet. GitHub-hosted runners reach niks3 and upload NARs through
the WAF, but the WAF blocks the .ls listings and build logs every push also
uploads (FortiWeb attack ID 20000021), so no push completes and no narinfo is
written. niks3 cannot skip those objects. Pushes are meant to come from
self-hosted runners inside the cluster instead, once the
cluster resolver answers cache.gewis.nl and
s3-public.gewis.nl with Traefik's address so they bypass the WAF; GEPRINT
keeps pushing to Cachix until then.
The server side is in place: pushes come through
Mic92/niks3-action and GitHub's OIDC
tokens; no push secret exists anywhere. The github provider in the
HelmRelease accepts a token only when all of these match:
| Claim | Allowed |
|---|---|
repository |
GEWIS/GEPRINT |
ref |
refs/heads/main |
event_name |
push, workflow_dispatch, schedule |
and grants only the write scope. event_name keeps out pull_request_target
runs, which carry the base branch's ref. A repository that may push is added to
that list and nowhere else; its workflow only names the server URL.
Push rights are root on every host that trusts the key: a signed narinfo is installed without further checks.
Clients upload NARs directly to s3-public.gewis.nl with presigned URLs; niks3 itself
only hands out the URLs and writes the narinfos.
Signing¶
The Ed25519 key is the transit key niks3 in OpenBao, not exportable, so the
private half never leaves OpenBao. niks3 starts /bin/niks3-openbao-signer from
its image for every narinfo, which calls transit/sign/niks3 with the token in
/secrets/signing/token.
That token comes from the VaultDynamicSecret generator niks3-signer-token.
External Secrets logs in as the ServiceAccount niks3-signer (OpenBao role
niks3-signer, policy niks3-token-issuer) and creates a token from the token
role niks3-signer:
| Property | Value |
|---|---|
| Policy | niks3-signer: update on transit/sign/niks3, without default |
| TTL | 24 hours, not renewable |
| Parent | none (orphan), so it outlives External Secrets' one-hour login |
| Refresh | a new token every hour |
The Secret is mounted as a whole volume, so the kubelet swaps the file within about a minute and the signer, which reads it on every request, picks it up without a restart.
terraform/50_niks3-signing writes public-key and signature-name into
flux/50_apps/niks3/signing/, where a configMapGenerator turns them into the
ConfigMap niks3-signing that the HelmRelease reads. A plan after any edit to
those files shows them being rewritten from the transit key.
Garbage collection¶
The chart's CronJob runs at 03:00 and removes paths not pushed or referenced for
30 days, and uploads that never completed after six hours. It authenticates with
the API token in niks3-token, a random value External Secrets generates once;
that token is never given to a pusher.
Losing the bucket¶
The bucket is not copied off-site; everything in it is rebuilt by CI. Postgres
is backed up, so after the bucket is lost the database still lists every path
and niks3 tells pushers those paths are already there. Drop and recreate the
niks3 database (taint postgresql_database.app["niks3"] in 40_databases)
together with the bucket.