fix: harden WARP route bridge setup

This commit is contained in:
Андрей Бобырев
2026-06-05 20:19:11 +03:00
parent 6e905ec600
commit c03cd7361b
2 changed files with 14 additions and 3 deletions

15
app.py
View File

@@ -367,8 +367,18 @@ RestartSec=2
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target
""" """
with open(unit_path, "w", encoding="utf-8") as f: try:
f.write(unit) with open(unit_path, "w", encoding="utf-8") as f:
f.write(unit)
except OSError as e:
log_event("error", "socks_bridge_write_failed", unit=unit_path, error=str(e))
return {
"unit": unit_path,
"bridge": f"{BRIDGE_HOST}:{BRIDGE_PORT}",
"target": f"127.0.0.1:{target_port}",
"ok": False,
"error": str(e),
}
run_cmd(["systemctl", "daemon-reload"]) run_cmd(["systemctl", "daemon-reload"])
c1, _, _ = run_cmd(["systemctl", "enable", "--now", "warp-socks-bridge.service"]) c1, _, _ = run_cmd(["systemctl", "enable", "--now", "warp-socks-bridge.service"])
c2, out, err = run_cmd(["systemctl", "is-active", "warp-socks-bridge.service"]) c2, out, err = run_cmd(["systemctl", "is-active", "warp-socks-bridge.service"])
@@ -376,6 +386,7 @@ WantedBy=multi-user.target
"unit": unit_path, "unit": unit_path,
"bridge": f"{BRIDGE_HOST}:{BRIDGE_PORT}", "bridge": f"{BRIDGE_HOST}:{BRIDGE_PORT}",
"target": f"127.0.0.1:{target_port}", "target": f"127.0.0.1:{target_port}",
"ok": c1 == 0 and c2 == 0,
"enable_code": c1, "enable_code": c1,
"active": out.strip() if c2 == 0 else "unknown", "active": out.strip() if c2 == 0 else "unknown",
"stderr": err, "stderr": err,

View File

@@ -14,7 +14,7 @@ NoNewPrivileges=true
PrivateTmp=true PrivateTmp=true
ProtectSystem=full ProtectSystem=full
ProtectHome=true ProtectHome=true
ReadWritePaths=/run /var/log /etc/default /etc/warp-webui /var/backups/warp-webui /etc/sysctl.d /etc/nftables.conf /etc/iptables ReadWritePaths=/run /var/log /etc/default /etc/warp-webui /var/backups/warp-webui /etc/sysctl.d /etc/nftables.conf /etc/iptables /etc/systemd/system
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target