mirror of
https://gitverse.ru/kpa39l/infrastructure.git
synced 2026-11-27 14:33:13 +00:00
openspec: switch-telegram-egress-vps03 — SOCKS5 127.0.0.1:1082 через vps03 (egress 77.67.89.154), tuigram использует его (validate -> archive)
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
schema: spec-driven
|
||||
created: 2026-11-07
|
||||
@@ -0,0 +1,74 @@
|
||||
# Design — switch-telegram-egress-vps03
|
||||
|
||||
## Почему vps01 не годится
|
||||
|
||||
| Проверка | vps01 (1080) | vps03 (1082) |
|
||||
| --- | --- | --- |
|
||||
| TCP до `149.154.175.50:443` через SOCKS | ok | ok |
|
||||
| MTProto handshake | `Timeout expired` (10 с), циклично | `auth_key_id` за ~2 с |
|
||||
| Egress IP | `5.129.217.146` (та же сеть, что у bigbox) | `77.67.89.154` |
|
||||
| UI tuigram | `Connecting…` навсегда | экран логина без ошибок, QR живой |
|
||||
|
||||
Вывод: смена выхода важнее, чем «прокси включён». Туннель в той же сети
|
||||
блокировку не обходит.
|
||||
|
||||
## Почему не MTProto-прокси владельца
|
||||
|
||||
`87.242.100.206:8443`, secret `ee70a1…2e7275` (FakeTLS, домен
|
||||
`tgate.nixg.ru`) — TCP открыт, TLS-хендшейк с SNI `tgate.nixg.ru` проходит
|
||||
(`Verify return code: 0`). Но tuigram 1.8.1 ссылку не применяет:
|
||||
|
||||
- `settings.toml` с `proxy = "https://t.me/proxy?server=…&port=8443&secret=…"`
|
||||
→ в `lsof` прямые `SYN_SENT` на `149.154.175.50:443` и `194.221.250.50:443`;
|
||||
- `TG_PROXY=<та же ссылка>` → то же самое;
|
||||
- `socks5://127.0.0.1:1080` тем же способом применяется (видно ESTABLISHED
|
||||
на локальный порт), то есть парсер настроек работает, проблема именно в
|
||||
`t.me/proxy`-ветке.
|
||||
|
||||
Поэтому путь через SOCKS5 — поддерживаемый и проверенный.
|
||||
|
||||
## Реализация
|
||||
|
||||
`/etc/systemd/system/telegram-tunnel-vps03.service`:
|
||||
|
||||
```
|
||||
[Service]
|
||||
Type=simple
|
||||
User=estorozhenko
|
||||
ExecStart=/usr/bin/ssh -i /home/estorozhenko/.ssh/hostkeyVPS \
|
||||
-D 127.0.0.1:1082 -N \
|
||||
-o ServerAliveInterval=30 -o ServerAliveCountMax=3 \
|
||||
-o ExitOnForwardFailure=yes -o StrictHostKeyChecking=accept-new \
|
||||
-o IdentitiesOnly=yes root@77.67.89.154
|
||||
Restart=always
|
||||
RestartSec=10
|
||||
```
|
||||
|
||||
Отличия от `telegram-tunnel.service`: bind на `127.0.0.1` (старый слушает
|
||||
`0.0.0.0`, что шире нужного), нет зависимости от `wg-quick@wg0` (SSH идёт
|
||||
прямо в интернет, не по WG).
|
||||
|
||||
Пресет: `~/.local/share/tuigram/settings.toml` → `proxy =
|
||||
"socks5://127.0.0.1:1082"`. Применяется при старте клиента, поэтому после
|
||||
смены настройки запущенный tuigram нужно перезапустить.
|
||||
|
||||
## Проверка
|
||||
|
||||
```bash
|
||||
systemctl is-active telegram-tunnel-vps03 # active
|
||||
ss -ltn | grep 1082 # 127.0.0.1:1082
|
||||
curl -s --socks5-hostname 127.0.0.1:1082 https://ifconfig.me # 77.67.89.154
|
||||
nc -zv -X 5 -x 127.0.0.1:1082 149.154.175.50 443 # succeeded
|
||||
```
|
||||
|
||||
Живой клиент: свежий `TG_DATA_DIR` + `TG_PROXY=socks5://127.0.0.1:1082` →
|
||||
`tdlib.log` содержит `auth_key_id`, в UI по `Tab` появляется QR.
|
||||
|
||||
## Риски
|
||||
|
||||
- Зависимость от доступности vps03 и ключа `hostkeyVPS`; при падении SSH
|
||||
юнит перезапускается сам (Restart=always), при долгом отказе — клиент
|
||||
покажет `Connecting…`.
|
||||
- Через vps03 пойдёт и другой трафик, если им пользуются другие сервисы
|
||||
(там уже есть `firecrawl-tunnel.service` на 1081) — это разные ssh-сессии,
|
||||
они не конфликтуют.
|
||||
@@ -0,0 +1,44 @@
|
||||
# Смена выхода для tuigram: SOCKS5 через vps03 вместо vps01
|
||||
|
||||
## Why
|
||||
|
||||
Первый вариант (`telegram-tunnel.service` → vps01, `127.0.0.1:1080`)
|
||||
перестал доводить MTProto-хендшейк: TCP до DC открывается, но TDLib
|
||||
бесконечно висит на `Connecting…`, а `Failed to open connection: Timeout
|
||||
expired` в `tdlib.log` повторяется. Egress vps01 и bigbox находятся в одной
|
||||
российской сети (оба показывают `5.129.217.146`), то есть туннель не меняет
|
||||
юрисдикцию выхода — именно это и режется.
|
||||
|
||||
vps03 (`77.67.89.154`) отдаёт иностранный egress, и через него TDLib
|
||||
получает `auth_key` за ~2 секунды, а tuigram показывает живой QR-код.
|
||||
|
||||
Дополнительно проверена альтернатива — MTProto-прокси владельца
|
||||
(`87.242.100.206:8443`, secret с доменом `tgate.nixg.ru`, TCP/TLS отвечают).
|
||||
tuigram 1.8.1 её НЕ применяет: и `proxy = "https://t.me/proxy?…"` в
|
||||
`settings.toml`, и `TG_PROXY` с той же ссылкой игнорируются — процесс уходит
|
||||
напрямую на `149.154.175.50:443` (видно в `lsof`, `SYN_SENT`). Поэтому
|
||||
рабочий путь — SOCKS5, а не `t.me/proxy`-ссылка.
|
||||
|
||||
## What Changes
|
||||
|
||||
- Новый systemd-юнит `telegram-tunnel-vps03.service`: `ssh -D 127.0.0.1:1082`
|
||||
→ `root@77.67.89.154`, ключ `hostkeyVPS`, `Restart=always`, включён в
|
||||
автозапуск. Слушает ТОЛЬКО localhost.
|
||||
- Пресет прокси в `~/.local/share/tuigram/settings.toml` переводится с
|
||||
`socks5://127.0.0.1:1080` на `socks5://127.0.0.1:1082`.
|
||||
- `telegram-tunnel.service` (vps01, 1080) НЕ трогаем: он остаётся для других
|
||||
задач и покрыт спекой `tunnel-proxy`.
|
||||
|
||||
## Impact
|
||||
|
||||
- bigbox, `/etc/systemd/system/telegram-tunnel-vps03.service`, порт
|
||||
`127.0.0.1:1082`, исходящий SSH 22 до `77.67.89.154`.
|
||||
- Rollback: `systemctl disable --now telegram-tunnel-vps03`, вернуть
|
||||
`settings.toml` на `socks5://127.0.0.1:1080`.
|
||||
|
||||
## Non-goals
|
||||
|
||||
- Не чиним egress vps01 и не выясняем, почему Telegram перестал отвечать
|
||||
через него: для клиента достаточно рабочего выхода.
|
||||
- Не настраиваем MTProto-прокси в tuigram обходными путями (патч бинарника,
|
||||
локальный шим) — ограничиваемся поддерживаемым SOCKS5.
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
# terminal-telegram-client Specification
|
||||
|
||||
## MODIFIED Requirements
|
||||
|
||||
### Requirement: Proxy Preset Before First Login
|
||||
|
||||
The client MUST default to the SOCKS5 tunnel that leaves the country
|
||||
(`127.0.0.1:1082` → vps03) before the first login, because direct MTProto to
|
||||
Telegram datacenters is blocked from this host and a tunnel that egresses from
|
||||
the same network as the host does not bypass the block.
|
||||
|
||||
#### Scenario: Settings file carries the proxy
|
||||
- GIVEN `~/.local/share/tuigram/settings.toml` does not exist yet
|
||||
- WHEN the proxy preset is applied
|
||||
- THEN the file contains `proxy = "socks5://127.0.0.1:1082"`
|
||||
- AND an existing file is not overwritten without an explicit decision
|
||||
|
||||
#### Scenario: Proxy path is reachable
|
||||
- GIVEN `telegram-tunnel-vps03.service` is active
|
||||
- WHEN opening a TCP connection to `149.154.175.50:443` through
|
||||
`127.0.0.1:1082`
|
||||
- THEN the connection succeeds
|
||||
- AND `tdlib.log` records an `auth_key_id` for the main datacenter, i.e. the
|
||||
MTProto handshake actually completed through the tunnel
|
||||
- AND the same connection attempted directly fails, confirming the proxy is
|
||||
required rather than optional
|
||||
|
||||
#### Scenario: Egress differs from the host's own address
|
||||
- GIVEN the tunnel is up
|
||||
- WHEN querying `https://ifconfig.me` through `127.0.0.1:1082`
|
||||
- THEN the reported address is `77.67.89.154` (vps03)
|
||||
- AND it differs from the address seen without a proxy, which is the condition
|
||||
that makes the tunnel useful at all
|
||||
|
||||
#### Scenario: One-off override
|
||||
- GIVEN the preset points at `127.0.0.1:1082`
|
||||
- WHEN the client is started as `TG_PROXY=socks5://host:port tuigram`
|
||||
- THEN the environment value takes precedence over the saved setting
|
||||
|
||||
#### Scenario: MTProto proxy links are not a substitute
|
||||
- GIVEN a working MTProto proxy reachable from the host
|
||||
- WHEN it is supplied as a `t.me/proxy` link through `settings.toml` or
|
||||
`TG_PROXY`
|
||||
- THEN tuigram 1.8.1 MUST NOT be assumed to use it: the observed behaviour is a
|
||||
direct connection attempt to the datacenter, so the SOCKS5 preset stays the
|
||||
supported path
|
||||
|
||||
## ADDED Requirements
|
||||
|
||||
### Requirement: Dedicated Egress Tunnel
|
||||
|
||||
The host MUST run a dedicated SOCKS5 tunnel to vps03 for the terminal Telegram
|
||||
client, independent of tunnels serving other tools.
|
||||
|
||||
#### Scenario: Unit is enabled and listening on localhost only
|
||||
- GIVEN the host boots
|
||||
- WHEN systemd starts `telegram-tunnel-vps03.service`
|
||||
- THEN it listens on `127.0.0.1:1082` and not on wildcard addresses
|
||||
- AND the unit is enabled in `multi-user.target.wants`
|
||||
|
||||
#### Scenario: Tunnel dies
|
||||
- GIVEN the SSH process exits unexpectedly
|
||||
- WHEN systemd detects the failure
|
||||
- THEN the service restarts automatically (`Restart=always`, `RestartSec=10`)
|
||||
|
||||
#### Scenario: Existing tunnels are untouched
|
||||
- GIVEN `telegram-tunnel.service` (vps01, `127.0.0.1:1080`) serves other tasks
|
||||
- WHEN the vps03 tunnel is added or restarted
|
||||
- THEN the vps01 tunnel keeps running and its port binding is unchanged
|
||||
@@ -0,0 +1,39 @@
|
||||
# Tasks — switch-telegram-egress-vps03
|
||||
|
||||
## 1. Диагностика (подтвердить, что дело в выходе)
|
||||
|
||||
- [x] 1.1 Прямой TCP до DC заблокирован, через `127.0.0.1:1080` (vps01) —
|
||||
открывается; egress vps01 = `5.129.217.146`, как у bigbox.
|
||||
- [x] 1.2 Через SOCKS vps01 TDLib не доходит до `auth_key`
|
||||
(`Failed to open connection: Timeout expired`), UI висит на `Connecting…`.
|
||||
- [x] 1.3 MTProto-прокси владельца (`87.242.100.206:8443`, FakeTLS
|
||||
`tgate.nixg.ru`) доступен (TCP + TLS ok), но tuigram 1.8.1 ссылку
|
||||
`t.me/proxy` не применяет — уходит напрямую (`SYN_SENT` на DC).
|
||||
|
||||
## 2. Туннель
|
||||
|
||||
- [x] 2.1 Создать `/etc/systemd/system/telegram-tunnel-vps03.service`
|
||||
(`ssh -D 127.0.0.1:1082` → `root@77.67.89.154`, ключ `hostkeyVPS`).
|
||||
Верификация: `systemctl is-active` → active, `ss -ltn | grep 1082`.
|
||||
- [x] 2.2 Включить в автозапуск: `systemctl enable --now`.
|
||||
Верификация: симлинк в `multi-user.target.wants`.
|
||||
- [x] 2.3 Проверить выход и доступность DC:
|
||||
`curl --socks5-hostname 127.0.0.1:1082 https://ifconfig.me` → `77.67.89.154`;
|
||||
`nc -zv -X 5 -x 127.0.0.1:1082 149.154.175.50 443` → succeeded.
|
||||
|
||||
## 3. Клиент
|
||||
|
||||
- [x] 3.1 `~/.local/share/tuigram/settings.toml` →
|
||||
`proxy = "socks5://127.0.0.1:1082"`.
|
||||
Верификация: `grep proxy …/settings.toml`.
|
||||
- [x] 3.2 Живой прогон с отдельным `TG_DATA_DIR`: `auth_key_id` в
|
||||
`tdlib.log`, по `Tab` — QR-код, статус `Connecting…` отсутствует.
|
||||
- [ ] 3.3 Перезапустить рабочий экземпляр клиента у владельца (настройка
|
||||
читается только при старте) и войти по номеру/QR.
|
||||
|
||||
## 4. Фиксация
|
||||
|
||||
- [x] 4.1 Обновить `/opt/tuigram/README.md` (прокси 1082, юнит, почему не
|
||||
`t.me/proxy`).
|
||||
- [x] 4.2 Обновить `STATUS.md` и `WALKTHROUGH.md`.
|
||||
- [x] 4.3 `openspec validate switch-telegram-egress-vps03 --strict` → archive.
|
||||
@@ -57,29 +57,47 @@ Installation and update MUST use the upstream GitHub release asset for
|
||||
|
||||
### Requirement: Proxy Preset Before First Login
|
||||
|
||||
The client MUST default to the existing SOCKS5 tunnel at `127.0.0.1:1080`
|
||||
before the first login, because direct MTProto to Telegram datacenters is
|
||||
blocked from this host.
|
||||
The client MUST default to the SOCKS5 tunnel that leaves the country
|
||||
(`127.0.0.1:1082` → vps03) before the first login, because direct MTProto to
|
||||
Telegram datacenters is blocked from this host and a tunnel that egresses from
|
||||
the same network as the host does not bypass the block.
|
||||
|
||||
#### Scenario: Settings file carries the proxy
|
||||
- GIVEN `~/.local/share/tuigram/settings.toml` does not exist yet
|
||||
- WHEN the proxy preset is applied
|
||||
- THEN the file contains `proxy = "socks5://127.0.0.1:1080"`
|
||||
- THEN the file contains `proxy = "socks5://127.0.0.1:1082"`
|
||||
- AND an existing file is not overwritten without an explicit decision
|
||||
|
||||
#### Scenario: Proxy path is reachable
|
||||
- GIVEN `telegram-tunnel.service` is active
|
||||
- WHEN opening a TCP connection to `149.154.167.51:443` through
|
||||
`127.0.0.1:1080`
|
||||
- GIVEN `telegram-tunnel-vps03.service` is active
|
||||
- WHEN opening a TCP connection to `149.154.175.50:443` through
|
||||
`127.0.0.1:1082`
|
||||
- THEN the connection succeeds
|
||||
- AND `tdlib.log` records an `auth_key_id` for the main datacenter, i.e. the
|
||||
MTProto handshake actually completed through the tunnel
|
||||
- AND the same connection attempted directly fails, confirming the proxy is
|
||||
required rather than optional
|
||||
|
||||
#### Scenario: Egress differs from the host's own address
|
||||
- GIVEN the tunnel is up
|
||||
- WHEN querying `https://ifconfig.me` through `127.0.0.1:1082`
|
||||
- THEN the reported address is `77.67.89.154` (vps03)
|
||||
- AND it differs from the address seen without a proxy, which is the condition
|
||||
that makes the tunnel useful at all
|
||||
|
||||
#### Scenario: One-off override
|
||||
- GIVEN the preset points at `127.0.0.1:1080`
|
||||
- GIVEN the preset points at `127.0.0.1:1082`
|
||||
- WHEN the client is started as `TG_PROXY=socks5://host:port tuigram`
|
||||
- THEN the environment value takes precedence over the saved setting
|
||||
|
||||
#### Scenario: MTProto proxy links are not a substitute
|
||||
- GIVEN a working MTProto proxy reachable from the host
|
||||
- WHEN it is supplied as a `t.me/proxy` link through `settings.toml` or
|
||||
`TG_PROXY`
|
||||
- THEN tuigram 1.8.1 MUST NOT be assumed to use it: the observed behaviour is a
|
||||
direct connection attempt to the datacenter, so the SOCKS5 preset stays the
|
||||
supported path
|
||||
|
||||
### Requirement: Operators' Documentation
|
||||
|
||||
`/opt/tuigram/README.md` MUST document the installed version, how to update
|
||||
@@ -90,3 +108,24 @@ and roll back, the proxy setting, and where user data lives.
|
||||
- WHEN comparing it to the installed artifacts
|
||||
- THEN the documented version equals `/opt/tuigram/VERSION`
|
||||
- AND the documented data directory equals the path printed by `tuigram --help`
|
||||
|
||||
### Requirement: Dedicated Egress Tunnel
|
||||
|
||||
The host MUST run a dedicated SOCKS5 tunnel to vps03 for the terminal Telegram
|
||||
client, independent of tunnels serving other tools.
|
||||
|
||||
#### Scenario: Unit is enabled and listening on localhost only
|
||||
- GIVEN the host boots
|
||||
- WHEN systemd starts `telegram-tunnel-vps03.service`
|
||||
- THEN it listens on `127.0.0.1:1082` and not on wildcard addresses
|
||||
- AND the unit is enabled in `multi-user.target.wants`
|
||||
|
||||
#### Scenario: Tunnel dies
|
||||
- GIVEN the SSH process exits unexpectedly
|
||||
- WHEN systemd detects the failure
|
||||
- THEN the service restarts automatically (`Restart=always`, `RestartSec=10`)
|
||||
|
||||
#### Scenario: Existing tunnels are untouched
|
||||
- GIVEN `telegram-tunnel.service` (vps01, `127.0.0.1:1080`) serves other tasks
|
||||
- WHEN the vps03 tunnel is added or restarted
|
||||
- THEN the vps01 tunnel keeps running and its port binding is unchanged
|
||||
|
||||
Reference in New Issue
Block a user