buzz working
This commit is contained in:
1 parent
8ef626a16b
commit
217b122c67
9 files changed
+204
-20
No files matched your search
+18
-5
@@ -6,11 +6,11 @@ managed with agenix.
|
||||
|
||||
## Contents
|
||||
|
||||
| File | Description |
|
||||
|---|---|
|
||||
| `lab-ca.crt` | Root CA cert (`CN=Skyg Lab CA`). Trusted fleet-wide via `modules/core/lab-ca.nix` (`security.pki.certificateFiles`). |
|
||||
| `lab-ca.srl` | OpenSSL serial counter, written on first `ca issue`. Needed for unique serials — commit it. |
|
||||
| `<domain>.crt` | Leaf certs issued for services (e.g. `buzz.app.internal.crt`). |
|
||||
| File | Description |
|
||||
| -------------- | -------------------------------------------------------------------------------------------------------------------- |
|
||||
| `lab-ca.crt` | Root CA cert (`CN=Skyg Lab CA`). Trusted fleet-wide via `modules/core/lab-ca.nix` (`security.pki.certificateFiles`). |
|
||||
| `lab-ca.srl` | OpenSSL serial counter, written on first `ca issue`. Needed for unique serials — commit it. |
|
||||
| `<domain>.crt` | Leaf certs issued for services (e.g. `buzz.app.internal.crt`). |
|
||||
|
||||
## Managed by `skyg ca` (bin/lib/cmds.nu)
|
||||
|
||||
@@ -31,3 +31,16 @@ Never hand-edit or commit keys here. Re-issuing: delete the leaf cert and
|
||||
re-run `ca issue`. Rotating the CA itself: delete `lab-ca.crt` +
|
||||
`secrets/lab-ca-key.age`, re-run `ca init`, re-issue all leaves, and rebuild
|
||||
every host (fleet trust comes from the committed root cert).
|
||||
|
||||
## When to use what
|
||||
|
||||
- **Lab CA (this dir)**: internal-only services whose clients all use the
|
||||
system trust store (fleet trust via `modules/core/lab-ca.nix`).
|
||||
- **Public Let's Encrypt cert** (`skyg.server.acme`, see
|
||||
`modules/nixos/server/acme/`): anything reached by clients that only trust
|
||||
public CAs — e.g. the Buzz desktop app, whose WS client bundles Mozilla
|
||||
roots and ignores the system store. Buzz uses a public cert for
|
||||
`buzz.home.sosnovsky.ca` (Cloudflare DNS-01); the zone lives in
|
||||
`~/Projects/Homelab/homelab` pending migration into this repo.
|
||||
`buzz.app.internal.crt` here is now unused by the buzz stack and kept only
|
||||
as a lab-CA example.
|
||||
+27
-15
@@ -34,6 +34,8 @@ let
|
||||
# Buzz stack
|
||||
buzz = {
|
||||
domain = "buzz.app.internal";
|
||||
# Public name with a Let's Encrypt cert (skyg.server.acme) — what clients use.
|
||||
publicDomain = "buzz.home.sosnovsky.ca";
|
||||
port = 3000;
|
||||
# Caddy's macvlan IP — buzz.app.internal resolves here; the relay is internal-only.
|
||||
ip = "10.0.101.3";
|
||||
@@ -264,8 +266,17 @@ in
|
||||
|
||||
# Buzz — relay + postgres + redis + minio (S3).
|
||||
age.secrets.buzz-env.file = ../secrets/buzz-env.age;
|
||||
# TLS key for buzz.app.internal, minted by `skyg ca issue` (lab CA).
|
||||
age.secrets.buzz-tls-key.file = ../secrets/buzz-tls-key.age;
|
||||
|
||||
age.secrets.cloudflare-dns.file = ../secrets/cloudflare-dns.age;
|
||||
skyg.server.acme = {
|
||||
enable = true;
|
||||
credentialsFile = config.age.secrets.cloudflare-dns.path;
|
||||
certs."${buzz.publicDomain}" = {
|
||||
postRun = "${pkgs.docker}/bin/docker restart buzz-caddy-1";
|
||||
orderBefore = [ "container-services-buzz" ];
|
||||
};
|
||||
};
|
||||
|
||||
skyg.nixos.common.container-services.buzz = {
|
||||
enable = true;
|
||||
autoUpdate.enable = true;
|
||||
@@ -298,10 +309,10 @@ in
|
||||
BUZZ_BIND_ADDR = "0.0.0.0:${toString buzz.port}";
|
||||
BUZZ_HEALTH_PORT = "8080";
|
||||
BUZZ_METRICS_PORT = "9102";
|
||||
RELAY_URL = "wss://${buzz.domain}";
|
||||
BUZZ_MEDIA_BASE_URL = "https://${buzz.domain}/media";
|
||||
BUZZ_MEDIA_SERVER_DOMAIN = buzz.domain;
|
||||
BUZZ_CORS_ORIGINS = "https://${buzz.domain}";
|
||||
RELAY_URL = "wss://${buzz.publicDomain}";
|
||||
BUZZ_MEDIA_BASE_URL = "https://${buzz.publicDomain}/media";
|
||||
BUZZ_MEDIA_SERVER_DOMAIN = buzz.publicDomain;
|
||||
BUZZ_CORS_ORIGINS = "https://${buzz.publicDomain}";
|
||||
BUZZ_S3_ENDPOINT = "http://minio:9000";
|
||||
BUZZ_S3_REGION = "us-east-1";
|
||||
BUZZ_S3_ADDRESSING_STYLE = "path";
|
||||
@@ -324,10 +335,6 @@ in
|
||||
};
|
||||
};
|
||||
|
||||
# TLS terminator — owns buzz.app.internal (443/80), proxies to the relay
|
||||
# over the internal network. Cert minted by `skyg ca issue` (lab CA).
|
||||
# Also proxies plain :3000 (Hermes guest can't trust the CA yet), :8080
|
||||
# health and :9102 metrics so everything stays on 10.0.101.3.
|
||||
caddy = {
|
||||
image = buzz.images.caddy;
|
||||
extraConfig.depends_on.relay.condition = "service_healthy";
|
||||
@@ -335,14 +342,19 @@ in
|
||||
internal = { };
|
||||
lan = { ipv4_address = buzz.ip; };
|
||||
};
|
||||
dns.names = [ buzz.domain ];
|
||||
dns.names = [ buzz.domain buzz.publicDomain ];
|
||||
files."/etc/caddy/Caddyfile" = ''
|
||||
${buzz.domain} {
|
||||
tls /etc/caddy/tls/cert.pem /etc/caddy/tls/key.pem
|
||||
${buzz.publicDomain} {
|
||||
tls /etc/caddy/tls/fullchain.pem /etc/caddy/tls/key.pem
|
||||
encode zstd gzip
|
||||
reverse_proxy relay:${toString buzz.port}
|
||||
}
|
||||
|
||||
# Old internal name -> public one (plain :3000 below still serves it).
|
||||
http://${buzz.domain} {
|
||||
redir https://${buzz.publicDomain}{uri} permanent
|
||||
}
|
||||
|
||||
:${toString buzz.port} {
|
||||
reverse_proxy relay:${toString buzz.port}
|
||||
}
|
||||
@@ -356,8 +368,8 @@ in
|
||||
}
|
||||
'';
|
||||
volumes = [
|
||||
"${../configs/pki/buzz.app.internal.crt}:/etc/caddy/tls/cert.pem:ro"
|
||||
"${config.age.secrets.buzz-tls-key.path}:/etc/caddy/tls/key.pem:ro"
|
||||
"/var/lib/acme/${buzz.publicDomain}/fullchain.pem:/etc/caddy/tls/fullchain.pem:ro"
|
||||
"/var/lib/acme/${buzz.publicDomain}/key.pem:/etc/caddy/tls/key.pem:ro"
|
||||
];
|
||||
};
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ server/
|
||||
├── admin.nix # skyg.server.admin — www-data group/user for shared web data
|
||||
├── exporters.nix # skyg.server.exporters — Prometheus node exporter (:9100)
|
||||
├── timers.nix # skyg.server.timers — generic attrset → systemd timer+oneshot service
|
||||
├── acme/ # skyg.server.acme — Let's Encrypt certs via DNS-01 (lego), no internet exposure
|
||||
├── arrs/ # *arr media-automation stack (prowlarr/sonarr/radarr) + postgres
|
||||
├── dns/ # Local DNS resolver, certbot, local CA
|
||||
├── k3s/ # Single-binary K3s cluster role
|
||||
@@ -36,6 +37,7 @@ server/
|
||||
skyg.server.admin.enable → admin.nix
|
||||
skyg.server.exporters.enable → exporters.nix
|
||||
skyg.server.timers.<name> → timers.nix
|
||||
skyg.server.acme.* → acme/
|
||||
skyg.server.arrs.* → arrs/
|
||||
skyg.server.dns.* → dns/
|
||||
skyg.nixos.server.k3s.* → k3s/
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
# modules/nixos/server/acme/
|
||||
|
||||
Let's Encrypt certificates via **DNS-01**, wrapped around NixOS
|
||||
`security.acme` (lego) with this repo's conventions. Domain ownership is
|
||||
proven through DNS records at the provider, so **nothing needs to be
|
||||
reachable from the internet** — no port forwards, no public listeners.
|
||||
|
||||
## Options (`skyg.server.acme.*`)
|
||||
|
||||
| Option | Default | Purpose |
|
||||
| ------------------------ | -------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `enable` | `false` | Master switch, per host. |
|
||||
| `email` | `admin@sosnovsky.ca` | Let's Encrypt account contact (expiry notices). |
|
||||
| `dnsProvider` | `"cloudflare"` | lego DNS provider name (see lego docs). |
|
||||
| `credentialsFile` | — | Env file with provider API credentials (e.g. `CLOUDFLARE_DNS_API_TOKEN=...`). Point at an agenix secret — never the Nix store. |
|
||||
| `certs."<domain>"` | `{ }` | One block per certificate; the attribute name is the primary domain. |
|
||||
| `certs.*.extraDomains` | `[ ]` | Extra names on the same cert (SANs). |
|
||||
| `certs.*.reloadServices` | `[ ]` | Native systemd services reloaded after each renewal. |
|
||||
| `certs.*.postRun` | `""` | Shell command after each renewal (e.g. `docker restart <container>` for compose stacks). |
|
||||
| `certs.*.orderBefore` | `[ ]` | `systemd.services` attribute names (no `.service` suffix) that start only after the cert exists (first boot — otherwise Docker bind-mounts empty dirs over the missing cert files). |
|
||||
|
||||
## Usage
|
||||
|
||||
```nix
|
||||
age.secrets.cloudflare-dns.file = ../secrets/cloudflare-dns.age;
|
||||
skyg.server.acme = {
|
||||
enable = true;
|
||||
credentialsFile = config.age.secrets.cloudflare-dns.path;
|
||||
certs."app.home.sosnovsky.ca" = {
|
||||
postRun = "${pkgs.docker}/bin/docker restart my-stack-caddy-1";
|
||||
orderBefore = [ "container-services-my-stack" ];
|
||||
};
|
||||
};
|
||||
```
|
||||
|
||||
Certs land in `/var/lib/acme/<domain>/` (`fullchain.pem`, `key.pem`, …),
|
||||
renewed automatically by the `acme-<domain>.service` timer; hooks run after
|
||||
each renewal. The secret contains one line: `CLOUDFLARE_DNS_API_TOKEN=<token>`
|
||||
(token scope: Zone → DNS → Edit, restricted to the one zone).
|
||||
|
||||
## ⚠ Cloudflare zone lives elsewhere (for now)
|
||||
|
||||
The `sosnovsky.ca` zone and the Cloudflare account/API token are managed in
|
||||
`~/Projects/Homelab/homelab` (Terraform `tf-dns.tf`, cert-manager) until
|
||||
DNS/SSL management migrates into this repo. When that migration happens, only
|
||||
the token's provenance changes — this module is unaffected.
|
||||
|
||||
## Notes
|
||||
|
||||
- Supersedes `skyg.server.dns.certbot` (HTTP-01 + nginx, disabled) for hosts
|
||||
that are not publicly reachable. The certbot module is left untouched.
|
||||
- For internal-only services whose clients all use the system trust store,
|
||||
the lab CA (`skyg ca`, see `configs/pki/ABOUTME.md`) is the simpler option —
|
||||
no public name needed.
|
||||
@@ -0,0 +1,99 @@
|
||||
{ config, lib, ... }:
|
||||
|
||||
with lib;
|
||||
|
||||
let
|
||||
cfg = config.skyg.server.acme;
|
||||
in
|
||||
{
|
||||
# Let's Encrypt certificates via DNS-01 (NixOS security.acme / lego).
|
||||
# Proves domain ownership through DNS records at the provider — nothing
|
||||
# needs to be reachable from the internet.
|
||||
options.skyg.server.acme = {
|
||||
enable = mkEnableOption "Let's Encrypt certificates via DNS-01";
|
||||
|
||||
email = mkOption {
|
||||
type = types.str;
|
||||
default = "admin@sosnovsky.ca";
|
||||
description = "Contact email for the Let's Encrypt account (expiry notices).";
|
||||
};
|
||||
|
||||
dnsProvider = mkOption {
|
||||
type = types.str;
|
||||
default = "cloudflare";
|
||||
description = "lego DNS provider used to prove ownership (see lego docs for names).";
|
||||
};
|
||||
|
||||
credentialsFile = mkOption {
|
||||
type = types.path;
|
||||
description = ''
|
||||
File with the DNS provider's API credentials in lego's env-var format
|
||||
(e.g. CLOUDFLARE_DNS_API_TOKEN=... for cloudflare). Point at an agenix
|
||||
secret so the token never enters the Nix store.
|
||||
'';
|
||||
};
|
||||
|
||||
certs = mkOption {
|
||||
type = types.attrsOf (types.submodule {
|
||||
options = {
|
||||
extraDomains = mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = [ ];
|
||||
description = "Extra names covered by the same certificate (SANs).";
|
||||
};
|
||||
reloadServices = mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = [ ];
|
||||
description = "Native systemd services reloaded after each renewal.";
|
||||
};
|
||||
postRun = mkOption {
|
||||
type = types.str;
|
||||
default = "";
|
||||
description = "Shell command run after each renewal (e.g. restart a container).";
|
||||
};
|
||||
orderBefore = mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = [ ];
|
||||
description = ''
|
||||
systemd.services attribute names (without the .service suffix)
|
||||
that must start only after this cert exists (first boot).
|
||||
'';
|
||||
};
|
||||
};
|
||||
});
|
||||
default = { };
|
||||
description = "Certificates to issue; the attribute name is the primary domain.";
|
||||
};
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
security.acme = {
|
||||
acceptTerms = true;
|
||||
defaults.email = cfg.email;
|
||||
certs = mapAttrs
|
||||
(domain: certCfg: {
|
||||
inherit (cfg) dnsProvider;
|
||||
environmentFile = cfg.credentialsFile;
|
||||
extraDomainNames = certCfg.extraDomains;
|
||||
reloadServices = certCfg.reloadServices;
|
||||
postRun = certCfg.postRun;
|
||||
})
|
||||
cfg.certs;
|
||||
};
|
||||
|
||||
# First-boot ordering: consumers start only after the cert exists.
|
||||
systemd.services = mkMerge (flatten (
|
||||
mapAttrsToList
|
||||
(domain: certCfg:
|
||||
map
|
||||
(unit: {
|
||||
${unit} = {
|
||||
after = [ "acme-${domain}.service" ];
|
||||
wants = [ "acme-${domain}.service" ];
|
||||
};
|
||||
})
|
||||
certCfg.orderBefore)
|
||||
cfg.certs
|
||||
));
|
||||
};
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
imports = [
|
||||
./exporters.nix
|
||||
./admin.nix
|
||||
./acme
|
||||
./arrs
|
||||
./k8s
|
||||
./k3s
|
||||
|
||||
@@ -28,6 +28,9 @@ in
|
||||
# Buzz stack env (minipc1)
|
||||
"secrets/buzz-env.age".publicKeys = [ ari minipc1 ];
|
||||
|
||||
# Cloudflare DNS API token for ACME DNS-01 (skyg.server.acme)
|
||||
"secrets/cloudflare-dns.age".publicKeys = [ ari minipc1 ];
|
||||
|
||||
# stack compose definition — minipc2
|
||||
"secrets/stack1.age".publicKeys = [ ari minipc2 ];
|
||||
"secrets/stack2.age".publicKeys = [ ari minipc2 ];
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Reference in new issue
Block a user