ci: permament builder, https cache, proxy through cloudflared
ci/woodpecker/manual/woodpecker Pipeline was successful
ci/woodpecker/manual/woodpecker Pipeline was successful
This commit is contained in:
19 files changed
+280
-78
No files matched your search
+83
-56
@@ -1,70 +1,97 @@
|
||||
# NixOS builds and LAN cache
|
||||
# NixOS build and cache
|
||||
|
||||
`builder` is the headless configuration for the VM at `10.17.1.100`.
|
||||
Woodpecker builds every `nixosConfigurations` toplevel on pushes and manual
|
||||
runs. Builds run sequentially with one Nix job and four cores on this 8 GiB VM.
|
||||
Secrix runtime secrets do not need decryption in CI.
|
||||
The `builder` flake host is `nix-builder.cazzzer.com`. Router reservations assign
|
||||
`10.17.1.20` and the LAN IPv6 prefix plus `::20:1`. NetworkManager pins the
|
||||
matching DUID and SLAAC token; local DNS returns `.20` and the LAN ULA `::20:1`.
|
||||
|
||||
## Finish Woodpecker registration
|
||||
Woodpecker connects to `woodpecker-grpc.cazzzer.com` with TLS and certificate
|
||||
verification. Its local backend is restricted by repository and builder labels;
|
||||
only trusted push/manual workflows should run on it. The pipeline discovers
|
||||
all flake hosts and builds sequentially into the VM store. Stable indirect GC
|
||||
roots in `/var/lib/nix-ci/<host>` preserve each last successful closure.
|
||||
|
||||
1. Create an agent in Woodpecker and restrict its server-side filters to
|
||||
`repo=CaZzzer/nix-conf` (use the repository's exact spelling as displayed
|
||||
by Woodpecker).
|
||||
Allow only trusted users to push or change pipelines. The local backend
|
||||
executes repository commands as the `woodpecker` user on the VM.
|
||||
2. On the VM, use `sudo install -m 0600 /dev/null /var/lib/woodpecker/agent.env`
|
||||
once, then `sudoedit /var/lib/woodpecker/agent.env` and enter:
|
||||
## Secrets
|
||||
|
||||
```ini
|
||||
WOODPECKER_AGENT_SECRET=<agent token>
|
||||
WOODPECKER_SERVER=<reachable gRPC host:port>
|
||||
WOODPECKER_GRPC_SECURE=true
|
||||
WOODPECKER_GRPC_SKIP_VERIFY=false
|
||||
```
|
||||
`hosts/builder/secrets/*.age` are encrypted to the builder SSH host public key.
|
||||
Back up `/etc/ssh/ssh_host_ed25519_key` securely: it is required to recover these
|
||||
secrets. Secrix decrypts the signing key and CI credentials into service runtime
|
||||
directories. The transcrypt password is read from
|
||||
`/run/nix-builder-ci-secrets/transcrypt-password`; the Woodpecker repository
|
||||
secret is no longer required after deploying this change and pipeline.
|
||||
|
||||
Use `WOODPECKER_GRPC_SECURE=false` for a private plaintext gRPC listener.
|
||||
The public web UI address does not necessarily expose gRPC. The default
|
||||
in the module is `woodpecker.cazzzer.com:9000`; override it here as needed.
|
||||
3. Run `sudo systemctl start woodpecker-agent-nix`.
|
||||
4. Enable this repository in Woodpecker. Add a repository secret named
|
||||
`transcrypt_password` containing the existing transcrypt password. Limit
|
||||
it to push/manual events; do not enable it for pull requests. Commit and
|
||||
push these changes, then confirm the agent picks up the workflow.
|
||||
The migrated agent environment contains the existing token; rotate the token
|
||||
and re-encrypt that file before deploying it, since it appeared in tool output.
|
||||
Existing plaintext files on the VM are left in place for rollback. Remove
|
||||
`/var/lib/woodpecker/agent.env` and `/var/lib/nix-cache/cache-key.sec` after
|
||||
verifying the secrix-managed services and retaining a secure recovery backup.
|
||||
|
||||
The pipeline explicitly uses the native `woodpecker-plugin-git` clone binary.
|
||||
It initializes transcrypt with `aes-256-cbc`, suppressing its credential output.
|
||||
No secret values belong in Nix expressions or the repository.
|
||||
Cloudflare credentials are stored alongside the other encrypted secrets:
|
||||
|
||||
## Cache
|
||||
- `cloudflare-dns.env.age`: plaintext format `CF_API_TOKEN=<token>`, with a
|
||||
Cloudflare API token scoped to DNS Edit and Zone Read for `cazzzer.com`.
|
||||
- `cloudflare-tunnel-token.age`: raw token for a remotely managed tunnel.
|
||||
|
||||
`nix-serve-ng` serves the VM's persistent store at `http://10.17.1.100:5000`
|
||||
through the NixOS `nix-serve` service.
|
||||
It signs responses using `/var/lib/nix-cache/cache-key.sec` (root-only).
|
||||
Back up this key securely; its public key is configured in `hosts/common.nix`.
|
||||
Rebuilding each client once installs cache trust. Clients need LAN/VPN access
|
||||
to this address; the official NixOS cache remains configured.
|
||||
Encrypt each file using `nix run .#secrix -- -h` to inspect the pinned CLI, or
|
||||
pipe it through `age -a -r <builder SSH public key> -o <destination>.age`.
|
||||
Never put plaintext credentials in the repository or Nix store. All referenced
|
||||
credentials are required; missing files fail the build rather than disabling services.
|
||||
|
||||
Successful builds leave indirect GC roots at `/var/lib/nix-ci/<host>`, retaining
|
||||
the latest successful closure per host. Weekly GC removes unrooted paths older
|
||||
than 14 days. Monitor disk space: 100 GiB may become tight for desktop closures
|
||||
and intermediate builds. Remove roots for retired hosts deliberately.
|
||||
## HTTPS and tunnel
|
||||
|
||||
The cache is intended for a trusted LAN. Transcrypt plaintext can occur in Nix
|
||||
store sources and generated configuration, so readers of the cache may recover
|
||||
that information. Runtime secrix secrets remain encrypted. Do not expose this
|
||||
endpoint publicly without adding access control.
|
||||
Caddy uses DNS-01 with the Cloudflare provider and explicit Cloudflare DNS
|
||||
resolvers. It proxies HTTPS to nix-serve-ng on `127.0.0.1:5000`. The raw cache
|
||||
port is closed externally. When enabled, the firewall opens TCP 80/443 and UDP
|
||||
443; SSH remains enabled through the common host configuration. The tunnel
|
||||
requires outbound connectivity only.
|
||||
|
||||
## Updating the builder
|
||||
Tunnel ingress is declared in `hosts/builder/https.nix`: the builder hostname
|
||||
proxies to `https://localhost:443` with the expected origin server name and
|
||||
certificate verification enabled. The proxied public DNS CNAME points to the
|
||||
tunnel. Caddy requires basic authentication for every cache request through
|
||||
both the LAN and tunnel routes. If remote tunnel configuration is later added
|
||||
in Cloudflare, keep its ingress consistent with the repository.
|
||||
|
||||
Build `.#nixosConfigurations.builder.config.system.build.toplevel`, copy its
|
||||
closure to the VM and activate it, or use `nixos-rebuild` targeting `builder`.
|
||||
New repository files must be added to Git before a Git-flake build sees them;
|
||||
`path:.` can be used when validating an uncommitted working tree.
|
||||
### Client authentication
|
||||
|
||||
Check services with:
|
||||
The username is `nix-cache`. The password and its bcrypt hash live in
|
||||
`vars/private.nix` under `cache`, protected in Git by the existing transcrypt filter.
|
||||
Caddy uses the hash; every host imports the shared credentials to generate
|
||||
`/etc/nix/netrc` with mode 0600. No per-host SSH recipients or manual credential
|
||||
distribution are required for basic auth. Decrypt transcrypt before building any
|
||||
host, including new generic VM images.
|
||||
|
||||
```sh
|
||||
systemctl status woodpecker-agent-nix nix-serve
|
||||
journalctl -u woodpecker-agent-nix -f
|
||||
curl http://10.17.1.100:5000/nix-cache-info
|
||||
```
|
||||
Generating netrc this way also places the plaintext cache password in the Nix
|
||||
store, which local users can read and the cache may serve. This is a deliberate
|
||||
tradeoff approved for this cache password; transcrypt protects the Git copy, not build outputs.
|
||||
Secrix remains responsible for Cloudflare tokens, the cache signing key, and
|
||||
Woodpecker credentials.
|
||||
|
||||
Rotating the password requires updating both password and bcrypt hash in the
|
||||
shared private file, then rebuilding the builder and clients.
|
||||
|
||||
### Shared Caddy package
|
||||
|
||||
`vars/default.nix` defines the shared domain and derived service hostnames.
|
||||
It exposes transcrypt-managed shared values as `vars.private`; runtime secrets
|
||||
managed by secrix remain in their host/module `secrets` directories.
|
||||
|
||||
`pkgs/caddy-cloudflare.nix` defines the Cloudflare plugin version and build hash
|
||||
once. Both router and builder call this package. Their routing and credential
|
||||
configuration stays in their respective service modules.
|
||||
|
||||
## Deployment and checks
|
||||
|
||||
1. Ensure Cloudflare credentials are present and rotate the previously exposed agent token.
|
||||
2. Build and deploy the router reservations/DNS before renewing the builder's
|
||||
network connection. Avoid simultaneously switching DHCP identity and routing
|
||||
without a working console or recovery connection.
|
||||
3. Build and deploy `.#nixosConfigurations.builder.config.system.build.toplevel`.
|
||||
Set its transient hostname to `nix-builder` if an old DHCP hostname persists.
|
||||
4. Verify `woodpecker-agent-nix`, `nix-serve`, `caddy`, and
|
||||
`cloudflared-nix-builder` services and their secrix key units.
|
||||
5. Verify LAN and external HTTPS access, signed narinfo responses, and a complete
|
||||
CI run. Rebuild clients to install the new HTTPS substituter URL.
|
||||
|
||||
New files must be added to Git for Git-flake builds; `path:.` includes untracked
|
||||
files during local validation. Weekly GC deletes unrooted paths older than 14
|
||||
days. Monitor the 100 GiB VM disk as desktop closures grow.
|
||||
Reference in new issue
Block a user