diff --git a/.gitignore b/.gitignore index 8931e9f..c6895f5 100644 --- a/.gitignore +++ b/.gitignore @@ -34,4 +34,5 @@ venv/ # OS Metadata .DS_Store Thumbs.db -apps/homepage/config/logs/homepage.log +apps/homepage/config/logs/ + diff --git a/README.md b/README.md index 40550f3..4cbc7b3 100644 --- a/README.md +++ b/README.md @@ -92,3 +92,16 @@ This policy is currently enabled on core infrastructure and is recommended for a - **SSO Integration:** Critical apps (Gitea, Dozzle, Portainer) are behind Authelia Forward Auth. - **Automatic TLS:** Traefik manages Let's Encrypt certificates via DNS-01 challenges with Dynu. - **Network Segmentation:** Services are isolated on `proxy-net` and `socket-net`. + +--- + +## πŸ“š Detailed Documentation + +For more in-depth information, please refer to the following guides: + +- **[Server Architecture](docs/architecture.md)**: Deep dive into the layered model, networking, and security posture. +- **[Usability & Operations](docs/usability.md)**: How to use the hub, add new apps, and manage updates. +- **[Troubleshooting](docs/troubleshooting.md)**: Solutions for common connectivity, SSL, and authentication issues. +- **[Project Roadmap](docs/roadmap.md)**: Current status and future planned features. +- **[Dynu IP Protocol](docs/dynu-ip-update-protocol.md)**: Technical details on the DDNS synchronization mechanism. + diff --git a/docs/architecture.md b/docs/architecture.md new file mode 100644 index 0000000..812a3dc --- /dev/null +++ b/docs/architecture.md @@ -0,0 +1,45 @@ +# πŸ—οΈ Server Architecture: Hardened Hub Model + +The homeserver follows a **Layered Architecture** designed for security, observability, and modularity. It is split into two logical tiers: the **Control Plane** (Infrastructure) and the **Data Plane** (Applications). + +## 1. Physical & Host Layer +- **OS**: Linux (Generic). +- **IP Sync**: A host-level systemd service (`scripts/dynu/`) monitors the public IP and updates Dynu DDNS records. This ensures that the external domain always points to the correct gateway. +- **Docker Engine**: Orchestrates all containerized services. + +## 2. Infrastructure Layer (`infra/`) +The "Control Plane" manages the lifecycle and security of the entire stack. + +### 🌐 Edge Gateway (`infra/core`) +- **Traefik v3**: Acts as the Reverse Proxy and SSL terminator. + - Handles **DNS-01 Challenges** via Dynu for wildcard SSL certificates. + - Routes traffic based on subdomains (e.g., `gitea.*`). +- **Socket-Proxy**: A secure bridge that protects the Docker socket. Services needing Docker access (Portainer, Watchtower) talk to this proxy instead of the raw socket, preventing container-escape vulnerabilities. + +### πŸ” Identity & Access (`infra/authelia`) +- **Authelia**: Provides Single Sign-On (SSO) and Two-Factor Authentication (2FA). +- **Forward Auth**: Traefik delegates authentication to Authelia before allowing traffic to sensitive applications. + +### πŸ› οΈ Management & Maintenance +- **Portainer**: Graphical UI for managing Docker stacks and containers. +- **Watchtower**: Automatically pulls new images and restarts containers when updates are available. +- **Diun**: Notifies the administrator of new image tags. + +## 3. Application Layer (`apps/`) +The "Data Plane" contains the services used by end-users. These are isolated on the `proxy-net` network and have no direct access to host resources unless explicitly defined. + +- **Service Discovery**: 'Homepage' (the dashboard) provides a unified portal. +- **SSO Integration**: Apps like Gitea and Dozzle are integrated with Authelia for secure, authenticated access. + +## 4. Networking Model +- **`proxy-net`**: Shared internal network for Traefik and all exposed applications. +- **`socket-net`**: Isolated network for communication between the Socket-Proxy and management tools. +- **External Exposure**: Only ports 80 and 443 are exposed to the internet. All other management (SSH, API) is restricted or handled via the reverse proxy. + +--- + +## πŸ›‘οΈ Security Posture +1. **No Root Docker**: Most containers are encouraged to run with specific PUID/PGID. +2. **Wildcard Certificates**: Wildcard SSL prevents domain enumeration by malicious scanners. +3. **Internal-Only Services**: Some tools (like Portainer) are reachable only via the local network or authenticated proxy. +4. **Log Rotation**: Global policy ensures container logs don't consume all disk space. diff --git a/docs/roadmap.md b/docs/roadmap.md index 860b13e..9fb6fe8 100644 --- a/docs/roadmap.md +++ b/docs/roadmap.md @@ -1,113 +1,55 @@ -# πŸ—ΊοΈ Project Roadmap: Arch-traefik-hub +# πŸ—ΊοΈ Project Roadmap: Hardened Private Cloud Hub -This roadmap reflects the current system maturity and next priorities. +This roadmap reflects the current system maturity and future priorities. --- -## Phase 1: Core Gateway & DNS Stability πŸ”’ (Mostly Complete) +## βœ… Phase 1: Core Gateway & Infrastructure (Complete) +*Objective: Stable external access, identity management, and core security.* -Objective: stable external access with correct DNS resolution. - -- [x] NAT Port Forwarding (80/443) -- [x] Dynu DDNS IP synchronization (systemd-based) -- [x] Traefik deployment with reverse proxy -- [ ] ACME DNS-01 validation (Let's Encrypt) -- [ ] End-to-end HTTPS verification across all services - -Notes: -- IP drift is now handled independently via Dynu updater -- Remaining risk is ACME challenge correctness +- [x] **Dynamic DNS:** Reliable IP synchronization via systemd-based Dynu updater. +- [x] **Edge Routing:** Traefik v3 with Let's Encrypt (DNS-01) automation. +- [x] **Layered Architecture:** Clear separation between `infra/` (control plane) and `apps/` (data plane). +- [x] **Identity & SSO:** Authelia integration with 2FA/OIDC support. +- [x] **Security Hardening:** Docker socket proxy, internal network segmentation, and non-root users where possible. +- [x] **Centralized Logging:** Real-time log streaming via Dozzle. --- -## Phase 2: Observability & Control Plane πŸ“Š +## πŸ—οΈ Phase 2: Application Ecosystem & Observability (In Progress) +*Objective: Expand utility and improve "Single Pane of Glass" monitoring.* -Objective: reduce reliance on CLI and improve visibility. - -- [ ] FastAPI backend for service metadata -- [ ] Minimal JS frontend dashboard -- [ ] Integration with Docker socket (read-only) -- [ ] Deep-linking to Dozzle logs per service -- [ ] Health/status indicators for: - - containers - - domains - - SSL certificates +- [x] **Service Discovery:** 'Homepage' dashboard integration. +- [x] **Visual Tools:** Excalidraw and Mermaid deployment. +- [x] **Development:** Self-hosted Gitea with SSO. +- [x] **AI/ML:** Scalable Ollama cluster with model management. +- [ ] **Unified Health:** Integrate Traefik/Docker health checks into the Homepage dashboard. +- [ ] **Resource Monitoring:** Add lightweight metrics (e.g., Glances or Netdata) with dashboard widgets. --- -## Phase 3: Service Ecosystem Expansion πŸš€ +## πŸš€ Phase 3: Automation & Resilience +*Objective: Move from "manual maintenance" to "autonomous operations".* -Objective: increase utility without compromising isolation. - -- [ ] Excalidraw + diagram tooling -- [ ] Expand Ollama cluster (load + memory tuning) -- [ ] Add developer-focused tools (CI, registry, etc.) -- [ ] Define service templates for quick onboarding - -Constraints: -- Must use `proxy-net` -- Must be Traefik-exposed -- Must remain resource-aware +- [x] **Automated Updates:** Watchtower and Diun for image lifecycle management. +- [ ] **Backup Strategy:** Automated, encrypted off-site backups for persistent volumes (Gitea, DBs). +- [ ] **Infrastructure as Code:** Further modularization of the `up.sh` script into a more robust CLI or Ansible-based setup. +- [ ] **Alerting:** Push notifications (via Gotify/Ntfy) for system failures, auth breaches, or IP update issues. --- -## Phase 4: Network Optimization & Resilience 🌐 +## 🌐 Phase 4: Network Optimization +*Objective: Reduce latency and external dependencies.* -Objective: reduce external dependencies and improve latency. - -- [ ] Local DNS resolver (Pi-hole or equivalent) -- [ ] Internal hostname resolution (LAN-first) -- [ ] NAT hairpinning validation across devices -- [ ] Optional fallback DNS providers for redundancy +- [ ] **Local DNS:** Ad-blocking DNS (Pi-hole/AdGuard Home) for LAN clients. +- [ ] **Hairpin NAT:** Validation and optimization for internal traffic routing. +- [ ] **VPN Integration:** WireGuard-based remote access for private management without public exposure. --- -## Phase 5: Hardening & Reliability βš™οΈ +## πŸ“œ Engineering Principles -Objective: move from β€œworking” to β€œrobust”. - -- [ ] Add alerting (failed Dynu updates, SSL issues) -- [ ] Timer tuning based on real IP volatility -- [ ] Rate-limit awareness for Dynu API -- [ ] Backup strategy for: - - Traefik config - - ACME storage -- [ ] Evaluate IPv6 support (explicitly out-of-scope so far) - ---- - -## πŸ’‘ Engineering Notes - -### Separation of Concerns - -- Dynu updater: - - ensures correct **public IP** - - runs via systemd (host-level) - -- Traefik: - - ensures **TLS + routing** - - runs in Docker - -This separation prevents coupling failures (e.g., container restart affecting DNS correctness). - ---- - -### Failure Model - -- **Degraded** - - DNS failure β†’ HTTP fallback - - Provider-specific issues - -- **Error** - - No valid IP found - - Dynu API failure - -Only **successful external sync** mutates local state. - ---- - -### How to Use This Roadmap - -- Updated after stable merges into `main` -- Items should represent **deployable increments**, not ideas -- Avoid speculative features unless tied to concrete problems \ No newline at end of file +1. **Idempotency:** All deployment scripts (`up.sh`, `down.sh`) must be safe to run repeatedly. +2. **Layered Security:** No single point of failure. If the gateway is breached, apps are still behind SSO. +3. **Auditability:** Every change is reflected in documentation and Git history. +4. **Resilience:** Infrastructure must survive reboots and network outages automatically. diff --git a/docs/troubleshooting.md b/docs/troubleshooting.md new file mode 100644 index 0000000..8773f1d --- /dev/null +++ b/docs/troubleshooting.md @@ -0,0 +1,54 @@ +# 🩺 Troubleshooting Guide + +Common issues and their resolutions for the Hardened Hub. + +## 🌐 Connectivity Issues +### 1. Site is unreachable (General) +- **Check External IP**: Verify if your public IP matches the DNS record at Dynu. + - Run `scripts/dynu/run-once.sh` to force an update. +- **Check Traefik Status**: + - `docker compose -f infra/core/docker-compose.yml ps` + - Ensure Traefik is running and port 80/443 are mapped. + +### 2. "Bad Gateway" (502) or "Service Unavailable" (503) +- This usually means the application container is down or not connected to the `proxy-net`. +- **Action**: Verify the app container is running: + ```bash + docker ps | grep + ``` +- **Action**: Check container logs via Dozzle or `docker logs`. + +## πŸ”’ SSL & Certificate Issues +### 1. "Your connection is not private" +- Traefik might be struggling with the Let's Encrypt challenge. +- **Action**: Check Traefik logs for "ACME" or "LE" errors: + ```bash + docker compose -f infra/core/docker-compose.yml logs -f traefik + ``` +- **Common Cause**: Dynu API key is incorrect or API rate limits were hit. + +### 2. Certificate is not valid for the subdomain +- Ensure the Traefik `Host` rule in your `docker-compose.yml` labels is correct. + +## πŸ” Authentication (Authelia) Issues +### 1. Stuck in a Login Loop +- This often happens if the browser clock or server clock is out of sync. +- **Action**: Sync the server time (`sudo ntpdate pool.ntp.org`). +- **Action**: Clear browser cookies for your domain. + +### 2. Forbidden (403) after login +- Your user may not have the required permissions in `infra/authelia/config/configuration.yml`. +- **Action**: Check the `access_control` section in the Authelia config. + +## 🐳 Docker & Performance +### 1. Disk is full +- **Cause**: Usually excessive logs or orphaned volumes. +- **Action**: Run the cleanup command: + ```bash + docker system prune -a --volumes + ``` +- **Action**: Check `apps/homepage/config/logs/` and other app-specific log paths. + +### 2. High CPU/RAM Usage +- Check the Homepage dashboard or run `docker stats` to identify the culprit. +- **Common Culprit**: Ollama during model inference or Gitea indexing large repos. diff --git a/docs/usability.md b/docs/usability.md new file mode 100644 index 0000000..b6d177a --- /dev/null +++ b/docs/usability.md @@ -0,0 +1,49 @@ +# πŸ–±οΈ Usability & Operational Notes + +This guide explains how to interact with the Hardened Hub once it is deployed. + +## πŸ”‘ Authentication (SSO) +Most services are protected by **Authelia**. +1. When you access a protected service (e.g., `gitea.*`), you will be redirected to the Auth Portal (`auth.*`). +2. Log in with your credentials. +3. Once authenticated, you will have access to all SSO-enabled services for the duration of your session. + +## 🧭 Navigating the Hub +The **Homepage** dashboard is your central entry point: +- **URL**: `https://arch-services.mywire.org` +- **Widgets**: View the health of Docker containers, system resources, and quick links to all deployed applications. + +## πŸ› οΈ Service Management +### Deployment Commands +Use the provided scripts for lifecycle management: +- `./up.sh`: Starts everything. +- `./up.sh --infra-only`: Starts only the control plane (routing, auth, monitoring). +- `./down.sh`: Stops and removes all containers gracefully. + +### Managing a Specific Service +To restart or view logs for a single service (e.g., Gitea): +```bash +cd apps/gitea +docker compose restart +docker compose logs -f +``` + +## βž• Adding a New Application +To add a new service to the Hub: +1. Create a directory in `apps/your-app`. +2. Add a `docker-compose.yml`. +3. Ensure it connects to the `proxy-net` network: + ```yaml + networks: + proxy-net: + external: true + ``` +4. Add Traefik labels for routing and (optional) Authelia labels for SSO. +5. Add the service to `apps/homepage/config/services.yaml` to see it on the dashboard. + +## πŸ“¦ Container Updates +- **Automated**: Watchtower checks for updates every few hours. +- **Manual**: Use Portainer (`portainer.*`) to manually pull new images and recreate containers with a single click. + +## πŸ“ Logging +Real-time logs can be viewed via **Dozzle** at `https://logs.arch-services.mywire.org`. This is preferred over `docker logs` for quick debugging across multiple containers.