Files
mtusi2026lab7-safronov/evidence/security/https-hooks.md
T
2026-11-17 04:49:45 +03:00

121 lines
8.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Hook-и стенда на HTTPS (change `pki-ingress-mtls`, задача 5.2)
Дата: 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 api-3)
…
{"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-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 api-4)
…
{"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-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
$ make test-failover ACTION_SCRIPT=scripts/stop-one.sh STOP_MODE=kill (replica api-3)
…
{"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-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
```
Ещё два прогона `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 без
сертификата клиента, порт — `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
…
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-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-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 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"
PASS: lab7 public API scenario; infrastructure and grading evidence remain separate.
exit=0
```
`econ`, `wredis` и `hrsp_5xx` у `BACKEND` — счётчики с запуска LB за все прогоны выше
(остановки реплик посреди записи); у слотов после замены 5xx нет, `failed_attempts` всех
прогонов — 0.