diff --git a/README.md b/README.md index 5dc3d55..2178aa5 100644 --- a/README.md +++ b/README.md @@ -45,17 +45,17 @@ User and service applications (e.g. `dashboard`, `docs`, `jellyfin`, `excalidraw The security model is built on zero hardcoded secrets and defense-in-depth: -``` -[~/Config/hosts/desktop/secrets.yaml] (Encrypted with SOPS + age keys) +```text +[nixos/secrets.yaml] (Encrypted with SOPS + age keys) │ - ▼ (Decrypted at boot by sops-nix using SSH host key) + ▼ (Decrypted at boot by sops-nix using host SSH key) [/run/secrets/rendered/homeserver.env] & [/run/secrets/rendered/traefik-deployments.env] │ ▼ (Fed via --env-file and appctl) [Core & Sites Containers] ``` -1. **SOPS & sops-nix Integration:** All sensitive tokens (Dynu API key, Authelia session secrets, JWT keys, database passwords) are encrypted in `~/Config/hosts/desktop/secrets.yaml` and decrypted by NixOS at runtime into in-memory `/run/secrets/rendered/`. +1. **SOPS & sops-nix Integration:** All sensitive tokens (Dynu API key, Authelia session secrets, JWT keys, database passwords) are encrypted in `nixos/secrets.yaml` and decrypted by NixOS at runtime into in-memory `/run/secrets/` and `/run/secrets/rendered/`. 2. **Edge TLS & HSTS:** All external traffic is forced over HTTPS using Let's Encrypt wildcard certificates with strict redirect schemes (`https-redirect@docker`). 3. **Authelia ForwardAuth:** Applications that require authentication declare `traefik.http.routers..middlewares=authelia-auth@docker`, delegating identity verification to Authelia. 4. **Socket Isolation:** Direct Docker daemon sockets are completely hidden behind `socket-proxy`. @@ -170,15 +170,42 @@ appctl up myapp --- -## ⚙️ NixOS Service Management +## ❄️ Declarative NixOS Appliance + +This repository is a self-contained NixOS appliance. It defines the operating system, Docker infrastructure, firewall rules, automated DDNS updates, and host shell environment in a single flake. -The Core Control Plane runs as a native systemd unit managed declaratively by NixOS: +### Repository NixOS Layout: +* **[`flake.nix`](flake.nix)** — Flake entrypoint defining `nixosConfigurations.server`. +* **[`nixos/configuration.nix`](nixos/configuration.nix)** — Standalone headless host configuration (locale, SSH, Docker, packages). +* **[`nixos/hardware-configuration.nix`](nixos/hardware-configuration.nix)** — Server hardware, disk mounts, and kernel parameters. +* **[`nixos/secrets.yaml`](nixos/secrets.yaml)** — SOPS-encrypted secrets for the server. +* **[`nixos/modules/homeserver.nix`](nixos/modules/homeserver.nix)** — `homeserver-core.service`, `homelab-gitops.service`, and Authelia secrets. +* **[`nixos/modules/traefik-deployments.nix`](nixos/modules/traefik-deployments.nix)** — Traefik applications environment secrets (`traefik-deployments.env`). +* **[`nixos/modules/dynu.nix`](nixos/modules/dynu.nix)** — Dynu DDNS smart IP monitor timer and ddclient credentials. +* **[`nixos/modules/shell.nix`](nixos/modules/shell.nix)** — Server-tailored bash shell profile, aliases, and utilities. -* **Service Unit:** `homeserver-core.service` -* **Nix Module:** [`~/Config/hosts/desktop/homeserver.nix`](file:///home/kiskaadee/Config/hosts/desktop/homeserver.nix) -* **Status Inspection:** `systemctl status homeserver-core` -* **Logs:** `journalctl -u homeserver-core -f` -* **Restart:** `sudo systemctl restart homeserver-core` +### Common Operations: +```bash +# Rebuild and switch the running system +sudo nixos-rebuild switch --flake ~/Core#server +# (or use the built-in alias: nix-switch) + +# Inspect core service units +systemctl status homeserver-core +journalctl -u homeserver-core -f + +# Inspect GitOps webhook dispatcher +systemctl status homelab-gitops + +# Inspect dynamic IP monitor +systemctl status dynu-monitor +``` + +### Disaster Recovery: +Any clean machine can be provisioned into this server: +```bash +nixos-install --flake ~/Core#server +``` --- diff --git a/SECURITY.md b/SECURITY.md index 78e4bc7..20704fd 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -29,8 +29,8 @@ The most critical security feature. No container (including Traefik or Portainer Despite the hardening, you should remain vigilant about the following: ### 1. Host-Level Security (The Foundation) -If an attacker gains SSH access to your Arch Linux host, they have total control. -- **Action**: Use SSH Keys only (disable password login). Install `fail2ban`. Keep the host kernel updated (`pacman -Syu`). +If an attacker gains SSH access to your host, they have control over the system. +- **Action**: Use SSH Keys exclusively (`PermitRootLogin = "no"` is enforced by NixOS). Keep your Nix flake inputs and system updated (`sudo nixos-rebuild switch --flake ~/Core#server`). ### 2. Application-Specific Vulnerabilities A zero-day exploit in Gitea or Ollama could allow an attacker to execute code *inside* that specific container. diff --git a/docs/setup_guide.md b/docs/setup_guide.md index f6a34ab..76f766f 100644 --- a/docs/setup_guide.md +++ b/docs/setup_guide.md @@ -22,8 +22,8 @@ All sensitive tokens, encryption keys, and credentials are encrypted using **`so ### Secrets Lifecycle: -``` -[~/Config/hosts/desktop/secrets.yaml] (Encrypted with Age) +```text +[nixos/secrets.yaml] (Encrypted with Age) │ ▼ (Decrypted at boot by sops-nix daemon) 1. [/run/secrets/rendered/homeserver.env] --> Fed to Core Compose Stack @@ -39,55 +39,56 @@ All sensitive tokens, encryption keys, and credentials are encrypted using **`so To update credentials (e.g. changing your Dynu API key or updating Authelia user passwords): -1. Navigate to your NixOS configuration repository: +1. Navigate to the core repository: ```bash - cd ~/Config + cd ~/Core ``` 2. Decrypt and open the secrets file in your editor: ```bash - nix-shell -p sops --run "sops hosts/desktop/secrets.yaml" + sops nixos/secrets.yaml ``` 3. Update or append keys under the root block: ```yaml - dynu_api_key: "your_dynu_api_key" - acme_email: "your_email@domain.com" - authelia_session_secret: "secure_64_char_secret" - authelia_storage_encryption_key: "secure_64_char_key" - authelia_identity_validation_reset_password_jwt_secret: "secure_64_char_jwt_secret" - authelia_user_kiskaadee_password_hash: "$argon2id$v=19$m=65536..." + dynu: + api_key: "your_dynu_api_key" + traefik: + acme_email: "your_email@domain.com" + authelia: + session_secret: "secure_64_char_secret" + storage_encryption_key: "secure_64_char_key" + jwt_secret: "secure_64_char_jwt_secret" + users: + kiskaadee: + password_hash: "$argon2id$v=19$m=65536..." ``` *To generate an Argon2 password hash securely, run:* ```bash docker run --rm -it authelia/authelia:latest authelia crypto hash generate argon2 ``` 4. Save and close. SOPS will automatically encrypt the modified file before saving. +5. Rebuild the system to apply new secret templates: + ```bash + sudo nixos-rebuild switch --flake ~/Core#server + ``` --- ## ⚙️ Declarative NixOS Modules -The Core stack and deployment environments are defined declaratively in `~/Config`: +The Core stack and deployment environments are defined declaratively in `nixos/modules/`: -### 1. Control Plane Module ([`hosts/desktop/homeserver.nix`](file:///home/kiskaadee/Config/hosts/desktop/homeserver.nix)) -Generates `/run/secrets/rendered/homeserver.env` and manages the `homeserver-core.service` systemd daemon: -```nix -sops.templates."homeserver.env" = { - owner = "kiskaadee"; - content = lib.generators.toKeyValue {} { - DOMAIN = "roadtotech.me"; - DOCKER_API_VERSION = "1.40"; - DYNU_API_KEY = config.sops.placeholder.dynu_api_key; - ACME_EMAIL = config.sops.placeholder.acme_email; - AUTHELIA_SESSION_SECRET = config.sops.placeholder.authelia_session_secret; - AUTHELIA_STORAGE_ENCRYPTION_KEY = config.sops.placeholder.authelia_storage_encryption_key; - AUTHELIA_IDENTITY_VALIDATION_RESET_PASSWORD_JWT_SECRET = config.sops.placeholder.authelia_identity_validation_reset_password_jwt_secret; - }; -}; -``` +### 1. Control Plane Module ([`nixos/modules/homeserver.nix`](../nixos/modules/homeserver.nix)) +Generates `/run/secrets/rendered/homeserver.env`, `/run/secrets/rendered/users.yml`, and manages the `homeserver-core.service` and `homelab-gitops.service` systemd daemons. -### 2. Applications Secret Module ([`hosts/desktop/traefik-deployments.nix`](file:///home/kiskaadee/Config/hosts/desktop/traefik-deployments.nix)) +### 2. Applications Secret Module ([`nixos/modules/traefik-deployments.nix`](../nixos/modules/traefik-deployments.nix)) Generates `/run/secrets/rendered/traefik-deployments.env` consumed by `appctl`. +### 3. Dynamic DNS Module ([`nixos/modules/dynu.nix`](../nixos/modules/dynu.nix)) +Configures the smart IP monitor timer and updates ddclient when IP rotations occur. + +### 4. Server Shell Module ([`nixos/modules/shell.nix`](../nixos/modules/shell.nix)) +Defines interactive bash aliases, git helpers, and terminal tools via system `/etc/bashrc`. + --- ## 🚀 Running and Managing the Stack