# Что доказывает: mTLS приёма OTLP Collector с раздельными identity отправителей # (рубрика «3»: TLS, сеть/аутентификация запрещает произвольный ingest; «4»: # mTLS с раздельными identities и отрицательный набор пункта 2 для Collector; # contracts/trust-matrix.md, строка «API/worker → Collector» и каналы шлюза; # обязательная проверка 3; перенос telemetry-mtls): приём — только TLS-шлюз # otel-gateway (HAProxy, TLS 1.3, сертификат клиента CA стенда, CRL, allowlist # api / worker / relay по всей строке SAN, только POST /v1/traces|metrics|logs); # Collector слушает OTLP только на loopback сетевого пространства шлюза; SDK # трёх процессов — только https, свой контекст, без файлов или с IP — код 2. # Отрицательная проверка одной командой make telemetry-tls-check; на стенде «до» # (da3ac78) она красная; отчёт «до» и «после»; контроль; отзыв identity # api-client; ловушки сетевого пространства; переход рабочего стенда с данными. # Дата: 2026-12-01 UTC, 15:05–17:30. # Окружение: машина переноса (не машина замеров): macOS 26, Docker 29.9.3 (ВМ 12 CPU # / 11,6 ГиБ), Compose 5.7.1, python3 хоста 3.11.9. Параллельно на машине шёл # чужой стенд (mtusi-lab7). # Стенд: рабочий vladimirceva-lab7, LB https://localhost:18443, Grafana # localhost:13180 (порты .env машины); портов шлюза и Collector на хосте нет. # Код: стенд «до» — git archive da3ac78 (перенос messaging-telemetry-mtls), # запущенный из временного каталога с .env и .pki/stand рабочего стенда под тем # же проектом, проверка — текущая scripts/lab7.py с COMPOSE_FILE каталога «до»; # остальное — src_sha256 # 5d6d03d7f9ae981534ffc455dbdb52e18eadfbb2548047757691d0a99df01ff7 (перенос # telemetry-mtls; образ mtusi-messenger-vladimirceva:lab7 — тот же хеш). # Повторить: make pki-stand; make up; make telemetry-tls-check [REPORT=1]; # make unit-test; make telemetry-check; make test-isolated; make failure-checks. # --- 1. PKI: две новые identity, прежние leaf не перевыпущены --- $ make pki-stand ... valid relay: serial 01A1669353DC029D45D5137E797255D6, not after 2027-02-25 03:08:49Z, ... valid worker: serial 01A1669353DC029D45D5137E797255DE, not after 2027-02-25 03:16:33Z, ... reissue otel-collector: missing issued otel-collector (server, SAN otel-collector): serial 01A1669353DC029D45D5137E797255E3, not after 2027-03-01 15:12:08Z, ... reissue api-client: missing issued api-client (client, SAN api): serial 01A1669353DC029D45D5137E797255E4, not after 2027-03-01 15:12:08Z, ... # Серийные номера haproxy, api, ingress, postgres, valkey, s3, rabbitmq, relay, # worker — прежние. # --- 2. Быстрые тесты: красные на коде «до», зелёные после --- $ (код da3ac78 + новый файл) pytest student-tests/unit/test_telemetry_tls.py 7 failed, 1 passed, 19 errors in 1.72s # errors — списка identity без otel-collector фикстура PKI не принимает; failed — # http:// в адресе, нет переменных TELEMETRY_*_FILE, нет шлюза и его allowlist, # compose без сетевого пространства шлюза и файлов identity. $ make unit-test ======================= 187 passed, 1 warning in 22.75s ======================== # 160 прежних + 27 student-tests/unit/test_telemetry_tls.py; в прежних намеренно # изменены ожидания: наборы проверок процессов (+telemetry) и https в адресе. # --- 3. Красный прогон и отчёт «до»: стенд da3ac78 (OTLP открытым текстом) --- $ COMPOSE_FILE=<временный каталог da3ac78>/compose.yaml COMPOSE_ENV_FILES=<репозиторий>/.env \ python3 scripts/lab7.py telemetry-tls-check FAIL service otel-gateway is healthy: none FAIL the Collector lives in the namespace of the running gateway: vladimirceva-lab7_defa FAIL default: OTLP export without TLS -> no HTTP response: HTTP 200 FAIL default: no client certificate -> handshake refused: no TLS on the port FAIL default: certificate of another CA (SAN worker) -> handshake refused: no TLS on the port ... FAIL telemetry: OTLP export without TLS -> no HTTP response: HTTP 200 ... FAIL temporary gateway: revoked leaf -> refused: no gateway PASS listening outside loopback = 4318 8888 8889: 4318 8888 8889 FAIL Collector receiver :14318 only on loopback: none FAIL allowlist of the gateway = api, worker, relay: none PASS signals of messenger-api arrive (process CPU grows in Prometheus): +0.17 s ... telemetry-tls-check: FAIL (9/45 checks, 3 s) cleanup: 0 probe container(s) removed, temporary key directory removed: True $ ... telemetry-tls-check --report == receiver the Collector receives OTLP directly (no gateway) == allowlist (DNS SAN) none == listeners of the Collector network namespace :::4318 :::8888 :::8889 127.0.0.11:42967 (loopback) == otel-collector:4318 from network default OTLP export without TLS: HTTP 200 no client certificate: no TLS on the port TLS 1.2 only (worker): no TLS on the port identity haproxy of the stand CA: no TLS on the port identity api (leaf api-client): empty export: no TLS on the port identity worker: empty export: no TLS on the port identity relay: empty export: no TLS on the port == otel-collector:4318 from network telemetry OTLP export without TLS: HTTP 200 ... REPORT: what the OTLP receiver accepts (no verdict) # «До»: любой контейнер сети отправляет телеметрию без TLS и без identity (200). # --- 4. Переход рабочего стенда с данными (da3ac78 → перенос) --- $ python3 transition.py before before: upload 202 ready $ make up ... (код 0, 34,7 с, с первого раза; .env не менялся) otel-collector Up 27 seconds otel-gateway Up 28 seconds (healthy) ... $ python3 transition.py after after: previous token works, attachment ready 99ea7533c441 after: new upload 202 ready $ docker compose logs otel-gateway otel-gateway-1 | otlp-refused <адрес> san=- tls=TLSv1.3 reason=- conn_err=SSL handshake failure ssl_err=error:0A00009C:SSL routines::http request cert_err=X509_V_OK ca_err=X509_V_OK term=PR-- # Прежние процессы ещё слали открытым текстом, пока compose их не пересоздал, — # шлюз такие соединения закрывает. Сессия и вложение «до» на месте. # --- 5. make telemetry-tls-check на стенде переноса --- $ make telemetry-tls-check PASS service otel-gateway is healthy: healthy PASS the Collector lives in the namespace of the running gateway: container:5d601af1ed1b stand network vladimirceva-lab7_default: probe container of image mtusi-messenger-vladimirceva:lab7 PASS default: OTLP export without TLS -> no HTTP response: no HTTP response, RemoteDisconnected PASS default: no client certificate -> handshake refused: handshake refused, [SSL: TLSV13_ALERT_CERTIFICATE_REQUIRED] tlsv13 alert certificate required (_ssl PASS default: certificate of another CA (SAN worker) -> handshake refused: handshake refused, [SSL: TLSV1_ALERT_UNKNOWN_CA] tlsv1 alert unknown ca (_ssl.c:2660) PASS default: server certificate of the stand CA (telemetry-probe) -> handshake refused: handshake refused, [SSL: SSLV3_ALERT_UNSUPPORTED_CERTIFICATE] ssl/tls alert unsupported certificate PASS default: TLS 1.2 only (worker) -> handshake refused: handshake refused, [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:1032) PASS default: identity of the stand CA outside the list (telemetry-probe) -> closed without HTTP response: closed without HTTP response, BrokenPipeError TLSv1.3 PASS default: identity haproxy of the stand CA -> closed without HTTP response: closed without HTTP response, BrokenPipeError TLSv1.3 PASS default: certificate with two names (api and another) -> closed without HTTP response: closed without HTTP response, BrokenPipeError TLSv1.3 PASS default: client trusts another CA -> client rejected certificate: client rejected certificate, unable to get local issuer certificate PASS default: server name outside SAN (api) -> client rejected certificate: client rejected certificate, Hostname mismatch, certificate is not valid for 'api'. PASS default: identity api (leaf api-client): empty export -> HTTP 200: HTTP 200, TLSv1.3 PASS default: identity worker: empty export -> HTTP 200: HTTP 200, TLSv1.3 PASS default: identity relay: empty export -> HTTP 200: HTTP 200, TLSv1.3 PASS default: identity relay: GET /v1/traces -> HTTP 404: HTTP 404, TLSv1.3 PASS default: identity api: POST /v1/other -> HTTP 404: HTTP 404, TLSv1.3 PASS default: Collector receiver port 14318 -> not reachable: not reachable, ConnectionRefusedError PASS default: gateway health port 8405 -> not reachable: not reachable, ConnectionRefusedError stand network vladimirceva-lab7_telemetry: probe container of image mtusi-messenger-vladimirceva:lab7 ... (те же 17 случаев из сети telemetry — PASS) temporary gateway with the same configuration and its own PKI PASS temporary gateway: revoked leaf worker -> handshake refused: handshake refused, [SSL: SSLV3_ALERT_CERTIFICATE_REVOKED] ssl/tls alert certificate revoked (_ssl.c PASS temporary gateway: valid leaf relay (control: gateway without Collector) -> HTTP 503: HTTP 503, TLSv1.3 PASS temporary gateway: gateway log names the reason -> X509_V_ERR_CERT_REVOKED: X509_V_ERR_CERT_REVOKED PASS listening outside loopback = 4318 8888 8889: 4318 8888 8889 PASS Collector receiver :14318 only on loopback: 127.0.0.1:14318 (loopback) PASS gateway health :8405 only on loopback: 127.0.0.1:8405 (loopback) PASS gateway and Collector publish no ports: none PASS allowlist of the gateway = api, worker, relay: DNS:api DNS:worker DNS:relay PASS signals of messenger-api arrive (process CPU grows in Prometheus): +3.93 s PASS signals of messenger-worker arrive (process CPU grows in Prometheus): +1.62 s PASS signals of messenger-relay arrive (process CPU grows in Prometheus): +1.39 s telemetry-tls-check: PASS (47/47 checks, 31 s) cleanup: 0 probe container(s) removed, temporary key directory removed: True $ make telemetry-tls-check REPORT=1 == receiver TLS gateway otel-gateway in front of the Collector == allowlist (DNS SAN) DNS:api DNS:worker DNS:relay == listeners of the Collector network namespace :::8888 :::8889 0.0.0.0:4318 127.0.0.1:8405 (loopback) 127.0.0.1:14318 (loopback) 127.0.0.11:45403 (loopback) == otel-collector:4318 from network default OTLP export without TLS: no HTTP response (RemoteDisconnected) no client certificate: handshake refused ([SSL: TLSV13_ALERT_CERTIFICATE_REQUIRED] tlsv13 alert certificate required (_ssl) TLS 1.2 only (worker): handshake refused ([SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:1032)) identity haproxy of the stand CA: closed without HTTP response (BrokenPipeError TLSv1.3) identity api (leaf api-client): empty export: HTTP 200 (TLSv1.3) identity worker: empty export: HTTP 200 (TLSv1.3) identity relay: empty export: HTTP 200 (TLSv1.3) ... REPORT: what the OTLP receiver accepts (no verdict) # --- 6. Контроль: лишняя identity в allowlist краснит проверку --- # infra/otel/gateway.cfg: allowlist + DNS:haproxy $ docker compose restart otel-gateway; make telemetry-tls-check FAIL default: identity haproxy of the stand CA -> closed without HTTP response: HTTP 200, TLSv1.3 FAIL telemetry: identity haproxy of the stand CA -> closed without HTTP response: HTTP 200, TLSv1.3 FAIL allowlist of the gateway = api, worker, relay: DNS:api DNS:worker DNS:relay DNS:haproxy telemetry-tls-check: FAIL (44/47 checks, 21 s) $ pytest student-tests/unit/test_telemetry_tls.py -k allowlist FAILED student-tests/unit/test_telemetry_tls.py::test_gateway_allowlist_matches_identities # правка возвращена $ docker compose restart otel-gateway; make telemetry-tls-check telemetry-tls-check: PASS (47/47 checks, 26 s) $ make telemetry-tls-check (SIGINT посреди прогона) telemetry-tls-check: interrupted cleanup: 0 probe container(s) removed, temporary key directory removed: True # Контейнеров с меткой проверки и временных каталогов после прерывания — 0. # --- 7. Отзыв identity api-client: новое соединение отвергнуто, приложение живёт --- $ make pki-revoke IDENTITY=api-client revoked api-client: serial 01A1669353DC029D45D5137E797255E4 $ docker compose logs otel-gateway | grep -c CERT_REVOKED (до рестарта шлюза, 18 с) 0 $ docker compose restart otel-gateway Container vladimirceva-lab7-otel-collector-1 Started $ sum by(job)(process_cpu_time_seconds_total) через 50 с messenger-relay=4.29 messenger-worker=2.26 (ряда messenger-api нет) $ docker compose logs otel-gateway | grep otlp-refused | sort | uniq -c 28 otlp-refused <адрес> san=DNS:api tls=TLSv1.3 reason=- conn_err=SSL client certificate not trusted ssl_err=error:0A000086:SSL routines::certificate verify failed cert_err=X509_V_ERR_CERT_REVOKED ca_err=X509_V_OK term=PR-- $ docker compose logs api api-1 | ... WARNING opentelemetry.exporter.otlp.proto.http.metric_exporter [rid=-] Transient error HTTPSConnectionPool(host='otel-collector', port=4318): Max retries exceeded ... $ make test PASS: lab7 public API scenario; infrastructure and grading evidence remain separate. $ make pki-stand reissue api-client: revoked issued api-client (client, SAN api): serial 01A1669353DC029D45D5137E79725611, not after 2027-03-01 15:40:35Z, ... $ docker compose restart otel-gateway; docker compose up -d --force-recreate --no-deps --wait api $ sum by(job)(process_cpu_time_seconds_total) через 50 с messenger-relay=4.99 messenger-worker=2.58 messenger-api=3.48 $ make telemetry-tls-check telemetry-tls-check: PASS (47/47 checks, 6 s) # Отзыв действует на новые соединения после рестарта шлюза (CRL читается при # старте); worker и relay не затронуты; после перевыпуска сигналы api снова идут. # --- 8. Отказ старта: процессы без верных файлов телеметрии --- $ docker compose run --rm --no-deps -T -e <переменная> (у всех трёх одинаково) TELEMETRY_CERT_FILE= -> rc=2 configuration error: invalid client TLS settings: TELEMETRY_CERT_FILE TELEMETRY_KEY_FILE=/run/secrets/missing.key -> rc=2 configuration error: invalid client TLS settings: TELEMETRY_KEY_FILE TELEMETRY_CRL_FILE=/run/secrets/ca.crt -> rc=2 configuration error: invalid client TLS settings: TELEMETRY_CRL_FILE TELEMETRY_KEY_FILE=/run/secrets/ca.crt -> rc=2 configuration error: invalid client TLS settings: TELEMETRY_KEY_FILE OTEL_EXPORTER_OTLP_ENDPOINT=https://172.18.0.5:4318 -> rc=2 configuration error: invalid client TLS settings: OTEL_EXPORTER_OTLP_ENDPOINT OTEL_EXPORTER_OTLP_ENDPOINT=http://otel-collector:4318 -> rc=2 configuration error: OTEL_EXPORTER_OTLP_ENDPOINT must match https://... $ docker compose run --rm --no-deps -T -e TELEMETRY_CERT_FILE= -e TELEMETRY_KEY_FILE= -e TELEMETRY_CRL_FILE= relay replay ... failed registry listed=1 apply=False (код 0: replay SDK не собирает) $ ... -e OTEL_SDK_DISABLED=true с пустыми TELEMETRY_*: client_tls_problems problems with SDK disabled: [] $ файлы /run/secrets по контейнерам api: api-client.crt api-client.key api.crt api.key ca.crt crl.pem worker: ca.crt crl.pem worker.crt worker.key relay: ca.crt crl.pem relay.crt relay.key otel-gateway: ca.crt crl.pem otel-collector.pem cleaner: ca.crt otel-collector: нет (только /etc/otelcol-contrib/collector.yaml) # Строка называет переменную, без путей; ключей PEM в окружении контейнеров — 0. # --- 9. Сетевое пространство шлюза: ловушки и восстановление --- $ docker compose up -d --force-recreate otel-gateway gateway 6caab3e1fc42 collector container:5d601af1ed1b $ make telemetry-tls-check FAIL the Collector lives in the namespace of the running gateway: container:5d601af1ed1b FAIL default: identity api (leaf api-client): empty export -> HTTP 200: HTTP 503, TLSv1.3 ... FAIL signals of messenger-api arrive (process CPU grows in Prometheus): +0.00 s telemetry-tls-check: FAIL (35/47 checks, 276 s) $ docker compose restart otel-collector Error response from daemon: Cannot restart container ...: joining network namespace of container: No such container: ... $ docker compose up -d otel-collector gateway 6caab3e1fc42 collector container:6caab3e1fc42 $ docker compose restart otel-gateway -> Collector перезапущен с ним $ docker compose exec otel-gateway bash -c 'kill -TERM 1' (рестарт политикой Docker, RestartCount 1) $ make telemetry-tls-check telemetry-tls-check: FAIL (36/47 checks, 278 s) (503: Collector без сети) $ docker compose restart otel-collector; make telemetry-tls-check telemetry-tls-check: PASS (47/47 checks, 26 s) $ docker compose stop otel-gateway; docker compose up -d --wait otel-gateway otel-collector $ make telemetry-tls-check telemetry-tls-check: FAIL (36/47 checks, 96 s) (up -d Collector не перезапускает) $ docker compose restart otel-gateway приёмник 127.0.0.1:14318 снова в пространстве шлюза $ docker compose stop otel-gateway otel-collector; docker compose up -d --wait otel-gateway otel-collector приёмник на месте (make stop + make up безопасны) # Проверка называет причину; восстановление — infra/otel/runbooks/telemetry-down.md. # 276–278 с — до правки срока ожидания сигналов (общий на три сервиса, 90 с). # --- 10. Отказ Collector и шлюза: приложение работает --- $ docker compose stop otel-collector; make test PASS: lab7 public API scenario; infrastructure and grading evidence remain separate. otel-gateway-1 | otlp <адрес> san=DNS:api tls=TLSv1.3 POST /v1/traces status=503 bytes=0 term=SC-- backend=collector/collector time=0 $ docker compose pause otel-collector; make test PASS: lab7 public API scenario; infrastructure and grading evidence remain separate. $ docker compose pause otel-gateway; make test PASS: lab7 public API scenario; infrastructure and grading evidence remain separate. $ docker compose stop relay; docker compose stop worker (шлюз заморожен) stop relay: 2 s, exit 0 stop worker: 2 s, exit 0 $ docker compose stop otel-gateway; make test PASS: lab7 public API scenario; infrastructure and grading evidence remain separate. $ cat /sys/fs/cgroup/memory.peak (шлюз, после smoke, student-test и учений) 32210944 # Пик памяти шлюза 30,7 МиБ при лимите 64 МиБ (запас больше 1,5 раза). # --- 11. Прежние проверки на новом транспорте --- $ make test; make test-security PASS: lab7 public API scenario; infrastructure and grading evidence remain separate. PASS: trusted HTTPS works; untrusted CA rejected. This does NOT verify internal mTLS, OpenBao or hardening. $ make student-test =========== 338 passed, 45 deselected, 1 warning in 89.68s (0:01:29) =========== $ make mtls-check; make storage-tls-check; make storage-roles-check; make broker-mtls-check; make s3-check mtls-check: PASS (23/23 checks, 17 s) storage-tls-check: PASS (29/29 checks, 3 s) storage-roles-check: PASS (68/68 checks, 18 s) broker-mtls-check: PASS (50/50 checks, 32 s) checks: 79, failed: 0, bootstrap exit 0 $ make telemetry-check; make trace-chain; make alerts-test; make telemetry-outage telemetry-check: PASS (22/22 checks) trace-chain: PASS (9/9 checks, 32 s) SUCCESS telemetry-outage: PASS (5/5 checks, 142 s) $ make test-failover ACTION_SCRIPT=scripts/stop-one.sh; make failover-each; make attachment-failover; make defense PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence. PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence. PASS PASS $ make test-persistence ACTION_SCRIPT=scripts/restart.sh PASS: persistence preserved confirmed data and existing session. Hook scope needs operator evidence. $ make run RUN_PORT=18181; make test BASE_URL=https://localhost:18181; make run-relay; make run-worker telemetry=off ... PASS: lab7 public API scenario; infrastructure and grading evidence remain separate. relay stopped exit_code=0 worker stopped exit_code=0 cancelled=0 returned=0 # Консоль — без телеметрии и без файлов TELEMETRY_*. На 8081 слушал чужой # контейнер (localhost → IPv6), поэтому RUN_PORT=18181. $ make test-isolated (рабочий стенд — make stop) [isolated] results: {'test': 0, 'student-test': 0, 'test-failover': 0, 'attachment-failover': 0, 'test-persistence': 0, 'postgres-permissions': 0} $ make failure-checks ========== 45 passed, 338 deselected, 1 warning in 484.06s (0:08:04) =========== [failures] postgres log: permission denied 0 [failures] results: {'fault': 0, 'postgres-permissions': 0} # Временные стенды телеметрию выключают: шлюз и Collector не запускаются, новые # secrets берутся из PKI прогона. # --- 12. bench/ (только работоспособность; машина переноса, не машина замеров; # рабочий стенд — make stop; числа — не результат замера) --- $ make bench-queue-quick (16:55:08–17:05 UTC; первые ~6 мин, до 17:00:52, рядом # работал чужой стенд mtusi-lab7 — вердикты этого прогона не учитываются) done: evidence/queue/quick-queue-20261201T165502Z (код 0, aborted нет) $ make bench-queue-quick (повтор 17:15:58–17:25:52 UTC, чужой стенд остановлен) done: evidence/queue/quick-queue-20261201T171558Z (код 0, aborted нет) Q3 подтверждена, Q4 подтверждена, Q5 подтверждена stand.rabbitmq.connections: relay true tlsv1.3 EXTERNAL; worker true tlsv1.3 EXTERNAL $ run_telemetry напрямую: варианты off и full профиля telemetry-quick (17:05 UTC; с # лабы 7 профиль не поддерживается — проба стенда vlad-bench с телеметрией) [20:05:03] run PKI: per-run CA and leaf certificates in <временный каталог> [20:05:37] run 1/2 full-r1 [20:07:04] full: ... tempo 575.442 spans/s, 500 kept 8/8, slow 33/33, bad 4/4, run 86.5 s [20:07:04] run 2/2 off-r1 [20:08:11] done in 3.1 min: evidence/telemetry-cost/quick-telemetry-20261201T170502Z stand.telemetry_tls: {'otlp': 'mtls1.3 via otel-gateway, per-run CA and CRL, Collector on loopback', 'allowlist': ['api', 'worker', 'relay']} $ make bench-uploads-quick (17:08 UTC, чужой стенд остановлен) U2, U3, U4 подтверждены; U1 опровергнута на грани (258,2 МиБ при 256 — KNOWN_ISSUES.md) $ make bench-login-quick (17:12 UTC, чужой стенд остановлен) L1, L2, L3, L4 подтверждены (OOM варианта before — ожидаемый) $ grep -rl 'PRIVATE KEY' <метки этих прогонов> | wc -l 0 # src_sha256 образов — 5d6d03d7… Рабочие профили идут с выключенным SDK; стенд с # телеметрией принимает сигналы через шлюз с PKI прогона (575 spans/с в Tempo).