Remove Portainer from the homelab control plane to strictly enforce declarative GitOps and Infrastructure as Code boundaries. GUI-based container mutation conflicts with automated webhook deployments and the read-only Docker socket proxy invariant. - Remove compose service and volume declarations - Prune SOPS administrative secrets and NixOS module injection - Remove from appctl discovery and Homepage dashboard compilation - Purge from architecture and operational documentation - Add negative Pytest invariant to prevent future reintroduction
6.4 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/credentials/ddclient.service/ddclient.conf │
│ -> Consumed by systemd ddclient service │
│ │
│ 5. /run/secrets/pdf_decrypt_password │
│ -> Consumed by shell pdf_dc utility │
└────────────────────────────────────────────────────────────────────────┘
3. Projected Secret Templates
A. Core Platform Environment (/run/secrets/homeserver.env)
Generated by nixos/modules/homeserver.nix. Supplies credentials to the Core Compose stack:
DOMAIN: Apex domain (roadtotech.me).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 sources when orchestrating stacks in ~/Sites (such as database passwords, API keys, and runner tokens).
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: "..."
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). - Dynamic User Directory: User accounts, credentials, and group memberships are managed live in LLDAP (
https://users.roadtotech.me). 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 files |
| 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 |
| Webmail Storage | ~/Core/config/snappymail/data/ |
❌ No | SnappyMail configuration and sessions |
| 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 |