diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index bd9a392f..478949a2 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -10,9 +10,9 @@ Ограничения / известные ошибки: один Docker-host и singleton stores/LB; ручной unseal/leaf lifecycle, static KV credentials; loopback hop TLS proxies внутри namespace; production HA/ротация не заявлены. Источники и использование ИИ: собственный №6 commit1a14da9, нормативные материалы №7, официальная документация OpenBao/RabbitMQ/OTel/OWASP; Codex помог с кодом, конфигурацией, проверками и отчётом. -- [ ] Весь обязательный минимум текущей и предыдущих работ сохранён с объявленными переходами. -- [ ] Контракт и публичные тесты не ослаблены. -- [ ] make check и make test выполнены; приложен реальный вывод. -- [ ] Сценарии отказов/безопасности своего уровня воспроизведены. -- [ ] Все секреты и приватные ключи находятся вне Git; отчёт не содержит tokens. -- [ ] README задания сохранён, REPORT.md содержит инструкцию именно моего решения. +- [x] Весь обязательный минимум текущей и предыдущих работ сохранён с объявленными переходами. +- [x] Контракт и публичные тесты не ослаблены. +- [x] make check и make test выполнены эквивалентными Python-командами; приложен реальный вывод. +- [x] Сценарии отказов/безопасности своего уровня воспроизведены. +- [x] Все секреты и приватные ключи находятся вне Git; отчёт не содержит tokens. +- [x] README задания сохранён, REPORT.md содержит инструкцию именно моего решения. diff --git a/REPORT.md b/REPORT.md index 8fd20511..03537bfc 100644 --- a/REPORT.md +++ b/REPORT.md @@ -25,6 +25,8 @@ Linux: `.venv/bin/python`, разделители `/`; активируйте ve Bootstrap сохраняет существующие CA, ключи, passwords, `.env`, KV. Миграции защищены advisory lock и таблицей версий, bucket/policies повторяются безопасно. `manage.py start` строит свои образы, поднимает stores, выполняет операторские действия с явными флагами, миграции, GRANT, приватный bucket, запускает приложение и ждёт HTTPS readiness. API: `https://localhost:8443`, CA — `secrets/ca.crt`. Grafana: `https://localhost:3007`, пользователь `admin`, пароль читает оператор из `secrets/grafana_password`. OpenBao: `https://localhost:8207`, UI выключен. Для браузера импортируется публичный CA; проверки всегда используют CA file. +Повторный bootstrap проверен сравнением всех 102 локальных файлов secrets/PKI/operator material и `.env`: изменённых файлов 0 (`evidence/bootstrap-repeat.json`). Чистое воспроизведение экспортировало commit `06459d3`; новая PKI, init/unseal, build/readiness, публичный smoke/TLS и внутренняя матрица завершились PASS. Временные project/volumes/network/images удалены (`evidence/reproduction.json`). Последующие изменения касаются аудита и отчётности; runtime source/config относительно экспортированной ревизии не менялся. + Эквиваленты make без установки make: ```powershell @@ -116,10 +118,12 @@ Argon2id оставлен на минимуме19MiB/t2/p1: измерение ## Эксперименты и отказы -Обязательная гипотеза: подтверждённые session/message/ready attachment сохраняются после restart stores и потери одной API. Публичные сценарии создают синтетические данные; volumes не удаляются. Failover15s, POST с интервалом0.1s, повтор неопределённой записи с тем же ключом. Первый завершённый прогон:64/55 успешных записей,1/2 переходных неудачных попытки, first recovery5.634/5.605s. Более поздние evidence имеют приоритет. Hook сохраняет реальные IDs/StartedAt до/после; в persistence рестартует все stores, Bao и telemetry, затем proxy namespace. Unseal делает host-оператор. +Обязательная гипотеза: подтверждённые session/message/ready attachment сохраняются после restart stores и потери одной API. Публичные сценарии создают синтетические данные; volumes не удаляются. Failover15s, POST с интервалом0.1s, повтор неопределённой записи с тем же ключом. Итоговый прогон:55/51 успешных записей,2/3 переходных неудачных попытки, first recovery5.660/5.899s. Hook сохраняет реальные IDs/StartedAt до/после; в persistence рестартует все stores, Bao и telemetry, затем proxy namespace. Unseal делает host-оператор. Короткая closed-loop нагрузка:15s/concurrency2, evidence/load.json; p50/p95/p99 только успешных HTTP-запросов, без прозрачных retry. Прогрев — предшествующие smoke/security; набор накоплен синтетическими проверками. CPU/RAM — evidence/resources.txt. Это наблюдаемый профиль, не поиск максимального RPS/исследовательский трек. Есть coordinated omission клиента. +Результат:419 успешных запросов,0 ошибок,27.814 RPS; p50=70.416ms, p95=101.467ms, p99=209.268ms. Снимок во время нагрузки: API1/2 около133/131MiB из512MiB, CPU25.92/16.54%; Docker CPU% относится к одному ядру. Набор перед нагрузкой уже содержал данные предыдущих синтетических сценариев, поэтому это профиль растущей истории, а не benchmark пустой БД. + | Воздействие | Ожидание / факт | Граница | | --- | --- | --- | | Restart API+stores | Прежний токен/сообщения/S3 bytes сохранились | Volumes и host сохранены | diff --git a/evidence/audit.json b/evidence/audit.json new file mode 100644 index 00000000..3125fbde --- /dev/null +++ b/evidence/audit.json @@ -0,0 +1,304 @@ +{ + "commit": "06459d3eed01a0794d6c9919f53c21bc5913c3ef", + "branch": "solution/BVT2301-lyakhonov", + "origin": "https://gitea.privcloud.tech/lyakhonov/mtusi2026lab7.git", + "normative_files_unchanged": 38, + "files_scanned": 141, + "secrets_scan": "PASS; actual credentials, private keys, tracked/evidence and exported layers", + "previous_projects": [ + { + "folder": "vysoko-nagr 6_2", + "head": "1a14da96aabd0106caf0b55c62096ba884a29dcd", + "status": "## solution/BVT2301-lyakhonov...origin/solution/BVT2301-lyakhonov\n?? vysoko-nagr_gitea/", + "origin": "https://gitea.privcloud.tech/lyakhonov/mtusi2026lab6.git" + }, + { + "folder": "vysoko-nagr 6", + "head": "1a14da96aabd0106caf0b55c62096ba884a29dcd", + "status": "## solution/BVT2301-lyakhonov", + "origin": "https://gitea.privcloud.tech/mtusi2026/mtusi2026lab6.git" + }, + { + "folder": "vysoko-nagr 5", + "head": "9dd2a03aa72150d2b786fa8271792e242eaea816", + "status": "## solution/BVT2301-lyakhonov...origin/solution/BVT2301-lyakhonov", + "origin": "https://gitea.privcloud.tech/lyakhonov/mtusi2026lab5.git" + }, + { + "folder": "vysoko-nagr 4", + "head": "8f112e092a10d72a98c3d9d4554c52b81ebff2b3", + "status": "## solution/BVT2301-lyakhonov...origin/solution/BVT2301-lyakhonov", + "origin": "https://gitea.privcloud.tech/lyakhonov/mtusi2026lab4-fork.git" + } + ], + "commits": [ + "06459d3 Sergey Lyakhonov | Sergey Lyakhonov ", + "d4f64be Sergey Lyakhonov | Sergey Lyakhonov ", + "cb7824c Sergey Lyakhonov | Sergey Lyakhonov " + ], + "containers": [ + { + "service": "api1", + "id": "3f8011e29aac", + "image": "lyakhonov-lab7-app:1.0", + "image_id": "sha256:7e650f1e11a46bf52860a3245d175ce2a77c8b8c5a42df9921f1ce66d5e4461e", + "state": "running", + "started_at": "2026-12-04T04:06:46.648239914Z", + "cpu_limit": 0.5, + "memory_bytes": 536870912, + "published": {}, + "user": "appuser" + }, + { + "service": "api2", + "id": "0ad5d03d1795", + "image": "lyakhonov-lab7-app:1.0", + "image_id": "sha256:7e650f1e11a46bf52860a3245d175ce2a77c8b8c5a42df9921f1ce66d5e4461e", + "state": "running", + "started_at": "2026-12-04T04:06:24.95818671Z", + "cpu_limit": 0.5, + "memory_bytes": 536870912, + "published": {}, + "user": "appuser" + }, + { + "service": "broker", + "id": "ad179479d203", + "image": "rabbitmq:4.1.0-alpine", + "image_id": "sha256:8a73e9185f8420247c5b3c19231df18dfac28a8d5706203e13b291934044966d", + "state": "running", + "started_at": "2026-12-04T04:05:42.735730626Z", + "cpu_limit": 0.75, + "memory_bytes": 536870912, + "published": {}, + "user": "" + }, + { + "service": "cleaner", + "id": "4ccfd6831a32", + "image": "lyakhonov-lab7-app:1.0", + "image_id": "sha256:7e650f1e11a46bf52860a3245d175ce2a77c8b8c5a42df9921f1ce66d5e4461e", + "state": "running", + "started_at": "2026-12-04T04:05:57.144558117Z", + "cpu_limit": 0.5, + "memory_bytes": 536870912, + "published": {}, + "user": "appuser" + }, + { + "service": "db", + "id": "066deb34f44b", + "image": "postgres:16.6-alpine", + "image_id": "sha256:1d04b9ba1d4996401f2552b51beda8187f175c0645c091e4781134fc9c9a3eef", + "state": "running", + "started_at": "2026-12-04T04:05:39.712347588Z", + "cpu_limit": 1.0, + "memory_bytes": 536870912, + "published": {}, + "user": "" + }, + { + "service": "dispatcher", + "id": "b6e967fec6da", + "image": "lyakhonov-lab7-app:1.0", + "image_id": "sha256:7e650f1e11a46bf52860a3245d175ce2a77c8b8c5a42df9921f1ce66d5e4461e", + "state": "running", + "started_at": "2026-12-04T04:06:00.987337652Z", + "cpu_limit": 0.5, + "memory_bytes": 536870912, + "published": {}, + "user": "appuser" + }, + { + "service": "grafana", + "id": "96a5e64b1f07", + "image": "grafana/grafana:12.2.1", + "image_id": "sha256:35c41e0fd0295f5d0ee5db7e780cf33506abfaf47686196f825364889dee878b", + "state": "running", + "started_at": "2026-12-04T04:05:39.11568327Z", + "cpu_limit": 0.5, + "memory_bytes": 402653184, + "published": { + "3000/tcp": [ + { + "HostIp": "127.0.0.1", + "HostPort": "3007" + } + ] + }, + "user": "472" + }, + { + "service": "lb", + "id": "6987f231f4ee", + "image": "haproxy:3.0.6-alpine", + "image_id": "sha256:c22c8710886104a48b920306f063401f0d11811858e3c6b9d87d88a7556b2e61", + "state": "running", + "started_at": "2026-12-04T03:45:12.584051263Z", + "cpu_limit": 0.5, + "memory_bytes": 134217728, + "published": { + "8443/tcp": [ + { + "HostIp": "127.0.0.1", + "HostPort": "8443" + } + ] + }, + "user": "haproxy" + }, + { + "service": "loki", + "id": "f6e1437e4f14", + "image": "grafana/loki:3.5.7", + "image_id": "sha256:0eaee7bf39cc83aaef46914fb58f287d4f4c4be6ec96b86c2ed55719a75e49c8", + "state": "running", + "started_at": "2026-12-04T04:05:40.110312226Z", + "cpu_limit": 0.5, + "memory_bytes": 402653184, + "published": {}, + "user": "10001" + }, + { + "service": "loki-tls", + "id": "d063732cd20f", + "image": "lyakhonov-lab7-app:1.0", + "image_id": "sha256:7e650f1e11a46bf52860a3245d175ce2a77c8b8c5a42df9921f1ce66d5e4461e", + "state": "running", + "started_at": "2026-12-04T04:05:57.069088892Z", + "cpu_limit": 0.25, + "memory_bytes": 100663296, + "published": {}, + "user": "appuser" + }, + { + "service": "openbao", + "id": "b13db1a9bb50", + "image": "quay.io/openbao/openbao:2.4.0", + "image_id": "sha256:e32efa32d85567a7ff02ff91cd6e10da1bff809287db5cedfd9373c83437a80c", + "state": "running", + "started_at": "2026-12-04T04:05:39.986508578Z", + "cpu_limit": 0.5, + "memory_bytes": 268435456, + "published": { + "8200/tcp": [ + { + "HostIp": "127.0.0.1", + "HostPort": "8207" + } + ] + }, + "user": "" + }, + { + "service": "otel-collector", + "id": "65a9667c97a6", + "image": "otel/opentelemetry-collector-contrib:0.137.0", + "image_id": "sha256:886722fe0f37af9d1fe24d29529253ec59fbf263b3b1df4facaf221373e19d23", + "state": "running", + "started_at": "2026-12-04T04:05:38.589790006Z", + "cpu_limit": 0.5, + "memory_bytes": 268435456, + "published": {}, + "user": "10001:10001" + }, + { + "service": "prometheus", + "id": "c6f6d2c39cb7", + "image": "prom/prometheus:v3.7.3", + "image_id": "sha256:49214755b6153f90a597adcbff0252cc61069f8ab69ce8411285cd4a560e8038", + "state": "running", + "started_at": "2026-12-04T04:05:39.497453883Z", + "cpu_limit": 0.5, + "memory_bytes": 402653184, + "published": {}, + "user": "nobody" + }, + { + "service": "prometheus-tls", + "id": "75ccd885c898", + "image": "lyakhonov-lab7-app:1.0", + "image_id": "sha256:7e650f1e11a46bf52860a3245d175ce2a77c8b8c5a42df9921f1ce66d5e4461e", + "state": "running", + "started_at": "2026-12-04T04:05:57.064732936Z", + "cpu_limit": 0.25, + "memory_bytes": 100663296, + "published": {}, + "user": "appuser" + }, + { + "service": "s3", + "id": "965e69714ae8", + "image": "lyakhonov-lab7-s3:1.0", + "image_id": "sha256:e4ac6faf3a1f70da22badd8a97c4409905990d4c960f9eb3aa5e77285c2f4b68", + "state": "running", + "started_at": "2026-12-04T04:05:39.646780612Z", + "cpu_limit": 1.0, + "memory_bytes": 671088640, + "published": {}, + "user": "" + }, + { + "service": "tempo", + "id": "86b293fe1216", + "image": "grafana/tempo:2.9.0", + "image_id": "sha256:65a5789759435f1ef696f1953258b9bbdb18eb571d5ce711ff812d2e128288a4", + "state": "running", + "started_at": "2026-12-04T04:05:39.819740464Z", + "cpu_limit": 0.5, + "memory_bytes": 402653184, + "published": {}, + "user": "10001:10001" + }, + { + "service": "tempo-tls", + "id": "2bff90ca023b", + "image": "lyakhonov-lab7-app:1.0", + "image_id": "sha256:7e650f1e11a46bf52860a3245d175ce2a77c8b8c5a42df9921f1ce66d5e4461e", + "state": "running", + "started_at": "2026-12-04T04:05:57.060650395Z", + "cpu_limit": 0.25, + "memory_bytes": 100663296, + "published": {}, + "user": "appuser" + }, + { + "service": "tempo-tls-ingest", + "id": "ae500cc323a9", + "image": "lyakhonov-lab7-app:1.0", + "image_id": "sha256:7e650f1e11a46bf52860a3245d175ce2a77c8b8c5a42df9921f1ce66d5e4461e", + "state": "running", + "started_at": "2026-12-04T04:05:57.063230533Z", + "cpu_limit": 0.25, + "memory_bytes": 100663296, + "published": {}, + "user": "appuser" + }, + { + "service": "worker", + "id": "bc02bc027b94", + "image": "lyakhonov-lab7-app:1.0", + "image_id": "sha256:7e650f1e11a46bf52860a3245d175ce2a77c8b8c5a42df9921f1ce66d5e4461e", + "state": "running", + "started_at": "2026-12-04T04:13:27.079081567Z", + "cpu_limit": 0.5, + "memory_bytes": 536870912, + "published": {}, + "user": "appuser" + } + ], + "images": [ + { + "image": "lyakhonov-lab7-app:1.0", + "archive_members_scanned": 19, + "gzip_members_expanded": 10, + "actual_credentials": "absent" + }, + { + "image": "lyakhonov-lab7-s3:1.0", + "archive_members_scanned": 15, + "gzip_members_expanded": 6, + "actual_credentials": "absent" + } + ] +} \ No newline at end of file diff --git a/evidence/bootstrap-repeat.json b/evidence/bootstrap-repeat.json new file mode 100644 index 00000000..342684ca --- /dev/null +++ b/evidence/bootstrap-repeat.json @@ -0,0 +1,5 @@ +{ + "files_checked": 102, + "changed_files": 0, + "result": "PASS existing PKI, operator material, credentials and .env preserved" +} \ No newline at end of file diff --git a/evidence/reproduction.json b/evidence/reproduction.json new file mode 100644 index 00000000..6637448f --- /dev/null +++ b/evidence/reproduction.json @@ -0,0 +1,33 @@ +{ + "project": "lyakhonov-lab7-repro-29cf5551", + "exported_commit": "06459d3eed01a0794d6c9919f53c21bc5913c3ef", + "ports": [ + 57463, + 57464, + 57465 + ], + "steps": [ + { + "step": "new PKI and secrets", + "exit": 0, + "output": "Local PKI and credentials ready; existing files preserved. No secret values printed." + }, + { + "step": "build, bootstrap OpenBao, migrate, readiness", + "exit": 0, + "output": "Initialized persistent OpenBao; operator material saved privately on host.\nOpenBao unsealed by host operator.\nCertificate auth, 300s tokens, scoped policies and KV paths configured.\nPrivate bucket and separate scoped identities ready" + }, + { + "step": "public HTTPS smoke and external TLS trust", + "exit": 0, + "output": "PASS: lab7 public API scenario; infrastructure and grading evidence remain separate.\nPASS: trusted HTTPS works; untrusted CA rejected. This does NOT verify internal mTLS, OpenBao or hardening." + }, + { + "step": "internal mTLS, TLS links and policy deny", + "exit": 0, + "output": "PASS api1 no cert / foreign CA / trusted wrong identity rejected; lb=200; port8080 closed\nPASS api2 no cert / foreign CA / trusted wrong identity rejected; lb=200; port8080 closed\nPASS OpenBao api cert auth; TTL<=300; own read=200; foreign read/policy write/KV write=403\nPASS OpenBao api2 cert auth; TTL<=300; own read=200; foreign read/policy write/KV write=403\nPASS OpenBao worker cert auth; TTL<=300; own read=200; foreign read/policy write/KV write=403\nPASS OpenBao dispatcher cert auth; TTL<=300; own read=200; foreign read/policy write/KV write=403\nPASS OpenBao cleaner cert auth; TTL<=300; own read=200; foreign read/policy write/KV write=403\nPASS PostgreSQL api verify-full, server TLS observed; plaintext rejected\nPASS PostgreSQL worker verify-full, server TLS observed; plaintext rejected\nPASS PostgreSQL dispatcher verify-full, server TLS observed; plaintext rejected\nPASS PostgreSQL cleaner verify-full, server TLS observed; plaintext rejected\nPASS S3 api TLS; administrative bucket listing denied; scoped permissions\nPASS S3 worker TLS; administrative bucket listing denied; scoped permissions\nPASS S3 cleaner TLS; administrative bucket listing denied; scoped permissions\nPASS RabbitMQ worker TLS; wrong producer/consumer operation=403\nPASS RabbitMQ dispatcher TLS; wrong producer/consumer operation=403\nPASS Collector TLS authenticated ingest; no-certificate rejected\nPASS backend prometheus Grafana mTLS; wrong identity rejected; plaintext closed\nPASS backend loki Grafana mTLS; wrong identity rejected; plaintext closed\nPASS backend tempo Grafana mTLS; wrong identity rejected; plaintext closed\nPASS Collector -> all backends mTLS\nPASS internal wrong hostname rejected by certificate verifier" + } + ], + "result": "PASS", + "temporary_resources_removed": true +} \ No newline at end of file diff --git a/scripts/audit.py b/scripts/audit.py index b90b0c3b..94a8802f 100644 --- a/scripts/audit.py +++ b/scripts/audit.py @@ -6,6 +6,7 @@ import re import subprocess import sys import tarfile +import zlib ROOT=Path(__file__).resolve().parents[1] sys.path.insert(0,str(ROOT/'student-tests')) @@ -64,20 +65,28 @@ def main(): for image in (env['APP_IMAGE'],env['S3_IMAGE']): print('Scanning exported image layers:',image,flush=True) proc=subprocess.Popen(['docker','image','save',image],stdout=subprocess.PIPE) - count=0 + count=0;compressed=0 with tarfile.open(fileobj=proc.stdout,mode='r|*') as bundle: for entry in bundle: if not entry.isfile():continue count+=1 source=bundle.extractfile(entry);tail=b'' + prefix=source.read(2) + decoder=zlib.decompressobj(31) if prefix==b'\x1f\x8b' else None + if decoder:compressed+=1 while True: - block=source.read(1024*1024) + block=prefix+source.read(1024*1024) + prefix=b'' if not block:break - data=tail+block - assert not any(value in data for value in values),'Credential in exported image' - tail=data[-16384:] + while block: + expanded=decoder.decompress(block,4*1024*1024) if decoder else block + data=tail+expanded + assert not any(value in data for value in values),'Credential in exported image' + tail=data[-16384:] + block=decoder.unconsumed_tail if decoder else b'' + if decoder:assert decoder.eof,'Truncated compressed image layer' assert proc.wait()==0 - image_results.append({'image':image,'archive_members_scanned':count,'actual_credentials':'absent'}) + image_results.append({'image':image,'archive_members_scanned':count,'gzip_members_expanded':compressed,'actual_credentials':'absent'}) commits=command('git','log',baseline+'..HEAD','--format=%h %an <%ae> | %cn <%ce>').splitlines() assert all('Sergey Lyakhonov | Sergey Lyakhonov ' in line for line in commits) summary={'commit':command('git','rev-parse','HEAD'),'branch':command('git','branch','--show-current'),