- Update docs/appctl.md to cover core_manifest.py, Schema v1.0, Class A/B source provenance, and two-axis status output. - Align docs/architecture.md, docs/secrets-and-state.md, and docs/operations.md with P1 mail topology (Stalwart on smtp.<domain>, SnappyMail in ~/Sites, workload state under ~/var/lib/homelab/<app>/). - Remove external vault path references from docs/decisions/README.md and scrub remaining personal domains/usernames across docs/ and SECURITY.md. - Extend platform genericism security invariant test to guard docs/ and root markdown/flake files.
121 lines
6.4 KiB
Markdown
121 lines
6.4 KiB
Markdown
# 🔒 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-nix`** into an ephemeral in-memory filesystem (`/run/secrets/` and `/run/credentials/`) and are not committed to unencrypted persistent storage.
|
|
|
|
---
|
|
|
|
## 2. Secrets Lifecycle & Projection Architecture
|
|
|
|
```text
|
|
[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 (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` 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
|
|
```bash
|
|
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
|
|
```yaml
|
|
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:
|
|
```bash
|
|
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.${HOMELAB_DOMAIN}`). User account updates do not require editing `secrets.yaml` or 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 |
|
|
| **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 |
|