Files
michaelschiemer/docs/deployment/WIREGUARD-IMPLEMENTATION-PLAN.md
Michael Schiemer 3ed2685e74 feat: add comprehensive framework features and deployment improvements
Major additions:
- Storage abstraction layer with filesystem and in-memory implementations
- Gitea API integration with MCP tools for repository management
- Console dialog mode with interactive command execution
- WireGuard VPN DNS fix implementation and documentation
- HTTP client streaming response support
- Router generic result type
- Parameter type validator for framework core

Framework enhancements:
- Console command registry improvements
- Console dialog components
- Method signature analyzer updates
- Route mapper refinements
- MCP server and tool mapper updates
- Queue job chain and dependency commands
- Discovery tokenizer improvements

Infrastructure:
- Deployment architecture documentation
- Ansible playbook updates for WireGuard client regeneration
- Production environment configuration updates
- Docker Compose local configuration updates
- Remove obsolete docker-compose.yml (replaced by environment-specific configs)

Documentation:
- PERMISSIONS.md for access control guidelines
- WireGuard DNS fix implementation details
- Console dialog mode usage guide
- Deployment architecture overview

Testing:
- Multi-purpose attribute tests
- Gitea Actions integration tests (typed and untyped)
2025-11-04 20:39:48 +01:00

1176 lines
29 KiB
Markdown

# WireGuard VPN Implementation Plan
**Ziel**: Funktionsfähiges WireGuard VPN für sicheren Zugriff auf interne Services (Grafana, Traefik Dashboard)
**Status**: Analysephase abgeschlossen, Implementierungsplan erstellt
**Datum**: 2025-11-04
---
## 1. Current State Assessment
### Server Configuration
- **Host**: michaelschiemer.de (94.16.110.151)
- **Port**: 51820/udp
- **VPN Network**: 10.8.0.0/24
- **Server IP (VPN)**: 10.8.0.1
- **Server Public Key**: hT3OCWZ6ElX79YdAdexSsZnbWLzRM/5szk+XNEBUaS8=
### Existing Infrastructure
**Ansible Automation** (vollständig vorhanden):
- `setup-wireguard.yml` - Server Installation
- `add-wireguard-client.yml` - Client Creation mit Auto-IP
- `regenerate-wireguard-client.yml` - Client Regeneration
- `test-wireguard-docker-container.yml` - Docker Testing
**Documentation** (umfassend):
- WIREGUARD-SETUP.md - Komplette Setup-Dokumentation
- WIREGUARD-WINDOWS-ROUTING-FINAL-ANALYSIS.md - Windows Routing Problem
- WIREGUARD-WINDOWS-DNS-FIX.md - DNS Konfiguration
- WIREGUARD-RECREATE-AND-TEST.md - Troubleshooting Strategy
**Existing Clients** (4 Konfigurationen):
- `grafana-latest.conf`
- `test-client.conf`
- `mikepc.conf`
- `grafana-test.conf`
### Protected Services
- **Traefik Dashboard**: VPN-only + BasicAuth
- **Grafana**: VPN-only middleware
- **Main App**: Bleibt öffentlich (michaelschiemer.de)
---
## 2. Root Cause Analysis
### Primary Issue: Windows Routing Problem
**Symptome**:
- WireGuard verbindet erfolgreich ✅
- Route vorhanden: `10.8.0.0/24`
- Ping zu 10.8.0.1 funktioniert ✅
- **ABER**: HTTP/HTTPS Traffic kommt von Public IP (89.246.96.244) ❌
- **Erwartet**: Traffic sollte von VPN IP (10.8.0.7) kommen ❌
**Diagnose** (aus WIREGUARD-WINDOWS-ROUTING-FINAL-ANALYSIS.md):
```
Traefik Access Log zeigt:
89.246.96.244 - - [Date] "GET /grafana HTTP/2.0" 404
↑ Public IP statt 10.8.0.7
```
**Root Causes** (Priorisiert):
1. **DNS fehlt in Client Config** (Höchste Wahrscheinlichkeit):
- Windows nutzt Standard-DNS statt VPN-DNS
- Auflösung von `grafana.michaelschiemer.de` geht über Public DNS
- Traffic wird entsprechend über Public Interface geroutet
2. **Windows Interface Metric Prioritization**:
- Standard-Netzwerk hat niedrigeren Metric (höhere Priorität)
- WireGuard-Interface wird für HTTP/HTTPS-Traffic ignoriert
3. **Split Tunneling Configuration**:
- `AllowedIPs = 10.8.0.0/24` limitiert VPN auf internes Netz
- Windows könnte HTTP/HTTPS als "nicht-VPN" klassifizieren
**Versuchte Lösungen** (bisher erfolglos):
- ❌ Interface Metric Adjustment: `Set-NetIPInterface -InterfaceMetric 1`
- ❌ Explicit Route mit Gateway: `route add 10.8.0.0 ... IF 18`
- ❌ Windows Firewall Check
- ❌ WireGuard Reinstallation
**Fehlende Lösung**: DNS Configuration in Client Config
---
## 3. Implementation Strategy
### **OPTION A: DNS Fix (EMPFOHLEN)** 🎯
**Warum diese Option**:
- Einfachste Lösung (eine Zeile in Config)
- Dokumentiert in WIREGUARD-WINDOWS-DNS-FIX.md
- Adressiert wahrscheinlichste Root Cause
- Keine Server-Änderungen nötig
- Geringe Auswirkung auf existierende Clients
**Implementierung**:
#### Schritt 1: Server Status verifizieren
```bash
# SSH zum Server
ssh deploy@michaelschiemer.de
# WireGuard Service prüfen
sudo systemctl status wg-quick@wg0
# Erwartete Ausgabe:
# ● wg-quick@wg0.service - WireGuard via wg-quick(8) for wg0
# Loaded: loaded
# Active: active (exited)
# Interface prüfen
sudo wg show
# Erwartete Ausgabe:
# interface: wg0
# public key: hT3OCWZ6ElX79YdAdexSsZnbWLzRM/5szk+XNEBUaS8=
# private key: (hidden)
# listening port: 51820
```
#### Schritt 2: Client Config mit DNS regenerieren
**Ansible Template Update** (`wireguard-client.conf.j2`):
```ini
[Interface]
PrivateKey = {{ client_private_key.stdout }}
Address = {{ client_ip }}/24
DNS = 10.8.0.1 # ← NEU: VPN-DNS Server
[Peer]
PublicKey = {{ server_public_key_cmd.stdout }}
Endpoint = {{ server_external_ip_content }}:{{ wireguard_port }}
AllowedIPs = {{ allowed_ips }}
PersistentKeepalive = 25
```
**Playbook Ausführen**:
```bash
cd /home/michael/dev/michaelschiemer/deployment/ansible
# Client Config regenerieren (mit DNS)
ansible-playbook -i inventory/production.yml \
playbooks/regenerate-wireguard-client.yml \
-e "client_name=mikepc" \
-e "client_ip=10.8.0.5"
```
#### Schritt 3: Mit Docker Container testen
```bash
# Container-Test für Baseline
ansible-playbook -i inventory/production.yml \
playbooks/test-wireguard-docker-container.yml \
-e "client_name=mikepc"
# Erwartete Ausgabe:
# ✓ Container gestartet
# ✓ WireGuard verbunden
# ✓ Ping zu 10.8.0.1 erfolgreich
# ✓ HTTP Request zu Grafana zeigt VPN IP im Log
```
#### Schritt 4: Windows Client Setup
**Config herunterladen**:
```bash
# Config wird automatisch heruntergeladen nach:
# /home/michael/dev/michaelschiemer/deployment/ansible/wireguard-clients/mikepc.conf
```
**Windows Installation**:
1. WireGuard GUI öffnen
2. "Import tunnel(s) from file"
3. `mikepc.conf` auswählen
4. Tunnel aktivieren
**Verification (PowerShell als Admin)**:
```powershell
# 1. DNS Check - WICHTIG!
Get-DnsClientServerAddress | Select-Object InterfaceAlias, ServerAddresses
# Erwartete Ausgabe:
# InterfaceAlias ServerAddresses
# -------------- ---------------
# WireGuard Tunnel {10.8.0.1} ← VPN DNS!
# 2. DNS Resolution Test
Resolve-DnsName grafana.michaelschiemer.de | Select-Object Name, IPAddress
# Erwartete Ausgabe:
# Name IPAddress
# ---- ---------
# grafana.michaelschiemer.de 10.8.0.1 ← VPN IP, NICHT Public IP!
# 3. Ping Test
ping 10.8.0.1
# Erwartete Ausgabe:
# Reply from 10.8.0.1: bytes=32 time=25ms TTL=64
# 4. HTTP Test (via Browser)
# https://grafana.michaelschiemer.de
# Sollte funktionieren und Traefik Log sollte 10.8.0.5 zeigen
```
#### Schritt 5: Traefik Log Verification
```bash
# SSH zum Server
ssh deploy@michaelschiemer.de
# Traefik Access Log live anzeigen
docker logs -f traefik 2>&1 | grep grafana
# VORHER (falsch):
# 89.246.96.244 - - [Date] "GET /grafana HTTP/2.0" 404
# NACHHER (korrekt):
# 10.8.0.5 - - [Date] "GET /grafana HTTP/2.0" 200
# ↑ VPN IP des Windows Client!
```
**SUCCESS CRITERIA**:
- ✅ DNS resolves `grafana.michaelschiemer.de` zu `10.8.0.1`
- ✅ Traefik Log zeigt VPN IP (`10.8.0.5`) statt Public IP
- ✅ Grafana Dashboard erreichbar ohne 404
- ✅ Ping zu 10.8.0.1 erfolgreich
---
### **OPTION B: Full Tunnel VPN (Fallback)**
**Nur verwenden wenn Option A fehlschlägt!**
**Änderungen**:
```ini
[Peer]
AllowedIPs = 0.0.0.0/0 # ← Ändere von 10.8.0.0/24
# Routet ALLE Traffic durch VPN
```
**Vorteile**:
- Erzwingt VPN-Routing für alle Verbindungen
- Umgeht Windows Routing-Probleme
**Nachteile**:
- ❌ Alle Traffic über VPN (Performance-Impact)
- ❌ Lokales Netzwerk (Drucker, etc.) nicht erreichbar
- ❌ SSH zu Server über Public IP funktioniert nicht mehr
- ❌ Komplexere Firewall-Konfiguration nötig
**Implementierung** (nur wenn nötig):
1. Template `wireguard-client.conf.j2` ändern
2. Server-Firewall für NAT konfigurieren
3. Client regenerieren und testen
---
### **OPTION C: Alternative VPN Software (Letzte Option)**
**Nur wenn Option A und B fehlschlagen!**
**Alternativen**:
- **OpenVPN**: Mature, Windows-freundlich, mehr Overhead
- **Tailscale**: Mesh VPN, einfacher Setup, closed source
- **ZeroTier**: Ähnlich zu Tailscale, eigenes Netzwerk-Paradigma
**Nicht empfohlen weil**:
- WireGuard ist moderner und schneller
- Existing Infrastructure ist gut aufgebaut
- Problem ist wahrscheinlich nur DNS-Konfiguration
- Ansible Automation müsste neu geschrieben werden
---
## 4. Step-by-Step Implementation Guide
### Phase 1: Preparation (5 Minuten)
```bash
# 1. Zum Ansible Verzeichnis navigieren
cd /home/michael/dev/michaelschiemer/deployment/ansible
# 2. Inventory prüfen
cat inventory/production.yml
# 3. Ansible Connectivity Test
ansible -i inventory/production.yml production -m ping
# Erwartete Ausgabe:
# michaelschiemer.de | SUCCESS => {
# "changed": false,
# "ping": "pong"
# }
```
### Phase 2: Template Update (2 Minuten)
```bash
# DNS Zeile zu Client Template hinzufügen
# templates/wireguard-client.conf.j2
# Öffne Template:
nano templates/wireguard-client.conf.j2
# Füge unter [Interface] hinzu:
# DNS = {{ wireguard_server_ip }}
```
**Template-Inhalt** (complete):
```ini
[Interface]
PrivateKey = {{ client_private_key.stdout }}
Address = {{ client_ip }}/24
DNS = {{ wireguard_server_ip }} # ← HINZUFÜGEN
[Peer]
PublicKey = {{ server_public_key_cmd.stdout }}
Endpoint = {{ server_external_ip_content }}:{{ wireguard_port }}
AllowedIPs = {{ allowed_ips }}
PersistentKeepalive = 25
```
### Phase 3: Client Regeneration (3 Minuten)
```bash
# Windows Client neu generieren
ansible-playbook -i inventory/production.yml \
playbooks/regenerate-wireguard-client.yml \
-e "client_name=mikepc" \
-e "client_ip=10.8.0.5"
# Config wird automatisch heruntergeladen nach:
# wireguard-clients/mikepc.conf
# Verify DNS in Config:
cat wireguard-clients/mikepc.conf | grep DNS
# Erwartete Ausgabe:
# DNS = 10.8.0.1
```
### Phase 4: Docker Container Test (5 Minuten)
```bash
# Container-Test durchführen
ansible-playbook -i inventory/production.yml \
playbooks/test-wireguard-docker-container.yml \
-e "client_name=mikepc"
# Playbook führt aus:
# 1. Container Start mit WireGuard
# 2. Ping zu 10.8.0.1
# 3. HTTP Test zu Grafana
# 4. Log Verification
# Check Container Logs:
docker logs wireguard-test-mikepc
# Erwartete Ausgabe:
# [cont-init.d] 10-adduser: exited 0.
# [cont-init.d] 30-config: executing...
# [cont-init.d] 30-config: exited 0.
# [cont-init.d] 99-custom-scripts: executing...
# [cont-init.d] done.
# [services.d] starting services
# [services.d] done.
```
### Phase 5: Windows Client Import (3 Minuten)
**Schritte**:
1. Alte WireGuard Konfiguration entfernen:
- WireGuard GUI öffnen
- Rechtsklick auf "mikepc" Tunnel
- "Remove" auswählen
2. Neue Konfiguration importieren:
- "Import tunnel(s) from file"
- Navigation zu: `\\wsl$\Ubuntu\home\michael\dev\michaelschiemer\deployment\ansible\wireguard-clients\mikepc.conf`
- Import bestätigen
3. Tunnel aktivieren:
- Klick auf "Activate"
### Phase 6: Verification (5 Minuten)
**PowerShell Tests** (als Administrator):
```powershell
# 1. Interface Check
Get-NetAdapter | Where-Object {$_.InterfaceDescription -like "*WireGuard*"}
# Erwartete Ausgabe:
# Name Status MacAddress LinkSpeed
# ---- ------ ---------- ---------
# WireGuard Up 00-00-00-00-00 Gbps
# 2. DNS Configuration Check
Get-DnsClientServerAddress | Where-Object {$_.InterfaceAlias -like "*WireGuard*"}
# Erwartete Ausgabe:
# InterfaceAlias ServerAddresses
# -------------- ---------------
# WireGuard {10.8.0.1}
# 3. DNS Resolution Test
Resolve-DnsName grafana.michaelschiemer.de
# Erwartete Ausgabe:
# Name IPAddress
# ---- ---------
# grafana.michaelschiemer.de 10.8.0.1
# 4. Connectivity Test
Test-NetConnection 10.8.0.1 -Port 443
# Erwartete Ausgabe:
# ComputerName : 10.8.0.1
# RemoteAddress : 10.8.0.1
# RemotePort : 443
# TcpTestSucceeded : True
# 5. Traefik Dashboard Test (Browser)
# https://traefik.michaelschiemer.de
# Username: admin
# Password: [aus .env]
```
**Server-Side Verification**:
```bash
# SSH zum Server
ssh deploy@michaelschiemer.de
# 1. WireGuard Status
sudo wg show
# Erwartete Ausgabe:
# interface: wg0
# public key: hT3OCWZ6ElX79YdAdexSsZnbWLzRM/5szk+XNEBUaS8=
# private key: (hidden)
# listening port: 51820
#
# peer: [mikepc public key]
# endpoint: 89.246.96.244:xxxxx
# allowed ips: 10.8.0.5/32
# latest handshake: X seconds ago
# transfer: X.XX GiB received, X.XX GiB sent
# 2. Traefik Access Log (live)
docker logs -f traefik 2>&1 | grep -E "10\.8\.0\.[0-9]+"
# Erwartete Ausgabe:
# 10.8.0.5 - - [Date] "GET /grafana HTTP/2.0" 200 ...
# ↑ VPN IP sichtbar!
# 3. CoreDNS Logs (falls DNS problematisch)
docker logs coredns 2>&1 | tail -20
```
### Phase 7: Troubleshooting (falls nötig)
**Problem: DNS nicht gesetzt**
```powershell
# Manual DNS Override
Set-DnsClientServerAddress -InterfaceAlias "WireGuard" -ServerAddresses "10.8.0.1"
# Verify
Get-DnsClientServerAddress | Where-Object {$_.InterfaceAlias -like "*WireGuard*"}
```
**Problem: Route nicht aktiv**
```powershell
# Check Routing Table
route print | findstr "10.8.0.0"
# Erwartete Ausgabe:
# 10.8.0.0 255.255.255.0 On-link 10.8.0.5 281
# Falls fehlt, manuell hinzufügen:
route add 10.8.0.0 MASK 255.255.255.0 10.8.0.1 IF [Interface-Index]
```
**Problem: Traffic kommt weiterhin von Public IP**
```bash
# Server: tcpdump auf WireGuard Interface
ssh deploy@michaelschiemer.de
sudo tcpdump -i wg0 -n
# Erwartete Ausgabe beim Browser-Zugriff:
# IP 10.8.0.5.xxxxx > 10.8.0.1.443: Flags [S], seq ...
# ↑ Client IP ↑ Server IP
```
---
## 5. Testing Checklist
### ✅ Server-Side Tests
```bash
# Test 1: Service Running
sudo systemctl status wg-quick@wg0
# Expected: active (exited)
# Test 2: Interface Up
ip addr show wg0
# Expected: inet 10.8.0.1/24 scope global wg0
# Test 3: Firewall Rule
sudo ufw status | grep 51820
# Expected: 51820/udp ALLOW Anywhere
# Test 4: Peer Connected
sudo wg show
# Expected: peer: [client public key]
# latest handshake: < 3 minutes ago
# Test 5: IP Forwarding Enabled
sysctl net.ipv4.ip_forward
# Expected: net.ipv4.ip_forward = 1
# Test 6: NAT Masquerading Active
sudo iptables -t nat -L POSTROUTING -n -v
# Expected: MASQUERADE all -- 0.0.0.0/0 0.0.0.0/0
```
### ✅ Client-Side Tests (Windows)
```powershell
# Test 1: WireGuard Connected
Get-NetAdapter | Where-Object {$_.InterfaceDescription -like "*WireGuard*"}
# Expected: Status = Up
# Test 2: DNS Configured
Get-DnsClientServerAddress -InterfaceAlias "WireGuard"
# Expected: ServerAddresses = {10.8.0.1}
# Test 3: Ping VPN Gateway
ping 10.8.0.1
# Expected: Reply from 10.8.0.1: bytes=32 time<50ms
# Test 4: DNS Resolution
Resolve-DnsName grafana.michaelschiemer.de
# Expected: IPAddress = 10.8.0.1
# Test 5: HTTPS Connectivity
Test-NetConnection 10.8.0.1 -Port 443
# Expected: TcpTestSucceeded = True
# Test 6: Browser Access
# https://grafana.michaelschiemer.de
# Expected: Grafana Dashboard loads (no 404)
# Test 7: Traefik Dashboard Access
# https://traefik.michaelschiemer.de
# Expected: Traefik Dashboard loads (BasicAuth prompt)
```
### ✅ Log Verification
```bash
# Test 1: Traefik Access Log shows VPN IP
ssh deploy@michaelschiemer.de
docker logs traefik 2>&1 | grep -E "10\.8\.0\.[0-9]+" | tail -5
# Expected:
# 10.8.0.5 - - [Date] "GET /grafana HTTP/2.0" 200 ...
# Test 2: CoreDNS Resolution Log
docker logs coredns 2>&1 | grep grafana | tail -5
# Expected:
# [INFO] 10.8.0.5:xxxxx - "A IN grafana.michaelschiemer.de udp 45 false 512"
```
---
## 6. Client Setup Instructions
### Windows Client
**Prerequisites**:
- Windows 10/11
- Administrator Rechte
- WireGuard for Windows installiert
**Setup**:
1. Config generieren lassen (siehe Phase 3)
2. Config importieren (siehe Phase 5)
3. Tunnel aktivieren
4. Tests durchführen (siehe Phase 6)
**Config Location**: `C:\Program Files\WireGuard\Data\Configurations\mikepc.conf`
### Linux Client
**Prerequisites**:
```bash
sudo apt update
sudo apt install wireguard wireguard-tools
```
**Setup**:
```bash
# 1. Config generieren
ansible-playbook -i inventory/production.yml \
playbooks/add-wireguard-client.yml \
-e "client_name=linux-laptop" \
-e "client_ip=10.8.0.10"
# 2. Config kopieren
sudo cp wireguard-clients/linux-laptop.conf /etc/wireguard/wg0.conf
sudo chmod 600 /etc/wireguard/wg0.conf
# 3. Interface starten
sudo wg-quick up wg0
# 4. Bei Bedarf: Auto-Start bei Boot
sudo systemctl enable wg-quick@wg0
# 5. Status prüfen
sudo wg show
# 6. Test
ping 10.8.0.1
curl -k https://grafana.michaelschiemer.de
```
### macOS Client
**Prerequisites**:
```bash
brew install wireguard-tools
```
**Setup**:
1. WireGuard App aus App Store installieren
2. Config importieren (wie Windows)
3. Tunnel aktivieren
### Android/iOS Client
**Setup**:
1. WireGuard App installieren (Play Store/App Store)
2. QR Code scannen:
```bash
# QR Code für mobilen Import generieren
ansible-playbook -i inventory/production.yml \
playbooks/add-wireguard-client.yml \
-e "client_name=android-phone" \
-e "client_ip=10.8.0.15"
# QR Code wird automatisch generiert:
# wireguard-clients/android-phone.conf.png
```
3. In App: "Add Tunnel" → "Create from QR Code"
4. Scannen und aktivieren
---
## 7. Monitoring & Maintenance
### Daily Checks
```bash
# Server Health Check
ssh deploy@michaelschiemer.de 'sudo wg show | grep "latest handshake"'
# Erwartete Ausgabe:
# latest handshake: 2 minutes 30 seconds ago
# latest handshake: 5 minutes 10 seconds ago
```
### Weekly Maintenance
```bash
# 1. Check for security updates
ssh deploy@michaelschiemer.de 'sudo apt update && sudo apt list --upgradable | grep wireguard'
# 2. Review Traefik Logs für VPN Traffic
ssh deploy@michaelschiemer.de \
'docker logs traefik 2>&1 | grep -E "10\.8\.0\.[0-9]+" | wc -l'
# 3. Unused Clients entfernen
# Liste aller Clients mit letztem Handshake
sudo wg show | grep -E "(peer|latest handshake)"
```
### Backup Strategy
```bash
# 1. Server Config Backup
ssh deploy@michaelschiemer.de 'sudo cat /etc/wireguard/wg0.conf' > backup-wg0.conf-$(date +%F)
# 2. Client Configs Backup
tar -czf wireguard-clients-backup-$(date +%F).tar.gz wireguard-clients/
# 3. Ansible Playbooks Backup (via git)
cd /home/michael/dev/michaelschiemer/deployment/ansible
git add playbooks/ templates/ group_vars/
git commit -m "backup: WireGuard configuration $(date +%F)"
```
---
## 8. Troubleshooting Guide
### Problem: Client verbindet nicht
**Symptome**:
- WireGuard Status: "Disconnected"
- Keine Handshake im Server Log
**Diagnose**:
```bash
# Server: Check Firewall
ssh deploy@michaelschiemer.de 'sudo ufw status | grep 51820'
# Server: Check Service
ssh deploy@michaelschiemer.de 'sudo systemctl status wg-quick@wg0'
# Client: Check Config Syntax
# Windows: C:\Program Files\WireGuard\log.txt
# Linux: journalctl -u wg-quick@wg0
```
**Lösungen**:
1. Firewall öffnen: `sudo ufw allow 51820/udp`
2. Service neu starten: `sudo systemctl restart wg-quick@wg0`
3. Config-Syntax prüfen: `sudo wg-quick up wg0` (zeigt Fehler)
### Problem: DNS Resolution schlägt fehl
**Symptome**:
- Ping zu 10.8.0.1 funktioniert ✅
- `Resolve-DnsName grafana.michaelschiemer.de` zeigt Public IP ❌
**Diagnose**:
```powershell
# Check DNS Server
Get-DnsClientServerAddress -InterfaceAlias "WireGuard"
# Expected: ServerAddresses = {10.8.0.1}
# Actual: ServerAddresses = {} (leer)
```
**Lösung**:
```powershell
# Manual DNS Set
Set-DnsClientServerAddress -InterfaceAlias "WireGuard" -ServerAddresses "10.8.0.1"
# Persistent DNS (in Config):
# [Interface]
# DNS = 10.8.0.1 ← Diese Zeile muss vorhanden sein!
```
### Problem: Traefik zeigt weiterhin Public IP
**Symptome**:
- WireGuard verbunden ✅
- DNS resolved zu 10.8.0.1 ✅
- Traefik Log zeigt: `89.246.96.244 - - "GET /grafana ..."` ❌
**Diagnose**:
```powershell
# Routing Table Check
route print | findstr "10.8.0.0"
# Interface Metric Check
Get-NetIPInterface | Where-Object {$_.AddressFamily -eq "IPv4"} | Sort-Object InterfaceMetric
```
**Lösung**:
```powershell
# Option 1: Interface Metric senken
$WgIndex = (Get-NetAdapter | Where-Object {$_.InterfaceDescription -like "*WireGuard*"}).ifIndex
Set-NetIPInterface -InterfaceIndex $WgIndex -InterfaceMetric 1
# Option 2: Explicit Route mit niedrigem Metric
route add 10.8.0.0 MASK 255.255.255.0 10.8.0.1 METRIC 1 IF $WgIndex
# Verify
route print | findstr "10.8.0.0"
```
### Problem: Handshake schlägt fehl
**Symptome**:
- Server Log: `latest handshake: never`
- Client bleibt auf "Connecting"
**Diagnose**:
```bash
# Server: tcpdump auf Port 51820
ssh deploy@michaelschiemer.de
sudo tcpdump -i any -n port 51820
# Erwartete Ausgabe:
# IP [client-public-ip].xxxxx > 94.16.110.151.51820: UDP
```
**Lösungen**:
1. **Firewall Issue**:
```bash
sudo ufw allow 51820/udp
sudo ufw reload
```
2. **NAT Issue** (Client hinter Router):
- Router-Firewall prüfen
- Port Forwarding nicht nötig (ausgehend)
- PersistentKeepalive erhöhen: `PersistentKeepalive = 25`
3. **Clock Skew Issue**:
```bash
# Server: Zeit prüfen
ssh deploy@michaelschiemer.de 'date'
# Client: Zeit prüfen
date # Linux/macOS
Get-Date # Windows
# Bei Abweichung: NTP sync
sudo ntpdate pool.ntp.org
```
### Problem: Peer-to-Peer nicht möglich
**Symptome**:
- Ping zu 10.8.0.1 funktioniert ✅
- Ping zu anderem Client (z.B. 10.8.0.10) schlägt fehl ❌
**Root Cause**:
- AllowedIPs limitiert auf Server IP nur
**Lösung**:
```ini
# Server Config ändern (/etc/wireguard/wg0.conf)
[Peer]
# For client 10.8.0.5
PublicKey = [client-public-key]
AllowedIPs = 10.8.0.5/32, 10.8.0.0/24 # ← Network hinzufügen
# Restart
sudo wg-quick down wg0
sudo wg-quick up wg0
```
---
## 9. Performance Optimization
### Server-Side Tuning
```bash
# /etc/sysctl.conf
net.ipv4.ip_forward = 1
net.core.default_qdisc = fq
net.ipv4.tcp_congestion_control = bbr
net.core.rmem_max = 2500000
net.core.wmem_max = 2500000
# Apply
sudo sysctl -p
```
### Client-Side Tuning (Windows)
```powershell
# MTU Optimization
netsh interface ipv4 set subinterface "WireGuard" mtu=1420 store=persistent
# Registry Tweaks (optional)
# HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters
# - TcpAckFrequency = 1
# - TCPNoDelay = 1
```
---
## 10. Security Hardening
### Key Rotation Policy
**Empfehlung**: Keys alle 6 Monate rotieren
```bash
# 1. Neuen Client mit neuen Keys generieren
ansible-playbook -i inventory/production.yml \
playbooks/regenerate-wireguard-client.yml \
-e "client_name=mikepc" \
-e "client_ip=10.8.0.5"
# 2. Alte Config entfernen (nach Verification)
# Server: /etc/wireguard/wg0.conf - alten Peer-Block löschen
# 3. Server neu starten
ssh deploy@michaelschiemer.de 'sudo wg-quick down wg0 && sudo wg-quick up wg0'
```
### Access Logging
**Traefik Access Log für VPN-Only Services**:
```yaml
# docker-compose.yml (bereits konfiguriert)
services:
traefik:
command:
- --accesslog=true
- --accesslog.filepath=/var/log/traefik/access.log
- --accesslog.filters.statusCodes=200,404,403
```
**Log Analysis**:
```bash
# Daily Report: VPN Zugriffe
ssh deploy@michaelschiemer.de \
'docker exec traefik cat /var/log/traefik/access.log | grep -E "10\.8\.0\.[0-9]+" | tail -20'
# Weekly Report: Failed Auth Attempts
ssh deploy@michaelschiemer.de \
'docker exec traefik cat /var/log/traefik/access.log | grep "401\|403" | wc -l'
```
### Fail2Ban Integration (Optional)
```bash
# /etc/fail2ban/filter.d/wireguard.conf
[Definition]
failregex = Invalid handshake from <HOST>
ignoreregex =
# /etc/fail2ban/jail.local
[wireguard]
enabled = true
port = 51820
protocol = udp
filter = wireguard
logpath = /var/log/syslog
maxretry = 5
bantime = 3600
```
---
## 11. Migration Path (Falls Option A fehlschlägt)
### Plan B: Full Tunnel VPN
**Nur wenn DNS-Fix nicht funktioniert!**
**Changes Required**:
1. **Client Config Template Update**:
```ini
[Peer]
AllowedIPs = 0.0.0.0/0, ::/0 # ← Ändere von 10.8.0.0/24
```
2. **Server NAT Configuration**:
```bash
# /etc/wireguard/wg0.conf
PostUp = iptables -A FORWARD -i %i -j ACCEPT; \
iptables -A FORWARD -o %i -j ACCEPT; \
iptables -t nat -A POSTROUTING -o ens3 -j MASQUERADE
PostDown = iptables -D FORWARD -i %i -j ACCEPT; \
iptables -D FORWARD -o %i -j ACCEPT; \
iptables -t nat -D POSTROUTING -o ens3 -j MASQUERADE
```
3. **Split Tunneling Exceptions** (für lokales Netzwerk):
```powershell
# Windows: Route für lokales Netz außerhalb VPN
route add 192.168.0.0 MASK 255.255.255.0 192.168.0.1 METRIC 1
```
**Trade-offs**:
- ✅ Pro: Forciert VPN für alle Verbindungen
- ❌ Con: Performance-Impact (alle Traffic durch VPN)
- ❌ Con: Lokales Netzwerk (Drucker, NAS) nicht direkt erreichbar
- ❌ Con: SSH zu Server nur über VPN möglich
---
## 12. Next Steps
### Immediate Actions (Nächste 30 Minuten)
1. ✅ **Template Update**:
```bash
nano /home/michael/dev/michaelschiemer/deployment/ansible/templates/wireguard-client.conf.j2
# DNS = {{ wireguard_server_ip }} hinzufügen
```
2. ✅ **Client Regeneration**:
```bash
cd /home/michael/dev/michaelschiemer/deployment/ansible
ansible-playbook -i inventory/production.yml \
playbooks/regenerate-wireguard-client.yml \
-e "client_name=mikepc" \
-e "client_ip=10.8.0.5"
```
3. ✅ **Docker Test**:
```bash
ansible-playbook -i inventory/production.yml \
playbooks/test-wireguard-docker-container.yml \
-e "client_name=mikepc"
```
4. ✅ **Windows Import**:
- Config importieren
- Tunnel aktivieren
- Tests durchführen
### Short-Term (Nächste Woche)
1. ✅ Alle existierenden Clients mit DNS-Config aktualisieren
2. ✅ Monitoring Setup für WireGuard Handshakes
3. ✅ Backup-Strategie implementieren
4. ✅ Dokumentation in Wiki übertragen
### Long-Term (Nächster Monat)
1. ✅ Key Rotation Policy dokumentieren und schedulen
2. ✅ Fail2Ban Integration evaluieren
3. ✅ Performance Tuning basierend auf Logs
4. ✅ Mobile Clients für Admin Team einrichten
---
## 13. Success Metrics
### KPIs für erfolgreiche Implementation
| Metric | Target | Current | Status |
|--------|--------|---------|--------|
| VPN Handshake Success Rate | >99% | TBD | 🟡 |
| DNS Resolution zu VPN IP | 100% | TBD | 🟡 |
| Traefik Log zeigt VPN IP | 100% | 0% | 🔴 |
| Grafana Erreichbarkeit | 100% | TBD | 🟡 |
| Latenz zu 10.8.0.1 | <50ms | TBD | 🟡 |
| Client Setup Time | <10min | TBD | 🟡 |
**Update nach Implementation**: Metrics werden nach Phase 6 aktualisiert.
---
## 14. Risk Assessment
### Risks & Mitigation
| Risk | Probability | Impact | Mitigation |
|------|------------|--------|------------|
| DNS-Fix löst Problem nicht | Low | Medium | Plan B: Full Tunnel VPN |
| Windows Routing weiterhin problematisch | Medium | High | Plan C: OpenVPN als Fallback |
| Existing Clients brechen | Low | Low | Backup Configs vorhanden |
| Performance Degradation | Low | Medium | Performance Monitoring, Tuning |
| Security Incident | Very Low | High | Key Rotation, Access Logging, Fail2Ban |
### Rollback Plan
**Falls Implementation fehlschlägt**:
1. **Clients zurücksetzen**:
```bash
# Restore old config
cp wireguard-clients/mikepc.conf.backup-[timestamp] \
wireguard-clients/mikepc.conf
```
2. **Template zurücksetzen**:
```bash
git checkout templates/wireguard-client.conf.j2
```
3. **Server unverändert**: Keine Server-Änderungen nötig für Option A
**Rollback Time**: <5 Minuten
---
## 15. Contacts & Support
### Internal Contacts
**Primary Admin**: michael@michaelschiemer.de
**Server**: michaelschiemer.de (94.16.110.151)
**SSH User**: deploy
**Ansible Location**: `/home/michael/dev/michaelschiemer/deployment/ansible`
### External Resources
- **WireGuard Docs**: https://www.wireguard.com/quickstart/
- **Ansible WireGuard Module**: https://galaxy.ansible.com/githubixx/ansible_role_wireguard
- **Windows Troubleshooting**: https://www.wireguard.com/known-limitations/
### Support Channels
- **GitHub Issues**: (Falls applicable)
- **WireGuard Mailing List**: wireguard@lists.zx2c4.com
---
## Appendix: Quick Reference
### Useful Commands
```bash
# Server Status
ssh deploy@michaelschiemer.de 'sudo wg show'
# Client Generation
ansible-playbook -i inventory/production.yml playbooks/add-wireguard-client.yml \
-e "client_name=NEW_CLIENT" -e "client_ip=10.8.0.X"
# Container Test
ansible-playbook -i inventory/production.yml playbooks/test-wireguard-docker-container.yml \
-e "client_name=CLIENT"
# Log Monitoring
ssh deploy@michaelschiemer.de 'docker logs -f traefik 2>&1 | grep -E "10\.8\.0\.[0-9]+"'
# Client Regeneration
ansible-playbook -i inventory/production.yml playbooks/regenerate-wireguard-client.yml \
-e "client_name=CLIENT" -e "client_ip=10.8.0.X"
```
### Config Locations
- **Server Config**: `/etc/wireguard/wg0.conf`
- **Client Configs**: `/home/michael/dev/michaelschiemer/deployment/ansible/wireguard-clients/`
- **Templates**: `/home/michael/dev/michaelschiemer/deployment/ansible/templates/`
- **Windows Config**: `C:\Program Files\WireGuard\Data\Configurations\`
- **Linux Config**: `/etc/wireguard/wg0.conf`
### IP Allocation
| IP Address | Hostname | Client | Status |
|------------|----------|--------|--------|
| 10.8.0.1 | michaelschiemer.de | Server | Active |
| 10.8.0.5 | mikepc | Windows Client | Pending |
| 10.8.0.7 | grafana-test | Test Client | Unknown |
| 10.8.0.10-254 | - | Available | Free |
---
**Plan Status**: ✅ READY FOR IMPLEMENTATION
**Empfohlene Option**: Option A (DNS Fix)
**Estimated Implementation Time**: 30 Minuten
**Rollback Risk**: LOW
**Success Probability**: HIGH (>80%)
---
**Ende des Implementierungsplans**
**Nächster Schritt**: Template Update (Phase 2) durchführen und Client regenerieren (Phase 3).