Files
infrastructure/openspec/specs/tunnel-proxy/spec.md
T

98 lines
3.9 KiB
Markdown

# tunnel-proxy Specification
## Purpose
TBD - created by archiving change add-vpn-tunnel-proxy. Update Purpose after archive.
## Requirements
### Requirement: Persistent SOCKS5 Tunnel
The system MUST maintain a persistent SOCKS5 proxy tunnel from the host to VPS01, listening on 127.0.0.1:1080.
#### Scenario: Tunnel starts on boot
- GIVEN the host boots
- WHEN systemd starts telegram-tunnel.service
- THEN the tunnel listens on 127.0.0.1:1080
- AND the SSH connection is established with key /mnt/yandex-disk/.ssh_box/timewebVPS
#### Scenario: Tunnel dies
- GIVEN the tunnel process exits unexpectedly
- WHEN systemd detects failure
- THEN the service restarts automatically (Restart=always)
### Requirement: Tunnel Health Monitoring
The system MUST verify tunnel liveness at least every 60 seconds.
#### Scenario: Health check passes
- GIVEN the tunnel is running
- WHEN checking connectivity through 127.0.0.1:1080
- THEN curl through the proxy returns HTTP 200 for a known endpoint
#### Scenario: Health check fails
- GIVEN the tunnel is down
- WHEN the watchdog fires
- THEN a notification is raised (no routine "all ok" messages)
### Requirement: Relay Through vps02 When a Direct Link Is Blocked
The WireGuard mesh MUST stay usable when the path between two nodes is
blocked by an external party, without adding a new tunnel or a new port: the
mesh MUST route the affected pair through a node that still has working links
to both sides.
#### Scenario: Blocked pair still passes traffic
- GIVEN the direct path between bigbox (`178.176.197.2`) and vps01
(`5.129.217.146`) is blocked at the IP level (ICMP, TCP and UDP all dead)
- AND vps02 (`10.8.0.4`) has live WireGuard handshakes with both nodes
- WHEN `10.8.0.1/32` is routed to vps02 on bigbox and `10.8.0.2/32` to vps02
on vps01
- THEN `ping 10.8.0.1` from bigbox succeeds without an SSH jump host
- AND the relay node forwards the packets, i.e. WireGuard on vps01 stays
untouched and keeps listening on the same port and address
#### Scenario: No new port or tunnel is opened
- GIVEN the relay is configured
- WHEN the resulting configuration is inspected
- THEN all nodes still use UDP `51820` and the existing `10.8.0.x` addresses
- AND no additional systemd tunnel unit exists on any node
#### Scenario: Blocked UDP path to the egress peer is relayed too
- GIVEN bigbox sends WireGuard keepalives to vps03 (`77.67.89.154:51820`) but
a packet capture on vps03 shows no inbound UDP from `178.176.197.2`, while
TCP and ICMP to that address work
- AND `10.8.0.3/32` on bigbox is pinned to the peer whose handshake has been
dead for hours
- WHEN `10.8.0.3/32` is moved to the vps02 peer and vps03's stale bigbox peer
is disabled
- THEN `ping 10.8.0.3` from bigbox succeeds through vps02
- AND `ping 10.8.0.2` from vps03 succeeds through vps02 in the opposite
direction
#### Scenario: Overlapping AllowedIPs do not hijack relayed traffic
- GIVEN a node carries `10.8.0.2/32` on a peer whose link is dead and
`10.8.0.0/24` on the relay peer
- WHEN a relayed packet is sent to `10.8.0.2`
- THEN the more specific `/32` MUST NOT be allowed to win, because the
longest-prefix match would send the packet down the dead link
- AND the stale `/32` is removed so the address falls under the relay peer
#### Scenario: Consumers recover on their own
- GIVEN `telegram-tunnel.service` keeps restarting because `10.8.0.1:22`
times out
- WHEN the relay restores L3 reachability to `10.8.0.1`
- THEN the service starts listening on `127.0.0.1:1080` without a manual
restart
- AND an HTTP request through that SOCKS5 port reaches Telegram
#### Scenario: Rollback keeps the blocked path blocked
- GIVEN the original `wg0.conf` files are backed up on every changed node
- WHEN the backup is restored and `wg syncconf` is applied
- THEN the pre-change peering is back
- AND the direct bigbox↔vps01 path remains blocked, which is the expected
original state rather than a regression