fix(server): v3.6 — implicit auto-NAT on Linux (root cause of full-VPN dying)

Symptoms: in default = "VPN" full-VPN mode external internet was dead even
though tunnel-internal ping (10.7.0.1) worked perfectly. The tunnel itself
was assembled and AEAD-encrypted (see TEST_CASES.md), but packets sent
through it died on the server side.

Root cause: server's `[server.nat]` was opt-in. On the production server
(187.77.67.17) deployed before v2, the section is absent in
/etc/aura/server.toml, so `aura server` never ran the iptables MASQUERADE
plan. Packets egressed to the upstream router with src = 10.7.0.10 (RFC1918),
which the provider's reverse-path filter dropped — full-VPN clients saw
"internet is dead". Tunnel-internal pool addresses worked because they
don't need NAT.

Fix:
* `server.rs`: when `[server.nat]` is absent in server.toml AND we are on
  Linux, attempt auto-NAT with an auto-detected egress_iface. If detection
  or the iptables call fails we DON'T bail — we log a loud error and let
  the server come up so safe-mode clients keep working.
* `config.rs`: `ServerNatSection::default()` now defaults `auto = true`.
  A bare `[server.nat]` header (no `auto =`) now means "yes, enable it"
  instead of the silent-noop it used to be.
* New tests for both bare-header and explicit `auto = false` opt-out paths.
* `docs/server_nat_fix.md`: step-by-step instructions for fixing the
  existing 187.77.67.17 server (binary upgrade vs. manual server.toml
  patch vs. fully-manual sysctl + iptables).
* `docs/deployment.md`: replaces "manual mandatory step" wording with
  the new auto-NAT story.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
xah30
2026-06-01 14:11:24 +03:00
parent 7c8ea919c4
commit 15c7da12fe
4 changed files with 296 additions and 20 deletions
+19 -1
View File
@@ -151,7 +151,22 @@ masquerade = true
#### IP-форвардинг и NAT (для выхода клиентов в интернет)
В v1 настройка egress на стороне сервера — **обязательный ручной шаг**. На Linux:
**v3.6 и новее:** настройка делается **автоматически** при старте `aura server`.
Если в `server.toml` есть секция `[server.nat]` с `auto = true` (так пишет
`aura server-init`) — сервер сам сделает `sysctl net.ipv4.ip_forward=1` и
поставит правило MASQUERADE на нужный интерфейс, а при остановке откатит обе
операции. Если секции вообще нет (legacy-конфиг до v2), сервер всё равно
попытается включить NAT с автодетектом egress-интерфейса (**implicit auto-NAT**)
и громко скажет это в логе.
Опт-аут — если оператор уже сам управляет фаерволом:
```toml
[server.nat]
auto = false
```
**Legacy / ручной путь** (v1 или сценарий с отключённым auto-NAT):
```bash
# 1) Включить IP-форвардинг.
@@ -167,6 +182,9 @@ sudo iptables -t nat -A POSTROUTING \
Подставьте свой `pool_cidr` и имя интернет-интерфейса.
Подробный сценарий «существующий сервер до v3.6, full-VPN не работает» разобран
в [`docs/server_nat_fix.md`](server_nat_fix.md).
### 2.5. Запуск сервера
```bash