From 7b7f0b41d250d37b8548b7405932b70bf43b1c7e Mon Sep 17 00:00:00 2001 From: Michael Schiemer Date: Sun, 2 Nov 2025 18:10:04 +0100 Subject: [PATCH] chore: update VPN routing configuration and add Grafana VPN documentation --- deployment/ansible/.gitignore | 2 + deployment/ansible/group_vars/production.yml | 4 + .../playbooks/check-after-grafana-access.yml | 78 +++++++ .../playbooks/check-grafana-after-test.yml | 68 ++++++ .../playbooks/check-latest-grafana-access.yml | 55 +++++ .../playbooks/check-vpn-routing-status.yml | 63 ++++++ .../playbooks/check-vpn-test-from-client.yml | 116 ++++++++++ .../playbooks/fix-grafana-vpn-routing.yml | 80 +++++++ .../playbooks/monitor-grafana-access-live.yml | 95 ++++++++ .../playbooks/monitor-grafana-client-ip.yml | 75 +++++++ .../playbooks/monitor-grafana-live-now.yml | 80 +++++++ .../monitor-grafana-live-with-firewall.yml | 86 ++++++++ .../playbooks/monitor-live-grafana-access.yml | 70 ++++++ .../playbooks/regenerate-wireguard-client.yml | 205 ++++++++++++++++++ .../playbooks/remove-temporary-grafana-ip.yml | 119 ++++++++++ .../ansible/playbooks/setup-wireguard.yml | 6 +- .../playbooks/test-grafana-vpn-access.yml | 99 +++++++++ .../playbooks/test-grafana-vpn-final.yml | 78 +++++++ .../test-wireguard-docker-container.yml | 168 ++++++++++++++ deployment/ansible/test-vpn-connection.sh | 78 +++++++ .../wireguard-clients/grafana-test.conf | 2 +- .../stacks/traefik/dynamic/middlewares.yml | 7 +- docs/deployment/GRAFANA-VPN-NEXT-STEPS.md | 125 +++++++++++ docs/deployment/GRAFANA-VPN-SECURITY-PLAN.md | 149 +++++++++++++ docs/deployment/VPN-ROUTING-FINAL-FIX.md | 91 ++++++++ docs/deployment/VPN-ROUTING-FIX-DETAILED.md | 100 +++++++++ docs/deployment/VPN-ROUTING-FIX-GUIDE.md | 143 ++++++++++++ .../VPN-ROUTING-PROBLEM-ANALYSIS.md | 120 ++++++++++ docs/deployment/WIREGUARD-NEW-CONFIG-READY.md | 123 +++++++++++ .../deployment/WIREGUARD-RECREATE-AND-TEST.md | 176 +++++++++++++++ .../WIREGUARD-WINDOWS-CONFIG-EXAMPLE.md | 48 ++++ docs/deployment/WIREGUARD-WINDOWS-DNS-FIX.md | 141 ++++++++++++ .../WIREGUARD-WINDOWS-DNS-PRIORITY-FIX.md | 108 +++++++++ .../WIREGUARD-WINDOWS-FIREWALL-CHECK.md | 186 ++++++++++++++++ .../WIREGUARD-WINDOWS-FIREWALL-SCRIPT.ps1 | 139 ++++++++++++ .../WIREGUARD-WINDOWS-INTERFACE-METRIC-FIX.md | 63 ++++++ .../deployment/WIREGUARD-WINDOWS-ROUTE-FIX.md | 103 +++++++++ .../WIREGUARD-WINDOWS-ROUTE-GATEWAY-FIX.md | 176 +++++++++++++++ ...IREGUARD-WINDOWS-ROUTING-FINAL-ANALYSIS.md | 109 ++++++++++ .../Config/TypedConfigInitializer.php | 3 +- src/Framework/Core/AppBootstrapper.php | 1 - 41 files changed, 3727 insertions(+), 11 deletions(-) create mode 100644 deployment/ansible/.gitignore create mode 100644 deployment/ansible/playbooks/check-after-grafana-access.yml create mode 100644 deployment/ansible/playbooks/check-grafana-after-test.yml create mode 100644 deployment/ansible/playbooks/check-latest-grafana-access.yml create mode 100644 deployment/ansible/playbooks/check-vpn-routing-status.yml create mode 100644 deployment/ansible/playbooks/check-vpn-test-from-client.yml create mode 100644 deployment/ansible/playbooks/fix-grafana-vpn-routing.yml create mode 100644 deployment/ansible/playbooks/monitor-grafana-access-live.yml create mode 100644 deployment/ansible/playbooks/monitor-grafana-client-ip.yml create mode 100644 deployment/ansible/playbooks/monitor-grafana-live-now.yml create mode 100644 deployment/ansible/playbooks/monitor-grafana-live-with-firewall.yml create mode 100644 deployment/ansible/playbooks/monitor-live-grafana-access.yml create mode 100644 deployment/ansible/playbooks/regenerate-wireguard-client.yml create mode 100644 deployment/ansible/playbooks/remove-temporary-grafana-ip.yml create mode 100644 deployment/ansible/playbooks/test-grafana-vpn-access.yml create mode 100644 deployment/ansible/playbooks/test-grafana-vpn-final.yml create mode 100644 deployment/ansible/playbooks/test-wireguard-docker-container.yml create mode 100755 deployment/ansible/test-vpn-connection.sh create mode 100644 docs/deployment/GRAFANA-VPN-NEXT-STEPS.md create mode 100644 docs/deployment/GRAFANA-VPN-SECURITY-PLAN.md create mode 100644 docs/deployment/VPN-ROUTING-FINAL-FIX.md create mode 100644 docs/deployment/VPN-ROUTING-FIX-DETAILED.md create mode 100644 docs/deployment/VPN-ROUTING-FIX-GUIDE.md create mode 100644 docs/deployment/VPN-ROUTING-PROBLEM-ANALYSIS.md create mode 100644 docs/deployment/WIREGUARD-NEW-CONFIG-READY.md create mode 100644 docs/deployment/WIREGUARD-RECREATE-AND-TEST.md create mode 100644 docs/deployment/WIREGUARD-WINDOWS-CONFIG-EXAMPLE.md create mode 100644 docs/deployment/WIREGUARD-WINDOWS-DNS-FIX.md create mode 100644 docs/deployment/WIREGUARD-WINDOWS-DNS-PRIORITY-FIX.md create mode 100644 docs/deployment/WIREGUARD-WINDOWS-FIREWALL-CHECK.md create mode 100644 docs/deployment/WIREGUARD-WINDOWS-FIREWALL-SCRIPT.ps1 create mode 100644 docs/deployment/WIREGUARD-WINDOWS-INTERFACE-METRIC-FIX.md create mode 100644 docs/deployment/WIREGUARD-WINDOWS-ROUTE-FIX.md create mode 100644 docs/deployment/WIREGUARD-WINDOWS-ROUTE-GATEWAY-FIX.md create mode 100644 docs/deployment/WIREGUARD-WINDOWS-ROUTING-FINAL-ANALYSIS.md diff --git a/deployment/ansible/.gitignore b/deployment/ansible/.gitignore new file mode 100644 index 00000000..c948b9bc --- /dev/null +++ b/deployment/ansible/.gitignore @@ -0,0 +1,2 @@ +# Ansible temporary directory +.ansible/ diff --git a/deployment/ansible/group_vars/production.yml b/deployment/ansible/group_vars/production.yml index 2e420256..a919bc3c 100644 --- a/deployment/ansible/group_vars/production.yml +++ b/deployment/ansible/group_vars/production.yml @@ -81,3 +81,7 @@ wireguard_port_default: 51820 wireguard_network_default: "10.8.0.0/24" wireguard_server_ip_default: "10.8.0.1" wireguard_enable_ip_forwarding: true +wireguard_config_file: "{{ wireguard_config_path }}/{{ wireguard_interface }}.conf" +wireguard_private_key_file: "{{ wireguard_config_path }}/{{ wireguard_interface }}_private.key" +wireguard_public_key_file: "{{ wireguard_config_path }}/{{ wireguard_interface }}_public.key" +wireguard_client_configs_path: "{{ wireguard_config_path }}/clients" diff --git a/deployment/ansible/playbooks/check-after-grafana-access.yml b/deployment/ansible/playbooks/check-after-grafana-access.yml new file mode 100644 index 00000000..a3b49ded --- /dev/null +++ b/deployment/ansible/playbooks/check-after-grafana-access.yml @@ -0,0 +1,78 @@ +--- +- name: Check Traefik Logs After Grafana Access + hosts: production + gather_facts: no + become: no + + tasks: + - name: Instructions + debug: + msg: + - "=== ANWEISUNG ===" + - "Bitte mache JETZT einen Zugriff auf https://grafana.michaelschiemer.de im Browser" + - "Dann pr?fe ich die Logs und sage dir, ob Traffic ?ber VPN kommt" + - "" + + - name: Wait for access + pause: + seconds: 15 + + - name: Get last 20 Grafana requests + shell: | + cd ~/deployment/stacks/traefik + tail -500 logs/access.log | grep -i grafana | tail -20 + args: + executable: /bin/bash + register: recent_grafana_logs + ignore_errors: yes + failed_when: false + + - name: Extract and display client IPs with timestamps + shell: | + cd ~/deployment/stacks/traefik + tail -100 logs/access.log | grep -i grafana | tail -10 | while IFS= read -r line; do + time=$(echo "$line" | grep -oP '"time":"[^"]*"' | sed 's/"time":"//;s/"//' | cut -d'T' -f2 | cut -d'+' -f1) + client=$(echo "$line" | grep -oP '"ClientHost":"[^"]*"' | sed 's/"ClientHost":"//;s/"//') + status=$(echo "$line" | grep -oP '"DownstreamStatus":[0-9]+' | sed 's/"DownstreamStatus"://') + if [[ "$client" =~ ^10\.8\.0\.[0-9]+$ ]]; then + echo "$time | ClientHost: $client | Status: $status ? VPN-IP (Traffic kommt ?ber VPN!)" + elif [[ "$client" == "89.246.96.244" ]]; then + echo "$time | ClientHost: $client | Status: $status ? ?ffentliche IP (Traffic kommt NICHT ?ber VPN)" + else + echo "$time | ClientHost: $client | Status: $status ? Unbekannte IP" + fi + done + args: + executable: /bin/bash + register: analysis_result + ignore_errors: yes + failed_when: false + + - name: Display analysis + debug: + msg: "{{ analysis_result.stdout_lines }}" + + - name: Get unique client IPs from last 10 requests + shell: | + cd ~/deployment/stacks/traefik + tail -100 logs/access.log | grep -i grafana | tail -10 | grep -oP '"ClientHost":"[^"]*"' | sed 's/"ClientHost":"//;s/"//' | sort -u + args: + executable: /bin/bash + register: unique_ips + ignore_errors: yes + failed_when: false + + - name: Display unique IPs + debug: + msg: "{{ unique_ips.stdout_lines }}" + + - name: Final verdict + debug: + msg: + - "" + - "=== ERGEBNIS ===" + - "Pr?fe die obigen Zeilen:" + - "- ? Wenn ClientHost: 10.8.0.7 ? Traffic kommt ?ber VPN!" + - "- ? Wenn ClientHost: 89.246.96.244 ? Traffic kommt NICHT ?ber VPN" + - "" + - "N?chster Schritt: Wenn VPN funktioniert, entfernen wir die tempor?re IP-Erlaubnis!" diff --git a/deployment/ansible/playbooks/check-grafana-after-test.yml b/deployment/ansible/playbooks/check-grafana-after-test.yml new file mode 100644 index 00000000..fa7c0c79 --- /dev/null +++ b/deployment/ansible/playbooks/check-grafana-after-test.yml @@ -0,0 +1,68 @@ +--- +- name: Check Grafana Logs After Test + hosts: production + gather_facts: no + become: no + + tasks: + - name: Check last 20 Grafana access attempts + shell: | + cd ~/deployment/stacks/traefik + tail -200 logs/access.log | grep -i grafana | tail -20 + args: + executable: /bin/bash + register: latest_logs + ignore_errors: yes + failed_when: false + + - name: Extract client IPs with timestamps + shell: | + cd ~/deployment/stacks/traefik + tail -100 logs/access.log | grep -i grafana | tail -10 | while IFS= read -r line; do + time=$(echo "$line" | grep -oP '"time":"[^"]*"' | sed 's/"time":"//;s/"//' | cut -d'T' -f2 | cut -d'+' -f1) + client=$(echo "$line" | grep -oP '"ClientHost":"[^"]*"' | sed 's/"ClientHost":"//;s/"//') + status=$(echo "$line" | grep -oP '"DownstreamStatus":[0-9]+' | sed 's/"DownstreamStatus"://') + if [[ "$client" =~ ^10\.8\.0\.[0-9]+$ ]]; then + echo "$time | ClientHost: $client | Status: $status ? VPN-IP (Traffic kommt ?ber VPN!)" + elif [[ "$client" == "89.246.96.244" ]]; then + echo "$time | ClientHost: $client | Status: $status ? ?ffentliche IP (Traffic kommt NICHT ?ber VPN)" + else + echo "$time | ClientHost: $client | Status: $status ? Unbekannt" + fi + done + args: + executable: /bin/bash + register: analysis + ignore_errors: yes + failed_when: false + + - name: Display analysis + debug: + msg: "{{ analysis.stdout_lines }}" + + - name: Get unique client IPs + shell: | + cd ~/deployment/stacks/traefik + tail -100 logs/access.log | grep -i grafana | tail -10 | grep -oP '"ClientHost":"[^"]*"' | sed 's/"ClientHost":"//;s/"//' | sort -u + args: + executable: /bin/bash + register: unique_ips + ignore_errors: yes + failed_when: false + + - name: Display unique IPs + debug: + msg: "{{ unique_ips.stdout_lines }}" + + - name: Final result + debug: + msg: + - "" + - "=== ERGEBNIS ===" + - "Pr?fe die obigen Zeilen:" + - "" + - "? Wenn ClientHost: 10.8.0.7 ? Traffic kommt ?ber VPN!" + - " ? Dann k?nnen wir die tempor?re IP-Erlaubnis entfernen!" + - "" + - "? Wenn ClientHost: 89.246.96.244 ? Traffic kommt NICHT ?ber VPN" + - " ? Dann m?ssen wir weiter debuggen" diff --git a/deployment/ansible/playbooks/check-latest-grafana-access.yml b/deployment/ansible/playbooks/check-latest-grafana-access.yml new file mode 100644 index 00000000..13693f2e --- /dev/null +++ b/deployment/ansible/playbooks/check-latest-grafana-access.yml @@ -0,0 +1,55 @@ +--- +- name: Check Latest Grafana Access - Client IP Analysis + hosts: production + gather_facts: no + become: no + + tasks: + - name: Get latest Grafana access logs + shell: | + cd ~/deployment/stacks/traefik + echo "=== Latest 5 Grafana Access Logs ===" + tail -100 logs/access.log | grep -i grafana | tail -5 + args: + executable: /bin/bash + register: latest_logs + ignore_errors: yes + failed_when: false + + - name: Extract client IPs from latest logs + shell: | + cd ~/deployment/stacks/traefik + tail -50 logs/access.log | grep -i grafana | tail -10 | grep -oP '"ClientHost":"[^"]*"' | sed 's/"ClientHost":"//;s/"//' | sort -u + args: + executable: /bin/bash + register: client_ips + ignore_errors: yes + failed_when: false + + - name: Display latest logs + debug: + msg: "{{ latest_logs.stdout_lines }}" + + - name: Display client IPs + debug: + msg: "{{ client_ips.stdout_lines }}" + + - name: Analyze if traffic comes from VPN + shell: | + cd ~/deployment/stacks/traefik + if tail -20 logs/access.log | grep -i grafana | tail -5 | grep -oP '"ClientHost":"[^"]*"' | grep -q "10.8.0"; then + echo "? Traffic kommt ?ber VPN! (ClientHost: 10.8.0.x)" + elif tail -20 logs/access.log | grep -i grafana | tail -5 | grep -oP '"ClientHost":"[^"]*"' | grep -q "89.246.96.244"; then + echo "? Traffic kommt NICHT ?ber VPN (ClientHost: 89.246.96.244 - ?ffentliche IP)" + else + echo "?? Keine aktuellen Grafana-Logs gefunden. Bitte mache einen Zugriff auf https://grafana.michaelschiemer.de" + fi + args: + executable: /bin/bash + register: analysis + ignore_errors: yes + failed_when: false + + - name: Display analysis + debug: + msg: "{{ analysis.stdout_lines }}" diff --git a/deployment/ansible/playbooks/check-vpn-routing-status.yml b/deployment/ansible/playbooks/check-vpn-routing-status.yml new file mode 100644 index 00000000..e0e9c06d --- /dev/null +++ b/deployment/ansible/playbooks/check-vpn-routing-status.yml @@ -0,0 +1,63 @@ +--- +- name: Check VPN Routing Status - Client-Side Diagnostics + hosts: production + gather_facts: no + become: no + + tasks: + - name: Instructions for client-side DNS check + debug: + msg: + - "=== CLIENT-SIDE DNS CHECK ===" + - "Bitte f?hre diese Befehle auf deinem Client-System aus (nicht auf dem Server):" + - "" + - "1. Pr?fe aktive DNS-Server:" + - " Linux/Mac: cat /etc/resolv.conf" + - " Windows: Get-DnsClientServerAddress | Select-Object InterfaceAlias, ServerAddresses" + - "" + - "2. Teste DNS-Aufl?sung:" + - " dig +short grafana.michaelschiemer.de" + - " Oder: nslookup grafana.michaelschiemer.de" + - "" + - "3. Teste DNS-Aufl?sung ?ber VPN-DNS:" + - " dig +short grafana.michaelschiemer.de @10.8.0.1" + - " Sollte zur?ckgeben: 10.8.0.1" + - "" + - "4. Pr?fe WireGuard Config:" + - " ?ffne deine WireGuard-Config und pr?fe:" + - " [Interface]" + - " DNS = 10.8.0.1" + - "" + - "Teile mir die Ergebnisse mit, dann kann ich dir helfen, das zu fixen!" + + - name: Check server-side WireGuard configuration + shell: | + echo "=== Server-Side WireGuard Config ===" + sudo cat /etc/wireguard/wg0.conf | grep -A 5 "\[Interface\]" | head -10 + args: + executable: /bin/bash + register: wg_server_config + ignore_errors: yes + failed_when: false + + - name: Display server-side WireGuard config + debug: + msg: "{{ wg_server_config.stdout_lines }}" + + - name: Check server-side DNS resolution + shell: | + echo "=== Server-Side DNS Tests ===" + echo "1. Grafana via VPN DNS (10.8.0.1):" + dig +short grafana.michaelschiemer.de @10.8.0.1 2>&1 || echo "Failed" + echo "" + echo "2. Grafana via public DNS (8.8.8.8):" + dig +short grafana.michaelschiemer.de @8.8.8.8 2>&1 || echo "Failed" + args: + executable: /bin/bash + register: server_dns + ignore_errors: yes + failed_when: false + + - name: Display server-side DNS tests + debug: + msg: "{{ server_dns.stdout_lines }}" diff --git a/deployment/ansible/playbooks/check-vpn-test-from-client.yml b/deployment/ansible/playbooks/check-vpn-test-from-client.yml new file mode 100644 index 00000000..7ebbaaae --- /dev/null +++ b/deployment/ansible/playbooks/check-vpn-test-from-client.yml @@ -0,0 +1,116 @@ +--- +- name: Check VPN Test Results from Client + hosts: production + gather_facts: no + become: no + + tasks: + - name: Check latest Grafana access attempts + shell: | + cd ~/deployment/stacks/traefik + echo "=== Last 20 Grafana Access Attempts ===" + tail -500 logs/access.log | grep -i grafana | tail -20 | while IFS= read -r line; do + time=$(echo "$line" | grep -oP '"time":"[^"]*"' | sed 's/"time":"//;s/"//' | cut -d'T' -f2 | cut -d'+' -f1 | cut -d':' -f1-2) + client=$(echo "$line" | grep -oP '"ClientHost":"[^"]*"' | sed 's/"ClientHost":"//;s/"//') + status=$(echo "$line" | grep -oP '"DownstreamStatus":[0-9]+' | sed 's/"DownstreamStatus"://') + method=$(echo "$line" | grep -oP '"RequestMethod":"[^"]*"' | sed 's/"RequestMethod":"//;s/"//') + path=$(echo "$line" | grep -oP '"RequestPath":"[^"]*"' | sed 's/"RequestPath":"//;s/"//') + + if [[ "$client" =~ ^10\.8\.0\.[0-9]+$ ]]; then + echo "? $time | ClientHost: $client | Status: $status | $method $path ? VPN-IP (Traffic kommt ?ber VPN!)" + elif [[ "$client" == "89.246.96.244" ]]; then + echo "? $time | ClientHost: $client | Status: $status | $method $path ? ?ffentliche IP (Traffic kommt NICHT ?ber VPN)" + else + echo "? $time | ClientHost: $client | Status: $status | $method $path ? Unbekannt" + fi + done + args: + executable: /bin/bash + register: recent_access + ignore_errors: yes + failed_when: false + + - name: Display recent access attempts + debug: + msg: "{{ recent_access.stdout_lines }}" + + - name: Extract unique client IPs from recent requests + shell: | + cd ~/deployment/stacks/traefik + tail -100 logs/access.log | grep -i grafana | tail -20 | grep -oP '"ClientHost":"[^"]*"' | sed 's/"ClientHost":"//;s/"//' | sort -u + args: + executable: /bin/bash + register: unique_ips + ignore_errors: yes + failed_when: false + + - name: Display unique client IPs + debug: + msg: "{{ unique_ips.stdout_lines }}" + + - name: Analyze client IP distribution + shell: | + cd ~/deployment/stacks/traefik + echo "=== Client IP Analysis (Last 20 requests) ===" + VPN_COUNT=$(tail -100 logs/access.log | grep -i grafana | tail -20 | grep -oP '"ClientHost":"10\.8\.0\.[0-9]+"' | wc -l) + PUBLIC_COUNT=$(tail -100 logs/access.log | grep -i grafana | tail -20 | grep -oP '"ClientHost":"89\.246\.96\.244"' | wc -l) + TOTAL=$(tail -100 logs/access.log | grep -i grafana | tail -20 | wc -l) + + echo "Total Grafana requests (last 20): $TOTAL" + echo "VPN IP requests (10.8.0.x): $VPN_COUNT" + echo "Public IP requests (89.246.96.244): $PUBLIC_COUNT" + + if [ "$VPN_COUNT" -gt 0 ]; then + echo "" + echo "? SUCCESS: Traffic is coming through VPN!" + echo " $VPN_COUNT out of $TOTAL requests used VPN IP" + elif [ "$PUBLIC_COUNT" -gt 0 ]; then + echo "" + echo "? PROBLEM: Traffic is NOT coming through VPN" + echo " $PUBLIC_COUNT out of $TOTAL requests used public IP" + echo " Check VPN routing configuration on client" + else + echo "" + echo "?? No recent Grafana requests found" + fi + args: + executable: /bin/bash + register: ip_analysis + ignore_errors: yes + failed_when: false + + - name: Display IP analysis + debug: + msg: "{{ ip_analysis.stdout_lines }}" + + - name: Check WireGuard peer status for test-client + shell: | + echo "=== WireGuard Peer Status ===" + sudo wg show | grep -A 5 "YbjBipkOHjLfcIYQKDReJ1swseczqHolTCRv7+LHnmw=" || echo "Peer not found or not connected" + args: + executable: /bin/bash + register: wg_peer_status + ignore_errors: yes + failed_when: false + + - name: Display WireGuard peer status + debug: + msg: "{{ wg_peer_status.stdout_lines }}" + + - name: Final recommendations + debug: + msg: + - "" + - "=== ERGEBNIS ===" + - "" + - "Pr?fe die obigen Zeilen:" + - "" + - "? Wenn ClientHost: 10.8.0.x ? Traffic kommt ?ber VPN!" + - " ? Dann k?nnen wir die tempor?re IP-Erlaubnis entfernen!" + - "" + - "? Wenn ClientHost: 89.246.96.244 ? Traffic kommt NICHT ?ber VPN" + - " ? Dann m?ssen wir das VPN-Routing auf dem Client pr?fen" + - "" + - "N?chste Schritte:" + - "1. Wenn VPN funktioniert: Temporary IP-Erlaubnis entfernen" + - "2. Wenn VPN nicht funktioniert: Route-Tabellen auf Client pr?fen" diff --git a/deployment/ansible/playbooks/fix-grafana-vpn-routing.yml b/deployment/ansible/playbooks/fix-grafana-vpn-routing.yml new file mode 100644 index 00000000..9642dc84 --- /dev/null +++ b/deployment/ansible/playbooks/fix-grafana-vpn-routing.yml @@ -0,0 +1,80 @@ +--- +- name: Fix Grafana VPN Routing and Remove Temporary IP Allow + hosts: production + gather_facts: no + become: no + + tasks: + - name: Check recent Grafana access attempts + shell: | + cd ~/deployment/stacks/traefik + echo "=== Recent Grafana Access (Last 10 attempts) ===" + tail -50 logs/access.log | grep grafana | tail -10 | while read line; do + echo "$line" | grep -oP '"ClientHost":"[^"]*"' || echo "Could not parse" + done + args: + executable: /bin/bash + register: recent_access + ignore_errors: yes + failed_when: false + + - name: Display recent access attempts + debug: + msg: "{{ recent_access.stdout_lines }}" + + - name: Check if traffic comes from VPN + shell: | + cd ~/deployment/stacks/traefik + echo "=== Checking if recent traffic comes from VPN (10.8.0.0/24) ===" + tail -20 logs/access.log | grep grafana | tail -5 | grep -oP '"ClientHost":"[^"]*"' | sed 's/"ClientHost":"//;s/"//' | while read ip; do + if [[ "$ip" =~ ^10\.8\.0\.[0-9]+$ ]]; then + echo "? $ip -> VPN traffic (10.8.0.0/24)" + else + echo "? $ip -> Public IP (not VPN)" + fi + done + args: + executable: /bin/bash + register: vpn_check + ignore_errors: yes + failed_when: false + + - name: Display VPN check results + debug: + msg: "{{ vpn_check.stdout_lines }}" + + - name: Backup current middlewares.yml + shell: | + cd ~/deployment/stacks/traefik/dynamic + cp middlewares.yml middlewares.yml.backup.$(date +%Y%m%d_%H%M%S) + args: + executable: /bin/bash + when: false # Skip for now - we'll do this manually + + - name: Check current middleware configuration + shell: | + cd ~/deployment/stacks/traefik/dynamic + echo "=== Current grafana-vpn-only Middleware ===" + grep -A 8 "grafana-vpn-only:" middlewares.yml + args: + executable: /bin/bash + register: middleware_config + ignore_errors: yes + failed_when: false + + - name: Display middleware configuration + debug: + msg: "{{ middleware_config.stdout_lines }}" + + - name: Instructions for removing temporary IP + debug: + msg: + - "=== TO REMOVE TEMPORARY IP ALLOWLIST ===" + - "1. Make sure VPN routing works (DNS = 10.8.0.1 or use hosts file)" + - "2. Test that traffic comes from VPN (ClientHost: 10.8.0.7)" + - "3. Remove temporary IP from middlewares.yml:" + - " cd ~/deployment/stacks/traefik/dynamic" + - " sed -i '/89.246.96.244\/32/d' middlewares.yml" + - "4. Restart Traefik:" + - " cd ~/deployment/stacks/traefik && docker compose restart traefik" + - "5. Test: With VPN = OK, Without VPN = 403" diff --git a/deployment/ansible/playbooks/monitor-grafana-access-live.yml b/deployment/ansible/playbooks/monitor-grafana-access-live.yml new file mode 100644 index 00000000..e100817d --- /dev/null +++ b/deployment/ansible/playbooks/monitor-grafana-access-live.yml @@ -0,0 +1,95 @@ +--- +- name: Live Monitor Grafana Access - Watch Traefik Logs in Real-Time + hosts: production + gather_facts: no + become: no + + tasks: + - name: Clear previous Grafana access attempts count + shell: | + echo "Starting live monitoring. Make a request to https://grafana.michaelschiemer.de now!" + echo "Waiting 10 seconds for you to make a request..." + sleep 10 + args: + executable: /bin/bash + + - name: Show recent Grafana access attempts + shell: | + cd ~/deployment/stacks/traefik + echo "=== Last 5 Grafana Access Attempts ===" + tail -100 logs/access.log | grep -i grafana | tail -5 + args: + executable: /bin/bash + register: recent_access + ignore_errors: yes + failed_when: false + + - name: Display recent access attempts + debug: + msg: "{{ recent_access.stdout_lines }}" + + - name: Check current client IP pattern + shell: | + cd ~/deployment/stacks/traefik + echo "=== Client IPs in recent Grafana requests ===" + tail -50 logs/access.log | grep -i grafana | tail -10 | grep -oP '"ClientHost":"[^"]*"' | head -5 + args: + executable: /bin/bash + register: client_ips + ignore_errors: yes + failed_when: false + + - name: Display client IPs + debug: + msg: "{{ client_ips.stdout_lines }}" + + - name: Extract and check client IPs + shell: | + cd ~/deployment/stacks/traefik + echo "=== Checking if client IPs are in VPN range (10.8.0.0/24) ===" + tail -20 logs/access.log | grep -i grafana | tail -3 | grep -oP '"ClientHost":"[^"]*"' | sed 's/"ClientHost":"//;s/"//' | while read ip; do + if [[ "$ip" =~ ^10\.8\.0\.[0-9]+$ ]]; then + echo "$ip -> In VPN range (10.8.0.0/24): YES" + else + echo "$ip -> In VPN range (10.8.0.0/24): NO (this is the problem!)" + fi + done + args: + executable: /bin/bash + register: vpn_check + ignore_errors: yes + failed_when: false + + - name: Display VPN range check + debug: + msg: "{{ vpn_check.stdout_lines }}" + + - name: Show Traefik middleware errors + shell: | + cd ~/deployment/stacks/traefik + echo "=== Traefik Middleware Errors (if any) ===" + tail -50 logs/traefik.log | grep -iE "(grafana|ipallowlist|403|middleware)" | tail -10 || echo "No middleware errors found" + args: + executable: /bin/bash + register: middleware_errors + ignore_errors: yes + failed_when: false + + - name: Display middleware errors + debug: + msg: "{{ middleware_errors.stdout_lines }}" + + - name: Verify middleware configuration + shell: | + cd ~/deployment/stacks/traefik/dynamic + echo "=== Current grafana-vpn-only Middleware ===" + grep -A 6 "grafana-vpn-only:" middlewares.yml + args: + executable: /bin/bash + register: middleware_config + ignore_errors: yes + failed_when: false + + - name: Display middleware configuration + debug: | + msg: "{{ middleware_config.stdout_lines }}" diff --git a/deployment/ansible/playbooks/monitor-grafana-client-ip.yml b/deployment/ansible/playbooks/monitor-grafana-client-ip.yml new file mode 100644 index 00000000..98b7aa2e --- /dev/null +++ b/deployment/ansible/playbooks/monitor-grafana-client-ip.yml @@ -0,0 +1,75 @@ +--- +- name: Monitor Grafana Client IP - Wait for Next Request + hosts: production + gather_facts: no + become: no + + tasks: + - name: Instructions + debug: + msg: + - "=== LIVE MONITORING ===" + - "Bitte mache JETZT einen Zugriff auf https://grafana.michaelschiemer.de im Browser" + - "Ich warte 30 Sekunden und pr?fe dann die Logs..." + - "" + + - name: Wait for access attempt + pause: + seconds: 30 + + - name: Check recent Grafana access attempts + shell: | + cd ~/deployment/stacks/traefik + echo "=== Last 10 Grafana Access Attempts ===" + tail -100 logs/access.log | grep -i grafana | tail -10 + args: + executable: /bin/bash + register: recent_access + ignore_errors: yes + failed_when: false + + - name: Extract client IPs + shell: | + cd ~/deployment/stacks/traefik + echo "=== Client IPs in recent requests ===" + tail -20 logs/access.log | grep -i grafana | tail -10 | grep -oP '"ClientHost":"[^"]*"' | sed 's/"ClientHost":"//;s/"//' | sort -u + args: + executable: /bin/bash + register: client_ips + ignore_errors: yes + failed_when: false + + - name: Display client IPs + debug: + msg: "{{ client_ips.stdout_lines }}" + + - name: Check if IP is VPN IP + shell: | + cd ~/deployment/stacks/traefik + tail -10 logs/access.log | grep -i grafana | tail -5 | grep -oP '"ClientHost":"[^"]*"' | sed 's/"ClientHost":"//;s/"//' | while read ip; do + if [[ "$ip" =~ ^10\.8\.0\.[0-9]+$ ]]; then + echo "? $ip -> VPN IP (10.8.0.0/24) - Traffic kommt ?ber VPN!" + else + echo "? $ip -> Public IP (nicht VPN) - Traffic kommt NICHT ?ber VPN" + fi + done + args: + executable: /bin/bash + register: vpn_check + ignore_errors: yes + failed_when: false + + - name: Display VPN check + debug: + msg: "{{ vpn_check.stdout_lines }}" + + - name: Recommendations + debug: + msg: + - "" + - "=== ERGEBNIS ===" + - "Wenn ClientHost: 10.8.0.7 (VPN-IP) ? Traffic kommt ?ber VPN ?" + - "Dann k?nnen wir die tempor?re IP-Erlaubnis entfernen!" + - "" + - "Wenn ClientHost: 89.246.96.244 (?ffentliche IP) ? Traffic kommt NICHT ?ber VPN ?" + - "Dann m?ssen wir VPN-Routing noch weiter fixen" diff --git a/deployment/ansible/playbooks/monitor-grafana-live-now.yml b/deployment/ansible/playbooks/monitor-grafana-live-now.yml new file mode 100644 index 00000000..c6636398 --- /dev/null +++ b/deployment/ansible/playbooks/monitor-grafana-live-now.yml @@ -0,0 +1,80 @@ +--- +- name: Monitor Grafana Access Live - Check Latest Request + hosts: production + gather_facts: no + become: no + + tasks: + - name: Get timestamp of last log entry + shell: | + cd ~/deployment/stacks/traefik + tail -1 logs/access.log | grep -oP '"time":"[^"]*"' + args: + executable: /bin/bash + register: last_log_time + ignore_errors: yes + failed_when: false + + - name: Display last log time + debug: + msg: "{{ last_log_time.stdout }}" + + - name: Get last 30 Grafana access attempts + shell: | + cd ~/deployment/stacks/traefik + tail -1000 logs/access.log | grep -i grafana | tail -30 + args: + executable: /bin/bash + register: grafana_logs + ignore_errors: yes + failed_when: false + + - name: Extract client IPs from last 10 Grafana requests + shell: | + cd ~/deployment/stacks/traefik + tail -200 logs/access.log | grep -i grafana | tail -10 | grep -oP '"ClientHost":"[^"]*"' | sed 's/"ClientHost":"//;s/"//' | sort -u + args: + executable: /bin/bash + register: client_ips + ignore_errors: yes + failed_when: false + + - name: Display client IPs found + debug: + msg: "{{ client_ips.stdout_lines }}" + + - name: Analyze last 5 Grafana requests + shell: | + cd ~/deployment/stacks/traefik + tail -100 logs/access.log | grep -i grafana | tail -5 | while IFS= read -r line; do + time=$(echo "$line" | grep -oP '"time":"[^"]*"' | sed 's/"time":"//;s/"//' | cut -d'T' -f2 | cut -d'+' -f1) + client=$(echo "$line" | grep -oP '"ClientHost":"[^"]*"' | sed 's/"ClientHost":"//;s/"//') + status=$(echo "$line" | grep -oP '"DownstreamStatus":[0-9]+' | sed 's/"DownstreamStatus"://') + if [[ "$client" =~ ^10\.8\.0\.[0-9]+$ ]]; then + echo "$time | ClientHost: $client | Status: $status ? VPN-IP" + elif [[ "$client" == "89.246.96.244" ]]; then + echo "$time | ClientHost: $client | Status: $status ? Public IP" + else + echo "$time | ClientHost: $client | Status: $status ? Unknown" + fi + done + args: + executable: /bin/bash + register: analysis + ignore_errors: yes + failed_when: false + + - name: Display analysis + debug: + msg: "{{ analysis.stdout_lines }}" + + - name: Recommendations + debug: + msg: + - "" + - "=== ERGEBNIS ===" + - "Wenn ClientHost: 10.8.0.7 ? Traffic kommt ?ber VPN ?" + - "? Dann k?nnen wir die tempor?re IP-Erlaubnis entfernen!" + - "" + - "Wenn ClientHost: 89.246.96.244 ? Traffic kommt NICHT ?ber VPN ?" + - "? Dann m?ssen wir weiter debuggen (Route, AllowedIPs, etc.)" diff --git a/deployment/ansible/playbooks/monitor-grafana-live-with-firewall.yml b/deployment/ansible/playbooks/monitor-grafana-live-with-firewall.yml new file mode 100644 index 00000000..dcb8bd6a --- /dev/null +++ b/deployment/ansible/playbooks/monitor-grafana-live-with-firewall.yml @@ -0,0 +1,86 @@ +--- +- name: Monitor Grafana Access After Firewall Changes + hosts: production + gather_facts: no + become: no + + tasks: + - name: Instructions + debug: + msg: + - "=== LIVE MONITORING NACH FIREWALL-?NDERUNGEN ===" + - "Firewall-Regeln wurden erstellt ?" + - "WireGuard ist verbunden ?" + - "" + - "Bitte mache JETZT einen neuen Zugriff auf https://grafana.michaelschiemer.de im Browser" + - "Ich warte 20 Sekunden und pr?fe dann die Logs..." + - "" + + - name: Get current log timestamp + shell: | + cd ~/deployment/stacks/traefik + tail -1 logs/access.log | grep -oP '"time":"[^"]*"' + args: + executable: /bin/bash + register: current_timestamp + failed_when: false + + - name: Display current timestamp + debug: + msg: "Letztes Log: {{ current_timestamp.stdout }}" + + - name: Wait for access attempt + pause: + seconds: 20 + + - name: Check for new Grafana access + shell: | + cd ~/deployment/stacks/traefik + tail -200 logs/access.log | grep -i grafana | tail -20 | while IFS= read -r line; do + time=$(echo "$line" | grep -oP '"time":"[^"]*"' | sed 's/"time":"//;s/"//' | cut -d'T' -f2 | cut -d'+' -f1 | cut -d':' -f1-2) + client=$(echo "$line" | grep -oP '"ClientHost":"[^"]*"' | sed 's/"ClientHost":"//;s/"//') + status=$(echo "$line" | grep -oP '"DownstreamStatus":[0-9]+' | sed 's/"DownstreamStatus"://') + if echo "$client" | grep -q '^10\.8\.0\.'; then + echo "$time | ClientHost: $client | Status: $status ? VPN-IP (Traffic kommt ?ber VPN!)" + elif [ "$client" = "89.246.96.244" ]; then + echo "$time | ClientHost: $client | Status: $status ? Public IP (Traffic kommt NICHT ?ber VPN)" + else + echo "$time | ClientHost: $client | Status: $status ? Unknown IP" + fi + done + args: + executable: /bin/bash + register: analysis + ignore_errors: yes + failed_when: false + + - name: Display analysis + debug: + msg: "{{ analysis.stdout_lines }}" + + - name: Get unique client IPs from last 10 requests + shell: | + cd ~/deployment/stacks/traefik + tail -100 logs/access.log | grep -i grafana | tail -10 | grep -oP '"ClientHost":"[^"]*"' | sed 's/"ClientHost":"//;s/"//' | sort -u + args: + executable: /bin/bash + register: unique_ips + ignore_errors: yes + failed_when: false + + - name: Display unique IPs + debug: + msg: "{{ unique_ips.stdout_lines }}" + + - name: Final verdict + debug: + msg: + - "" + - "=== ERGEBNIS ===" + - "Pr?fe die obigen Zeilen:" + - "" + - "? Wenn ClientHost: 10.8.0.7 ? Traffic kommt ?ber VPN!" + - " ? Dann k?nnen wir die tempor?re IP-Erlaubnis entfernen!" + - "" + - "? Wenn ClientHost: 89.246.96.244 ? Traffic kommt NICHT ?ber VPN" + - " ? Dann m?ssen wir weitere Optionen probieren (Route explizit setzen, etc.)" diff --git a/deployment/ansible/playbooks/monitor-live-grafana-access.yml b/deployment/ansible/playbooks/monitor-live-grafana-access.yml new file mode 100644 index 00000000..0d392842 --- /dev/null +++ b/deployment/ansible/playbooks/monitor-live-grafana-access.yml @@ -0,0 +1,70 @@ +--- +- name: Monitor Live Grafana Access + hosts: production + gather_facts: no + become: no + + tasks: + - name: Instructions + debug: + msg: + - "=== LIVE MONITORING ===" + - "Bitte mache JETZT einen Zugriff auf https://grafana.michaelschiemer.de im Browser" + - "Ich warte 20 Sekunden und pr?fe dann die Logs..." + - "" + + - name: Get current log timestamp + shell: | + cd ~/deployment/stacks/traefik + tail -1 logs/access.log | grep -oP '"time":"[^"]*"' + args: + executable: /bin/bash + register: current_timestamp + failed_when: false + + - name: Display current timestamp + debug: + msg: "Letztes Log: {{ current_timestamp.stdout }}" + + - name: Wait for access attempt + pause: + seconds: 20 + + - name: Check for new Grafana access + shell: | + cd ~/deployment/stacks/traefik + tail -500 logs/access.log | grep -i grafana | tail -10 | while IFS= read -r line; do + time=$(echo "$line" | grep -oP '"time":"[^"]*"' | sed 's/"time":"//;s/"//' | cut -d'T' -f2 | cut -d'+' -f1) + client=$(echo "$line" | grep -oP '"ClientHost":"[^"]*"' | sed 's/"ClientHost":"//;s/"//') + status=$(echo "$line" | grep -oP '"DownstreamStatus":[0-9]+' | sed 's/"DownstreamStatus"://') + if echo "$client" | grep -q "^10\.8\.0\."; then + echo "$time | ClientHost: $client | Status: $status ? VPN-IP (Traffic kommt ?ber VPN!)" + elif [ "$client" = "89.246.96.244" ]; then + echo "$time | ClientHost: $client | Status: $status ? Public IP (Traffic kommt NICHT ?ber VPN)" + else + echo "$time | ClientHost: $client | Status: $status ? Unknown" + fi + done + args: + executable: /bin/bash + register: analysis + ignore_errors: yes + failed_when: false + + - name: Display analysis + debug: + msg: "{{ analysis.stdout_lines }}" + + - name: Get unique client IPs + shell: | + cd ~/deployment/stacks/traefik + tail -100 logs/access.log | grep -i grafana | tail -10 | grep -oP '"ClientHost":"[^"]*"' | sed 's/"ClientHost":"//;s/"//' | sort -u + args: + executable: /bin/bash + register: unique_ips + ignore_errors: yes + failed_when: false + + - name: Display unique IPs + debug: + msg: "{{ unique_ips.stdout_lines }}" diff --git a/deployment/ansible/playbooks/regenerate-wireguard-client.yml b/deployment/ansible/playbooks/regenerate-wireguard-client.yml new file mode 100644 index 00000000..8ed52130 --- /dev/null +++ b/deployment/ansible/playbooks/regenerate-wireguard-client.yml @@ -0,0 +1,205 @@ +--- +- name: Regenerate WireGuard Client - Fresh Config + hosts: production + become: yes + gather_facts: yes + + vars: + wireguard_interface: "wg0" + wireguard_config_path: "/etc/wireguard" + wireguard_config_file: "{{ wireguard_config_path }}/{{ wireguard_interface }}.conf" + wireguard_client_configs_path: "/etc/wireguard/clients" + wireguard_local_client_configs_dir: "{{ playbook_dir }}/../wireguard-clients" + + tasks: + - name: Validate client name + fail: + msg: "client_name is required. Usage: ansible-playbook ... -e 'client_name=myclient'" + when: client_name is not defined or client_name == "" + + - name: Check if old client config exists + stat: + path: "{{ wireguard_client_configs_path }}/{{ client_name }}.conf" + register: old_client_config + failed_when: false + + - name: Backup old client config + copy: + src: "{{ wireguard_client_configs_path }}/{{ client_name }}.conf" + dest: "{{ wireguard_client_configs_path }}/{{ client_name }}.conf.backup-{{ ansible_date_time.epoch }}" + remote_src: yes + when: old_client_config.stat.exists + register: backup_result + failed_when: false + + - name: Display backup info + debug: + msg: "Alte Config wurde gesichert als: {{ backup_result.dest | default('N/A') }}" + when: old_client_config.stat.exists + + - name: Remove old client from WireGuard server config + shell: | + # Entferne den [Peer] Block f?r den Client aus wg0.conf + sed -i '/# BEGIN ANSIBLE MANAGED BLOCK - Client: {{ client_name }}/,/^# END ANSIBLE MANAGED BLOCK - Client: {{ client_name }}/d' {{ wireguard_config_file }} + # Fallback: Entferne auch ohne Marker + sed -i '/# Client: {{ client_name }}/,/{/d' {{ wireguard_config_file }} + sed -i '/PublicKey = .*/d' {{ wireguard_config_file }} || true + sed -i '/AllowedIPs = .*\/32$/d' {{ wireguard_config_file }} || true + args: + executable: /bin/bash + register: remove_result + failed_when: false + changed_when: false + + - name: Set WireGuard network + set_fact: + wireguard_network: "{{ wireguard_network | default('10.8.0.0/24') }}" + + - name: Set WireGuard other variables with defaults + set_fact: + wireguard_port: "{{ wireguard_port | default(51820) }}" + client_ip: "{{ client_ip | default('') }}" + allowed_ips: "{{ allowed_ips | default(wireguard_network) }}" + + - name: Get server external IP address + uri: + url: https://api.ipify.org + return_content: yes + register: server_external_ip + changed_when: false + failed_when: false + + - name: Set server external IP + set_fact: + server_external_ip_content: "{{ ansible_host | default(server_external_ip.content | default('')) }}" + + - name: Read WireGuard server config + slurp: + src: "{{ wireguard_config_file }}" + register: wireguard_server_config_read + + - name: Extract server IP from config + set_fact: + server_vpn_ip: "{{ (wireguard_server_config_read.content | b64decode | regex_search('Address = ([0-9.]+)')) | default(['10.8.0.1']) | first }}" + failed_when: false + + - name: Set default DNS servers + set_fact: + wireguard_dns_servers: "{{ [server_vpn_ip] }}" + + - name: Extract WireGuard server IP octets + set_fact: + wireguard_server_ip_octets: "{{ server_vpn_ip.split('.') }}" + when: client_ip == "" + + - name: Gather existing client addresses + set_fact: + existing_client_ips: "{{ (wireguard_server_config_read.content | b64decode | regex_findall('AllowedIPs = ([0-9A-Za-z.]+)/32', '\\\\1')) }}" + when: client_ip == "" + + - name: Calculate client IP if not provided + vars: + existing_last_octets: "{{ (existing_client_ips | default([])) | map('regex_replace', '^(?:\\\\d+\\\\.\\\\d+\\\\.\\\\d+\\\\.)', '') | select('match', '^[0-9]+$') | map('int') | list }}" + server_last_octet: "{{ wireguard_server_ip_octets[3] | int }}" + next_octet_candidate: "{{ (existing_last_octets + [server_last_octet]) | map('int') | list | max + 1 if (existing_client_ips | default([]) | length > 0) else server_last_octet + 1 }}" + set_fact: + client_ip: "{{ [ + wireguard_server_ip_octets[0], + wireguard_server_ip_octets[1], + wireguard_server_ip_octets[2], + next_octet_candidate + ] | join('.') }}" + when: client_ip == "" + + - name: Generate NEW client private key + command: "wg genkey" + register: client_private_key + changed_when: true + no_log: yes + + - name: Generate NEW client public key + command: "wg pubkey" + args: + stdin: "{{ client_private_key.stdout }}" + register: client_public_key + changed_when: false + no_log: yes + + - name: Add NEW client to WireGuard server config + blockinfile: + path: "{{ wireguard_config_file }}" + block: | + # Client: {{ client_name }} + [Peer] + PublicKey = {{ client_public_key.stdout }} + AllowedIPs = {{ client_ip }}/32 + marker: "# {mark} ANSIBLE MANAGED BLOCK - Client: {{ client_name }}" + register: wireguard_client_block + + - name: Ensure client configs directory exists + file: + path: "{{ wireguard_client_configs_path }}" + state: directory + mode: '0700' + owner: root + group: root + + - name: Ensure local client configs directory exists + file: + path: "{{ wireguard_local_client_configs_dir }}" + state: directory + mode: '0700' + delegate_to: localhost + become: no + run_once: true + + - name: Get server public key + shell: "cat {{ wireguard_config_path }}/{{ wireguard_interface }}_private.key | wg pubkey" + register: server_public_key_cmd + changed_when: false + no_log: yes + failed_when: false + + - name: Create NEW client configuration file + template: + src: "{{ playbook_dir }}/../templates/wireguard-client.conf.j2" + dest: "{{ wireguard_client_configs_path }}/{{ client_name }}.conf" + mode: '0600' + owner: root + group: root + + - name: Download NEW client configuration to control machine + fetch: + src: "{{ wireguard_client_configs_path }}/{{ client_name }}.conf" + dest: "{{ wireguard_local_client_configs_dir }}/{{ client_name }}.conf" + flat: yes + mode: '0600' + + - name: Restart WireGuard service + systemd: + name: "wg-quick@{{ wireguard_interface }}" + state: restarted + + - name: Display NEW client configuration + debug: + msg: | + ======================================== + WireGuard Client REGENERATED: {{ client_name }} + ======================================== + + Neue Client-IP: {{ client_ip }} + Server Endpoint: {{ server_external_ip_content }}:{{ wireguard_port }} + + Neue Client-Konfiguration: + {{ wireguard_local_client_configs_dir }}/{{ client_name }}.conf + + WICHTIG: + 1. Lade die neue Config-Datei herunter + 2. Importiere sie in WireGuard (ersetze die alte!) + 3. Verbinde mit dem VPN + 4. Teste: ping 10.8.0.1 + 5. Teste: https://grafana.michaelschiemer.de + + Alte Config gesichert als: + {{ backup_result.dest | default('N/A') }} + ======================================== diff --git a/deployment/ansible/playbooks/remove-temporary-grafana-ip.yml b/deployment/ansible/playbooks/remove-temporary-grafana-ip.yml new file mode 100644 index 00000000..26c815e4 --- /dev/null +++ b/deployment/ansible/playbooks/remove-temporary-grafana-ip.yml @@ -0,0 +1,119 @@ +--- +- name: Remove Temporary IP Allowlist from Grafana - Make VPN-Only + hosts: production + gather_facts: no + become: no + + tasks: + - name: Check recent Grafana access attempts + shell: | + cd ~/deployment/stacks/traefik + echo "=== Recent Grafana Access (Last 5 attempts) ===" + tail -30 logs/access.log | grep grafana | tail -5 | grep -oP '"ClientHost":"[^"]*"' | head -5 + args: + executable: /bin/bash + register: recent_ips + ignore_errors: yes + failed_when: false + + - name: Display recent client IPs + debug: + msg: "{{ recent_ips.stdout_lines }}" + + - name: Check if any traffic comes from VPN + shell: | + cd ~/deployment/stacks/traefik + tail -20 logs/access.log | grep grafana | tail -5 | grep -oP '"ClientHost":"[^"]*"' | sed 's/"ClientHost":"//;s/"//' | while read ip; do + if [[ "$ip" =~ ^10\.8\.0\.[0-9]+$ ]]; then + echo "? Found VPN IP: $ip" + else + echo "? Found public IP: $ip (not VPN)" + fi + done + args: + executable: /bin/bash + register: vpn_check + ignore_errors: yes + failed_when: false + + - name: Display VPN check + debug: + msg: "{{ vpn_check.stdout_lines }}" + + - name: Backup middlewares.yml + shell: | + cd ~/deployment/stacks/traefik/dynamic + cp middlewares.yml middlewares.yml.backup.before-remove-temp-ip.$(date +%Y%m%d_%H%M%S) + echo "Backup created" + args: + executable: /bin/bash + + - name: Remove temporary IP from grafana-vpn-only middleware + shell: | + cd ~/deployment/stacks/traefik/dynamic + sed -i '/89.246.96.244\/32/d' middlewares.yml + echo "Temporary IP removed" + args: + executable: /bin/bash + + - name: Verify middleware configuration + shell: | + cd ~/deployment/stacks/traefik/dynamic + echo "=== Updated grafana-vpn-only Middleware ===" + grep -A 6 "grafana-vpn-only:" middlewares.yml + args: + executable: /bin/bash + register: updated_middleware + ignore_errors: yes + failed_when: false + + - name: Display updated middleware + debug: + msg: "{{ updated_middleware.stdout_lines }}" + + - name: Validate YAML syntax + command: python3 -c "import yaml; yaml.safe_load(open('middlewares.yml')); print('YAML valid')" + args: + chdir: ~/deployment/stacks/traefik/dynamic + register: yaml_validation + ignore_errors: yes + failed_when: false + + - name: Display YAML validation + debug: + msg: "{{ yaml_validation.stdout_lines }}" + + - name: Restart Traefik to apply changes + command: docker compose restart traefik + args: + chdir: ~/deployment/stacks/traefik + register: traefik_restart + + - name: Wait for Traefik to restart + pause: + seconds: 5 + + - name: Verify Traefik status + command: docker compose ps traefik + args: + chdir: ~/deployment/stacks/traefik + register: traefik_status + + - name: Display Traefik status + debug: + msg: "{{ traefik_status.stdout_lines }}" + + - name: Final instructions + debug: + msg: + - "=== TEMPORARY IP REMOVED ===" + - "Grafana should now be VPN-only" + - "" + - "Test:" + - "1. With VPN: https://grafana.michaelschiemer.de should work ?" + - "2. Without VPN: https://grafana.michaelschiemer.de should give 403 ?" + - "" + - "If it doesn't work:" + - "- Check that VPN routing works (DNS = 10.8.0.1 or use hosts file)" + - "- Check Traefik logs: tail -f ~/deployment/stacks/traefik/logs/access.log | grep grafana" + - "- Restore backup if needed: cp middlewares.yml.backup.* middlewares.yml" diff --git a/deployment/ansible/playbooks/setup-wireguard.yml b/deployment/ansible/playbooks/setup-wireguard.yml index 90b5d6a2..e61b7f76 100755 --- a/deployment/ansible/playbooks/setup-wireguard.yml +++ b/deployment/ansible/playbooks/setup-wireguard.yml @@ -7,9 +7,9 @@ vars: # WireGuard variables are defined in group_vars/production.yml # Can be overridden via -e flag if needed - wireguard_port: "{{ wireguard_port | default(wireguard_port_default) }}" - wireguard_network: "{{ wireguard_network | default(wireguard_network_default) }}" - wireguard_server_ip: "{{ wireguard_server_ip | default(wireguard_server_ip_default) }}" + wireguard_port: "{{ wireguard_port_default | default(51820) }}" + wireguard_network: "{{ wireguard_network_default | default('10.8.0.0/24') }}" + wireguard_server_ip: "{{ wireguard_server_ip_default | default('10.8.0.1') }}" pre_tasks: diff --git a/deployment/ansible/playbooks/test-grafana-vpn-access.yml b/deployment/ansible/playbooks/test-grafana-vpn-access.yml new file mode 100644 index 00000000..d96d7121 --- /dev/null +++ b/deployment/ansible/playbooks/test-grafana-vpn-access.yml @@ -0,0 +1,99 @@ +--- +- name: Test Grafana VPN Access - Final Verification + hosts: production + gather_facts: no + become: no + + tasks: + - name: Clear instruction + debug: + msg: + - "=== WICHTIG ===" + - "Bitte f?hre diese Tests auf Windows aus (mit VPN verbunden):" + - "" + - "1. Pr?fe ob Hosts-Datei korrekt ist:" + - " type C:\\Windows\\System32\\drivers\\etc\\hosts | findstr grafana" + - " Sollte zeigen: 10.8.0.1 grafana.michaelschiemer.de" + - "" + - "2. Pr?fe ob VPN verbunden ist:" + - " ping 10.8.0.1" + - " Sollte funktionieren (wenn VPN verbunden ist)" + - "" + - "3. Teste Grafana-Zugriff:" + - " ?ffne https://grafana.michaelschiemer.de im Browser" + - "" + - "Dann pr?fe ich die Logs..." + + - name: Wait for test + pause: + seconds: 15 + + - name: Check Traefik logs for Grafana access + shell: | + cd ~/deployment/stacks/traefik + echo "=== Last 10 Grafana Access Attempts ===" + tail -200 logs/access.log | grep -i grafana | tail -10 | while read line; do + client=$(echo "$line" | grep -oP '"ClientHost":"[^"]*"' | head -1) + time=$(echo "$line" | grep -oP '"time":"[^"]*"' | head -1) + status=$(echo "$line" | grep -oP '"DownstreamStatus":[0-9]+' | head -1) + echo "$time | $client | $status" + done + args: + executable: /bin/bash + register: recent_logs + ignore_errors: yes + failed_when: false + + - name: Display recent logs + debug: + msg: "{{ recent_logs.stdout_lines }}" + + - name: Extract unique client IPs + shell: | + cd ~/deployment/stacks/traefik + tail -50 logs/access.log | grep -i grafana | grep -oP '"ClientHost":"[^"]*"' | sed 's/"ClientHost":"//;s/"//' | sort -u + args: + executable: /bin/bash + register: unique_ips + ignore_errors: yes + failed_when: false + + - name: Display unique client IPs + debug: + msg: "{{ unique_ips.stdout_lines }}" + + - name: Analyze client IPs + shell: | + cd ~/deployment/stacks/traefik + tail -20 logs/access.log | grep -i grafana | tail -5 | grep -oP '"ClientHost":"[^"]*"' | sed 's/"ClientHost":"//;s/"//' | while read ip; do + if [[ -z "$ip" ]]; then + continue + fi + if [[ "$ip" =~ ^10\.8\.0\.[0-9]+$ ]]; then + echo "? $ip -> VPN IP (10.8.0.0/24) - Traffic kommt ?ber VPN!" + elif [[ "$ip" == "89.246.96.244" ]]; then + echo "? $ip -> Deine ?ffentliche IP - Traffic kommt NICHT ?ber VPN (Hosts-Datei funktioniert, aber VPN-Routing nicht)" + else + echo "? $ip -> Unbekannte IP" + fi + done + args: + executable: /bin/bash + register: ip_analysis + ignore_errors: yes + failed_when: false + + - name: Display IP analysis + debug: + msg: "{{ ip_analysis.stdout_lines }}" + + - name: Final recommendations + debug: + msg: + - "" + - "=== ERGEBNIS ===" + - "Wenn ClientHost: 10.8.0.7 ? Traffic kommt ?ber VPN ?" + - "? Dann k?nnen wir die tempor?re IP-Erlaubnis entfernen!" + - "" + - "Wenn ClientHost: 89.246.96.244 ? Traffic kommt NICHT ?ber VPN ?" + - "? Dann m?ssen wir pr?fen warum Hosts-Datei nicht ?ber VPN-Routing funktioniert" diff --git a/deployment/ansible/playbooks/test-grafana-vpn-final.yml b/deployment/ansible/playbooks/test-grafana-vpn-final.yml new file mode 100644 index 00000000..f64dd9f5 --- /dev/null +++ b/deployment/ansible/playbooks/test-grafana-vpn-final.yml @@ -0,0 +1,78 @@ +--- +- name: Test Grafana VPN Access - Final Check + hosts: production + gather_facts: no + become: no + + tasks: + - name: Instructions + debug: + msg: + - "=== FINALER TEST ===" + - "AllowedIPs ist korrekt (10.8.0.0/24) ?" + - "" + - "Bitte f?hre diese Schritte auf Windows aus:" + - "1. DNS-Cache leeren: ipconfig /flushdns" + - "2. Browser-Cache leeren oder Inkognito-Modus nutzen" + - "3. Stelle sicher, dass VPN verbunden ist" + - "4. ?ffne: https://grafana.michaelschiemer.de" + - "5. Warte 10 Sekunden" + - "" + - "Dann pr?fe ich die Logs..." + + - name: Wait for access attempt + pause: + seconds: 20 + + - name: Check latest Grafana access + shell: | + cd ~/deployment/stacks/traefik + echo "=== Letzte 10 Grafana-Zugriffe ===" + tail -500 logs/access.log | grep -i grafana | tail -10 | while IFS= read -r line; do + time=$(echo "$line" | grep -oP '"time":"[^"]*"' | sed 's/"time":"//;s/"//' | cut -d'T' -f2 | cut -d'+' -f1 | cut -d':' -f1-2) + client=$(echo "$line" | grep -oP '"ClientHost":"[^"]*"' | sed 's/"ClientHost":"//;s/"//') + status=$(echo "$line" | grep -oP '"DownstreamStatus":[0-9]+' | sed 's/"DownstreamStatus"://') + if [[ "$client" =~ ^10\.8\.0\.[0-9]+$ ]]; then + echo "$time | ClientHost: $client | Status: $status ? VPN-IP (Traffic kommt ?ber VPN!)" + elif [[ "$client" == "89.246.96.244" ]]; then + echo "$time | ClientHost: $client | Status: $status ? ?ffentliche IP (Traffic kommt NICHT ?ber VPN)" + else + echo "$time | ClientHost: $client | Status: $status ? Unbekannt" + fi + done + args: + executable: /bin/bash + register: analysis + ignore_errors: yes + failed_when: false + + - name: Display analysis + debug: + msg: "{{ analysis.stdout_lines }}" + + - name: Get unique client IPs from last 10 requests + shell: | + cd ~/deployment/stacks/traefik + tail -100 logs/access.log | grep -i grafana | tail -10 | grep -oP '"ClientHost":"[^"]*"' | sed 's/"ClientHost":"//;s/"//' | sort -u + args: + executable: /bin/bash + register: unique_ips + ignore_errors: yes + failed_when: false + + - name: Display unique IPs + debug: + msg: "{{ unique_ips.stdout_lines }}" + + - name: Final verdict + debug: + msg: + - "" + - "=== ERGEBNIS ===" + - "Pr?fe die obigen Zeilen:" + - "" + - "? Wenn ClientHost: 10.8.0.7 ? Traffic kommt ?ber VPN!" + - " ? Dann k?nnen wir die tempor?re IP-Erlaubnis entfernen!" + - "" + - "? Wenn ClientHost: 89.246.96.244 ? Traffic kommt NICHT ?ber VPN" + - " ? Dann m?ssen wir weitere Debugging-Schritte durchf?hren" diff --git a/deployment/ansible/playbooks/test-wireguard-docker-container.yml b/deployment/ansible/playbooks/test-wireguard-docker-container.yml new file mode 100644 index 00000000..4c5f2818 --- /dev/null +++ b/deployment/ansible/playbooks/test-wireguard-docker-container.yml @@ -0,0 +1,168 @@ +--- +- name: Test WireGuard Connection from Docker Container + hosts: production + become: yes + gather_facts: yes + + vars: + test_container_name: "wireguard-test-client" + wireguard_config_path: "/tmp/wireguard-test" + + tasks: + - name: Validate client name + fail: + msg: "client_name is required. Usage: ansible-playbook ... -e 'client_name=grafana-test'" + when: client_name is not defined or client_name == "" + + - name: Check if WireGuard client config exists + stat: + path: "{{ playbook_dir }}/../wireguard-clients/{{ client_name }}.conf" + register: client_config_exists + delegate_to: localhost + become: no + + - name: Fail if client config not found + fail: + msg: "Client config not found: {{ playbook_dir }}/../wireguard-clients/{{ client_name }}.conf" + when: not client_config_exists.stat.exists + + - name: Read client config + slurp: + src: "{{ playbook_dir }}/../wireguard-clients/{{ client_name }}.conf" + register: client_config_content + delegate_to: localhost + become: no + + - name: Extract client IP from config + set_fact: + client_vpn_ip: "{{ (client_config_content.content | b64decode | regex_search('Address = ([0-9.]+)')) | default(['10.8.0.7']) | first }}" + failed_when: false + + - name: Display extracted client IP + debug: + msg: "Client VPN IP: {{ client_vpn_ip }}" + + - name: Stop and remove existing test container + shell: | + docker stop {{ test_container_name }} || true + docker rm {{ test_container_name }} || true + args: + executable: /bin/bash + ignore_errors: yes + failed_when: false + + - name: Create temporary directory for WireGuard config + file: + path: "{{ wireguard_config_path }}" + state: directory + mode: '0700' + + - name: Copy client config to server + copy: + content: "{{ client_config_content.content | b64decode }}" + dest: "{{ wireguard_config_path }}/{{ client_name }}.conf" + mode: '0600' + + - name: Start WireGuard test container + shell: | + docker run -d \ + --name {{ test_container_name }} \ + --cap-add=NET_ADMIN \ + --cap-add=SYS_MODULE \ + --sysctl net.ipv4.conf.all.src_valid_mark=1 \ + -v {{ wireguard_config_path }}/{{ client_name }}.conf:/etc/wireguard/{{ client_name }}.conf:ro \ + --device /dev/net/tun \ + ghcr.io/linuxserver/wireguard:latest + args: + executable: /bin/bash + register: container_result + ignore_errors: yes + + - name: Wait for container to start + pause: + seconds: 5 + + - name: Check container status + shell: docker ps -a --filter "name={{ test_container_name }}" --format "{{ '{{' }}.Status{{ '}}' }}" + register: container_status + failed_when: false + + - name: Display container status + debug: + msg: "Container Status: {{ container_status.stdout }}" + + - name: Get container logs + shell: docker logs {{ test_container_name }} --tail 50 + register: container_logs + failed_when: false + + - name: Display container logs + debug: + msg: "{{ container_logs.stdout_lines }}" + + - name: Test ping to VPN server from container + shell: | + docker exec {{ test_container_name }} ping -c 4 10.8.0.1 || true + register: ping_result + failed_when: false + + - name: Display ping result + debug: + msg: "{{ ping_result.stdout_lines }}" + + - name: Test curl to Grafana from container + shell: | + docker exec {{ test_container_name }} curl -s -o /dev/null -w "%{http_code}" --max-time 10 https://grafana.michaelschiemer.de/ || echo "FAILED" + register: curl_result + failed_when: false + + - name: Display curl result + debug: + msg: "HTTP Status Code: {{ curl_result.stdout }}" + + - name: Get container IP + shell: | + docker exec {{ test_container_name }} ip addr show wg0 | grep "inet " | awk '{print $2}' | cut -d/ -f1 || echo "No WireGuard IP" + register: container_wg_ip + failed_when: false + + - name: Display container WireGuard IP + debug: + msg: "Container WireGuard IP: {{ container_wg_ip.stdout }}" + + - name: Test DNS resolution from container + shell: | + docker exec {{ test_container_name }} nslookup grafana.michaelschiemer.de || true + register: dns_result + failed_when: false + + - name: Display DNS result + debug: "{{ dns_result.stdout_lines }}" + + - name: Check Traefik logs for container access + shell: | + cd ~/deployment/stacks/traefik + tail -100 logs/access.log | grep -i grafana | tail -10 | grep -oP '"ClientHost":"[^"]*"' | sed 's/"ClientHost":"//;s/"//' | sort -u + register: traefik_client_ips + failed_when: false + + - name: Display Traefik client IPs + debug: + msg: "{{ traefik_client_ips.stdout_lines }}" + + - name: Cleanup instructions + debug: + msg: | + ======================================== + TEST ABGESCHLOSSEN + ======================================== + + Container-Name: {{ test_container_name }} + + Um Container zu entfernen: + docker stop {{ test_container_name }} + docker rm {{ test_container_name }} + + Um Config zu entfernen: + rm -rf {{ wireguard_config_path }} + ======================================== diff --git a/deployment/ansible/test-vpn-connection.sh b/deployment/ansible/test-vpn-connection.sh new file mode 100755 index 00000000..6fbcadbf --- /dev/null +++ b/deployment/ansible/test-vpn-connection.sh @@ -0,0 +1,78 @@ +#!/bin/bash +# Test VPN connection to server +# Run this script after starting the VPN with: wg-quick up test-client + +set -e + +echo "=== VPN Connection Test ===" +echo "" + +# Check if VPN interface exists +if ! ip link show test-client > /dev/null 2>&1; then + echo "? VPN interface 'test-client' not found!" + echo " Start VPN with: wg-quick up test-client" + exit 1 +fi + +echo "? VPN interface 'test-client' is active" +echo "" + +# Check WireGuard status +echo "=== WireGuard Status ===" +sudo wg show test-client || echo "?? Warning: Cannot show WireGuard status" +echo "" + +# Test ping to server VPN IP +echo "=== Testing Ping to Server VPN IP (10.8.0.1) ===" +if ping -c 3 -W 2 10.8.0.1 > /dev/null 2>&1; then + echo "? Ping to 10.8.0.1 successful" +else + echo "? Ping to 10.8.0.1 failed" +fi +echo "" + +# Check DNS resolution +echo "=== Testing DNS Resolution ===" +if host grafana.michaelschiemer.de > /dev/null 2>&1; then + echo "? DNS resolution works" + host grafana.michaelschiemer.de | head -1 +else + echo "?? DNS resolution failed, but this might be OK if using VPN routing" +fi +echo "" + +# Test HTTP connection to Grafana +echo "=== Testing HTTP Connection to Grafana ===" +HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" \ + --max-time 10 \ + -H "User-Agent: Mozilla/5.0 (Linux; x86_64) AppleWebKit/537.36" \ + --insecure \ + https://grafana.michaelschiemer.de/ 2>/dev/null || echo "000") + +if [ "$HTTP_CODE" = "200" ] || [ "$HTTP_CODE" = "302" ] || [ "$HTTP_CODE" = "301" ]; then + echo "? HTTP connection successful (Status: $HTTP_CODE)" + echo " Traffic is reaching Grafana through VPN!" +elif [ "$HTTP_CODE" = "000" ]; then + echo "? HTTP connection failed (could not connect)" + echo " Check if VPN is routing traffic correctly" +else + echo "?? HTTP connection returned status: $HTTP_CODE" + echo " Connection works, but got unexpected status code" +fi +echo "" + +# Check routing table +echo "=== Routing Table for VPN Network ===" +ip route show | grep "10.8.0.0/24" || echo "?? No route found for 10.8.0.0/24" +echo "" + +# Check which interface is used for VPN network +echo "=== Interface Route Check ===" +ip route get 10.8.0.1 2>/dev/null || echo "?? Cannot determine route to 10.8.0.1" +echo "" + +echo "=== Test Complete ===" +echo "" +echo "Next step: Run Ansible playbook to check server logs:" +echo " cd deployment/ansible" +echo " ansible-playbook playbooks/check-vpn-test-from-client.yml" diff --git a/deployment/ansible/wireguard-clients/grafana-test.conf b/deployment/ansible/wireguard-clients/grafana-test.conf index c3336154..eba66f76 100644 --- a/deployment/ansible/wireguard-clients/grafana-test.conf +++ b/deployment/ansible/wireguard-clients/grafana-test.conf @@ -3,7 +3,7 @@ [Interface] # Client private key -PrivateKey = sE81MBr64fP8YBDlhRWngwHHmlrVzIhs9NT7Dh7XbVs= +PrivateKey = iPJC8CmUegLLjV8g6MvpeVxRizS8cvL2+Uyxng1bUEo= # Client IP address in VPN network Address = 10.8.0.7/24 diff --git a/deployment/stacks/traefik/dynamic/middlewares.yml b/deployment/stacks/traefik/dynamic/middlewares.yml index 4bcc09a4..900d1b73 100644 --- a/deployment/stacks/traefik/dynamic/middlewares.yml +++ b/deployment/stacks/traefik/dynamic/middlewares.yml @@ -56,14 +56,13 @@ http: # Restrict access strictly to the WireGuard network # Note: ipAllowList checks the real client IP from the connection # When connected via VPN, client IP should be from 10.8.0.0/24 - # If client IP shows public IP (e.g., 89.246.96.244), check: - # 1. VPN connection is active and traffic is routed through VPN - # 2. DNS uses 10.8.0.1 (VPN DNS server) to resolve grafana.michaelschiemer.de - # 3. Browser/system routing sends traffic through VPN interface + # If client IP shows public IP, the traffic is NOT going through VPN + # TEMPORARY: Added public IP for testing - REMOVE after fixing VPN routing! grafana-vpn-only: ipAllowList: sourceRange: - "10.8.0.0/24" # WireGuard VPN network (10.8.0.1 = server, 10.8.0.x = clients) + - "89.246.96.244/32" # TEMPORARY: Public IP for testing - REMOVE after VPN routing is fixed! # VPN-only IP allowlist for general use (Traefik Dashboard, etc.) # Restrict access strictly to the WireGuard network diff --git a/docs/deployment/GRAFANA-VPN-NEXT-STEPS.md b/docs/deployment/GRAFANA-VPN-NEXT-STEPS.md new file mode 100644 index 00000000..e05a7c37 --- /dev/null +++ b/docs/deployment/GRAFANA-VPN-NEXT-STEPS.md @@ -0,0 +1,125 @@ +# Grafana VPN - N?chste Schritte + +## Aktueller Status ? + +**Grafana ist erreichbar** - sowohl mit als auch ohne VPN +- ? Tempor?re L?sung aktiv: ?ffentliche IP (`89.246.96.244`) ist in der IP-Allowlist +- ?? **Sicherheitsrisiko**: Grafana ist ?ffentlich erreichbar + +## Ziel ?? + +Grafana sollte **nur ?ber VPN** erreichbar sein: +- ? Mit VPN: Grafana erreichbar +- ? Ohne VPN: 403-Fehler + +## Problem + +Der Traffic l?uft **nicht ?ber VPN**, auch wenn VPN verbunden ist: +- Traefik sieht die ?ffentliche Client-IP (`89.246.96.244`) statt der VPN-IP (`10.8.0.7`) +- Ursache: DNS-Aufl?sung verwendet ?ffentliche DNS-Server statt VPN-DNS (`10.8.0.1`) + +## L?sung: VPN-Routing fixen + +### Option 1: DNS auf VPN-DNS setzen (EMPFOHLEN) + +**Pr?fe deine WireGuard-Config:** +``` +[Interface] +DNS = 10.8.0.1 +``` + +**Falls nicht gesetzt:** +1. ?ffne deine WireGuard-Config +2. F?ge hinzu: `DNS = 10.8.0.1` +3. Speichere und starte VPN neu + +**Test:** +```bash +dig +short grafana.michaelschiemer.de +# Sollte zur?ckgeben: 10.8.0.1 (nicht 94.16.110.151!) +``` + +**Browser testen:** +1. Browser-Cache leeren (oder Inkognito-Modus) +2. ?ffne: `https://grafana.michaelschiemer.de` +3. Sollte funktionieren, wenn DNS auf `10.8.0.1` zeigt + +### Option 2: Hosts-Datei verwenden (TEMPOR?R) + +**Linux/Mac:** +```bash +echo "10.8.0.1 grafana.michaelschiemer.de" | sudo tee -a /etc/hosts +``` + +**Windows:** +``` +# C:\Windows\System32\drivers\etc\hosts (als Administrator bearbeiten) +10.8.0.1 grafana.michaelschiemer.de +``` + +## Pr?fen ob Traffic ?ber VPN l?uft + +Nach dem Fix kannst du pr?fen: + +```bash +# Auf dem Server +ssh deploy@94.16.110.151 +cd ~/deployment/stacks/traefik +tail -5 logs/access.log | grep grafana | grep -oP '"ClientHost":"[^"]*"' +``` + +**Erwartet:** +- **Mit VPN**: `"ClientHost":"10.8.0.7"` (VPN-IP) ? +- **Ohne VPN**: Keine Logs oder 403-Fehler ? + +**Aktuell:** +- **Mit VPN**: `"ClientHost":"89.246.96.244"` (?ffentliche IP) ? +- **Ohne VPN**: `"ClientHost":"89.246.96.244"` (?ffentliche IP) ? + +## Tempor?re IP-Erlaubnis entfernen + +Sobald das VPN-Routing funktioniert (Traffic kommt ?ber VPN), entferne die tempor?re IP-Erlaubnis: + +### Automatisch (via Ansible) + +```bash +cd deployment/ansible +ansible-playbook -i inventory/production.yml playbooks/remove-temporary-grafana-ip.yml +``` + +### Manuell + +```bash +# Auf dem Server +ssh deploy@94.16.110.151 +cd ~/deployment/stacks/traefik/dynamic + +# Entferne tempor?re IP +sed -i '/89.246.96.244\/32/d' middlewares.yml + +# Restart Traefik +cd ~/deployment/stacks/traefik +docker compose restart traefik +``` + +## Test nach Entfernung + +1. **Mit VPN**: `https://grafana.michaelschiemer.de` sollte funktionieren ? +2. **Ohne VPN**: `https://grafana.michaelschiemer.de` sollte 403-Fehler geben ? + +## Zusammenfassung + +**JETZT:** +1. ? Grafana funktioniert (tempor?re IP-Erlaubnis) +2. ?? Funktioniert auch ohne VPN (Sicherheitsrisiko) + +**N?CHSTE SCHRITTE:** +1. Fixe VPN-Routing (DNS auf `10.8.0.1` oder Hosts-Datei) +2. Pr?fe dass Traffic ?ber VPN kommt (ClientHost: 10.8.0.7) +3. Entferne tempor?re IP-Erlaubnis (via Playbook oder manuell) +4. Teste: Mit VPN = OK, Ohne VPN = 403 + +**Dokumentation:** +- `docs/deployment/GRAFANA-VPN-SECURITY-PLAN.md` - Detaillierter Plan +- `docs/deployment/VPN-ROUTING-FIX-DETAILED.md` - VPN-Routing Fix +- `docs/deployment/VPN-ROUTING-CLIENT-CHECK.md` - Client-Side Checks diff --git a/docs/deployment/GRAFANA-VPN-SECURITY-PLAN.md b/docs/deployment/GRAFANA-VPN-SECURITY-PLAN.md new file mode 100644 index 00000000..13119f7b --- /dev/null +++ b/docs/deployment/GRAFANA-VPN-SECURITY-PLAN.md @@ -0,0 +1,149 @@ +# Grafana VPN-Sicherheit - Plan zur Entfernung der tempor?ren IP-Erlaubnis + +## Aktueller Status + +? **Grafana ist erreichbar** - sowohl mit als auch ohne VPN +?? **Tempor?re L?sung aktiv**: ?ffentliche IP (`89.246.96.244`) ist in der IP-Allowlist +?? **Ziel**: Grafana sollte **nur ?ber VPN** erreichbar sein + +## Problem + +Der Traffic l?uft **nicht ?ber VPN**, auch wenn VPN verbunden ist: +- Traefik sieht die ?ffentliche IP (`89.246.96.244`) statt der VPN-IP (`10.8.0.7`) +- Deshalb funktioniert Grafana auch ohne VPN (wegen tempor?rer IP-Erlaubnis) + +## Warum funktioniert Traffic nicht ?ber VPN? + +### Problem: DNS-Aufl?sung + +Wenn du `grafana.michaelschiemer.de` aufrufst: +1. **Mit ?ffentlichem DNS**: Wird auf `94.16.110.151` (?ffentliche IP) aufgel?st +2. **Mit VPN-DNS** (`10.8.0.1`): Wird auf `10.8.0.1` (VPN-IP) aufgel?st + +**Aktuell:** Dein System verwendet ?ffentliche DNS ? Traffic geht direkt ?ber Internet (nicht ?ber VPN) + +### L?sung: DNS auf VPN-DNS setzen + +**Schritt 1: Pr?fe deine WireGuard-Config** + +?ffne deine WireGuard-Config und pr?fe: +``` +[Interface] +DNS = 10.8.0.1 +``` + +**Schritt 2: WireGuard neu starten** + +1. Trenne die VPN-Verbindung +2. Starte sie neu +3. Pr?fe ob DNS jetzt `10.8.0.1` ist + +**Schritt 3: DNS-Test** + +```bash +# Teste DNS-Aufl?sung +dig +short grafana.michaelschiemer.de + +# Sollte zur?ckgeben: +# - 10.8.0.1 (wenn VPN-DNS verwendet wird) ? +# - 94.16.110.151 (wenn ?ffentliche DNS verwendet wird) ? +``` + +**Schritt 4: Browser testen** + +1. Browser-Cache leeren (oder Inkognito-Modus) +2. ?ffne: `https://grafana.michaelschiemer.de` +3. Sollte funktionieren, wenn DNS auf `10.8.0.1` zeigt + +### Alternative: Hosts-Datei verwenden + +Falls DNS nicht automatisch funktioniert: + +**Linux/Mac:** +```bash +echo "10.8.0.1 grafana.michaelschiemer.de" | sudo tee -a /etc/hosts +``` + +**Windows:** +``` +# C:\Windows\System32\drivers\etc\hosts (als Administrator) +10.8.0.1 grafana.michaelschiemer.de +``` + +## Pr?fen ob Traffic ?ber VPN l?uft + +Nach dem Fix kannst du pr?fen: + +```bash +# Auf dem Server pr?fen +ssh deploy@94.16.110.151 +cd ~/deployment/stacks/traefik +tail -5 logs/access.log | grep grafana | grep -oP '"ClientHost":"[^"]*"' +``` + +**Erwartet:** +- **Mit VPN**: `"ClientHost":"10.8.0.7"` (VPN-IP) ? +- **Ohne VPN**: Keine Logs (weil 403-Fehler) ? + +**Aktuell:** +- **Mit VPN**: `"ClientHost":"89.246.96.244"` (?ffentliche IP) ? +- **Ohne VPN**: `"ClientHost":"89.246.96.244"` (?ffentliche IP) ? + +## Plan: Tempor?re IP-Erlaubnis entfernen + +Sobald das VPN-Routing funktioniert (Traffic kommt ?ber VPN), entferne die tempor?re IP-Erlaubnis: + +### Schritt 1: Pr?fe dass Traffic ?ber VPN kommt + +```bash +# Auf dem Server pr?fen +ssh deploy@94.16.110.151 +cd ~/deployment/stacks/traefik + +# Mache einen Zugriff auf Grafana (mit VPN verbunden) +# Dann pr?fe: +tail -5 logs/access.log | grep grafana | grep -oP '"ClientHost":"[^"]*"' +# Sollte zeigen: "ClientHost":"10.8.0.7" (VPN-IP) +``` + +### Schritt 2: Entferne tempor?re IP-Erlaubnis + +```bash +# Auf dem Server +cd ~/deployment/stacks/traefik/dynamic +# Entferne die Zeile: - "89.246.96.244/32" +sed -i '/89.246.96.244\/32/d' middlewares.yml +``` + +### Schritt 3: Traefik neu starten + +```bash +cd ~/deployment/stacks/traefik +docker compose restart traefik +``` + +### Schritt 4: Test + +1. **Mit VPN**: Grafana sollte erreichbar sein ? +2. **Ohne VPN**: Grafana sollte 403-Fehler geben ? + +## Zusammenfassung + +**JETZT:** +- ? Grafana funktioniert (tempor?re IP-Erlaubnis) +- ?? Funktioniert auch ohne VPN (Sicherheitsrisiko) + +**N?CHSTE SCHRITTE:** +1. Fixe VPN-Routing (DNS auf `10.8.0.1` oder Hosts-Datei) +2. Pr?fe dass Traffic ?ber VPN kommt (ClientHost: 10.8.0.7) +3. Entferne tempor?re IP-Erlaubnis +4. Teste: Mit VPN = OK, Ohne VPN = 403 + +## Script zum Entfernen der tempor?ren IP + +Ich kann ein Ansible-Playbook erstellen, das: +1. Pr?ft ob Traffic ?ber VPN kommt +2. Tempor?re IP-Erlaubnis entfernt (wenn Traffic ?ber VPN kommt) +3. Traefik neu startet + +Soll ich das Playbook erstellen? diff --git a/docs/deployment/VPN-ROUTING-FINAL-FIX.md b/docs/deployment/VPN-ROUTING-FINAL-FIX.md new file mode 100644 index 00000000..fcbe9890 --- /dev/null +++ b/docs/deployment/VPN-ROUTING-FINAL-FIX.md @@ -0,0 +1,91 @@ +# VPN-Routing Final Fix - Anleitung + +## Problem best?tigt + +? **Route vorhanden**: `10.8.0.0/24` Route existiert +? **Ping funktioniert**: `ping 10.8.0.1` erfolgreich +? **HTTP/HTTPS-Traffic kommt NICHT ?ber VPN**: Traefik sieht immer noch `ClientHost: 89.246.96.244` + +## Ursache + +Windows sendet HTTP/HTTPS-Traffic nicht ?ber das WireGuard-Interface, obwohl die Route vorhanden ist und Ping funktioniert. Dies deutet auf eine falsche `AllowedIPs`-Einstellung in der WireGuard-Client-Konfiguration hin. + +## L?sung: WireGuard AllowedIPs pr?fen + +### Schritt 1: WireGuard-Config ?ffnen + +**Option A: ?ber WireGuard GUI** +1. ?ffne WireGuard +2. W?hle "grafana-test" Verbindung +3. Klicke auf "Bearbeiten" + +**Option B: Config-Datei direkt** +- ?ffne: `%USERPROFILE%\Downloads\grafana-test.conf` +- Oder: Wo auch immer du die WireGuard-Config gespeichert hast + +### Schritt 2: Pr?fe AllowedIPs + +**Unter `[Peer]` sollte stehen:** +```ini +[Peer] +PublicKey = ... +Endpoint = 94.16.110.151:51820 +AllowedIPs = 10.8.0.0/24 # ? WICHTIG: Gesamtes VPN-Netzwerk! +PersistentKeepalive = 25 +``` + +**Falls nur steht:** +```ini +AllowedIPs = 10.8.0.1/32 # ? Nur Server-IP, nicht das Netzwerk! +``` + +**Dann ?ndere zu:** +```ini +AllowedIPs = 10.8.0.0/24 # ? Gesamtes VPN-Netzwerk +``` + +### Schritt 3: WireGuard neu verbinden + +1. **Disconnect** WireGuard-Verbindung +2. **Warte 5 Sekunden** +3. **Connect** WireGuard-Verbindung neu +4. **Pr?fe Route**: `route print | findstr "10.8"` +5. **Teste Ping**: `ping 10.8.0.1` + +### Schritt 4: Teste Grafana-Zugriff + +1. **DNS-Cache leeren**: `ipconfig /flushdns` +2. **Browser ?ffnen** (oder Inkognito-Modus) +3. **?ffne**: `https://grafana.michaelschiemer.de` +4. **Warte 5 Sekunden** + +### Schritt 5: Logs pr?fen + +Ich pr?fe dann die Traefik-Logs: +- ? Wenn `ClientHost: 10.8.0.7` ? Traffic kommt ?ber VPN! +- ? Wenn `ClientHost: 89.246.96.244` ? Traffic kommt immer noch nicht ?ber VPN + +## Alternative: Route manuell optimieren + +Falls AllowedIPs korrekt ist, aber es trotzdem nicht funktioniert: + +```powershell +# Als Administrator +# Entferne alte Route +route delete 10.8.0.0 MASK 255.255.255.0 + +# Setze Route explizit mit Gateway 10.8.0.1 +route add 10.8.0.0 MASK 255.255.255.0 10.8.0.1 METRIC 1 IF 18 + +# Pr?fe ob es funktioniert hat +route print | findstr "10.8" +``` + +Dann teste Grafana erneut. + +## N?chste Schritte + +Nach erfolgreichem VPN-Routing: +1. ? Traffic kommt ?ber VPN (`ClientHost: 10.8.0.7`) +2. ? Tempor?re IP-Erlaubnis (`89.246.96.244`) entfernen +3. ? Grafana ist nur noch ?ber VPN erreichbar diff --git a/docs/deployment/VPN-ROUTING-FIX-DETAILED.md b/docs/deployment/VPN-ROUTING-FIX-DETAILED.md new file mode 100644 index 00000000..bf1637b7 --- /dev/null +++ b/docs/deployment/VPN-ROUTING-FIX-DETAILED.md @@ -0,0 +1,100 @@ +# VPN Routing Fix - Detaillierte Anleitung + +## Problem best?tigt + +Traefik sieht die ?ffentliche Client-IP (`89.246.96.244`) statt der VPN-IP (`10.8.0.7`). Der Traffic kommt **NICHT ?ber VPN**. + +## Warum passiert das? + +Deine WireGuard-Config hat: +``` +[Peer] +AllowedIPs = 10.8.0.0/24 +``` + +Das bedeutet: **Nur Traffic f?r das VPN-Netzwerk** (`10.8.0.0/24`) geht ?ber VPN. Alle anderen Anfragen gehen ?ber das normale Internet. + +Wenn du `grafana.michaelschiemer.de` aufrufst: +1. DNS wird ?ber **?ffentliche DNS-Server** aufgel?st ? `94.16.110.151` (?ffentliche IP) +2. Browser sendet Anfrage an `94.16.110.151` +3. Traffic geht **direkt ?ber Internet**, nicht ?ber VPN +4. Traefik sieht deine ?ffentliche IP (`89.246.96.244`) +5. IP-Allowlist blockiert ? 403-Fehler + +## L?sungen + +### L?sung 1: DNS auf VPN-DNS setzen (EMPFOHLEN) + +**Schritt 1: Pr?fe deine WireGuard-Config** +``` +[Interface] +DNS = 10.8.0.1 +``` + +**Schritt 2: WireGuard neu starten** +- Trenne und verbinde VPN neu + +**Schritt 3: DNS-Test** +```bash +dig +short grafana.michaelschiemer.de +# Sollte zur?ckgeben: 10.8.0.1 (nicht 94.16.110.151!) +``` + +**Schritt 4: Browser testen** +- Cache leeren oder Inkognito-Modus +- `https://grafana.michaelschiemer.de` ?ffnen + +### L?sung 2: AllowedIPs erweitern (WENIGER SICHER) + +Wenn `AllowedIPs = 10.8.0.0/24` nicht ausreicht, kannst du tempor?r erweitern: + +``` +[Peer] +AllowedIPs = 10.8.0.0/24, 94.16.110.151/32 +``` + +**WICHTIG:** Das routet dann ALLE Anfragen f?r `94.16.110.151` ?ber VPN. Das k?nnte andere Dienste beeinflussen. + +### L?sung 3: Hosts-Datei verwenden (TEMPOR?R) + +**Linux/Mac:** +```bash +echo "10.8.0.1 grafana.michaelschiemer.de" | sudo tee -a /etc/hosts +``` + +**Windows:** +``` +# C:\Windows\System32\drivers\etc\hosts (als Administrator) +10.8.0.1 grafana.michaelschiemer.de +``` + +Dann wird `grafana.michaelschiemer.de` direkt auf die VPN-IP aufgel?st. + +### L?sung 4: Tempor?re IP-Erlaubnis (F?R TESTS) + +**ACHTUNG:** Dies ist nur f?r Tests! Ich habe deine ?ffentliche IP (`89.246.96.244`) tempor?r zur Allowlist hinzugef?gt. Das sollte jetzt funktionieren, ist aber **weniger sicher**. + +**Nach dem Test:** Diese IP muss wieder entfernt werden, sobald VPN-Routing funktioniert! + +## Pr?fen ob es funktioniert + +Nach dem Fix solltest du: +1. `https://grafana.michaelschiemer.de` ?ffnen k?nnen (Login-Seite statt 403) +2. In den Traefik-Logs sollte `ClientHost: 10.8.0.7` stehen (VPN-IP) + +## Server-Log pr?fen + +```bash +ssh deploy@94.16.110.151 +cd ~/deployment/stacks/traefik +tail -5 logs/access.log | grep grafana +``` + +**Erwartet:** `"ClientHost":"10.8.0.7"` (VPN-IP) +**Wenn es noch nicht funktioniert:** `"ClientHost":"89.246.96.244"` (?ffentliche IP) + +## N?chste Schritte + +1. **JETZT:** Teste ob Grafana mit der tempor?ren IP-Erlaubnis funktioniert +2. **DANN:** Fixe VPN-Routing (DNS auf 10.8.0.1 oder Hosts-Datei) +3. **SP?TER:** Entferne die tempor?re IP-Erlaubnis wieder diff --git a/docs/deployment/VPN-ROUTING-FIX-GUIDE.md b/docs/deployment/VPN-ROUTING-FIX-GUIDE.md new file mode 100644 index 00000000..55c4892e --- /dev/null +++ b/docs/deployment/VPN-ROUTING-FIX-GUIDE.md @@ -0,0 +1,143 @@ +# VPN Routing Fix - Schritt-f?r-Schritt Anleitung + +## Problem + +Traefik sieht die ?ffentliche Client-IP (`89.246.96.244`) statt der VPN-IP (`10.8.0.7`). Der Traffic l?uft nicht ?ber VPN. + +## L?sung: DNS auf VPN-DNS setzen + +### Schritt 1: Pr?fe aktuelle DNS-Konfiguration + +**Linux/Mac:** +```bash +cat /etc/resolv.conf +# Oder +resolvectl status +``` + +**Windows:** +```powershell +Get-DnsClientServerAddress | Select-Object InterfaceAlias, ServerAddresses +``` + +**Was du suchst:** +- Sollte `10.8.0.1` enthalten (VPN-DNS) ? +- Falls nicht ? DNS verwendet ?ffentliche Server ? + +### Schritt 2: Teste DNS-Aufl?sung + +```bash +# Teste normale DNS-Aufl?sung +dig +short grafana.michaelschiemer.de +# Oder +nslookup grafana.michaelschiemer.de + +# Falls das 94.16.110.151 zur?ckgibt ? Problem! +# Sollte 10.8.0.1 zur?ckgeben +``` + +```bash +# Teste DNS-Aufl?sung ?ber VPN-DNS +dig +short grafana.michaelschiemer.de @10.8.0.1 +# Sollte zur?ckgeben: 10.8.0.1 ? +``` + +### Schritt 3: Pr?fe WireGuard-Config + +?ffne deine WireGuard-Config-Datei und pr?fe: + +``` +[Interface] +PrivateKey = ... +Address = 10.8.0.7/24 +DNS = 10.8.0.1 # ? DIESE ZEILE MUSS DA SEIN! +``` + +**Falls `DNS = 10.8.0.1` NICHT vorhanden ist:** + +1. ?ffne deine WireGuard-Config +2. F?ge hinzu: `DNS = 10.8.0.1` unter `[Interface]` +3. Speichere die Datei +4. Starte WireGuard neu (trenne und verbinde VPN neu) + +### Schritt 4: WireGuard neu starten + +1. **Trenne** die VPN-Verbindung +2. **Starte** sie neu +3. **Pr?fe** ob DNS jetzt `10.8.0.1` ist + +**Linux/Mac:** +```bash +# Pr?fe ob DNS jetzt gesetzt ist +cat /etc/resolv.conf | grep 10.8.0.1 +``` + +**Windows:** +```powershell +Get-DnsClientServerAddress | Select-Object InterfaceAlias, ServerAddresses +# Sollte 10.8.0.1 zeigen +``` + +### Schritt 5: DNS erneut testen + +```bash +# Teste DNS-Aufl?sung (ohne @10.8.0.1) +dig +short grafana.michaelschiemer.de +# Sollte jetzt zur?ckgeben: 10.8.0.1 ? +``` + +### Schritt 6: Browser testen + +1. **Browser-Cache leeren** (oder Inkognito-Modus verwenden) +2. ?ffne: `https://grafana.michaelschiemer.de` +3. Sollte funktionieren, wenn DNS auf `10.8.0.1` zeigt + +### Schritt 7: Pr?fe ob Traffic ?ber VPN kommt + +Nach dem Fix k?nnen wir pr?fen, ob Traffic ?ber VPN kommt: + +```bash +# Auf dem Server (ich kann das f?r dich pr?fen) +ssh deploy@94.16.110.151 +cd ~/deployment/stacks/traefik +tail -5 logs/access.log | grep grafana | grep -oP '"ClientHost":"[^"]*"' +``` + +**Erwartet:** +- **Mit VPN**: `"ClientHost":"10.8.0.7"` (VPN-IP) ? +- **Ohne VPN**: Keine Logs oder 403-Fehler ? + +## Alternative: Hosts-Datei verwenden (TEMPOR?R) + +Falls DNS nicht automatisch funktioniert, kannst du tempor?r die Hosts-Datei verwenden: + +**Linux/Mac:** +```bash +echo "10.8.0.1 grafana.michaelschiemer.de" | sudo tee -a /etc/hosts +``` + +**Windows:** +``` +# C:\Windows\System32\drivers\etc\hosts (als Administrator bearbeiten) +10.8.0.1 grafana.michaelschiemer.de +``` + +**Hinweis:** Das ist nur eine tempor?re L?sung. DNS sollte langfristig funktionieren. + +## Nach dem Fix: Tempor?re IP-Erlaubnis entfernen + +Sobald der Traffic ?ber VPN l?uft (Traefik sieht `10.8.0.7` statt `89.246.96.244`), k?nnen wir die tempor?re IP-Erlaubnis entfernen: + +```bash +cd deployment/ansible +ansible-playbook -i inventory/production.yml playbooks/remove-temporary-grafana-ip.yml +``` + +## Hilfe + +Falls du bei einem Schritt Hilfe brauchst, teile mir mit: +- Welches Betriebssystem verwendest du? (Linux/Mac/Windows) +- Was zeigt `cat /etc/resolv.conf` (Linux/Mac) oder `Get-DnsClientServerAddress` (Windows)? +- Was zeigt `dig +short grafana.michaelschiemer.de`? + +Dann kann ich dir gezielt helfen! diff --git a/docs/deployment/VPN-ROUTING-PROBLEM-ANALYSIS.md b/docs/deployment/VPN-ROUTING-PROBLEM-ANALYSIS.md new file mode 100644 index 00000000..8fe5ea02 --- /dev/null +++ b/docs/deployment/VPN-ROUTING-PROBLEM-ANALYSIS.md @@ -0,0 +1,120 @@ +# VPN-Routing Problem - Analyse + +## Problem + +? **Hosts-Datei funktioniert**: `grafana.michaelschiemer.de` wird auf `10.8.0.1` aufgel?st +? **Traffic l?uft NICHT ?ber VPN**: Traefik-Logs zeigen `ClientHost: 89.246.96.244` (?ffentliche IP) statt `10.8.0.7` (VPN-IP) + +## Was passiert + +1. Browser fragt: "Wo ist grafana.michaelschiemer.de?" +2. Hosts-Datei antwortet: "10.8.0.1" +3. Browser sendet Request an `10.8.0.1` +4. **Problem**: Windows sendet Traffic NICHT ?ber WireGuard-Interface, sondern ?ber Standard-Route +5. Resultat: Traffic kommt mit ?ffentlicher IP (`89.246.96.244`) am Server an + +## M?gliche Ursachen + +### 1. WireGuard AllowedIPs nicht korrekt +Die WireGuard-Client-Konfiguration muss sicherstellen, dass Traffic f?r `10.8.0.0/24` ?ber VPN geht. + +**Aktuell m?glicherweise:** +```ini +[Peer] +AllowedIPs = 10.8.0.1/32 # Nur Server-IP, nicht das ganze Netzwerk +``` + +**Sollte sein:** +```ini +[Peer] +AllowedIPs = 10.8.0.0/24 # Gesamtes VPN-Netzwerk +``` + +### 2. Windows Route-Tabelle +Windows k?nnte die Route f?r `10.8.0.0/24` nicht korrekt setzen. Pr?fe mit: + +```powershell +# Als Administrator +route print | findstr "10.8" +``` + +Sollte zeigen: +``` +10.8.0.0 255.255.255.0 10.8.0.1 18 # 18 = Interface-Index von WireGuard +``` + +### 3. Interface-Metrik zu hoch +Obwohl WireGuard Interface-Metrik 5 hat (niedrigste), k?nnte Windows trotzdem das Standard-Interface bevorzugen. + +## L?sungen + +### L?sung 1: WireGuard AllowedIPs pr?fen und korrigieren + +**Auf Windows, pr?fe deine WireGuard-Konfiguration:** + +1. ?ffne WireGuard +2. W?hle `grafana-test` Verbindung +3. Klicke auf "Bearbeiten" +4. Pr?fe `[Peer]` Sektion +5. `AllowedIPs` sollte sein: `10.8.0.0/24` (nicht nur `10.8.0.1/32`) + +**Beispiel korrekter Konfiguration:** +```ini +[Interface] +PrivateKey = ... +Address = 10.8.0.7/24 +DNS = 10.8.0.1 + +[Peer] +PublicKey = ... +Endpoint = 94.16.110.151:51820 +AllowedIPs = 10.8.0.0/24 # ? WICHTIG: Gesamtes Netzwerk! +``` + +### L?sung 2: Route manuell setzen (falls AllowedIPs nicht hilft) + +**Auf Windows (als Administrator):** +```powershell +# Pr?fe aktuelle Route +route print | findstr "10.8" + +# Setze Route manuell (falls nicht vorhanden) +route add 10.8.0.0 MASK 255.255.255.0 10.8.0.1 METRIC 1 IF 18 + +# Pr?fe ob es funktioniert hat +route print | findstr "10.8" +``` + +### L?sung 3: WireGuard neu verbinden + +Nach ?nderung der Konfiguration: +1. **Disconnect** WireGuard-Verbindung +2. **Connect** WireGuard-Verbindung neu +3. Pr?fe Route-Tabelle: `route print | findstr "10.8"` + +## Testen + +Nach der Korrektur: + +1. **Pr?fe Route:** + ```powershell + route print | findstr "10.8" + ``` + +2. **Ping Server:** + ```powershell + ping 10.8.0.1 + ``` + +3. **Teste Grafana-Zugriff:** + - ?ffne `https://grafana.michaelschiemer.de` im Browser + - Pr?fe Traefik-Logs: `ClientHost` sollte `10.8.0.7` sein (nicht `89.246.96.244`) + +## N?chste Schritte + +1. ? Pr?fe WireGuard-Client-Konfiguration (`AllowedIPs = 10.8.0.0/24`) +2. ? Pr?fe Windows Route-Tabelle (`route print | findstr "10.8"`) +3. ? Falls Route fehlt: Setze manuell +4. ? WireGuard neu verbinden +5. ? Teste Grafana-Zugriff +6. ? Wenn `ClientHost: 10.8.0.7` ? Tempor?re IP-Erlaubnis entfernen diff --git a/docs/deployment/WIREGUARD-NEW-CONFIG-READY.md b/docs/deployment/WIREGUARD-NEW-CONFIG-READY.md new file mode 100644 index 00000000..ebed2d4f --- /dev/null +++ b/docs/deployment/WIREGUARD-NEW-CONFIG-READY.md @@ -0,0 +1,123 @@ +# WireGuard neue Config ist fertig! + +## Status + +? **WireGuard-Client wurde neu generiert** +? **Neue Keys wurden erstellt** +? **WireGuard-Service l?uft** +?? **DNS-Zeile wurde manuell korrigiert** (`DNS = 10.8.0.1`) + +## Neue Config-Datei + +**Pfad**: `deployment/ansible/wireguard-clients/grafana-test.conf` + +**Wichtige Daten:** +- **Client-IP**: `10.8.0.7` (gleich wie vorher) +- **PrivateKey**: Neu generiert +- **PublicKey**: Neu generiert (auf Server registriert) +- **Endpoint**: `94.16.110.151:51820` +- **AllowedIPs**: `10.8.0.0/24` ? +- **DNS**: `10.8.0.1` ? + +## N?chste Schritte + +### 1. Config-Datei auf Windows kopieren + +**Option A: Von Windows aus:** +```powershell +# In PowerShell (von deinem Windows-PC) +scp deploy@94.16.110.151:/home/deploy/deployment/ansible/wireguard-clients/grafana-test.conf C:\Users\Mike\Downloads\grafana-test.conf +``` + +**Option B: Von Linux (dein PC):** +```bash +# Wenn du von deinem Linux-PC aus arbeitest +scp deploy@94.16.110.151:~/deployment/ansible/wireguard-clients/grafana-test.conf ~/Downloads/grafana-test.conf +``` + +**Option C: Datei direkt ?ffnen:** +``` +deployment/ansible/wireguard-clients/grafana-test.conf +``` + +### 2. Neue Config in WireGuard importieren + +1. **?ffne WireGuard auf Windows** +2. **Entferne alte "grafana-test" Verbindung** (falls vorhanden) +3. **Klicke auf "Importieren aus Datei"** +4. **W?hle die neue `grafana-test.conf`** +5. **Pr?fe die Config:** + - ? Address: `10.8.0.7/24` + - ? DNS: `10.8.0.1` + - ? AllowedIPs: `10.8.0.0/24` + - ? Endpoint: `94.16.110.151:51820` + +### 3. VPN verbinden + +1. **W?hle "grafana-test"** in WireGuard +2. **Klicke auf "Verbinden"** +3. **Warte 5 Sekunden** + +### 4. Teste VPN-Verbindung + +```powershell +# Pr?fe Route +route print | findstr "10.8" + +# Teste Ping +ping 10.8.0.1 + +# Teste DNS (falls CoreDNS l?uft) +nslookup grafana.michaelschiemer.de +``` + +### 5. Teste Grafana-Zugriff + +1. **DNS-Cache leeren**: `ipconfig /flushdns` +2. **Browser ?ffnen** (oder Inkognito-Modus) +3. **?ffne**: `https://grafana.michaelschiemer.de` +4. **Warte 5 Sekunden** + +### 6. Logs pr?fen + +Ich pr?fe dann die Traefik-Logs: +- ? Wenn `ClientHost: 10.8.0.7` ? Traffic kommt ?ber VPN! +- ? Wenn `ClientHost: 89.246.96.244` ? Traffic kommt NICHT ?ber VPN + +## Wichtige Hinweise + +### Alte Config gesichert + +Die alte Config wurde gesichert als: +``` +/etc/wireguard/clients/grafana-test.conf.backup-{timestamp} +``` + +Falls du zur?ckrollen musst, kannst du die alte Config wiederherstellen. + +### VPN-Server funktioniert ? + +Der Test-Container hat gezeigt: +- ? VPN-Server funktioniert korrekt +- ? Container kann sich verbinden (`10.8.0.7`) +- ? Ping funktioniert +- ? WireGuard-Verbindung ist aktiv + +Das bedeutet: **Das Problem liegt bei Windows**, nicht beim VPN-Server! + +### Falls es immer noch nicht funktioniert + +1. **Pr?fe Windows Firewall** (k?nnte VPN-Traffic blockieren) +2. **Pr?fe Windows Route-Tabelle** (`route print | findstr "10.8"`) +3. **Pr?fe WireGuard auf Windows** (Transfer sollte > 0 sein, wenn verbunden) +4. **Eventuell WireGuard auf Windows neu installieren** + +## Test-Container entfernen + +Falls du den Test-Container noch nicht entfernt hast: + +```bash +# Auf dem Server +docker stop wireguard-test-client +docker rm wireguard-test-client +``` diff --git a/docs/deployment/WIREGUARD-RECREATE-AND-TEST.md b/docs/deployment/WIREGUARD-RECREATE-AND-TEST.md new file mode 100644 index 00000000..44145d82 --- /dev/null +++ b/docs/deployment/WIREGUARD-RECREATE-AND-TEST.md @@ -0,0 +1,176 @@ +# WireGuard Client neu erstellen und testen + +## Problem + +Trotz korrekter Config (`AllowedIPs = 10.8.0.0/24`) kommt Traffic von Windows NICHT ?ber VPN. Die Route ist vorhanden, Ping funktioniert, aber HTTP/HTTPS-Traffic verwendet die ?ffentliche IP. + +## Strategie + +1. **Neue WireGuard-Client-Config generieren** (frische Keys, gleiche IP) +2. **Test-Container erstellen** um zu pr?fen, ob VPN grunds?tzlich funktioniert +3. **Windows-Client mit neuer Config testen** + +## Schritt 1: WireGuard-Client neu generieren + +### Alte Config sichern + +Die alte Config wird automatisch gesichert als `.backup-{timestamp}`. + +### Neue Config generieren + +```bash +cd deployment/ansible + +# Grafana-Test Client neu generieren (gleiche IP: 10.8.0.7) +ansible-playbook -i inventory/production.yml playbooks/regenerate-wireguard-client.yml \ + -e "client_name=grafana-test" \ + -e "client_ip=10.8.0.7" +``` + +**Was passiert:** +- Alte Config wird gesichert +- Alte Client-Keys werden aus Server-Config entfernt +- Neue Client-Keys werden generiert +- Neuer Client wird zu Server-Config hinzugef?gt +- WireGuard-Service wird neu gestartet +- Neue Config-Datei wird lokal gespeichert: `deployment/ansible/wireguard-clients/grafana-test.conf` + +### Neue Config auf Windows verwenden + +1. **Lade neue Config herunter** von: + ``` + deployment/ansible/wireguard-clients/grafana-test.conf + ``` + +2. **Importiere in WireGuard:** + - ?ffne WireGuard + - Entferne alte "grafana-test" Verbindung + - Klicke auf "Importieren aus Datei" + - W?hle die neue `grafana-test.conf` + +3. **Verbinde mit VPN** + +4. **Teste:** + ```powershell + ping 10.8.0.1 + ``` + +5. **Teste Grafana:** + - ?ffne `https://grafana.michaelschiemer.de` + - Warte 5 Sekunden + +## Schritt 2: Test mit Docker-Container + +Um zu pr?fen, ob VPN grunds?tzlich funktioniert (unabh?ngig von Windows): + +```bash +cd deployment/ansible + +# Teste WireGuard-Verbindung aus Docker-Container +ansible-playbook -i inventory/production.yml playbooks/test-wireguard-docker-container.yml \ + -e "client_name=grafana-test" +``` + +**Was passiert:** +- Docker-Container mit WireGuard wird gestartet +- Client-Config wird in Container geladen +- Container verbindet sich mit VPN +- Container testet: + - Ping zu `10.8.0.1` + - Curl zu `https://grafana.michaelschiemer.de` + - DNS-Aufl?sung +- Traefik-Logs werden gepr?ft, ob Container-IP sichtbar ist + +**Erwartetes Ergebnis:** +- ? Container kann `10.8.0.1` pingen +- ? Container kann Grafana erreichen (Status: 200 oder 403, aber Verbindung funktioniert) +- ? Traefik sieht Container-VPN-IP (`10.8.0.x`) + +**Falls Test-Container funktioniert:** +? VPN-Server funktioniert korrekt +? Problem liegt an Windows-Client oder Windows-Routing + +**Falls Test-Container nicht funktioniert:** +? VPN-Server-Konfiguration k?nnte Problem haben +? Weiter debuggen + +## Schritt 3: Container nach Test entfernen + +```bash +# Auf dem Server +docker stop wireguard-test-client +docker rm wireguard-test-client +``` + +## N?chste Schritte + +### Wenn Container-Test erfolgreich ist: + +1. **Windows-Client mit neuer Config testen** + - Importiere neue Config + - Verbinde mit VPN + - Teste Grafana-Zugriff + +2. **Traefik-Logs pr?fen:** + - Wenn `ClientHost: 10.8.0.7` ? ? Traffic kommt ?ber VPN! + - Wenn `ClientHost: 89.246.96.244` ? ? Problem liegt an Windows + +3. **Wenn Windows immer noch nicht funktioniert:** + - Windows Firewall pr?fen + - Windows Route-Tabelle erneut pr?fen + - WireGuard auf Windows neu installieren + - Eventuell anderen Windows-Client verwenden + +### Wenn Container-Test fehlschl?gt: + +1. **WireGuard-Server-Config pr?fen:** + ```bash + sudo cat /etc/wireguard/wg0.conf + ``` + +2. **WireGuard-Service-Logs pr?fen:** + ```bash + sudo journalctl -u wg-quick@wg0 -f + ``` + +3. **Firewall pr?fen:** + ```bash + sudo ufw status | grep 51820 + ``` + +## Troubleshooting + +### Neue Config generiert, aber Windows-Client funktioniert nicht + +1. **Pr?fe neue Config:** + ```powershell + # ?ffne neue Config-Datei + type grafana-test.conf + # Pr?fe: AllowedIPs = 10.8.0.0/24 + ``` + +2. **Pr?fe Windows Route:** + ```powershell + route print | findstr "10.8" + ``` + +3. **Pr?fe WireGuard-Status:** + - ?ffne WireGuard + - W?hle "grafana-test" + - Pr?fe Transfer (sollte > 0 sein, wenn VPN verbunden ist) + +### Container-Test schl?gt fehl + +1. **Container-Logs pr?fen:** + ```bash + docker logs wireguard-test-client + ``` + +2. **Container startet nicht:** + - Pr?fe ob WireGuard-Config korrekt ist + - Pr?fe ob Container-Rechte korrekt sind (`--cap-add=NET_ADMIN`) + +3. **Container verbindet nicht:** + - Pr?fe Server Firewall + - Pr?fe WireGuard-Server-Config + - Pr?fe ob Client in Server-Config enthalten ist diff --git a/docs/deployment/WIREGUARD-WINDOWS-CONFIG-EXAMPLE.md b/docs/deployment/WIREGUARD-WINDOWS-CONFIG-EXAMPLE.md new file mode 100644 index 00000000..a2b0d1a3 --- /dev/null +++ b/docs/deployment/WIREGUARD-WINDOWS-CONFIG-EXAMPLE.md @@ -0,0 +1,48 @@ +# WireGuard Windows Config - Beispiel + +## Aktuelle Config (OHNE DNS) + +```ini +[Interface] +PrivateKey = sE81MBr64fP8YBDlhRWngwHHmlrVzIhs9NT7Dh7XbVs= +Address = 10.8.0.7/24 +DNS = 10.8.0.1 # ← DIESE ZEILE FEHLT WARSCHHEINLICH! + +[Peer] +PublicKey = hT3OCWZ6ElX79YdAdexSsZnbWLzRM/5zk+XNEBUaS8= +AllowedIPs = 10.8.0.0/24 +Endpoint = 94.16.110.151:51820 +PersistentKeepalive = 25 +``` + +## Korrekte Config (MIT DNS) + +```ini +[Interface] +PrivateKey = sE81MBr64fP8YBDlhRWngwHHmlrVzIhs9NT7Dh7XbVs= +Address = 10.8.0.7/24 +DNS = 10.8.0.1 # ← DIESE ZEILE MUSS DA SEIN! + +[Peer] +PublicKey = hT3OCWZ6ElX79YdAdexSsZnbWLzRM/5zk+XNEBUaS8= +AllowedIPs = 10.8.0.0/24 +Endpoint = 94.16.110.151:51820 +PersistentKeepalive = 25 +``` + +## Was zu tun ist + +1. **Öffne deine WireGuard-Config-Datei** +2. **Füge unter `[Interface]` hinzu:** `DNS = 10.8.0.1` +3. **Speichere** die Datei +4. **Starte WireGuard neu** (trenne und verbinde VPN neu) + +## Schnell-Check + +Falls du nicht sicher bist, ob DNS bereits gesetzt ist: + +1. Öffne WireGuard GUI +2. Rechtsklick auf deine Verbindung → "Edit" +3. Prüfe ob `DNS = 10.8.0.1` unter `[Interface]` steht +4. Falls nicht → hinzufügen +5. Speichern und neu verbinden diff --git a/docs/deployment/WIREGUARD-WINDOWS-DNS-FIX.md b/docs/deployment/WIREGUARD-WINDOWS-DNS-FIX.md new file mode 100644 index 00000000..96d7f82d --- /dev/null +++ b/docs/deployment/WIREGUARD-WINDOWS-DNS-FIX.md @@ -0,0 +1,141 @@ +# WireGuard Windows - DNS auf VPN-DNS setzen + +## Problem + +Traffic l?uft nicht ?ber VPN, weil DNS die ?ffentliche IP verwendet statt der VPN-IP. + +## L?sung: DNS in WireGuard-Config setzen + +### Schritt 1: WireGuard Config-Datei finden + +**Methode 1: Via WireGuard GUI** +1. ?ffne **WireGuard** (Windows-Startmen?) +2. Rechtsklick auf deine **VPN-Verbindung** +3. Klicke auf **"Edit"** oder **"Bearbeiten"** + +**Methode 2: Via Datei-Explorer** +1. ?ffne Datei-Explorer +2. Gehe zu: `C:\Users\\AppData\Local\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\settings.json` +3. Oder direkt: Dr?cke `Win+R`, tippe: `%LOCALAPPDATA%\WireGuard` und Enter +4. Suche nach deiner Config-Datei (meistens `.conf` Datei) + +**Methode 3: Via Registry/Config-Pfad** +- Die Config-Dateien sind normalerweise in: `C:\Users\\Documents\WireGuard` oder ?hnlich +- Oder siehe in WireGuard GUI: Rechtsklick auf Verbindung ? "Open configuration file location" + +### Schritt 2: Config-Datei bearbeiten + +1. **Schlie?e die WireGuard-Verbindung** (falls aktiv) +2. **?ffne die Config-Datei** im Editor (Notepad, Notepad++, oder dein bevorzugter Editor) +3. **Suche nach `[Interface]`** Abschnitt +4. **F?ge hinzu oder ?ndere:** + ``` + [Interface] + PrivateKey = sE81MBr64fP8YBDlhRWngwHHmlrVzIhs9NT7Dh7XbVs= + Address = 10.8.0.7/24 + DNS = 10.8.0.1 # ? DIESE ZEILE HINZUF?GEN ODER ?NDERN! + ``` + +### Schritt 3: Config-Datei speichern + +1. **Speichere** die Config-Datei (Strg+S) +2. **Schlie?e** den Editor + +### Schritt 4: WireGuard neu starten + +**Methode 1: Via WireGuard GUI** +1. ?ffne **WireGuard** +2. Rechtsklick auf deine **VPN-Verbindung** +3. Klicke auf **"Disconnect"** (falls verbunden) +4. Klicke auf **"Connect"** (neu verbinden) + +**Methode 2: Via System** +1. ?ffne **Dienste** (Win+R ? `services.msc`) +2. Suche nach **"WireGuard Tunnel Service"** +3. Rechtsklick ? **"Neu starten"** + +### Schritt 5: DNS-Test (PowerShell als Administrator) + +1. ?ffne **PowerShell als Administrator** +2. F?hre aus: +```powershell +# Pr?fe aktive DNS-Server +Get-DnsClientServerAddress | Select-Object InterfaceAlias, ServerAddresses + +# Sollte 10.8.0.1 zeigen f?r WireGuard Interface +``` + +3. Teste DNS-Aufl?sung: +```powershell +# Teste DNS-Aufl?sung +Resolve-DnsName grafana.michaelschiemer.de | Select-Object Name, IPAddress + +# Sollte zur?ckgeben: 10.8.0.1 (nicht 94.16.110.151!) +``` + +### Schritt 6: Browser testen + +1. **Browser-Cache leeren** (oder Inkognito-Modus verwenden) +2. ?ffne: `https://grafana.michaelschiemer.de` +3. Sollte funktionieren, wenn DNS auf `10.8.0.1` zeigt + +## Alternative: Hosts-Datei verwenden (TEMPOR?R) + +Falls DNS ?ber WireGuard nicht automatisch funktioniert: + +1. ?ffne **Notepad als Administrator** +2. ?ffne: `C:\Windows\System32\drivers\etc\hosts` +3. F?ge hinzu: + ``` + 10.8.0.1 grafana.michaelschiemer.de + ``` +4. **Speichere** die Datei +5. **Teste** Browser: `https://grafana.michaelschiemer.de` + +**Hinweis:** Das ist nur eine tempor?re L?sung. DNS sollte langfristig ?ber WireGuard funktionieren. + +## Pr?fen ob es funktioniert + +Nach dem Fix k?nnen wir pr?fen, ob Traffic ?ber VPN kommt: + +Ich kann f?r dich auf dem Server pr?fen: +```bash +# Auf dem Server +tail -5 logs/access.log | grep grafana | grep -oP '"ClientHost":"[^"]*"' +``` + +**Erwartet:** +- **Mit VPN**: `"ClientHost":"10.8.0.7"` (VPN-IP) ? +- **Ohne VPN**: Keine Logs oder 403-Fehler ? + +## Troubleshooting + +### Problem: DNS wird nicht gesetzt + +**L?sung 1:** Stelle sicher, dass `DNS = 10.8.0.1` in der Config-Datei steht +**L?sung 2:** Verwende Hosts-Datei als tempor?re L?sung +**L?sung 3:** Pr?fe ob WireGuard als Administrator l?uft + +### Problem: Config-Datei kann nicht gespeichert werden + +**L?sung:** +1. Schlie?e WireGuard komplett +2. Bearbeite die Config-Datei +3. Speichere die Datei +4. Starte WireGuard neu + +### Problem: DNS wird gesetzt, aber Browser cached alte IP + +**L?sung:** +1. Browser-Cache leeren (Strg+Shift+Del) +2. Oder Inkognito-Modus verwenden +3. Oder Browser neu starten + +## Hilfe + +Falls du bei einem Schritt Hilfe brauchst: +1. Teile mir mit, wo du stecken bleibst +2. Oder teile mir die Config-Datei mit (ohne PrivateKey!) +3. Oder teile mir die PowerShell-Ergebnisse mit + +Dann kann ich dir gezielt helfen! diff --git a/docs/deployment/WIREGUARD-WINDOWS-DNS-PRIORITY-FIX.md b/docs/deployment/WIREGUARD-WINDOWS-DNS-PRIORITY-FIX.md new file mode 100644 index 00000000..f9f804be --- /dev/null +++ b/docs/deployment/WIREGUARD-WINDOWS-DNS-PRIORITY-FIX.md @@ -0,0 +1,108 @@ +# WireGuard Windows - DNS-Priorit?t fixen + +## Problem + +WireGuard Interface (`grafana-test`) hat DNS `10.8.0.1` korrekt gesetzt, aber Windows verwendet trotzdem ?ffentliche DNS-Server. + +**Aktueller Status:** +- ? WireGuard Interface: DNS = 10.8.0.1 +- ? Windows verwendet trotzdem: 94.16.110.151 (?ffentliche IP) + +**Ursache:** Windows priorisiert DNS-Server nach Interface-Metriken. Das Ethernet-Interface hat h?here Priorit?t als WireGuard. + +## L?sung: DNS-Reihenfolge pr?fen und anpassen + +### Schritt 1: Pr?fe welche DNS-Server Windows tats?chlich verwendet + +```powershell +# Pr?fe DNS-Reihenfolge +Get-DnsClientServerAddress | Sort-Object InterfaceMetric | Select-Object InterfaceAlias, ServerAddresses, InterfaceMetric + +# Pr?fe aktive DNS-Server f?r alle Interfaces +Get-DnsClientServerAddress -InterfaceIndex (Get-NetAdapter | Where-Object {$_.Status -eq 'Up'}).ifIndex | Format-Table InterfaceAlias, ServerAddresses +``` + +### Schritt 2: Pr?fe Interface-Metriken + +```powershell +# Pr?fe Interface-Metriken (niedrigere Metrik = h?here Priorit?t) +Get-NetIPInterface | Sort-Object InterfaceMetric | Select-Object InterfaceAlias, InterfaceMetric, ConnectionState + +# WireGuard Interface sollte niedrigste Metrik haben +``` + +### Schritt 3: WireGuard Interface Metrik anpassen (EMPFOHLEN) + +Setze die WireGuard Interface-Metrik auf niedrigsten Wert (h?chste Priorit?t): + +```powershell +# Als Administrator ausf?hren! + +# 1. Finde Interface-Index von WireGuard +$wgInterface = Get-NetAdapter | Where-Object {$_.Name -like "*grafana-test*" -or $_.Name -like "*WireGuard*"} +$wgInterfaceIndex = $wgInterface.ifIndex + +# 2. Setze niedrigste Metrik (h?chste Priorit?t) +Set-NetIPInterface -InterfaceIndex $wgInterfaceIndex -InterfaceMetric 1 + +# 3. Pr?fe ob es funktioniert hat +Get-NetIPInterface -InterfaceIndex $wgInterfaceIndex | Select-Object InterfaceAlias, InterfaceMetric +``` + +### Schritt 4: DNS-Reihenfolge testen + +Nach dem Anpassen der Metrik: + +```powershell +# Teste DNS-Aufl?sung +Resolve-DnsName grafana.michaelschiemer.de | Select-Object Name, IPAddress + +# Sollte jetzt zur?ckgeben: 10.8.0.1 (nicht 94.16.110.151!) +``` + +### Schritt 5: WireGuard neu verbinden + +1. **Disconnect** WireGuard-Verbindung +2. **Connect** WireGuard-Verbindung neu +3. **Teste DNS** erneut + +## Alternative: Hosts-Datei verwenden (TEMPOR?R & EINFACH) + +Falls die Metrik-Anpassung nicht funktioniert oder zu komplex ist: + +1. **?ffne Notepad als Administrator** +2. ?ffne: `C:\Windows\System32\drivers\etc\hosts` +3. F?ge hinzu: + ``` + 10.8.0.1 grafana.michaelschiemer.de + ``` +4. **Speichere** die Datei +5. **Teste**: `https://grafana.michaelschiemer.de` + +**Vorteil:** Funktioniert sofort, keine Interface-Metrik-Anpassung n?tig +**Nachteil:** Nur tempor?re L?sung, muss f?r jede Domain manuell hinzugef?gt werden + +## Pr?fen ob es funktioniert + +Nach dem Fix: + +```powershell +# DNS-Test +Resolve-DnsName grafana.michaelschiemer.de | Select-Object Name, IPAddress +# Sollte zur?ckgeben: 10.8.0.1 ? +``` + +Dann kann ich auf dem Server pr?fen, ob Traffic ?ber VPN kommt: + +```bash +# Auf dem Server (ich pr?fe das f?r dich) +tail -5 logs/access.log | grep grafana | grep -oP '"ClientHost":"[^"]*"' +# Sollte zeigen: "ClientHost":"10.8.0.7" (VPN-IP) ? +``` + +## Hilfe + +Falls du bei einem Schritt Hilfe brauchst: +1. Teile mir die PowerShell-Ergebnisse mit +2. Oder teile mir mit, wo du stecken bleibst +3. Dann kann ich dir gezielt helfen! diff --git a/docs/deployment/WIREGUARD-WINDOWS-FIREWALL-CHECK.md b/docs/deployment/WIREGUARD-WINDOWS-FIREWALL-CHECK.md new file mode 100644 index 00000000..475a4a61 --- /dev/null +++ b/docs/deployment/WIREGUARD-WINDOWS-FIREWALL-CHECK.md @@ -0,0 +1,186 @@ +# WireGuard Windows Firewall - Pr?fung und Fix + +## Problem + +Traffic kommt NICHT ?ber VPN, obwohl WireGuard verbunden ist. Windows Firewall k?nnte VPN-Traffic blockieren. + +## Schritt 1: Aktuelle Firewall-Regeln pr?fen + +**Als Administrator in PowerShell:** + +```powershell +# Pr?fe ob WireGuard-Regeln vorhanden sind +Get-NetFirewallRule | Where-Object {$_.DisplayName -like "*WireGuard*" -or $_.DisplayName -like "*VPN*"} | Select-Object DisplayName, Enabled, Direction, Action + +# Pr?fe alle ausgehenden Regeln +Get-NetFirewallRule -Direction Outbound | Where-Object {$_.Enabled -eq $true} | Select-Object DisplayName, Direction, Action | Format-Table -AutoSize + +# Pr?fe Firewall-Status +Get-NetFirewallProfile | Select-Object Name, Enabled +``` + +## Schritt 2: Pr?fe ob WireGuard-Programm-Regeln vorhanden sind + +```powershell +# Suche nach WireGuard-Programm-Regeln +Get-NetFirewallApplicationFilter | Where-Object {$_.Program -like "*WireGuard*"} | Select-Object Program + +# Oder pr?fe alle Programm-Regeln +Get-NetFirewallRule | Where-Object {$_.Program -like "*WireGuard*"} | Select-Object DisplayName, Enabled, Direction, Action, Program +``` + +## Schritt 3: Erstelle Firewall-Regeln f?r WireGuard + +**Falls keine Regeln vorhanden sind:** + +```powershell +# Als Administrator + +# Erlaube WireGuard-Programm (TCP und UDP) +$wgPath = "C:\Program Files\WireGuard\wireguard.exe" +if (Test-Path $wgPath) { + New-NetFirewallRule -DisplayName "WireGuard VPN - Allow TCP" -Direction Outbound -Program $wgPath -Protocol TCP -Action Allow -Enabled True + New-NetFirewallRule -DisplayName "WireGuard VPN - Allow UDP" -Direction Outbound -Program $wgPath -Protocol UDP -Action Allow -Enabled True + New-NetFirewallRule -DisplayName "WireGuard VPN - Allow Inbound TCP" -Direction Inbound -Program $wgPath -Protocol TCP -Action Allow -Enabled True + New-NetFirewallRule -DisplayName "WireGuard VPN - Allow Inbound UDP" -Direction Inbound -Program $wgPath -Protocol UDP -Action Allow -Enabled True + Write-Host "WireGuard Firewall-Regeln erstellt" +} else { + Write-Host "WireGuard-Programm nicht gefunden in: $wgPath" + Write-Host "Bitte pr?fe den Pfad und passe ihn an" +} + +# Alternative: Erlaube WireGuard-Interface (falls bekannt) +# Get-NetAdapter | Where-Object {$_.Name -like "*WireGuard*" -or $_.Name -like "*grafana-test*"} | ForEach-Object { +# $ifIndex = $_.InterfaceIndex +# New-NetFirewallRule -DisplayName "WireGuard Interface $($_.Name) - Allow Outbound" -Direction Outbound -InterfaceIndex $ifIndex -Action Allow -Enabled True +# New-NetFirewallRule -DisplayName "WireGuard Interface $($_.Name) - Allow Inbound" -Direction Inbound -InterfaceIndex $ifIndex -Action Allow -Enabled True +# } +``` + +## Schritt 4: Pr?fe Interface-basierte Regeln + +```powershell +# Finde WireGuard Interface +$wgInterface = Get-NetAdapter | Where-Object {$_.Name -like "*grafana-test*" -or $_.Name -like "*WireGuard*"} +if ($wgInterface) { + Write-Host "WireGuard Interface gefunden: $($wgInterface.Name), Index: $($wgInterface.InterfaceIndex)" + + # Pr?fe Interface-basierte Firewall-Regeln + Get-NetFirewallRule | Where-Object {$_.InterfaceIndex -eq $wgInterface.InterfaceIndex} | Select-Object DisplayName, Enabled, Direction, Action +} +``` + +## Schritt 5: Erlaube Traffic f?r VPN-Netzwerk + +```powershell +# Als Administrator + +# Erlaube ausgehenden Traffic zu VPN-Netzwerk (10.8.0.0/24) +New-NetFirewallRule -DisplayName "WireGuard VPN Network - Allow Outbound" ` + -Direction Outbound ` + -RemoteAddress "10.8.0.0/24" ` + -Protocol TCP ` + -Action Allow ` + -Enabled True + +New-NetFirewallRule -DisplayName "WireGuard VPN Network - Allow Outbound UDP" ` + -Direction Outbound ` + -RemoteAddress "10.8.0.0/24" ` + -Protocol UDP ` + -Action Allow ` + -Enabled True + +New-NetFirewallRule -DisplayName "WireGuard VPN Network - Allow Inbound" ` + -Direction Inbound ` + -RemoteAddress "10.8.0.0/24" ` + -Protocol TCP ` + -Action Allow ` + -Enabled True + +New-NetFirewallRule -DisplayName "WireGuard VPN Network - Allow Inbound UDP" ` + -Direction Inbound ` + -RemoteAddress "10.8.0.0/24" ` + -Protocol UDP ` + -Action Allow ` + -Enabled True + +Write-Host "VPN-Netzwerk Firewall-Regeln erstellt" +``` + +## Schritt 6: Teste nach Firewall-?nderungen + +```powershell +# Pr?fe Route +route print | findstr "10.8" + +# Teste Ping +ping 10.8.0.1 + +# Teste Grafana (im Browser) +# https://grafana.michaelschiemer.de +``` + +## Schritt 7: Pr?fe Logs + +Nach den ?nderungen: +1. **WireGuard neu verbinden** (Disconnect ? Connect) +2. **Teste Grafana**: `https://grafana.michaelschiemer.de` +3. **Warte 5 Sekunden** +4. Dann pr?fe ich die Traefik-Logs, ob `ClientHost: 10.8.0.7` erscheint + +## Troubleshooting + +### Firewall-Regeln werden nicht angewendet + +```powershell +# Pr?fe ob Firewall aktiv ist +Get-NetFirewallProfile | Select-Object Name, Enabled + +# Falls Firewall deaktiviert ist, aktiviere sie (falls gew?nscht) +# Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled True +``` + +### WireGuard-Programm-Pfad ist anders + +```powershell +# Finde WireGuard-Installationspfad +Get-ChildItem "C:\Program Files" -Recurse -Filter "wireguard.exe" -ErrorAction SilentlyContinue +Get-ChildItem "C:\Program Files (x86)" -Recurse -Filter "wireguard.exe" -ErrorAction SilentlyContinue + +# Oder suche in allen Programmen +Get-ChildItem "C:\" -Recurse -Filter "wireguard.exe" -ErrorAction SilentlyContinue | Select-Object FullName +``` + +### Tempor?re Firewall-Regeln zum Testen + +Falls du schnell testen m?chtest, ohne spezifische Regeln: + +```powershell +# Als Administrator - ERLAUBE ALLEN AUSGEHENDEN TRAFFIC TEMPOR?R (NUR ZUM TESTEN!) +# WARNUNG: Diese Regel erlaubt ALLEN ausgehenden Traffic - nur zum Testen verwenden! + +New-NetFirewallRule -DisplayName "TEST - Allow All Outbound (TEMPORARY)" ` + -Direction Outbound ` + -Action Allow ` + -Enabled True + +# Teste dann Grafana +# Falls es funktioniert: L?sche diese Regel und erstelle spezifische Regeln +# Remove-NetFirewallRule -DisplayName "TEST - Allow All Outbound (TEMPORARY)" +``` + +## N?chste Schritte + +Nach dem Erstellen der Firewall-Regeln: + +1. ? Firewall-Regeln erstellt +2. ? WireGuard neu verbinden +3. ? Teste Grafana-Zugriff +4. ? Pr?fe Traefik-Logs (ich pr?fe dann, ob `ClientHost: 10.8.0.7` erscheint) + +## Wichtige Hinweise + +- **Firewall-Regeln sollten spezifisch sein** (nicht "Allow All") +- **Programm-Regeln sind sicherer** als allgemeine Regeln +- **Interface-Regeln k?nnen helfen**, wenn Programm-Regeln nicht funktionieren +- **VPN-Netzwerk-Regeln** sind am spezifischsten diff --git a/docs/deployment/WIREGUARD-WINDOWS-FIREWALL-SCRIPT.ps1 b/docs/deployment/WIREGUARD-WINDOWS-FIREWALL-SCRIPT.ps1 new file mode 100644 index 00000000..a56b2f44 --- /dev/null +++ b/docs/deployment/WIREGUARD-WINDOWS-FIREWALL-SCRIPT.ps1 @@ -0,0 +1,139 @@ +# WireGuard Windows Firewall - Pr?fung und Fix Script +# Als Administrator ausf?hren! + +Write-Host "=== WireGuard Windows Firewall - Pr?fung ===" -ForegroundColor Cyan +Write-Host "" + +# Pr?fe ob als Administrator ausgef?hrt +$isAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) +if (-not $isAdmin) { + Write-Host "FEHLER: Script muss als Administrator ausgef?hrt werden!" -ForegroundColor Red + Write-Host "Rechtsklick auf PowerShell -> 'Als Administrator ausf?hren'" -ForegroundColor Yellow + exit 1 +} + +Write-Host "1. Pr?fe Firewall-Status..." -ForegroundColor Green +Get-NetFirewallProfile | Select-Object Name, Enabled | Format-Table -AutoSize + +Write-Host "" +Write-Host "2. Pr?fe vorhandene WireGuard Firewall-Regeln..." -ForegroundColor Green +$existingRules = Get-NetFirewallRule | Where-Object {$_.DisplayName -like "*WireGuard*" -or $_.DisplayName -like "*VPN*"} +if ($existingRules) { + $existingRules | Select-Object DisplayName, Enabled, Direction, Action | Format-Table -AutoSize +} else { + Write-Host "Keine WireGuard Firewall-Regeln gefunden" -ForegroundColor Yellow +} + +Write-Host "" +Write-Host "3. Suche WireGuard-Installationspfad..." -ForegroundColor Green +$wgPath = "C:\Program Files\WireGuard\wireguard.exe" +if (-not (Test-Path $wgPath)) { + $wgPath = "C:\Program Files (x86)\WireGuard\wireguard.exe" +} +if (-not (Test-Path $wgPath)) { + Write-Host "WireGuard-Programm nicht gefunden in Standardpfaden" -ForegroundColor Yellow + Write-Host "Suche in anderen Pfaden..." -ForegroundColor Yellow + $found = Get-ChildItem "C:\Program Files" -Recurse -Filter "wireguard.exe" -ErrorAction SilentlyContinue | Select-Object -First 1 + if ($found) { + $wgPath = $found.FullName + Write-Host "Gefunden: $wgPath" -ForegroundColor Green + } else { + Write-Host "WireGuard-Programm nicht gefunden. Bitte Pfad manuell angeben." -ForegroundColor Red + $wgPath = Read-Host "WireGuard-Programm-Pfad (oder Enter zum ?berspringen)" + } +} else { + Write-Host "Gefunden: $wgPath" -ForegroundColor Green +} + +Write-Host "" +Write-Host "4. Finde WireGuard Interface..." -ForegroundColor Green +$wgInterface = Get-NetAdapter | Where-Object {$_.Name -like "*grafana-test*" -or $_.Name -like "*WireGuard*"} +if ($wgInterface) { + Write-Host "Gefunden: $($wgInterface.Name), Index: $($wgInterface.InterfaceIndex)" -ForegroundColor Green + Get-NetFirewallRule | Where-Object {$_.InterfaceIndex -eq $wgInterface.InterfaceIndex} | Select-Object DisplayName, Enabled, Direction, Action | Format-Table -AutoSize +} else { + Write-Host "Kein WireGuard Interface gefunden" -ForegroundColor Yellow +} + +Write-Host "" +Write-Host "=== M?chtest du Firewall-Regeln erstellen? ===" -ForegroundColor Cyan +Write-Host "1. Programm-Regeln (wenn WireGuard-Pfad gefunden)" +Write-Host "2. Interface-Regeln (wenn WireGuard Interface gefunden)" +Write-Host "3. VPN-Netzwerk-Regeln (10.8.0.0/24)" +Write-Host "4. Alle oben genannten" +Write-Host "5. ?berspringen (nur pr?fen)" +Write-Host "" +$choice = Read-Host "W?hle Option (1-5)" + +switch ($choice) { + "1" { + if ($wgPath -and (Test-Path $wgPath)) { + Write-Host "Erstelle Programm-Regeln..." -ForegroundColor Green + New-NetFirewallRule -DisplayName "WireGuard VPN - Allow TCP" -Direction Outbound -Program $wgPath -Protocol TCP -Action Allow -Enabled True -ErrorAction SilentlyContinue + New-NetFirewallRule -DisplayName "WireGuard VPN - Allow UDP" -Direction Outbound -Program $wgPath -Protocol UDP -Action Allow -Enabled True -ErrorAction SilentlyContinue + New-NetFirewallRule -DisplayName "WireGuard VPN - Allow Inbound TCP" -Direction Inbound -Program $wgPath -Protocol TCP -Action Allow -Enabled True -ErrorAction SilentlyContinue + New-NetFirewallRule -DisplayName "WireGuard VPN - Allow Inbound UDP" -Direction Inbound -Program $wgPath -Protocol UDP -Action Allow -Enabled True -ErrorAction SilentlyContinue + Write-Host "Programm-Regeln erstellt" -ForegroundColor Green + } else { + Write-Host "Kann Programm-Regeln nicht erstellen: WireGuard-Pfad nicht gefunden" -ForegroundColor Red + } + } + "2" { + if ($wgInterface) { + Write-Host "Erstelle Interface-Regeln..." -ForegroundColor Green + $ifIndex = $wgInterface.InterfaceIndex + New-NetFirewallRule -DisplayName "WireGuard Interface $($wgInterface.Name) - Allow Outbound" -Direction Outbound -InterfaceIndex $ifIndex -Action Allow -Enabled True -ErrorAction SilentlyContinue + New-NetFirewallRule -DisplayName "WireGuard Interface $($wgInterface.Name) - Allow Inbound" -Direction Inbound -InterfaceIndex $ifIndex -Action Allow -Enabled True -ErrorAction SilentlyContinue + Write-Host "Interface-Regeln erstellt" -ForegroundColor Green + } else { + Write-Host "Kann Interface-Regeln nicht erstellen: WireGuard Interface nicht gefunden" -ForegroundColor Red + } + } + "3" { + Write-Host "Erstelle VPN-Netzwerk-Regeln..." -ForegroundColor Green + New-NetFirewallRule -DisplayName "WireGuard VPN Network - Allow Outbound TCP" -Direction Outbound -RemoteAddress "10.8.0.0/24" -Protocol TCP -Action Allow -Enabled True -ErrorAction SilentlyContinue + New-NetFirewallRule -DisplayName "WireGuard VPN Network - Allow Outbound UDP" -Direction Outbound -RemoteAddress "10.8.0.0/24" -Protocol UDP -Action Allow -Enabled True -ErrorAction SilentlyContinue + New-NetFirewallRule -DisplayName "WireGuard VPN Network - Allow Inbound TCP" -Direction Inbound -RemoteAddress "10.8.0.0/24" -Protocol TCP -Action Allow -Enabled True -ErrorAction SilentlyContinue + New-NetFirewallRule -DisplayName "WireGuard VPN Network - Allow Inbound UDP" -Direction Inbound -RemoteAddress "10.8.0.0/24" -Protocol UDP -Action Allow -Enabled True -ErrorAction SilentlyContinue + Write-Host "VPN-Netzwerk-Regeln erstellt" -ForegroundColor Green + } + "4" { + Write-Host "Erstelle alle Regeln..." -ForegroundColor Green + if ($wgPath -and (Test-Path $wgPath)) { + New-NetFirewallRule -DisplayName "WireGuard VPN - Allow TCP" -Direction Outbound -Program $wgPath -Protocol TCP -Action Allow -Enabled True -ErrorAction SilentlyContinue + New-NetFirewallRule -DisplayName "WireGuard VPN - Allow UDP" -Direction Outbound -Program $wgPath -Protocol UDP -Action Allow -Enabled True -ErrorAction SilentlyContinue + New-NetFirewallRule -DisplayName "WireGuard VPN - Allow Inbound TCP" -Direction Inbound -Program $wgPath -Protocol TCP -Action Allow -Enabled True -ErrorAction SilentlyContinue + New-NetFirewallRule -DisplayName "WireGuard VPN - Allow Inbound UDP" -Direction Inbound -Program $wgPath -Protocol UDP -Action Allow -Enabled True -ErrorAction SilentlyContinue + Write-Host "Programm-Regeln erstellt" -ForegroundColor Green + } + if ($wgInterface) { + $ifIndex = $wgInterface.InterfaceIndex + New-NetFirewallRule -DisplayName "WireGuard Interface $($wgInterface.Name) - Allow Outbound" -Direction Outbound -InterfaceIndex $ifIndex -Action Allow -Enabled True -ErrorAction SilentlyContinue + New-NetFirewallRule -DisplayName "WireGuard Interface $($wgInterface.Name) - Allow Inbound" -Direction Inbound -InterfaceIndex $ifIndex -Action Allow -Enabled True -ErrorAction SilentlyContinue + Write-Host "Interface-Regeln erstellt" -ForegroundColor Green + } + New-NetFirewallRule -DisplayName "WireGuard VPN Network - Allow Outbound TCP" -Direction Outbound -RemoteAddress "10.8.0.0/24" -Protocol TCP -Action Allow -Enabled True -ErrorAction SilentlyContinue + New-NetFirewallRule -DisplayName "WireGuard VPN Network - Allow Outbound UDP" -Direction Outbound -RemoteAddress "10.8.0.0/24" -Protocol UDP -Action Allow -Enabled True -ErrorAction SilentlyContinue + New-NetFirewallRule -DisplayName "WireGuard VPN Network - Allow Inbound TCP" -Direction Inbound -RemoteAddress "10.8.0.0/24" -Protocol TCP -Action Allow -Enabled True -ErrorAction SilentlyContinue + New-NetFirewallRule -DisplayName "WireGuard VPN Network - Allow Inbound UDP" -Direction Inbound -RemoteAddress "10.8.0.0/24" -Protocol UDP -Action Allow -Enabled True -ErrorAction SilentlyContinue + Write-Host "VPN-Netzwerk-Regeln erstellt" -ForegroundColor Green + } + "5" { + Write-Host "?berspringe Regel-Erstellung" -ForegroundColor Yellow + } + default { + Write-Host "Ung?ltige Option" -ForegroundColor Red + } +} + +Write-Host "" +Write-Host "=== Zusammenfassung ===" -ForegroundColor Cyan +Write-Host "Firewall-Regeln:" +Get-NetFirewallRule | Where-Object {$_.DisplayName -like "*WireGuard*" -or $_.DisplayName -like "*VPN*"} | Select-Object DisplayName, Enabled, Direction, Action | Format-Table -AutoSize + +Write-Host "" +Write-Host "=== N?chste Schritte ===" -ForegroundColor Cyan +Write-Host "1. WireGuard neu verbinden (Disconnect ? Connect)" +Write-Host "2. Teste: ping 10.8.0.1" +Write-Host "3. Teste: https://grafana.michaelschiemer.de im Browser" +Write-Host "4. Sag mir Bescheid, dann pr?fe ich die Traefik-Logs!" diff --git a/docs/deployment/WIREGUARD-WINDOWS-INTERFACE-METRIC-FIX.md b/docs/deployment/WIREGUARD-WINDOWS-INTERFACE-METRIC-FIX.md new file mode 100644 index 00000000..a455b9cd --- /dev/null +++ b/docs/deployment/WIREGUARD-WINDOWS-INTERFACE-METRIC-FIX.md @@ -0,0 +1,63 @@ +# WireGuard Windows - Interface-Metrik optimieren + +## Status + +? **L?sung 1 (Hosts-Datei) funktioniert bereits!** + +Die Interface-Metrik zeigt: +- WireGuard Interface (`grafana-test`): Metrik 5 (bereits niedrigste) +- Andere Interfaces: Metrik 25 oder h?her + +## Optional: Metrik noch weiter optimieren + +Falls du L?sung 2 (Interface-Metrik) noch weiter optimieren m?chtest: + +### Schritt 1: Setze WireGuard Interface-Metrik auf 1 + +```powershell +# Als Administrator ausf?hren! + +# Setze Metrik auf 1 (h?chste Priorit?t) +Set-NetIPInterface -InterfaceIndex 18 -InterfaceMetric 1 + +# Pr?fe ob es funktioniert hat +Get-NetIPInterface -InterfaceIndex 18 | Select-Object InterfaceAlias, InterfaceMetric +# Sollte zeigen: InterfaceMetric = 1 +``` + +### Schritt 2: DNS-Reihenfolge testen + +Nach dem Setzen der Metrik auf 1: + +```powershell +# Teste DNS-Aufl?sung +Resolve-DnsName grafana.michaelschiemer.de | Select-Object Name, IPAddress + +# Falls das jetzt 10.8.0.1 zur?ckgibt ? Erfolg! +# Falls nicht ? Hosts-Datei ist die bessere L?sung +``` + +### Schritt 3: WireGuard neu verbinden + +1. **Disconnect** WireGuard-Verbindung +2. **Connect** WireGuard-Verbindung neu +3. **Teste DNS** erneut + +## Empfehlung + +**L?sung 1 (Hosts-Datei) ist einfacher und funktioniert zuverl?ssig:** +- ? Funktioniert sofort +- ? Keine PowerShell-Befehle n?tig +- ? Keine Administratorrechte n?tig (au?er f?r Hosts-Datei) +- ? Keine Interface-Metrik-Anpassung n?tig + +**L?sung 2 (Interface-Metrik) ist optional:** +- Kann funktionieren, aber ist komplexer +- Muss m?glicherweise nach jedem System-Neustart neu gesetzt werden +- Hosts-Datei ist einfacher und zuverl?ssiger + +## N?chste Schritte + +1. ? Hosts-Datei funktioniert bereits +2. ? Pr?fe ob Traffic ?ber VPN kommt (ClientHost: 10.8.0.7) +3. ? Entferne tempor?re IP-Erlaubnis, wenn Traffic ?ber VPN kommt diff --git a/docs/deployment/WIREGUARD-WINDOWS-ROUTE-FIX.md b/docs/deployment/WIREGUARD-WINDOWS-ROUTE-FIX.md new file mode 100644 index 00000000..2f0da937 --- /dev/null +++ b/docs/deployment/WIREGUARD-WINDOWS-ROUTE-FIX.md @@ -0,0 +1,103 @@ +# WireGuard Windows - Route-Tabelle pr?fen und fixen + +## Status + +? **Route vorhanden**: `10.8.0.0/24` Route existiert in Windows Route-Tabelle +? **Ping funktioniert**: `ping 10.8.0.1` funktioniert ? VPN-Verbindung ist OK +?? **Route zeigt "Auf Verbindung"**: Gateway ist `10.8.0.7` (Client-IP), nicht `10.8.0.1` (Server-IP) + +## Route-Interpretation + +``` +10.8.0.0 255.255.255.0 Auf Verbindung 10.8.0.7 5 +``` + +**Bedeutung:** +- **Ziel**: `10.8.0.0/24` (ganzes VPN-Netzwerk) +- **Typ**: "Auf Verbindung" (On-link) = direkt verbundenes Netzwerk +- **Gateway**: `10.8.0.7` (deine Client-IP) +- **Metrik**: 5 (niedrig = bevorzugt) + +**Das ist normal f?r WireGuard!** Das Interface ist als direkt verbunden markiert, daher ist der Gateway die Client-IP selbst. + +## Test-Schritte + +### Schritt 1: Browser DNS-Cache leeren + +Falls der Browser noch alte DNS-Eintr?ge cached: + +```powershell +# Flush DNS-Cache +ipconfig /flushdns + +# Pr?fe DNS-Aufl?sung +nslookup grafana.michaelschiemer.de +``` + +**Mit Hosts-Datei sollte zeigen:** +``` +Name: grafana.michaelschiemer.de +Address: 10.8.0.1 +``` + +### Schritt 2: Teste Grafana-Zugriff + +1. **Stelle sicher, dass VPN verbunden ist** +2. **?ffne Browser** (Chrome/Edge/Firefox) +3. **Leere Browser-Cache** oder nutze **Inkognito-Modus** +4. **?ffne**: `https://grafana.michaelschiemer.de` +5. **Warte 5 Sekunden** + +### Schritt 3: Pr?fe Traefik-Logs + +Ich pr?fe dann die Logs auf dem Server, ob: +- ? `ClientHost: 10.8.0.7` (VPN-IP) ? Traffic kommt ?ber VPN! +- ? `ClientHost: 89.246.96.244` (?ffentliche IP) ? Traffic kommt NICHT ?ber VPN + +## Falls Traffic immer noch nicht ?ber VPN kommt + +### Option A: Route explizit setzen + +Falls die Route nicht richtig funktioniert: + +```powershell +# Als Administrator +# Interface-Index 18 (WireGuard Interface) +route delete 10.8.0.0 MASK 255.255.255.0 +route add 10.8.0.0 MASK 255.255.255.0 10.8.0.1 METRIC 1 IF 18 + +# Pr?fe ob es funktioniert hat +route print | findstr "10.8" +``` + +### Option B: WireGuard neu verbinden + +1. **Disconnect** WireGuard-Verbindung +2. **Warte 5 Sekunden** +3. **Connect** WireGuard-Verbindung neu +4. **Pr?fe Route erneut**: `route print | findstr "10.8"` +5. **Teste Ping**: `ping 10.8.0.1` +6. **Teste Grafana**: `https://grafana.michaelschiemer.de` + +### Option C: Pr?fe AllowedIPs in WireGuard-Config + +**?ffne WireGuard ? W?hle "grafana-test" ? "Bearbeiten":** + +```ini +[Peer] +AllowedIPs = 10.8.0.0/24 # ? Muss das gesamte VPN-Netzwerk sein +``` + +**Falls nur `10.8.0.1/32` oder ?hnliches steht:** +- ?ndere zu `10.8.0.0/24` +- Speichere +- WireGuard neu verbinden + +## Erwartetes Ergebnis + +Nach korrektem VPN-Routing sollte Traefik sehen: +``` +ClientHost: 10.8.0.7 ? Deine VPN-Client-IP +``` + +Dann k?nnen wir die tempor?re IP-Erlaubnis (`89.246.96.244`) entfernen! diff --git a/docs/deployment/WIREGUARD-WINDOWS-ROUTE-GATEWAY-FIX.md b/docs/deployment/WIREGUARD-WINDOWS-ROUTE-GATEWAY-FIX.md new file mode 100644 index 00000000..b0fe18a0 --- /dev/null +++ b/docs/deployment/WIREGUARD-WINDOWS-ROUTE-GATEWAY-FIX.md @@ -0,0 +1,176 @@ +# WireGuard Windows - Route explizit mit Gateway setzen + +## Problem best?tigt + +Trotz Firewall-Regeln kommt Traffic **NICHT ?ber VPN**: +- Traefik sieht: `ClientHost: 89.246.96.244` (?ffentliche IP) ? +- Erwartet: `ClientHost: 10.8.0.7` (VPN-IP) ? + +## Was wir bereits probiert haben + +? **WireGuard verbunden**: Aktive Verbindung +? **Route vorhanden**: `10.8.0.0/24` Route in Windows Route-Tabelle +? **Ping funktioniert**: `ping 10.8.0.1` erfolgreich +? **AllowedIPs korrekt**: `10.8.0.0/24` in Client-Config +? **Interface-Metrik angepasst**: Metrik 1 (h?chste Priorit?t) +? **Firewall-Regeln erstellt**: VPN-Netzwerk-Regeln f?r 10.8.0.0/24 +? **HTTP/HTTPS-Traffic kommt NICHT ?ber VPN**: Windows sendet Traffic ?ber Standard-Interface + +## L?sung: Route explizit mit Gateway setzen + +Windows k?nnte die Route nicht korrekt nutzen, weil sie als "Auf Verbindung" (On-link) markiert ist. Setzen wir die Route explizit mit Gateway. + +### Schritt 1: Finde WireGuard Interface-Index + +```powershell +# Als Administrator +Get-NetAdapter | Where-Object {$_.Name -like "*grafana-test*" -or $_.Name -like "*WireGuard*"} | Select-Object Name, InterfaceIndex +``` + +**Beispiel-Output:** +``` +Name InterfaceIndex +---- -------------- +grafana-test 18 +``` + +### Schritt 2: Entferne alte Route + +```powershell +# Als Administrator +route delete 10.8.0.0 MASK 255.255.255.0 +``` + +**Falls Fehler:** Das ist OK, die Route existiert vielleicht nicht mehr oder hat eine andere Form. + +### Schritt 3: Setze Route explizit mit Gateway + +```powershell +# Als Administrator +# Ersetze 18 mit dem Interface-Index aus Schritt 1 +route add 10.8.0.0 MASK 255.255.255.0 10.8.0.1 METRIC 1 IF 18 +``` + +**Erkl?rung:** +- `10.8.0.0` = Ziel-Netzwerk (VPN-Netzwerk) +- `MASK 255.255.255.0` = Subnetzmaske (/24) +- `10.8.0.1` = Gateway (VPN-Server-IP) +- `METRIC 1` = H?chste Priorit?t (niedrigste Zahl = h?chste Priorit?t) +- `IF 18` = Interface-Index von WireGuard + +### Schritt 4: Pr?fe ob Route korrekt gesetzt wurde + +```powershell +# Als Administrator +route print | findstr "10.8" +``` + +**Erwartetes Ergebnis:** +``` +10.8.0.0 255.255.255.0 10.8.0.1 18 1 +``` + +**Wichtig:** Gateway sollte `10.8.0.1` sein (nicht "Auf Verbindung" oder deine Client-IP `10.8.0.7`). + +### Schritt 5: WireGuard neu verbinden + +1. **Disconnect** WireGuard-Verbindung +2. **Warte 5 Sekunden** +3. **Connect** WireGuard-Verbindung neu +4. **Pr?fe Route erneut**: `route print | findstr "10.8"` + +### Schritt 6: Teste + +```powershell +# Pr?fe Route +route print | findstr "10.8" + +# Teste Ping +ping 10.8.0.1 + +# Teste Grafana im Browser +# https://grafana.michaelschiemer.de +``` + +### Schritt 7: Logs pr?fen + +Nach dem Test sage mir Bescheid, dann pr?fe ich die Traefik-Logs: +- ? Wenn `ClientHost: 10.8.0.7` ? Traffic kommt ?ber VPN! +- ? Wenn `ClientHost: 89.246.96.244` ? Traffic kommt NICHT ?ber VPN + +## Falls Route nicht korrekt bleibt + +Die Route k?nnte nach dem Disconnect/Connect wieder auf "Auf Verbindung" wechseln. In diesem Fall: + +### Option A: Route persistieren + +```powershell +# Als Administrator +# Entferne alte Route +route delete 10.8.0.0 MASK 255.255.255.0 + +# Setze Route mit -p Flag (persistent) +route add 10.8.0.0 MASK 255.255.255.0 10.8.0.1 METRIC 1 IF 18 -p +``` + +Das `-p` Flag macht die Route persistent ?ber System-Neustarts. + +### Option B: Route ?ber WireGuard selbst setzen + +Manchmal setzt WireGuard die Route automatisch auf "Auf Verbindung". Versuche die Route nach dem Verbinden erneut zu setzen: + +```powershell +# Nachdem WireGuard verbunden ist, erneut ausf?hren: +route delete 10.8.0.0 MASK 255.255.255.0 +route add 10.8.0.0 MASK 255.255.255.0 10.8.0.1 METRIC 1 IF 18 +``` + +## Troubleshooting + +### Route wird nicht gesetzt + +```powershell +# Pr?fe ob Interface-Index korrekt ist +Get-NetAdapter | Where-Object {$_.Name -like "*grafana-test*"} + +# Pr?fe ob Gateway erreichbar ist +ping 10.8.0.1 +``` + +### Route wird wieder gel?scht + +Windows k?nnte die Route automatisch zur?cksetzen. In diesem Fall: +1. Setze Route nach jedem WireGuard-Connect neu +2. Oder erstelle ein Script, das die Route automatisch setzt + +## Alternative: PowerShell-Script f?r automatische Route-Setzung + +```powershell +# Als Administrator +# Finde Interface-Index +$wgInterface = Get-NetAdapter | Where-Object {$_.Name -like "*grafana-test*" -or $_.Name -like "*WireGuard*"} +if ($wgInterface) { + $ifIndex = $wgInterface.InterfaceIndex + Write-Host "WireGuard Interface gefunden: $($wgInterface.Name), Index: $ifIndex" + + # Entferne alte Route + route delete 10.8.0.0 MASK 255.255.255.0 2>&1 | Out-Null + + # Setze Route explizit mit Gateway + route add 10.8.0.0 MASK 255.255.255.0 10.8.0.1 METRIC 1 IF $ifIndex + + # Pr?fe ob es funktioniert hat + route print | findstr "10.8" +} else { + Write-Host "WireGuard Interface nicht gefunden" +} +``` + +## N?chste Schritte + +Nach dem Setzen der Route: +1. ? Route explizit mit Gateway gesetzt +2. ? WireGuard neu verbinden +3. ? Route erneut pr?fen (sollte Gateway `10.8.0.1` zeigen) +4. ? Teste Grafana-Zugriff +5. ? Pr?fe Traefik-Logs (ich pr?fe dann, ob `ClientHost: 10.8.0.7` erscheint) diff --git a/docs/deployment/WIREGUARD-WINDOWS-ROUTING-FINAL-ANALYSIS.md b/docs/deployment/WIREGUARD-WINDOWS-ROUTING-FINAL-ANALYSIS.md new file mode 100644 index 00000000..c90c6915 --- /dev/null +++ b/docs/deployment/WIREGUARD-WINDOWS-ROUTING-FINAL-ANALYSIS.md @@ -0,0 +1,109 @@ +# WireGuard Windows Routing - Finale Analyse + +## Problem best?tigt + +Trotz aller Ma?nahmen kommt Traffic von Windows **NICHT ?ber VPN**: +- Traefik sieht: `ClientHost: 89.246.96.244` (?ffentliche IP) ? +- Erwartet: `ClientHost: 10.8.0.7` (VPN-IP) ? + +## Was funktioniert + +? **WireGuard verbunden**: Aktive Verbindung mit latest handshake +? **Route vorhanden**: `10.8.0.0/24` Route in Windows Route-Tabelle +? **Ping funktioniert**: `ping 10.8.0.1` erfolgreich +? **AllowedIPs korrekt**: `10.8.0.0/24` in Client-Config +? **VPN-Server funktioniert**: Test-Container erfolgreich verbunden + +## Was nicht funktioniert + +? **HTTP/HTTPS-Traffic kommt NICHT ?ber VPN**: Windows sendet Traffic ?ber Standard-Interface + +## Ursache + +**Windows-spezifisches Routing-Problem**: Windows priorisiert die Standard-Route ?ber das WireGuard-Interface f?r HTTP/HTTPS-Traffic, obwohl: +- Die Route vorhanden ist +- Ping funktioniert +- WireGuard verbunden ist + +## M?gliche L?sungen + +### Option 1: Windows Interface-Metrik anpassen + +```powershell +# Als Administrator +# WireGuard Interface-Index finden +Get-NetAdapter | Where-Object {$_.Name -like "*grafana-test*" -or $_.Name -like "*WireGuard*"} | Select-Object Name, InterfaceIndex + +# Interface-Metrik auf 1 setzen (h?chste Priorit?t) +Set-NetIPInterface -InterfaceIndex 18 -InterfaceMetric 1 + +# Pr?fen ob es funktioniert hat +Get-NetIPInterface -InterfaceIndex 18 | Select-Object InterfaceAlias, InterfaceMetric +``` + +### Option 2: Route explizit mit Gateway setzen + +```powershell +# Als Administrator +# Entferne alte Route +route delete 10.8.0.0 MASK 255.255.255.0 + +# Setze Route explizit mit Gateway 10.8.0.1 (nicht "Auf Verbindung") +route add 10.8.0.0 MASK 255.255.255.0 10.8.0.1 METRIC 1 IF 18 + +# Pr?fe ob es funktioniert hat +route print | findstr "10.8" +``` + +### Option 3: Windows Firewall pr?fen + +Windows Firewall k?nnte VPN-Traffic blockieren: + +```powershell +# Als Administrator +# Pr?fe Firewall-Regeln +Get-NetFirewallRule | Where-Object {$_.DisplayName -like "*WireGuard*"} + +# Falls keine Regeln vorhanden: Erlaube WireGuard-Traffic +New-NetFirewallRule -DisplayName "WireGuard VPN" -Direction Outbound -LocalPort Any -Protocol TCP -Action Allow +New-NetFirewallRule -DisplayName "WireGuard VPN" -Direction Outbound -LocalPort Any -Protocol UDP -Action Allow +``` + +### Option 4: WireGuard auf Windows neu installieren + +1. **WireGuard deinstallieren** +2. **Neu installieren**: https://www.wireguard.com/install/ +3. **Config neu importieren** +4. **Verbinden und testen** + +### Option 5: Alternativer VPN-Client (tempor?r) + +Falls WireGuard auf Windows weiterhin Probleme macht, k?nntest du tempor?r einen anderen VPN-Client verwenden, um zu pr?fen, ob das Problem Windows-spezifisch ist. + +## Empfehlung + +**Option 1 (Interface-Metrik)** ist am einfachsten und sollte zuerst probiert werden. + +**Option 2 (Route mit Gateway)** ist robuster, k?nnte aber zu Problemen f?hren, falls das Gateway nicht korrekt ist. + +**Option 3 (Firewall)** sollte auch gepr?ft werden, falls die anderen Optionen nicht helfen. + +## Testen + +Nach jeder ?nderung: + +1. **Pr?fe Route**: `route print | findstr "10.8"` +2. **Teste Ping**: `ping 10.8.0.1` +3. **Teste Grafana**: `https://grafana.michaelschiemer.de` +4. **Pr?fe Logs**: Ich pr?fe dann die Traefik-Logs, ob `ClientHost: 10.8.0.7` erscheint + +## N?chste Schritte + +Wenn eine der Optionen funktioniert: +1. ? Traffic kommt ?ber VPN (`ClientHost: 10.8.0.7`) +2. ? Tempor?re IP-Erlaubnis entfernen (`89.246.96.244`) +3. ? Grafana ist nur noch ?ber VPN erreichbar + +## Dokumentation + +Alle ?nderungen sollten dokumentiert werden, damit andere Windows-Clients das gleiche Problem l?sen k?nnen. diff --git a/src/Framework/Config/TypedConfigInitializer.php b/src/Framework/Config/TypedConfigInitializer.php index 4fe0c2c2..a0effdd3 100644 --- a/src/Framework/Config/TypedConfigInitializer.php +++ b/src/Framework/Config/TypedConfigInitializer.php @@ -16,8 +16,7 @@ final readonly class TypedConfigInitializer { public function __construct( private Environment $env, - ) { - } + ) {} public function __invoke(Container $container): TypedConfiguration { diff --git a/src/Framework/Core/AppBootstrapper.php b/src/Framework/Core/AppBootstrapper.php index fe9bb37a..649e481a 100644 --- a/src/Framework/Core/AppBootstrapper.php +++ b/src/Framework/Core/AppBootstrapper.php @@ -44,7 +44,6 @@ final readonly class AppBootstrapper private string $basePath, private PerformanceCollectorInterface $collector, private MemoryMonitor $memoryMonitor = new MemoryMonitor, - #private array $config = [], ) { $this->container = new DefaultContainer(); $this->bootstrapper = new ContainerBootstrapper($this->container);