Closes #6
8.1 KiB
🔒 Homelab Core — Secrets Management & Persistent State
This document explains the secrets distribution architecture, runtime projection mechanisms, user directory model, and persistent state boundaries for Homelab Core.
1. Secrets Management Policy
- No Plaintext Secrets in Git: All sensitive credentials, API keys, tokens, and private keys are encrypted at rest using Mozilla SOPS with Age keys derived from the server's SSH host key.
- In-Memory Projections: Secret files are decrypted at boot by
sops-nixinto an ephemeral in-memory filesystem (/run/secrets/and/run/credentials/) and are not committed to unencrypted persistent storage.
2. Secrets Lifecycle & Projection Architecture
[nixos/secrets.yaml] (Encrypted with Age / SOPS)
│
▼ (Decrypted at boot by sops-nix using /etc/ssh/ssh_host_ed25519_key)
┌──────┴─────────────────────────────────────────────────────────────────┐
│ In-Memory Projections (/run/secrets/ & /run/credentials/) │
├────────────────────────────────────────────────────────────────────────┤
│ 1. /run/secrets/homeserver.env │
│ -> Consumed by homeserver-core.service & Core docker-compose.yml │
│ │
│ 2. /run/secrets/traefik-deployments.env │
│ -> Consumed by appctl to inject secrets into Sites workloads │
│ │
│ 3. /run/secrets/gitops/webhook_secret │
│ -> Consumed by homelab-gitops.service for HMAC verification │
│ │
│ 4. /run/secrets/appctl/tokens.json (mode 0400, homelab-appctl) │
│ -> Consumed by homelab-appctl.service for SHA-256 Bearer auth │
│ │
│ 5. /run/secrets/gitops/appctl_token (mode 0400, operatorUser) │
│ -> Consumed by homelab-gitops.service worker for UDS daemon auth │
│ │
│ 6. /run/credentials/ddclient.service/ddclient.conf │
│ -> Consumed by systemd ddclient service │
│ │
│ 7. /run/secrets/pdf_decrypt_password │
│ -> Consumed by shell pdf_dc utility │
└────────────────────────────────────────────────────────────────────────┘
3. Projected Secret Templates & Token Store
A. Core Platform Environment (/run/secrets/homeserver.env)
Generated by nixos/modules/homeserver.nix. Supplies credentials to the Core Compose stack:
DOMAIN: Apex domain (e.g.,example.com).DYNU_API_KEY: API key for Dynu DNS-01 ACME Let's Encrypt validation.ACME_EMAIL: Account email for Let's Encrypt certificates.AUTHELIA_SESSION_SECRET: Authelia cookie encryption secret.AUTHELIA_STORAGE_ENCRYPTION_KEY: Database encryption key for Authelia SQLite storage.AUTHELIA_IDENTITY_VALIDATION_RESET_PASSWORD_JWT_SECRET: Reset password token secret.LLDAP_JWT_SECRET&LLDAP_KEY_SEED: Cryptographic tokens for LLDAP.LLDAP_LDAP_USER_PASS: Admin password for LLDAP and Authelia LDAP binding.SMTP_SERVER,SMTP_PORT,SMTP_LOGIN,SMTP_KEY: Outbound relay credentials (Brevo) for Stalwart mail transport.
B. Workload Deployments Environment (/run/secrets/traefik-deployments.env)
Generated by nixos/modules/traefik-deployments.nix. Projects shared infrastructure secrets and workload credentials that appctl parses inertly in pure Python when orchestrating stacks in ~/Sites (such as database passwords, API keys, and runner tokens).
C. Control Plane Token Store (/run/secrets/appctl/tokens.json & /run/secrets/gitops/appctl_token)
Provisioned from nixos/secrets.yaml (appctl/tokens_json and gitops/appctl_token):
/run/secrets/appctl/tokens.json: Owned byhomelab-appctl:homelab-operatorswith strict mode0400(enforced fail-closed byTokenStore._verify_permissions()). Stores SHA-256 hex digests of Bearer secrets mapped totoken_id,identity, androle(homelab-admin,homelab-operator,homelab-viewer)./run/secrets/gitops/appctl_token: Owned byconfig.homelab.operatorUser(mode0400). Supplies thehomelab-operatorBearer secret tohomelab-gitops.servicewhen delegatingworkload.updatetohomelab-appctl.service.~/.config/homelab/token: Local operator Bearer token (mode0600) read byappctl_cli.pyfor interactive CLI mutations.
4. Secret Modification and Rotation Workflow
To edit or rotate secrets:
1. Open the Encrypted Secrets File
cd ~/Core
sops nixos/secrets.yaml
SOPS decrypts the file using your host SSH private key and opens it in your editor.
2. Modify Secret Keys
dynu:
api_key: "..."
authelia:
session_secret: "..."
jwt_secret: "..."
lldap:
admin_password: "..."
gitops:
webhook_secret: "..."
appctl_token: "..."
appctl:
tokens_json: "[...]"
brevo:
smtp_login: "..."
smtp_key: "..."
3. Save and Apply Changes
Saving the file in your editor automatically re-encrypts it with Age. Apply the updated templates to running services:
sudo nixos-rebuild switch --flake ~/Core#server
5. User Directory vs. Static Secrets
Homelab Core separates user identity from static platform secrets:
- Static Secrets: Stored in
nixos/secrets.yaml(system API keys, JWT secrets, database passwords, control-plane token hashes). - Dynamic User Directory: User accounts, credentials, and group memberships are managed live in LLDAP (
https://users.${HOMELAB_DOMAIN}). User account updates do not require editingsecrets.yamlor rebuilding NixOS. - Authelia Integration: Authelia queries LLDAP over LDAP (
ldap://lldap:3890) at runtime using credentials projected from/run/secrets/homeserver.env.
6. Persistent State Map
| Category | Storage Location | Stored in Git? | Description |
|---|---|---|---|
| Declarative Config | ~/Core/nixos/*.nix, docker-compose.yml |
✅ Yes | System and container definitions |
| Encrypted Secrets | ~/Core/nixos/secrets.yaml |
✅ Yes (Encrypted) | SOPS Age-encrypted secret source |
| Runtime Secrets | /run/secrets/* |
❌ No (RAM tmpfs) | Ephemeral decrypted environment & token files |
| Control Plane Audit | /var/log/homelab/appctl/audit.jsonl |
❌ No | Append-only JSONL security & mutation log (0600) |
| Control Plane Locks | /var/lib/homelab/appctl/locks/ |
❌ No | Per-target flock files & _homepage_sync.lock |
| SSL Certificates | ~/Core/config/letsencrypt/acme.json |
❌ No | Active Let's Encrypt certificates (mode 0600) |
| User Directory | ~/Core/config/lldap/data/ |
❌ No | LLDAP SQLite database (users.db) |
| Auth Database | ~/Core/config/authelia/db.sqlite3 |
❌ No | Authelia session database |
| Mail Data & Keys | ~/Core/config/stalwart/ |
❌ No | Stalwart mail storage, DKIM keys, mailboxes |
| Workload State Root | ~/var/lib/homelab/<app>/ |
❌ No | Per-workload persistent runtime state (e.g., snappymail) |
| Container Volumes | Docker volume dozzle_data |
❌ No | Dozzle UI preferences and state |
| DDNS History | /var/lib/dynu/ip_history.jsonl |
❌ No | Historical WAN IP transitions log |
| GitOps State | ~/.local/state/homelab/gitops/ |
❌ No | Deployment locks, pending JSONs, status logs |