wip: apply pki-ingress-mtls groups 1-4

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-16 06:42:44 +03:00
co-authored by Claude Opus 5.5
parent 44fe7110a2
commit 5c514b09e8
28 changed files with 2067 additions and 60 deletions
+108
View File
@@ -0,0 +1,108 @@
# Внешний HTTPS стенда (change `pki-ingress-mtls`)
Дата: 2026-11-16. Код: рабочее дерево поверх `44fe711` (apply change, до коммита). Спеки
`transport-security` («Внешний HTTPS на балансировщике», «Клиенты стенда проверяют
сертификат»), `load-balancing` («Единая точка входа»), `container-run` («Порты из .env»).
Путь репозитория — `<repo>`.
## Переход стенда (задача 4.4)
Прежний стенд — `make run_docker` на `44fe711` (HTTP на `127.0.0.1:8080`). Затем `make
run_docker` на рабочем дереве: `env_setup` дописал новую переменную в существующий `.env`,
LB и обе реплики пересозданы (новые `secrets`):
```
$ make run_docker
…
added to existing .env: HTTPS_OUT_PORT
env ready: .env, config.toml
infra/pki/pki.sh stand
CA exists, unchanged
…
valid haproxy: … valid api: … valid ingress: …
…
$ docker compose ps --format '{{.Service}} {{.Status}}' | grep -E 'api|haproxy'
api Up 15 seconds (healthy)
api Up 15 seconds (healthy)
haproxy Up 15 seconds (healthy)
$ make lb_stats
svname addr status check_status scur stot econ wretr wredis hrsp_5xx
api-1 192.168.176.10:8080 UP L7OK 0 0 0 0 0 0
api-2 192.168.176.11:8080 UP L7OK 0 0 0 0 0 0
BACKEND - UP - 0 0 0 0 0 0
free slots: 6
```
Проверки слотов (`L7OK`) идут по mTLS: `default-server … ssl verify required … verifyhost api
ssl-min-ver TLSv1.3`, а порт реплики без сертификата клиента не отвечает
(`evidence/security/mtls-lb-api.md`).
## Публичные проверки без аргументов
```
$ make test
python3 tests/smoke.py --base-url "https://localhost:8443" --ca-file "<repo>/.pki/stand/ca.crt"
PASS: lab7 public API scenario; infrastructure and grading evidence remain separate.
$ make test-security
python3 tests/security.py --base-url "https://localhost:8443" --ca-file "<repo>/.pki/stand/ca.crt"
PASS: trusted HTTPS works; untrusted CA rejected. This does NOT verify internal mTLS, OpenBao or hardening.
```
`CA_FILE` по умолчанию — CA стенда, явное значение сильнее:
```
$ make -n test
python3 tests/smoke.py --base-url "https://localhost:8443" --ca-file "<repo>/.pki/stand/ca.crt"
$ make -n test CA_FILE=/x
python3 tests/smoke.py --base-url "https://localhost:8443" --ca-file "/x"
$ make test CA_FILE= # пустой — системное хранилище доверия
FAIL: GET /health/live: connection/TLS failure (URLError)
make: *** [test] Error 1
```
## Отрицательные проверки внешнего канала
Имя не из SAN (`127.0.0.1` вместо `localhost`) с CA стенда — ошибка hostname:
```
$ curl --cacert .pki/stand/ca.crt https://127.0.0.1:8443/health/live
curl: (60) SSL: no alternative certificate subject name matches target ipv4 address '127.0.0.1'
rc=60
$ python3 -c "…urllib.request.urlopen('https://127.0.0.1:8443/health/live', context=ssl.create_default_context(cafile='.pki/stand/ca.crt'))"
URLError <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: IP address mismatch, certificate is not valid for '127.0.0.1'. (_ssl.c:1006)>
```
HTTP открытым текстом на HTTPS-порт — ни одного байта HTTP-ответа (HAProxy закрывает
соединение без ответа):
```
$ printf 'GET /health/live HTTP/1.1\r\nHost: localhost\r\n\r\n' | nc -w 3 127.0.0.1 8443 | head -c 200 | od -c | head -3
(пусто)
```
Устаревший протокол: OpenSSL 4.1 хоста сам не предлагает TLS 1.1 («no protocols available»),
поэтому — с пониженным уровнем безопасности клиента; сервер отвечает alert `protocol
version`. TLS 1.2 и 1.3 с CA стенда и hostname `localhost` проходят:
```
$ openssl s_client -connect 127.0.0.1:8443 -servername localhost -tls1_1 -cipher 'DEFAULT:@SECLEVEL=0' </dev/null
…:error:0A00042E:SSL routines:ssl3_read_bytes:tlsv1 alert protocol version:…:SSL alert number 70
SSL handshake has read 7 bytes and written 127 bytes
New, (NONE), Cipher is (NONE)
$ openssl s_client … -tls1_2 -CAfile .pki/stand/ca.crt -verify_hostname localhost
Protocol: TLSv1.2
$ openssl s_client … -tls1_3 -CAfile .pki/stand/ca.crt -verify_hostname localhost
Protocol: TLSv1.3
Verify return code: 0 (ok)
```
Прежнего HTTP-порта нет, у реплик опубликованных портов нет:
```
$ curl -sS -m 3 http://127.0.0.1:8080/health/live
curl: (7) Failed to connect to 127.0.0.1 port 8080 after 0 ms: Couldn't connect to server
$ docker compose ps --format '{{.Service}} {{.Ports}}' | grep -E '^(api|haproxy) '
api 8080/tcp
api 8080/tcp
haproxy 127.0.0.1:8443->8443/tcp
```