fix: address verify remarks for pki-ingress-mtls

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-17 04:49:45 +03:00
co-authored by Claude Opus 5.5
parent 2649eb24b4
commit 99b8d1b8d4
14 changed files with 487 additions and 170 deletions
+71 -60
View File
@@ -1,102 +1,113 @@
# Hook-и стенда на HTTPS (change `pki-ingress-mtls`, задача 5.2)
Дата: 2026-11-16. Код: `5c514b0` и рабочее дерево apply (`scripts/stop-one.sh` по alias —
`evidence/security/instance-alias.md`). Стенд — `make run_docker`: LB на
`https://localhost:8443`, mTLS LB → реплики. Публичные проверки берут `CA_FILE` стенда из
Makefile. Скрипты `restart.sh` и `rolling-update.sh` не менялись — регрессия прошла без правок.
Сдвиг очереди round-robin между прогонами для разных реплик — один запрос через LB
(`balancer.md`). ID контейнера в строке `STOP_ONE_LOG` укорочен до 12 символов.
Дата: 2026-11-17. Код приложения и стенда на момент съёмки — `2649eb2` (правки verify:
`scripts/stop-one.sh` ищет alias в первых 50 записях журнала процесса — S3, порт health
одним источником `APP__HEALTH_PORT` — W1, срок ответа слушателя health — S2); рабочее дерево
отличалось от него только документами. Первая съёмка (2026-11-16, код `5c514b0` и рабочее
дерево apply со `stop-one.sh` по alias) заменена этой: правки S3, W1 и S2 касаются hook-ов
(`stop-one.sh`, healthcheck в `restart.sh` и `rolling-update.sh`). Стенд — `make run_docker`:
LB на `https://localhost:8443`, mTLS LB → реплики. Публичные проверки берут `CA_FILE` стенда
из Makefile. Скрипты `restart.sh` и `rolling-update.sh` не менялись — регрессия прошла без
правок. Сдвиг очереди round-robin между прогонами — один запрос через LB (`balancer.md`); он не
всегда переводит первую отправку теста на другую реплику, поэтому `stop` второй реплики — из
отдельного прогона того же кода до серии (первый блок ниже). ID контейнера в строке
`STOP_ONE_LOG` укорочен до 12 символов.
```
$ make test-failover ACTION_SCRIPT=scripts/stop-one.sh STOP_MODE=stop (replica api-4)
python3 tests/resilience.py --mode failover --action-script "scripts/stop-one.sh" --base-url "https://localhost:8443" --ca-file "<repo>/.pki/stand/ca.crt"
Executing explicit failover hook; hook output suppressed to avoid leaking secrets.
{"observed_instances_before": 2, "successful_writes": 119, "failed_attempts": 0, "first_recovery_seconds": 1.459}
PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence.
exit=0
STOP_ONE_LOG:
2026-11-17T01:34:28Z TARGET_INSTANCE_ID=cccacf9b0540977e container=c3c948a8138f… mode=stop
make replicas exit=0
$ make test-persistence ACTION_SCRIPT=scripts/restart.sh
python3 tests/resilience.py --mode persistence --action-script "scripts/restart.sh" --base-url "https://localhost:8443" --ca-file "<repo>/.pki/stand/ca.crt"
Executing explicit persistence hook; hook output suppressed to avoid leaking secrets.
PASS: persistence preserved confirmed data and existing session. Hook scope needs operator evidence.
exit=0
$ make test-failover ACTION_SCRIPT=scripts/stop-one.sh STOP_MODE=stop (replica 1)
python3 tests/resilience.py --mode failover --action-script "scripts/stop-one.sh" --base-url "https://localhost:8443" --ca-file "<repo>/.pki/stand/ca.crt"
Executing explicit failover hook; hook output suppressed to avoid leaking secrets.
{"observed_instances_before": 2, "successful_writes": 120, "failed_attempts": 0, "first_recovery_seconds": 1.219}
PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence.
exit=0
STOP_ONE_LOG:
2026-11-16T03:47:08Z TARGET_INSTANCE_ID=25f3831bc035f792 container=bc6852978ba2… mode=stop
mtusi-lab7-api-1 6d771a9c6e5f running Up 20 seconds (healthy)
mtusi-lab7-api-2 bc6852978ba2 exited Exited (0) 14 seconds ago
make replicas exit=0
shift: X-Instance-Id 1cc88155d5304436
$ make test-failover ACTION_SCRIPT=scripts/stop-one.sh STOP_MODE=stop (replica 2)
$ make test-failover ACTION_SCRIPT=scripts/stop-one.sh STOP_MODE=stop (replica api-3)
…
{"observed_instances_before": 2, "successful_writes": 116, "failed_attempts": 0, "first_recovery_seconds": 1.739}
{"observed_instances_before": 2, "successful_writes": 119, "failed_attempts": 0, "first_recovery_seconds": 1.124}
PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence.
exit=0
STOP_ONE_LOG:
2026-11-16T03:47:27Z TARGET_INSTANCE_ID=1cc88155d5304436 container=6d771a9c6e5f… mode=stop
mtusi-lab7-api-1 6d771a9c6e5f exited Exited (0) 14 seconds ago
mtusi-lab7-api-2 bc6852978ba2 running Up 18 seconds (healthy)
2026-11-17T01:35:35Z TARGET_INSTANCE_ID=bfe29cd956caad9c container=1fe4b4c30a20… mode=stop
mtusi-lab7-api-3 1fe4b4c30a20 exited Exited (0) 14 seconds ago
mtusi-lab7-api-4 c3c948a8138f running Up 19 seconds (healthy)
make replicas exit=0
$ make test-failover ACTION_SCRIPT=scripts/stop-one.sh STOP_MODE=kill (replica 1)
$ make test-failover ACTION_SCRIPT=scripts/stop-one.sh STOP_MODE=kill (replica api-4)
…
{"observed_instances_before": 2, "successful_writes": 120, "failed_attempts": 0, "first_recovery_seconds": 0.876}
{"observed_instances_before": 2, "successful_writes": 119, "failed_attempts": 0, "first_recovery_seconds": 0.864}
PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence.
exit=0
STOP_ONE_LOG:
2026-11-16T03:47:45Z TARGET_INSTANCE_ID=6a8eddeefdf77bfc container=bc6852978ba2… mode=kill
mtusi-lab7-api-1 6d771a9c6e5f running Up 18 seconds (healthy)
mtusi-lab7-api-2 bc6852978ba2 exited Exited (137) 15 seconds ago
2026-11-17T01:36:12Z TARGET_INSTANCE_ID=dd5b1c9e472800d4 container=c3c948a8138f… mode=kill
mtusi-lab7-api-3 1fe4b4c30a20 running Up 18 seconds (healthy)
mtusi-lab7-api-4 c3c948a8138f exited Exited (137) 15 seconds ago
make replicas exit=0
shift: X-Instance-Id 12813d3c4eb1425f
$ make test-failover ACTION_SCRIPT=scripts/stop-one.sh STOP_MODE=kill (replica 2)
$ make test-failover ACTION_SCRIPT=scripts/stop-one.sh STOP_MODE=kill (replica api-3)
…
{"observed_instances_before": 2, "successful_writes": 120, "failed_attempts": 0, "first_recovery_seconds": 0.886}
{"observed_instances_before": 2, "successful_writes": 114, "failed_attempts": 0, "first_recovery_seconds": 1.462}
PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence.
exit=0
STOP_ONE_LOG:
2026-11-16T03:48:04Z TARGET_INSTANCE_ID=12813d3c4eb1425f container=6d771a9c6e5f… mode=kill
mtusi-lab7-api-1 6d771a9c6e5f exited Exited (137) 15 seconds ago
mtusi-lab7-api-2 bc6852978ba2 running Up 17 seconds (healthy)
2026-11-17T01:36:31Z TARGET_INSTANCE_ID=25203d92b16ae67b container=1fe4b4c30a20… mode=kill
mtusi-lab7-api-3 1fe4b4c30a20 exited Exited (137) 15 seconds ago
mtusi-lab7-api-4 c3c948a8138f running Up 19 seconds (healthy)
make replicas exit=0
```
Восстановление записи через LB после остановки — 0,9–1,7 с (было в лабе 6 того же порядка):
новое рукопожатие TLS 1.3 LB → реплика на каждый сеанс клиента цепочку таймаутов не
сдвинуло. Тест берёт alias реплики из `X-Instance-Id` первой отправки, hook находит её
контейнер по журналу.
Ещё два прогона `stop` той же серии (01:35:54 и 01:37:12) попали на `api-3` — PASS,
`failed_attempts` 0, восстановление 1,2 и 1,3 с. Восстановление записи через LB после
остановки — 0,9–1,5 с (в первой съёмке 0,9–1,7 с, в лабе 6 того же порядка): новое
рукопожатие TLS 1.3 LB → реплика на каждый сеанс клиента цепочку таймаутов не сдвинуло. Тест
берёт alias реплики из `X-Instance-Id` первой отправки, hook находит её контейнер по первым
записям журнала текущего процесса (у каждого — новый alias после `make replicas`, прежний
alias того же контейнера не совпадает).
Поочерёдная замена: шаг «новая `healthy`» — через loopback-слушатель health (healthcheck без
сертификата клиента), «`UP` в LB» — проверки LB по mTLS:
сертификата клиента, порт — `APP__HEALTH_PORT` окружения), «`UP` в LB» — проверки LB по mTLS.
Запуск сразу после `make replicas` (слот возвращённой реплики ещё `DOWN 1/2`) скрипт отверг
предусловием — `error: replica 1fe4b4c30a20 is not UP in LB (DOWN 1/2): run make replicas and
wait`, ни одной замены; через ~30 с:
```
$ make rolling_update
…
03:48:25 rolling-update: migrate done in 2s
03:48:26 rolling-update: replica 1/2: started new cc1a66e643e3
03:48:27 rolling-update: replica 1/2: new cc1a66e643e3 addr 192.168.176.13 slot api-3 UP in 2s
03:48:28 rolling-update: replica 1/2: drain old 6d771a9c6e5f addr 192.168.176.10 slot api-1
03:48:28 rolling-update: replica 1/2: old 6d771a9c6e5f idle after 0s
03:48:28 rolling-update: replica 1/2: maint slot api-1, stopping old 6d771a9c6e5f
03:48:28 rolling-update: replica 1/2: removed old 6d771a9c6e5f (stop 0s, exit 0)
03:48:29 rolling-update: replica 1/2: slot api-1 ready
03:48:30 rolling-update: replica 2/2: started new 5a09a9bb6663
03:48:31 rolling-update: replica 2/2: new 5a09a9bb6663 addr 192.168.176.10 slot api-1 UP in 2s
03:48:31 rolling-update: replica 2/2: drain old bc6852978ba2 addr 192.168.176.11 slot api-2
03:48:31 rolling-update: replica 2/2: old bc6852978ba2 idle after 0s
03:48:31 rolling-update: replica 2/2: maint slot api-2, stopping old bc6852978ba2
03:48:32 rolling-update: replica 2/2: removed old bc6852978ba2 (stop 1s, exit 0)
03:48:32 rolling-update: replica 2/2: slot api-2 ready
03:48:33 rolling-update: done: 2 replicas cc1a66e643e3 5a09a9bb6663 UP in 12s
01:37:46 rolling-update: start: 2 replicas 1fe4b4c30a20 c3c948a8138f, image mtusi-messenger:lab7 from working tree
01:37:47 rolling-update: build done in 1s
01:37:49 rolling-update: migrate done in 2s
01:37:50 rolling-update: replica 1/2: started new e0ee35b619a8
01:37:52 rolling-update: replica 1/2: new e0ee35b619a8 addr 192.168.176.13 slot api-3 UP in 3s
01:37:53 rolling-update: replica 1/2: drain old 1fe4b4c30a20 addr 192.168.176.11 slot api-2
01:37:53 rolling-update: replica 1/2: old 1fe4b4c30a20 idle after 0s
01:37:53 rolling-update: replica 1/2: maint slot api-2, stopping old 1fe4b4c30a20
01:37:53 rolling-update: replica 1/2: removed old 1fe4b4c30a20 (stop 0s, exit 0)
01:37:54 rolling-update: replica 1/2: slot api-2 ready
01:37:54 rolling-update: replica 2/2: started new cef19a211f95
01:37:56 rolling-update: replica 2/2: new cef19a211f95 addr 192.168.176.11 slot api-2 UP in 2s
01:37:56 rolling-update: replica 2/2: drain old c3c948a8138f addr 192.168.176.10 slot api-1
01:37:56 rolling-update: replica 2/2: old c3c948a8138f idle after 0s
01:37:56 rolling-update: replica 2/2: maint slot api-1, stopping old c3c948a8138f
01:37:57 rolling-update: replica 2/2: removed old c3c948a8138f (stop 1s, exit 0)
01:37:58 rolling-update: replica 2/2: slot api-1 ready
01:37:58 rolling-update: done: 2 replicas e0ee35b619a8 cef19a211f95 UP in 12s
exit=0
mtusi-lab7-api-3 cc1a66e643e3 running Up 7 seconds (healthy)
mtusi-lab7-api-4 5a09a9bb6663 running Up 3 seconds (healthy)
mtusi-lab7-api-5 e0ee35b619a8 running Up 8 seconds (healthy)
mtusi-lab7-api-6 cef19a211f95 running Up 4 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 369 0 0 6 0
api-2 192.168.176.11:8080 UP L7OK 0 289 0 0 15 0
api-3 192.168.176.13:8080 UP L7OK 0 0 0 0 0 0
BACKEND - UP - 0 719 5 0 10 5
BACKEND - UP - 0 930 5 0 16 5
free slots: 6
$ make test
python3 tests/smoke.py --base-url "https://localhost:8443" --ca-file "<repo>/.pki/stand/ca.crt"