fix(vpn): backport VPN fixes from production debugging
- Fix _commit_and_sync infinite recursion - Use admin session for subnet_index allocation (bypass RLS) - Auto-set VPN endpoint from CORS_ORIGINS hostname - Remove server address field from VPN setup UI - Add DELETE endpoint and button for VPN config removal - Add wg-reload watcher for reliable config hot-reload via wg syncconf - Add wg_status.json writer for live peer handshake status in UI - Per-tenant SNAT for poller-to-device routing through VPN - Restrict VPN→eth0 forwarding to Docker networks only (block exit node abuse) - Use 10.10.0.0/16 allowed-address in RouterOS commands - Fix structlog event= conflict (use audit=True) - Export backup_scheduler proxy for firmware/upgrade imports
This commit is contained in:
9
setup.py
9
setup.py
@@ -988,8 +988,12 @@ def prepare_data_dirs() -> None:
|
||||
#!/bin/sh
|
||||
# Enable forwarding between Docker network and WireGuard tunnel
|
||||
# Idempotent: check before adding to prevent duplicates on restart
|
||||
# Allow Docker→VPN (poller/API reaching devices)
|
||||
iptables -C FORWARD -i eth0 -o wg0 -j ACCEPT 2>/dev/null || iptables -A FORWARD -i eth0 -o wg0 -j ACCEPT
|
||||
iptables -C FORWARD -i wg0 -o eth0 -j ACCEPT 2>/dev/null || iptables -A FORWARD -i wg0 -o eth0 -j ACCEPT
|
||||
# Allow VPN→Docker ONLY (devices reaching poller/API, NOT the public internet)
|
||||
iptables -C FORWARD -i wg0 -o eth0 -d 172.16.0.0/12 -j ACCEPT 2>/dev/null || iptables -A FORWARD -i wg0 -o eth0 -d 172.16.0.0/12 -j ACCEPT
|
||||
# Block VPN→anywhere else (prevents using server as exit node)
|
||||
iptables -C FORWARD -i wg0 -o eth0 -j DROP 2>/dev/null || iptables -A FORWARD -i wg0 -o eth0 -j DROP
|
||||
|
||||
# Block cross-subnet traffic on wg0 (tenant isolation)
|
||||
# Peers in 10.10.1.0/24 cannot reach peers in 10.10.2.0/24
|
||||
@@ -998,8 +1002,7 @@ iptables -C FORWARD -i wg0 -o wg0 -j DROP 2>/dev/null || iptables -A FORWARD -i
|
||||
# Block IPv6 forwarding on wg0 (prevent link-local bypass)
|
||||
ip6tables -C FORWARD -i wg0 -j DROP 2>/dev/null || ip6tables -A FORWARD -i wg0 -j DROP
|
||||
|
||||
# NAT for return traffic
|
||||
iptables -t nat -C POSTROUTING -o wg0 -j MASQUERADE 2>/dev/null || iptables -t nat -A POSTROUTING -o wg0 -j MASQUERADE
|
||||
# NAT for return traffic — per-tenant SNAT rules applied by wg-reload watcher
|
||||
|
||||
echo "WireGuard forwarding and tenant isolation rules applied"
|
||||
""")
|
||||
|
||||
Reference in New Issue
Block a user