diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..46526f6 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,3 @@ +* text=auto eol=lf +*.png binary +*.jpg binary diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..7cb4e5f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,18 @@ +# Official Docker Python image; immutable digest. +FROM python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b +ENV PYTHONDONTWRITEBYTECODE=1 PYTHONUNBUFFERED=1 PYTHONUTF8=1 \ + APP_HOST=0.0.0.0 APP_PORT=8080 +WORKDIR /app +RUN apt-get update && apt-get install -y --no-install-recommends \ + zlib1g=1:1.3.dfsg+really1.3.1-1+deb13u1 && rm -rf /var/lib/apt/lists/* +COPY requirements.txt . +RUN pip install --no-cache-dir pip==26.3 && pip install --no-cache-dir -r requirements.txt && pip uninstall -y setuptools && \ + groupadd --gid 10001 messenger && useradd --uid 10001 --gid 10001 --no-create-home messenger +COPY src ./src +COPY migrations ./migrations +USER 10001:10001 +EXPOSE 8080 +STOPSIGNAL SIGTERM +HEALTHCHECK --interval=5s --timeout=6s --start-period=60s --retries=3 \ + CMD python -c "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8080/health/ready',timeout=5)" +CMD ["python", "-m", "src"] diff --git a/REPORT.md b/REPORT.md index 9801db4..987c273 100644 --- a/REPORT.md +++ b/REPORT.md @@ -1,37 +1,233 @@ -# Отчёт — лабораторная 7 +# ЛР7 — Парамонов Глеб, БВТ2301 -- Автор, группа: TODO -- Целевая оценка; выбранный трек 5, если нужен: TODO -- Commit/PR: TODO после публикации -- Использованные источники, библиотеки и помощь ИИ: TODO +Целевая оценка **5**, трек 1: **компрометация worker**. Ветка +`solution/bvt2301-paramonov`. Перенесена собственная реализация ЛР6: две API, +PostgreSQL, profile cache, приватный S3, transactional outbox, Valkey Streams, +worker с versioned image pipeline, reconciler, OTel/Grafana. Новый внешний API — +HTTPS. README задания, business contract и public tests не ослаблены; заполнен +предусмотренный заданием `contracts/trust-matrix.md`. + +Код, исследование и оформление подготовлены с помощью OpenAI Codex. Результаты +в `evidence/` получены на реальном локальном стенде, а не сгенерированы как +пример. Это учебная реализация в заявленной модели угроз, не production seal. ## Запуск из чистого clone -TODO: версии runtime/образов, prerequisites, команды создания локальных secrets/.env, build, миграций, запуска, ожидания готовности, тестов и остановки. Указать необходимые действия оператора. Не вставлять секреты. Отдельно указать безопасную остановку и команду намеренного удаления учебных данных. +Нужны Git, Docker Engine/Compose v2, Python 3.12+ и сеть для официальных images/ +PyPI. Проверено на Windows10, Docker Desktop4.39 / Engine28 / Compose2.33, WSL2 +4CPU/3GiB RAM/4GiB swap, i5-11400H/8GiB host RAM. Версии образов закреплены digest +в `compose.yaml`/`Dockerfile`; зависимости — точными версиями в requirements. +Предыдущие стенды остановить: административный Grafana port3000 общий. -## Архитектура и решения +```sh +python -m venv .venv +# Windows: вместо .venv/bin/python используйте .venv/Scripts/python.exe +.venv/bin/python -m pip install -r requirements-dev.txt -r requirements-test.txt +.venv/bin/python -X utf8 scripts/up.py +.venv/bin/python -X utf8 scripts/verify_public.py +``` -TODO: схема процессов/хранилищ, источник истины, транзакционные границы, ограничения. Что перенесено из lab6, что изменено в этой работе. Соответствие переменных из .env.example реальной конфигурации. +`up.py` — явная операторская команда. Она создаёт локальные секреты, строит image, +согласованно останавливает старые процессы без удаления volumes, запускает Bao +и хранилища, выполняет init/unseal, migrations/GRANT, policy/KV provisioning, +создаёт private bucket, запускает остальное и ждёт verified HTTPS readiness. +Повтор сохраняет пароли/CA/data и проверяет hashes применённых migrations. +Leaf certificates с остатком <2h обновляются оператором. Это cold-start +workflow, бесшовный rollout не заявляется. На этой машине dependencies для +работы выполнялись также из соседнего существующего venv; для проверяющего +полностью достаточно собственного venv этого репозитория. -## Доказательства критериев +После запуска: API https://localhost:8443, Grafana https://localhost:3000 +(login admin, пароль только в локальном `secrets/grafana-password`), Bao API +https://localhost:8200 (обязательный operator client cert). Не отключайте +проверку CA: для Python/public tests `--ca-file secrets/trust/ca.crt`. Для +браузера сначала установите публичный учебный CA вручную, если нужен UI. +HTTP на этих портах не является fallback. -| Критерий README | Команда/сценарий | Наблюдаемый результат | Файл доказательства | -| --- | --- | --- | --- | -| Публичный smoke | make test | TODO | TODO | -| Остальные пункты уровня 3 | TODO | TODO | TODO | -| Все пункты уровня 4, если заявлен | TODO | TODO | TODO | -| Выбранный трек 5, если заявлен | TODO | TODO | TODO | +Эквивалентные операции по шагам приведены в `scripts/up.py`. Обычный restart +API не требует unseal. После перезапуска Bao: -TODO: добавить отдельную строку для каждого заявленного критерия. PASS без команды и наблюдения не является доказательством. Проверка инфраструктурного hook требует подтверждения, какие реальные процессы/хранилища перезапущены. +```sh +.venv/bin/python scripts/bao_operator.py unseal +``` -## Эксперименты и отказы +Root token и 3 unseal shares (threshold2) находятся только в +`secrets/operator/bao-init.json`; CA key — рядом в `ca.key`. Их не передают в +PR/чат, не монтируют в runtime и не печатают. Windows bootstrap убирает inherited +ACL и оставляет owner/SYSTEM/Administrators; POSIX secrets0700/files0600. +Все доли на одном защищённом компьютере — ограничение учебного bootstrap, +не production secret custody. Резервные копии этих файлов должен хранить +оператор отдельно от data volume; потеря shares делает sealed data недоступными. -TODO: гипотеза, hardware/лимиты, версии, объём данных, профиль нагрузки, concurrency/arrival rate, длительность/прогрев, повторы, успешные RPS, ошибки, p50/p95/p99, CPU/RAM. Сохранить raw summary без tokens и объяснить ограничения измерения. +Остановка с сохранением данных: `docker compose down`. Осознанное удаление +**всех учебных данных только этого проекта**: `docker compose down --volumes`. +После такого сброса следует создать новый clone/workdir и новые secrets; +старый bao-init не соответствует новому пустому raft volume. Команда удаления +не используется тестами. Restart hook делает stop/start в dependency order, +потому что приложение и его TLS sidecar разделяют network namespace. -| Воздействие | Что ожидаем | Что наблюдали | Время восстановления / потеря данных | -| --- | --- | --- | --- | -| TODO | TODO | TODO | TODO | +## Архитектура и эксплуатация -## Ограничения и следующие шаги +Клиент → TLS LB → mTLS API1/API2 → mTLS DB/S3/cache/Collector. Worker и dispatcher +используют отдельные broker identities. Collector экспортирует через mTLS в +Loki/Tempo; Prometheus читает защищённые scrape endpoints; Grafana читает data +sources через собственные mTLS tunnels. [Полная матрица](contracts/trust-matrix.md). -TODO: какие отказы выдерживаются и какие нет; что не реализовано; где учебное упрощение; какое улучшение подтверждено, а какое пока гипотеза. +В backend namespace native listener только loopback. Прокси использует Python +stdlib/OpenSSL, проверяет CA, hostname и SAN allowlist; TLS>=1.2, CRL, максимум +64 активные/96 ожидающие задачи, 16KiB buffers, 60s connection lifetime. TLS +context cache <=1s, поэтому срок прекращения существующей связи <=61s. TLS +session tickets на server proxy выключены. Прокси не логирует payload. Native +TLS применяется у LB, Bao и Grafana. CA private key в services отсутствует. + +Secret supervisor использует native mTLS cert auth OpenBao, а не постоянный +секрет «для получения секретов». Политика разрешает read только собственного +KV path. Token TTL/maxTTL120s, re-auth20s; после чтения token revoke-self. +Пароли БД/S3/Valkey — **static KV**, их реальная валидность заканчивается +ротацией backend. Локальный budget120s ограничивает продолжение работы child +при sealed/unavailable Bao, но не обезвреживает скопированный злоумышленником +пароль. Смена KV перезапускает child и закрывает старые pooled connections. +Crash child также обрабатывается supervisor без смены network namespace. + +PostgreSQL — источник истины для пользователей, sessions, идемпотентности, +attachments/jobs/outbox. Native host authentication на loopback — SCRAM, +не trust. Только операторский Unix socket использует доверенный local role; +этот socket другим контейнерам не расшарен. Worker не читает users/sessions/ +messages и не может DDL/role administration. API имеет business-table grants; +worker/dispatcher — jobs/attachments/outbox/audit, reconciler — attachments. +Dispatcher не получает S3 credentials. Valkey ACL ограничивает команды и key; +S3 policy — bucket prefixes. Отдельные credentials каждой роли лежат в Bao. + +Argon2id: 32MiB, t2, p1, случайный salt. При успешном входе старые параметры +rehash с compare-and-swap. Session token — 256 случайных бит, в PostgreSQL +только SHA-256; expiry1h/logout проверяются по БД. KDF concurrency2/API, общий +limiter12 login attempts/10s и8 registration/10s. 429 содержит Retry-After10. +Это глобальный учебный бюджет, не распределённая антибот-система по пользователям. + +Runtime non-privileged, capabilities dropped, no-new-privileges, read_only root +filesystem, RAM/CPU/pids limits, writable named volumes/tmpfs только где нужны. +Worker1CPU/768MiB, render subprocess имеет отдельный timeout/лимиты. Init jobs +кратковременно root с CHOWN/FOWNER/DAC_OVERRIDE для отдельных secret volumes; +в runtime этих capabilities нет. Stateful write paths: PG/Seaweed/Valkey data, +Bao raft+audit, Grafana/Prometheus/Loki/Tempo data. Наружу только loopback +8443/8200/3000. `.env.example` — исходный перечень ролей, фактические параметры +создаются `bootstrap.py`: `.env` только DB bootstrap, service env приходит из Bao, +S3 admin имеет отдельный `.env.storage-admin` лишь в operator profile. + +## Проверки и доказательства + +Финальная проверка выполнена из отдельного clone `clean-lab7-final` с собственным +venv, новой PKI/секретами и новыми volumes. Код соответствует commit `0bf1ff9`; +финальные evidence/документация зафиксированы отдельным последующим коммитом. Проверка публичного +набора 13.11.2026 прошла целиком: contract, OpenAPI, HTTPS smoke/security, +persistence, три failover-запуска с двумя различными container IDs. После fault +первые успешные записи восстановились за 3.390/2.953/2.610s. Первые два запуска +выбрали одну реплику, третий — другую; все реальные процессы остановлены SIGKILL, +без замены target теста. Перед следующим сценарием обе API и TLS sidecars +восстанавливаются согласованно. Публичные tests не изменены. + +Полный security suite завершился PASS 13.11.2026 в 10:00:37 UTC: все 11 этапов, +включая TLS allow/deny matrix, Bao policies, worker permissions, API security, +компрометацию worker, sealed Bao, telemetry, hardening и 4 renderer unit tests. +При компрометации восстановлены 3/3 задания без изменения содержимого и образа; +старые certificate/Bao auth/DB password отклонены; полный эксперимент 35.61s. +При sealed Bao обе API child остановились через 123.86s (120s budget + grace), +восстановление после unseal 20.44s. Argon2 hash+verify median 0.207s, +maxRSS 53184KiB; 20 login за 4.578s дали 12×401 и 8×429 на двух API. +Это результаты одного запуска на указанном стенде, а не гарантированные SLO. +Сводка: [clean-clone.json](evidence/clean-clone.json), +[public suite](evidence/public-suite.txt), [security suite](evidence/security-suite.txt). +Image scan от 12.11 предшествует исправлению планирования TLS handshake; +зависимости не изменились, но scan не заявляется для точного app image ID +финального запуска (он отдельно записан в clean-clone.json). + +```sh +.venv/bin/python scripts/verify_public.py +.venv/bin/python scripts/verify_security.py +# Ниже отдельные сценарии для воспроизведения/диагностики, уже включённые в suite: +.venv/bin/python scripts/test_identities.py +.venv/bin/python scripts/bao_operator.py publish-crl +docker compose run --rm security-check +# В Windows вывод перенаправлять в UTF-8, пример: > evidence/tls-matrix.json +docker compose run --rm security-check python /checks/bao_policy.py +.venv/bin/python checks/security_api.py +.venv/bin/python checks/compromised_worker.py +.venv/bin/python checks/sealed_bao.py +.venv/bin/python checks/telemetry_security.py +.venv/bin/python checks/hardening.py +docker compose exec -T worker python - < checks/worker_rights.py +docker compose run --rm --no-deps -v "$PWD/checks:/checks:ro" api1 python -m unittest discover -s /checks -p test_render.py +.venv/bin/python scripts/scan_images.py +``` + +Последний `run api1` использует только unittest renderer, service secret supervisor +не запускается (command переопределён). PowerShell stdin: `Get-Content +checks/worker_rights.py -Raw | docker compose exec -T worker python -`. +Перед повтором быстрых suites дайте limiter10s; не отключайте его ради PASS. + +| Критерий | Сценарий / evidence | +| --- | --- | +| Неизменённый business contract/OpenAPI, HTTPS smoke | verify_public → check_contract.txt, validate_openapi.txt, smoke.txt, security.txt | +| Сохранность всех данных/сессии/файла после restart | persistence.txt + restart-processes.json, реальные StartedAt всех сервисов | +| Отказ обеих настоящих API-реплик | failover-*.txt и *-process.json, target из X-Instance-Id, distinct container IDs | +| Вся внутренняя TLS матрица и отрицательные identities | tls-matrix.json: все allow edges и no-cert/foreign CA/wrong SAN/expired/revoked/plaintext | +| Scoped cert auth/TTL/policy allow-deny | bao-policy.json | +| Пароли/session hashes/rehash/shared DoS budget/ACL | security-api.json | +| Реальный доступ с credentials worker | worker-rights.json | +| Отзыв identity, ротация cert+DB password, сохранность задач | compromised-worker.json | +| Sealed Bao и bounded expiry/recovery | sealed-bao.json | +| Метрики, сквозной upload trace, correlated logs без canaries | telemetry-security.json | +| Runtime isolation/permissions/mounts/ports | hardening.json | +| Dependencies и образы | dependency-audit.json, image-audit.json, security/SCAN_TRIAGE.md | + +Модель угроз связывает 11 конкретных сценариев с этими проверками: +[security/THREAT_MODEL.md](security/THREAT_MODEL.md). Публичный smoke не используется +как доказательство всех security claims. + +## Исследование: компрометация worker + +Гипотеза: раздельная identity + least privilege ограничивают последствия захвата +worker обработкой вложений, а отзыв cert и связанного пароля останавливает новый +доступ; transactional outbox сохраняет принятые задания до восстановления. + +Методика `checks/compromised_worker.py`: синтетические пользователи/чат; сравнение +operator session-read с denied worker session-read; revoke serial в proxy CRL и +Bao cert-auth CRL; завершение старых worker DB sessions; 3 загрузки при отозванном +worker; проверка queued; ALTER ROLE PASSWORD; новый24h leaf; secret-init; проверка +старого пароля на новом TLS соединении; обновление KV; ожидание ready всех3, +проверка distinct jobs и SHA-256. Образ worker до/после должен совпадать. + +Первый завершённый запуск 04.11.2026: 3/3 задачи восстановлены без дублей, SHA-256 +сохранены, образ не менялся, полный эксперимент39.16s. Это время включает fault +injection/provision и ожидание20s re-auth, не pure service recovery latency. +В ходе разработки тест нашёл loopback trust в PostgreSQL; после исправления на +SCRAM старый пароль действительно отклонён. Финальные повторные результаты +смотрите в JSON evidence (они заменяют предыдущий запуск). + +Отдельный sealed-Bao эксперимент04.11: обе API child прекратили слушать через +106.58s от seal (остаток последнего120s budget), recovery23.44s после unseal. +Измерение Argon2 в API container: hash+verify median0.209s, maxRSS53168KiB; +20 конкурентных login завершились за2.031s, 12×401 и8×429, две instance identities. +Основная KDF memory bound двух API: 4×32MiB=128MiB плюс overhead процесса. +Эти числа — один контрольный запуск, не гарантия p99/capacity/устойчивости к DDoS. + +## Ограничения и источники + +Single host и single DB/S3/broker/Bao/LB: отказ хоста или этих зависимостей не +переживается без перерыва. Есть отказ отдельной API-реплики, но не полноценная +HA всех компонентов. Cert/CRL renewal операторский; безопасный CA rollover под +нагрузкой не заявляется (выбран трек1). Учебная PKI и все shares на одном хосте. +Worker сохраняет возможность повредить разрешённые prefixes/jobs; least privilege +ограничивает ущерб, не делает скомпрометированный процесс безопасным. Audit Bao +остаётся в operator volume, rotation/retention нужны для длительной эксплуатации. +Сканирование не является доказательством отсутствия уязвимостей; применимость и +оставшиеся findings разобраны отдельно. Более строгий deployment потребует +динамических DB leases, isolated worker VM/seccomp, сетевых политик и отдельной +защиты operator workstation. + +Первичные источники: [OpenBao cert auth](https://openbao.org/docs/auth/cert/), +[declarative audit](https://openbao.org/docs/configuration/audit/), +[Python ssl](https://docs.python.org/3/library/ssl.html), +[OWASP Password Storage](https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html), +[Pillow13 release](https://pillow.readthedocs.io/en/stable/releasenotes/13.0.0.html), +[Trivy](https://trivy.dev/docs/latest/getting-started/installation/). diff --git a/checks/bao_policy.py b/checks/bao_policy.py new file mode 100644 index 0000000..ffa9923 --- /dev/null +++ b/checks/bao_policy.py @@ -0,0 +1,39 @@ +import json +import ssl +import urllib.request +from urllib.error import HTTPError +from tls_matrix import context + + +def request(role,path,body=None,token=None): + headers={'Content-Type':'application/json'} + if token:headers['X-Vault-Token']=token + req=urllib.request.Request('https://openbao:8200/v1/'+path,headers=headers, + data=json.dumps(body).encode() if body is not None else None) + try: + with urllib.request.urlopen(req,context=context(role),timeout=5) as r: + raw=r.read();return r.status,json.loads(raw) if raw else {} + except HTTPError as e:return e.code,{} + + +results=[] +for role in ('api1','api2','worker','dispatcher','reconciler'): + code,data=request(role,'auth/cert/login',{'name':role}) + assert code==200,(role,code) + auth=data['auth'];token=auth['client_token'] + assert 00, + 'scoped_worker_denied':['sessions','password_hashes','messages','DDL','role_admin','foreign_S3_prefix','bucket_admin','queue_publish','queue_admin']} + image_before=docker('images','-q','worker') + root=json.loads((ROOT/'secrets/operator/bao-init.json').read_text())['root_token'] + identity=ROOT/'secrets/identities/worker' + backup=ROOT/'secrets/operator/worker-before-rotation';backup.mkdir(exist_ok=True) + for f in identity.iterdir():shutil.copy2(f,backup/f.name) + old_serial=pki.x509.load_pem_x509_certificate((identity/'cert.pem').read_bytes()).serial_number + start=time.monotonic() + pki.revoke('worker') + request('auth/cert/crls/operator',{'crl':(ROOT/'secrets/trust/revocations.pem').read_text()},root) + deny="import sys;sys.path.insert(0,'/checks');from tls_matrix import rejected;assert rejected('db',8443,'worker');print('old worker TLS denied')" + assert 'denied' in docker('run','--rm','--no-deps','security-check','python','-c',deny) + # Terminate old already-authenticated DB sessions as part of containment. + sql("SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE usename='worker'") + queued=[c.attachment(a,chat) for _ in range(3)] + time.sleep(3) + ids=','.join("'"+att['id']+"'" for att,_ in queued) + assert sql(f"SELECT count(*) FROM attachments WHERE id IN ({ids}) AND status='queued'")=='3' + # Cert auth must reject the old identity even though signed by our CA. + rejection=docker('exec','-T','worker','python','-',input="from src.secret_agent import fetch\nfrom urllib.error import HTTPError\ntry: fetch()\nexcept HTTPError as e: assert e.code in (400,403); print('denied')\nelse: raise AssertionError('revoked worker got secrets')\n") + assert rejection=='denied' + cfg_path=ROOT/'secrets/operator/config.json';cfg=json.loads(cfg_path.read_text()) + old_url=cfg['service_credentials']['worker']['DATABASE_URL'] + password=secrets.token_hex(24) + sql(f"ALTER ROLE worker PASSWORD '{password}'") + cfg['database_passwords']['worker']=password + cfg['service_credentials']['worker']['DATABASE_URL']=f'postgresql://worker:{password}@127.0.0.1:5432/messenger' + cfg_path.write_text(json.dumps(cfg,indent=2));cfg_path.chmod(0o600) + cert=pki.issue('worker') + docker('run','--rm','--no-deps','secret-init') + # New TLS identity + old database secret is denied by PostgreSQL itself. + code="""import json,sys,psycopg +url=json.load(sys.stdin)['url'] +try: psycopg.connect(url,connect_timeout=3) +except psycopg.OperationalError as e: + assert 'password authentication failed' in str(e);print('old password denied') +else:raise AssertionError('old database secret still valid') +""" + check=docker('exec','-T','worker','python','-c',code,input=json.dumps({'url':old_url})) + assert check=='old password denied' + request('secret/data/worker',{'data':cfg['service_credentials']['worker']},root) + for att,content in queued: + c.wait_ready(a,att,wait_seconds=90) + downloaded=c.call('GET','/api/v1/attachments/'+att['id']+'/content',actor=a)['bytes'] + assert hashlib.sha256(downloaded).digest()==hashlib.sha256(content).digest() + assert sql(f"SELECT count(*) FROM jobs WHERE attachment_id IN ({ids}) AND status='done'")=='3' + assert sql(f"SELECT count(*) FROM jobs WHERE attachment_id IN ({ids})")=='3' + assert image_before==docker('images','-q','worker') + result={'passed':True,'baseline':baseline,'revoked_serial':str(old_serial),'new_serial':str(cert.serial_number), + 'revoked_certificate_denied':True,'revoked_Bao_auth_denied':True,'rotated_old_DB_password_denied':True, + 'queued_during_revocation':3,'completed_after_rotation':3,'distinct_jobs':3,'content_SHA256_preserved':True, + 'image_unchanged':True,'total_seconds':round(time.monotonic()-start,2)} + (ROOT/'evidence/compromised-worker.json').write_text(json.dumps(result,indent=2)+'\n') + print('PASS: revoked worker -> queue preserved -> new cert/DB secret -> 3/3 jobs and hashes intact') + + +if __name__=='__main__':main() diff --git a/checks/hardening.py b/checks/hardening.py new file mode 100644 index 0000000..2dea500 --- /dev/null +++ b/checks/hardening.py @@ -0,0 +1,36 @@ +import json +from pathlib import Path +import ssl +import subprocess +import urllib.request + +ROOT=Path(__file__).resolve().parents[1] +def docker(*args):return subprocess.check_output(['docker',*args],cwd=ROOT,text=True,encoding='utf-8').strip() +rows=[] +ids=docker('compose','ps','-q').splitlines() +for cid in ids: + data=json.loads(docker('inspect',cid))[0] + role=data['Config']['Labels']['com.docker.compose.service'] + if role in ('telemetry-init','secret-init'):continue + h=data['HostConfig'];mounts=data['Mounts'];user=data['Config']['User'] + assert not h['Privileged'] and h['NetworkMode']!='host' + assert h['ReadonlyRootfs'] and 'ALL' in h['CapDrop'] and 'no-new-privileges:true' in h['SecurityOpt'] + assert h['Memory']>0 and h['NanoCpus']>0 and h['PidsLimit']>0 + assert not any('docker.sock' in m['Source'] or '/operator' in m['Source'].replace('\\','/') for m in mounts) + published=[] + for port,bindings in (h.get('PortBindings') or {}).items(): + for bind in bindings or []: + assert bind['HostIp']=='127.0.0.1' + assert (role,bind['HostPort']) in {('lb','8443'),('openbao','8200'),('grafana','3000')} + published.append(bind['HostPort']) + if role in ('api1','api2','worker','dispatcher','reconciler'): + assert user=='10001:10001' + assert all(not e.startswith(('DATABASE_URL=','S3_SECRET_KEY=','BAO_TOKEN=','POSTGRES_PASSWORD=')) for e in data['Config']['Env']) + assert all(m['Destination'] in ('/identity','/trust','/tmp') for m in mounts) + rows.append({'service':role,'user':user,'read_only':True,'cap_drop':['ALL'],'memory_bytes':h['Memory'],'NanoCpus':h['NanoCpus'],'pids_limit':h['PidsLimit'],'published_loopback_ports':published,'operator_material_absent':True}) +ctx=ssl.create_default_context(cafile=str(ROOT/'secrets/trust/ca.crt')) +with urllib.request.urlopen('https://127.0.0.1:3000/login',context=ctx,timeout=10) as r:assert r.status==200 +raw=docker('compose','run','--rm','--no-deps','security-check','python','/checks/plaintext_isolation.py') +isolation=json.loads(raw);assert isolation['passed'] +(ROOT/'evidence/hardening.json').write_text(json.dumps({'passed':True,'runtime':rows,'grafana_verified_HTTPS':True,'plaintext_isolation':isolation},indent=2)+'\n') +print('PASS: runtime privileges/resource limits/mounts/public ports and loopback-only plaintext') diff --git a/checks/plaintext_isolation.py b/checks/plaintext_isolation.py new file mode 100644 index 0000000..bd44fb1 --- /dev/null +++ b/checks/plaintext_isolation.py @@ -0,0 +1,15 @@ +import json +import socket + +ports={'api1':[8080],'api2':[8080],'db':[5432],'s3':[8333,8888,9333,19333], + 'cache':[6379],'broker':[6379],'otel-collector':[4318,9464,8888,13133], + 'prometheus':[9090],'loki':[3100,9095],'tempo':[3200,4318,9095]} +results=[] +for host,values in ports.items(): + for port in values: + with socket.socket() as s: + s.settimeout(2) + try:s.connect((host,port)) + except ConnectionRefusedError:results.append({'host':host,'port':port,'refused':True}) + else:raise AssertionError(f'Plaintext port reachable: {host}:{port}') +print(json.dumps({'passed':True,'probes':results},indent=2)) diff --git a/checks/sealed_bao.py b/checks/sealed_bao.py new file mode 100644 index 0000000..56b53ee --- /dev/null +++ b/checks/sealed_bao.py @@ -0,0 +1,46 @@ +"""Finite supervisor lease under real sealed OpenBao, then explicit recovery.""" +import json +from pathlib import Path +import ssl +import subprocess +import sys +import time +import urllib.request +from urllib.error import HTTPError,URLError + +ROOT=Path(__file__).resolve().parents[1] +sys.path.insert(0,str(ROOT/'scripts')) +from bao_operator import request + +ctx=ssl.create_default_context(cafile=str(ROOT/'secrets/trust/ca.crt')) +def status(): + try: + with urllib.request.urlopen('https://127.0.0.1:8443/health/ready',context=ctx,timeout=3) as r:return r.status + except HTTPError as e:return e.code + +assert status()==200 +root=json.loads((ROOT/'secrets/operator/bao-init.json').read_text())['root_token'] +start=time.monotonic();observations=[] +try: + request('sys/seal',{},root) + while time.monotonic()-start<150: + current=status();observations.append({'seconds':round(time.monotonic()-start,1),'HTTP':current}) + if current==503: + # Both API children must actually have stopped, not just one LB check. + code="import socket; s=socket.socket();s.settimeout(1);assert s.connect_ex(('127.0.0.1',8080))!=0" + for role in ('api1','api2'): + subprocess.run(['docker','compose','exec','-T',role,'python','-c',code],cwd=ROOT,check=True,capture_output=True) + break + time.sleep(2) + else:raise AssertionError('Application exceeded finite secret availability budget') + stopped=time.monotonic()-start +finally: + subprocess.run([sys.executable,str(ROOT/'scripts/bao_operator.py'),'unseal'],cwd=ROOT,check=True) +recovery=time.monotonic() +while time.monotonic()-recovery<60: + if status()==200:break + time.sleep(1) +else:raise AssertionError('Unsealed system failed to recover') +result={'passed':True,'secret_refresh_seconds':20,'token_max_TTL_seconds':120,'both_API_children_stopped_seconds':round(stopped,2),'recovery_seconds':round(time.monotonic()-recovery,2),'observations':observations,'scope':'Supervisor bounds use during Bao outage; static backend passwords themselves require explicit rotation.'} +(ROOT/'evidence/sealed-bao.json').write_text(json.dumps(result,indent=2)+'\n') +print('PASS: sealed Bao -> finite lease -> both API children stopped -> unseal -> recovery') diff --git a/checks/security_api.py b/checks/security_api.py new file mode 100644 index 0000000..cd9173c --- /dev/null +++ b/checks/security_api.py @@ -0,0 +1,68 @@ +"""HTTPS ACL/session/KDF/replica-shared login limits. Synthetic local test data.""" +import base64 +from concurrent.futures import ThreadPoolExecutor +import hashlib +import json +from pathlib import Path +import statistics +import subprocess +import sys +import time + +ROOT=Path(__file__).resolve().parents[1] +sys.path[:0]=[str(ROOT/'tests'),str(ROOT/'scripts')] +from client import Client +from database_operator import sql +from argon2 import PasswordHasher + + +def client():return Client('https://127.0.0.1:8443',str(ROOT/'secrets/trust/ca.crt')) + + +def main(): + c=client();a,b,e,chat=c.bootstrap();att,content=c.attachment(a,chat);c.wait_ready(a,att) + for suffix in ('','/content','/thumbnail'): + c.call('GET','/api/v1/attachments/'+att['id']+suffix,404,actor=e) + c.call('POST','/api/v1/chats/'+chat['id']+'/attachments?filename=x.png',404,actor=e,raw=content,headers={'Content-Type':'image/png'}) + c.call('GET','/api/v1/users/me',401,headers={'Authorization':'Bearer '+'x'*43}) + # Upgrade a valid historical hash only after successful verification. + old=PasswordHasher(time_cost=2,memory_cost=19456,parallelism=1).hash(a['registration']['password']) + sql(f"UPDATE users SET password_hash='{old}' WHERE id='{a['id']}'") + credential=base64.b64encode((a['registration']['username']+':'+a['registration']['password']).encode()).decode() + session=c.call('POST','/api/v1/auth/sessions',201,headers={'Authorization':'Basic '+credential},schema='Session')['json'] + stored=sql(f"SELECT password_hash FROM users WHERE id='{a['id']}'") + assert stored!=old and '$argon2id$' in stored and 'm=32768,t=2,p=1' in stored + digest=hashlib.sha256(session['token'].encode()).hexdigest() + assert sql(f"SELECT count(*) FROM sessions WHERE token_hash='{digest}'")=='1' + sql(f"UPDATE sessions SET expires_at=clock_timestamp()-interval '1 second' WHERE token_hash='{digest}'") + c.call('GET','/api/v1/users/me',401,actor={'token':session['token']}) + c.call('DELETE','/api/v1/auth/sessions/current',204,actor=b) + c.call('GET','/api/v1/users/me',401,actor=b) + # Reset only the synthetic experiment's two limiter counters; limiter stays on. + sql('DELETE FROM login_budget') + wrong=base64.b64encode((a['registration']['username']+':Wrong-password-123').encode()).decode() + def login(_): + r=client().call('POST','/api/v1/auth/sessions',(401,429),headers={'Authorization':'Basic '+wrong}) + if r['status']==429:assert int(r['headers']['Retry-After'])>0 + assert a['registration']['password'].encode() not in r['bytes'] and b'argon2' not in r['bytes'] + return {'status':r['status'],'seconds':round(r['elapsed'],4),'instance':r['headers']['X-Instance-Id']} + begin=time.monotonic() + with ThreadPoolExecutor(max_workers=20) as pool:attempts=list(pool.map(login,range(20))) + elapsed=time.monotonic()-begin + assert elapsed<10 and sum(r['status']==401 for r in attempts)==12 and sum(r['status']==429 for r in attempts)==8 + assert len({r['instance'] for r in attempts})==2 + # Measure actual Argon2 on the resource-limited API container, not the host. + bench="""import json,time,statistics,resource +from argon2 import PasswordHasher +p=PasswordHasher(time_cost=2,memory_cost=32768,parallelism=1);times=[] +for i in range(12): + t=time.perf_counter();h=p.hash('synthetic-benchmark-password');p.verify(h,'synthetic-benchmark-password');times.append(time.perf_counter()-t) +print(json.dumps({'hash_plus_verify_seconds':times,'median':statistics.median(times),'max_rss_kib':resource.getrusage(resource.RUSAGE_SELF).ru_maxrss})) +""" + kdf=json.loads(subprocess.check_output(['docker','compose','exec','-T','api1','python','-c',bench],cwd=ROOT,text=True)) + result={'passed':True,'ACL_attachment_denials':4,'expired_session_denied':True,'logout_denied':True,'token_hash_sha256':True,'rehash':'19456 -> 32768 KiB','login_burst':attempts,'burst_seconds':round(elapsed,3),'KDF':kdf,'KDF_slots_per_API':2,'KDF_memory_bound_two_APIs_MiB':128} + (ROOT/'evidence/security-api.json').write_text(json.dumps(result,indent=2)+'\n') + print('PASS: ACL, expiry/logout, hash storage/rehash, shared 12/10s rate limit, measured Argon2') + + +if __name__=='__main__':main() diff --git a/checks/telemetry_probe.py b/checks/telemetry_probe.py new file mode 100644 index 0000000..99509e9 --- /dev/null +++ b/checks/telemetry_probe.py @@ -0,0 +1,31 @@ +"""Read telemetry using the operator's mTLS identity; never emit secret canaries.""" +import json +import sys +import time +import urllib.request +import urllib.parse +from urllib.error import HTTPError +from tls_matrix import context + +args=json.load(sys.stdin);trace_id=args['trace_id'] +def get(host,port,path): + with urllib.request.urlopen('https://'+host+':'+str(port)+path,context=context('operator'),timeout=8) as r:return json.load(r) +deadline=time.monotonic()+90 +while True: + try: + trace=get('tempo',8444,'/api/traces/'+trace_id) + spans=[s for b in trace.get('batches',trace.get('resourceSpans',[])) for scope in b.get('scopeSpans',b.get('instrumentationLibrarySpans',[])) for s in scope.get('spans',[])] + names={s['name'] for s in spans} + query=urllib.parse.urlencode({'query':'{service_name=~"messenger-(api|worker|dispatcher)"} |= "'+trace_id+'"','limit':1000,'start':int((time.time()-600)*1e9),'end':int(time.time()*1e9)}) + logs=get('loki',8443,'/loki/api/v1/query_range?'+query) + lines=[line for stream in logs['data']['result'] for _,line in stream['values']] + if {'attachment.consume','db.attachment.commit','attachment.publish','image.render'}<=names and any('job_finished' in line for line in lines):break + except HTTPError as e: + if e.code!=404:raise + if time.monotonic()>deadline:raise AssertionError('Telemetry did not arrive over TLS') + time.sleep(2) +raw=json.dumps([trace,logs]) +assert all(secret not in raw for secret in args['canaries']) +metrics=get('prometheus',8443,'/api/v1/query?'+urllib.parse.urlencode({'query':'http_server_requests_total'})) +assert metrics['status']=='success' and metrics['data']['result'] +print(json.dumps({'passed':True,'trace_id':trace_id,'span_count':len(spans),'span_names':sorted(names),'correlated_log_count':len(lines),'http_metric_series':len(metrics['data']['result']),'credential_canaries_absent':True,'all_queries':'mTLS verified operator identity'},indent=2)) diff --git a/checks/telemetry_security.py b/checks/telemetry_security.py new file mode 100644 index 0000000..f7d9586 --- /dev/null +++ b/checks/telemetry_security.py @@ -0,0 +1,30 @@ +import json +from pathlib import Path +import subprocess +import sys +import uuid + +ROOT=Path(__file__).resolve().parents[1] +sys.path.insert(0,str(ROOT/'tests')) +from client import Client + +c=Client('https://127.0.0.1:8443',str(ROOT/'secrets/trust/ca.crt')) +a=c.user('telemetry') +chat=c.call('POST','/api/v1/chats',201,actor=a,body={'title':'TLS telemetry','member_ids':[a['id']]},schema='Chat')['json'] +trace=uuid.uuid4().hex +att=c.call('POST','/api/v1/chats/'+chat['id']+'/attachments?filename=sample.png',202,actor=a, + raw=(ROOT/'tests/fixtures/sample.png').read_bytes(),headers={'Content-Type':'image/png','traceparent':'00-'+trace+'-'+uuid.uuid4().hex[:16]+'-01'},schema='Attachment')['json'] +c.wait_ready(a,att) +cfg=json.loads((ROOT/'secrets/operator/config.json').read_text()) +canaries=[a['token'],a['registration']['password'],*cfg['database_passwords'].values()] +for data in cfg['service_credentials'].values(): + canaries.extend([data[k] for k in ('CURSOR_SECRET','S3_SECRET_KEY') if k in data]) +result=subprocess.run(['docker','compose','run','--rm','-T','--no-deps','security-check','python','/checks/telemetry_probe.py'],cwd=ROOT, + input=json.dumps({'trace_id':trace,'canaries':canaries}),text=True,capture_output=True) +if result.returncode:raise RuntimeError('Telemetry check failed: '+result.stderr[-1500:]) +summary=json.loads(result.stdout) +logs=subprocess.check_output(['docker','compose','logs','--no-color'],cwd=ROOT,text=True,encoding='utf-8',errors='replace') +assert all(secret not in logs for secret in canaries) +summary['container_logs_canaries_absent']=True +(ROOT/'evidence/telemetry-security.json').write_text(json.dumps(summary,indent=2)+'\n') +print('PASS: TLS metrics/traces/log correlation, credential canaries absent in telemetry/container logs') diff --git a/checks/test_render.py b/checks/test_render.py new file mode 100644 index 0000000..d7ab562 --- /dev/null +++ b/checks/test_render.py @@ -0,0 +1,49 @@ +import json +from pathlib import Path +import tempfile +import unittest + +from PIL import Image +from src.render import render + + +class RenderTests(unittest.TestCase): + def generate(self, image, fmt='PNG', **save_args): + folder=tempfile.TemporaryDirectory(); self.addCleanup(folder.cleanup) + root=Path(folder.name); source=root/'input' + image.save(source,format=fmt,**save_args) + records=render(source,root,1) + return root,{row['name']:row for row in records} + + def test_contract_dimensions(self): + root,rows=self.generate(Image.new('RGB',(320,200),'red')) + self.assertEqual((rows['thumbnail']['width'],rows['thumbnail']['height']),(256,160)) + self.assertEqual((rows['crop']['width'],rows['crop']['height']),(128,128)) + with Image.open(root/'optimized') as optimized: + self.assertEqual(optimized.format,'WEBP') + self.assertEqual(optimized.size,(320,200)) + + def test_alpha_white_and_small_image_not_enlarged(self): + root,rows=self.generate(Image.new('RGBA',(17,9),(255,0,0,0))) + with Image.open(root/'thumbnail') as thumb: + self.assertEqual(thumb.size,(17,9)) + self.assertTrue(all(c>=250 for c in thumb.getpixel((0,0)))) + self.assertEqual(rows['crop']['width'],128) + + def test_exif_orientation_and_metadata_removed(self): + exif=Image.Exif(); exif[274]=6; exif[270]='synthetic metadata must disappear' + root,rows=self.generate(Image.new('RGB',(40,20),'blue'),'JPEG',exif=exif) + with Image.open(root/'thumbnail') as thumb: + self.assertEqual(thumb.size,(20,40)) + self.assertFalse(thumb.getexif()) + + def test_centered_crop(self): + image=Image.new('RGB',(300,100),'red') + image.paste(Image.new('RGB',(100,100),'green'),(100,0)) + root,_=self.generate(image) + with Image.open(root/'crop') as crop: + r,g,b=crop.getpixel((64,64)) + self.assertGreater(g,r+60); self.assertGreater(g,b+60) + + +if __name__=='__main__': unittest.main() diff --git a/checks/tls_matrix.py b/checks/tls_matrix.py new file mode 100644 index 0000000..0151e27 --- /dev/null +++ b/checks/tls_matrix.py @@ -0,0 +1,65 @@ +"""Inside the isolated test network. Every permitted edge and rejected identity. + +A timeout/refused connection is never counted as a valid negative TLS result. +""" +import json +from pathlib import Path +import socket +import ssl +import struct +import time + +IDENTITIES=Path('/audit-identities') +TRUST=Path('/trust') + + +def context(role=None): + ctx=ssl.create_default_context(cafile=str(TRUST/'bundle.pem')) + ctx.verify_flags |= ssl.VERIFY_CRL_CHECK_LEAF + if role:ctx.load_cert_chain(IDENTITIES/role/'cert.pem',IDENTITIES/role/'key.pem') + return ctx + + +def probe(host,port,role,hostname=None): + ctx=context(role) + with socket.create_connection((host,port),timeout=5) as raw: + with ctx.wrap_socket(raw,server_hostname=hostname or host) as conn: + conn.settimeout(5) + if host=='db':payload=struct.pack('!II',8,80877103) + elif host in ('cache','broker'):payload=b'*1\r\n$4\r\nPING\r\n' + else:payload=b'GET /health/live HTTP/1.1\r\nHost: '+host.encode()+b'\r\nConnection: close\r\n\r\n' + conn.sendall(payload) + return conn.recv(4096) + + +def rejected(host,port,role): + try:return not probe(host,port,role) + except (ssl.SSLError,ConnectionResetError,BrokenPipeError):return True + + +def main(): + start=time.monotonic();results=[] + for file in sorted(Path('/mesh').glob('*.json')): + host=file.stem + for route in json.loads(file.read_text()): + if route['mode']!='server':continue + port=route['listen'] + for role in route['allow']: + assert probe(host,port,role),f'Permitted edge failed: {role}->{host}:{port}' + results.append({'source':role,'destination':host,'port':port,'allowed':True}) + for role in (None,'outsider','alien','expired','revoked'): + assert rejected(host,port,role),f'Forbidden edge accepted: {role}->{host}:{port}' + # Same-CA hostname mismatch must fail client validation, not timeout. + try:probe(host,port,route['allow'][0],hostname='outsider') + except ssl.SSLCertVerificationError:pass + else:raise AssertionError('Wrong server identity accepted') + # Plaintext has no protocol response from a TLS-only ingress. + with socket.create_connection((host,port),timeout=5) as raw: + raw.settimeout(5);raw.sendall(b'GET / HTTP/1.1\r\nHost: x\r\n\r\n') + try:assert raw.recv(100)==b'' + except ConnectionResetError:pass + results.append({'destination':host,'port':port,'denied':['no_cert','wrong_CA','wrong_SAN','expired','revoked','wrong_server_SAN','plaintext']}) + print(json.dumps({'passed':True,'seconds':round(time.monotonic()-start,2),'edges':results},indent=2)) + + +if __name__=='__main__':main() diff --git a/checks/worker_rights.py b/checks/worker_rights.py new file mode 100644 index 0000000..4456c10 --- /dev/null +++ b/checks/worker_rights.py @@ -0,0 +1,37 @@ +"""Execute inside the real worker container with its cert-authenticated credentials.""" +import io +import json +import os +from uuid import uuid4 +import psycopg +import redis +from botocore.exceptions import ClientError +from src.secret_agent import fetch +from src.jobs import database +from src.storage import Storage +from src.broker import connect,ensure_group + +data,_=fetch();os.environ.update(data) +results={} +with database() as db: + assert db.execute('SELECT current_user AS role').fetchone()['role']=='worker' + db.execute('SELECT id FROM jobs LIMIT 1');results['jobs_read']='allowed' + for name,query in [('sessions','SELECT * FROM sessions'),('password_hashes','SELECT password_hash FROM users'),('messages','SELECT * FROM messages'),('schema','CREATE TABLE public.worker_escape(id int)'),('privilege','CREATE ROLE worker_escape SUPERUSER')]: + try:db.execute(query) + except psycopg.errors.InsufficientPrivilege:results[name]='denied' + else:raise AssertionError('Unexpected worker permission: '+name) +storage=Storage();key='variants/security-test-'+uuid4().hex+'/probe' +storage.client.put_object(Bucket=storage.bucket,Key=key,Body=b'test') +assert storage.client.get_object(Bucket=storage.bucket,Key=key)['Body'].read()==b'test' +storage.delete(key);results['variants_read_write_delete']='allowed' +for name,operation in [('foreign_prefix',lambda:storage.client.put_object(Bucket=storage.bucket,Key='private/forbidden',Body=b'test')),('bucket_admin',lambda:storage.client.create_bucket(Bucket='forbidden-'+uuid4().hex))]: + try:operation() + except ClientError as e: + assert e.response['ResponseMetadata']['HTTPStatusCode']==403;results[name]='denied' + else:raise AssertionError('Unexpected S3 permission: '+name) +queue=connect();ensure_group(queue);assert queue.ping();results['queue_group']='allowed' +for name,op in [('queue_publish',lambda:queue.xadd('attachment-jobs',{'forbidden':'test'})),('foreign_queue',lambda:queue.xreadgroup('image-workers','security-test',{'other-queue':'>'},count=1)),('queue_admin',lambda:queue.config_get('*'))]: + try:op() + except redis.exceptions.NoPermissionError:results[name]='denied' + else:raise AssertionError('Unexpected queue permission: '+name) +print(json.dumps({'passed':True,'rights':results},indent=2)) diff --git a/compose.yaml b/compose.yaml new file mode 100644 index 0000000..a8e15ce --- /dev/null +++ b/compose.yaml @@ -0,0 +1,1061 @@ +services: + telemetry-init: + image: mtusi-messenger:lab7 + cpus: 1.0 + mem_limit: 256m + pids_limit: 64 + read_only: true + cap_drop: + - ALL + security_opt: + - no-new-privileges:true + stop_grace_period: 35s + logging: + driver: json-file + options: + max-size: 5m + max-file: '2' + user: 0:0 + cap_add: + - CHOWN + - FOWNER + command: + - python + - -c + - import os; [(os.chown(p,u,g),os.chmod(p,0o750)) for p,u,g in [('/bao',10001,10001),('/grafana',472,472),('/prometheus',65534,65534),('/loki',10001,10001),('/tempo',10001,10001),('/pg',999,999),('/broker',999,1000)]] + healthcheck: + disable: true + volumes: + - grafanadata:/grafana + - prometheusdata:/prometheus + - lokidata:/loki + - tempodata:/tempo + - baodata:/bao + - pgdata:/pg + - brokerdata:/broker + otel-collector: + image: mirror.gcr.io/otel/opentelemetry-collector-contrib@sha256:ffc818ee108d0b934fd14207fd87ff247c9b64f344ed349d0b66c166c18a2312 + command: + - --config=/etc/otel/config.yaml + volumes: + - ./infra/otel-collector.yaml:/etc/otel/config.yaml:ro + mem_limit: 256m + cpus: 0.5 + environment: + GOMEMLIMIT: 192MiB + GOMAXPROCS: '2' + read_only: true + cap_drop: + - ALL + security_opt: + - no-new-privileges:true + pids_limit: 128 + logging: + driver: json-file + options: + max-size: 5m + max-file: '2' + prometheus: + image: mirror.gcr.io/prom/prometheus@sha256:efd719c99d83b060d9daefdcf00360461adf279f45ef5391f8d111892118753e + command: + - --config.file=/etc/prometheus/prometheus.yaml + - --storage.tsdb.path=/prometheus + - --storage.tsdb.retention.time=24h + - --storage.tsdb.retention.size=256MB + - --web.listen-address=127.0.0.1:9090 + volumes: + - ./infra/prometheus.yaml:/etc/prometheus/prometheus.yaml:ro + - ./infra/alerts.yaml:/etc/prometheus/alerts.yaml:ro + - prometheusdata:/prometheus + mem_limit: 256m + cpus: 0.5 + security_opt: + - no-new-privileges:true + cap_drop: + - ALL + pids_limit: 128 + logging: + driver: json-file + options: + max-size: 5m + max-file: '2' + depends_on: + telemetry-init: + condition: service_completed_successfully + read_only: true + tmpfs: + - /tmp:size=32m,mode=1777 + loki: + image: mirror.gcr.io/grafana/loki@sha256:3c8fd3570dd9219951a60d3f919c7f31923d10baee578b77bc26c4a0b32d092d + command: + - -config.file=/etc/loki/config.yaml + volumes: + - ./infra/loki.yaml:/etc/loki/config.yaml:ro + - lokidata:/var/loki + mem_limit: 256m + cpus: 0.5 + environment: + GOMEMLIMIT: 192MiB + GOMAXPROCS: '2' + security_opt: + - no-new-privileges:true + cap_drop: + - ALL + pids_limit: 128 + logging: + driver: json-file + options: + max-size: 5m + max-file: '2' + depends_on: + telemetry-init: + condition: service_completed_successfully + read_only: true + tmpfs: + - /tmp:size=32m,mode=1777 + tempo: + image: mirror.gcr.io/grafana/tempo@sha256:d7f4c72e0bad2b42b4e7263b0addaf3f5bbc105cec6b1917eba0aae3b9b70364 + command: + - -config.file=/etc/tempo/config.yaml + volumes: + - ./infra/tempo.yaml:/etc/tempo/config.yaml:ro + - tempodata:/var/tempo + mem_limit: 256m + cpus: 0.5 + environment: + GOMEMLIMIT: 192MiB + GOMAXPROCS: '2' + security_opt: + - no-new-privileges:true + cap_drop: + - ALL + pids_limit: 128 + logging: + driver: json-file + options: + max-size: 5m + max-file: '2' + depends_on: + telemetry-init: + condition: service_completed_successfully + read_only: true + tmpfs: + - /tmp:size=32m,mode=1777 + grafana: + image: mirror.gcr.io/grafana/grafana@sha256:dbbc38ea21103cefb50396340cd88afec779c7e070b0a7bf5a75b4ce46651d3f + environment: + GF_SECURITY_ADMIN_USER: admin + GF_SECURITY_ADMIN_PASSWORD__FILE: /run/secrets/password + GF_USERS_ALLOW_SIGN_UP: 'false' + GF_ANALYTICS_REPORTING_ENABLED: 'false' + GF_ANALYTICS_CHECK_FOR_UPDATES: 'false' + GOMEMLIMIT: 384MiB + GOMAXPROCS: '2' + GF_SERVER_PROTOCOL: https + GF_SERVER_CERT_FILE: /identity/cert.pem + GF_SERVER_CERT_KEY: /identity/key.pem + volumes: + - grafanadata:/var/lib/grafana + - ./infra/grafana/provisioning:/etc/grafana/provisioning:ro + - ./infra/grafana/dashboards:/var/lib/grafana/dashboards:ro + - config-grafana:/run/secrets:ro + - identity-grafana:/identity:ro + mem_limit: 512m + cpus: 1.0 + security_opt: + - no-new-privileges:true + cap_drop: + - ALL + pids_limit: 128 + logging: + driver: json-file + options: + max-size: 5m + max-file: '2' + ports: + - 127.0.0.1:3000:3000 + depends_on: + telemetry-init: + condition: service_completed_successfully + secret-init: + condition: service_completed_successfully + read_only: true + tmpfs: + - /tmp:size=32m,mode=1777 + db: + image: mirror.gcr.io/library/postgres@sha256:3645570cccdfa447589da9f57dd740faa29b30938e861289a5574b6ca6b03826 + environment: + POSTGRES_USER: messenger + POSTGRES_DB: messenger + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?Run python scripts/bootstrap.py} + command: + - postgres + - -c + - shared_buffers=64MB + - -c + - max_connections=30 + - -c + - listen_addresses=127.0.0.1 + - -c + - hba_file=/etc/postgresql/pg_hba.conf + volumes: + - pgdata:/var/lib/postgresql/data + - ./infra/pg_hba.conf:/etc/postgresql/pg_hba.conf:ro + cpus: 1.0 + mem_limit: 256m + healthcheck: + test: + - CMD-SHELL + - pg_isready -U messenger -d messenger + interval: 2s + timeout: 2s + retries: 20 + security_opt: + - no-new-privileges:true + cap_drop: + - ALL + pids_limit: 128 + logging: + driver: json-file + options: + max-size: 5m + max-file: '2' + user: 999:999 + tmpfs: + - /var/run/postgresql:uid=999,gid=999,mode=0700 + - /tmp:size=32m,mode=1777 + depends_on: + telemetry-init: + condition: service_completed_successfully + read_only: true + cache: + image: mirror.gcr.io/valkey/valkey@sha256:081c2f5cb575efc901aa80ff9cdbd1ec6a301682fd35e1ebb4b0990a4a4a8507 + command: + - valkey-server + - /etc/valkey/lab.conf + cpus: 0.25 + mem_limit: 64m + security_opt: + - no-new-privileges:true + cap_drop: + - ALL + pids_limit: 128 + logging: + driver: json-file + options: + max-size: 5m + max-file: '2' + volumes: + - config-cache:/etc/valkey:ro + user: 999:1000 + depends_on: + telemetry-init: + condition: service_completed_successfully + secret-init: + condition: service_completed_successfully + read_only: true + tmpfs: + - /tmp:size=32m,mode=1777 + - /data:uid=999,gid=1000,size=1m + s3: + image: chrislusf/seaweedfs@sha256:ccad23e18639c8b98cee17e7100b95830a06077b56d8e5b006d6dcf8ec5e94a0 + user: 1000:1000 + command: + - server + - -dir=/data + - -ip=127.0.0.1 + - -ip.bind=127.0.0.1 + - -s3 + - -s3.ip.bind=127.0.0.1 + - -s3.config=/etc/seaweedfs/s3.json + - -s3.port.iceberg=0 + - -s3.port.lance=0 + - -s3.autoCreateBucket=false + - -volume.max=10 + - -master.volumeSizeLimitMB=100 + - -filer.concurrentUploadLimitMB=64 + environment: + GOMEMLIMIT: 384MiB + GOMAXPROCS: '2' + volumes: + - s3data:/data + - config-s3:/etc/seaweedfs:ro + cpus: 1.0 + mem_limit: 512m + cap_drop: + - ALL + security_opt: + - no-new-privileges:true + stop_grace_period: 20s + pids_limit: 128 + logging: + driver: json-file + options: + max-size: 5m + max-file: '2' + depends_on: + secret-init: + condition: service_completed_successfully + read_only: true + tmpfs: + - /tmp:size=32m,mode=1777 + reconciler: + image: mtusi-messenger:lab7 + cpus: 0.25 + mem_limit: 192m + pids_limit: 64 + read_only: true + cap_drop: + - ALL + security_opt: + - no-new-privileges:true + stop_grace_period: 35s + logging: + driver: json-file + options: + max-size: 5m + max-file: '2' + command: + - python + - -m + - src.secret_agent + - python + - -m + - src.cleanup + healthcheck: + disable: true + environment: + SERVICE_ROLE: reconciler + APP_HOST: 127.0.0.1 + volumes: + - identity-reconciler:/identity:ro + - ./secrets/trust:/trust:ro + depends_on: + secret-init: + condition: service_completed_successfully + broker: + image: mirror.gcr.io/valkey/valkey@sha256:081c2f5cb575efc901aa80ff9cdbd1ec6a301682fd35e1ebb4b0990a4a4a8507 + command: + - valkey-server + - /etc/valkey/lab.conf + volumes: + - brokerdata:/data + - config-broker:/etc/valkey:ro + cpus: 0.25 + mem_limit: 128m + security_opt: + - no-new-privileges:true + cap_drop: + - ALL + pids_limit: 128 + logging: + driver: json-file + options: + max-size: 5m + max-file: '2' + user: 999:1000 + depends_on: + telemetry-init: + condition: service_completed_successfully + secret-init: + condition: service_completed_successfully + read_only: true + tmpfs: + - /tmp:size=32m,mode=1777 + dispatcher: + image: mtusi-messenger:lab7 + cpus: 0.25 + mem_limit: 128m + pids_limit: 64 + read_only: true + cap_drop: + - ALL + security_opt: + - no-new-privileges:true + stop_grace_period: 35s + logging: + driver: json-file + options: + max-size: 5m + max-file: '2' + tmpfs: + - /tmp:size=32m,mode=1777 + command: + - python + - -m + - src.secret_agent + - python + - -m + - src.dispatcher + healthcheck: + disable: true + environment: + SERVICE_ROLE: dispatcher + APP_HOST: 127.0.0.1 + volumes: + - identity-dispatcher:/identity:ro + - ./secrets/trust:/trust:ro + depends_on: + secret-init: + condition: service_completed_successfully + worker: + image: mtusi-messenger:lab7 + cpus: 1.0 + mem_limit: 768m + pids_limit: 64 + read_only: true + cap_drop: + - ALL + security_opt: + - no-new-privileges:true + stop_grace_period: 35s + logging: + driver: json-file + options: + max-size: 5m + max-file: '2' + tmpfs: + - /tmp:size=64m,mode=1777 + command: + - python + - -m + - src.secret_agent + - python + - -m + - src.worker + healthcheck: + disable: true + environment: + SERVICE_ROLE: worker + APP_HOST: 127.0.0.1 + volumes: + - identity-worker:/identity:ro + - ./secrets/trust:/trust:ro + depends_on: + secret-init: + condition: service_completed_successfully + lb: + image: mirror.gcr.io/library/haproxy@sha256:b9fe316f718d5015c5cfebd8ca019591f3e44656f61d93cb8b59a1028961e530 + volumes: + - ./infra/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro + - identity-lb:/identity:ro + - ./secrets/trust:/trust:ro + cpus: 0.5 + mem_limit: 64m + read_only: true + cap_drop: + - ALL + security_opt: + - no-new-privileges:true + pids_limit: 128 + logging: + driver: json-file + options: + max-size: 5m + max-file: '2' + ports: + - 127.0.0.1:8443:8443 + user: 10001:10001 + depends_on: + secret-init: + condition: service_completed_successfully + api1: + image: mtusi-messenger:lab7 + cpus: 0.5 + mem_limit: 512m + pids_limit: 64 + read_only: true + cap_drop: + - ALL + security_opt: + - no-new-privileges:true + stop_grace_period: 35s + logging: + driver: json-file + options: + max-size: 5m + max-file: '2' + tmpfs: + - /tmp:size=32m,mode=1777 + environment: + SERVICE_ROLE: api1 + APP_HOST: 127.0.0.1 + volumes: + - identity-api1:/identity:ro + - ./secrets/trust:/trust:ro + command: + - python + - -m + - src.secret_agent + - python + - -m + - src + build: . + depends_on: + secret-init: + condition: service_completed_successfully + api2: + image: mtusi-messenger:lab7 + cpus: 0.5 + mem_limit: 512m + pids_limit: 64 + read_only: true + cap_drop: + - ALL + security_opt: + - no-new-privileges:true + stop_grace_period: 35s + logging: + driver: json-file + options: + max-size: 5m + max-file: '2' + tmpfs: + - /tmp:size=32m,mode=1777 + environment: + SERVICE_ROLE: api2 + APP_HOST: 127.0.0.1 + volumes: + - identity-api2:/identity:ro + - ./secrets/trust:/trust:ro + command: + - python + - -m + - src.secret_agent + - python + - -m + - src + depends_on: + secret-init: + condition: service_completed_successfully + openbao: + image: quay.io/openbao/openbao@sha256:5046911075e137e154ce49ab051502f4ec7cf367d484ae4a4dce665d9b90561f + user: 10001:10001 + entrypoint: + - bao + command: + - server + - -config=/etc/bao/config.hcl + volumes: + - ./infra/openbao.hcl:/etc/bao/config.hcl:ro + - identity-openbao:/identity:ro + - ./secrets/trust:/trust:ro + - baodata:/bao + ports: + - 127.0.0.1:8200:8200 + mem_limit: 256m + memswap_limit: 256m + pids_limit: 128 + cpus: 0.5 + read_only: true + cap_drop: + - ALL + security_opt: + - no-new-privileges:true + environment: + GOMEMLIMIT: 192MiB + depends_on: + telemetry-init: + condition: service_completed_successfully + secret-init: + condition: service_completed_successfully + api1-tls: + image: mtusi-messenger:lab7 + command: + - python + - -m + - src.tls_proxy + network_mode: service:api1 + depends_on: + api1: + condition: service_started + secret-init: + condition: service_completed_successfully + volumes: + - ./infra/mesh/api1.json:/proxy.json:ro + - identity-api1:/identity:ro + - ./secrets/trust:/trust:ro + healthcheck: + disable: true + read_only: true + cap_drop: + - ALL + security_opt: + - no-new-privileges:true + mem_limit: 64m + cpus: 0.2 + pids_limit: 32 + api2-tls: + image: mtusi-messenger:lab7 + command: + - python + - -m + - src.tls_proxy + network_mode: service:api2 + depends_on: + api2: + condition: service_started + secret-init: + condition: service_completed_successfully + volumes: + - ./infra/mesh/api2.json:/proxy.json:ro + - identity-api2:/identity:ro + - ./secrets/trust:/trust:ro + healthcheck: + disable: true + read_only: true + cap_drop: + - ALL + security_opt: + - no-new-privileges:true + mem_limit: 64m + cpus: 0.2 + pids_limit: 32 + db-tls: + image: mtusi-messenger:lab7 + command: + - python + - -m + - src.tls_proxy + network_mode: service:db + depends_on: + db: + condition: service_started + secret-init: + condition: service_completed_successfully + volumes: + - ./infra/mesh/db.json:/proxy.json:ro + - identity-db:/identity:ro + - ./secrets/trust:/trust:ro + healthcheck: + disable: true + read_only: true + cap_drop: + - ALL + security_opt: + - no-new-privileges:true + mem_limit: 64m + cpus: 0.2 + pids_limit: 32 + s3-tls: + image: mtusi-messenger:lab7 + command: + - python + - -m + - src.tls_proxy + network_mode: service:s3 + depends_on: + s3: + condition: service_started + secret-init: + condition: service_completed_successfully + volumes: + - ./infra/mesh/s3.json:/proxy.json:ro + - identity-s3:/identity:ro + - ./secrets/trust:/trust:ro + healthcheck: + disable: true + read_only: true + cap_drop: + - ALL + security_opt: + - no-new-privileges:true + mem_limit: 64m + cpus: 0.2 + pids_limit: 32 + cache-tls: + image: mtusi-messenger:lab7 + command: + - python + - -m + - src.tls_proxy + network_mode: service:cache + depends_on: + cache: + condition: service_started + secret-init: + condition: service_completed_successfully + volumes: + - ./infra/mesh/cache.json:/proxy.json:ro + - identity-cache:/identity:ro + - ./secrets/trust:/trust:ro + healthcheck: + disable: true + read_only: true + cap_drop: + - ALL + security_opt: + - no-new-privileges:true + mem_limit: 64m + cpus: 0.2 + pids_limit: 32 + broker-tls: + image: mtusi-messenger:lab7 + command: + - python + - -m + - src.tls_proxy + network_mode: service:broker + depends_on: + broker: + condition: service_started + secret-init: + condition: service_completed_successfully + volumes: + - ./infra/mesh/broker.json:/proxy.json:ro + - identity-broker:/identity:ro + - ./secrets/trust:/trust:ro + healthcheck: + disable: true + read_only: true + cap_drop: + - ALL + security_opt: + - no-new-privileges:true + mem_limit: 64m + cpus: 0.2 + pids_limit: 32 + otel-collector-tls: + image: mtusi-messenger:lab7 + command: + - python + - -m + - src.tls_proxy + network_mode: service:otel-collector + depends_on: + otel-collector: + condition: service_started + secret-init: + condition: service_completed_successfully + volumes: + - ./infra/mesh/otel-collector.json:/proxy.json:ro + - identity-otel-collector:/identity:ro + - ./secrets/trust:/trust:ro + healthcheck: + disable: true + read_only: true + cap_drop: + - ALL + security_opt: + - no-new-privileges:true + mem_limit: 64m + cpus: 0.2 + pids_limit: 32 + tempo-tls: + image: mtusi-messenger:lab7 + command: + - python + - -m + - src.tls_proxy + network_mode: service:tempo + depends_on: + tempo: + condition: service_started + secret-init: + condition: service_completed_successfully + volumes: + - ./infra/mesh/tempo.json:/proxy.json:ro + - identity-tempo:/identity:ro + - ./secrets/trust:/trust:ro + healthcheck: + disable: true + read_only: true + cap_drop: + - ALL + security_opt: + - no-new-privileges:true + mem_limit: 64m + cpus: 0.2 + pids_limit: 32 + loki-tls: + image: mtusi-messenger:lab7 + command: + - python + - -m + - src.tls_proxy + network_mode: service:loki + depends_on: + loki: + condition: service_started + secret-init: + condition: service_completed_successfully + volumes: + - ./infra/mesh/loki.json:/proxy.json:ro + - identity-loki:/identity:ro + - ./secrets/trust:/trust:ro + healthcheck: + disable: true + read_only: true + cap_drop: + - ALL + security_opt: + - no-new-privileges:true + mem_limit: 64m + cpus: 0.2 + pids_limit: 32 + prometheus-tls: + image: mtusi-messenger:lab7 + command: + - python + - -m + - src.tls_proxy + network_mode: service:prometheus + depends_on: + prometheus: + condition: service_started + secret-init: + condition: service_completed_successfully + volumes: + - ./infra/mesh/prometheus.json:/proxy.json:ro + - identity-prometheus:/identity:ro + - ./secrets/trust:/trust:ro + healthcheck: + disable: true + read_only: true + cap_drop: + - ALL + security_opt: + - no-new-privileges:true + mem_limit: 64m + cpus: 0.2 + pids_limit: 32 + worker-tls: + image: mtusi-messenger:lab7 + command: + - python + - -m + - src.tls_proxy + network_mode: service:worker + depends_on: + worker: + condition: service_started + secret-init: + condition: service_completed_successfully + volumes: + - ./infra/mesh/worker.json:/proxy.json:ro + - identity-worker:/identity:ro + - ./secrets/trust:/trust:ro + healthcheck: + disable: true + read_only: true + cap_drop: + - ALL + security_opt: + - no-new-privileges:true + mem_limit: 64m + cpus: 0.2 + pids_limit: 32 + dispatcher-tls: + image: mtusi-messenger:lab7 + command: + - python + - -m + - src.tls_proxy + network_mode: service:dispatcher + depends_on: + dispatcher: + condition: service_started + secret-init: + condition: service_completed_successfully + volumes: + - ./infra/mesh/dispatcher.json:/proxy.json:ro + - identity-dispatcher:/identity:ro + - ./secrets/trust:/trust:ro + healthcheck: + disable: true + read_only: true + cap_drop: + - ALL + security_opt: + - no-new-privileges:true + mem_limit: 64m + cpus: 0.2 + pids_limit: 32 + reconciler-tls: + image: mtusi-messenger:lab7 + command: + - python + - -m + - src.tls_proxy + network_mode: service:reconciler + depends_on: + reconciler: + condition: service_started + secret-init: + condition: service_completed_successfully + volumes: + - ./infra/mesh/reconciler.json:/proxy.json:ro + - identity-reconciler:/identity:ro + - ./secrets/trust:/trust:ro + healthcheck: + disable: true + read_only: true + cap_drop: + - ALL + security_opt: + - no-new-privileges:true + mem_limit: 64m + cpus: 0.2 + pids_limit: 32 + grafana-tls: + image: mtusi-messenger:lab7 + command: + - python + - -m + - src.tls_proxy + network_mode: service:grafana + depends_on: + grafana: + condition: service_started + secret-init: + condition: service_completed_successfully + volumes: + - ./infra/mesh/grafana.json:/proxy.json:ro + - identity-grafana:/identity:ro + - ./secrets/trust:/trust:ro + healthcheck: + disable: true + read_only: true + cap_drop: + - ALL + security_opt: + - no-new-privileges:true + mem_limit: 64m + cpus: 0.2 + pids_limit: 32 + storage-init: + image: mtusi-messenger:lab7 + network_mode: service:s3 + env_file: .env.storage-admin + command: + - python + - -m + - src.bootstrap_storage + profiles: + - operator + healthcheck: + disable: true + read_only: true + cap_drop: + - ALL + security_opt: + - no-new-privileges:true + mem_limit: 128m + cpus: 0.5 + volumes: [] + secret-init: + image: mtusi-messenger:lab7 + user: 0:0 + command: + - python + - -m + - src.secret_mounts + read_only: true + cap_drop: + - ALL + cap_add: + - CHOWN + - FOWNER + - DAC_OVERRIDE + security_opt: + - no-new-privileges:true + mem_limit: 64m + cpus: 0.5 + pids_limit: 32 + healthcheck: + disable: true + volumes: + - ./secrets/cache.conf:/source/cache.conf:ro + - ./secrets/broker.conf:/source/broker.conf:ro + - ./secrets/s3.json:/source/s3.json:ro + - ./secrets/grafana-password:/source/grafana-password:ro + - identity-grafana:/output/grafana + - identity-reconciler:/output/reconciler + - identity-dispatcher:/output/dispatcher + - identity-worker:/output/worker + - identity-lb:/output/lb + - identity-api1:/output/api1 + - identity-api2:/output/api2 + - identity-openbao:/output/openbao + - identity-db:/output/db + - identity-s3:/output/s3 + - identity-cache:/output/cache + - identity-broker:/output/broker + - identity-otel-collector:/output/otel-collector + - identity-tempo:/output/tempo + - identity-loki:/output/loki + - identity-prometheus:/output/prometheus + - config-s3:/configs/s3 + - config-cache:/configs/cache + - config-broker:/configs/broker + - config-grafana:/configs/grafana + - ./secrets/identities/grafana:/source/identities/grafana:ro + - ./secrets/identities/reconciler:/source/identities/reconciler:ro + - ./secrets/identities/dispatcher:/source/identities/dispatcher:ro + - ./secrets/identities/worker:/source/identities/worker:ro + - ./secrets/identities/lb:/source/identities/lb:ro + - ./secrets/identities/api1:/source/identities/api1:ro + - ./secrets/identities/api2:/source/identities/api2:ro + - ./secrets/identities/openbao:/source/identities/openbao:ro + - ./secrets/identities/db:/source/identities/db:ro + - ./secrets/identities/s3:/source/identities/s3:ro + - ./secrets/identities/cache:/source/identities/cache:ro + - ./secrets/identities/broker:/source/identities/broker:ro + - ./secrets/identities/otel-collector:/source/identities/otel-collector:ro + - ./secrets/identities/tempo:/source/identities/tempo:ro + - ./secrets/identities/loki:/source/identities/loki:ro + - ./secrets/identities/prometheus:/source/identities/prometheus:ro + security-check: + image: mtusi-messenger:lab7 + profiles: + - operator + user: 0:0 + read_only: true + cap_drop: + - ALL + cap_add: + - DAC_READ_SEARCH + security_opt: + - no-new-privileges:true + mem_limit: 128m + cpus: 0.5 + pids_limit: 32 + healthcheck: + disable: true + volumes: + - ./secrets/identities:/audit-identities:ro + - ./secrets/trust:/trust:ro + - ./checks:/checks:ro + - ./infra/mesh:/mesh:ro + command: + - python + - /checks/tls_matrix.py +volumes: + grafanadata: null + prometheusdata: null + lokidata: null + tempodata: null + pgdata: null + s3data: null + brokerdata: null + baodata: null + identity-grafana: {} + identity-reconciler: {} + identity-dispatcher: {} + identity-worker: {} + identity-lb: {} + identity-api1: {} + identity-api2: {} + identity-openbao: {} + identity-db: {} + identity-s3: {} + identity-cache: {} + identity-broker: {} + identity-otel-collector: {} + identity-tempo: {} + identity-loki: {} + identity-prometheus: {} + config-s3: {} + config-cache: {} + config-broker: {} + config-grafana: {} diff --git a/contracts/trust-matrix.md b/contracts/trust-matrix.md index 0c2a977..c19b4bb 100644 --- a/contracts/trust-matrix.md +++ b/contracts/trust-matrix.md @@ -1,37 +1,47 @@ -# Матрица доверия — заполнить в решении lab7 +# Матрица доверия реализации ЛР7 -Это обязательная матрица покрытия. Для каждой строки укажите реальный порт, endpoint, CA, service identity, проверку SAN/ACL, срок жизни credentials и команду положительного/отрицательного теста. TLS шифрует и подтверждает сервер; mTLS также проверяет клиента. При доверенном CA всё равно нужно ограничивать разрешённую identity. Plaintext hop допустим только внутри закрытого локального transport/proxy boundary, без опубликованного обхода; границу и rationale нужно доказать. +Обозначения: mTLS = TLS >=1.2 с CA, hostname/SAN сервера, обязательным клиентским +cert и точным SAN allowlist. CA общий, identity/key отдельны для каждой роли. +Полные allowlist/порты в `infra/mesh/*.json`; ниже перечислены все сетевые hops. +Внешние порты привязаны только к 127.0.0.1 хоста, внутренние не публикуются. -| Связь | Минимум на 3 | Дополнительно на 4 | Доказательство / конфиг | +| Связь | Transport / проверяемая identity | Прикладные права | Доказательство | | --- | --- | --- | --- | -| Клиент → ingress/LB | TLS, CA + hostname, Bearer | Проверка expiry/revocation сессии и общего login rate limit | TODO | -| LB → API (все реплики) | mTLS + allowlist LB identity | Ротация leaf без обхода проверки | TODO | -| API/worker → PostgreSQL | TLS verify-full + раздельные ограниченные DB roles | Ротация credentials; mTLS — допустимое усиление | TODO | -| API/worker → S3 | TLS + разные scoped credentials/prefix rights | Проверка denied prefix и ротация | TODO | -| API/worker → broker | TLS + разные producer/consumer identities и ACL | mTLS + ограничение допустимых SAN/ролей | TODO | -| API/worker → Collector | TLS; сеть/аутентификация запрещает произвольный ingest | mTLS с раздельными identities | TODO | -| Collector → telemetry backends | TLS + scoped backend credentials или mTLS | Ротация и проверка least privilege | TODO | -| Grafana → data sources | TLS с проверкой сервера, ограниченная identity | Отрицательные проверки доступа | TODO | -| API/worker/agent → OpenBao | TLS + сервисный auth + scoped policy | Renewal/expiry/revocation | TODO | -| Оператор → OpenBao/Grafana/S3 admin | TLS + authentication, доступ локальный/через защищённый канал | Разделение operator/application roles | TODO | -| API → Redis/Valkey, если используется | TLS + ACL/пароль с минимальными правами | Ротация; mTLS по возможности | TODO | -| Replication/кластерные каналы, если добавлены | TLS/mTLS либо подтверждённый шифрованный transport | Проверка заявленной модели отказа | TODO | +| Клиент → LB:8443 | Native TLS, SAN localhost/127.0.0.1, клиент доверяет локальному CA | Basic только login; Bearer для business API | tests/smoke.py, tests/security.py | +| LB → api1/api2:8443 | mTLS, server SAN api1/api2, client SAN только lb | API:8080 только loopback | tls_matrix, no-cert/foreign-CA/wrong-SAN/expiry/revoke/plaintext | +| API/worker/dispatcher/reconciler → db:8443 | mTLS, SAN db, отдельные client SAN; operator для диагностики | SCRAM; отдельные PostgreSQL roles, не superuser; `database_operator.py` GRANT | tls_matrix, worker_rights, compromised_worker | +| API/worker/reconciler → s3:8443 | mTLS, SAN s3, соответствующие client SAN; dispatcher запрещён | SigV4 credentials отдельно. API: Read originals/variants, Write staging. Worker: Read/Write staging/originals/variants. Reconciler дополнительно List bucket | tls_matrix, worker_rights, public upload | +| worker/dispatcher → broker:8443 | mTLS, SAN broker, client worker/dispatcher; operator diagnostic | Valkey ACL: worker consume/ack/claim; dispatcher publish; только attachment-jobs | tls_matrix, worker_rights | +| api1/api2 → cache:8443 | mTLS, SAN cache, client api1/api2 | Именованные ACL GET/SET user:*; TTL 60s; truth в PostgreSQL | tls_matrix + smoke | +| API/worker/dispatcher/reconciler → otel-collector:8443 | mTLS, SAN otel-collector, allowlist этих identities | OTLP HTTP; без body/Authorization в telemetry. Cleanup пока не испускает сигналы, роль зарезервирована | tls_matrix, telemetry_security | +| Collector → tempo:8443 / loki:8443 | mTLS, server SAN tempo/loki; client otel-collector | OTLP; внутренние native backends без отдельного auth, authorizer TLS sidecar | tls_matrix, telemetry_security | +| Prometheus → collector:8444/8445 | mTLS, client prometheus; server otel-collector | Scrape application/exporter metrics, оба native listeners loopback | tls_matrix + telemetry_security | +| Grafana → prometheus:8443, loki:8443, tempo:8444 | mTLS, client grafana; отдельный server SAN | Queries через loopback outgoing tunnel; нет публичного доступа к backend | tls_matrix + telemetry_security | +| Service supervisor → OpenBao:8200 | Native mTLS; server SAN openbao; cert auth role требует SAN service-name | read только secret/data/role, token TTL/maxTTL 120s, re-auth 20s, revoke-self после чтения | bao_policy, sealed_bao | +| Оператор → OpenBao:127.0.0.1:8200 | Native mTLS operator + root token только для provision/seal | Init/unseal вручную с защищёнными локальными shares | bao_operator, restart-processes | +| Оператор → Grafana:127.0.0.1:3000 | Native HTTPS, SAN localhost/127.0.0.1 + уникальный admin password | Только локальный административный интерфейс | hardening audit / HTTPS login page | +| storage-init → S3 admin | Только loopback в namespace S3, одноразовый operator profile, собственного внешнего hop нет | Admin credential из отдельного локального файла, runtime его не получает | up.py private bucket bootstrap | +| database_operator → PostgreSQL | docker exec, Unix socket внутри DB, не сетевой hop | operator messenger role; socket не расшарен | миграции + сравнение privileged/scoped в track1 | +| secret-init → runtime secret volumes | Локальные mounts, одноразовый operator-owned процесс | Только service cert/config, chmod/chown; CA/unseal/root отсутствуют | hardening audit | +| Healthchecks | API/DB native loopback/Unix; LB → API по mTLS | /health/ready без секретов; public endpoint через LB HTTPS | smoke, verify_public | +| Репликация/кластер | N/A: single PostgreSQL, S3, broker, Bao raft node | Нет межузловых replication hops; HA dependencies не заявляется | compose.yaml | -Нет выбранного компонента — отметьте N/A с причиной, а не оставляйте пустую строку. Внутренний публичный health listener, если нужен, минимален и изолирован; через него нельзя обращаться к бизнес-API без mTLS. Отдельно задокументируйте scrape/health/bootstrap каналы: они тоже не должны создавать обход. +Каждый TLS proxy имеет только свой identity volume и публичный trust bundle. +Native plaintext слушает только loopback общей namespace с proxy; iptables и +«внутренняя сеть» не заменяют проверку SAN. Сетевые payloads в proxy не логируются. +Контекст TLS кэшируется максимум 1s; соединение максимум 60s, TLS tickets на +server proxy отключены. Отзыв нового подключения применяется <=1s, действующей +связи <=61s; эксперимент также завершает старые worker DB sessions. Native +HAProxy/OpenBao/Grafana перечитывают cert/config при restart/reload. CRL cert-auth +OpenBao отдельно публикуется `bao_operator.py publish-crl`. -## Обязательные отрицательные проверки +Отрицательные тесты не считают timeout/connection-refused правильным TLS отказом: +сначала положительно проверяется каждая разрешённая связь. В `bao_policy` допускается +именно SSL alert или HTTP deny, а не произвольная сетевая ошибка. Для API ACL, +OpenBao policy и прав backend есть отдельные прикладные тесты. -1. HTTPS с правильным CA/hostname проходит; с пустым/чужим CA и неправильным hostname — ошибка верификации, не «сервер недоступен». -2. LB→API: без client cert, с cert чужого CA, с запрещённой identity от доверенного CA — отказ; с разрешённой LB identity — успех. -3. На 4 повторите набор для broker и Collector; ограничение на network policy не заменяет проверку identity. -4. Пользователь вне чата не читает metadata/content и не прикрепляет чужой файл; поддельный X-User-Id не меняет Bearer identity. -5. OpenBao app policy читает только свой secret/path; запись policy и чтение чужого path запрещены. Worker не получает admin credentials API/БД/S3. -6. На 4 отзовите secret/cert и дождитесь контролируемого эффекта с учётом действующих соединений, TLS resumption и cache/TTL. Покажите новое подключение, иначе тест отзыва может ничего не проверить. - -## Bootstrap и эксплуатация - -В репозитории только открытые конфиги, policy templates и scripts. CA private key, leaf keys, root token, unseal shares и SecretID не коммитятся, не запекаются в образ и не печатаются в отчёте. Для локального стенда оператор создаёт их вне Git и передаёт через files/secrets с ограниченными правами. Опишите, кто имеет доступ к CA/unseal, что нужно после рестарта OpenBao и как восстановить работу. - -OpenBao не использует dev-mode. Выберите persistent storage и auth метод (например AppRole с короткоживущим SecretID/response wrapping, cert auth или иная обоснованная identity). Не подменяйте root token постоянной переменной BAO_TOKEN в приложении. Рабочие tokens имеют policy, TTL и renewal/re-auth сценарий. Статические KV secrets на 3 допустимы при реальном чтении через сервисную identity; динамические DB credentials — хорошее расширение, но не обязательное название технологии. - -Разрешённый компромисс учебного стенда: ручной operator init/unseal, если он безопасно документирован и не нужен при каждом обычном рестарте API. Автоматическое хранение всех unseal shares рядом с OpenBao без защиты не считается решённым bootstrap. +Root token/unseal shares/CA private key — только защищённые `secrets/operator` +на хосте, вне Git/image/container mounts. Static KV passwords не получают +автоматический backend TTL: supervisor прекращает их использование после +истечения локального бюджета, а украденные passwords отзываются ротацией. +Роли SQL/Valkey/S3 и доступы не объединяются общим service credential. diff --git a/evidence/bao-policy.json b/evidence/bao-policy.json new file mode 100644 index 0000000..624a1df --- /dev/null +++ b/evidence/bao-policy.json @@ -0,0 +1,65 @@ +{ + "passed": true, + "results": [ + { + "role": "api1", + "own_secret": 200, + "other_secret": 403, + "admin": 403, + "TTL": 120, + "wrong_role_denied": true + }, + { + "role": "api2", + "own_secret": 200, + "other_secret": 403, + "admin": 403, + "TTL": 120, + "wrong_role_denied": true + }, + { + "role": "worker", + "own_secret": 200, + "other_secret": 403, + "admin": 403, + "TTL": 120, + "wrong_role_denied": true + }, + { + "role": "dispatcher", + "own_secret": 200, + "other_secret": 403, + "admin": 403, + "TTL": 120, + "wrong_role_denied": true + }, + { + "role": "reconciler", + "own_secret": 200, + "other_secret": 403, + "admin": 403, + "TTL": 120, + "wrong_role_denied": true + }, + { + "identity": null, + "login_denied": true + }, + { + "identity": "outsider", + "login_denied": true + }, + { + "identity": "revoked", + "login_denied": true + }, + { + "identity": "expired", + "login_denied": true + }, + { + "identity": "alien", + "login_denied": true + } + ] +} diff --git a/evidence/check_contract.txt b/evidence/check_contract.txt new file mode 100644 index 0000000..b62af9c --- /dev/null +++ b/evidence/check_contract.txt @@ -0,0 +1 @@ +PASS: offline skeleton structure, local refs and Python syntax; application NOT tested. diff --git a/evidence/clean-clone.json b/evidence/clean-clone.json new file mode 100644 index 0000000..135e139 --- /dev/null +++ b/evidence/clean-clone.json @@ -0,0 +1,14 @@ +{ + "passed": true, + "completed_at_UTC": "2026-11-13T10:00:37.671336+00:00", + "source_commit": "0bf1ff93c71a6a8cf16edeceefc3b3fab8d23261", + "isolated_clone": true, + "own_venv": true, + "fresh_PKI_and_secrets": true, + "fresh_compose_volumes": true, + "public_suite": "PASS; 3 real SIGKILL scenarios cover 2 distinct API containers", + "security_suite": "PASS; all 11 stages", + "app_image_tested": "sha256:5d549e32c6a790e783550782db9b5c5993861fa5e7dac46039aaa9adb03e2eed", + "host": "Windows 10, Docker Desktop 4.39 / Engine 28 / Compose 2.33, WSL2 4 CPU / 3 GiB RAM / 4 GiB swap", + "scan_scope": "image-audit.json is the 12 November scan, preceding the TLS scheduling code fix; dependencies unchanged. It is not a scan of the exact app image above." +} diff --git a/evidence/compromised-worker-run.txt b/evidence/compromised-worker-run.txt new file mode 100644 index 0000000..62baf91 --- /dev/null +++ b/evidence/compromised-worker-run.txt @@ -0,0 +1 @@ +PASS: revoked worker -> queue preserved -> new cert/DB secret -> 3/3 jobs and hashes intact diff --git a/evidence/compromised-worker.json b/evidence/compromised-worker.json new file mode 100644 index 0000000..5d4f6c9 --- /dev/null +++ b/evidence/compromised-worker.json @@ -0,0 +1,28 @@ +{ + "passed": true, + "baseline": { + "legacy_admin_can_read_sessions": true, + "scoped_worker_denied": [ + "sessions", + "password_hashes", + "messages", + "DDL", + "role_admin", + "foreign_S3_prefix", + "bucket_admin", + "queue_publish", + "queue_admin" + ] + }, + "revoked_serial": "296803757360939619598658580576779705066316270051", + "new_serial": "582892826110773913646976171481035976112843893487", + "revoked_certificate_denied": true, + "revoked_Bao_auth_denied": true, + "rotated_old_DB_password_denied": true, + "queued_during_revocation": 3, + "completed_after_rotation": 3, + "distinct_jobs": 3, + "content_SHA256_preserved": true, + "image_unchanged": true, + "total_seconds": 35.61 +} diff --git a/evidence/dependency-audit.json b/evidence/dependency-audit.json new file mode 100644 index 0000000..de65d88 --- /dev/null +++ b/evidence/dependency-audit.json @@ -0,0 +1 @@ +{"dependencies": [{"name": "annotated-doc", "version": "0.0.5", "vulns": []}, {"name": "annotated-types", "version": "0.8.0", "vulns": []}, {"name": "anyio", "version": "4.15.1", "vulns": []}, {"name": "argon2-cffi", "version": "25.1.0", "vulns": []}, {"name": "argon2-cffi-bindings", "version": "26.1.0", "vulns": []}, {"name": "boto3", "version": "1.43.114", "vulns": []}, {"name": "botocore", "version": "1.43.114", "vulns": []}, {"name": "certifi", "version": "2026.10.23", "vulns": []}, {"name": "cffi", "version": "2.1.1", "vulns": []}, {"name": "charset-normalizer", "version": "3.5.2", "vulns": []}, {"name": "click", "version": "8.5.0", "vulns": []}, {"name": "fastapi", "version": "0.143.2", "vulns": []}, {"name": "googleapis-common-protos", "version": "1.75.5", "vulns": []}, {"name": "h11", "version": "0.16.0", "vulns": []}, {"name": "idna", "version": "3.20", "vulns": []}, {"name": "jmespath", "version": "1.1.0", "vulns": []}, {"name": "opentelemetry-api", "version": "1.45.1", "vulns": []}, {"name": "opentelemetry-exporter-http-transport", "version": "0.66b1", "vulns": []}, {"name": "opentelemetry-exporter-otlp-common", "version": "0.66b1", "vulns": []}, {"name": "opentelemetry-exporter-otlp-proto-common", "version": "1.45.1", "vulns": []}, {"name": "opentelemetry-exporter-otlp-proto-http", "version": "1.45.1", "vulns": []}, {"name": "opentelemetry-proto", "version": "1.45.1", "vulns": []}, {"name": "opentelemetry-sdk", "version": "1.45.1", "vulns": []}, {"name": "opentelemetry-semantic-conventions", "version": "0.66b1", "vulns": []}, {"name": "pillow", "version": "13.0.0", "vulns": []}, {"name": "protobuf", "version": "7.36.2", "vulns": []}, {"name": "psycopg", "version": "3.3.6", "vulns": []}, {"name": "psycopg-binary", "version": "3.3.6", "vulns": []}, {"name": "psycopg-pool", "version": "3.3.3", "vulns": []}, {"name": "pycparser", "version": "3.11", "vulns": []}, {"name": "pydantic", "version": "2.14.1", "vulns": []}, {"name": "pydantic-core", "version": "2.50.1", "vulns": []}, {"name": "python-dateutil", "version": "2.9.0.post0", "vulns": []}, {"name": "redis", "version": "8.1.0", "vulns": []}, {"name": "requests", "version": "2.34.2", "vulns": []}, {"name": "s3transfer", "version": "0.19.2", "vulns": []}, {"name": "six", "version": "1.17.0", "vulns": []}, {"name": "starlette", "version": "1.8.0", "vulns": []}, {"name": "typing-inspection", "version": "0.4.4", "vulns": []}, {"name": "typing-extensions", "version": "4.16.0", "vulns": []}, {"name": "tzdata", "version": "2026.5", "vulns": []}, {"name": "urllib3", "version": "2.8.0", "vulns": []}, {"name": "uvicorn", "version": "0.54.0", "vulns": []}], "fixes": []} diff --git a/evidence/failover-1-process.json b/evidence/failover-1-process.json new file mode 100644 index 0000000..91ebd80 --- /dev/null +++ b/evidence/failover-1-process.json @@ -0,0 +1,11 @@ +{ + "target_instance": "b1a678ea159c4aaea77efbcc38b117e8", + "stopped_container": "0a05a29d377fb35aa4676b597fa301dc1625ccfe208a7edbc6a74794659407b3", + "before_containers": [ + "1570e3cf0bcaf52840456fe4527c951913c184c7a910035c662fd93573f1c1c7", + "0a05a29d377fb35aa4676b597fa301dc1625ccfe208a7edbc6a74794659407b3" + ], + "after_running_containers": [ + "1570e3cf0bcaf52840456fe4527c951913c184c7a910035c662fd93573f1c1c7" + ] +} \ No newline at end of file diff --git a/evidence/failover-1.txt b/evidence/failover-1.txt new file mode 100644 index 0000000..7eb4630 --- /dev/null +++ b/evidence/failover-1.txt @@ -0,0 +1,3 @@ +Executing explicit failover hook; hook output suppressed to avoid leaking secrets. +{"observed_instances_before": 2, "successful_writes": 77, "failed_attempts": 4, "first_recovery_seconds": 3.39} +PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence. diff --git a/evidence/failover-2-process.json b/evidence/failover-2-process.json new file mode 100644 index 0000000..bcea5e9 --- /dev/null +++ b/evidence/failover-2-process.json @@ -0,0 +1,11 @@ +{ + "target_instance": "7f288f373c5140c3a3a1f8de74fa91f2", + "stopped_container": "0a05a29d377fb35aa4676b597fa301dc1625ccfe208a7edbc6a74794659407b3", + "before_containers": [ + "1570e3cf0bcaf52840456fe4527c951913c184c7a910035c662fd93573f1c1c7", + "0a05a29d377fb35aa4676b597fa301dc1625ccfe208a7edbc6a74794659407b3" + ], + "after_running_containers": [ + "1570e3cf0bcaf52840456fe4527c951913c184c7a910035c662fd93573f1c1c7" + ] +} \ No newline at end of file diff --git a/evidence/failover-2.txt b/evidence/failover-2.txt new file mode 100644 index 0000000..0ec51bb --- /dev/null +++ b/evidence/failover-2.txt @@ -0,0 +1,3 @@ +Executing explicit failover hook; hook output suppressed to avoid leaking secrets. +{"observed_instances_before": 2, "successful_writes": 83, "failed_attempts": 4, "first_recovery_seconds": 2.953} +PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence. diff --git a/evidence/failover-3-process.json b/evidence/failover-3-process.json new file mode 100644 index 0000000..f864155 --- /dev/null +++ b/evidence/failover-3-process.json @@ -0,0 +1,11 @@ +{ + "target_instance": "932b533b493e4dab8e09817e66f77901", + "stopped_container": "1570e3cf0bcaf52840456fe4527c951913c184c7a910035c662fd93573f1c1c7", + "before_containers": [ + "1570e3cf0bcaf52840456fe4527c951913c184c7a910035c662fd93573f1c1c7", + "0a05a29d377fb35aa4676b597fa301dc1625ccfe208a7edbc6a74794659407b3" + ], + "after_running_containers": [ + "0a05a29d377fb35aa4676b597fa301dc1625ccfe208a7edbc6a74794659407b3" + ] +} \ No newline at end of file diff --git a/evidence/failover-3.txt b/evidence/failover-3.txt new file mode 100644 index 0000000..08847ea --- /dev/null +++ b/evidence/failover-3.txt @@ -0,0 +1,3 @@ +Executing explicit failover hook; hook output suppressed to avoid leaking secrets. +{"observed_instances_before": 2, "successful_writes": 79, "failed_attempts": 4, "first_recovery_seconds": 2.61} +PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence. diff --git a/evidence/generate-test-identities.txt b/evidence/generate-test-identities.txt new file mode 100644 index 0000000..d5326fe --- /dev/null +++ b/evidence/generate-test-identities.txt @@ -0,0 +1 @@ +Negative test identities generated diff --git a/evidence/hardening-run.txt b/evidence/hardening-run.txt new file mode 100644 index 0000000..90d839c --- /dev/null +++ b/evidence/hardening-run.txt @@ -0,0 +1 @@ +PASS: runtime privileges/resource limits/mounts/public ports and loopback-only plaintext diff --git a/evidence/hardening.json b/evidence/hardening.json new file mode 100644 index 0000000..04995d0 --- /dev/null +++ b/evidence/hardening.json @@ -0,0 +1,502 @@ +{ + "passed": true, + "runtime": [ + { + "service": "api1", + "user": "10001:10001", + "read_only": true, + "cap_drop": [ + "ALL" + ], + "memory_bytes": 536870912, + "NanoCpus": 500000000, + "pids_limit": 64, + "published_loopback_ports": [], + "operator_material_absent": true + }, + { + "service": "api1-tls", + "user": "10001:10001", + "read_only": true, + "cap_drop": [ + "ALL" + ], + "memory_bytes": 67108864, + "NanoCpus": 200000000, + "pids_limit": 32, + "published_loopback_ports": [], + "operator_material_absent": true + }, + { + "service": "api2", + "user": "10001:10001", + "read_only": true, + "cap_drop": [ + "ALL" + ], + "memory_bytes": 536870912, + "NanoCpus": 500000000, + "pids_limit": 64, + "published_loopback_ports": [], + "operator_material_absent": true + }, + { + "service": "api2-tls", + "user": "10001:10001", + "read_only": true, + "cap_drop": [ + "ALL" + ], + "memory_bytes": 67108864, + "NanoCpus": 200000000, + "pids_limit": 32, + "published_loopback_ports": [], + "operator_material_absent": true + }, + { + "service": "broker", + "user": "999:1000", + "read_only": true, + "cap_drop": [ + "ALL" + ], + "memory_bytes": 134217728, + "NanoCpus": 250000000, + "pids_limit": 128, + "published_loopback_ports": [], + "operator_material_absent": true + }, + { + "service": "broker-tls", + "user": "10001:10001", + "read_only": true, + "cap_drop": [ + "ALL" + ], + "memory_bytes": 67108864, + "NanoCpus": 200000000, + "pids_limit": 32, + "published_loopback_ports": [], + "operator_material_absent": true + }, + { + "service": "cache", + "user": "999:1000", + "read_only": true, + "cap_drop": [ + "ALL" + ], + "memory_bytes": 67108864, + "NanoCpus": 250000000, + "pids_limit": 128, + "published_loopback_ports": [], + "operator_material_absent": true + }, + { + "service": "cache-tls", + "user": "10001:10001", + "read_only": true, + "cap_drop": [ + "ALL" + ], + "memory_bytes": 67108864, + "NanoCpus": 200000000, + "pids_limit": 32, + "published_loopback_ports": [], + "operator_material_absent": true + }, + { + "service": "db", + "user": "999:999", + "read_only": true, + "cap_drop": [ + "ALL" + ], + "memory_bytes": 268435456, + "NanoCpus": 1000000000, + "pids_limit": 128, + "published_loopback_ports": [], + "operator_material_absent": true + }, + { + "service": "db-tls", + "user": "10001:10001", + "read_only": true, + "cap_drop": [ + "ALL" + ], + "memory_bytes": 67108864, + "NanoCpus": 200000000, + "pids_limit": 32, + "published_loopback_ports": [], + "operator_material_absent": true + }, + { + "service": "dispatcher", + "user": "10001:10001", + "read_only": true, + "cap_drop": [ + "ALL" + ], + "memory_bytes": 134217728, + "NanoCpus": 250000000, + "pids_limit": 64, + "published_loopback_ports": [], + "operator_material_absent": true + }, + { + "service": "dispatcher-tls", + "user": "10001:10001", + "read_only": true, + "cap_drop": [ + "ALL" + ], + "memory_bytes": 67108864, + "NanoCpus": 200000000, + "pids_limit": 32, + "published_loopback_ports": [], + "operator_material_absent": true + }, + { + "service": "grafana", + "user": "472", + "read_only": true, + "cap_drop": [ + "ALL" + ], + "memory_bytes": 536870912, + "NanoCpus": 1000000000, + "pids_limit": 128, + "published_loopback_ports": [ + "3000" + ], + "operator_material_absent": true + }, + { + "service": "grafana-tls", + "user": "10001:10001", + "read_only": true, + "cap_drop": [ + "ALL" + ], + "memory_bytes": 67108864, + "NanoCpus": 200000000, + "pids_limit": 32, + "published_loopback_ports": [], + "operator_material_absent": true + }, + { + "service": "lb", + "user": "10001:10001", + "read_only": true, + "cap_drop": [ + "ALL" + ], + "memory_bytes": 67108864, + "NanoCpus": 500000000, + "pids_limit": 128, + "published_loopback_ports": [ + "8443" + ], + "operator_material_absent": true + }, + { + "service": "loki", + "user": "10001", + "read_only": true, + "cap_drop": [ + "ALL" + ], + "memory_bytes": 268435456, + "NanoCpus": 500000000, + "pids_limit": 128, + "published_loopback_ports": [], + "operator_material_absent": true + }, + { + "service": "loki-tls", + "user": "10001:10001", + "read_only": true, + "cap_drop": [ + "ALL" + ], + "memory_bytes": 67108864, + "NanoCpus": 200000000, + "pids_limit": 32, + "published_loopback_ports": [], + "operator_material_absent": true + }, + { + "service": "openbao", + "user": "10001:10001", + "read_only": true, + "cap_drop": [ + "ALL" + ], + "memory_bytes": 268435456, + "NanoCpus": 500000000, + "pids_limit": 128, + "published_loopback_ports": [ + "8200" + ], + "operator_material_absent": true + }, + { + "service": "otel-collector", + "user": "10001:10001", + "read_only": true, + "cap_drop": [ + "ALL" + ], + "memory_bytes": 268435456, + "NanoCpus": 500000000, + "pids_limit": 128, + "published_loopback_ports": [], + "operator_material_absent": true + }, + { + "service": "otel-collector-tls", + "user": "10001:10001", + "read_only": true, + "cap_drop": [ + "ALL" + ], + "memory_bytes": 67108864, + "NanoCpus": 200000000, + "pids_limit": 32, + "published_loopback_ports": [], + "operator_material_absent": true + }, + { + "service": "prometheus", + "user": "nobody", + "read_only": true, + "cap_drop": [ + "ALL" + ], + "memory_bytes": 268435456, + "NanoCpus": 500000000, + "pids_limit": 128, + "published_loopback_ports": [], + "operator_material_absent": true + }, + { + "service": "prometheus-tls", + "user": "10001:10001", + "read_only": true, + "cap_drop": [ + "ALL" + ], + "memory_bytes": 67108864, + "NanoCpus": 200000000, + "pids_limit": 32, + "published_loopback_ports": [], + "operator_material_absent": true + }, + { + "service": "reconciler", + "user": "10001:10001", + "read_only": true, + "cap_drop": [ + "ALL" + ], + "memory_bytes": 201326592, + "NanoCpus": 250000000, + "pids_limit": 64, + "published_loopback_ports": [], + "operator_material_absent": true + }, + { + "service": "reconciler-tls", + "user": "10001:10001", + "read_only": true, + "cap_drop": [ + "ALL" + ], + "memory_bytes": 67108864, + "NanoCpus": 200000000, + "pids_limit": 32, + "published_loopback_ports": [], + "operator_material_absent": true + }, + { + "service": "s3", + "user": "1000:1000", + "read_only": true, + "cap_drop": [ + "ALL" + ], + "memory_bytes": 536870912, + "NanoCpus": 1000000000, + "pids_limit": 128, + "published_loopback_ports": [], + "operator_material_absent": true + }, + { + "service": "s3-tls", + "user": "10001:10001", + "read_only": true, + "cap_drop": [ + "ALL" + ], + "memory_bytes": 67108864, + "NanoCpus": 200000000, + "pids_limit": 32, + "published_loopback_ports": [], + "operator_material_absent": true + }, + { + "service": "tempo", + "user": "10001:10001", + "read_only": true, + "cap_drop": [ + "ALL" + ], + "memory_bytes": 268435456, + "NanoCpus": 500000000, + "pids_limit": 128, + "published_loopback_ports": [], + "operator_material_absent": true + }, + { + "service": "tempo-tls", + "user": "10001:10001", + "read_only": true, + "cap_drop": [ + "ALL" + ], + "memory_bytes": 67108864, + "NanoCpus": 200000000, + "pids_limit": 32, + "published_loopback_ports": [], + "operator_material_absent": true + }, + { + "service": "worker", + "user": "10001:10001", + "read_only": true, + "cap_drop": [ + "ALL" + ], + "memory_bytes": 805306368, + "NanoCpus": 1000000000, + "pids_limit": 64, + "published_loopback_ports": [], + "operator_material_absent": true + }, + { + "service": "worker-tls", + "user": "10001:10001", + "read_only": true, + "cap_drop": [ + "ALL" + ], + "memory_bytes": 67108864, + "NanoCpus": 200000000, + "pids_limit": 32, + "published_loopback_ports": [], + "operator_material_absent": true + } + ], + "grafana_verified_HTTPS": true, + "plaintext_isolation": { + "passed": true, + "probes": [ + { + "host": "api1", + "port": 8080, + "refused": true + }, + { + "host": "api2", + "port": 8080, + "refused": true + }, + { + "host": "db", + "port": 5432, + "refused": true + }, + { + "host": "s3", + "port": 8333, + "refused": true + }, + { + "host": "s3", + "port": 8888, + "refused": true + }, + { + "host": "s3", + "port": 9333, + "refused": true + }, + { + "host": "s3", + "port": 19333, + "refused": true + }, + { + "host": "cache", + "port": 6379, + "refused": true + }, + { + "host": "broker", + "port": 6379, + "refused": true + }, + { + "host": "otel-collector", + "port": 4318, + "refused": true + }, + { + "host": "otel-collector", + "port": 9464, + "refused": true + }, + { + "host": "otel-collector", + "port": 8888, + "refused": true + }, + { + "host": "otel-collector", + "port": 13133, + "refused": true + }, + { + "host": "prometheus", + "port": 9090, + "refused": true + }, + { + "host": "loki", + "port": 3100, + "refused": true + }, + { + "host": "loki", + "port": 9095, + "refused": true + }, + { + "host": "tempo", + "port": 3200, + "refused": true + }, + { + "host": "tempo", + "port": 4318, + "refused": true + }, + { + "host": "tempo", + "port": 9095, + "refused": true + } + ] + } +} diff --git a/evidence/image-audit.json b/evidence/image-audit.json new file mode 100644 index 0000000..919ce7f --- /dev/null +++ b/evidence/image-audit.json @@ -0,0 +1,2303 @@ +{ + "at_UTC": "2026-11-12T16:09:52.050386+00:00", + "scanner": "aquasec/trivy@sha256:790fd66d1697395d8693d1acaa1ea702406a20f109b6fc7bac8db623eca6c06c", + "scope": [ + "api1", + "openbao", + "s3", + "lb" + ], + "images": [ + { + "service": "api1", + "image": "mtusi-messenger:lab7", + "image_id": "sha256:b47a7a450bfddd12e8998b5f1f00a3086c80c834c6b6fdabbc5514b497305ae2", + "report_sha256": "b812db7214ca49421508806e36ad552db9c8012718bee37d5927a53f25731228", + "counts": { + "LOW": 66, + "HIGH": 48, + "MEDIUM": 75, + "UNKNOWN": 19 + }, + "findings": [ + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2011-3374", + "PkgName": "apt", + "InstalledVersion": "3.0.4", + "FixedVersion": null, + "Severity": "LOW", + "Title": "It was found that apt-key in apt, all versions, do not correctly valid ...", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2011-3374" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "TEMP-0841856-B18BAF", + "PkgName": "bash", + "InstalledVersion": "5.2.37-2+b10", + "FixedVersion": null, + "Severity": "LOW", + "Title": "[Privilege escalation possible to other user than root]", + "PrimaryURL": "https://security-tracker.debian.org/tracker/TEMP-0841856-B18BAF" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-76642", + "PkgName": "bsdutils", + "InstalledVersion": "1:2.41.5-0+deb13u1", + "FixedVersion": null, + "Severity": "HIGH", + "Title": "util-linux: util-linux: failed external mount helper still runs privileged X-mount post-hooks", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-76642" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-78408", + "PkgName": "bsdutils", + "InstalledVersion": "1:2.41.5-0+deb13u1", + "FixedVersion": null, + "Severity": "HIGH", + "Title": "util-linux: util-linux: nsenter --join-cgroup leaks root cgroup migration authority", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-78408" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-78409", + "PkgName": "bsdutils", + "InstalledVersion": "1:2.41.5-0+deb13u1", + "FixedVersion": null, + "Severity": "HIGH", + "Title": "util-linux: util-linux: X-mount.subdir detached-tree resolution can escape via intermediate symlinks", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-78409" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-78410", + "PkgName": "bsdutils", + "InstalledVersion": "1:2.41.5-0+deb13u1", + "FixedVersion": null, + "Severity": "HIGH", + "Title": "util-linux: util-linux: restricted bind mounts do not pin the source, allowing X-mount.owner/group/mode redirection", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-78410" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-3184", + "PkgName": "bsdutils", + "InstalledVersion": "1:2.41.5-0+deb13u1", + "FixedVersion": null, + "Severity": "MEDIUM", + "Title": "util-linux: util-linux: Access control bypass due to improper hostname canonicalization", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-3184" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2022-0563", + "PkgName": "bsdutils", + "InstalledVersion": "1:2.41.5-0+deb13u1", + "FixedVersion": null, + "Severity": "LOW", + "Title": "util-linux: partial disclosure of arbitrary files in chfn and chsh when compiled with libreadline", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2022-0563" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2017-18018", + "PkgName": "coreutils", + "InstalledVersion": "9.7-3", + "FixedVersion": null, + "Severity": "LOW", + "Title": "coreutils: race condition vulnerability in chown and chgrp", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2017-18018" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2025-5278", + "PkgName": "coreutils", + "InstalledVersion": "9.7-3", + "FixedVersion": null, + "Severity": "LOW", + "Title": "coreutils: Heap Buffer Under-Read in GNU Coreutils sort via Key Specification", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2025-5278" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-56391", + "PkgName": "coreutils", + "InstalledVersion": "9.7-3", + "FixedVersion": null, + "Severity": "LOW", + "Title": "coreutils: GNU coreutils uniq: Denial of Service and information disclosure via out-of-bounds read with multibyte input", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-56391" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-56392", + "PkgName": "coreutils", + "InstalledVersion": "9.7-3", + "FixedVersion": null, + "Severity": "LOW", + "Title": "coreutils: GNU coreutils unexpand: Denial of Service via crafted tab stop values", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-56392" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-102473", + "PkgName": "dash", + "InstalledVersion": "0.5.12-12", + "FixedVersion": null, + "Severity": "LOW", + "Title": "dash: dash: Super-polynomial backtracking in pmatch when libc fnmatch is disabled", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-102473" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-102474", + "PkgName": "dash", + "InstalledVersion": "0.5.12-12", + "FixedVersion": null, + "Severity": "LOW", + "Title": "dash: dash: Heap out-of-bounds write in conv_escape via undersized Unicode escape reservation", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-102474" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-53910", + "PkgName": "diffutils", + "InstalledVersion": "1:3.10-4", + "FixedVersion": null, + "Severity": "LOW", + "Title": "diffutils: heap\u2011based buffer overflow due to multiple signed integer overflows in line\u2011mapping calculations", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-53910" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-102010", + "PkgName": "gcc-14-base", + "InstalledVersion": "14.2.0-19", + "FixedVersion": null, + "Severity": "MEDIUM", + "Title": "gcc-toolset-15-gcc: gcc: gcc-toolset-16: gcc: Denial of Service via use-after-free in binary heap erase_if", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-102010" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-114690", + "PkgName": "gcc-14-base", + "InstalledVersion": "14.2.0-19", + "FixedVersion": null, + "Severity": "MEDIUM", + "Title": "gcc: Confirmed out-of-bounds read/write in libstdc++ parallel `std", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-114690" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-114691", + "PkgName": "gcc-14-base", + "InstalledVersion": "14.2.0-19", + "FixedVersion": null, + "Severity": "MEDIUM", + "Title": "gcc: Integer wrap in `std", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-114691" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-115455", + "PkgName": "gcc-14-base", + "InstalledVersion": "14.2.0-19", + "FixedVersion": null, + "Severity": "MEDIUM", + "Title": "gcc: Stack overflow in std::bitset on libstdc++", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-115455" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-95619", + "PkgName": "gcc-14-base", + "InstalledVersion": "14.2.0-19", + "FixedVersion": null, + "Severity": "MEDIUM", + "Title": "gcc: libstdc++ integer overflow in `new` operator", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-95619" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-115456", + "PkgName": "gcc-14-base", + "InstalledVersion": "14.2.0-19", + "FixedVersion": null, + "Severity": "LOW", + "Title": "gcc: Out-of-bounds read in std::from_chars", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-115456" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-54369", + "PkgName": "libacl1", + "InstalledVersion": "2.3.2-2+b1", + "FixedVersion": null, + "Severity": "HIGH", + "Title": "acl: Symlink traversal privilege escalation via libacl functions", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-54369" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-54370", + "PkgName": "libacl1", + "InstalledVersion": "2.3.2-2+b1", + "FixedVersion": null, + "Severity": "MEDIUM", + "Title": "acl: TOCTOU Symlink Traversal via getfacl/setfacl", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-54370" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2011-3374", + "PkgName": "libapt-pkg7.0", + "InstalledVersion": "3.0.4", + "FixedVersion": null, + "Severity": "LOW", + "Title": "It was found that apt-key in apt, all versions, do not correctly valid ...", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2011-3374" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-54371", + "PkgName": "libattr1", + "InstalledVersion": "1:2.5.2-3", + "FixedVersion": null, + "Severity": "MEDIUM", + "Title": "attr: attr: Symlink Traversal Privilege Escalation via getfattr and setfattr", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-54371" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-76642", + "PkgName": "libblkid1", + "InstalledVersion": "2.41.5-0+deb13u1", + "FixedVersion": null, + "Severity": "HIGH", + "Title": "util-linux: util-linux: failed external mount helper still runs privileged X-mount post-hooks", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-76642" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-78408", + "PkgName": "libblkid1", + "InstalledVersion": "2.41.5-0+deb13u1", + "FixedVersion": null, + "Severity": "HIGH", + "Title": "util-linux: util-linux: nsenter --join-cgroup leaks root cgroup migration authority", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-78408" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-78409", + "PkgName": "libblkid1", + "InstalledVersion": "2.41.5-0+deb13u1", + "FixedVersion": null, + "Severity": "HIGH", + "Title": "util-linux: util-linux: X-mount.subdir detached-tree resolution can escape via intermediate symlinks", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-78409" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-78410", + "PkgName": "libblkid1", + "InstalledVersion": "2.41.5-0+deb13u1", + "FixedVersion": null, + "Severity": "HIGH", + "Title": "util-linux: util-linux: restricted bind mounts do not pin the source, allowing X-mount.owner/group/mode redirection", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-78410" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-3184", + "PkgName": "libblkid1", + "InstalledVersion": "2.41.5-0+deb13u1", + "FixedVersion": null, + "Severity": "MEDIUM", + "Title": "util-linux: util-linux: Access control bypass due to improper hostname canonicalization", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-3184" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2022-0563", + "PkgName": "libblkid1", + "InstalledVersion": "2.41.5-0+deb13u1", + "FixedVersion": null, + "Severity": "LOW", + "Title": "util-linux: partial disclosure of arbitrary files in chfn and chsh when compiled with libreadline", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2022-0563" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-42250", + "PkgName": "libbz2-1.0", + "InstalledVersion": "1.0.8-6", + "FixedVersion": null, + "Severity": "MEDIUM", + "Title": "bzip2: bzip2: Denial of Service in bzip2recover via a specially crafted file", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-42250" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-18374", + "PkgName": "libc-bin", + "InstalledVersion": "2.41-12+deb13u4", + "FixedVersion": null, + "Severity": "MEDIUM", + "Title": "glibc: glibc: Heap buffer overflow via attacker-controlled fopen mode string", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-18374" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-19499", + "PkgName": "libc-bin", + "InstalledVersion": "2.41-12+deb13u4", + "FixedVersion": null, + "Severity": "MEDIUM", + "Title": "glibc: Buffer Overflow in strfmon right-justification padding", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-19499" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-19542", + "PkgName": "libc-bin", + "InstalledVersion": "2.41-12+deb13u4", + "FixedVersion": null, + "Severity": "MEDIUM", + "Title": "glibc: Fix out-of-bounds array write in tdelete", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-19542" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-5435", + "PkgName": "libc-bin", + "InstalledVersion": "2.41-12+deb13u4", + "FixedVersion": null, + "Severity": "MEDIUM", + "Title": "glibc: glibc: Out-of-bounds write via TSIG record processing", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-5435" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-6238", + "PkgName": "libc-bin", + "InstalledVersion": "2.41-12+deb13u4", + "FixedVersion": null, + "Severity": "MEDIUM", + "Title": "glibc: glibc: Application crash or uninitialized memory read via crafted DNS response", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-6238" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-6368", + "PkgName": "libc-bin", + "InstalledVersion": "2.41-12+deb13u4", + "FixedVersion": null, + "Severity": "MEDIUM", + "Title": "glibc: glibc: Process abort due to invalid memory in wordexp", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-6368" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-6791", + "PkgName": "libc-bin", + "InstalledVersion": "2.41-12+deb13u4", + "FixedVersion": null, + "Severity": "MEDIUM", + "Title": "glibc: Glibc: Denial of Service via stack exhaustion during tilde expansion", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-6791" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-77117", + "PkgName": "libc-bin", + "InstalledVersion": "2.41-12+deb13u4", + "FixedVersion": null, + "Severity": "MEDIUM", + "Title": "glibc: Non-progress DoS in SHIFT_JISX0213 ->", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-77117" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-80489", + "PkgName": "libc-bin", + "InstalledVersion": "2.41-12+deb13u4", + "FixedVersion": null, + "Severity": "MEDIUM", + "Title": "glibc: Non-progress DoS in EUC_JISX0213 -> UCS-4 conversion state", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-80489" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-84243", + "PkgName": "libc-bin", + "InstalledVersion": "2.41-12+deb13u4", + "FixedVersion": null, + "Severity": "MEDIUM", + "Title": "glibc: glibc: Arbitrary code execution via directory traversal in LANGUAGE environment variable", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-84243" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-8674", + "PkgName": "libc-bin", + "InstalledVersion": "2.41-12+deb13u4", + "FixedVersion": null, + "Severity": "MEDIUM", + "Title": "glibc: glibc DNS stub resolver: Denial of Service via long search domain in configuration", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-8674" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-86805", + "PkgName": "libc-bin", + "InstalledVersion": "2.41-12+deb13u4", + "FixedVersion": null, + "Severity": "MEDIUM", + "Title": "glibc: glibc: Privilege escalation and arbitrary code execution via TOCTOU race condition in dynamic loader", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-86805" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-89092", + "PkgName": "libc-bin", + "InstalledVersion": "2.41-12+deb13u4", + "FixedVersion": null, + "Severity": "MEDIUM", + "Title": "glibc: nscd stack overflow leads to degraded DNS resolution", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-89092" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-95818", + "PkgName": "libc-bin", + "InstalledVersion": "2.41-12+deb13u4", + "FixedVersion": null, + "Severity": "MEDIUM", + "Title": "glibc: glibc: Local attacker can cause denial of service and information disclosure via stack-based buffer overflow.", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-95818" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2010-4756", + "PkgName": "libc-bin", + "InstalledVersion": "2.41-12+deb13u4", + "FixedVersion": null, + "Severity": "LOW", + "Title": "glibc: glob implementation can cause excessive CPU and memory consumption due to crafted glob expressions", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2010-4756" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2018-20796", + "PkgName": "libc-bin", + "InstalledVersion": "2.41-12+deb13u4", + "FixedVersion": null, + "Severity": "LOW", + "Title": "glibc: uncontrolled recursion in function check_dst_limits_calc_pos_1 in posix/regexec.c", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2018-20796" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2019-1010022", + "PkgName": "libc-bin", + "InstalledVersion": "2.41-12+deb13u4", + "FixedVersion": null, + "Severity": "LOW", + "Title": "glibc: stack guard protection bypass", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2019-1010022" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2019-1010023", + "PkgName": "libc-bin", + "InstalledVersion": "2.41-12+deb13u4", + "FixedVersion": null, + "Severity": "LOW", + "Title": "glibc: running ldd on malicious ELF leads to code execution because of wrong size computation", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2019-1010023" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2019-1010024", + "PkgName": "libc-bin", + "InstalledVersion": "2.41-12+deb13u4", + "FixedVersion": null, + "Severity": "LOW", + "Title": "glibc: ASLR bypass using cache of thread stack and heap", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2019-1010024" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2019-1010025", + "PkgName": "libc-bin", + "InstalledVersion": "2.41-12+deb13u4", + "FixedVersion": null, + "Severity": "LOW", + "Title": "glibc: information disclosure of heap addresses of pthread_created thread", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2019-1010025" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2019-9192", + "PkgName": "libc-bin", + "InstalledVersion": "2.41-12+deb13u4", + "FixedVersion": null, + "Severity": "LOW", + "Title": "glibc: uncontrolled recursion in function check_dst_limits_calc_pos_1 in posix/regexec.c", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2019-9192" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-97399", + "PkgName": "libc-bin", + "InstalledVersion": "2.41-12+deb13u4", + "FixedVersion": null, + "Severity": "LOW", + "Title": "glibc: glibc: Denial of Service via out-of-bounds read in strncasecmp", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-97399" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-100290", + "PkgName": "libc-bin", + "InstalledVersion": "2.41-12+deb13u4", + "FixedVersion": null, + "Severity": "UNKNOWN", + "Title": "The regcomp and regexec functions in the GNU C Library version 2.3 to ...", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-100290" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-115819", + "PkgName": "libc-bin", + "InstalledVersion": "2.41-12+deb13u4", + "FixedVersion": null, + "Severity": "UNKNOWN", + "Title": "Calling the wide scanf family of functions (swscanf, fwscanf, wscanf, ...", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-115819" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-18374", + "PkgName": "libc6", + "InstalledVersion": "2.41-12+deb13u4", + "FixedVersion": null, + "Severity": "MEDIUM", + "Title": "glibc: glibc: Heap buffer overflow via attacker-controlled fopen mode string", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-18374" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-19499", + "PkgName": "libc6", + "InstalledVersion": "2.41-12+deb13u4", + "FixedVersion": null, + "Severity": "MEDIUM", + "Title": "glibc: Buffer Overflow in strfmon right-justification padding", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-19499" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-19542", + "PkgName": "libc6", + "InstalledVersion": "2.41-12+deb13u4", + "FixedVersion": null, + "Severity": "MEDIUM", + "Title": "glibc: Fix out-of-bounds array write in tdelete", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-19542" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-5435", + "PkgName": "libc6", + "InstalledVersion": "2.41-12+deb13u4", + "FixedVersion": null, + "Severity": "MEDIUM", + "Title": "glibc: glibc: Out-of-bounds write via TSIG record processing", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-5435" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-6238", + "PkgName": "libc6", + "InstalledVersion": "2.41-12+deb13u4", + "FixedVersion": null, + "Severity": "MEDIUM", + "Title": "glibc: glibc: Application crash or uninitialized memory read via crafted DNS response", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-6238" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-6368", + "PkgName": "libc6", + "InstalledVersion": "2.41-12+deb13u4", + "FixedVersion": null, + "Severity": "MEDIUM", + "Title": "glibc: glibc: Process abort due to invalid memory in wordexp", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-6368" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-6791", + "PkgName": "libc6", + "InstalledVersion": "2.41-12+deb13u4", + "FixedVersion": null, + "Severity": "MEDIUM", + "Title": "glibc: Glibc: Denial of Service via stack exhaustion during tilde expansion", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-6791" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-77117", + "PkgName": "libc6", + "InstalledVersion": "2.41-12+deb13u4", + "FixedVersion": null, + "Severity": "MEDIUM", + "Title": "glibc: Non-progress DoS in SHIFT_JISX0213 ->", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-77117" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-80489", + "PkgName": "libc6", + "InstalledVersion": "2.41-12+deb13u4", + "FixedVersion": null, + "Severity": "MEDIUM", + "Title": "glibc: Non-progress DoS in EUC_JISX0213 -> UCS-4 conversion state", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-80489" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-84243", + "PkgName": "libc6", + "InstalledVersion": "2.41-12+deb13u4", + "FixedVersion": null, + "Severity": "MEDIUM", + "Title": "glibc: glibc: Arbitrary code execution via directory traversal in LANGUAGE environment variable", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-84243" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-8674", + "PkgName": "libc6", + "InstalledVersion": "2.41-12+deb13u4", + "FixedVersion": null, + "Severity": "MEDIUM", + "Title": "glibc: glibc DNS stub resolver: Denial of Service via long search domain in configuration", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-8674" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-86805", + "PkgName": "libc6", + "InstalledVersion": "2.41-12+deb13u4", + "FixedVersion": null, + "Severity": "MEDIUM", + "Title": "glibc: glibc: Privilege escalation and arbitrary code execution via TOCTOU race condition in dynamic loader", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-86805" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-89092", + "PkgName": "libc6", + "InstalledVersion": "2.41-12+deb13u4", + "FixedVersion": null, + "Severity": "MEDIUM", + "Title": "glibc: nscd stack overflow leads to degraded DNS resolution", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-89092" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-95818", + "PkgName": "libc6", + "InstalledVersion": "2.41-12+deb13u4", + "FixedVersion": null, + "Severity": "MEDIUM", + "Title": "glibc: glibc: Local attacker can cause denial of service and information disclosure via stack-based buffer overflow.", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-95818" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2010-4756", + "PkgName": "libc6", + "InstalledVersion": "2.41-12+deb13u4", + "FixedVersion": null, + "Severity": "LOW", + "Title": "glibc: glob implementation can cause excessive CPU and memory consumption due to crafted glob expressions", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2010-4756" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2018-20796", + "PkgName": "libc6", + "InstalledVersion": "2.41-12+deb13u4", + "FixedVersion": null, + "Severity": "LOW", + "Title": "glibc: uncontrolled recursion in function check_dst_limits_calc_pos_1 in posix/regexec.c", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2018-20796" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2019-1010022", + "PkgName": "libc6", + "InstalledVersion": "2.41-12+deb13u4", + "FixedVersion": null, + "Severity": "LOW", + "Title": "glibc: stack guard protection bypass", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2019-1010022" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2019-1010023", + "PkgName": "libc6", + "InstalledVersion": "2.41-12+deb13u4", + "FixedVersion": null, + "Severity": "LOW", + "Title": "glibc: running ldd on malicious ELF leads to code execution because of wrong size computation", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2019-1010023" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2019-1010024", + "PkgName": "libc6", + "InstalledVersion": "2.41-12+deb13u4", + "FixedVersion": null, + "Severity": "LOW", + "Title": "glibc: ASLR bypass using cache of thread stack and heap", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2019-1010024" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2019-1010025", + "PkgName": "libc6", + "InstalledVersion": "2.41-12+deb13u4", + "FixedVersion": null, + "Severity": "LOW", + "Title": "glibc: information disclosure of heap addresses of pthread_created thread", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2019-1010025" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2019-9192", + "PkgName": "libc6", + "InstalledVersion": "2.41-12+deb13u4", + "FixedVersion": null, + "Severity": "LOW", + "Title": "glibc: uncontrolled recursion in function check_dst_limits_calc_pos_1 in posix/regexec.c", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2019-9192" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-97399", + "PkgName": "libc6", + "InstalledVersion": "2.41-12+deb13u4", + "FixedVersion": null, + "Severity": "LOW", + "Title": "glibc: glibc: Denial of Service via out-of-bounds read in strncasecmp", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-97399" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-100290", + "PkgName": "libc6", + "InstalledVersion": "2.41-12+deb13u4", + "FixedVersion": null, + "Severity": "UNKNOWN", + "Title": "The regcomp and regexec functions in the GNU C Library version 2.3 to ...", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-100290" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-115819", + "PkgName": "libc6", + "InstalledVersion": "2.41-12+deb13u4", + "FixedVersion": null, + "Severity": "UNKNOWN", + "Title": "Calling the wide scanf family of functions (swscanf, fwscanf, wscanf, ...", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-115819" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-102010", + "PkgName": "libgcc-s1", + "InstalledVersion": "14.2.0-19", + "FixedVersion": null, + "Severity": "MEDIUM", + "Title": "gcc-toolset-15-gcc: gcc: gcc-toolset-16: gcc: Denial of Service via use-after-free in binary heap erase_if", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-102010" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-114690", + "PkgName": "libgcc-s1", + "InstalledVersion": "14.2.0-19", + "FixedVersion": null, + "Severity": "MEDIUM", + "Title": "gcc: Confirmed out-of-bounds read/write in libstdc++ parallel `std", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-114690" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-114691", + "PkgName": "libgcc-s1", + "InstalledVersion": "14.2.0-19", + "FixedVersion": null, + "Severity": "MEDIUM", + "Title": "gcc: Integer wrap in `std", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-114691" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-115455", + "PkgName": "libgcc-s1", + "InstalledVersion": "14.2.0-19", + "FixedVersion": null, + "Severity": "MEDIUM", + "Title": "gcc: Stack overflow in std::bitset on libstdc++", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-115455" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-95619", + "PkgName": "libgcc-s1", + "InstalledVersion": "14.2.0-19", + "FixedVersion": null, + "Severity": "MEDIUM", + "Title": "gcc: libstdc++ integer overflow in `new` operator", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-95619" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-115456", + "PkgName": "libgcc-s1", + "InstalledVersion": "14.2.0-19", + "FixedVersion": null, + "Severity": "LOW", + "Title": "gcc: Out-of-bounds read in std::from_chars", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-115456" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-76642", + "PkgName": "liblastlog2-2", + "InstalledVersion": "2.41.5-0+deb13u1", + "FixedVersion": null, + "Severity": "HIGH", + "Title": "util-linux: util-linux: failed external mount helper still runs privileged X-mount post-hooks", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-76642" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-78408", + "PkgName": "liblastlog2-2", + "InstalledVersion": "2.41.5-0+deb13u1", + "FixedVersion": null, + "Severity": "HIGH", + "Title": "util-linux: util-linux: nsenter --join-cgroup leaks root cgroup migration authority", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-78408" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-78409", + "PkgName": "liblastlog2-2", + "InstalledVersion": "2.41.5-0+deb13u1", + "FixedVersion": null, + "Severity": "HIGH", + "Title": "util-linux: util-linux: X-mount.subdir detached-tree resolution can escape via intermediate symlinks", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-78409" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-78410", + "PkgName": "liblastlog2-2", + "InstalledVersion": "2.41.5-0+deb13u1", + "FixedVersion": null, + "Severity": "HIGH", + "Title": "util-linux: util-linux: restricted bind mounts do not pin the source, allowing X-mount.owner/group/mode redirection", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-78410" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-3184", + "PkgName": "liblastlog2-2", + "InstalledVersion": "2.41.5-0+deb13u1", + "FixedVersion": null, + "Severity": "MEDIUM", + "Title": "util-linux: util-linux: Access control bypass due to improper hostname canonicalization", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-3184" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2022-0563", + "PkgName": "liblastlog2-2", + "InstalledVersion": "2.41.5-0+deb13u1", + "FixedVersion": null, + "Severity": "LOW", + "Title": "util-linux: partial disclosure of arbitrary files in chfn and chsh when compiled with libreadline", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2022-0563" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-76642", + "PkgName": "libmount1", + "InstalledVersion": "2.41.5-0+deb13u1", + "FixedVersion": null, + "Severity": "HIGH", + "Title": "util-linux: util-linux: failed external mount helper still runs privileged X-mount post-hooks", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-76642" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-78408", + "PkgName": "libmount1", + "InstalledVersion": "2.41.5-0+deb13u1", + "FixedVersion": null, + "Severity": "HIGH", + "Title": "util-linux: util-linux: nsenter --join-cgroup leaks root cgroup migration authority", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-78408" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-78409", + "PkgName": "libmount1", + "InstalledVersion": "2.41.5-0+deb13u1", + "FixedVersion": null, + "Severity": "HIGH", + "Title": "util-linux: util-linux: X-mount.subdir detached-tree resolution can escape via intermediate symlinks", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-78409" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-78410", + "PkgName": "libmount1", + "InstalledVersion": "2.41.5-0+deb13u1", + "FixedVersion": null, + "Severity": "HIGH", + "Title": "util-linux: util-linux: restricted bind mounts do not pin the source, allowing X-mount.owner/group/mode redirection", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-78410" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-3184", + "PkgName": "libmount1", + "InstalledVersion": "2.41.5-0+deb13u1", + "FixedVersion": null, + "Severity": "MEDIUM", + "Title": "util-linux: util-linux: Access control bypass due to improper hostname canonicalization", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-3184" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2022-0563", + "PkgName": "libmount1", + "InstalledVersion": "2.41.5-0+deb13u1", + "FixedVersion": null, + "Severity": "LOW", + "Title": "util-linux: partial disclosure of arbitrary files in chfn and chsh when compiled with libreadline", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2022-0563" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2025-69720", + "PkgName": "libncursesw6", + "InstalledVersion": "6.5+20250216-2", + "FixedVersion": null, + "Severity": "HIGH", + "Title": "ncurses: ncurses: Buffer overflow vulnerability may lead to arbitrary code execution.", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2025-69720" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2025-6141", + "PkgName": "libncursesw6", + "InstalledVersion": "6.5+20250216-2", + "FixedVersion": null, + "Severity": "LOW", + "Title": "gnu-ncurses: ncurses Stack Buffer Overflow", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2025-6141" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-54411", + "PkgName": "libpam-modules", + "InstalledVersion": "1.7.0-5", + "FixedVersion": null, + "Severity": "MEDIUM", + "Title": "linux-pam: Plaintext password recovery via timing discrepancy in pam_userdb module", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-54411" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-54411", + "PkgName": "libpam-modules-bin", + "InstalledVersion": "1.7.0-5", + "FixedVersion": null, + "Severity": "MEDIUM", + "Title": "linux-pam: Plaintext password recovery via timing discrepancy in pam_userdb module", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-54411" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-54411", + "PkgName": "libpam-runtime", + "InstalledVersion": "1.7.0-5", + "FixedVersion": null, + "Severity": "MEDIUM", + "Title": "linux-pam: Plaintext password recovery via timing discrepancy in pam_userdb module", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-54411" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-54411", + "PkgName": "libpam0g", + "InstalledVersion": "1.7.0-5", + "FixedVersion": null, + "Severity": "MEDIUM", + "Title": "linux-pam: Plaintext password recovery via timing discrepancy in pam_userdb module", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-54411" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-76642", + "PkgName": "libsmartcols1", + "InstalledVersion": "2.41.5-0+deb13u1", + "FixedVersion": null, + "Severity": "HIGH", + "Title": "util-linux: util-linux: failed external mount helper still runs privileged X-mount post-hooks", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-76642" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-78408", + "PkgName": "libsmartcols1", + "InstalledVersion": "2.41.5-0+deb13u1", + "FixedVersion": null, + "Severity": "HIGH", + "Title": "util-linux: util-linux: nsenter --join-cgroup leaks root cgroup migration authority", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-78408" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-78409", + "PkgName": "libsmartcols1", + "InstalledVersion": "2.41.5-0+deb13u1", + "FixedVersion": null, + "Severity": "HIGH", + "Title": "util-linux: util-linux: X-mount.subdir detached-tree resolution can escape via intermediate symlinks", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-78409" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-78410", + "PkgName": "libsmartcols1", + "InstalledVersion": "2.41.5-0+deb13u1", + "FixedVersion": null, + "Severity": "HIGH", + "Title": "util-linux: util-linux: restricted bind mounts do not pin the source, allowing X-mount.owner/group/mode redirection", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-78410" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-3184", + "PkgName": "libsmartcols1", + "InstalledVersion": "2.41.5-0+deb13u1", + "FixedVersion": null, + "Severity": "MEDIUM", + "Title": "util-linux: util-linux: Access control bypass due to improper hostname canonicalization", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-3184" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2022-0563", + "PkgName": "libsmartcols1", + "InstalledVersion": "2.41.5-0+deb13u1", + "FixedVersion": null, + "Severity": "LOW", + "Title": "util-linux: partial disclosure of arbitrary files in chfn and chsh when compiled with libreadline", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2022-0563" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-119373", + "PkgName": "libsqlite3-0", + "InstalledVersion": "3.46.1-7+deb13u2", + "FixedVersion": null, + "Severity": "HIGH", + "Title": "sqlite: sqlite: Denial of service via heap-based buffer overflow in FTS5", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-119373" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-119374", + "PkgName": "libsqlite3-0", + "InstalledVersion": "3.46.1-7+deb13u2", + "FixedVersion": null, + "Severity": "HIGH", + "Title": "sqlite: sqlite: Arbitrary code execution via corrupted FTS5 index", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-119374" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-119379", + "PkgName": "libsqlite3-0", + "InstalledVersion": "3.46.1-7+deb13u2", + "FixedVersion": null, + "Severity": "HIGH", + "Title": "sqlite: sqlite: Arbitrary code execution via crafted session changesets", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-119379" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-119371", + "PkgName": "libsqlite3-0", + "InstalledVersion": "3.46.1-7+deb13u2", + "FixedVersion": null, + "Severity": "MEDIUM", + "Title": "sqlite: sqlite: Denial of Service via stack exhaustion from deeply nested Common Table Expressions", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-119371" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-119372", + "PkgName": "libsqlite3-0", + "InstalledVersion": "3.46.1-7+deb13u2", + "FixedVersion": null, + "Severity": "MEDIUM", + "Title": "sqlite: sqlite: Denial of Service via use-after-free in full-text search", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-119372" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-119375", + "PkgName": "libsqlite3-0", + "InstalledVersion": "3.46.1-7+deb13u2", + "FixedVersion": null, + "Severity": "MEDIUM", + "Title": "sqlite: sqlite: Information disclosure via undersized WAL page size", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-119375" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-119376", + "PkgName": "libsqlite3-0", + "InstalledVersion": "3.46.1-7+deb13u2", + "FixedVersion": null, + "Severity": "MEDIUM", + "Title": "sqlite: sqlite: Denial of Service via stack exhaustion from chained COLLATE operators", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-119376" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-119378", + "PkgName": "libsqlite3-0", + "InstalledVersion": "3.46.1-7+deb13u2", + "FixedVersion": null, + "Severity": "MEDIUM", + "Title": "sqlite: sqlite: Denial of Service via use-after-free in R-Tree extension", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-119378" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-119591", + "PkgName": "libsqlite3-0", + "InstalledVersion": "3.46.1-7+deb13u2", + "FixedVersion": null, + "Severity": "MEDIUM", + "Title": "sqlite: sqlite: Denial of Service via stack exhaustion in countOfViewOptimization()", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-119591" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-50812", + "PkgName": "libsqlite3-0", + "InstalledVersion": "3.46.1-7+deb13u2", + "FixedVersion": null, + "Severity": "MEDIUM", + "Title": "sqlite: SQLite: Denial of Service via malformed changeset in Session Extension", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-50812" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-50813", + "PkgName": "libsqlite3-0", + "InstalledVersion": "3.46.1-7+deb13u2", + "FixedVersion": null, + "Severity": "MEDIUM", + "Title": "sqlite: SQLite: Information disclosure via Session Extension changeset merge path", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-50813" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2021-45346", + "PkgName": "libsqlite3-0", + "InstalledVersion": "3.46.1-7+deb13u2", + "FixedVersion": null, + "Severity": "LOW", + "Title": "sqlite: crafted SQL query allows a malicious user to obtain sensitive information", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2021-45346" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2025-70873", + "PkgName": "libsqlite3-0", + "InstalledVersion": "3.46.1-7+deb13u2", + "FixedVersion": null, + "Severity": "LOW", + "Title": "sqlite: SQLite: Information Disclosure via Crafted ZIP File", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2025-70873" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-119377", + "PkgName": "libsqlite3-0", + "InstalledVersion": "3.46.1-7+deb13u2", + "FixedVersion": null, + "Severity": "LOW", + "Title": "sqlite: sqlite: Authorization bypass via USING clause in JOIN queries", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-119377" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-107496", + "PkgName": "libssl3t64", + "InstalledVersion": "3.5.7-1~deb13u3", + "FixedVersion": null, + "Severity": "UNKNOWN", + "Title": "Issue summary: Encrypting a CMS message to an EC certificate whose gro ...", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-107496" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-88822", + "PkgName": "libssl3t64", + "InstalledVersion": "3.5.7-1~deb13u3", + "FixedVersion": null, + "Severity": "UNKNOWN", + "Title": "Issue summary: QUIC, when performing automated peer detection, may all ...", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-88822" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-88823", + "PkgName": "libssl3t64", + "InstalledVersion": "3.5.7-1~deb13u3", + "FixedVersion": null, + "Severity": "UNKNOWN", + "Title": "Issue summary: The AES-GCM-SIV implementation treats a zero-length Add ...", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-88823" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-95691", + "PkgName": "libssl3t64", + "InstalledVersion": "3.5.7-1~deb13u3", + "FixedVersion": null, + "Severity": "UNKNOWN", + "Title": "Issue summary: A retransmitted QUIC CRYPTO frame can release packet st ...", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-95691" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-95692", + "PkgName": "libssl3t64", + "InstalledVersion": "3.5.7-1~deb13u3", + "FixedVersion": null, + "Severity": "UNKNOWN", + "Title": "Issue summary: Setting an AES-GCM-SIV IV shorter than the expected non ...", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-95692" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-102010", + "PkgName": "libstdc++6", + "InstalledVersion": "14.2.0-19", + "FixedVersion": null, + "Severity": "MEDIUM", + "Title": "gcc-toolset-15-gcc: gcc: gcc-toolset-16: gcc: Denial of Service via use-after-free in binary heap erase_if", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-102010" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-114690", + "PkgName": "libstdc++6", + "InstalledVersion": "14.2.0-19", + "FixedVersion": null, + "Severity": "MEDIUM", + "Title": "gcc: Confirmed out-of-bounds read/write in libstdc++ parallel `std", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-114690" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-114691", + "PkgName": "libstdc++6", + "InstalledVersion": "14.2.0-19", + "FixedVersion": null, + "Severity": "MEDIUM", + "Title": "gcc: Integer wrap in `std", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-114691" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-115455", + "PkgName": "libstdc++6", + "InstalledVersion": "14.2.0-19", + "FixedVersion": null, + "Severity": "MEDIUM", + "Title": "gcc: Stack overflow in std::bitset on libstdc++", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-115455" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-95619", + "PkgName": "libstdc++6", + "InstalledVersion": "14.2.0-19", + "FixedVersion": null, + "Severity": "MEDIUM", + "Title": "gcc: libstdc++ integer overflow in `new` operator", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-95619" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-115456", + "PkgName": "libstdc++6", + "InstalledVersion": "14.2.0-19", + "FixedVersion": null, + "Severity": "LOW", + "Title": "gcc: Out-of-bounds read in std::from_chars", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-115456" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-16742", + "PkgName": "libsystemd0", + "InstalledVersion": "257.13-1~deb13u1", + "FixedVersion": null, + "Severity": "HIGH", + "Title": "systemd: systemd-homed: Local privilege escalation via missing home-record signature verification", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-16742" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-15059", + "PkgName": "libsystemd0", + "InstalledVersion": "257.13-1~deb13u1", + "FixedVersion": null, + "Severity": "MEDIUM", + "Title": "systemd: systemd-oomd: Unprivileged users can terminate arbitrary processes via IPC API", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-15059" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2013-4392", + "PkgName": "libsystemd0", + "InstalledVersion": "257.13-1~deb13u1", + "FixedVersion": null, + "Severity": "LOW", + "Title": "systemd: TOCTOU race condition when updating file permissions and SELinux security contexts", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2013-4392" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2023-31437", + "PkgName": "libsystemd0", + "InstalledVersion": "257.13-1~deb13u1", + "FixedVersion": null, + "Severity": "LOW", + "Title": "An issue was discovered in systemd 253. An attacker can modify a seale ...", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2023-31437" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2023-31438", + "PkgName": "libsystemd0", + "InstalledVersion": "257.13-1~deb13u1", + "FixedVersion": null, + "Severity": "LOW", + "Title": "An issue was discovered in systemd 253. An attacker can truncate a sea ...", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2023-31438" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2023-31439", + "PkgName": "libsystemd0", + "InstalledVersion": "257.13-1~deb13u1", + "FixedVersion": null, + "Severity": "LOW", + "Title": "An issue was discovered in systemd 253. An attacker can modify the con ...", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2023-31439" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-40228", + "PkgName": "libsystemd0", + "InstalledVersion": "257.13-1~deb13u1", + "FixedVersion": null, + "Severity": "LOW", + "Title": "systemd: systemd-journald: Unintended output to user terminals via logger command", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-40228" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2025-69720", + "PkgName": "libtinfo6", + "InstalledVersion": "6.5+20250216-2", + "FixedVersion": null, + "Severity": "HIGH", + "Title": "ncurses: ncurses: Buffer overflow vulnerability may lead to arbitrary code execution.", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2025-69720" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2025-6141", + "PkgName": "libtinfo6", + "InstalledVersion": "6.5+20250216-2", + "FixedVersion": null, + "Severity": "LOW", + "Title": "gnu-ncurses: ncurses Stack Buffer Overflow", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2025-6141" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-16742", + "PkgName": "libudev1", + "InstalledVersion": "257.13-1~deb13u1", + "FixedVersion": null, + "Severity": "HIGH", + "Title": "systemd: systemd-homed: Local privilege escalation via missing home-record signature verification", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-16742" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-15059", + "PkgName": "libudev1", + "InstalledVersion": "257.13-1~deb13u1", + "FixedVersion": null, + "Severity": "MEDIUM", + "Title": "systemd: systemd-oomd: Unprivileged users can terminate arbitrary processes via IPC API", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-15059" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2013-4392", + "PkgName": "libudev1", + "InstalledVersion": "257.13-1~deb13u1", + "FixedVersion": null, + "Severity": "LOW", + "Title": "systemd: TOCTOU race condition when updating file permissions and SELinux security contexts", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2013-4392" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2023-31437", + "PkgName": "libudev1", + "InstalledVersion": "257.13-1~deb13u1", + "FixedVersion": null, + "Severity": "LOW", + "Title": "An issue was discovered in systemd 253. An attacker can modify a seale ...", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2023-31437" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2023-31438", + "PkgName": "libudev1", + "InstalledVersion": "257.13-1~deb13u1", + "FixedVersion": null, + "Severity": "LOW", + "Title": "An issue was discovered in systemd 253. An attacker can truncate a sea ...", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2023-31438" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2023-31439", + "PkgName": "libudev1", + "InstalledVersion": "257.13-1~deb13u1", + "FixedVersion": null, + "Severity": "LOW", + "Title": "An issue was discovered in systemd 253. An attacker can modify the con ...", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2023-31439" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-40228", + "PkgName": "libudev1", + "InstalledVersion": "257.13-1~deb13u1", + "FixedVersion": null, + "Severity": "LOW", + "Title": "systemd: systemd-journald: Unintended output to user terminals via logger command", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-40228" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-76642", + "PkgName": "libuuid1", + "InstalledVersion": "2.41.5-0+deb13u1", + "FixedVersion": null, + "Severity": "HIGH", + "Title": "util-linux: util-linux: failed external mount helper still runs privileged X-mount post-hooks", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-76642" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-78408", + "PkgName": "libuuid1", + "InstalledVersion": "2.41.5-0+deb13u1", + "FixedVersion": null, + "Severity": "HIGH", + "Title": "util-linux: util-linux: nsenter --join-cgroup leaks root cgroup migration authority", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-78408" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-78409", + "PkgName": "libuuid1", + "InstalledVersion": "2.41.5-0+deb13u1", + "FixedVersion": null, + "Severity": "HIGH", + "Title": "util-linux: util-linux: X-mount.subdir detached-tree resolution can escape via intermediate symlinks", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-78409" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-78410", + "PkgName": "libuuid1", + "InstalledVersion": "2.41.5-0+deb13u1", + "FixedVersion": null, + "Severity": "HIGH", + "Title": "util-linux: util-linux: restricted bind mounts do not pin the source, allowing X-mount.owner/group/mode redirection", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-78410" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-3184", + "PkgName": "libuuid1", + "InstalledVersion": "2.41.5-0+deb13u1", + "FixedVersion": null, + "Severity": "MEDIUM", + "Title": "util-linux: util-linux: Access control bypass due to improper hostname canonicalization", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-3184" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2022-0563", + "PkgName": "libuuid1", + "InstalledVersion": "2.41.5-0+deb13u1", + "FixedVersion": null, + "Severity": "LOW", + "Title": "util-linux: partial disclosure of arbitrary files in chfn and chsh when compiled with libreadline", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2022-0563" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-76642", + "PkgName": "login", + "InstalledVersion": "1:4.16.0-2+really2.41.5-0+deb13u1", + "FixedVersion": null, + "Severity": "HIGH", + "Title": "util-linux: util-linux: failed external mount helper still runs privileged X-mount post-hooks", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-76642" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-78408", + "PkgName": "login", + "InstalledVersion": "1:4.16.0-2+really2.41.5-0+deb13u1", + "FixedVersion": null, + "Severity": "HIGH", + "Title": "util-linux: util-linux: nsenter --join-cgroup leaks root cgroup migration authority", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-78408" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-78409", + "PkgName": "login", + "InstalledVersion": "1:4.16.0-2+really2.41.5-0+deb13u1", + "FixedVersion": null, + "Severity": "HIGH", + "Title": "util-linux: util-linux: X-mount.subdir detached-tree resolution can escape via intermediate symlinks", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-78409" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-78410", + "PkgName": "login", + "InstalledVersion": "1:4.16.0-2+really2.41.5-0+deb13u1", + "FixedVersion": null, + "Severity": "HIGH", + "Title": "util-linux: util-linux: restricted bind mounts do not pin the source, allowing X-mount.owner/group/mode redirection", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-78410" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-3184", + "PkgName": "login", + "InstalledVersion": "1:4.16.0-2+really2.41.5-0+deb13u1", + "FixedVersion": null, + "Severity": "MEDIUM", + "Title": "util-linux: util-linux: Access control bypass due to improper hostname canonicalization", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-3184" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2022-0563", + "PkgName": "login", + "InstalledVersion": "1:4.16.0-2+really2.41.5-0+deb13u1", + "FixedVersion": null, + "Severity": "LOW", + "Title": "util-linux: partial disclosure of arbitrary files in chfn and chsh when compiled with libreadline", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2022-0563" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2007-5686", + "PkgName": "login.defs", + "InstalledVersion": "1:4.17.4-2", + "FixedVersion": null, + "Severity": "LOW", + "Title": "initscripts in rPath Linux 1 sets insecure permissions for the /var/lo ...", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2007-5686" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2024-56433", + "PkgName": "login.defs", + "InstalledVersion": "1:4.17.4-2", + "FixedVersion": null, + "Severity": "LOW", + "Title": "shadow-utils: Default subordinate ID configuration in /etc/login.defs could lead to compromise", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2024-56433" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "TEMP-0628843-DBAD28", + "PkgName": "login.defs", + "InstalledVersion": "1:4.17.4-2", + "FixedVersion": null, + "Severity": "LOW", + "Title": "[more related to CVE-2005-4890]", + "PrimaryURL": "https://security-tracker.debian.org/tracker/TEMP-0628843-DBAD28" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-76642", + "PkgName": "mount", + "InstalledVersion": "2.41.5-0+deb13u1", + "FixedVersion": null, + "Severity": "HIGH", + "Title": "util-linux: util-linux: failed external mount helper still runs privileged X-mount post-hooks", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-76642" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-78408", + "PkgName": "mount", + "InstalledVersion": "2.41.5-0+deb13u1", + "FixedVersion": null, + "Severity": "HIGH", + "Title": "util-linux: util-linux: nsenter --join-cgroup leaks root cgroup migration authority", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-78408" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-78409", + "PkgName": "mount", + "InstalledVersion": "2.41.5-0+deb13u1", + "FixedVersion": null, + "Severity": "HIGH", + "Title": "util-linux: util-linux: X-mount.subdir detached-tree resolution can escape via intermediate symlinks", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-78409" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-78410", + "PkgName": "mount", + "InstalledVersion": "2.41.5-0+deb13u1", + "FixedVersion": null, + "Severity": "HIGH", + "Title": "util-linux: util-linux: restricted bind mounts do not pin the source, allowing X-mount.owner/group/mode redirection", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-78410" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-3184", + "PkgName": "mount", + "InstalledVersion": "2.41.5-0+deb13u1", + "FixedVersion": null, + "Severity": "MEDIUM", + "Title": "util-linux: util-linux: Access control bypass due to improper hostname canonicalization", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-3184" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2022-0563", + "PkgName": "mount", + "InstalledVersion": "2.41.5-0+deb13u1", + "FixedVersion": null, + "Severity": "LOW", + "Title": "util-linux: partial disclosure of arbitrary files in chfn and chsh when compiled with libreadline", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2022-0563" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2025-69720", + "PkgName": "ncurses-base", + "InstalledVersion": "6.5+20250216-2", + "FixedVersion": null, + "Severity": "HIGH", + "Title": "ncurses: ncurses: Buffer overflow vulnerability may lead to arbitrary code execution.", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2025-69720" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2025-6141", + "PkgName": "ncurses-base", + "InstalledVersion": "6.5+20250216-2", + "FixedVersion": null, + "Severity": "LOW", + "Title": "gnu-ncurses: ncurses Stack Buffer Overflow", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2025-6141" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2025-69720", + "PkgName": "ncurses-bin", + "InstalledVersion": "6.5+20250216-2", + "FixedVersion": null, + "Severity": "HIGH", + "Title": "ncurses: ncurses: Buffer overflow vulnerability may lead to arbitrary code execution.", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2025-69720" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2025-6141", + "PkgName": "ncurses-bin", + "InstalledVersion": "6.5+20250216-2", + "FixedVersion": null, + "Severity": "LOW", + "Title": "gnu-ncurses: ncurses Stack Buffer Overflow", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2025-6141" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-107496", + "PkgName": "openssl", + "InstalledVersion": "3.5.7-1~deb13u3", + "FixedVersion": null, + "Severity": "UNKNOWN", + "Title": "Issue summary: Encrypting a CMS message to an EC certificate whose gro ...", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-107496" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-88822", + "PkgName": "openssl", + "InstalledVersion": "3.5.7-1~deb13u3", + "FixedVersion": null, + "Severity": "UNKNOWN", + "Title": "Issue summary: QUIC, when performing automated peer detection, may all ...", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-88822" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-88823", + "PkgName": "openssl", + "InstalledVersion": "3.5.7-1~deb13u3", + "FixedVersion": null, + "Severity": "UNKNOWN", + "Title": "Issue summary: The AES-GCM-SIV implementation treats a zero-length Add ...", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-88823" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-95691", + "PkgName": "openssl", + "InstalledVersion": "3.5.7-1~deb13u3", + "FixedVersion": null, + "Severity": "UNKNOWN", + "Title": "Issue summary: A retransmitted QUIC CRYPTO frame can release packet st ...", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-95691" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-95692", + "PkgName": "openssl", + "InstalledVersion": "3.5.7-1~deb13u3", + "FixedVersion": null, + "Severity": "UNKNOWN", + "Title": "Issue summary: Setting an AES-GCM-SIV IV shorter than the expected non ...", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-95692" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-107496", + "PkgName": "openssl-provider-legacy", + "InstalledVersion": "3.5.7-1~deb13u3", + "FixedVersion": null, + "Severity": "UNKNOWN", + "Title": "Issue summary: Encrypting a CMS message to an EC certificate whose gro ...", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-107496" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-88822", + "PkgName": "openssl-provider-legacy", + "InstalledVersion": "3.5.7-1~deb13u3", + "FixedVersion": null, + "Severity": "UNKNOWN", + "Title": "Issue summary: QUIC, when performing automated peer detection, may all ...", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-88822" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-88823", + "PkgName": "openssl-provider-legacy", + "InstalledVersion": "3.5.7-1~deb13u3", + "FixedVersion": null, + "Severity": "UNKNOWN", + "Title": "Issue summary: The AES-GCM-SIV implementation treats a zero-length Add ...", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-88823" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-95691", + "PkgName": "openssl-provider-legacy", + "InstalledVersion": "3.5.7-1~deb13u3", + "FixedVersion": null, + "Severity": "UNKNOWN", + "Title": "Issue summary: A retransmitted QUIC CRYPTO frame can release packet st ...", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-95691" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-95692", + "PkgName": "openssl-provider-legacy", + "InstalledVersion": "3.5.7-1~deb13u3", + "FixedVersion": null, + "Severity": "UNKNOWN", + "Title": "Issue summary: Setting an AES-GCM-SIV IV shorter than the expected non ...", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-95692" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2007-5686", + "PkgName": "passwd", + "InstalledVersion": "1:4.17.4-2", + "FixedVersion": null, + "Severity": "LOW", + "Title": "initscripts in rPath Linux 1 sets insecure permissions for the /var/lo ...", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2007-5686" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2024-56433", + "PkgName": "passwd", + "InstalledVersion": "1:4.17.4-2", + "FixedVersion": null, + "Severity": "LOW", + "Title": "shadow-utils: Default subordinate ID configuration in /etc/login.defs could lead to compromise", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2024-56433" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "TEMP-0628843-DBAD28", + "PkgName": "passwd", + "InstalledVersion": "1:4.17.4-2", + "FixedVersion": null, + "Severity": "LOW", + "Title": "[more related to CVE-2005-4890]", + "PrimaryURL": "https://security-tracker.debian.org/tracker/TEMP-0628843-DBAD28" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-9538", + "PkgName": "perl-base", + "InstalledVersion": "5.40.1-6+deb13u1", + "FixedVersion": null, + "Severity": "HIGH", + "Title": "perl-Archive-Tar: perl-Archive-Tar: Denial of Service via crafted tar header with large entry size", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-9538" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-15534", + "PkgName": "perl-base", + "InstalledVersion": "5.40.1-6+deb13u1", + "FixedVersion": null, + "Severity": "MEDIUM", + "Title": "perl: Perl: Arbitrary code execution via out-of-bounds memory access in regular expression engine.", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-15534" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-82560", + "PkgName": "perl-base", + "InstalledVersion": "5.40.1-6+deb13u1", + "FixedVersion": null, + "Severity": "MEDIUM", + "Title": "Pod::Text versions before 6.1.1 for Perl allow CPU and memory exhausti ...", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-82560" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2011-4116", + "PkgName": "perl-base", + "InstalledVersion": "5.40.1-6+deb13u1", + "FixedVersion": null, + "Severity": "LOW", + "Title": "perl: File:: Temp insecure temporary file handling", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2011-4116" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "TEMP-0517018-A83CE6", + "PkgName": "sysvinit-utils", + "InstalledVersion": "3.14-4", + "FixedVersion": null, + "Severity": "LOW", + "Title": "[sysvinit: no-root option in expert installer exposes locally exploitable security flaw]", + "PrimaryURL": "https://security-tracker.debian.org/tracker/TEMP-0517018-A83CE6" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-18477", + "PkgName": "tar", + "InstalledVersion": "1.35+dfsg-3.1", + "FixedVersion": null, + "Severity": "MEDIUM", + "Title": "tar: tar: TOCTOU in incremental dumpdir 'X' rename handling allows restore path escape", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-18477" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-18508", + "PkgName": "tar", + "InstalledVersion": "1.35+dfsg-3.1", + "FixedVersion": null, + "Severity": "MEDIUM", + "Title": "tar: tar: --one-top-level hardlink targets not confined to top-level directory enabling arbitrary file overwrite", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-18508" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-5704", + "PkgName": "tar", + "InstalledVersion": "1.35+dfsg-3.1", + "FixedVersion": null, + "Severity": "MEDIUM", + "Title": "tar: tar: Hidden file injection via crafted archives", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-5704" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2005-2541", + "PkgName": "tar", + "InstalledVersion": "1.35+dfsg-3.1", + "FixedVersion": null, + "Severity": "LOW", + "Title": "tar: does not properly warn the user when extracting setuid or setgid files", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2005-2541" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "TEMP-0290435-0B57B5", + "PkgName": "tar", + "InstalledVersion": "1.35+dfsg-3.1", + "FixedVersion": null, + "Severity": "LOW", + "Title": "[tar's rmt command may have undesired side effects]", + "PrimaryURL": "https://security-tracker.debian.org/tracker/TEMP-0290435-0B57B5" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-76642", + "PkgName": "util-linux", + "InstalledVersion": "2.41.5-0+deb13u1", + "FixedVersion": null, + "Severity": "HIGH", + "Title": "util-linux: util-linux: failed external mount helper still runs privileged X-mount post-hooks", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-76642" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-78408", + "PkgName": "util-linux", + "InstalledVersion": "2.41.5-0+deb13u1", + "FixedVersion": null, + "Severity": "HIGH", + "Title": "util-linux: util-linux: nsenter --join-cgroup leaks root cgroup migration authority", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-78408" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-78409", + "PkgName": "util-linux", + "InstalledVersion": "2.41.5-0+deb13u1", + "FixedVersion": null, + "Severity": "HIGH", + "Title": "util-linux: util-linux: X-mount.subdir detached-tree resolution can escape via intermediate symlinks", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-78409" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-78410", + "PkgName": "util-linux", + "InstalledVersion": "2.41.5-0+deb13u1", + "FixedVersion": null, + "Severity": "HIGH", + "Title": "util-linux: util-linux: restricted bind mounts do not pin the source, allowing X-mount.owner/group/mode redirection", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-78410" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2026-3184", + "PkgName": "util-linux", + "InstalledVersion": "2.41.5-0+deb13u1", + "FixedVersion": null, + "Severity": "MEDIUM", + "Title": "util-linux: util-linux: Access control bypass due to improper hostname canonicalization", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-3184" + }, + { + "target": "/scan/image.tar (debian 13.7)", + "VulnerabilityID": "CVE-2022-0563", + "PkgName": "util-linux", + "InstalledVersion": "2.41.5-0+deb13u1", + "FixedVersion": null, + "Severity": "LOW", + "Title": "util-linux: partial disclosure of arbitrary files in chfn and chsh when compiled with libreadline", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2022-0563" + }, + { + "target": "Python", + "VulnerabilityID": "CVE-2025-47273", + "PkgName": "setuptools", + "InstalledVersion": "70.3.0", + "FixedVersion": "78.1.1", + "Severity": "HIGH", + "Title": "setuptools: Path Traversal Vulnerability in setuptools PackageIndex", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2025-47273" + }, + { + "target": "Python", + "VulnerabilityID": "CVE-2026-59890", + "PkgName": "setuptools", + "InstalledVersion": "70.3.0", + "FixedVersion": "83.0.0", + "Severity": "MEDIUM", + "Title": "setuptools: setuptools: MANIFEST.in exclusion bypass in sdist via Unicode normalization collision (NFC/NFD)", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-59890" + }, + { + "target": "Python", + "VulnerabilityID": "GHSA-xmj3-9gf7-h52w", + "PkgName": "setuptools", + "InstalledVersion": "70.3.0", + "FixedVersion": "84.1.0", + "Severity": "LOW", + "Title": "setuptools: Windows path escape via namespace_packages.txt during legacy wheel installation Description", + "PrimaryURL": "https://github.com/advisories/GHSA-xmj3-9gf7-h52w" + } + ] + }, + { + "service": "openbao", + "image": "quay.io/openbao/openbao@sha256:5046911075e137e154ce49ab051502f4ec7cf367d484ae4a4dce665d9b90561f", + "image_id": "sha256:5046911075e137e154ce49ab051502f4ec7cf367d484ae4a4dce665d9b90561f", + "report_sha256": "4403b52321426afd3f2ac4c16eaad3371dd293b689092259f24b748cf49b045c", + "counts": { + "MEDIUM": 6, + "HIGH": 3, + "UNKNOWN": 2 + }, + "findings": [ + { + "target": "/scan/image.tar (alpine 3.24.3)", + "VulnerabilityID": "CVE-2026-4738", + "PkgName": "zlib", + "InstalledVersion": "1.3.2-r1", + "FixedVersion": "1.4-r0", + "Severity": "MEDIUM", + "Title": "Improper Restriction of Operations within the Bounds of a Memory Buffe ...", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-4738" + }, + { + "target": "usr/bin/bao", + "VulnerabilityID": "CVE-2026-116587", + "PkgName": "github.com/go-jose/go-jose/v3", + "InstalledVersion": "v3.0.5", + "FixedVersion": null, + "Severity": "HIGH", + "Title": "github.com/go-jose/go-jose: go-jose: Denial of Service via crafted RSA parameters in JWKs", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-116587" + }, + { + "target": "usr/bin/bao", + "VulnerabilityID": "CVE-2026-116585", + "PkgName": "github.com/go-jose/go-jose/v3", + "InstalledVersion": "v3.0.5", + "FixedVersion": null, + "Severity": "MEDIUM", + "Title": "github.com/go-jose/go-jose: go-jose: Denial of Service via empty ciphertext buffer during JWE decryption", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-116585" + }, + { + "target": "usr/bin/bao", + "VulnerabilityID": "CVE-2026-116586", + "PkgName": "github.com/go-jose/go-jose/v3", + "InstalledVersion": "v3.0.5", + "FixedVersion": null, + "Severity": "MEDIUM", + "Title": "github.com/go-jose/go-jose: go-jose: Denial of Service via deeply nested JSON parsing", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-116586" + }, + { + "target": "usr/bin/bao", + "VulnerabilityID": "CVE-2026-116587", + "PkgName": "github.com/go-jose/go-jose/v4", + "InstalledVersion": "v4.1.4", + "FixedVersion": "4.1.6", + "Severity": "HIGH", + "Title": "github.com/go-jose/go-jose: go-jose: Denial of Service via crafted RSA parameters in JWKs", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-116587" + }, + { + "target": "usr/bin/bao", + "VulnerabilityID": "CVE-2026-116585", + "PkgName": "github.com/go-jose/go-jose/v4", + "InstalledVersion": "v4.1.4", + "FixedVersion": "4.1.5", + "Severity": "MEDIUM", + "Title": "github.com/go-jose/go-jose: go-jose: Denial of Service via empty ciphertext buffer during JWE decryption", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-116585" + }, + { + "target": "usr/bin/bao", + "VulnerabilityID": "CVE-2026-116586", + "PkgName": "github.com/go-jose/go-jose/v4", + "InstalledVersion": "v4.1.4", + "FixedVersion": "4.1.5", + "Severity": "MEDIUM", + "Title": "github.com/go-jose/go-jose: go-jose: Denial of Service via deeply nested JSON parsing", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-116586" + }, + { + "target": "usr/bin/bao", + "VulnerabilityID": "GO-2026-5932", + "PkgName": "golang.org/x/crypto", + "InstalledVersion": "v0.58.0", + "FixedVersion": "0.58.1-0.20261009181718-2f1f834330b2", + "Severity": "UNKNOWN", + "Title": "The golang.org/x/crypto/openpgp package is unmaintained, unsafe by design, and has known security issues", + "PrimaryURL": null + }, + { + "target": "usr/bin/bao", + "VulnerabilityID": "CVE-2026-78661", + "PkgName": "golang.org/x/net", + "InstalledVersion": "v0.61.0", + "FixedVersion": "0.62.0", + "Severity": "HIGH", + "Title": "golang.org/x/net/html: golang.org/x/net/html: Denial of Service via crafted HTML input", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-78661" + }, + { + "target": "usr/bin/bao", + "VulnerabilityID": "CVE-2026-97045", + "PkgName": "golang.org/x/net", + "InstalledVersion": "v0.61.0", + "FixedVersion": "0.62.0", + "Severity": "MEDIUM", + "Title": "golang.org/x/net/html: golang.org/x/net/html: Cross-Site Scripting via improper namespace handling during HTML rendering", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-97045" + }, + { + "target": "usr/bin/bao", + "VulnerabilityID": "CVE-2026-97054", + "PkgName": "stdlib", + "InstalledVersion": "v1.27.3", + "FixedVersion": "1.26.11, 1.27.4", + "Severity": "UNKNOWN", + "Title": "For HTTP/1 servers, when MaxBytesReader's limit is exceeded, \"Connecti ...", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-97054" + } + ] + }, + { + "service": "s3", + "image": "chrislusf/seaweedfs@sha256:ccad23e18639c8b98cee17e7100b95830a06077b56d8e5b006d6dcf8ec5e94a0", + "image_id": "sha256:ccad23e18639c8b98cee17e7100b95830a06077b56d8e5b006d6dcf8ec5e94a0", + "report_sha256": "55e7f8150d05fbbd474140aad9cde0e49b521baa25e5e133c2d974f79c5890ac", + "counts": { + "UNKNOWN": 2, + "HIGH": 1, + "MEDIUM": 1 + }, + "findings": [ + { + "target": "usr/bin/weed", + "VulnerabilityID": "GO-2026-5932", + "PkgName": "golang.org/x/crypto", + "InstalledVersion": "v0.58.0", + "FixedVersion": "0.58.1-0.20261009181718-2f1f834330b2", + "Severity": "UNKNOWN", + "Title": "The golang.org/x/crypto/openpgp package is unmaintained, unsafe by design, and has known security issues", + "PrimaryURL": null + }, + { + "target": "usr/bin/weed", + "VulnerabilityID": "CVE-2026-78661", + "PkgName": "golang.org/x/net", + "InstalledVersion": "v0.61.0", + "FixedVersion": "0.62.0", + "Severity": "HIGH", + "Title": "golang.org/x/net/html: golang.org/x/net/html: Denial of Service via crafted HTML input", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-78661" + }, + { + "target": "usr/bin/weed", + "VulnerabilityID": "CVE-2026-97045", + "PkgName": "golang.org/x/net", + "InstalledVersion": "v0.61.0", + "FixedVersion": "0.62.0", + "Severity": "MEDIUM", + "Title": "golang.org/x/net/html: golang.org/x/net/html: Cross-Site Scripting via improper namespace handling during HTML rendering", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-97045" + }, + { + "target": "usr/bin/weed", + "VulnerabilityID": "CVE-2026-97054", + "PkgName": "stdlib", + "InstalledVersion": "v1.26.10", + "FixedVersion": "1.26.11, 1.27.4", + "Severity": "UNKNOWN", + "Title": "For HTTP/1 servers, when MaxBytesReader's limit is exceeded, \"Connecti ...", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-97054" + } + ] + }, + { + "service": "lb", + "image": "mirror.gcr.io/library/haproxy@sha256:b9fe316f718d5015c5cfebd8ca019591f3e44656f61d93cb8b59a1028961e530", + "image_id": "sha256:b9fe316f718d5015c5cfebd8ca019591f3e44656f61d93cb8b59a1028961e530", + "report_sha256": "61a5973b6806654fa98faf807e67b27e884f3fbbc42175f2170eea73130dbcd8", + "counts": { + "MEDIUM": 1 + }, + "findings": [ + { + "target": "/scan/image.tar (alpine 3.24.4)", + "VulnerabilityID": "CVE-2026-4738", + "PkgName": "zlib", + "InstalledVersion": "1.3.2-r1", + "FixedVersion": "1.4-r0", + "Severity": "MEDIUM", + "Title": "Improper Restriction of Operations within the Bounds of a Memory Buffe ...", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2026-4738" + } + ] + } + ] +} diff --git a/evidence/persistence.txt b/evidence/persistence.txt new file mode 100644 index 0000000..749fd29 --- /dev/null +++ b/evidence/persistence.txt @@ -0,0 +1,2 @@ +Executing explicit persistence hook; hook output suppressed to avoid leaking secrets. +PASS: persistence preserved confirmed data and existing session. Hook scope needs operator evidence. diff --git a/evidence/public-suite.txt b/evidence/public-suite.txt new file mode 100644 index 0000000..9e4207c --- /dev/null +++ b/evidence/public-suite.txt @@ -0,0 +1,9 @@ +scripts/check_contract.py: PASS +scripts/validate_openapi.py: PASS +tests/smoke.py: PASS +tests/security.py: PASS +persistence: PASS +failover-1: PASS +failover-2: PASS +failover-3: PASS +PASS: both distinct API containers failed over; all replicas restored diff --git a/evidence/publish-crl.txt b/evidence/publish-crl.txt new file mode 100644 index 0000000..24e594f --- /dev/null +++ b/evidence/publish-crl.txt @@ -0,0 +1 @@ +Operator action completed; no root token/unseal shares printed diff --git a/evidence/render-unit.txt b/evidence/render-unit.txt new file mode 100644 index 0000000..2278cc3 --- /dev/null +++ b/evidence/render-unit.txt @@ -0,0 +1,5 @@ +.... +---------------------------------------------------------------------- +Ran 4 tests in 0.217s + +OK diff --git a/evidence/restart-processes.json b/evidence/restart-processes.json new file mode 100644 index 0000000..648828a --- /dev/null +++ b/evidence/restart-processes.json @@ -0,0 +1,735 @@ +{ + "before": { + "1570e3cf0bcaf52840456fe4527c951913c184c7a910035c662fd93573f1c1c7": { + "service": "api1", + "state": { + "Status": "running", + "Running": true, + "Paused": false, + "Restarting": false, + "OOMKilled": false, + "Dead": false, + "Pid": 2835, + "ExitCode": 0, + "Error": "", + "StartedAt": "2026-11-13T09:51:55.809852669Z", + "FinishedAt": "0001-01-01T00:00:00Z", + "Health": { + "Status": "healthy", + "FailingStreak": 0, + "Log": [ + { + "Start": "2026-11-13T09:52:33.85158481Z", + "End": "2026-11-13T09:52:34.414940821Z", + "ExitCode": 0, + "Output": "" + }, + { + "Start": "2026-11-13T09:52:39.416434594Z", + "End": "2026-11-13T09:52:40.03112071Z", + "ExitCode": 0, + "Output": "" + }, + { + "Start": "2026-11-13T09:52:45.032672537Z", + "End": "2026-11-13T09:52:45.684456356Z", + "ExitCode": 0, + "Output": "" + }, + { + "Start": "2026-11-13T09:52:50.685337932Z", + "End": "2026-11-13T09:52:51.337051054Z", + "ExitCode": 0, + "Output": "" + }, + { + "Start": "2026-11-13T09:52:55.883682844Z", + "End": "2026-11-13T09:52:56.745165826Z", + "ExitCode": 0, + "Output": "" + } + ] + } + } + }, + "0a05a29d377fb35aa4676b597fa301dc1625ccfe208a7edbc6a74794659407b3": { + "service": "api2", + "state": { + "Status": "running", + "Running": true, + "Paused": false, + "Restarting": false, + "OOMKilled": false, + "Dead": false, + "Pid": 2820, + "ExitCode": 0, + "Error": "", + "StartedAt": "2026-11-13T09:51:55.797519555Z", + "FinishedAt": "0001-01-01T00:00:00Z", + "Health": { + "Status": "healthy", + "FailingStreak": 0, + "Log": [ + { + "Start": "2026-11-13T09:52:35.50023978Z", + "End": "2026-11-13T09:52:35.92798761Z", + "ExitCode": 0, + "Output": "" + }, + { + "Start": "2026-11-13T09:52:40.929156411Z", + "End": "2026-11-13T09:52:41.906797728Z", + "ExitCode": 0, + "Output": "" + }, + { + "Start": "2026-11-13T09:52:46.908309853Z", + "End": "2026-11-13T09:52:47.31147321Z", + "ExitCode": 0, + "Output": "" + }, + { + "Start": "2026-11-13T09:52:51.873454972Z", + "End": "2026-11-13T09:52:52.395517815Z", + "ExitCode": 0, + "Output": "" + }, + { + "Start": "2026-11-13T09:52:57.397494814Z", + "End": "2026-11-13T09:52:57.897562413Z", + "ExitCode": 0, + "Output": "" + } + ] + } + } + }, + "76e0e9ee11f2acd4202aa4641b07c2af83558e6726dd26a3521b33bb520cf177": { + "service": "db", + "state": { + "Status": "running", + "Running": true, + "Paused": false, + "Restarting": false, + "OOMKilled": false, + "Dead": false, + "Pid": 755, + "ExitCode": 0, + "Error": "", + "StartedAt": "2026-11-13T09:51:20.83333691Z", + "FinishedAt": "2026-11-13T09:50:28.225155745Z", + "Health": { + "Status": "healthy", + "FailingStreak": 0, + "Log": [ + { + "Start": "2026-11-13T09:52:50.379763185Z", + "End": "2026-11-13T09:52:50.456684316Z", + "ExitCode": 0, + "Output": "/var/run/postgresql:5432 - accepting connections\n" + }, + { + "Start": "2026-11-13T09:52:52.018791868Z", + "End": "2026-11-13T09:52:52.157704126Z", + "ExitCode": 0, + "Output": "/var/run/postgresql:5432 - accepting connections\n" + }, + { + "Start": "2026-11-13T09:52:54.159668931Z", + "End": "2026-11-13T09:52:54.239425636Z", + "ExitCode": 0, + "Output": "/var/run/postgresql:5432 - accepting connections\n" + }, + { + "Start": "2026-11-13T09:52:56.241459415Z", + "End": "2026-11-13T09:52:56.374718752Z", + "ExitCode": 0, + "Output": "/var/run/postgresql:5432 - accepting connections\n" + }, + { + "Start": "2026-11-13T09:52:58.375876362Z", + "End": "2026-11-13T09:52:58.425063406Z", + "ExitCode": 0, + "Output": "/var/run/postgresql:5432 - accepting connections\n" + } + ] + } + } + }, + "051a2a59f89f08acf5878b6ab22e2ad389bc09d4fa3d655604f27375b26922be": { + "service": "cache", + "state": { + "Status": "running", + "Running": true, + "Paused": false, + "Restarting": false, + "OOMKilled": false, + "Dead": false, + "Pid": 840, + "ExitCode": 0, + "Error": "", + "StartedAt": "2026-11-13T09:51:21.347055009Z", + "FinishedAt": "2026-11-13T09:50:28.224207664Z" + } + }, + "c0e3fc648ea6a23b643a0104ad9bf93f06bfd45e592fece24d8c4dc8788dc494": { + "service": "lb", + "state": { + "Status": "running", + "Running": true, + "Paused": false, + "Restarting": false, + "OOMKilled": false, + "Dead": false, + "Pid": 2892, + "ExitCode": 0, + "Error": "", + "StartedAt": "2026-11-13T09:51:55.925530847Z", + "FinishedAt": "2026-11-13T09:50:28.222150955Z" + } + }, + "68c83b0d029545c4c8bfa67979e23fda461d7b9aea909d5e99e462f4858fcc1a": { + "service": "s3", + "state": { + "Status": "running", + "Running": true, + "Paused": false, + "Restarting": false, + "OOMKilled": false, + "Dead": false, + "Pid": 863, + "ExitCode": 0, + "Error": "", + "StartedAt": "2026-11-13T09:51:21.411682013Z", + "FinishedAt": "2026-11-13T09:50:28.225741755Z" + } + }, + "6db578724c16067c9101d8ffb911ae3bb1127c087e0b8a598c958983914676a7": { + "service": "reconciler", + "state": { + "Status": "running", + "Running": true, + "Paused": false, + "Restarting": false, + "OOMKilled": false, + "Dead": false, + "Pid": 2676, + "ExitCode": 0, + "Error": "", + "StartedAt": "2026-11-13T09:51:55.784764196Z", + "FinishedAt": "0001-01-01T00:00:00Z" + } + }, + "362e538c9c53fa7feb054689ed85f862d070518a168c0efaa6e184ad51bd34f5": { + "service": "broker", + "state": { + "Status": "running", + "Running": true, + "Paused": false, + "Restarting": false, + "OOMKilled": false, + "Dead": false, + "Pid": 879, + "ExitCode": 0, + "Error": "", + "StartedAt": "2026-11-13T09:51:21.392114019Z", + "FinishedAt": "2026-11-13T09:50:28.224003528Z" + } + }, + "2e513af66f171401771b1a3680154f7edfc7472a5ee79e94041256efee78b2f0": { + "service": "worker", + "state": { + "Status": "running", + "Running": true, + "Paused": false, + "Restarting": false, + "OOMKilled": false, + "Dead": false, + "Pid": 2709, + "ExitCode": 0, + "Error": "", + "StartedAt": "2026-11-13T09:51:55.951329668Z", + "FinishedAt": "0001-01-01T00:00:00Z" + } + }, + "c40815a4d87373db33cf7eb4b89d473b853dd7a9ece81fa73e052da54ced5ff4": { + "service": "dispatcher", + "state": { + "Status": "running", + "Running": true, + "Paused": false, + "Restarting": false, + "OOMKilled": false, + "Dead": false, + "Pid": 2629, + "ExitCode": 0, + "Error": "", + "StartedAt": "2026-11-13T09:51:55.684909892Z", + "FinishedAt": "0001-01-01T00:00:00Z" + } + }, + "ea547f7d390f190c74b9f60d5be466be91924df7ead9930e916f0e5bf9161ae0": { + "service": "openbao", + "state": { + "Status": "running", + "Running": true, + "Paused": false, + "Restarting": false, + "OOMKilled": false, + "Dead": false, + "Pid": 940, + "ExitCode": 0, + "Error": "", + "StartedAt": "2026-11-13T09:51:21.574158786Z", + "FinishedAt": "2026-11-13T09:50:28.217091485Z" + } + }, + "c605ad2ea7cfb8fdc37b85d5e8df440c0f9dfb1ba8317a8b87d84ce5ff38e2cb": { + "service": "otel-collector", + "state": { + "Status": "running", + "Running": true, + "Paused": false, + "Restarting": false, + "OOMKilled": false, + "Dead": false, + "Pid": 2156, + "ExitCode": 0, + "Error": "", + "StartedAt": "2026-11-13T09:51:52.584501439Z", + "FinishedAt": "2026-11-13T09:50:28.224053739Z" + } + }, + "9b54b82ecd93b601a0ea977adedef1b81a1ff36eb925ab730684320a22113141": { + "service": "prometheus", + "state": { + "Status": "running", + "Running": true, + "Paused": false, + "Restarting": false, + "OOMKilled": false, + "Dead": false, + "Pid": 2352, + "ExitCode": 0, + "Error": "", + "StartedAt": "2026-11-13T09:51:53.97192011Z", + "FinishedAt": "2026-11-13T09:50:28.223361176Z" + } + }, + "72ece8cb2659be6a83a2516dcb19b472d4ab9d6d1b50f20eca4f49799cd17131": { + "service": "loki", + "state": { + "Status": "running", + "Running": true, + "Paused": false, + "Restarting": false, + "OOMKilled": false, + "Dead": false, + "Pid": 2359, + "ExitCode": 0, + "Error": "", + "StartedAt": "2026-11-13T09:51:54.028034454Z", + "FinishedAt": "2026-11-13T09:50:28.224411699Z" + } + }, + "574869ba08c1a34d0d30fa2da1e61c5a35dd66ee35afff36d18366e33658e621": { + "service": "tempo", + "state": { + "Status": "running", + "Running": true, + "Paused": false, + "Restarting": false, + "OOMKilled": false, + "Dead": false, + "Pid": 2288, + "ExitCode": 0, + "Error": "", + "StartedAt": "2026-11-13T09:51:53.935285487Z", + "FinishedAt": "2026-11-13T09:50:28.224318796Z" + } + }, + "4ed391665684b152c494235932554b04ed24e82fc7213219f6cfc1dc54c3e4db": { + "service": "grafana", + "state": { + "Status": "running", + "Running": true, + "Paused": false, + "Restarting": false, + "OOMKilled": false, + "Dead": false, + "Pid": 2946, + "ExitCode": 0, + "Error": "", + "StartedAt": "2026-11-13T09:51:56.097459745Z", + "FinishedAt": "2026-11-13T09:50:28.225512752Z" + } + } + }, + "after": { + "1570e3cf0bcaf52840456fe4527c951913c184c7a910035c662fd93573f1c1c7": { + "service": "api1", + "state": { + "Status": "running", + "Running": true, + "Paused": false, + "Restarting": false, + "OOMKilled": false, + "Dead": false, + "Pid": 6310, + "ExitCode": 0, + "Error": "", + "StartedAt": "2026-11-13T09:53:15.810798832Z", + "FinishedAt": "2026-11-13T09:53:06.716904603Z", + "Health": { + "Status": "starting", + "FailingStreak": 0, + "Log": [ + { + "Start": "2026-11-13T09:52:45.032672537Z", + "End": "2026-11-13T09:52:45.684456356Z", + "ExitCode": 0, + "Output": "" + }, + { + "Start": "2026-11-13T09:52:50.685337932Z", + "End": "2026-11-13T09:52:51.337051054Z", + "ExitCode": 0, + "Output": "" + }, + { + "Start": "2026-11-13T09:52:55.883682844Z", + "End": "2026-11-13T09:52:56.745165826Z", + "ExitCode": 0, + "Output": "" + }, + { + "Start": "2026-11-13T09:53:01.746116416Z", + "End": "2026-11-13T09:53:02.250230395Z", + "ExitCode": 0, + "Output": "" + }, + { + "Start": "2026-11-13T09:53:21.941393572Z", + "End": "2026-11-13T09:53:25.757437396Z", + "ExitCode": 1, + "Output": "Traceback (most recent call last):\n File \"/usr/local/lib/python3.12/urllib/request.py\", line 1357, in do_open\n h.request(req.get_method(), req.selector, req.data, headers,\n File \"/usr/local/lib/python3.12/http/client.py\", line 1386, in request\n self._send_request(method, url, body, headers, encode_chunked)\n File \"/usr/local/lib/python3.12/http/client.py\", line 1432, in _send_request\n self.endheaders(body, encode_chunked=encode_chunked)\n File \"/usr/local/lib/python3.12/http/client.py\", line 1381, in endheaders\n self._send_output(message_body, encode_chunked=encode_chunked)\n File \"/usr/local/lib/python3.12/http/client.py\", line 1141, in _send_output\n self.send(msg)\n File \"/usr/local/lib/python3.12/http/client.py\", line 1085, in send\n self.connect()\n File \"/usr/local/lib/python3.12/http/client.py\", line 1051, in connect\n self.sock = self._create_connection(\n ^^^^^^^^^^^^^^^^^^^^^^^^\n File \"/usr/local/lib/python3.12/socket.py\", line 865, in create_connection\n raise exceptions[0]\n File \"/usr/local/lib/python3.12/socket.py\", line 850, in create_connection\n sock.connect(sa)\nConnectionRefusedError: [Errno 111] Connection refused\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n File \"\", line 1, in \n File \"/usr/local/lib/python3.12/urllib/request.py\", line 215, in urlopen\n return opener.open(url, data, timeout)\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"/usr/local/lib/python3.12/urllib/request.py\", line 515, in open\n response = self._open(req, data)\n ^^^^^^^^^^^^^^^^^^^^^\n File \"/usr/local/lib/python3.12/urllib/request.py\", line 532, in _open\n result = self._call_chain(self.handle_open, protocol, protocol +\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"/usr/local/lib/python3.12/urllib/request.py\", line 492, in _call_chain\n result = func(*args)\n ^^^^^^^^^^^\n File \"/usr/local/lib/python3.12/urllib/request.py\", line 1386, in http_open\n return self.do_open(http.client.HTTPConnection, req)\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"/usr/local/lib/python3.12/urllib/request.py\", line 1360, in do_open\n raise URLError(err)\nurllib.error.URLError: \n" + } + ] + } + } + }, + "0a05a29d377fb35aa4676b597fa301dc1625ccfe208a7edbc6a74794659407b3": { + "service": "api2", + "state": { + "Status": "running", + "Running": true, + "Paused": false, + "Restarting": false, + "OOMKilled": false, + "Dead": false, + "Pid": 6454, + "ExitCode": 0, + "Error": "", + "StartedAt": "2026-11-13T09:53:15.906757854Z", + "FinishedAt": "2026-11-13T09:53:08.979949677Z", + "Health": { + "Status": "starting", + "FailingStreak": 0, + "Log": [ + { + "Start": "2026-11-13T09:52:46.908309853Z", + "End": "2026-11-13T09:52:47.31147321Z", + "ExitCode": 0, + "Output": "" + }, + { + "Start": "2026-11-13T09:52:51.873454972Z", + "End": "2026-11-13T09:52:52.395517815Z", + "ExitCode": 0, + "Output": "" + }, + { + "Start": "2026-11-13T09:52:57.397494814Z", + "End": "2026-11-13T09:52:57.897562413Z", + "ExitCode": 0, + "Output": "" + }, + { + "Start": "2026-11-13T09:53:02.902817408Z", + "End": "2026-11-13T09:53:06.233524775Z", + "ExitCode": 1, + "Output": "Traceback (most recent call last):\n File \"\", line 1, in \n File \"/usr/local/lib/python3.12/urllib/request.py\", line 215, in urlopen\n return opener.open(url, data, timeout)\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"/usr/local/lib/python3.12/urllib/request.py\", line 521, in open\n response = meth(req, response)\n ^^^^^^^^^^^^^^^^^^^\n File \"/usr/local/lib/python3.12/urllib/request.py\", line 630, in http_response\n response = self.parent.error(\n ^^^^^^^^^^^^^^^^^^\n File \"/usr/local/lib/python3.12/urllib/request.py\", line 559, in error\n return self._call_chain(*args)\n ^^^^^^^^^^^^^^^^^^^^^^^\n File \"/usr/local/lib/python3.12/urllib/request.py\", line 492, in _call_chain\n result = func(*args)\n ^^^^^^^^^^^\n File \"/usr/local/lib/python3.12/urllib/request.py\", line 639, in http_error_default\n raise HTTPError(req.full_url, code, msg, hdrs, fp)\nurllib.error.HTTPError: HTTP Error 503: Service Unavailable\n" + }, + { + "Start": "2026-11-13T09:53:22.46715569Z", + "End": "2026-11-13T09:53:25.869837051Z", + "ExitCode": 1, + "Output": "Traceback (most recent call last):\n File \"/usr/local/lib/python3.12/urllib/request.py\", line 1357, in do_open\n h.request(req.get_method(), req.selector, req.data, headers,\n File \"/usr/local/lib/python3.12/http/client.py\", line 1386, in request\n self._send_request(method, url, body, headers, encode_chunked)\n File \"/usr/local/lib/python3.12/http/client.py\", line 1432, in _send_request\n self.endheaders(body, encode_chunked=encode_chunked)\n File \"/usr/local/lib/python3.12/http/client.py\", line 1381, in endheaders\n self._send_output(message_body, encode_chunked=encode_chunked)\n File \"/usr/local/lib/python3.12/http/client.py\", line 1141, in _send_output\n self.send(msg)\n File \"/usr/local/lib/python3.12/http/client.py\", line 1085, in send\n self.connect()\n File \"/usr/local/lib/python3.12/http/client.py\", line 1051, in connect\n self.sock = self._create_connection(\n ^^^^^^^^^^^^^^^^^^^^^^^^\n File \"/usr/local/lib/python3.12/socket.py\", line 865, in create_connection\n raise exceptions[0]\n File \"/usr/local/lib/python3.12/socket.py\", line 850, in create_connection\n sock.connect(sa)\nConnectionRefusedError: [Errno 111] Connection refused\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n File \"\", line 1, in \n File \"/usr/local/lib/python3.12/urllib/request.py\", line 215, in urlopen\n return opener.open(url, data, timeout)\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"/usr/local/lib/python3.12/urllib/request.py\", line 515, in open\n response = self._open(req, data)\n ^^^^^^^^^^^^^^^^^^^^^\n File \"/usr/local/lib/python3.12/urllib/request.py\", line 532, in _open\n result = self._call_chain(self.handle_open, protocol, protocol +\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"/usr/local/lib/python3.12/urllib/request.py\", line 492, in _call_chain\n result = func(*args)\n ^^^^^^^^^^^\n File \"/usr/local/lib/python3.12/urllib/request.py\", line 1386, in http_open\n return self.do_open(http.client.HTTPConnection, req)\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"/usr/local/lib/python3.12/urllib/request.py\", line 1360, in do_open\n raise URLError(err)\nurllib.error.URLError: \n" + } + ] + } + } + }, + "76e0e9ee11f2acd4202aa4641b07c2af83558e6726dd26a3521b33bb520cf177": { + "service": "db", + "state": { + "Status": "running", + "Running": true, + "Paused": false, + "Restarting": false, + "OOMKilled": false, + "Dead": false, + "Pid": 5985, + "ExitCode": 0, + "Error": "", + "StartedAt": "2026-11-13T09:53:14.810659332Z", + "FinishedAt": "2026-11-13T09:53:05.266445865Z", + "Health": { + "Status": "healthy", + "FailingStreak": 0, + "Log": [ + { + "Start": "2026-11-13T09:53:02.49033307Z", + "End": "2026-11-13T09:53:02.543395178Z", + "ExitCode": 0, + "Output": "/var/run/postgresql:5432 - accepting connections\n" + }, + { + "Start": "2026-11-13T09:53:04.54387538Z", + "End": "2026-11-13T09:53:05.068330917Z", + "ExitCode": 1, + "Output": "/var/run/postgresql:5432 - rejecting connections\n" + }, + { + "Start": "2026-11-13T09:53:18.178982393Z", + "End": "2026-11-13T09:53:20.786679419Z", + "ExitCode": 0, + "Output": "/var/run/postgresql:5432 - accepting connections\n" + }, + { + "Start": "2026-11-13T09:53:22.800575887Z", + "End": "2026-11-13T09:53:24.416791098Z", + "ExitCode": 0, + "Output": "/var/run/postgresql:5432 - accepting connections\n" + }, + { + "Start": "2026-11-13T09:53:26.420377151Z", + "End": "2026-11-13T09:53:26.842575441Z", + "ExitCode": 0, + "Output": "/var/run/postgresql:5432 - accepting connections\n" + } + ] + } + } + }, + "051a2a59f89f08acf5878b6ab22e2ad389bc09d4fa3d655604f27375b26922be": { + "service": "cache", + "state": { + "Status": "running", + "Running": true, + "Paused": false, + "Restarting": false, + "OOMKilled": false, + "Dead": false, + "Pid": 6487, + "ExitCode": 0, + "Error": "", + "StartedAt": "2026-11-13T09:53:15.945227154Z", + "FinishedAt": "2026-11-13T09:53:05.04199852Z" + } + }, + "c0e3fc648ea6a23b643a0104ad9bf93f06bfd45e592fece24d8c4dc8788dc494": { + "service": "lb", + "state": { + "Status": "running", + "Running": true, + "Paused": false, + "Restarting": false, + "OOMKilled": false, + "Dead": false, + "Pid": 6479, + "ExitCode": 0, + "Error": "", + "StartedAt": "2026-11-13T09:53:15.9062729Z", + "FinishedAt": "2026-11-13T09:53:03.909611163Z" + } + }, + "68c83b0d029545c4c8bfa67979e23fda461d7b9aea909d5e99e462f4858fcc1a": { + "service": "s3", + "state": { + "Status": "running", + "Running": true, + "Paused": false, + "Restarting": false, + "OOMKilled": false, + "Dead": false, + "Pid": 6375, + "ExitCode": 0, + "Error": "", + "StartedAt": "2026-11-13T09:53:15.849272466Z", + "FinishedAt": "2026-11-13T09:53:10.186208925Z" + } + }, + "6db578724c16067c9101d8ffb911ae3bb1127c087e0b8a598c958983914676a7": { + "service": "reconciler", + "state": { + "Status": "running", + "Running": true, + "Paused": false, + "Restarting": false, + "OOMKilled": false, + "Dead": false, + "Pid": 6191, + "ExitCode": 0, + "Error": "", + "StartedAt": "2026-11-13T09:53:15.708018867Z", + "FinishedAt": "2026-11-13T09:53:09.175300496Z" + } + }, + "362e538c9c53fa7feb054689ed85f862d070518a168c0efaa6e184ad51bd34f5": { + "service": "broker", + "state": { + "Status": "running", + "Running": true, + "Paused": false, + "Restarting": false, + "OOMKilled": false, + "Dead": false, + "Pid": 6125, + "ExitCode": 0, + "Error": "", + "StartedAt": "2026-11-13T09:53:15.753030573Z", + "FinishedAt": "2026-11-13T09:53:05.167583954Z" + } + }, + "2e513af66f171401771b1a3680154f7edfc7472a5ee79e94041256efee78b2f0": { + "service": "worker", + "state": { + "Status": "running", + "Running": true, + "Paused": false, + "Restarting": false, + "OOMKilled": false, + "Dead": false, + "Pid": 6437, + "ExitCode": 0, + "Error": "", + "StartedAt": "2026-11-13T09:53:15.870744073Z", + "FinishedAt": "2026-11-13T09:53:09.192037057Z" + } + }, + "c40815a4d87373db33cf7eb4b89d473b853dd7a9ece81fa73e052da54ced5ff4": { + "service": "dispatcher", + "state": { + "Status": "running", + "Running": true, + "Paused": false, + "Restarting": false, + "OOMKilled": false, + "Dead": false, + "Pid": 6311, + "ExitCode": 0, + "Error": "", + "StartedAt": "2026-11-13T09:53:15.806673713Z", + "FinishedAt": "2026-11-13T09:53:09.581490205Z" + } + }, + "ea547f7d390f190c74b9f60d5be466be91924df7ead9930e916f0e5bf9161ae0": { + "service": "openbao", + "state": { + "Status": "running", + "Running": true, + "Paused": false, + "Restarting": false, + "OOMKilled": false, + "Dead": false, + "Pid": 6517, + "ExitCode": 0, + "Error": "", + "StartedAt": "2026-11-13T09:53:15.911866476Z", + "FinishedAt": "2026-11-13T09:53:03.972241104Z" + } + }, + "c605ad2ea7cfb8fdc37b85d5e8df440c0f9dfb1ba8317a8b87d84ce5ff38e2cb": { + "service": "otel-collector", + "state": { + "Status": "running", + "Running": true, + "Paused": false, + "Restarting": false, + "OOMKilled": false, + "Dead": false, + "Pid": 5717, + "ExitCode": 0, + "Error": "", + "StartedAt": "2026-11-13T09:53:13.768718976Z", + "FinishedAt": "2026-11-13T09:53:05.062618953Z" + } + }, + "9b54b82ecd93b601a0ea977adedef1b81a1ff36eb925ab730684320a22113141": { + "service": "prometheus", + "state": { + "Status": "running", + "Running": true, + "Paused": false, + "Restarting": false, + "OOMKilled": false, + "Dead": false, + "Pid": 5926, + "ExitCode": 0, + "Error": "", + "StartedAt": "2026-11-13T09:53:14.756925187Z", + "FinishedAt": "2026-11-13T09:53:05.244841875Z" + } + }, + "72ece8cb2659be6a83a2516dcb19b472d4ab9d6d1b50f20eca4f49799cd17131": { + "service": "loki", + "state": { + "Status": "running", + "Running": true, + "Paused": false, + "Restarting": false, + "OOMKilled": false, + "Dead": false, + "Pid": 5961, + "ExitCode": 0, + "Error": "", + "StartedAt": "2026-11-13T09:53:14.793956064Z", + "FinishedAt": "2026-11-13T09:53:05.416062037Z" + } + }, + "574869ba08c1a34d0d30fa2da1e61c5a35dd66ee35afff36d18366e33658e621": { + "service": "tempo", + "state": { + "Status": "running", + "Running": true, + "Paused": false, + "Restarting": false, + "OOMKilled": false, + "Dead": false, + "Pid": 5958, + "ExitCode": 0, + "Error": "", + "StartedAt": "2026-11-13T09:53:14.761611926Z", + "FinishedAt": "2026-11-13T09:53:05.299312685Z" + } + }, + "4ed391665684b152c494235932554b04ed24e82fc7213219f6cfc1dc54c3e4db": { + "service": "grafana", + "state": { + "Status": "running", + "Running": true, + "Paused": false, + "Restarting": false, + "OOMKilled": false, + "Dead": false, + "Pid": 6442, + "ExitCode": 0, + "Error": "", + "StartedAt": "2026-11-13T09:53:15.90242133Z", + "FinishedAt": "2026-11-13T09:53:05.770095425Z" + } + } + }, + "volumes_removed": false +} diff --git a/evidence/sealed-bao-run.txt b/evidence/sealed-bao-run.txt new file mode 100644 index 0000000..6c0caba --- /dev/null +++ b/evidence/sealed-bao-run.txt @@ -0,0 +1,2 @@ +Operator action completed; no root token/unseal shares printed +PASS: sealed Bao -> finite lease -> both API children stopped -> unseal -> recovery diff --git a/evidence/sealed-bao.json b/evidence/sealed-bao.json new file mode 100644 index 0000000..52dd1f3 --- /dev/null +++ b/evidence/sealed-bao.json @@ -0,0 +1,254 @@ +{ + "passed": true, + "secret_refresh_seconds": 20, + "token_max_TTL_seconds": 120, + "both_API_children_stopped_seconds": 123.86, + "recovery_seconds": 20.44, + "observations": [ + { + "seconds": 1.3, + "HTTP": 200 + }, + { + "seconds": 3.3, + "HTTP": 200 + }, + { + "seconds": 5.4, + "HTTP": 200 + }, + { + "seconds": 7.4, + "HTTP": 200 + }, + { + "seconds": 9.4, + "HTTP": 200 + }, + { + "seconds": 11.5, + "HTTP": 200 + }, + { + "seconds": 13.5, + "HTTP": 200 + }, + { + "seconds": 15.5, + "HTTP": 200 + }, + { + "seconds": 17.5, + "HTTP": 200 + }, + { + "seconds": 19.6, + "HTTP": 200 + }, + { + "seconds": 21.6, + "HTTP": 200 + }, + { + "seconds": 23.6, + "HTTP": 200 + }, + { + "seconds": 25.7, + "HTTP": 200 + }, + { + "seconds": 27.7, + "HTTP": 200 + }, + { + "seconds": 29.7, + "HTTP": 200 + }, + { + "seconds": 31.8, + "HTTP": 200 + }, + { + "seconds": 33.8, + "HTTP": 200 + }, + { + "seconds": 35.8, + "HTTP": 200 + }, + { + "seconds": 37.9, + "HTTP": 200 + }, + { + "seconds": 39.9, + "HTTP": 200 + }, + { + "seconds": 42.0, + "HTTP": 200 + }, + { + "seconds": 44.0, + "HTTP": 200 + }, + { + "seconds": 46.0, + "HTTP": 200 + }, + { + "seconds": 48.0, + "HTTP": 200 + }, + { + "seconds": 50.1, + "HTTP": 200 + }, + { + "seconds": 52.1, + "HTTP": 200 + }, + { + "seconds": 54.1, + "HTTP": 200 + }, + { + "seconds": 56.2, + "HTTP": 200 + }, + { + "seconds": 58.2, + "HTTP": 200 + }, + { + "seconds": 60.2, + "HTTP": 200 + }, + { + "seconds": 62.3, + "HTTP": 200 + }, + { + "seconds": 64.3, + "HTTP": 200 + }, + { + "seconds": 66.3, + "HTTP": 200 + }, + { + "seconds": 68.4, + "HTTP": 200 + }, + { + "seconds": 70.4, + "HTTP": 200 + }, + { + "seconds": 72.4, + "HTTP": 200 + }, + { + "seconds": 74.5, + "HTTP": 200 + }, + { + "seconds": 76.5, + "HTTP": 200 + }, + { + "seconds": 78.5, + "HTTP": 200 + }, + { + "seconds": 80.5, + "HTTP": 200 + }, + { + "seconds": 82.6, + "HTTP": 200 + }, + { + "seconds": 84.6, + "HTTP": 200 + }, + { + "seconds": 86.7, + "HTTP": 200 + }, + { + "seconds": 88.7, + "HTTP": 200 + }, + { + "seconds": 90.8, + "HTTP": 200 + }, + { + "seconds": 92.8, + "HTTP": 200 + }, + { + "seconds": 94.8, + "HTTP": 200 + }, + { + "seconds": 96.8, + "HTTP": 200 + }, + { + "seconds": 98.8, + "HTTP": 200 + }, + { + "seconds": 100.9, + "HTTP": 200 + }, + { + "seconds": 102.9, + "HTTP": 200 + }, + { + "seconds": 104.9, + "HTTP": 200 + }, + { + "seconds": 107.0, + "HTTP": 200 + }, + { + "seconds": 109.0, + "HTTP": 200 + }, + { + "seconds": 111.0, + "HTTP": 200 + }, + { + "seconds": 113.1, + "HTTP": 200 + }, + { + "seconds": 115.1, + "HTTP": 200 + }, + { + "seconds": 117.1, + "HTTP": 200 + }, + { + "seconds": 119.2, + "HTTP": 502 + }, + { + "seconds": 121.2, + "HTTP": 502 + }, + { + "seconds": 123.2, + "HTTP": 503 + } + ], + "scope": "Supervisor bounds use during Bao outage; static backend passwords themselves require explicit rotation." +} diff --git a/evidence/security-api-run.txt b/evidence/security-api-run.txt new file mode 100644 index 0000000..0eac407 --- /dev/null +++ b/evidence/security-api-run.txt @@ -0,0 +1 @@ +PASS: ACL, expiry/logout, hash storage/rehash, shared 12/10s rate limit, measured Argon2 diff --git a/evidence/security-api.json b/evidence/security-api.json new file mode 100644 index 0000000..5ea52c5 --- /dev/null +++ b/evidence/security-api.json @@ -0,0 +1,131 @@ +{ + "passed": true, + "ACL_attachment_denials": 4, + "expired_session_denied": true, + "logout_denied": true, + "token_hash_sha256": true, + "rehash": "19456 -> 32768 KiB", + "login_burst": [ + { + "status": 401, + "seconds": 2.891, + "instance": "9a29628cf7004fbfb295d86c41370777" + }, + { + "status": 429, + "seconds": 0.453, + "instance": "9a29628cf7004fbfb295d86c41370777" + }, + { + "status": 401, + "seconds": 4.078, + "instance": "8f1af19439ef4f8d9dbd95d4400217f7" + }, + { + "status": 401, + "seconds": 3.094, + "instance": "9a29628cf7004fbfb295d86c41370777" + }, + { + "status": 429, + "seconds": 0.281, + "instance": "9a29628cf7004fbfb295d86c41370777" + }, + { + "status": 401, + "seconds": 3.188, + "instance": "8f1af19439ef4f8d9dbd95d4400217f7" + }, + { + "status": 401, + "seconds": 3.375, + "instance": "9a29628cf7004fbfb295d86c41370777" + }, + { + "status": 429, + "seconds": 0.281, + "instance": "9a29628cf7004fbfb295d86c41370777" + }, + { + "status": 401, + "seconds": 2.11, + "instance": "8f1af19439ef4f8d9dbd95d4400217f7" + }, + { + "status": 401, + "seconds": 3.891, + "instance": "8f1af19439ef4f8d9dbd95d4400217f7" + }, + { + "status": 401, + "seconds": 4.547, + "instance": "8f1af19439ef4f8d9dbd95d4400217f7" + }, + { + "status": 401, + "seconds": 4.062, + "instance": "9a29628cf7004fbfb295d86c41370777" + }, + { + "status": 401, + "seconds": 3.781, + "instance": "9a29628cf7004fbfb295d86c41370777" + }, + { + "status": 429, + "seconds": 0.5, + "instance": "8f1af19439ef4f8d9dbd95d4400217f7" + }, + { + "status": 429, + "seconds": 0.531, + "instance": "9a29628cf7004fbfb295d86c41370777" + }, + { + "status": 401, + "seconds": 3.125, + "instance": "8f1af19439ef4f8d9dbd95d4400217f7" + }, + { + "status": 429, + "seconds": 0.39, + "instance": "8f1af19439ef4f8d9dbd95d4400217f7" + }, + { + "status": 401, + "seconds": 4.453, + "instance": "8f1af19439ef4f8d9dbd95d4400217f7" + }, + { + "status": 429, + "seconds": 0.39, + "instance": "9a29628cf7004fbfb295d86c41370777" + }, + { + "status": 429, + "seconds": 0.453, + "instance": "8f1af19439ef4f8d9dbd95d4400217f7" + } + ], + "burst_seconds": 4.578, + "KDF": { + "hash_plus_verify_seconds": [ + 0.21583701900004826, + 0.20667367100003275, + 0.22015716700002486, + 0.193256392999956, + 0.20241064300000744, + 0.20739852500003053, + 0.20553775699994503, + 0.2716375199999561, + 0.2128679730000158, + 0.22063045700002704, + 0.20332950599998867, + 0.20581266300001744 + ], + "median": 0.20703609800003164, + "max_rss_kib": 53184 + }, + "KDF_slots_per_API": 2, + "KDF_memory_bound_two_APIs_MiB": 128 +} diff --git a/evidence/security-suite.json b/evidence/security-suite.json new file mode 100644 index 0000000..66f9b59 --- /dev/null +++ b/evidence/security-suite.json @@ -0,0 +1,4 @@ +{ + "passed": true, + "completed_at_UTC": "2026-11-13T10:00:37.671336+00:00" +} diff --git a/evidence/security-suite.txt b/evidence/security-suite.txt new file mode 100644 index 0000000..729645e --- /dev/null +++ b/evidence/security-suite.txt @@ -0,0 +1,11 @@ +generate-test-identities: PASS +publish-crl: PASS +tls-matrix: PASS +bao-policy: PASS +worker-rights: PASS +security-api-run: PASS +compromised-worker-run: PASS +sealed-bao-run: PASS +telemetry-security-run: PASS +hardening-run: PASS +render-unit: PASS diff --git a/evidence/security.txt b/evidence/security.txt new file mode 100644 index 0000000..ff2e222 --- /dev/null +++ b/evidence/security.txt @@ -0,0 +1 @@ +PASS: trusted HTTPS works; untrusted CA rejected. This does NOT verify internal mTLS, OpenBao or hardening. diff --git a/evidence/smoke.txt b/evidence/smoke.txt new file mode 100644 index 0000000..b484213 --- /dev/null +++ b/evidence/smoke.txt @@ -0,0 +1 @@ +PASS: lab7 public API scenario; infrastructure and grading evidence remain separate. diff --git a/evidence/stop-one.json b/evidence/stop-one.json new file mode 100644 index 0000000..2b3e12e --- /dev/null +++ b/evidence/stop-one.json @@ -0,0 +1,11 @@ +{ + "target_instance": "932b533b493e4dab8e09817e66f77901", + "stopped_container": "1570e3cf0bcaf52840456fe4527c951913c184c7a910035c662fd93573f1c1c7", + "before_containers": [ + "1570e3cf0bcaf52840456fe4527c951913c184c7a910035c662fd93573f1c1c7", + "0a05a29d377fb35aa4676b597fa301dc1625ccfe208a7edbc6a74794659407b3" + ], + "after_running_containers": [ + "0a05a29d377fb35aa4676b597fa301dc1625ccfe208a7edbc6a74794659407b3" + ] +} diff --git a/evidence/telemetry-security-run.txt b/evidence/telemetry-security-run.txt new file mode 100644 index 0000000..b54e70f --- /dev/null +++ b/evidence/telemetry-security-run.txt @@ -0,0 +1 @@ +PASS: TLS metrics/traces/log correlation, credential canaries absent in telemetry/container logs diff --git a/evidence/telemetry-security.json b/evidence/telemetry-security.json new file mode 100644 index 0000000..cbf5375 --- /dev/null +++ b/evidence/telemetry-security.json @@ -0,0 +1,21 @@ +{ + "passed": true, + "trace_id": "918070f9c17e4f2b9b8e079df1824a06", + "span_count": 13, + "span_names": [ + "POST /api/v1/chats/{chat_id}/attachments", + "attachment.consume", + "attachment.durable_accept", + "attachment.publish", + "db.attachment.commit", + "db.session.authenticate", + "image.render", + "s3.get", + "s3.put" + ], + "correlated_log_count": 3, + "http_metric_series": 26, + "credential_canaries_absent": true, + "all_queries": "mTLS verified operator identity", + "container_logs_canaries_absent": true +} diff --git a/evidence/tls-matrix.json b/evidence/tls-matrix.json new file mode 100644 index 0000000..7be97b9 --- /dev/null +++ b/evidence/tls-matrix.json @@ -0,0 +1,397 @@ +{ + "passed": true, + "seconds": 2.49, + "edges": [ + { + "source": "lb", + "destination": "api1", + "port": 8443, + "allowed": true + }, + { + "destination": "api1", + "port": 8443, + "denied": [ + "no_cert", + "wrong_CA", + "wrong_SAN", + "expired", + "revoked", + "wrong_server_SAN", + "plaintext" + ] + }, + { + "source": "lb", + "destination": "api2", + "port": 8443, + "allowed": true + }, + { + "destination": "api2", + "port": 8443, + "denied": [ + "no_cert", + "wrong_CA", + "wrong_SAN", + "expired", + "revoked", + "wrong_server_SAN", + "plaintext" + ] + }, + { + "source": "worker", + "destination": "broker", + "port": 8443, + "allowed": true + }, + { + "source": "dispatcher", + "destination": "broker", + "port": 8443, + "allowed": true + }, + { + "source": "operator", + "destination": "broker", + "port": 8443, + "allowed": true + }, + { + "destination": "broker", + "port": 8443, + "denied": [ + "no_cert", + "wrong_CA", + "wrong_SAN", + "expired", + "revoked", + "wrong_server_SAN", + "plaintext" + ] + }, + { + "source": "api1", + "destination": "cache", + "port": 8443, + "allowed": true + }, + { + "source": "api2", + "destination": "cache", + "port": 8443, + "allowed": true + }, + { + "source": "operator", + "destination": "cache", + "port": 8443, + "allowed": true + }, + { + "destination": "cache", + "port": 8443, + "denied": [ + "no_cert", + "wrong_CA", + "wrong_SAN", + "expired", + "revoked", + "wrong_server_SAN", + "plaintext" + ] + }, + { + "source": "api1", + "destination": "db", + "port": 8443, + "allowed": true + }, + { + "source": "api2", + "destination": "db", + "port": 8443, + "allowed": true + }, + { + "source": "worker", + "destination": "db", + "port": 8443, + "allowed": true + }, + { + "source": "dispatcher", + "destination": "db", + "port": 8443, + "allowed": true + }, + { + "source": "reconciler", + "destination": "db", + "port": 8443, + "allowed": true + }, + { + "source": "operator", + "destination": "db", + "port": 8443, + "allowed": true + }, + { + "destination": "db", + "port": 8443, + "denied": [ + "no_cert", + "wrong_CA", + "wrong_SAN", + "expired", + "revoked", + "wrong_server_SAN", + "plaintext" + ] + }, + { + "source": "otel-collector", + "destination": "loki", + "port": 8443, + "allowed": true + }, + { + "source": "grafana", + "destination": "loki", + "port": 8443, + "allowed": true + }, + { + "source": "operator", + "destination": "loki", + "port": 8443, + "allowed": true + }, + { + "destination": "loki", + "port": 8443, + "denied": [ + "no_cert", + "wrong_CA", + "wrong_SAN", + "expired", + "revoked", + "wrong_server_SAN", + "plaintext" + ] + }, + { + "source": "api1", + "destination": "otel-collector", + "port": 8443, + "allowed": true + }, + { + "source": "api2", + "destination": "otel-collector", + "port": 8443, + "allowed": true + }, + { + "source": "worker", + "destination": "otel-collector", + "port": 8443, + "allowed": true + }, + { + "source": "dispatcher", + "destination": "otel-collector", + "port": 8443, + "allowed": true + }, + { + "source": "reconciler", + "destination": "otel-collector", + "port": 8443, + "allowed": true + }, + { + "source": "operator", + "destination": "otel-collector", + "port": 8443, + "allowed": true + }, + { + "destination": "otel-collector", + "port": 8443, + "denied": [ + "no_cert", + "wrong_CA", + "wrong_SAN", + "expired", + "revoked", + "wrong_server_SAN", + "plaintext" + ] + }, + { + "source": "prometheus", + "destination": "otel-collector", + "port": 8444, + "allowed": true + }, + { + "source": "operator", + "destination": "otel-collector", + "port": 8444, + "allowed": true + }, + { + "destination": "otel-collector", + "port": 8444, + "denied": [ + "no_cert", + "wrong_CA", + "wrong_SAN", + "expired", + "revoked", + "wrong_server_SAN", + "plaintext" + ] + }, + { + "source": "prometheus", + "destination": "otel-collector", + "port": 8445, + "allowed": true + }, + { + "source": "operator", + "destination": "otel-collector", + "port": 8445, + "allowed": true + }, + { + "destination": "otel-collector", + "port": 8445, + "denied": [ + "no_cert", + "wrong_CA", + "wrong_SAN", + "expired", + "revoked", + "wrong_server_SAN", + "plaintext" + ] + }, + { + "source": "grafana", + "destination": "prometheus", + "port": 8443, + "allowed": true + }, + { + "source": "operator", + "destination": "prometheus", + "port": 8443, + "allowed": true + }, + { + "destination": "prometheus", + "port": 8443, + "denied": [ + "no_cert", + "wrong_CA", + "wrong_SAN", + "expired", + "revoked", + "wrong_server_SAN", + "plaintext" + ] + }, + { + "source": "api1", + "destination": "s3", + "port": 8443, + "allowed": true + }, + { + "source": "api2", + "destination": "s3", + "port": 8443, + "allowed": true + }, + { + "source": "worker", + "destination": "s3", + "port": 8443, + "allowed": true + }, + { + "source": "reconciler", + "destination": "s3", + "port": 8443, + "allowed": true + }, + { + "source": "operator", + "destination": "s3", + "port": 8443, + "allowed": true + }, + { + "destination": "s3", + "port": 8443, + "denied": [ + "no_cert", + "wrong_CA", + "wrong_SAN", + "expired", + "revoked", + "wrong_server_SAN", + "plaintext" + ] + }, + { + "source": "otel-collector", + "destination": "tempo", + "port": 8443, + "allowed": true + }, + { + "destination": "tempo", + "port": 8443, + "denied": [ + "no_cert", + "wrong_CA", + "wrong_SAN", + "expired", + "revoked", + "wrong_server_SAN", + "plaintext" + ] + }, + { + "source": "grafana", + "destination": "tempo", + "port": 8444, + "allowed": true + }, + { + "source": "operator", + "destination": "tempo", + "port": 8444, + "allowed": true + }, + { + "destination": "tempo", + "port": 8444, + "denied": [ + "no_cert", + "wrong_CA", + "wrong_SAN", + "expired", + "revoked", + "wrong_server_SAN", + "plaintext" + ] + } + ] +} diff --git a/evidence/validate_openapi.txt b/evidence/validate_openapi.txt new file mode 100644 index 0000000..248343e --- /dev/null +++ b/evidence/validate_openapi.txt @@ -0,0 +1 @@ +PASS: full OpenAPI 3.1 and JSON Schema validation; application NOT tested. diff --git a/evidence/worker-rights.json b/evidence/worker-rights.json new file mode 100644 index 0000000..8538244 --- /dev/null +++ b/evidence/worker-rights.json @@ -0,0 +1,18 @@ +{ + "passed": true, + "rights": { + "jobs_read": "allowed", + "sessions": "denied", + "password_hashes": "denied", + "messages": "denied", + "schema": "denied", + "privilege": "denied", + "variants_read_write_delete": "allowed", + "foreign_prefix": "denied", + "bucket_admin": "denied", + "queue_group": "allowed", + "queue_publish": "denied", + "foreign_queue": "denied", + "queue_admin": "denied" + } +} diff --git a/infra/README.md b/infra/README.md index 5a39e86..573f7fd 100644 --- a/infra/README.md +++ b/infra/README.md @@ -1,7 +1,19 @@ -# Инфраструктура студента +# Infrastructure ЛР7 -Здесь разместите конфигурации выбранных сервисов; основную топологию — в корневом compose.yaml/stack.yaml. `compose.example.yaml` — только worksheet ролей и намеренно не запускается. `contracts/infrastructure.json` задаёт минимальные роли, не готовые образы/пароли. +Исполняемый стенд: ../compose.yaml. Полная инструкция: ../REPORT.md. +Все versions закреплены digest. Подготовка: `python scripts/up.py` из корня. -В REPORT.md сопоставьте роль → service name → версия/digest → health/readiness → volume → сеть/порт → способ передачи credentials. Приведите bootstrap (schema, bucket, broker topology, а с lab6 provisioning) и безопасное повторение этих команд. +- api1/api2 — non-root ASGI + cert-auth secret supervisor, public LB только HTTPS8443. +- *-tls — отдельные identities, mTLS SAN allowlist, CA+CRL; shared namespace с backend. +- db — PostgreSQL/SCRAM, named pgdata, операторские migrations/GRANT. +- cache/broker — разные Valkey ACL/configs; persistent AOF только у broker. +- s3 — private SeaweedFS bucket, раздельные SigV4 users/prefix ACL, named s3data. +- openbao — native TLS+client verification, persistent raft, declarative audit. +- telemetry — Collector/Prometheus/Loki/Tempo/Grafana, persistent backend volumes. +- secret-init/telemetry-init/storage-init — ограниченные операторские bootstrap jobs. -Приложение строится из исходников. Не используйте заранее существующий образ преподавательского сервера вместо своей реализации. Restart hook перезапускает все соответствующие stores с volumes; failover hook останавливает только заданную API-реплику. +Матрица соединений: ../contracts/trust-matrix.md. Native plaintext listener +закрыт на loopback, TLS hop существует на каждом межконтейнерном соединении. +`docker compose restart api1` отдельно от sidecar не является штатным workflow: +используйте scripts/restart.py для согласованного stop/start shared namespaces. +Volume deletion не входит ни в запуск, ни в тесты. diff --git a/infra/alerts.yaml b/infra/alerts.yaml new file mode 100644 index 0000000..1c5b9a2 --- /dev/null +++ b/infra/alerts.yaml @@ -0,0 +1,31 @@ +groups: + - name: messenger-slo + interval: 5s + rules: + - alert: APIAvailabilityBurn + expr: | + (sum(rate(http_server_requests_total{status_class="5xx"}[20s])) / clamp_min(sum(rate(http_server_requests_total[20s])), 0.001) / 0.005 > 10) + and + (sum(rate(http_server_requests_total{status_class="5xx"}[60s])) / clamp_min(sum(rate(http_server_requests_total[60s])), 0.001) / 0.005 > 10) + for: 30s + labels: {severity: critical} + annotations: + summary: "API 99.5% availability budget burns >10x in both 20s and 60s windows" + runbook: "RUNBOOK.md#api" + - alert: AttachmentReadyBurn + expr: | + (sum(attachment_slo_bad{window="60"}) / clamp_min(sum(attachment_slo_eligible{window="60"}),1) / 0.01 > 10) + and + (sum(attachment_slo_bad{window="300"}) / clamp_min(sum(attachment_slo_eligible{window="300"}),1) / 0.01 > 10) + for: 15s + labels: {severity: critical} + annotations: + summary: "99% ready within 30s budget burns >10x in both 60s and 300s eligible cohorts" + runbook: "RUNBOOK.md#queue" + - alert: QueueLag + expr: max(queue_oldest_age_seconds) > 30 and sum(queue_depth) > 0 + for: 10s + labels: {severity: warning} + annotations: + summary: "An unfinished durable job has waited over 30s" + runbook: "RUNBOOK.md#queue" diff --git a/infra/grafana/dashboards/messenger.json b/infra/grafana/dashboards/messenger.json new file mode 100644 index 0000000..f10c27c --- /dev/null +++ b/infra/grafana/dashboards/messenger.json @@ -0,0 +1,669 @@ +{ + "uid": "mtusi-messenger", + "title": "MTUSI Messenger - signals and SLO", + "schemaVersion": 39, + "version": 1, + "editable": false, + "timezone": "browser", + "time": { + "from": "now-15m", + "to": "now" + }, + "refresh": "15s", + "tags": [ + "mtusi", + "lab6" + ], + "panels": [ + { + "id": 1, + "type": "timeseries", + "title": "API requests / second", + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "gridPos": { + "x": 0, + "y": 0, + "w": 12, + "h": 8 + }, + "targets": [ + { + "refId": "A", + "expr": "sum by(method,route)(rate(http_server_requests_total[1m]))", + "legendFormat": "{{method}} {{route}}" + } + ], + "fieldConfig": { + "defaults": { + "unit": "reqps", + "min": 0 + }, + "overrides": [] + }, + "options": { + "legend": { + "displayMode": "list", + "placement": "bottom" + } + } + }, + { + "id": 2, + "type": "timeseries", + "title": "API 5xx / all business requests", + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "gridPos": { + "x": 12, + "y": 0, + "w": 12, + "h": 8 + }, + "targets": [ + { + "refId": "A", + "expr": "(sum(rate(http_server_requests_total{status_class=\"5xx\"}[1m])) or vector(0)) / clamp_min(sum(rate(http_server_requests_total[1m])),0.001)", + "legendFormat": "5xx fraction" + } + ], + "fieldConfig": { + "defaults": { + "unit": "percentunit", + "min": 0, + "max": 1 + }, + "overrides": [] + }, + "options": { + "legend": { + "displayMode": "list", + "placement": "bottom" + } + } + }, + { + "id": 3, + "type": "timeseries", + "title": "API latency: aggregate buckets across replicas", + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "gridPos": { + "x": 0, + "y": 8, + "w": 12, + "h": 8 + }, + "targets": [ + { + "refId": "A", + "expr": "histogram_quantile(0.5,sum by(le)(rate(http_server_duration_seconds_bucket[1m])))", + "legendFormat": "p50" + }, + { + "refId": "B", + "expr": "histogram_quantile(0.95,sum by(le)(rate(http_server_duration_seconds_bucket[1m])))", + "legendFormat": "p95" + }, + { + "refId": "C", + "expr": "histogram_quantile(0.99,sum by(le)(rate(http_server_duration_seconds_bucket[1m])))", + "legendFormat": "p99" + } + ], + "fieldConfig": { + "defaults": { + "unit": "s", + "min": 0 + }, + "overrides": [] + }, + "options": { + "legend": { + "displayMode": "list", + "placement": "bottom" + } + } + }, + { + "id": 4, + "type": "timeseries", + "title": "Jobs / second by outcome", + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "gridPos": { + "x": 12, + "y": 8, + "w": 12, + "h": 8 + }, + "targets": [ + { + "refId": "A", + "expr": "sum by(outcome)(rate(jobs_processed_total[1m]))", + "legendFormat": "{{outcome}}" + } + ], + "fieldConfig": { + "defaults": { + "unit": "ops", + "min": 0 + }, + "overrides": [] + }, + "options": { + "legend": { + "displayMode": "list", + "placement": "bottom" + } + } + }, + { + "id": 5, + "type": "timeseries", + "title": "Worker processing latency", + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "gridPos": { + "x": 0, + "y": 16, + "w": 12, + "h": 8 + }, + "targets": [ + { + "refId": "A", + "expr": "histogram_quantile(0.5,sum by(le)(rate(job_processing_duration_seconds_bucket[1m])))", + "legendFormat": "p50" + }, + { + "refId": "B", + "expr": "histogram_quantile(0.95,sum by(le)(rate(job_processing_duration_seconds_bucket[1m])))", + "legendFormat": "p95" + }, + { + "refId": "C", + "expr": "histogram_quantile(0.99,sum by(le)(rate(job_processing_duration_seconds_bucket[1m])))", + "legendFormat": "p99" + } + ], + "fieldConfig": { + "defaults": { + "unit": "s", + "min": 0 + }, + "overrides": [] + }, + "options": { + "legend": { + "displayMode": "list", + "placement": "bottom" + } + } + }, + { + "id": 6, + "type": "timeseries", + "title": "Acceptance to ready latency", + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "gridPos": { + "x": 12, + "y": 16, + "w": 12, + "h": 8 + }, + "targets": [ + { + "refId": "A", + "expr": "histogram_quantile(0.5,sum by(le)(rate(attachment_time_to_ready_seconds_bucket[5m])))", + "legendFormat": "p50" + }, + { + "refId": "B", + "expr": "histogram_quantile(0.95,sum by(le)(rate(attachment_time_to_ready_seconds_bucket[5m])))", + "legendFormat": "p95" + }, + { + "refId": "C", + "expr": "histogram_quantile(0.99,sum by(le)(rate(attachment_time_to_ready_seconds_bucket[5m])))", + "legendFormat": "p99" + } + ], + "fieldConfig": { + "defaults": { + "unit": "s", + "min": 0 + }, + "overrides": [] + }, + "options": { + "legend": { + "displayMode": "list", + "placement": "bottom" + } + } + }, + { + "id": 7, + "type": "timeseries", + "title": "Unfinished durable jobs", + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "gridPos": { + "x": 0, + "y": 24, + "w": 12, + "h": 8 + }, + "targets": [ + { + "refId": "A", + "expr": "sum(queue_depth)", + "legendFormat": "queue depth" + } + ], + "fieldConfig": { + "defaults": { + "unit": "short", + "min": 0 + }, + "overrides": [] + }, + "options": { + "legend": { + "displayMode": "list", + "placement": "bottom" + } + } + }, + { + "id": 8, + "type": "timeseries", + "title": "Oldest unfinished job age", + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "gridPos": { + "x": 12, + "y": 24, + "w": 12, + "h": 8 + }, + "targets": [ + { + "refId": "A", + "expr": "max(queue_oldest_age_seconds)", + "legendFormat": "oldest" + } + ], + "fieldConfig": { + "defaults": { + "unit": "s", + "min": 0 + }, + "overrides": [] + }, + "options": { + "legend": { + "displayMode": "list", + "placement": "bottom" + } + } + }, + { + "id": 9, + "type": "timeseries", + "title": "DB pool", + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "gridPos": { + "x": 0, + "y": 32, + "w": 12, + "h": 8 + }, + "targets": [ + { + "refId": "A", + "expr": "db_pool_used", + "legendFormat": "used {{process_instance}}" + }, + { + "refId": "B", + "expr": "db_pool_waiting", + "legendFormat": "waiting {{process_instance}}" + } + ], + "fieldConfig": { + "defaults": { + "unit": "short", + "min": 0 + }, + "overrides": [] + }, + "options": { + "legend": { + "displayMode": "list", + "placement": "bottom" + } + } + }, + { + "id": 10, + "type": "timeseries", + "title": "Worker saturation", + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "gridPos": { + "x": 12, + "y": 32, + "w": 12, + "h": 8 + }, + "targets": [ + { + "refId": "A", + "expr": "sum(worker_busy) / clamp_min(sum(worker_capacity),1)", + "legendFormat": "busy / capacity" + } + ], + "fieldConfig": { + "defaults": { + "unit": "percentunit", + "min": 0, + "max": 1 + }, + "overrides": [] + }, + "options": { + "legend": { + "displayMode": "list", + "placement": "bottom" + } + } + }, + { + "id": 11, + "type": "timeseries", + "title": "Current process RSS", + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "gridPos": { + "x": 0, + "y": 40, + "w": 12, + "h": 8 + }, + "targets": [ + { + "refId": "A", + "expr": "process_rss_bytes", + "legendFormat": "{{service}} {{process_instance}}" + } + ], + "fieldConfig": { + "defaults": { + "unit": "bytes", + "min": 0 + }, + "overrides": [] + }, + "options": { + "legend": { + "displayMode": "list", + "placement": "bottom" + } + } + }, + { + "id": 12, + "type": "timeseries", + "title": "Process CPU seconds / wall second", + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "gridPos": { + "x": 12, + "y": 40, + "w": 12, + "h": 8 + }, + "targets": [ + { + "refId": "A", + "expr": "clamp_min(deriv(process_cpu_time_seconds[1m]),0)", + "legendFormat": "{{service}} {{process_instance}}" + } + ], + "fieldConfig": { + "defaults": { + "unit": "short", + "min": 0 + }, + "overrides": [] + }, + "options": { + "legend": { + "displayMode": "list", + "placement": "bottom" + } + } + }, + { + "id": 13, + "type": "timeseries", + "title": "API availability burn rate; budget 0.5%", + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "gridPos": { + "x": 0, + "y": 48, + "w": 12, + "h": 8 + }, + "targets": [ + { + "refId": "A", + "expr": "(sum(rate(http_server_requests_total{status_class=\"5xx\"}[20s])) or vector(0)) / clamp_min(sum(rate(http_server_requests_total[20s])),0.001) / 0.005", + "legendFormat": "20s" + }, + { + "refId": "B", + "expr": "(sum(rate(http_server_requests_total{status_class=\"5xx\"}[60s])) or vector(0)) / clamp_min(sum(rate(http_server_requests_total[60s])),0.001) / 0.005", + "legendFormat": "60s" + } + ], + "fieldConfig": { + "defaults": { + "unit": "short", + "min": 0 + }, + "overrides": [] + }, + "options": { + "legend": { + "displayMode": "list", + "placement": "bottom" + } + } + }, + { + "id": 14, + "type": "timeseries", + "title": "Ready <=30s burn rate; budget 1%", + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "gridPos": { + "x": 12, + "y": 48, + "w": 12, + "h": 8 + }, + "targets": [ + { + "refId": "A", + "expr": "sum(attachment_slo_bad{window=\"60\"}) / clamp_min(sum(attachment_slo_eligible{window=\"60\"}),1) / 0.01", + "legendFormat": "60s eligible cohort" + }, + { + "refId": "B", + "expr": "sum(attachment_slo_bad{window=\"300\"}) / clamp_min(sum(attachment_slo_eligible{window=\"300\"}),1) / 0.01", + "legendFormat": "300s eligible cohort" + } + ], + "fieldConfig": { + "defaults": { + "unit": "short", + "min": 0 + }, + "overrides": [] + }, + "options": { + "legend": { + "displayMode": "list", + "placement": "bottom" + } + } + }, + { + "id": 15, + "type": "timeseries", + "title": "Collector exporter queue / capacity", + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "gridPos": { + "x": 0, + "y": 56, + "w": 12, + "h": 8 + }, + "targets": [ + { + "refId": "A", + "expr": "otelcol_exporter_queue_size", + "legendFormat": "{{exporter}} size" + }, + { + "refId": "B", + "expr": "otelcol_exporter_queue_capacity", + "legendFormat": "{{exporter}} capacity" + } + ], + "fieldConfig": { + "defaults": { + "unit": "short", + "min": 0 + }, + "overrides": [] + }, + "options": { + "legend": { + "displayMode": "list", + "placement": "bottom" + } + } + }, + { + "id": 16, + "type": "timeseries", + "title": "Collector failed exports", + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "gridPos": { + "x": 12, + "y": 56, + "w": 12, + "h": 8 + }, + "targets": [ + { + "refId": "A", + "expr": "rate(otelcol_exporter_send_failed_spans_total[1m])", + "legendFormat": "{{exporter}} spans" + }, + { + "refId": "B", + "expr": "rate(otelcol_exporter_send_failed_log_records_total[1m])", + "legendFormat": "{{exporter}} logs" + } + ], + "fieldConfig": { + "defaults": { + "unit": "ops", + "min": 0 + }, + "overrides": [] + }, + "options": { + "legend": { + "displayMode": "list", + "placement": "bottom" + } + } + }, + { + "id": 99, + "type": "logs", + "title": "Structured application logs; TraceID links to Tempo", + "datasource": { + "type": "loki", + "uid": "loki" + }, + "gridPos": { + "x": 0, + "y": 64, + "w": 24, + "h": 10 + }, + "targets": [ + { + "refId": "A", + "expr": "{service_name=~\"messenger-(api|worker|dispatcher)\"}" + } + ], + "options": { + "showTime": true, + "showLabels": false, + "wrapLogMessage": true, + "sortOrder": "Descending" + } + } + ], + "annotations": { + "list": [] + }, + "templating": { + "list": [] + } +} diff --git a/infra/grafana/provisioning/dashboards/provider.yaml b/infra/grafana/provisioning/dashboards/provider.yaml new file mode 100644 index 0000000..9af7c9b --- /dev/null +++ b/infra/grafana/provisioning/dashboards/provider.yaml @@ -0,0 +1,9 @@ +apiVersion: 1 +providers: + - name: Messenger + folder: MTUSI + type: file + disableDeletion: true + updateIntervalSeconds: 30 + options: + path: /var/lib/grafana/dashboards diff --git a/infra/grafana/provisioning/datasources/sources.yaml b/infra/grafana/provisioning/datasources/sources.yaml new file mode 100644 index 0000000..0d23bbb --- /dev/null +++ b/infra/grafana/provisioning/datasources/sources.yaml @@ -0,0 +1,31 @@ +apiVersion: 1 +datasources: + - name: Prometheus + uid: prometheus + type: prometheus + access: proxy + url: http://127.0.0.1:19090 + isDefault: true + - name: Loki + uid: loki + type: loki + access: proxy + url: http://127.0.0.1:13100 + jsonData: + derivedFields: + - name: TraceID + matcherRegex: '"trace_id": "([0-9a-f]{32})"' + datasourceUid: tempo + url: '$${__value.raw}' + - name: Tempo + uid: tempo + type: tempo + access: proxy + url: http://127.0.0.1:13200 + jsonData: + tracesToLogsV2: + datasourceUid: loki + spanStartTimeShift: '-1m' + spanEndTimeShift: '1m' + filterByTraceID: true + nodeGraph: {enabled: true} diff --git a/infra/haproxy.cfg b/infra/haproxy.cfg new file mode 100644 index 0000000..e4378df --- /dev/null +++ b/infra/haproxy.cfg @@ -0,0 +1,32 @@ +global + log stdout format raw local0 + maxconn 256 +defaults + mode http + log global + timeout connect 1s + timeout client 35s + timeout server 32s + timeout check 1s + timeout queue 2s + retries 0 + option http-server-close +resolvers docker + nameserver dns 127.0.0.11:53 + resolve_retries 3 + timeout resolve 1s + timeout retry 1s + hold valid 1s + hold obsolete 1s + hold nx 1s + hold timeout 1s +frontend public + bind :8443 ssl crt /identity/combined.pem ssl-min-ver TLSv1.2 + default_backend api +backend api + balance roundrobin + option log-health-checks + option httpchk GET /health/ready + http-check expect status 200 + server api1 api1:8443 ssl verify required ca-file /trust/ca.crt crl-file /trust/revocations.pem crt /identity/combined.pem verifyhost api1 sni str(api1) check-sni api1 check inter 1s resolvers docker init-addr none + server api2 api2:8443 ssl verify required ca-file /trust/ca.crt crl-file /trust/revocations.pem crt /identity/combined.pem verifyhost api2 sni str(api2) check-sni api2 check inter 1s resolvers docker init-addr none diff --git a/infra/loki.yaml b/infra/loki.yaml new file mode 100644 index 0000000..57311d3 --- /dev/null +++ b/infra/loki.yaml @@ -0,0 +1,36 @@ +auth_enabled: false +server: + http_listen_address: 127.0.0.1 + grpc_listen_address: 127.0.0.1 + http_listen_port: 3100 +common: + instance_addr: 127.0.0.1 + path_prefix: /var/loki + replication_factor: 1 + ring: + kvstore: + store: inmemory + storage: + filesystem: + chunks_directory: /var/loki/chunks + rules_directory: /var/loki/rules +schema_config: + configs: + - from: 2026-01-01 + store: tsdb + object_store: filesystem + schema: v13 + index: + prefix: index_ + period: 24h +limits_config: + allow_structured_metadata: true + retention_period: 24h + ingestion_rate_mb: 2 + ingestion_burst_size_mb: 4 +compactor: + working_directory: /var/loki/compactor + retention_enabled: true + delete_request_store: filesystem +analytics: + reporting_enabled: false diff --git a/infra/mesh/api1.json b/infra/mesh/api1.json new file mode 100644 index 0000000..940b781 --- /dev/null +++ b/infra/mesh/api1.json @@ -0,0 +1,34 @@ +[ + { + "mode": "server", + "listen": 8443, + "target": 8080, + "allow": [ + "lb" + ] + }, + { + "mode": "client", + "listen": 5432, + "host": "db", + "target": 8443 + }, + { + "mode": "client", + "listen": 8333, + "host": "s3", + "target": 8443 + }, + { + "mode": "client", + "listen": 4318, + "host": "otel-collector", + "target": 8443 + }, + { + "mode": "client", + "listen": 6379, + "host": "cache", + "target": 8443 + } +] diff --git a/infra/mesh/api2.json b/infra/mesh/api2.json new file mode 100644 index 0000000..940b781 --- /dev/null +++ b/infra/mesh/api2.json @@ -0,0 +1,34 @@ +[ + { + "mode": "server", + "listen": 8443, + "target": 8080, + "allow": [ + "lb" + ] + }, + { + "mode": "client", + "listen": 5432, + "host": "db", + "target": 8443 + }, + { + "mode": "client", + "listen": 8333, + "host": "s3", + "target": 8443 + }, + { + "mode": "client", + "listen": 4318, + "host": "otel-collector", + "target": 8443 + }, + { + "mode": "client", + "listen": 6379, + "host": "cache", + "target": 8443 + } +] diff --git a/infra/mesh/broker.json b/infra/mesh/broker.json new file mode 100644 index 0000000..ad83651 --- /dev/null +++ b/infra/mesh/broker.json @@ -0,0 +1,12 @@ +[ + { + "mode": "server", + "listen": 8443, + "target": 6379, + "allow": [ + "worker", + "dispatcher", + "operator" + ] + } +] diff --git a/infra/mesh/cache.json b/infra/mesh/cache.json new file mode 100644 index 0000000..e2f2dbc --- /dev/null +++ b/infra/mesh/cache.json @@ -0,0 +1,12 @@ +[ + { + "mode": "server", + "listen": 8443, + "target": 6379, + "allow": [ + "api1", + "api2", + "operator" + ] + } +] diff --git a/infra/mesh/db.json b/infra/mesh/db.json new file mode 100644 index 0000000..6e951ad --- /dev/null +++ b/infra/mesh/db.json @@ -0,0 +1,15 @@ +[ + { + "mode": "server", + "listen": 8443, + "target": 5432, + "allow": [ + "api1", + "api2", + "worker", + "dispatcher", + "reconciler", + "operator" + ] + } +] diff --git a/infra/mesh/dispatcher.json b/infra/mesh/dispatcher.json new file mode 100644 index 0000000..30290ee --- /dev/null +++ b/infra/mesh/dispatcher.json @@ -0,0 +1,20 @@ +[ + { + "mode": "client", + "listen": 5432, + "host": "db", + "target": 8443 + }, + { + "mode": "client", + "listen": 4318, + "host": "otel-collector", + "target": 8443 + }, + { + "mode": "client", + "listen": 6380, + "host": "broker", + "target": 8443 + } +] diff --git a/infra/mesh/grafana.json b/infra/mesh/grafana.json new file mode 100644 index 0000000..fd1af02 --- /dev/null +++ b/infra/mesh/grafana.json @@ -0,0 +1,20 @@ +[ + { + "mode": "client", + "listen": 19090, + "host": "prometheus", + "target": 8443 + }, + { + "mode": "client", + "listen": 13100, + "host": "loki", + "target": 8443 + }, + { + "mode": "client", + "listen": 13200, + "host": "tempo", + "target": 8444 + } +] diff --git a/infra/mesh/loki.json b/infra/mesh/loki.json new file mode 100644 index 0000000..f83ee4b --- /dev/null +++ b/infra/mesh/loki.json @@ -0,0 +1,12 @@ +[ + { + "mode": "server", + "listen": 8443, + "target": 3100, + "allow": [ + "otel-collector", + "grafana", + "operator" + ] + } +] diff --git a/infra/mesh/otel-collector.json b/infra/mesh/otel-collector.json new file mode 100644 index 0000000..170ab08 --- /dev/null +++ b/infra/mesh/otel-collector.json @@ -0,0 +1,45 @@ +[ + { + "mode": "server", + "listen": 8443, + "target": 4318, + "allow": [ + "api1", + "api2", + "worker", + "dispatcher", + "reconciler", + "operator" + ] + }, + { + "mode": "server", + "listen": 8444, + "target": 9464, + "allow": [ + "prometheus", + "operator" + ] + }, + { + "mode": "server", + "listen": 8445, + "target": 8888, + "allow": [ + "prometheus", + "operator" + ] + }, + { + "mode": "client", + "listen": 14318, + "host": "tempo", + "target": 8443 + }, + { + "mode": "client", + "listen": 13100, + "host": "loki", + "target": 8443 + } +] diff --git a/infra/mesh/prometheus.json b/infra/mesh/prometheus.json new file mode 100644 index 0000000..e5769f7 --- /dev/null +++ b/infra/mesh/prometheus.json @@ -0,0 +1,23 @@ +[ + { + "mode": "server", + "listen": 8443, + "target": 9090, + "allow": [ + "grafana", + "operator" + ] + }, + { + "mode": "client", + "listen": 19464, + "host": "otel-collector", + "target": 8444 + }, + { + "mode": "client", + "listen": 18888, + "host": "otel-collector", + "target": 8445 + } +] diff --git a/infra/mesh/reconciler.json b/infra/mesh/reconciler.json new file mode 100644 index 0000000..b0fb8cc --- /dev/null +++ b/infra/mesh/reconciler.json @@ -0,0 +1,20 @@ +[ + { + "mode": "client", + "listen": 5432, + "host": "db", + "target": 8443 + }, + { + "mode": "client", + "listen": 8333, + "host": "s3", + "target": 8443 + }, + { + "mode": "client", + "listen": 4318, + "host": "otel-collector", + "target": 8443 + } +] diff --git a/infra/mesh/s3.json b/infra/mesh/s3.json new file mode 100644 index 0000000..ff677cf --- /dev/null +++ b/infra/mesh/s3.json @@ -0,0 +1,14 @@ +[ + { + "mode": "server", + "listen": 8443, + "target": 8333, + "allow": [ + "api1", + "api2", + "worker", + "reconciler", + "operator" + ] + } +] diff --git a/infra/mesh/tempo.json b/infra/mesh/tempo.json new file mode 100644 index 0000000..99ce7c1 --- /dev/null +++ b/infra/mesh/tempo.json @@ -0,0 +1,19 @@ +[ + { + "mode": "server", + "listen": 8443, + "target": 4318, + "allow": [ + "otel-collector" + ] + }, + { + "mode": "server", + "listen": 8444, + "target": 3200, + "allow": [ + "grafana", + "operator" + ] + } +] diff --git a/infra/mesh/worker.json b/infra/mesh/worker.json new file mode 100644 index 0000000..5cd5a8c --- /dev/null +++ b/infra/mesh/worker.json @@ -0,0 +1,26 @@ +[ + { + "mode": "client", + "listen": 5432, + "host": "db", + "target": 8443 + }, + { + "mode": "client", + "listen": 8333, + "host": "s3", + "target": 8443 + }, + { + "mode": "client", + "listen": 4318, + "host": "otel-collector", + "target": 8443 + }, + { + "mode": "client", + "listen": 6380, + "host": "broker", + "target": 8443 + } +] diff --git a/infra/openbao.hcl b/infra/openbao.hcl new file mode 100644 index 0000000..ca2511c --- /dev/null +++ b/infra/openbao.hcl @@ -0,0 +1,21 @@ +ui = false +disable_mlock = true +api_addr = "https://openbao:8200" +cluster_addr = "https://127.0.0.1:8201" +audit "file" "operator" { + options { + file_path = "/bao/audit.json" + } +} +storage "raft" { + path = "/bao/data" + node_id = "lab7" +} +listener "tcp" { + address = "0.0.0.0:8200" + tls_cert_file = "/identity/cert.pem" + tls_key_file = "/identity/key.pem" + tls_client_ca_file = "/trust/ca.crt" + tls_require_and_verify_client_cert = true + tls_min_version = "tls12" +} diff --git a/infra/otel-collector.yaml b/infra/otel-collector.yaml new file mode 100644 index 0000000..f10b96a --- /dev/null +++ b/infra/otel-collector.yaml @@ -0,0 +1,67 @@ +receivers: + otlp: + protocols: + http: + endpoint: 127.0.0.1:4318 +processors: + memory_limiter: + check_interval: 1s + limit_mib: 192 + spike_limit_mib: 48 + batch: + timeout: 1s + send_batch_size: 64 + send_batch_max_size: 128 +exporters: + prometheus: + endpoint: 127.0.0.1:9464 + enable_open_metrics: true + metric_expiration: 2m + otlphttp/tempo: + endpoint: http://127.0.0.1:14318 + timeout: 2s + sending_queue: + enabled: true + num_consumers: 2 + queue_size: 32 + retry_on_failure: + initial_interval: 1s + max_interval: 5s + max_elapsed_time: 30s + otlphttp/loki: + endpoint: http://127.0.0.1:13100/otlp + timeout: 2s + sending_queue: + enabled: true + num_consumers: 2 + queue_size: 32 + retry_on_failure: + initial_interval: 1s + max_interval: 5s + max_elapsed_time: 30s +extensions: + health_check: + endpoint: 127.0.0.1:13133 +service: + extensions: [health_check] + telemetry: + metrics: + readers: + - pull: + exporter: + prometheus: + host: 127.0.0.1 + port: 8888 + pipelines: + traces: + receivers: [otlp] + processors: [memory_limiter, batch] + exporters: [otlphttp/tempo] + metrics: + receivers: [otlp] + processors: [memory_limiter, batch] + exporters: [prometheus] + logs: + receivers: [otlp] + processors: [memory_limiter, batch] + exporters: [otlphttp/loki] diff --git a/infra/otel/README.md b/infra/otel/README.md index c46fe89..7d1fee5 100644 --- a/infra/otel/README.md +++ b/infra/otel/README.md @@ -1,7 +1,14 @@ -# Конфигурация наблюдаемости — реализовать +# Telemetry ЛР7 -Добавьте `collector.yaml` с OTLP receivers, processors и exporters выбранной версии Collector. Укажите явные bind endpoints, внутренние сети, memory limits/batch и поведение при backpressure по уровню. Сопоставьте все три pipeline с реально развёрнутыми backend. +Перенесена реализация ЛР6. Collector принимает OTLP HTTP только на loopback; +сеть доступна через otel-collector:8443 с mTLS и SAN allowlist. Native экспорт +Collector → Tempo/Loki идёт в локальные tunnels, которые проверяют server CA/SAN +и предъявляют identity Collector. Prometheus scrape и Grafana queries также +используют разные mTLS identities. Backend ports не публикуются на хосте. -Добавьте конфигурации storage, Grafana provisioning/datasources, provisioning/dashboards и импортируемые dashboard JSON. На 4 — alert rules и runbooks. Пустой dashboard или debug exporter, который только печатает данные в stdout, не заменяют хранилища/доказательства из `contracts/observability.md`. - -Не публикуйте OTLP/metrics/административные ports в общую сеть без необходимости. В lab7 реализуйте TLS/mTLS по trust matrix; экспорт Authorization и message bodies запрещён. +Provisioned dashboard: infra/grafana/dashboards/messenger.json. Grafana доступна +на https://localhost:3000, пароль admin создаёт bootstrap; анонимного доступа нет. +Секреты, bodies и Authorization не включены в application spans/logs. +`python checks/telemetry_security.py` проверяет upload trace, correlated logs, +HTTP metric series и отсутствие известных credential canaries. Подробности +в REPORT.md и contracts/trust-matrix.md. diff --git a/infra/pg_hba.conf b/infra/pg_hba.conf new file mode 100644 index 0000000..bf6fcf6 --- /dev/null +++ b/infra/pg_hba.conf @@ -0,0 +1,8 @@ +# Operator-only Unix socket; no socket is shared with app containers. +local all messenger trust +local all all reject +# Plaintext exists only in the db TLS sidecar's shared loopback namespace. +# The TLS boundary enforces the peer identity; PostgreSQL ALSO verifies SCRAM. +host all all 127.0.0.1/32 scram-sha-256 +host all all ::1/128 reject +host all all 0.0.0.0/0 reject diff --git a/infra/prometheus.yaml b/infra/prometheus.yaml new file mode 100644 index 0000000..950cd3c --- /dev/null +++ b/infra/prometheus.yaml @@ -0,0 +1,12 @@ +global: + scrape_interval: 5s + evaluation_interval: 5s +rule_files: + - /etc/prometheus/alerts.yaml +scrape_configs: + - job_name: messenger-otlp + static_configs: + - targets: [127.0.0.1:19464] + - job_name: collector + static_configs: + - targets: [127.0.0.1:18888] diff --git a/infra/tempo.yaml b/infra/tempo.yaml new file mode 100644 index 0000000..55d2d97 --- /dev/null +++ b/infra/tempo.yaml @@ -0,0 +1,28 @@ +server: + http_listen_address: 127.0.0.1 + grpc_listen_address: 127.0.0.1 + http_listen_port: 3200 +distributor: + receivers: + otlp: + protocols: + http: + endpoint: 127.0.0.1:4318 +ingester: + trace_idle_period: 5s + max_block_duration: 1m +compactor: + compaction: + block_retention: 24h +storage: + trace: + backend: local + wal: + path: /var/tempo/wal + local: + path: /var/tempo/blocks +overrides: + defaults: + ingestion: + rate_limit_bytes: 1000000 + burst_size_bytes: 2000000 diff --git a/migrations/001_initial.sql b/migrations/001_initial.sql new file mode 100644 index 0000000..3b9cda9 --- /dev/null +++ b/migrations/001_initial.sql @@ -0,0 +1,35 @@ +CREATE TABLE users ( + id uuid PRIMARY KEY, + username text NOT NULL UNIQUE CHECK (username ~ '^[a-z0-9_]{3,32}$'), + display_name text NOT NULL CHECK (char_length(display_name) BETWEEN 1 AND 100), + password_hash text NOT NULL, + created_at timestamptz NOT NULL DEFAULT clock_timestamp() +); +CREATE TABLE sessions ( + token_hash text PRIMARY KEY, + user_id uuid NOT NULL REFERENCES users(id), + expires_at timestamptz NOT NULL, + created_at timestamptz NOT NULL DEFAULT clock_timestamp() +); +CREATE INDEX sessions_expiry ON sessions(expires_at); +CREATE TABLE chats ( + id uuid PRIMARY KEY, + title text NOT NULL CHECK (char_length(title) BETWEEN 1 AND 100), + created_at timestamptz NOT NULL DEFAULT clock_timestamp() +); +CREATE TABLE members ( + chat_id uuid NOT NULL REFERENCES chats(id), + user_id uuid NOT NULL REFERENCES users(id), + PRIMARY KEY(chat_id,user_id) +); +CREATE INDEX members_user_chat ON members(user_id,chat_id); +CREATE INDEX chats_order ON chats(created_at,id); +CREATE TABLE messages ( + id uuid PRIMARY KEY, + chat_id uuid NOT NULL REFERENCES chats(id), + sender_id uuid NOT NULL REFERENCES users(id), + text text NOT NULL CHECK (char_length(text) BETWEEN 1 AND 4000), + created_at timestamptz NOT NULL DEFAULT clock_timestamp(), + FOREIGN KEY(chat_id,sender_id) REFERENCES members(chat_id,user_id) +); +CREATE INDEX messages_history ON messages(chat_id,created_at,id); diff --git a/migrations/002_idempotency.sql b/migrations/002_idempotency.sql new file mode 100644 index 0000000..582b0c4 --- /dev/null +++ b/migrations/002_idempotency.sql @@ -0,0 +1,10 @@ +CREATE TABLE idempotency ( + actor_id uuid NOT NULL REFERENCES users(id), + chat_id uuid NOT NULL REFERENCES chats(id), + key text NOT NULL CHECK (key ~ '^[A-Za-z0-9._:-]{1,128}$'), + request_hash text NOT NULL, + message_id uuid NOT NULL REFERENCES messages(id), + expires_at timestamptz NOT NULL, + PRIMARY KEY(actor_id,chat_id,key) +); +CREATE INDEX idempotency_expiry ON idempotency(expires_at); diff --git a/migrations/003_attachments.sql b/migrations/003_attachments.sql new file mode 100644 index 0000000..839d675 --- /dev/null +++ b/migrations/003_attachments.sql @@ -0,0 +1,25 @@ +CREATE TABLE attachments ( + id uuid PRIMARY KEY, + chat_id uuid NOT NULL REFERENCES chats(id), + owner_id uuid NOT NULL REFERENCES users(id), + filename text NOT NULL, + object_key text NOT NULL UNIQUE, + content_type text NOT NULL CHECK (content_type IN ('image/png','image/jpeg')), + size_bytes bigint NOT NULL CHECK (size_bytes BETWEEN 1 AND 10485760), + sha256 text NOT NULL CHECK (sha256 ~ '^[a-f0-9]{64}$'), + storage_state text NOT NULL DEFAULT 'ready' CHECK (storage_state IN ('ready','missing')), + created_at timestamptz NOT NULL DEFAULT clock_timestamp(), + updated_at timestamptz NOT NULL DEFAULT clock_timestamp(), + UNIQUE (id, chat_id), + FOREIGN KEY (chat_id, owner_id) REFERENCES members(chat_id,user_id) +); +CREATE INDEX attachments_chat ON attachments(chat_id,created_at,id); +ALTER TABLE messages ADD COLUMN attachment_ids uuid[] NOT NULL DEFAULT '{}'; +ALTER TABLE messages DROP CONSTRAINT IF EXISTS messages_text_check; +ALTER TABLE messages ADD CONSTRAINT messages_content_check + CHECK (length(text) <= 4000 AND (length(btrim(text)) > 0 OR cardinality(attachment_ids) > 0)); +CREATE TABLE message_attachments ( + message_id uuid NOT NULL REFERENCES messages(id), + attachment_id uuid NOT NULL REFERENCES attachments(id), + PRIMARY KEY(message_id,attachment_id) +); diff --git a/migrations/004_jobs.sql b/migrations/004_jobs.sql new file mode 100644 index 0000000..23d39c7 --- /dev/null +++ b/migrations/004_jobs.sql @@ -0,0 +1,41 @@ +ALTER TABLE attachments ADD COLUMN status text NOT NULL DEFAULT 'ready' + CHECK (status IN ('queued','processing','ready','failed')); +ALTER TABLE attachments ADD COLUMN pipeline_version integer NOT NULL DEFAULT 1 CHECK (pipeline_version>0); +ALTER TABLE attachments ADD COLUMN staging_key text; +ALTER TABLE attachments ADD COLUMN variants jsonb NOT NULL DEFAULT '[]'; +ALTER TABLE attachments ADD COLUMN error_code text; +ALTER TABLE attachments ADD COLUMN accepted_at timestamptz NOT NULL DEFAULT clock_timestamp(); + +CREATE TABLE jobs ( + id uuid PRIMARY KEY, + attachment_id uuid NOT NULL REFERENCES attachments(id), + pipeline_version integer NOT NULL CHECK (pipeline_version IN (1,2)), + status text NOT NULL DEFAULT 'queued' CHECK (status IN ('queued','processing','done','failed','superseded')), + attempts integer NOT NULL DEFAULT 0 CHECK (attempts>=0), + lease_token uuid, + lease_until timestamptz, + next_attempt_at timestamptz NOT NULL DEFAULT clock_timestamp(), + error_code text, + traceparent text, + created_at timestamptz NOT NULL DEFAULT clock_timestamp(), + updated_at timestamptz NOT NULL DEFAULT clock_timestamp(), + UNIQUE (attachment_id,pipeline_version) +); +CREATE INDEX jobs_due ON jobs(status,next_attempt_at); +CREATE TABLE outbox ( + job_id uuid PRIMARY KEY REFERENCES jobs(id), + published_at timestamptz, + publications integer NOT NULL DEFAULT 0 +); +CREATE TABLE job_audit ( + id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY, + job_id uuid NOT NULL REFERENCES jobs(id), + event text NOT NULL, + details jsonb NOT NULL DEFAULT '{}', + created_at timestamptz NOT NULL DEFAULT clock_timestamp() +); +CREATE TABLE job_faults ( + job_id uuid PRIMARY KEY REFERENCES jobs(id), + point text NOT NULL CHECK (point IN ('before_effect','after_effect','after_commit','transient','permanent')), + remaining integer NOT NULL CHECK (remaining>=0) +); diff --git a/migrations/005_trace_state.sql b/migrations/005_trace_state.sql new file mode 100644 index 0000000..a6bd6d1 --- /dev/null +++ b/migrations/005_trace_state.sql @@ -0,0 +1 @@ +ALTER TABLE jobs ADD COLUMN IF NOT EXISTS tracestate text; diff --git a/migrations/006_security.sql b/migrations/006_security.sql new file mode 100644 index 0000000..52efcc2 --- /dev/null +++ b/migrations/006_security.sql @@ -0,0 +1,6 @@ +CREATE TABLE IF NOT EXISTS login_budget ( + name text PRIMARY KEY, + window_start timestamptz NOT NULL, + used integer NOT NULL +); +REVOKE CREATE ON SCHEMA public FROM PUBLIC; diff --git a/requirements-test.txt b/requirements-test.txt new file mode 100644 index 0000000..390e556 --- /dev/null +++ b/requirements-test.txt @@ -0,0 +1,3 @@ +-r requirements.txt +cryptography==50.0.2 +PyYAML==6.0.3 diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..8798c1c --- /dev/null +++ b/requirements.txt @@ -0,0 +1,43 @@ +annotated-doc==0.0.5 +annotated-types==0.8.0 +anyio==4.15.1 +argon2-cffi==25.1.0 +argon2-cffi-bindings==26.1.0 +boto3==1.43.114 +botocore==1.43.114 +certifi==2026.10.23 +cffi==2.1.1 +charset-normalizer==3.5.2 +click==8.5.0 +fastapi==0.143.2 +googleapis-common-protos==1.75.5 +h11==0.16.0 +idna==3.20 +jmespath==1.1.0 +opentelemetry-api==1.45.1 +opentelemetry-exporter-http-transport==0.66b1 +opentelemetry-exporter-otlp-common==0.66b1 +opentelemetry-exporter-otlp-proto-common==1.45.1 +opentelemetry-exporter-otlp-proto-http==1.45.1 +opentelemetry-proto==1.45.1 +opentelemetry-sdk==1.45.1 +opentelemetry-semantic-conventions==0.66b1 +pillow==13.0.0 +protobuf==7.36.2 +psycopg==3.3.6 +psycopg-binary==3.3.6 +psycopg-pool==3.3.3 +pycparser==3.11 +pydantic==2.14.1 +pydantic_core==2.50.1 +python-dateutil==2.9.0.post0 +redis==8.1.0 +requests==2.34.2 +s3transfer==0.19.2 +six==1.17.0 +starlette==1.8.0 +typing-inspection==0.4.4 +typing_extensions==4.16.0 +tzdata==2026.5 +urllib3==2.8.0 +uvicorn==0.54.0 diff --git a/scripts/bao_operator.py b/scripts/bao_operator.py new file mode 100644 index 0000000..482b58c --- /dev/null +++ b/scripts/bao_operator.py @@ -0,0 +1,60 @@ +"""Explicit operator init/unseal/provision. Shares never enter a service mount.""" +import argparse +import json +from pathlib import Path +import ssl +import time +import urllib.request +from urllib.error import HTTPError, URLError + +ROOT=Path(__file__).resolve().parents[1] + + +def request(path,body=None,token=None,method=None): + ctx=ssl.create_default_context(cafile=str(ROOT/'secrets/trust/ca.crt')) + ctx.load_cert_chain(ROOT/'secrets/identities/operator/cert.pem',ROOT/'secrets/identities/operator/key.pem') + headers={'Content-Type':'application/json'} + if token:headers['X-Vault-Token']=token + req=urllib.request.Request('https://127.0.0.1:8200/v1/'+path,data=json.dumps(body).encode() if body is not None else None,headers=headers,method=method) + with urllib.request.urlopen(req,context=ctx,timeout=15) as r: + raw=r.read();return json.loads(raw) if raw else {} + + +def main(): + p=argparse.ArgumentParser();p.add_argument('action',choices=['init','unseal','provision','seal','publish-crl']);args=p.parse_args() + file=ROOT/'secrets/operator/bao-init.json' + if args.action=='init': + if request('sys/init')['initialized']:raise SystemExit('Already initialized; preserve existing operator shares') + result=request('sys/init',{'secret_shares':3,'secret_threshold':2}) + with file.open('x',encoding='utf-8') as f:json.dump(result,f) + file.chmod(0o600) + print('Initialized; three shares stored in operator-only local file. Unseal explicitly.');return + operator=json.loads(file.read_text(encoding='utf-8'));token=operator['root_token'] + if args.action=='unseal': + deadline=time.monotonic()+20 + while True: + try:request('sys/seal-status');break + except (URLError,OSError): + if time.monotonic()>=deadline:raise + time.sleep(.5) + for share in operator['keys'][:2]:request('sys/unseal',{'key':share}) + elif args.action=='seal':request('sys/seal',{},token) + elif args.action=='publish-crl':request('auth/cert/crls/operator',{'crl':(ROOT/'secrets/trust/revocations.pem').read_text()},token) + elif args.action=='provision': + mounts=request('sys/mounts',token=token) + if 'secret/' not in mounts:request('sys/mounts/secret',{'type':'kv','options':{'version':'2'}},token) + auth=request('sys/auth',token=token) + if 'cert/' not in auth:request('sys/auth/cert',{'type':'cert'},token) + config=json.loads((ROOT/'secrets/operator/config.json').read_text()) + for role,data in config['service_credentials'].items(): + policy=f'path "secret/data/{role}" {{ capabilities = ["read"] }}\n' + request('sys/policies/acl/'+role,{'policy':policy},token) + request('auth/cert/certs/'+role,{'certificate':(ROOT/'secrets/trust/ca.crt').read_text(), + 'allowed_dns_sans':[role],'token_policies':[role],'token_ttl':120,'token_max_ttl':120,'token_no_default_policy':False},token) + request('secret/data/'+role,{'data':data},token) + # Audit is declarative in openbao.hcl; API audit creation remains disabled. + assert 'operator/' in request('sys/audit',token=token), 'Audit device missing' + print('Operator action completed; no root token/unseal shares printed') + + +if __name__=='__main__':main() diff --git a/scripts/bootstrap.py b/scripts/bootstrap.py new file mode 100644 index 0000000..f99b46e --- /dev/null +++ b/scripts/bootstrap.py @@ -0,0 +1,81 @@ +"""Generate isolated local credentials. Operator files are never app mounts.""" +import json +from pathlib import Path +import secrets +import csv +import os +import subprocess +from datetime import datetime,timedelta,timezone +import pki + +ROOT=Path(__file__).resolve().parents[1] +ROLES=['api1','api2','worker','dispatcher','reconciler'] + + +def protect_local_files(): + directory=ROOT/'secrets';directory.mkdir(exist_ok=True) + directory.chmod(0o700) + if os.name=='nt': + sid=next(csv.reader(subprocess.check_output(['whoami','/user','/fo','csv','/nh'],text=True).splitlines()))[1] + for path in (directory,ROOT/'.env',ROOT/'.env.storage-admin'): + if not path.exists():continue + flags='(OI)(CI)' if path.is_dir() else '' + result=subprocess.run(['icacls',str(path),'/inheritance:r','/grant:r', + '*'+sid+':'+flags+'F','*S-1-5-18:'+flags+'F','*S-1-5-32-544:'+flags+'F'],capture_output=True) + if result.returncode:raise RuntimeError('Could not restrict local secret ACLs') + + +def main(): + protect_local_files() + pki.init() + pki.crl() + for role in ROLES+['db','s3','broker','cache','otel-collector','prometheus','loki','tempo','grafana','lb','openbao','operator','outsider']: + cert_path=ROOT/'secrets/identities'/role/'cert.pem' + if (not cert_path.exists() or pki.x509.load_pem_x509_certificate(cert_path.read_bytes()).not_valid_after_utc + < datetime.now(timezone.utc)+timedelta(hours=2)): + pki.issue(role) + target=ROOT/'secrets/operator/config.json' + if target.exists(): + print('Existing local credentials preserved');return + password=secrets.token_hex(24) + db={role:secrets.token_hex(24) for role in ROLES} + broker={role:secrets.token_hex(24) for role in ('worker','dispatcher')} + cache={role:secrets.token_hex(24) for role in ('api1','api2')} + s3={role:(secrets.token_hex(12),secrets.token_hex(32)) for role in ROLES+['admin'] if role!='dispatcher'} + cursor=secrets.token_hex(32) + credentials={} + for role in ROLES: + credentials[role]={'DATABASE_URL':f'postgresql://{role}:{db[role]}@127.0.0.1:5432/messenger', + 'CURSOR_SECRET':cursor, + 'OTEL_EXPORTER_OTLP_ENDPOINT':'http://127.0.0.1:4318','TELEMETRY_ENABLED':'1','SESSION_TTL_SECONDS':'3600'} + if role in s3: + credentials[role].update({'S3_ENDPOINT':'http://127.0.0.1:8333','S3_BUCKET':'messenger', + 'S3_ACCESS_KEY':s3[role][0],'S3_SECRET_KEY':s3[role][1]}) + if role in cache: credentials[role]['REDIS_URL']=f'redis://{role}:{cache[role]}@127.0.0.1:6379/0' + if role in broker: credentials[role]['BROKER_URL']=f'redis://{role}:{broker[role]}@127.0.0.1:6380/0' + identities=[] + for role,(key,secret) in s3.items(): + if role=='admin':actions=['Admin','Read','Write','List','Tagging'] + elif role.startswith('api'):actions=['Read:messenger/originals/*','Read:messenger/variants/*','Write:messenger/staging/*'] + else: + actions=['Read:messenger/staging/*','Read:messenger/originals/*','Read:messenger/variants/*','Write:messenger/staging/*','Write:messenger/originals/*','Write:messenger/variants/*'] + if role=='reconciler':actions.append('List:messenger') + identities.append({'name':role,'credentials':[{'accessKey':key,'secretKey':secret}],'actions':actions}) + files={'.env':'POSTGRES_PASSWORD='+password+'\n', + '.env.storage-admin':f'S3_ENDPOINT=http://127.0.0.1:8333\nS3_BUCKET=messenger\nS3_ACCESS_KEY={s3["admin"][0]}\nS3_SECRET_KEY={s3["admin"][1]}\n', + 'secrets/s3.json':json.dumps({'identities':identities},indent=2), + 'secrets/grafana-password':secrets.token_urlsafe(24)+'\n', + 'secrets/cache.conf':'bind 127.0.0.1\nprotected-mode yes\nmaxmemory 32mb\nmaxmemory-policy allkeys-lru\nsave ""\nuser default off\n'+''.join(f'user {r} on >{v} ~user:* -@all +get +set +ping +hello +client|setinfo\n' for r,v in cache.items()), + 'secrets/broker.conf':'bind 127.0.0.1\nprotected-mode yes\nappendonly yes\nappendfsync always\ndir /data\nsave ""\nmaxmemory 64mb\nmaxmemory-policy noeviction\nuser default off\n'+ + f'user dispatcher on >{broker["dispatcher"]} ~attachment-jobs -@all +xadd +xgroup +ping +hello +client|setinfo\n'+ + f'user worker on >{broker["worker"]} ~attachment-jobs -@all +xgroup +xautoclaim +xreadgroup +xack +xdel +multi +exec +ping +hello +client|setinfo\n', + 'secrets/operator/config.json':json.dumps({'database_passwords':db,'service_credentials':credentials},indent=2)} + for name,value in files.items(): + p=ROOT/name;p.parent.mkdir(parents=True,exist_ok=True) + with p.open('x',encoding='utf-8',newline='\n') as f:f.write(value) + p.chmod(0o600) + protect_local_files() + print('Generated separate identities and local secrets; values not printed') + + +if __name__=='__main__':main() diff --git a/scripts/dashboard.py b/scripts/dashboard.py new file mode 100644 index 0000000..9ec3f4d --- /dev/null +++ b/scripts/dashboard.py @@ -0,0 +1,37 @@ +"""Generate the committed, provisioned dashboard from explicit PromQL.""" +import json +from pathlib import Path + +panels=[] +def panel(title,queries,unit='short'): + i=len(panels) + panels.append({'id':i+1,'type':'timeseries','title':title,'datasource':{'type':'prometheus','uid':'prometheus'}, + 'gridPos':{'x':(i%2)*12,'y':(i//2)*8,'w':12,'h':8}, + 'targets':[{'refId':chr(65+j),'expr':expr,'legendFormat':label} for j,(label,expr) in enumerate(queries)], + 'fieldConfig':{'defaults':{'unit':unit,'min':0,**({'max':1} if unit=='percentunit' else {})},'overrides':[]},'options':{'legend':{'displayMode':'list','placement':'bottom'}}}) + +panel('API requests / second',[('{{method}} {{route}}','sum by(method,route)(rate(http_server_requests_total[1m]))')],'reqps') +panel('API 5xx / all business requests',[('5xx fraction','(sum(rate(http_server_requests_total{status_class="5xx"}[1m])) or vector(0)) / clamp_min(sum(rate(http_server_requests_total[1m])),0.001)')],'percentunit') +panel('API latency: aggregate buckets across replicas',[(f'p{p}',f'histogram_quantile({p/100},sum by(le)(rate(http_server_duration_seconds_bucket[1m])))') for p in (50,95,99)],'s') +panel('Jobs / second by outcome',[('{{outcome}}','sum by(outcome)(rate(jobs_processed_total[1m]))')],'ops') +panel('Worker processing latency',[(f'p{p}',f'histogram_quantile({p/100},sum by(le)(rate(job_processing_duration_seconds_bucket[1m])))') for p in (50,95,99)],'s') +panel('Acceptance to ready latency',[(f'p{p}',f'histogram_quantile({p/100},sum by(le)(rate(attachment_time_to_ready_seconds_bucket[5m])))') for p in (50,95,99)],'s') +panel('Unfinished durable jobs',[('queue depth','sum(queue_depth)')]) +panel('Oldest unfinished job age',[('oldest','max(queue_oldest_age_seconds)')],'s') +panel('DB pool',[('used {{process_instance}}','db_pool_used'),('waiting {{process_instance}}','db_pool_waiting')]) +panel('Worker saturation',[('busy / capacity','sum(worker_busy) / clamp_min(sum(worker_capacity),1)')],'percentunit') +panel('Current process RSS',[('{{service}} {{process_instance}}','process_rss_bytes')],'bytes') +panel('Process CPU seconds / wall second',[('{{service}} {{process_instance}}','clamp_min(deriv(process_cpu_time_seconds[1m]),0)')],'short') +panel('API availability burn rate; budget 0.5%',[(f'{w}s',f'(sum(rate(http_server_requests_total{{status_class="5xx"}}[{w}s])) or vector(0)) / clamp_min(sum(rate(http_server_requests_total[{w}s])),0.001) / 0.005') for w in (20,60)]) +panel('Ready <=30s burn rate; budget 1%',[(f'{w}s eligible cohort',f'sum(attachment_slo_bad{{window="{w}"}}) / clamp_min(sum(attachment_slo_eligible{{window="{w}"}}),1) / 0.01') for w in (60,300)]) +panel('Collector exporter queue / capacity',[('{{exporter}} size','otelcol_exporter_queue_size'),('{{exporter}} capacity','otelcol_exporter_queue_capacity')]) +panel('Collector failed exports',[('{{exporter}} spans','rate(otelcol_exporter_send_failed_spans_total[1m])'),('{{exporter}} logs','rate(otelcol_exporter_send_failed_log_records_total[1m])')],'ops') +panels.append({'id':99,'type':'logs','title':'Structured application logs; TraceID links to Tempo','datasource':{'type':'loki','uid':'loki'}, + 'gridPos':{'x':0,'y':64,'w':24,'h':10},'targets':[{'refId':'A','expr':'{service_name=~"messenger-(api|worker|dispatcher)"}'}], + 'options':{'showTime':True,'showLabels':False,'wrapLogMessage':True,'sortOrder':'Descending'}}) +doc={'uid':'mtusi-messenger','title':'MTUSI Messenger - signals and SLO','schemaVersion':39,'version':1, + 'editable':False,'timezone':'browser','time':{'from':'now-15m','to':'now'},'refresh':'15s','tags':['mtusi','lab6'], + 'panels':panels,'annotations':{'list':[]},'templating':{'list':[]}} +path=Path(__file__).resolve().parents[1]/'infra/grafana/dashboards/messenger.json' +path.parent.mkdir(parents=True,exist_ok=True) +path.write_text(json.dumps(doc,ensure_ascii=False,indent=2)+'\n',encoding='utf-8') diff --git a/scripts/database_operator.py b/scripts/database_operator.py new file mode 100644 index 0000000..2868a94 --- /dev/null +++ b/scripts/database_operator.py @@ -0,0 +1,47 @@ +"""Operator migrations/grants over the container-local PostgreSQL Unix socket. + +SQL containing passwords travels on stdin, not argv/logs; no admin DB credential +is made available to an application. Existing migration hashes must match. +""" +import hashlib +import json +from pathlib import Path +import subprocess + +ROOT=Path(__file__).resolve().parents[1] + + +def sql(query): + result=subprocess.run(['docker','compose','exec','-T','db','psql','-X','-qAt', + '-v','ON_ERROR_STOP=1','-U','messenger','-d','messenger'],input=query, + text=True,encoding='utf-8',capture_output=True,cwd=ROOT) + if result.returncode: + # Server error text may echo a credential-bearing statement. + raise RuntimeError('Operator SQL failed; no query or credentials printed') + return result.stdout.strip() + + +def main(): + sql('CREATE TABLE IF NOT EXISTS schema_migrations (name text PRIMARY KEY, sha256 text NOT NULL, applied_at timestamptz NOT NULL DEFAULT clock_timestamp())') + for file in sorted((ROOT/'migrations').glob('*.sql')): + digest=hashlib.sha256(file.read_bytes()).hexdigest() + old=sql(f"SELECT sha256 FROM schema_migrations WHERE name='{file.name}'") + if old: + assert old==digest, 'Applied migration changed: '+file.name + else: + sql('BEGIN;\n'+file.read_text()+f"\nINSERT INTO schema_migrations(name,sha256) VALUES ('{file.name}','{digest}'); COMMIT;") + print('Migration verified:',file.name) + passwords=json.loads((ROOT/'secrets/operator/config.json').read_text())['database_passwords'] + for role,password in passwords.items(): + assert role in ('api1','api2','worker','dispatcher','reconciler') and all(c in '0123456789abcdef' for c in password) + if not sql(f"SELECT 1 FROM pg_roles WHERE rolname='{role}'"):sql(f'CREATE ROLE {role} LOGIN') + sql(f"ALTER ROLE {role} PASSWORD '{password}' NOSUPERUSER NOCREATEDB NOCREATEROLE NOREPLICATION; GRANT CONNECT ON DATABASE messenger TO {role}; GRANT USAGE ON SCHEMA public TO {role}; REVOKE ALL ON ALL TABLES IN SCHEMA public FROM {role}; REVOKE ALL ON ALL SEQUENCES IN SCHEMA public FROM {role};") + sql('REVOKE ALL ON DATABASE messenger FROM PUBLIC; REVOKE CREATE ON SCHEMA public FROM PUBLIC;') + sql('GRANT SELECT,INSERT,UPDATE,DELETE ON users,sessions,chats,members,messages,idempotency,attachments,message_attachments,jobs,outbox,login_budget TO api1,api2;') + sql('GRANT SELECT,UPDATE ON jobs,attachments,outbox,job_faults TO worker; GRANT INSERT ON job_audit TO worker; GRANT USAGE ON SEQUENCE job_audit_id_seq TO worker;') + sql('GRANT SELECT,UPDATE ON jobs,attachments,outbox TO dispatcher; GRANT INSERT ON job_audit TO dispatcher; GRANT USAGE ON SEQUENCE job_audit_id_seq TO dispatcher;') + sql('GRANT SELECT,UPDATE ON attachments TO reconciler;') + print('Scoped database roles applied') + + +if __name__=='__main__':main() diff --git a/scripts/pki.py b/scripts/pki.py new file mode 100644 index 0000000..19748e4 --- /dev/null +++ b/scripts/pki.py @@ -0,0 +1,84 @@ +"""Operator-owned local PKI. CA private material is never mounted into services.""" +from datetime import datetime, timedelta, timezone +import ipaddress +import json +from pathlib import Path +from cryptography import x509 +from cryptography.hazmat.primitives import hashes, serialization +from cryptography.hazmat.primitives.asymmetric import ec +from cryptography.x509.oid import NameOID, ExtendedKeyUsageOID + +ROOT=Path(__file__).resolve().parents[1] +PRIVATE=ROOT/'secrets/operator' +TRUST=ROOT/'secrets/trust' + + +def write(path,data): + path.parent.mkdir(parents=True,exist_ok=True) + path.write_bytes(data) + path.chmod(0o600 if 'key' in path.name or path.name == 'combined.pem' or path.parent == PRIVATE else 0o644) + + +def key_bytes(key): + return key.private_bytes(serialization.Encoding.PEM,serialization.PrivateFormat.PKCS8,serialization.NoEncryption()) + + +def ca(): + return (serialization.load_pem_private_key((PRIVATE/'ca.key').read_bytes(),None), + x509.load_pem_x509_certificate((TRUST/'ca.crt').read_bytes())) + + +def init(): + if (PRIVATE/'ca.key').exists(): return + key=ec.generate_private_key(ec.SECP256R1()); now=datetime.now(timezone.utc) + name=x509.Name([x509.NameAttribute(NameOID.COMMON_NAME,'MTUSI local operator CA')]) + cert=(x509.CertificateBuilder().subject_name(name).issuer_name(name).public_key(key.public_key()) + .serial_number(x509.random_serial_number()).not_valid_before(now-timedelta(minutes=1)) + .not_valid_after(now+timedelta(days=365)).add_extension(x509.BasicConstraints(ca=True,path_length=0),True) + .add_extension(x509.KeyUsage(False,False,False,False,False,True,True,None,None),True) + .add_extension(x509.SubjectKeyIdentifier.from_public_key(key.public_key()),False).sign(key,hashes.SHA256())) + write(PRIVATE/'ca.key',key_bytes(key));write(TRUST/'ca.crt',cert.public_bytes(serialization.Encoding.PEM)) + write(PRIVATE/'revoked.json',b'[]'); crl() + + +def issue(role,hours=24,extra=()): + key,issuer=ca(); leaf=ec.generate_private_key(ec.SECP256R1()); now=datetime.now(timezone.utc) + sans=[x509.DNSName(role),*[x509.DNSName(n) for n in extra]] + if role in ('lb','openbao','grafana'): sans += [x509.DNSName('localhost'),x509.IPAddress(ipaddress.ip_address('127.0.0.1'))] + cert=(x509.CertificateBuilder().subject_name(x509.Name([x509.NameAttribute(NameOID.COMMON_NAME,role)])) + .issuer_name(issuer.subject).public_key(leaf.public_key()).serial_number(x509.random_serial_number()) + .not_valid_before(now-timedelta(minutes=1)).not_valid_after(now+timedelta(hours=hours)) + .add_extension(x509.BasicConstraints(ca=False,path_length=None),True) + .add_extension(x509.SubjectAlternativeName(sans),False) + .add_extension(x509.ExtendedKeyUsage([ExtendedKeyUsageOID.SERVER_AUTH,ExtendedKeyUsageOID.CLIENT_AUTH]),False) + .add_extension(x509.AuthorityKeyIdentifier.from_issuer_public_key(key.public_key()),False) + .sign(key,hashes.SHA256())) + folder=ROOT/'secrets/identities'/role + write(folder/'key.pem',key_bytes(leaf));write(folder/'cert.pem',cert.public_bytes(serialization.Encoding.PEM)) + write(folder/'combined.pem',cert.public_bytes(serialization.Encoding.PEM)+key_bytes(leaf)) + return cert + + +def crl(): + key,issuer=ca();now=datetime.now(timezone.utc) + doc=x509.CertificateRevocationListBuilder().issuer_name(issuer.subject).last_update(now-timedelta(minutes=1)).next_update(now+timedelta(days=7)) + for serial in json.loads((PRIVATE/'revoked.json').read_text()): + doc=doc.add_revoked_certificate(x509.RevokedCertificateBuilder().serial_number(serial).revocation_date(now).build()) + pem=doc.sign(key,hashes.SHA256()).public_bytes(serialization.Encoding.PEM) + write(TRUST/'revocations.pem',pem);write(TRUST/'bundle.pem',(TRUST/'ca.crt').read_bytes()+pem) + + +def revoke(role): + cert=x509.load_pem_x509_certificate((ROOT/'secrets/identities'/role/'cert.pem').read_bytes()) + path=PRIVATE/'revoked.json';values=json.loads(path.read_text()) + if cert.serial_number not in values: values.append(cert.serial_number) + write(path,json.dumps(values).encode());crl() + + +if __name__=='__main__': + import argparse + p=argparse.ArgumentParser();p.add_argument('action',choices=['issue','revoke']);p.add_argument('role');p.add_argument('--hours',type=float,default=24) + a=p.parse_args();init() + if a.action=='issue': issue(a.role,a.hours) + else: revoke(a.role) + print('PKI operation complete; no key material printed') diff --git a/scripts/restart.cmd b/scripts/restart.cmd new file mode 100644 index 0000000..1a8d2ef --- /dev/null +++ b/scripts/restart.cmd @@ -0,0 +1,3 @@ +@echo off +if not defined LAB7_PYTHON set "LAB7_PYTHON=python" +"%LAB7_PYTHON%" "%~dp0restart.py" diff --git a/scripts/restart.py b/scripts/restart.py new file mode 100644 index 0000000..1caa94a --- /dev/null +++ b/scripts/restart.py @@ -0,0 +1,17 @@ +"""Restart every running replica and dependency, preserving durable volumes.""" +import json +import subprocess +import sys +from stack import ROOT, docker, state + +before = state() +docker('compose', 'stop', '--timeout', '5') +docker('compose', 'start') +subprocess.run([sys.executable,str(ROOT/'scripts/bao_operator.py'),'unseal'],check=True) +after = state() +assert set(before) == set(after) +assert all(before[c]['state']['StartedAt'] != after[c]['state']['StartedAt'] for c in before) +(ROOT / 'evidence').mkdir(exist_ok=True) +(ROOT / 'evidence/restart-processes.json').write_text( + json.dumps({'before': before, 'after': after, 'volumes_removed': False}, indent=2) + '\n', + encoding='utf-8') diff --git a/scripts/restart.sh b/scripts/restart.sh new file mode 100755 index 0000000..d504e1e --- /dev/null +++ b/scripts/restart.sh @@ -0,0 +1,4 @@ +#!/bin/sh +set -eu +cd "$(dirname "$0")/.." +python3 scripts/restart.py diff --git a/scripts/scan_images.py b/scripts/scan_images.py new file mode 100644 index 0000000..8fd44fd --- /dev/null +++ b/scripts/scan_images.py @@ -0,0 +1,39 @@ +"""Scan exported image archives without mounting the Docker socket or host secrets.""" +import argparse +import collections +from datetime import datetime,timezone +import hashlib +import json +from pathlib import Path +import subprocess +import tempfile +import yaml + +ROOT=Path(__file__).resolve().parents[1] +TRIVY='aquasec/trivy@sha256:790fd66d1697395d8693d1acaa1ea702406a20f109b6fc7bac8db623eca6c06c' + + +def main(): + parser=argparse.ArgumentParser();parser.add_argument('services',nargs='*',default=['api1','openbao','s3','lb']);args=parser.parse_args() + compose=yaml.safe_load((ROOT/'compose.yaml').read_text()) + summary={'at_UTC':datetime.now(timezone.utc).isoformat(),'scanner':TRIVY,'scope':args.services,'images':[]} + with tempfile.TemporaryDirectory(prefix='lab7-image-scan-') as tmp: + for service in args.services: + image=compose['services'][service]['image'] + image_id=subprocess.check_output(['docker','image','inspect',image,'--format','{{.Id}}'],text=True).strip() + archive=Path(tmp)/'image.tar';report=Path(tmp)/'report.json' + subprocess.run(['docker','save','--output',str(archive),image],check=True) + subprocess.run(['docker','run','--rm','--cpus','0.5','--memory','768m','--pids-limit','128', + '-v',tmp+':/scan','-v','mtusi-trivy-cache:/root/.cache/trivy',TRIVY,'image','--input','/scan/image.tar', + '--parallel','1','--scanners','vuln','--format','json','--output','/scan/report.json'],check=True) + data=json.loads(report.read_text());findings=[] + for result in data.get('Results',[]): + for v in result.get('Vulnerabilities',[]): + findings.append({'target':result.get('Target'),**{k:v.get(k) for k in ('VulnerabilityID','PkgName','InstalledVersion','FixedVersion','Severity','Title','PrimaryURL')}}) + summary['images'].append({'service':service,'image':image,'image_id':image_id,'report_sha256':hashlib.sha256(report.read_bytes()).hexdigest(), + 'counts':dict(collections.Counter(v['Severity'] for v in findings)),'findings':findings}) + (ROOT/'evidence/image-audit.json').write_text(json.dumps(summary,indent=2)+'\n') + print(service,summary['images'][-1]['counts'],flush=True) + + +if __name__=='__main__':main() diff --git a/scripts/stack.py b/scripts/stack.py new file mode 100644 index 0000000..0bd80cc --- /dev/null +++ b/scripts/stack.py @@ -0,0 +1,35 @@ +"""Shared bounded Docker helpers for reproducible, scoped failure experiments.""" +import json +from pathlib import Path +import subprocess +import time +ROOT=Path(__file__).resolve().parents[1] +def docker(*args): + return subprocess.check_output(['docker',*args],cwd=ROOT,text=True,encoding='utf-8',stderr=subprocess.PIPE).strip() +def replicas(): return docker('compose','ps','-q','api1','api2').splitlines() + +def ready_replicas(count=2,timeout=60): + deadline=time.monotonic()+timeout + while time.monotonic()=1s context cache expiration, no weakening of certificate verification. + time.sleep(2) + run(compose+['run','--rm','--no-deps','security-check'],'tls-matrix',json_output=True) + run(compose+['run','--rm','--no-deps','security-check','python','/checks/bao_policy.py'],'bao-policy',json_output=True) + run(compose+['exec','-T','worker','python','-'],'worker-rights',input=(ROOT/'checks/worker_rights.py').read_text(),json_output=True) + run(py+['checks/security_api.py'],'security-api-run') + time.sleep(10) + run(py+['checks/compromised_worker.py'],'compromised-worker-run') + run(py+['checks/sealed_bao.py'],'sealed-bao-run') + run(py+['checks/telemetry_security.py'],'telemetry-security-run') + run(py+['checks/hardening.py'],'hardening-run') + run(compose+['run','--rm','--no-deps','-v',str(ROOT/'checks')+':/checks:ro','api1','python','-m','unittest','discover','-s','/checks','-p','test_render.py'],'render-unit') + (ROOT/'evidence/security-suite.json').write_text(json.dumps({'passed':True,'completed_at_UTC':datetime.now(timezone.utc).isoformat()},indent=2)+'\n') + + +if __name__=='__main__':main() diff --git a/security/SCAN_TRIAGE.md b/security/SCAN_TRIAGE.md new file mode 100644 index 0000000..ee5210b --- /dev/null +++ b/security/SCAN_TRIAGE.md @@ -0,0 +1,71 @@ +# Разбор dependency/image scan + +Сканирование 12.11.2026: `evidence/dependency-audit.json` (pip-audit по точным +runtime requirements) и `evidence/image-audit.json` (Trivy 0.76.1, digest в +scripts/scan_images.py). В JSON сохранены image IDs, SHA-256 полного отчёта, +пакеты, версии, CVE, ссылки advisories и severity. Сканер получает экспорт +образа, а не Docker socket или каталог secrets. Повтор: `python scripts/scan_images.py`. +Для dependencies: `python -m pip_audit --no-deps --disable-pip -r requirements.txt --format json`. + +| Образ | Critical | High | Medium | Low | Unknown | +| --- | ---: | ---: | ---: | ---: | ---: | +| app/API/worker/TLS proxy | 0 | 48 | 75 | 66 | 19 | +| OpenBao 2.7.2 | 0 | 3 | 6 | 0 | 2 | +| SeaweedFS 4.53 | 0 | 1 | 1 | 0 | 2 | +| HAProxy 3.4.7 | 0 | 0 | 1 | 0 | 0 | + +Это число записей package/CVE, а не уникальных способов атаковать приложение. +Scope — четыре основных образа; отдельные PostgreSQL/Valkey/telemetry образы +этим отчётом не покрыты. Нулевые Critical не означают отсутствие риска. + +## Исправления + +Обновлены Pillow до 13.0.0 и certifi до 2026.10.23; pip-audit не обнаружил +известных уязвимостей в закреплённых runtime requirements. Обновлены официальные +Python, OpenBao, SeaweedFS и HAProxy images с закреплением digest. Устранён +Critical brotli из старого SeaweedFS. Debian zlib1g дополнительно обновлён до +1:1.3.dfsg+really1.3.1-1+deb13u1, устраняя CVE-2026-76844/85091/27171. +Ненужный runtime setuptools удалён; pip обновлён до 26.3. + +## Применимость и остаточный риск + +* Debian util-linux/mount/nsenter (например CVE-2026-78408/78409/78410): + описанные операции требуют локального выполнения/операций с mount namespace. + HTTP API их не вызывает; runtime UID10001, cap_drop ALL, no-new-privileges, + read_only и отсутствие host mounts уменьшают достижимость. Это ограничение + сценария, а не доказательство невозможности эксплуатации после RCE. +* glibc/libstdc++: часть находок относится к неиспользуемым интерфейсам + (wordexp, strfmon, nscd, пользовательские locale). DNS resolver и нативные + библиотеки реально используются, поэтому всю группу нельзя пометить как + неприменимую. Для многих записей scanner не указывает исправленную Debian + версию. Риск остаётся; нужны последующие vendor updates и повторный scan. +* tar/Perl/ncurses: приложение не принимает архивы, не запускает Perl/terminal + utilities и не передаёт пользовательские строки в shell. Основной + пользовательский binary input — PNG/JPEG, ограниченный размером, пикселями, + CPU/RAM/time и renderer subprocess. Это не замена обновлению системных пакетов. +* Trivy продолжает сообщать setuptools70.3.0 в target Python после удаления + установленного пакета. Поиск filesystem не нашёл его dist-info; finding + сохранён без suppression, окончательный источник метаданных не установлен. + Runtime не собирает/устанавливает пакеты и не обрабатывает MANIFEST.in. +* OpenBao go-jose CVE-2026-116585/116586/116587: стенд использует cert auth и KV, + не JWT/OIDC/JWE. Такие auth engines не включены; native mTLS требует доверенный + client cert до API. Потенциальный DoS для иных путей/после компрометации identity + не исключён; встроенную Go dependency нельзя исправить заменой Python-пакета. +* OpenBao/Seaweed x/net/html CVE-2026-78661/97045: workload не обрабатывает + пользовательский HTML и не публикует UI Seaweed. Native ports loopback, + доступ через allowlisted mTLS и S3 credentials. Достижимость уязвимой функции + не доказана; это условно ограниченный, а не исключённый риск. +* HAProxy/OpenBao zlib CVE-2026-4738: HTTP compression в HAProxy не настроена, + но библиотека присутствует. Остаточный риск принят только для изолированного + учебного стенда; требуется следующий исправленный vendor image. + +Unknown сохранены как неопределённые, а не переименованы в безопасные. Перед +реальным публичным deployment необходимы полный scope всех образов, обновление +оставшихся библиотек и независимая проверка достижимости функций. + +Версии/описания в этой таблице — результат локального scanner snapshot, а +применимость — анализ конфигурации данного репозитория. Первичные advisory URLs +для каждой записи находятся в JSON. Дополнительно: +[OpenBao releases](https://github.com/openbao/openbao/releases), +[SeaweedFS releases](https://github.com/seaweedfs/seaweedfs/releases), +[HAProxy TLS/SNI](https://www.haproxy.com/documentation/haproxy-configuration-tutorials/security/ssl-tls/basics-enable-tls/). diff --git a/security/THREAT_MODEL.md b/security/THREAT_MODEL.md index 31da287..62d779e 100644 --- a/security/THREAT_MODEL.md +++ b/security/THREAT_MODEL.md @@ -1,19 +1,52 @@ -# Модель угроз — заполнить +# Модель угроз ЛР7 -## Активы и акторы +Парамонов Глеб, БВТ2301. Цель: 5, трек «Компрометация worker». -TODO: пользовательские credentials/сессии, сообщения/вложения, service identities, CA/secrets, telemetry. Акторы: участник чата, посторонний пользователь, внешний клиент, скомпрометированный сервис, оператор. Опишите доступ атакующего и границы учебного стенда. +Активы: password hashes, сессии, сообщения/вложения, jobs/outbox, identities, +CA/secrets, telemetry. Акторы: участник чата, посторонний пользователь, сетевой +клиент, атакующий с правами worker, оператор. Хост, Docker daemon и оператор +доверены; захват CA/root token вне модели. Worker не получает Docker socket, +операторские файлы или чужие cert volumes. Сеть Docker считается доступной +атакующему, поэтому сама bridge-сеть не является авторизацией. Plaintext +допустим только в loopback namespace пары процесс/его TLS sidecar. -## Границы доверия +[Матрица](../contracts/trust-matrix.md) определяет связи, SAN и проверки. -TODO: схема и ссылка на заполненную contracts/trust-matrix.md; публичные/внутренние интерфейсы, процессы, секреты и их выдача. +| Конкретный путь атаки | Контроль | Отрицательный тест | Остаточный риск | +| --- | --- | --- | --- | +| Eve угадывает UUID чужого вложения/чата | Bearer → membership, единый 404 | public smoke, security_api: metadata/content/thumbnail/upload | Захват участника даёт его законные права | +| X-User-Id подменяет автора; истёкшая сессия используется снова | Автор только из Bearer, SHA-256 token в БД, logout/expires_at | public smoke + security_api | Живой украденный bearer действует до logout/expiry; MFA нет | +| Basic login расходует KDF память | Argon2id 32MiB/t2/p1, 2 KDF slots/API, общий PG limiter 12/10s | 20 параллельных запросов, две реплики: 12×401, 8×429 + Retry-After | Глобальный лимит может блокировать законные входы; это ограничение стоимости, не антибот | +| Прямой обход LB через API:8080 | Loopback-only API; внешний API:8443 требует SAN lb | tls_matrix: без cert, foreign CA, same-CA outsider, plaintext | Захват LB даёт его транспортные права, но не business Bearer | +| Worker читает секрет API через OpenBao | Cert auth SAN=role, policy только свой secret/data/role | bao_policy: other path/admin 403, wrong role denied | KV пароль статический; TTL токена не равен TTL пароля backend | +| Worker читает sessions/password_hashes или создаёт роль | NOSUPERUSER/NOCREATEROLE, узкие GRANT, SCRAM даже на loopback | worker_rights, compromised_worker: old password denied | Разрешённые attachment/jobs данные worker может испортить | +| Worker публикует job, читает другую queue, создаёт bucket | Valkey ACL по командам/ключу, S3 prefix ACL | XADD/CONFIG/foreign stream/prefix/CreateBucket denied | Разрешённые объекты worker может удалить | +| MITM или использование expired/revoked cert | TLS>=1.2, CA+hostname, SAN allowlist, CRL, соединение <=60s | tls_matrix на каждом listener, public security, compromised_worker | Renewal ручной; HAProxy перечитывает CRL при restart/reload | +| Sealed Bao оставляет бесконечный кэш secrets | Re-auth 20s, token TTL <=120s, child останавливается по expiry | sealed_bao: обе API реально закрывают loopback listeners, затем recovery | Атакующий может сохранить static password; его отзывает ротация backend, а не supervisor | +| Crafted image расходует CPU/RAM | PNG/JPEG whitelist, 10MiB/40Mpx, render subprocess/timeout, worker 1CPU/768MiB/pids64 | smoke upload, test_render, dependency scan | Native decoder остаётся поверхностью атаки, контейнер не VM sandbox | +| Secret попадает в telemetry/Git/образ | Явные поля без body/headers, ignore rules, отдельные cert volumes | telemetry_security, hardening audit, staged secret scan | Canary scan не доказывает отсутствие всех каналов утечки | -| Угроза и конкретный путь | Нарушаемый инвариант | Контроль | Отрицательный тест | Остаточное ограничение | -| --- | --- | --- | --- | --- | -| TODO | TODO | TODO | TODO | TODO | +## Bootstrap и lifecycle -На 4 минимум 6 конкретных угроз. Не заменяйте сценарии словами «SQL injection», «безопасный Docker», «mTLS включён» без пути и проверки. +`scripts/up.py`: локальная PKI → non-dev OpenBao raft → init (3 shares, threshold +2) → explicit unseal → scoped policies/KV → SQL migrations/GRANT → private +bucket → runtime. Root token и shares в `secrets/operator`, не в контейнерах. +Windows ACL: только текущий пользователь, SYSTEM, Administrators. POSIX: +secrets directory 0700, private files 0600. Кратковременный `secret-init` видит +только service leaf identities/configs и копирует их в отдельные volumes с UID +получателя; CA private key и operator identity он не видит. -## Lifecycle и инциденты +CA 365d, leaf 24h. Повтор bootstrap обновляет leaf с остатком <2h и CRL. Native +TLS LB/OpenBao/Grafana требует restart/reload; proxy кеширует TLS context не дольше +1s, существующее соединение живёт до 60s (граница распространения отзыва 61s). +API restart не требует unseal; рестарт Bao требует оператора. +Хранение всех долей на одной защищённой рабочей станции — учебное упрощение, +не распределённое хранение. Production требует независимых custodians/offline +backup, автоматизированного renewal и HA secret service. -TODO: bootstrap, expiry/renewal, revoke/rotation, компрометация identity, sealed OpenBao и восстановление. Указать владельца CA/unseal и способ защиты bootstrap credentials. Сопоставить scan findings с реальной применимостью и исправлением/остаточным риском. +Инцидент worker: CRL + cert-auth CRL → завершить старые DB sessions → изменить +пароль БД → новый leaf → secret-init → обновить worker KV → supervisor получает +изменение. `checks/compromised_worker.py` проверяет новые подключения старым +cert/паролем, 3 сохранённых задания и SHA-256 после восстановления. При утечке +остальных credentials отдельно ротируются S3/Valkey: пароль БД не отзывает все +скопированные secrets. [Разбор сканирования](SCAN_TRIAGE.md). diff --git a/src/__init__.py b/src/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/__main__.py b/src/__main__.py new file mode 100644 index 0000000..640133b --- /dev/null +++ b/src/__main__.py @@ -0,0 +1,9 @@ +import logging +import os +import uvicorn + +logging.basicConfig(level=logging.INFO, format='%(message)s') +uvicorn.run('src.app:app', host=os.environ.get('APP_HOST', '0.0.0.0'), + port=int(os.environ.get('APP_PORT', '8080')), workers=1, + access_log=False, server_header=False, timeout_keep_alive=2, + timeout_graceful_shutdown=32, backlog=64, h11_max_incomplete_event_size=16384) diff --git a/src/app.py b/src/app.py new file mode 100644 index 0000000..a25744e --- /dev/null +++ b/src/app.py @@ -0,0 +1,287 @@ +import asyncio +import base64 +from contextlib import asynccontextmanager +from dataclasses import dataclass +import os +import re +import secrets +import tempfile +import unicodedata + +from argon2 import PasswordHasher +from argon2.exceptions import VerificationError, InvalidHashError +from fastapi import FastAPI, Request, Response +import psycopg +from psycopg_pool import PoolTimeout, TooManyRequests +from starlette.exceptions import HTTPException +from starlette.responses import StreamingResponse +from botocore.exceptions import BotoCoreError, ClientError + +from .common import ApiError, invalid, json_body, object_fields, pagination, string, uuid_value +from .http import Boundaries, error_response +from .store import Store, clean +from .storage import Storage, MAX_BYTES, validate_image +from .offload import complete_thread +from . import telemetry as tel + + +@dataclass +class Settings: + database_url: str + redis_url: str + cursor_secret: str + session_ttl_seconds: int = 3600 + db_pool_size: int = 5 + max_body_bytes: int = 32768 + max_inflight: int = 32 + request_timeout: int = 30 + write_rps: int = 100 + write_burst: int = 100 + + @classmethod + def environment(cls): + result=cls(database_url=os.environ['DATABASE_URL'],redis_url=os.environ['REDIS_URL'],cursor_secret=os.environ['CURSOR_SECRET'], + **{name:int(os.environ.get(name.upper(),field.default)) for name,field in cls.__dataclass_fields__.items() if field.type is int}) + if len(result.cursor_secret)<32 or any(getattr(result,name)<=0 for name,field in cls.__dataclass_fields__.items() if field.type is int): + raise ValueError('Invalid configuration') + return result + + +def create_app(settings=None): + tel.setup('messenger-api') + cfg=settings or Settings.environment() + store=Store(cfg) + storage=Storage() + uploads=asyncio.Semaphore(2) + decoders=asyncio.Semaphore(1) + downloads=asyncio.Semaphore(4) + hasher=PasswordHasher(time_cost=2,memory_cost=32768,parallelism=1) + dummy_hash=hasher.hash(secrets.token_urlsafe(32)) + kdf_slots=asyncio.Semaphore(2) + + @asynccontextmanager + async def lifespan(api): + await store.open() + async def gauges(): + while True: + stats=store.pool.get_stats() + attrs={'process_instance':tel.instance} + tel.pool_used.set(stats.get('pool_size',0)-stats.get('pool_available',0),attrs) + tel.pool_waiting.set(stats.get('requests_waiting',0),attrs) + tel.process_metrics() + await asyncio.sleep(5) + task=asyncio.create_task(gauges()) + try: yield + finally: + task.cancel() + try: await task + except asyncio.CancelledError: pass + await store.close() + storage.client.close() + await asyncio.to_thread(tel.shutdown) + + # This pinned FastAPI release has native telemetry. Disable it because the + # explicit boundary below owns sampling, health exclusion and redaction. + api=FastAPI(lifespan=lifespan,openapi_url=None,docs_url=None,redoc_url=None, + telemetry={'tracing':False,'metrics':False,'logs':False, + 'operation_spans':False,'auto_configure':False}) + api.state.store=store + + @api.exception_handler(ApiError) + async def api_error(request,exc): return error_response(exc,request.state.request_id) + + @api.exception_handler(HTTPException) + async def http_error(request,exc): + return error_response(ApiError(404,'not_found','Route not found'),request.state.request_id) + + async def database_error(request,exc): + return error_response(ApiError(503,'unavailable','Database unavailable',{'Retry-After':'1'}),request.state.request_id) + for exception in (psycopg.Error,PoolTimeout,TooManyRequests): api.add_exception_handler(exception,database_error) + + async def storage_error(request,exc): + return error_response(ApiError(503,'unavailable','Object storage unavailable',{'Retry-After':'1'}),request.state.request_id) + for exception in (BotoCoreError,ClientError): api.add_exception_handler(exception,storage_error) + + @api.exception_handler(psycopg.DataError) + async def data_error(request,exc): + return error_response(ApiError(400,'invalid_request','Unsupported field value'),request.state.request_id) + + def unauthorized(basic=False): + scheme='Basic realm="messenger", charset="UTF-8"' if basic else 'Bearer realm="messenger"' + return ApiError(401,'unauthorized','Invalid credentials',{'WWW-Authenticate':scheme}) + + def bearer(request): + value=request.headers.get('authorization','') + parts=value.split() + if len(parts)!=2 or parts[0].lower()!='bearer' or not re.fullmatch(r'[A-Za-z0-9_-]{43}',parts[1]): + raise unauthorized() + return parts[1] + + async def actor(request): + with tel.span('db.session.authenticate',attributes={'db.system.name':'postgresql'}): + return await store.authenticate(bearer(request)) + + @api.get('/health/live') + async def live(): return {'status':'ok'} + + @api.get('/health/ready') + async def ready(): + await store.ready() + await asyncio.to_thread(storage.ready) + return {'status':'ok'} + + @api.post('/api/v1/users',status_code=201) + async def register(request:Request): + await store.login_limit('register', 8) + body=object_fields(await json_body(request),('username','display_name','password')) + username=string(body['username'],32) + if not re.fullmatch(r'[a-z0-9_]{3,32}',username): invalid('Invalid username') + name=string(body['display_name'],100) + password=string(body['password'],128) + if len(password)<12: invalid('Password must contain 12..128 code points') + async with kdf_slots: hashed=await asyncio.to_thread(hasher.hash,password) + return await store.register(username,name,hashed) + + @api.post('/api/v1/auth/sessions',status_code=201) + async def login(request:Request): + await store.login_limit('login', 12) + try: + scheme,encoded=request.headers.get('authorization','').split(' ',1) + if scheme.lower()!='basic': raise ValueError() + username,password=base64.b64decode(encoded,validate=True).decode('utf-8').split(':',1) + if not re.fullmatch(r'[a-z0-9_]{3,32}',username) or not 12<=len(password)<=128: raise ValueError() + except (ValueError,UnicodeError): raise unauthorized(True) from None + if await request.body(): invalid('Session login does not accept a body') + row=await store.credentials(username) + try: + async with kdf_slots: await asyncio.to_thread(hasher.verify,row['password_hash'] if row else dummy_hash,password) + except (VerificationError,InvalidHashError): raise unauthorized(True) from None + if not row: raise unauthorized(True) + if hasher.check_needs_rehash(row['password_hash']): + async with kdf_slots: replacement=await asyncio.to_thread(hasher.hash,password) + await store.rehash(row['id'],row['password_hash'],replacement) + token=secrets.token_urlsafe(32) + expires=await store.create_session(row['id'],token) + return {'token':token,'token_type':'Bearer','expires_at':expires, + 'user':clean({k:v for k,v in row.items() if k!='password_hash'})} + + @api.delete('/api/v1/auth/sessions/current',status_code=204) + async def logout(request:Request): + await actor(request) + await store.logout(bearer(request)) + return Response(status_code=204) + + @api.get('/api/v1/users/me') + async def me(request:Request): return await actor(request) + + @api.post('/api/v1/chats',status_code=201) + async def create_chat(request:Request): + user=await actor(request) + body=object_fields(await json_body(request),('title','member_ids')) + title=string(body['title'],100) + if not isinstance(body['member_ids'],list) or not 1<=len(body['member_ids'])<=100: invalid('Invalid members') + members=[uuid_value(v) for v in body['member_ids']] + if len(set(members))!=len(members): invalid('Duplicate member') + return await store.create_chat(user['id'],title,members) + + @api.get('/api/v1/chats') + async def list_chats(request:Request): + user=await actor(request) + limit,cursor=pagination(request,'chats:'+user['id'],store.secret) + return await store.page(user['id'],None,limit,cursor) + + @api.get('/api/v1/chats/{chat_id}') + async def get_chat(chat_id:str,request:Request): + user=await actor(request) + return await store.chat(user['id'],uuid_value(chat_id)) + + @api.get('/api/v1/chats/{chat_id}/messages') + async def list_messages(chat_id:str,request:Request): + user=await actor(request); chat_id=uuid_value(chat_id) + await store.chat(user['id'],chat_id) + limit,cursor=pagination(request,'messages:'+chat_id,store.secret) + return await store.page(user['id'],chat_id,limit,cursor) + + @api.post('/api/v1/chats/{chat_id}/messages',status_code=201) + async def create_message(chat_id:str,request:Request): + user=await actor(request); chat_id=uuid_value(chat_id) + await store.chat(user['id'],chat_id) + body=object_fields(await json_body(request),('text',),('attachment_ids',)) + key=request.headers.get('idempotency-key','') + if not re.fullmatch(r'[A-Za-z0-9._:-]{1,128}',key): invalid('Invalid Idempotency-Key') + ids=body.get('attachment_ids',[]) + if not isinstance(ids,list) or len(ids)>10: invalid('Invalid attachments') + ids=[uuid_value(v) for v in ids] + if len(ids)!=len(set(ids)): invalid('Duplicate attachment') + text=string(body['text'],4000,blank=True) + if not text.strip() and not ids: invalid('Message must have content') + with tel.span('db.message.commit',attributes={'db.system.name':'postgresql'}): + return await store.create_message(user['id'],chat_id,text,key,ids) + + def metadata(row): + fields=('id','chat_id','owner_id','filename','content_type','size_bytes','sha256','created_at','updated_at','status','error_code') + result={k:row[k] for k in fields} + result['variants']=[{k:v for k,v in variant.items() if k!='object_key'} for variant in row['variants']] if row['status']=='ready' else [] + return result + + @api.post('/api/v1/chats/{chat_id}/attachments',status_code=202) + async def upload(chat_id:str,request:Request): + user=await actor(request); chat_id=uuid_value(chat_id) + await store.chat(user['id'],chat_id) + if set(request.query_params)!={'filename'} or len(request.query_params.getlist('filename'))!=1: + invalid('Expected one filename') + filename=string(request.query_params['filename'],255) + if any(c in '/\\' or unicodedata.category(c)=='Cc' for c in filename): invalid('Invalid filename') + mime=request.headers.get('content-type','').strip().lower() + if mime not in ('image/png','image/jpeg'): raise ApiError(415,'unsupported_media_type','Expected PNG/JPEG') + if uploads.locked(): raise ApiError(503,'unavailable','Upload slots busy',{'Retry-After':'1'}) + async with uploads: + with tempfile.TemporaryFile() as file: + size=0 + async for chunk in request.stream(): + size+=len(chunk) + if size>MAX_BYTES: raise ApiError(413,'payload_too_large','Upload exceeds 10 MiB') + file.write(chunk) + async with decoders: + digest=await complete_thread(validate_image,file,mime) + with tel.span('attachment.durable_accept'): + row=await store.save_attachment(user['id'],chat_id,filename,mime,size,digest,file,storage) + return metadata(row) + + @api.get('/api/v1/attachments/{attachment_id}') + async def attachment(attachment_id:str,request:Request): + user=await actor(request) + return metadata(await store.attachment(user['id'],uuid_value(attachment_id))) + + @api.get('/api/v1/attachments/{attachment_id}/content') + async def content(attachment_id:str,request:Request): + user=await actor(request) + row=await store.attachment(user['id'],uuid_value(attachment_id)) + if row['status']!='ready': raise ApiError(409,'conflict','Attachment is not ready') + if set(request.query_params)-{'variant'} or len(request.query_params.getlist('variant'))>1: invalid('Invalid query') + variant=request.query_params.get('variant','original') + target=row if variant=='original' else next((v for v in row['variants'] if v['name']==variant),None) + if target is None: raise ApiError(404,'not_found','Variant not found') + if downloads.locked(): raise ApiError(503,'unavailable','Download slots busy') + await downloads.acquire() + try: + obj=await asyncio.to_thread(storage.get,target['object_key']) + except BaseException: + downloads.release() + raise + async def chunks(): + try: + while data:=await asyncio.to_thread(obj['Body'].read,65536): + yield data + finally: + obj['Body'].close() + downloads.release() + return StreamingResponse(chunks(),media_type=target['content_type'],headers={ + 'Content-Length':str(target['size_bytes']),'X-Content-Type-Options':'nosniff', + 'Content-Disposition':'attachment'}) + + api.add_middleware(Boundaries,settings=cfg) + return api + + +app=create_app() diff --git a/src/bootstrap_storage.py b/src/bootstrap_storage.py new file mode 100644 index 0000000..574a1d2 --- /dev/null +++ b/src/bootstrap_storage.py @@ -0,0 +1,42 @@ +"""Idempotent private bucket bootstrap; only this one-shot service receives admin credentials.""" +import time +from botocore.exceptions import BotoCoreError, ClientError +from .storage import Storage, HEALTH_KEY, HEALTH_BYTES + +storage=Storage() +for attempt in range(60): + try: + storage.client.list_buckets() + break + except (BotoCoreError,ClientError): + if attempt==59: raise RuntimeError('Object storage did not become available') from None + time.sleep(1) +try: + storage.client.head_bucket(Bucket=storage.bucket) +except ClientError as exc: + if exc.response['Error']['Code'] not in ('404','NoSuchBucket'): raise + storage.client.create_bucket(Bucket=storage.bucket) +# No anonymous identity and no public bucket policy. Do not overwrite any policy +# silently on repeat; reject a public policy if an operator added one accidentally. +try: + policy=storage.client.get_bucket_policy(Bucket=storage.bucket) +except ClientError as exc: + if exc.response['Error']['Code'] not in ('NoSuchBucketPolicy','404'): raise +else: + raise RuntimeError('Unexpected bucket policy; inspect it before starting API') +deadline=time.monotonic()+90 +while True: + try: + try: + storage.client.head_object(Bucket=storage.bucket, Key=HEALTH_KEY) + except ClientError as exc: + if exc.response['Error']['Code'] not in ('404','NoSuchKey'): raise + # Fixed, reserved key/content: retry after uncertain PUT is safe. + storage.client.put_object(Bucket=storage.bucket, Key=HEALTH_KEY, Body=HEALTH_BYTES) + storage.ready() + break + except (BotoCoreError,ClientError): + if time.monotonic()>=deadline: + raise RuntimeError('Storage volumes did not become ready within bootstrap deadline') from None + time.sleep(1) +print('Private bucket ready; bootstrap is repeatable') diff --git a/src/broker.py b/src/broker.py new file mode 100644 index 0000000..5fe09c0 --- /dev/null +++ b/src/broker.py @@ -0,0 +1,46 @@ +"""Persistent Valkey Streams transport; database outbox remains the durable intent.""" +import json +import os + +import redis + +STREAM = 'attachment-jobs' +GROUP = 'image-workers' + + +def connect(): + return redis.Redis.from_url(os.environ['BROKER_URL'], decode_responses=True, + socket_connect_timeout=2, socket_timeout=3) + + +def ensure_group(client): + try: + client.xgroup_create(STREAM, GROUP, id='0', mkstream=True) + except redis.ResponseError as exc: + if not str(exc).startswith('BUSYGROUP'): + raise + + +def publish(client, payload): + # appendfsync always in Compose: successful XADD is the broker acceptance + # boundary. This is NOT an atomic transaction with PostgreSQL's outbox update. + return client.xadd(STREAM, {'job': json.dumps(payload, separators=(',', ':'))}) + + +def receive(client, consumer): + ensure_group(client) + claimed = client.xautoclaim(STREAM, GROUP, consumer, min_idle_time=65_000, + start_id='0-0', count=1) + if claimed[1]: + return claimed[1][0] + items = client.xreadgroup(GROUP, consumer, {STREAM: '>'}, count=1, block=1000) + return items[0][1][0] if items else None + + +def acknowledge(client, message_id): + # Called only after durable terminal/no-op outcome (or durable scheduled retry). + # One consumer group owns this stream. Ack+delete prevents unbounded history. + with client.pipeline(transaction=True) as pipe: + pipe.xack(STREAM, GROUP, message_id) + pipe.xdel(STREAM, message_id) + pipe.execute() diff --git a/src/cleanup.py b/src/cleanup.py new file mode 100644 index 0000000..f79c283 --- /dev/null +++ b/src/cleanup.py @@ -0,0 +1,52 @@ +"""Version-aware staging retention. Never deletes active jobs or referenced final effects.""" +from datetime import datetime, timezone +import json +import signal +import threading + +from .jobs import database +from .storage import HEALTH_KEY, Storage + +stop=threading.Event() + + +def run(): + storage=Storage(); deleted=0; scanned=0 + try: + with database() as db: + for prefix in ('staging/','originals/','variants/'): + for page in storage.client.get_paginator('list_objects_v2').paginate(Bucket=storage.bucket,Prefix=prefix): + for obj in page.get('Contents',[]): + key=obj['Key']; scanned+=1 + if key==HEALTH_KEY: continue + age=datetime.now(timezone.utc).timestamp()-obj['LastModified'].timestamp() + if age<600: continue + with db.transaction(): + if not db.execute('SELECT pg_try_advisory_xact_lock(hashtextextended(%s,0)) AS ok',(key,)).fetchone()['ok']: continue + if prefix=='staging/': + att=db.execute('SELECT * FROM attachments WHERE staging_key=%s FOR UPDATE',(key,)).fetchone() + if att and (att['status'] in ('queued','processing') or (att['status']=='failed' and age<7*86400)): + continue + # Ready staging is obsolete. Failed staging retained 7 days; + # explicit operator replay afterwards requires a restored source. + storage.delete(key); deleted+=1 + if att: + db.execute('UPDATE attachments SET staging_key=NULL WHERE id=%s AND staging_key=%s',(att['id'],key)) + else: + # Keep every version for a known attachment; old versions + # are bounded by the two supported pipelines and aid audit. + part=key.split('/')[1] + row=db.execute('SELECT 1 FROM attachments WHERE id::text=%s',(part,)).fetchone() + if row: continue + storage.delete(key); deleted+=1 + return {'scanned':scanned,'deleted':deleted} + finally: storage.client.close() + + +if __name__=='__main__': + signal.signal(signal.SIGTERM,lambda *_:stop.set()) + signal.signal(signal.SIGINT,lambda *_:stop.set()) + while not stop.is_set(): + try: print(json.dumps({'event':'cleanup',**run()}),flush=True) + except Exception as exc: print(json.dumps({'event':'cleanup_retry','type':type(exc).__name__}),flush=True) + stop.wait(60) diff --git a/src/common.py b/src/common.py new file mode 100644 index 0000000..7d4e9e8 --- /dev/null +++ b/src/common.py @@ -0,0 +1,101 @@ +"""Strict contract validation and resource-bound cursors.""" +import base64 +import binascii +import hashlib +import hmac +import json +import re +from datetime import datetime, timezone +from uuid import UUID + + +class ApiError(Exception): + def __init__(self, status, code, message, headers=None): + self.status, self.code, self.message = status, code, message + self.headers = headers or {} + + +def invalid(message='Invalid request'): + raise ApiError(400, 'invalid_request', message) + + +def uuid_value(value): + if not isinstance(value, str) or not re.fullmatch( + r'[0-9a-fA-F]{8}-(?:[0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}', value + ): + invalid('Invalid UUID') + return str(UUID(value)) + + +def string(value, maximum, *, blank=False): + if not isinstance(value, str) or len(value) > maximum or (not blank and not value.strip()): + invalid('Invalid string') + # JSON can encode unpaired surrogates; they are not Unicode scalar values. + try: + value.encode('utf-8') + except UnicodeError: + invalid('Invalid Unicode') + return value + + +def object_fields(value, required, optional=()): + if not isinstance(value, dict) or not set(required) <= value.keys() or value.keys() - set(required) - set(optional): + invalid('Invalid fields') + return value + + +def timestamp(): + return datetime.now(timezone.utc).isoformat(timespec='microseconds').replace('+00:00', 'Z') + + +def encode_cursor(resource, key, secret): + data = json.dumps([resource, *key], separators=(',', ':')).encode() + return base64.urlsafe_b64encode(data + hmac.digest(secret, data, 'sha256')).decode().rstrip('=') + + +def decode_cursor(value, resource, secret): + try: + if len(value) > 1024 or not re.fullmatch(r'[A-Za-z0-9_-]+', value): + raise ValueError() + raw = base64.b64decode(value + '=' * (-len(value) % 4), altchars=b'-_', validate=True) + data, signature = raw[:-32], raw[-32:] + if not hmac.compare_digest(hmac.digest(secret, data, 'sha256'), signature): + raise ValueError() + scope, created, identifier = json.loads(data) + if scope != resource or not isinstance(created, str) or not created.endswith('Z'): + raise ValueError() + datetime.fromisoformat(created.replace('Z', '+00:00')) + UUID(identifier) + return created, identifier + except (ValueError, TypeError, binascii.Error, UnicodeError): + invalid('Invalid cursor') + + +def pagination(request, resource, secret): + if any(len(request.query_params.getlist(k)) != 1 for k in request.query_params): + invalid('Duplicate query parameter') + if set(request.query_params) - {'limit', 'cursor'}: + invalid('Unknown query parameter') + value = request.query_params.get('limit', '50') + if not re.fullmatch(r'[0-9]{1,3}', value) or not 1 <= int(value) <= 100: + invalid('Limit must be 1..100') + cursor = request.query_params.get('cursor') + return int(value), decode_cursor(cursor, resource, secret) if cursor is not None else None + + +async def json_body(request): + if request.headers.get('content-type', '').split(';')[0].strip().lower() != 'application/json': + raise ApiError(415, 'unsupported_media_type', 'Expected application/json') + def unique_pairs(pairs): + result = {} + for key, value in pairs: + if key in result: + raise ValueError('duplicate key') + result[key] = value + return result + def no_constant(value): + raise ValueError('non-finite number') + try: + return json.loads((await request.body()).decode('utf-8'), object_pairs_hook=unique_pairs, parse_constant=no_constant) + except (ValueError, UnicodeError, RecursionError): + invalid('Invalid JSON') diff --git a/src/dispatcher.py b/src/dispatcher.py new file mode 100644 index 0000000..f27ccd0 --- /dev/null +++ b/src/dispatcher.py @@ -0,0 +1,62 @@ +"""Recover committed intent automatically and republish after uncertain acceptance.""" +import json +import signal +import threading + +from .broker import connect, ensure_group, publish +from .jobs import database, payload, recover_expired +from . import telemetry as tel + +stop = threading.Event() + + +def tick(): + with database() as db, connect() as client: + recover_expired(db) + ensure_group(client) + with db.transaction(): + # Bounded batch and SKIP LOCKED allow another dispatcher without + # duplicate simultaneous publication. Crash after XADD may redeliver. + rows = db.execute("""SELECT j.* FROM outbox o JOIN jobs j ON j.id=o.job_id + WHERE j.status='queued' AND j.next_attempt_at<=clock_timestamp() + AND (o.published_at IS NULL OR o.published_ataccepted_at+interval '30 seconds') AS bad FROM attachments + WHERE accepted_at<=clock_timestamp()-interval '30 seconds' + AND accepted_at>clock_timestamp()-((%s+30)*interval '1 second')""",(window,)).fetchone() + tel.slo_total.set(slo['total'],{'window':str(window)}) + tel.slo_bad.set(slo['bad'],{'window':str(window)}) + tel.process_metrics() + return len(rows) + + +def main(): + tel.setup('messenger-dispatcher') + signal.signal(signal.SIGTERM, lambda *_: stop.set()) + signal.signal(signal.SIGINT, lambda *_: stop.set()) + while not stop.is_set(): + try: + count = tick() + if count: + tel.event('jobs_published',count=count) + except Exception as exc: + tel.event('dispatch_retry',error_type=type(exc).__name__) + stop.wait(.5) + + +if __name__ == '__main__': + main() diff --git a/src/http.py b/src/http.py new file mode 100644 index 0000000..6b841af --- /dev/null +++ b/src/http.py @@ -0,0 +1,119 @@ +import asyncio +import json +import logging +import time +from uuid import uuid4 +from starlette.responses import JSONResponse +from starlette.requests import ClientDisconnect +from .common import ApiError +from . import telemetry as tel +logger=logging.getLogger("messenger") + +def error_response(exc, request_id): + return JSONResponse({'error': {'code': exc.code, 'message': exc.message, 'request_id': request_id}}, + status_code=exc.status, headers={'X-Request-Id': request_id, **exc.headers}) + + +class Boundaries: + """Admission before body buffering; no unbounded application waiting queue.""" + def __init__(self, app, settings): + self.app, self.cfg = app, settings + self.instance_id = uuid4().hex + self.active, self.tokens, self.updated = 0, float(settings.write_burst), time.monotonic() + + async def __call__(self, scope, receive, send): + if scope['type']!='http' or scope['path'].startswith('/health/'): + return await self._call(scope,receive,send) + status=500; started=time.monotonic() + headers={k.decode():v.decode() for k,v in scope.get('headers',[]) if k in (b'traceparent',b'tracestate')} + async def observed_send(message): + nonlocal status + if message['type']=='http.response.start': status=message['status'] + await send(message) + with tel.span('HTTP '+scope['method'],kind=tel.trace.SpanKind.SERVER,carrier=headers) as current: + try: + await self._call(scope,receive,observed_send) + finally: + route=getattr(scope.get('route'),'path','unmatched') + method=scope['method'] if scope['method'] in {'GET','POST','PUT','PATCH','DELETE','HEAD','OPTIONS','TRACE','CONNECT'} else 'OTHER' + attrs={'method':method,'route':route,'status_class':str(status//100)+'xx'} + current.update_name(scope['method']+' '+route) + current.set_attributes({'http.request.method':scope['method'],'http.route':route,'http.response.status_code':status}) + if status>=500: current.set_status(tel.trace.Status(tel.trace.StatusCode.ERROR)) + duration=time.monotonic()-started + tel.http_count.add(1,attrs); tel.http_duration.record(duration,attrs) + tel.event('http_request',request_id=scope.get('state',{}).get('request_id'),status=status,route=route,duration_seconds=round(duration,6)) + + async def _call(self, scope, receive, send): + if scope['type'] != 'http': + return await self.app(scope, receive, send) + request_id, started, status = uuid4().hex, time.monotonic(), 500 + scope.setdefault('state', {})['request_id'] = request_id + started_response = False + async def tracked_send(message): + nonlocal status, started_response + if message['type'] == 'http.response.start': + status, started_response = message['status'], True + message['headers'] = [(k, v) for k, v in message.get('headers', []) if k.lower() != b'x-request-id'] + [(b'x-request-id', request_id.encode()), (b'x-instance-id', self.instance_id.encode())] + await send(message) + admitted = False + try: + if self.active >= self.cfg.max_inflight: + raise ApiError(503, 'unavailable', 'Too many in-flight requests', {'Retry-After': '1'}) + now = time.monotonic() + self.tokens = min(self.cfg.write_burst, self.tokens + (now - self.updated) * self.cfg.write_rps) + self.updated = now + if scope['method'] in ('POST', 'PUT', 'PATCH'): + if self.tokens < 1: + raise ApiError(429, 'rate_limited', 'Write rate exceeded', {'Retry-After': '1'}) + self.tokens -= 1 + self.active += 1 + admitted = True + # Binary uploads are streamed by the authorized route into a bounded + # temporary file; do not copy a 10 MiB body into every API request. + if scope['method']=='POST' and scope['path'].endswith('/attachments'): + async with asyncio.timeout(self.cfg.request_timeout): + await self.app(scope,receive,tracked_send) + return + chunks, total = bytearray(), 0 + async with asyncio.timeout(self.cfg.request_timeout): + while True: + message = await receive() + if message['type'] == 'http.disconnect': + return + chunk = message.get('body', b'') + total += len(chunk) + if total > self.cfg.max_body_bytes: + raise ApiError(413, 'payload_too_large', 'Request body exceeds byte limit') + chunks.extend(chunk) + if not message.get('more_body', False): + break + body = bytes(chunks) + delivered = False + async def replay(): + nonlocal delivered + if delivered: + return await receive() + delivered = True + return {'type': 'http.request', 'body': body, 'more_body': False} + await self.app(scope, replay, tracked_send) + except ClientDisconnect: + status=499 + except TimeoutError: + if not started_response: + await error_response(ApiError(503, 'unavailable', 'Request timed out'), request_id)(scope, receive, tracked_send) + except ApiError as exc: + if not started_response: + await error_response(exc, request_id)(scope, receive, tracked_send) + except Exception as exc: + logger.error(json.dumps({'event': 'unexpected_error', 'request_id': request_id, 'type': type(exc).__name__})) + if not started_response: + await error_response(ApiError(500, 'internal_error', 'Internal error'), request_id)(scope, receive, tracked_send) + finally: + if admitted: + self.active -= 1 + # No query, body, headers, usernames, or message content in logs. + route = scope.get('route') + logger.info(json.dumps({'event': 'http', 'request_id': request_id, 'method': scope['method'], + 'route': getattr(route, 'path', 'unmatched'), 'status': status, + 'duration_ms': round((time.monotonic() - started) * 1000, 3)})) diff --git a/src/jobs.py b/src/jobs.py new file mode 100644 index 0000000..cba59dd --- /dev/null +++ b/src/jobs.py @@ -0,0 +1,56 @@ +"""Job state, transactional outbox and explicit operator transitions.""" +from datetime import datetime, timezone +import os +from uuid import uuid4 + +import psycopg +from psycopg.rows import dict_row +from psycopg.types.json import Jsonb + +MAX_ATTEMPTS = 5 +LEASE_SECONDS = 60 + + +def database(): + return psycopg.connect(os.environ['DATABASE_URL'], row_factory=dict_row, + connect_timeout=3, autocommit=True, + options='-c statement_timeout=5000 -c lock_timeout=1000') + + +def audit(db, job_id, event, **details): + db.execute('INSERT INTO job_audit(job_id,event,details) VALUES (%s,%s,%s)', + (job_id, event, Jsonb(details))) + + +def payload(job): + result = {'schema_version': 1, 'job_id': str(job['id']), 'type': 'attachment.process.v1', + 'attachment_id': str(job['attachment_id']), 'pipeline_version': job['pipeline_version'], + 'attempt': job['attempts'] + 1, + 'created_at': job['created_at'].astimezone(timezone.utc).isoformat().replace('+00:00', 'Z')} + if job.get('traceparent'): + result['traceparent'] = job['traceparent'] + if job.get('tracestate'): + result['tracestate'] = job['tracestate'] + return result + + +def recover_expired(db): + with db.transaction(): + rows = db.execute("SELECT * FROM jobs WHERE status='processing' AND lease_until= MAX_ATTEMPTS + status = 'failed' if exhausted else 'queued' + db.execute("UPDATE jobs SET status=%s,lease_token=NULL,lease_until=NULL,error_code=%s,next_attempt_at=clock_timestamp(),updated_at=clock_timestamp() WHERE id=%s", + (status, 'retry_exhausted' if exhausted else 'lease_expired', job['id'])) + db.execute("UPDATE attachments SET status=%s,error_code=%s,updated_at=clock_timestamp() WHERE id=%s AND pipeline_version=%s AND status='processing'", + (status, 'retry_exhausted' if exhausted else None, job['attachment_id'], job['pipeline_version'])) + db.execute('UPDATE outbox SET published_at=NULL WHERE job_id=%s', (job['id'],)) + audit(db, job['id'], 'lease_expired', attempt=job['attempts'], outcome=status) + + +def take_fault(db, job_id): + # Only the operator test harness can populate this table. No HTTP fault switches. + with db.transaction(): + row = db.execute('UPDATE job_faults SET remaining=remaining-1 WHERE job_id=%s AND remaining>0 RETURNING point', + (job_id,)).fetchone() + return row['point'] if row else None diff --git a/src/migrate.py b/src/migrate.py new file mode 100644 index 0000000..a66ac91 --- /dev/null +++ b/src/migrate.py @@ -0,0 +1,28 @@ +"""Versioned, transactional migrations, serialized across deployers.""" +import hashlib +import os +from pathlib import Path +import psycopg + + +def main(): + with psycopg.connect(os.environ['DATABASE_URL'],autocommit=True,connect_timeout=5) as conn: + conn.execute('SELECT pg_advisory_lock(23012026)') + try: + conn.execute('CREATE TABLE IF NOT EXISTS schema_migrations (name text PRIMARY KEY, sha256 text NOT NULL, applied_at timestamptz NOT NULL DEFAULT clock_timestamp())') + for file in sorted((Path(__file__).resolve().parents[1]/'migrations').glob('*.sql')): + data=file.read_bytes(); digest=hashlib.sha256(data).hexdigest() + row=conn.execute('SELECT sha256 FROM schema_migrations WHERE name=%s',(file.name,)).fetchone() + if row: + if row[0]!=digest: raise RuntimeError('An applied migration was modified: '+file.name) + print('Already applied:',file.name,flush=True) + continue + with conn.transaction(): + conn.execute(data.decode('utf-8')) + conn.execute('INSERT INTO schema_migrations(name,sha256) VALUES (%s,%s)',(file.name,digest)) + print('Applied:',file.name,flush=True) + finally: + conn.execute('SELECT pg_advisory_unlock(23012026)') + + +if __name__=='__main__': main() diff --git a/src/offload.py b/src/offload.py new file mode 100644 index 0000000..24842d3 --- /dev/null +++ b/src/offload.py @@ -0,0 +1,16 @@ +"""Keep resource leases until a blocking operation actually finishes on cancellation.""" +import asyncio + + +async def complete_thread(function, *args): + task = asyncio.create_task(asyncio.to_thread(function, *args)) + try: + return await asyncio.shield(task) + except asyncio.CancelledError: + # asyncio cancellation cannot stop a Python thread. Do not close its file + # or release its decoder/upload permit while it is still using them. + try: + await asyncio.shield(task) + except Exception: + pass + raise diff --git a/src/operator.py b/src/operator.py new file mode 100644 index 0000000..ce381bf --- /dev/null +++ b/src/operator.py @@ -0,0 +1,71 @@ +"""Local operator CLI: failed registry, audited replay and versioned reprocessing.""" +import argparse +import json +import tempfile +from uuid import UUID, uuid4 + +from .jobs import audit, database +from .storage import MAX_BYTES, Storage + + +def replay(job_id): + storage=Storage() + try: + with database() as db, db.transaction(): + job=db.execute('SELECT * FROM jobs WHERE id=%s FOR UPDATE',(job_id,)).fetchone() + if not job or job['status']!='failed': raise ValueError('Only failed jobs can be replayed') + att=db.execute('SELECT * FROM attachments WHERE id=%s FOR UPDATE',(job['attachment_id'],)).fetchone() + if att['pipeline_version']!=job['pipeline_version'] or not att['staging_key']: + raise ValueError('Stale version or expired staging; replay refused') + storage.client.head_object(Bucket=storage.bucket,Key=att['staging_key']) + db.execute("UPDATE jobs SET status='queued',attempts=0,error_code=NULL,lease_token=NULL,lease_until=NULL,next_attempt_at=clock_timestamp(),updated_at=clock_timestamp() WHERE id=%s",(job_id,)) + db.execute("UPDATE attachments SET status='queued',error_code=NULL,updated_at=clock_timestamp() WHERE id=%s",(att['id'],)) + db.execute('UPDATE outbox SET published_at=NULL WHERE job_id=%s',(job_id,)) + audit(db,job_id,'operator_replay',previous_attempts=job['attempts']) + return {'job_id':str(job_id),'status':'queued'} + finally: storage.client.close() + + +def upgrade(attachment_id,version): + if version not in (1,2): raise ValueError('Supported pipeline versions are 1 and 2') + storage=Storage() + try: + with database() as db, db.transaction(): + att=db.execute('SELECT * FROM attachments WHERE id=%s FOR UPDATE',(attachment_id,)).fetchone() + if not att or version<=att['pipeline_version']: raise ValueError('Version must strictly increase') + source=att['object_key'] if att['status']=='ready' else att['staging_key'] + if not source: raise ValueError('Original is no longer available') + key=f'staging/{attachment_id}/v{version}' + db.execute('SELECT pg_advisory_xact_lock(hashtextextended(%s,0))',(key,)) + obj=storage.get(source) + try: + with tempfile.TemporaryFile() as file: + size=0 + while block:=obj['Body'].read(65536): + size+=len(block) + if size>MAX_BYTES: raise ValueError('Original exceeds byte limit') + file.write(block) + storage.put(key,file,size,att['content_type'],att['sha256']) + finally: obj['Body'].close() + job_id=uuid4() + db.execute("UPDATE attachments SET pipeline_version=%s,status='queued',staging_key=%s,error_code=NULL,updated_at=clock_timestamp() WHERE id=%s",(version,key,attachment_id)) + db.execute('INSERT INTO jobs(id,attachment_id,pipeline_version) VALUES (%s,%s,%s)',(job_id,attachment_id,version)) + db.execute('INSERT INTO outbox(job_id) VALUES (%s)',(job_id,)) + audit(db,job_id,'operator_upgrade',previous_version=att['pipeline_version'],version=version) + return {'job_id':str(job_id),'pipeline_version':version,'status':'queued'} + finally: storage.client.close() + + +if __name__=='__main__': + parser=argparse.ArgumentParser() + commands=parser.add_subparsers(dest='command',required=True) + commands.add_parser('failed') + commands.add_parser('replay').add_argument('job_id',type=UUID) + p=commands.add_parser('upgrade'); p.add_argument('attachment_id',type=UUID); p.add_argument('version',type=int) + args=parser.parse_args() + if args.command=='failed': + with database() as db: + result=db.execute("SELECT id,attachment_id,pipeline_version,attempts,error_code,updated_at FROM jobs WHERE status='failed' ORDER BY updated_at DESC LIMIT 100").fetchall() + elif args.command=='replay': result=replay(args.job_id) + else: result=upgrade(args.attachment_id,args.version) + print(json.dumps(result,default=str,indent=2)) diff --git a/src/render.py b/src/render.py new file mode 100644 index 0000000..08b841c --- /dev/null +++ b/src/render.py @@ -0,0 +1,69 @@ +"""Isolated image CPU/memory workload. Input/output paths are operator-owned temporary files.""" +import hashlib +import json +from pathlib import Path +import resource +import sys + +from PIL import Image, ImageOps + + +def fit_size(width, height, bound): + ratio = min(1, bound / width, bound / height) + return max(1, int(width * ratio)), max(1, int(height * ratio)) + + +def render(source, destination, version): + # Both versions are explicit, reproducible pipelines. Version 2 changes quality; + # storage effect keys include version, so old jobs cannot overwrite new bytes. + quality = {1: (85, 80), 2: (90, 85)}[version] + Image.MAX_IMAGE_PIXELS = 40_000_000 + with Image.open(source, formats=['PNG', 'JPEG']) as opened: + if opened.width * opened.height > 40_000_000: + raise ValueError('pixel_limit') + opened.load() + image = ImageOps.exif_transpose(opened) + try: + if image.mode in ('RGBA', 'LA') or 'transparency' in image.info: + rgba = image.convert('RGBA') + rgb = Image.new('RGB', rgba.size, 'white') + rgb.paste(rgba, mask=rgba.getchannel('A')) + rgba.close() + else: + rgb = image.convert('RGB') + finally: + image.close() + rgb.info.clear() # Do not propagate EXIF, ICC or arbitrary image metadata. + result = [] + try: + for name, mime, fmt in [('thumbnail', 'image/jpeg', 'JPEG'), + ('crop', 'image/jpeg', 'JPEG'), + ('optimized', 'image/webp', 'WEBP')]: + if name == 'crop': + variant = ImageOps.fit(rgb, (128, 128), method=Image.Resampling.LANCZOS, + centering=(.5, .5)) + else: + variant = rgb.resize(fit_size(*rgb.size, 256 if name == 'thumbnail' else 1280), + Image.Resampling.LANCZOS) + try: + variant.info.clear() + target = destination / name + options = {'quality': quality[1], 'method': 4} if fmt == 'WEBP' else { + 'quality': quality[0], 'optimize': True, 'subsampling': 0} + variant.save(target, format=fmt, **options) + result.append({'name': name, 'content_type': mime, 'width': variant.width, + 'height': variant.height, 'size_bytes': target.stat().st_size, + 'sha256': hashlib.sha256(target.read_bytes()).hexdigest()}) + finally: + variant.close() + finally: + rgb.close() + return result + + +if __name__ == '__main__': + # Container is the outer memory boundary; subprocess also has finite virtual + # memory and CPU budgets. Parent enforces a wall-clock timeout and kills it. + resource.setrlimit(resource.RLIMIT_AS, (640 * 1024 * 1024, 640 * 1024 * 1024)) + resource.setrlimit(resource.RLIMIT_CPU, (20, 20)) + print(json.dumps(render(Path(sys.argv[1]), Path(sys.argv[2]), int(sys.argv[3])))) diff --git a/src/secret_agent.py b/src/secret_agent.py new file mode 100644 index 0000000..376a43d --- /dev/null +++ b/src/secret_agent.py @@ -0,0 +1,74 @@ +"""Cert-authenticated, finite-lease child supervisor; no stored Bao token. + +An unavailable/sealed Bao is tolerated only until the last authenticated lease +expires. Secret changes restart the child, dropping old pooled connections. +""" +import json +import os +import signal +import ssl +import subprocess +import sys +import time +import urllib.request + + +def fetch(): + ctx=ssl.create_default_context(cafile='/trust/bundle.pem') + ctx.minimum_version=ssl.TLSVersion.TLSv1_2 + ctx.load_cert_chain('/identity/cert.pem','/identity/key.pem') + ctx.verify_flags |= ssl.VERIFY_CRL_CHECK_LEAF + def request(path,body=None,token=None): + headers={'Content-Type':'application/json'} + if token: headers['X-Vault-Token']=token + r=urllib.request.Request('https://openbao:8200/v1/'+path, + data=json.dumps(body).encode() if body is not None else None,headers=headers) + with urllib.request.urlopen(r,context=ctx,timeout=4) as response: return json.load(response) + role=os.environ['SERVICE_ROLE'] + auth=request('auth/cert/login',{'name':role})['auth'] + try: + data=request('secret/data/'+role,token=auth['client_token'])['data']['data'] + return data,min(120,int(auth['lease_duration'])) + finally: + # The secret validity budget is local and bounded; no orphaned tokens. + try: request('auth/token/revoke-self',{},auth['client_token']) + except Exception: pass + + +def main(): + child=None; stopping=False; expires=0; current=None + def stop(*_): + nonlocal stopping + stopping=True + for sig in (signal.SIGTERM,signal.SIGINT): signal.signal(sig,stop) + def terminate(): + nonlocal child + if child and child.poll() is None: + child.terminate() + try: child.wait(timeout=8) + except subprocess.TimeoutExpired: child.kill(); child.wait() + child=None + try: + while not stopping: + try: + data,ttl=fetch() + if data!=current: terminate(); current=data + expires=time.monotonic()+ttl + if child is None: + child=subprocess.Popen(sys.argv[1:],env={**os.environ,**{k:str(v) for k,v in data.items()}}) + elif child.poll() is not None: + # Restart the child, not its container/network namespace: + # the paired TLS sidecar shares that namespace. + print('{"event":"supervised_child_exited"}',flush=True) + child=None + except Exception: + print('{"event":"secret_refresh_unavailable"}',flush=True) + if time.monotonic()>=expires: terminate(); current=None + for _ in range(20): + if stopping: break + time.sleep(1) + finally: terminate() + return 0 + + +if __name__=='__main__': sys.exit(main()) diff --git a/src/secret_mounts.py b/src/secret_mounts.py new file mode 100644 index 0000000..caeda04 --- /dev/null +++ b/src/secret_mounts.py @@ -0,0 +1,28 @@ +"""One-shot operator initializer: private files copied to per-role volumes. + +Only this short-lived container sees all generated service identities. No CA key, +root token or unseal share is mounted. Runtime containers see their own volume. +""" +import os +from pathlib import Path + + +def copy(source, target, uid, gid): + target.parent.mkdir(parents=True, exist_ok=True) + temporary = target.with_suffix('.new') + temporary.write_bytes(source.read_bytes()) + os.chown(temporary, uid, gid) + temporary.chmod(0o600) + temporary.replace(target) + + +for destination in Path('/output').iterdir(): + role = destination.name + uid, gid = (472, 472) if role == 'grafana' else (10001, 10001) + for name in ('cert.pem', 'key.pem', 'combined.pem'): + copy(Path('/source/identities')/role/name, destination/name, uid, gid) +for role in ('cache', 'broker'): + copy(Path('/source')/(role+'.conf'), Path('/configs')/role/'lab.conf', 999, 1000) +copy(Path('/source/s3.json'), Path('/configs/s3/s3.json'), 1000, 1000) +copy(Path('/source/grafana-password'), Path('/configs/grafana/password'), 472, 472) +print('Per-service private volumes initialized; no secret values printed') diff --git a/src/storage.py b/src/storage.py new file mode 100644 index 0000000..cc9ac94 --- /dev/null +++ b/src/storage.py @@ -0,0 +1,79 @@ +"""Bounded S3 calls and strict PNG/JPEG validation; never trust a client filename.""" +import hashlib +import os +import warnings + +import boto3 +from botocore.config import Config +from PIL import Image, UnidentifiedImageError + +from .common import ApiError +from . import telemetry as tel + +MAX_BYTES = 10 * 1024 * 1024 +MAX_PIXELS = 40_000_000 +HEALTH_KEY = 'originals/.storage-health' +HEALTH_BYTES = b'messenger-storage-ready-v1' +Image.MAX_IMAGE_PIXELS = MAX_PIXELS +warnings.simplefilter('error', Image.DecompressionBombWarning) + + +def validate_image(file, content_type): + try: + file.seek(0) + with Image.open(file, formats=['PNG', 'JPEG']) as image: + actual = {'PNG': 'image/png', 'JPEG': 'image/jpeg'}[image.format] + if actual != content_type: + raise ApiError(415, 'unsupported_media_type', 'Image content does not match MIME') + if image.width * image.height > MAX_PIXELS: + raise ApiError(413, 'payload_too_large', 'Too many decoded pixels') + image.verify() + file.seek(0) + with Image.open(file, formats=['PNG', 'JPEG']) as image: + image.load() # JPEG.verify alone does not detect a truncated entropy stream. + file.seek(0) + digest = hashlib.file_digest(file, 'sha256').hexdigest() + file.seek(0) + return digest + except (Image.DecompressionBombWarning, Image.DecompressionBombError): + raise ApiError(413, 'payload_too_large', 'Too many decoded pixels') from None + except (UnidentifiedImageError, OSError, ValueError, SyntaxError): + raise ApiError(415, 'unsupported_media_type', 'Invalid PNG/JPEG') from None + + +class Storage: + def __init__(self): + self.bucket = os.environ['S3_BUCKET'] + self.client = boto3.client('s3', endpoint_url=os.environ['S3_ENDPOINT'], + aws_access_key_id=os.environ['S3_ACCESS_KEY'], + aws_secret_access_key=os.environ['S3_SECRET_KEY'], + region_name='us-east-1', + config=Config(connect_timeout=2, read_timeout=4, + retries={'total_max_attempts': 1}, + max_pool_connections=8, + s3={'addressing_style': 'path'})) + + def ready(self): + # Listing proves only filer metadata readiness. After a SeaweedFS restart, + # volume registration can lag; require a real read from a persisted volume. + obj = self.get(HEALTH_KEY) + try: + if obj['Body'].read(len(HEALTH_BYTES)+1) != HEALTH_BYTES: + raise ApiError(503, 'unavailable', 'Storage probe unavailable') + finally: + obj['Body'].close() + + def put(self, key, file, size, content_type, digest): + file.seek(0) + with tel.span('s3.put',attributes={'rpc.system':'aws-api','rpc.service':'S3','rpc.method':'PutObject'}): + self.client.put_object(Bucket=self.bucket, Key=key, Body=file, ContentLength=size, + ContentType=content_type, Metadata={'sha256': digest}) + + def get(self, key): + if key==HEALTH_KEY: + return self.client.get_object(Bucket=self.bucket, Key=key) + with tel.span('s3.get',attributes={'rpc.system':'aws-api','rpc.service':'S3','rpc.method':'GetObject'}): + return self.client.get_object(Bucket=self.bucket, Key=key) + + def delete(self, key): + self.client.delete_object(Bucket=self.bucket, Key=key) diff --git a/src/store.py b/src/store.py new file mode 100644 index 0000000..58dd753 --- /dev/null +++ b/src/store.py @@ -0,0 +1,193 @@ +import hashlib +import asyncio +import json +import logging +from uuid import uuid4 + +import psycopg +from psycopg.rows import dict_row +from psycopg_pool import AsyncConnectionPool +from redis.asyncio import Redis +from redis.exceptions import RedisError + +from .common import ApiError, encode_cursor, invalid +from . import telemetry as tel + + +def clean(row): + if isinstance(row,dict): return {k:clean(v) for k,v in row.items()} + if isinstance(row,list): return [clean(v) for v in row] + if hasattr(row,'isoformat'): return row.isoformat(timespec='microseconds').replace('+00:00','Z') + if type(row).__name__=='UUID': return str(row) + return row + + +class Store: + def __init__(self,cfg): + self.cfg=cfg + self.secret=cfg.cursor_secret.encode() + self.pool=AsyncConnectionPool(cfg.database_url,min_size=1,max_size=cfg.db_pool_size, + timeout=2,max_waiting=32,open=False,max_lifetime=45, + check=AsyncConnectionPool.check_connection, + kwargs={'row_factory':dict_row,'connect_timeout':3, + 'options':'-c statement_timeout=2000 -c lock_timeout=1000 -c timezone=UTC'}) + self.cache=Redis.from_url(cfg.redis_url,socket_timeout=.2,socket_connect_timeout=.2, + max_connections=8,decode_responses=True) + + async def open(self): await self.pool.open(wait=True,timeout=20) + async def close(self): + await self.cache.aclose() + await self.pool.close() + + async def ready(self): + async with self.pool.connection() as c: await c.execute('SELECT 1') + + async def login_limit(self,name,maximum): + # The same PG row serializes attempts across both replicas. Database + # failure is fail-closed and expensive KDF work has not started yet. + async with self.pool.connection() as c: + row=await (await c.execute("""INSERT INTO login_budget(name,window_start,used) + VALUES (%s,clock_timestamp(),1) ON CONFLICT(name) DO UPDATE SET + window_start=CASE WHEN login_budget.window_startmaximum: raise ApiError(429,'rate_limited','Try again later',{'Retry-After':'10'}) + + async def rehash(self,user_id,previous,replacement): + async with self.pool.connection() as c: + await c.execute('UPDATE users SET password_hash=%s WHERE id=%s AND password_hash=%s',(replacement,user_id,previous)) + + async def register(self,username,display_name,password_hash): + try: + async with self.pool.connection() as c: + row=await (await c.execute('INSERT INTO users(id,username,display_name,password_hash) VALUES (%s,%s,%s,%s) RETURNING id,username,display_name,created_at', + (uuid4(),username,display_name,password_hash))).fetchone() + return clean(row) + except psycopg.errors.UniqueViolation: + raise ApiError(409,'conflict','Username already exists') from None + + async def credentials(self,username): + async with self.pool.connection() as c: + return await (await c.execute('SELECT * FROM users WHERE username=%s',(username,))).fetchone() + + async def create_session(self,user_id,token): + async with self.pool.connection() as c: + row=await (await c.execute("INSERT INTO sessions(token_hash,user_id,expires_at) VALUES (%s,%s,clock_timestamp()+%s*interval '1 second') RETURNING expires_at", + (hashlib.sha256(token.encode()).hexdigest(),user_id,self.cfg.session_ttl_seconds))).fetchone() + return clean(row)['expires_at'] + + async def authenticate(self,token): + async with self.pool.connection() as c: + session=await (await c.execute('SELECT user_id FROM sessions WHERE token_hash=%s AND expires_at>clock_timestamp()', + (hashlib.sha256(token.encode()).hexdigest(),))).fetchone() + if session is None: raise ApiError(401,'unauthorized','Invalid session',{'WWW-Authenticate':'Bearer realm="messenger"'}) + key='user:'+str(session['user_id']) + try: + cached=await self.cache.get(key) + if cached: return json.loads(cached) + except (RedisError,ValueError): + logging.getLogger('messenger').warning('{"event":"cache_bypass"}') + row=await (await c.execute('SELECT id,username,display_name,created_at FROM users WHERE id=%s',(session['user_id'],))).fetchone() + user=clean(row) + try: await self.cache.set(key,json.dumps(user),ex=60) + except RedisError: pass + return user + + async def logout(self,token): + async with self.pool.connection() as c: + await c.execute('DELETE FROM sessions WHERE token_hash=%s',(hashlib.sha256(token.encode()).hexdigest(),)) + + async def _chat(self,c,actor,chat_id): + row=await (await c.execute('SELECT c.id,c.title,c.created_at,ARRAY(SELECT user_id FROM members WHERE chat_id=c.id ORDER BY user_id) AS member_ids FROM chats c JOIN members m ON m.chat_id=c.id WHERE c.id=%s AND m.user_id=%s',(chat_id,actor))).fetchone() + if row is None: raise ApiError(404,'not_found','Object not found') + return clean(row) + + async def chat(self,actor,chat_id): + async with self.pool.connection() as c: return await self._chat(c,actor,chat_id) + + async def create_chat(self,actor,title,members): + if actor not in members: invalid('Members must include the current user') + try: + async with self.pool.connection() as c: + cid=uuid4() + await c.execute('INSERT INTO chats(id,title) VALUES (%s,%s)',(cid,title)) + async with c.cursor() as cur: + await cur.executemany('INSERT INTO members(chat_id,user_id) VALUES (%s,%s)',[(cid,m) for m in members]) + return await self._chat(c,actor,cid) + except psycopg.errors.ForeignKeyViolation: + invalid('All members must exist') + + async def create_message(self,actor,chat_id,text,key,attachment_ids): + digest=hashlib.sha256(json.dumps({'text':text,'attachment_ids':attachment_ids},sort_keys=True,ensure_ascii=False,separators=(',',':')).encode()).hexdigest() + async with self.pool.connection() as c: + await self._chat(c,actor,chat_id) + # Fixed operation POST /chats/{id}/messages; lock and both rows share one transaction. + scope='POST:'+chat_id+':'+actor+':'+key + await c.execute('SELECT pg_advisory_xact_lock(hashtextextended(%s,0))',(scope,)) + previous=await (await c.execute("SELECT request_hash,message_id FROM idempotency WHERE actor_id=%s AND chat_id=%s AND key=%s AND expires_at>clock_timestamp()",(actor,chat_id,key))).fetchone() + if previous: + if previous['request_hash']!=digest: raise ApiError(409,'conflict','Key was used for another message') + return clean(await (await c.execute('SELECT id,chat_id,sender_id,text,created_at,attachment_ids FROM messages WHERE id=%s',(previous['message_id'],))).fetchone()) + for aid in attachment_ids: + attachment=await (await c.execute('SELECT status,storage_state FROM attachments WHERE id=%s AND chat_id=%s FOR SHARE',(aid,chat_id))).fetchone() + if attachment is None: raise ApiError(404,'not_found','Object not found') + if attachment['status']=='failed': raise ApiError(409,'conflict','Attachment processing failed') + if attachment['status']=='ready' and attachment['storage_state']!='ready': raise ApiError(503,'unavailable','Object temporarily unavailable') + await c.execute('DELETE FROM idempotency WHERE actor_id=%s AND chat_id=%s AND key=%s',(actor,chat_id,key)) + row=await (await c.execute('INSERT INTO messages(id,chat_id,sender_id,text,attachment_ids) VALUES (%s,%s,%s,%s,%s::uuid[]) RETURNING id,chat_id,sender_id,text,created_at,attachment_ids', + (uuid4(),chat_id,actor,text,attachment_ids))).fetchone() + for aid in attachment_ids: + await c.execute('INSERT INTO message_attachments(message_id,attachment_id) VALUES (%s,%s)',(row['id'],aid)) + await c.execute("INSERT INTO idempotency(actor_id,chat_id,key,request_hash,message_id,expires_at) VALUES (%s,%s,%s,%s,%s,clock_timestamp()+interval '24 hours')",(actor,chat_id,key,digest,row['id'])) + return clean(row) + + async def page(self,actor,chat_id,limit,cursor): + async with self.pool.connection() as c: + if chat_id: + await self._chat(c,actor,chat_id) + query='SELECT id,chat_id,sender_id,text,created_at,attachment_ids FROM messages WHERE chat_id=%s' + args=[chat_id]; resource='messages:'+chat_id + if cursor: + query+=' AND (created_at,id)>(%s::timestamptz,%s::uuid)'; args.extend(cursor) + query+=' ORDER BY created_at,id LIMIT %s'; args.append(limit+1) + else: + query='SELECT c.id,c.title,c.created_at,ARRAY(SELECT user_id FROM members WHERE chat_id=c.id ORDER BY user_id) AS member_ids FROM chats c JOIN members m ON m.chat_id=c.id WHERE m.user_id=%s' + args=[actor]; resource='chats:'+actor + if cursor: + query+=' AND (c.created_at,c.id)>(%s::timestamptz,%s::uuid)'; args.extend(cursor) + query+=' ORDER BY c.created_at,c.id LIMIT %s'; args.append(limit+1) + rows=[clean(row) for row in await (await c.execute(query,args)).fetchall()] + selected=rows[:limit] + next_cursor=encode_cursor(resource,(selected[-1]['created_at'],selected[-1]['id']),self.secret) if len(rows)>limit else None + return {'items':selected,'next_cursor':next_cursor} + + async def attachment(self,actor,identifier): + async with self.pool.connection() as c: + row=await (await c.execute('SELECT a.* FROM attachments a JOIN members m ON m.chat_id=a.chat_id WHERE a.id=%s AND m.user_id=%s',(identifier,actor))).fetchone() + if row is None: raise ApiError(404,'not_found','Object not found') + if row['status']=='ready' and row['storage_state']!='ready': raise ApiError(503,'unavailable','Object temporarily unavailable') + return clean(row) + + async def save_attachment(self,actor,chat_id,filename,mime,size,digest,file,storage): + identifier=uuid4() + key='staging/'+str(identifier)+'/v1' + # The same lock is taken by reconciliation before it can delete an orphan. + # DB COMMIT uncertainty must NEVER trigger an unconditional S3 delete: the row + # may have committed. Leave a possible orphan for the grace-period reconciler. + async with self.pool.connection() as c: + await self._chat(c,actor,chat_id) + # Admission is global and serialized: no unbounded durable backlog. + await c.execute("SELECT pg_advisory_xact_lock(hashtextextended('job-admission',0))") + pending=await (await c.execute("SELECT count(*) AS n FROM jobs WHERE status IN ('queued','processing')")).fetchone() + if pending['n']>=1000: raise ApiError(503,'unavailable','Processing backlog is full') + await c.execute('SELECT pg_advisory_xact_lock(hashtextextended(%s,0))',(key,)) + from .offload import complete_thread + await complete_thread(storage.put,key,file,size,mime,digest) + row=await (await c.execute("INSERT INTO attachments(id,chat_id,owner_id,filename,object_key,content_type,size_bytes,sha256,status,staging_key) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,'queued',%s) RETURNING *", + (identifier,chat_id,actor,filename,key,mime,size,digest,key))).fetchone() + job_id=uuid4() + context=tel.carrier() + await c.execute('INSERT INTO jobs(id,attachment_id,pipeline_version,traceparent,tracestate) VALUES (%s,%s,1,%s,%s)',(job_id,identifier,context.get('traceparent'),context.get('tracestate'))) + await c.execute('INSERT INTO outbox(job_id) VALUES (%s)',(job_id,)) + return clean(row) diff --git a/src/telemetry.py b/src/telemetry.py new file mode 100644 index 0000000..a08d0be --- /dev/null +++ b/src/telemetry.py @@ -0,0 +1,110 @@ +"""Explicit low-cardinality OTLP signals. Business operation never waits for export.""" +from contextlib import contextmanager +import json +import os +import resource +import time +from uuid import uuid4 + +from opentelemetry import metrics, trace +from opentelemetry._logs import SeverityNumber +from opentelemetry.propagate import extract, inject +from opentelemetry.sdk._logs import LoggerProvider +from opentelemetry.sdk._logs.export import BatchLogRecordProcessor +from opentelemetry.sdk.metrics import MeterProvider +from opentelemetry.sdk.metrics.export import PeriodicExportingMetricReader +from opentelemetry.sdk.metrics.view import ExplicitBucketHistogramAggregation, View +from opentelemetry.sdk.resources import Resource +from opentelemetry.sdk.trace import TracerProvider +from opentelemetry.sdk.trace.export import BatchSpanProcessor +from opentelemetry.sdk.trace.sampling import ParentBased, TraceIdRatioBased +from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter +from opentelemetry.exporter.otlp.proto.http.metric_exporter import OTLPMetricExporter +from opentelemetry.exporter.otlp.proto.http._log_exporter import OTLPLogExporter + +configured=False +log_provider=None +service='messenger' +instance=uuid4().hex + + +def setup(name): + global configured,log_provider,service,http_count,http_duration,job_count,job_duration,ready_duration,pool_used,pool_waiting,worker_busy,worker_capacity,queue_depth,queue_age,process_rss,process_cpu,slo_total,slo_bad + if configured: return + configured=True; service=name + enabled=os.environ.get('TELEMETRY_ENABLED','1')=='1' + endpoint=os.environ.get('OTEL_EXPORTER_OTLP_ENDPOINT','http://otel-collector:4318').rstrip('/') + res=Resource.create({'service.name':name,'service.version':'lab6-v1','service.instance.id':instance, + 'deployment.environment.name':'lab'}) + if enabled: + tracer=TracerProvider(resource=res,sampler=ParentBased(TraceIdRatioBased(float(os.environ.get('TRACE_SAMPLE_RATIO','1'))))) + tracer.add_span_processor(BatchSpanProcessor(OTLPSpanExporter(endpoint=endpoint+'/v1/traces',timeout=2), + max_queue_size=256,max_export_batch_size=64,schedule_delay_millis=1000,export_timeout_millis=2000)) + trace.set_tracer_provider(tracer) + log_provider=LoggerProvider(resource=res) + log_provider.add_log_record_processor(BatchLogRecordProcessor(OTLPLogExporter(endpoint=endpoint+'/v1/logs',timeout=2), + max_queue_size=256,max_export_batch_size=64,schedule_delay_millis=1000,export_timeout_millis=2000)) + reader=PeriodicExportingMetricReader(OTLPMetricExporter(endpoint=endpoint+'/v1/metrics',timeout=2),export_interval_millis=5000,export_timeout_millis=3000) + metrics.set_meter_provider(MeterProvider(resource=res,metric_readers=[reader],views=[ + View(instrument_type=metrics.Histogram,aggregation=ExplicitBucketHistogramAggregation([.005,.01,.025,.05,.1,.25,.5,1,2.5,5,10,30,60,120]))])) + meter=metrics.get_meter('messenger') + http_count=meter.create_counter('http_server_requests') + http_duration=meter.create_histogram('http_server_duration',unit='s') + job_count=meter.create_counter('jobs_processed') + job_duration=meter.create_histogram('job_processing_duration',unit='s') + ready_duration=meter.create_histogram('attachment_time_to_ready',unit='s') + pool_used=meter.create_gauge('db_pool_used') + pool_waiting=meter.create_gauge('db_pool_waiting') + worker_busy=meter.create_gauge('worker_busy') + worker_capacity=meter.create_gauge('worker_capacity') + queue_depth=meter.create_gauge('queue_depth') + queue_age=meter.create_gauge('queue_oldest_age',unit='s') + process_rss=meter.create_gauge('process_rss',unit='By') + process_cpu=meter.create_gauge('process_cpu_time',unit='s') + slo_total=meter.create_gauge('attachment_slo_eligible') + slo_bad=meter.create_gauge('attachment_slo_bad') + + +def tracer(): return trace.get_tracer('messenger') + + +@contextmanager +def span(name,kind=trace.SpanKind.INTERNAL,carrier=None,attributes=None): + with tracer().start_as_current_span(name,kind=kind,context=extract(carrier) if carrier else None, + attributes=attributes or {},record_exception=False,set_status_on_exception=False) as current: + try: yield current + except BaseException: + current.set_status(trace.Status(trace.StatusCode.ERROR)) + raise + + +def carrier(): + result={}; inject(result); return result + + +def event(name,**fields): + # Callers pass controlled fields only. Never capture arbitrary exceptions, + # HTTP headers/bodies/raw URLs, passwords, tokens, filenames or S3 URLs. + context=trace.get_current_span().get_span_context() + row={'timestamp':time.time(),'severity':'INFO','service.name':service,'event':name, + 'trace_id':format(context.trace_id,'032x'),'span_id':format(context.span_id,'016x'),**fields} + print(json.dumps(row),flush=True) + if log_provider: + log_provider.get_logger('messenger').emit(body=json.dumps(row),severity_number=SeverityNumber.INFO, + severity_text='INFO',attributes={'event':name}) + + +def process_metrics(): + # Linux ru_maxrss is KiB; use actual current RSS from proc for memory trend. + with open('/proc/self/statm') as file: + rss=int(file.read().split()[1])*os.sysconf('SC_PAGE_SIZE') + usage=resource.getrusage(resource.RUSAGE_SELF) + attrs={'service':service,'process_instance':instance} + process_rss.set(rss,attrs); process_cpu.set(usage.ru_utime+usage.ru_stime,attrs) + + +def shutdown(): + for provider in (trace.get_tracer_provider(),metrics.get_meter_provider(),log_provider): + if provider and hasattr(provider,'shutdown'): + try: provider.shutdown() + except Exception: pass diff --git a/src/tls_proxy.py b/src/tls_proxy.py new file mode 100644 index 0000000..fad757d --- /dev/null +++ b/src/tls_proxy.py @@ -0,0 +1,105 @@ +"""Bounded TLS transport boundary. Plaintext listeners/targets are loopback only. + +Trust/leaf contexts are cached for at most one second. Connections live at most +60 seconds, bounding revocation and certificate rollover propagation to 61 seconds. +""" +import asyncio +import json +import os +from pathlib import Path +import signal +import ssl +import time + +IDENTITY = Path(os.environ.get('IDENTITY_DIR', '/identity')) +TRUST = Path(os.environ.get('TRUST_DIR', '/trust')) +_contexts = {} + + +def context(server=False): + cached = _contexts.get(server) + if cached and time.monotonic() < cached[0]: + return cached[1] + ctx = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH if server else ssl.Purpose.SERVER_AUTH, + cafile=str(TRUST/'bundle.pem')) + ctx.minimum_version = ssl.TLSVersion.TLSv1_2 + ctx.load_cert_chain(IDENTITY/'cert.pem', IDENTITY/'key.pem') + ctx.verify_mode = ssl.CERT_REQUIRED + ctx.verify_flags |= ssl.VERIFY_CRL_CHECK_LEAF + if server: + ctx.options |= ssl.OP_NO_TICKET + _contexts[server] = (time.monotonic() + 1, ctx) + return ctx + + +async def pump(reader, writer): + while chunk := await reader.read(16384): + writer.write(chunk) + await writer.drain() + + +async def serve(routes): + slots = asyncio.Semaphore(64) + tasks = set() + + async def handle(reader, writer, route): + peer = None + try: + async with asyncio.timeout(60): + if slots.locked(): return + async with slots: + if route['mode'] == 'server': + # Do not yield before start_tls: a raw StreamReader may + # consume ClientHello bytes while awaiting other work. + tls_context = context(True) + await writer.start_tls(tls_context, ssl_handshake_timeout=3) + cert = writer.get_extra_info('ssl_object').getpeercert() + names = {value for kind, value in cert.get('subjectAltName', ()) if kind == 'DNS'} + if not names.intersection(route['allow']): + return + target, peer = await asyncio.wait_for(asyncio.open_connection('127.0.0.1', route['target']), 3) + else: + tls_context = context() + target, peer = await asyncio.wait_for(asyncio.open_connection( + route['host'], route['target'], ssl=tls_context, server_hostname=route['host'], + ssl_handshake_timeout=3), 5) + transfers = [asyncio.create_task(pump(reader, peer)), asyncio.create_task(pump(target, writer))] + try: + await asyncio.wait(transfers, return_when=asyncio.FIRST_COMPLETED) + finally: + for task in transfers: task.cancel() + await asyncio.gather(*transfers, return_exceptions=True) + except (OSError, ssl.SSLError, TimeoutError, ConnectionError): + # No credentials, payloads or untrusted exception text in logs. + pass + finally: + writer.close() + if peer: peer.close() + + def accept(reader, writer, route): + # connection_made calls this synchronously. Pause before scheduling the + # coroutine: otherwise StreamReader can consume ClientHello while that + # coroutine waits in the event-loop queue. start_tls resumes the transport + # after installing SSLProtocol. Outgoing local plaintext is unaffected. + if route['mode'] == 'server': + writer.transport.pause_reading() + if len(tasks) >= 96: + writer.close(); return + task = asyncio.create_task(handle(reader, writer, route)) + tasks.add(task); task.add_done_callback(tasks.discard) + + servers = [] + for route in routes: + host = '0.0.0.0' if route['mode'] == 'server' else '127.0.0.1' + servers.append(await asyncio.start_server(lambda r,w,v=route: accept(r,w,v),host,route['listen'],backlog=64)) + stop = asyncio.Event() + loop = asyncio.get_running_loop() + for sig in (signal.SIGTERM, signal.SIGINT): loop.add_signal_handler(sig, stop.set) + await stop.wait() + for server in servers: server.close() + for task in tasks: task.cancel() + await asyncio.gather(*tasks, return_exceptions=True) + + +if __name__ == '__main__': + asyncio.run(serve(json.loads(Path(os.environ.get('PROXY_CONFIG','/proxy.json')).read_text()))) diff --git a/src/worker.py b/src/worker.py new file mode 100644 index 0000000..2948cc0 --- /dev/null +++ b/src/worker.py @@ -0,0 +1,228 @@ +"""At-least-once processing with versioned effects, fenced commits and bounded retries.""" +from datetime import datetime, timezone +import hashlib +import json +import os +from pathlib import Path +import random +import signal +import subprocess +import sys +import tempfile +import threading +import time +from uuid import UUID, uuid4 + +from botocore.exceptions import ClientError +from psycopg.types.json import Jsonb + +from .broker import acknowledge, connect, receive +from .jobs import MAX_ATTEMPTS, audit, database, take_fault +from .storage import MAX_BYTES, Storage +from . import telemetry as tel + +stop = threading.Event() + + +class Permanent(Exception): + pass + + +def crash(point, job_id, code): + print(json.dumps({'event':'injected_crash','point':point,'job_id':str(job_id),'exit_code':code}),flush=True) + os._exit(code) + + +def parse(raw): + item = json.loads(raw) + required = {'schema_version','job_id','type','attachment_id','pipeline_version','attempt','created_at'} + if set(item)-required-{'traceparent','tracestate'} or required-set(item): + raise ValueError('invalid_job_fields') + if item['schema_version'] != 1 or item['type'] != 'attachment.process.v1': + raise ValueError('unsupported_job') + UUID(item['job_id']); UUID(item['attachment_id']) + for field in ('attempt','pipeline_version'): + if type(item[field]) is not int or item[field]<1: + raise ValueError('invalid_job_number') + datetime.fromisoformat(item['created_at'].replace('Z','+00:00')) + return item + + +def claim(db, item): + with db.transaction(): + job = db.execute('SELECT * FROM jobs WHERE id=%s FOR UPDATE', (item['job_id'],)).fetchone() + if not job or job['status'] in ('done','failed','superseded'): + return None + if str(job['attachment_id'])!=item['attachment_id'] or job['pipeline_version']!=item['pipeline_version']: + return None + attachment = db.execute('SELECT * FROM attachments WHERE id=%s FOR UPDATE', (job['attachment_id'],)).fetchone() + if attachment['pipeline_version']!=job['pipeline_version']: + db.execute("UPDATE jobs SET status='superseded',updated_at=clock_timestamp() WHERE id=%s", (job['id'],)) + audit(db, job['id'], 'stale_version_ignored') + return None + if job['status']!='queued' or job['next_attempt_at']>datetime.now(timezone.utc): + return None + if item['attempt']!=job['attempts']+1: + return None + token=uuid4() + job=db.execute("""UPDATE jobs SET status='processing',attempts=attempts+1,lease_token=%s, + lease_until=clock_timestamp()+interval '60 seconds',updated_at=clock_timestamp() + WHERE id=%s RETURNING *""", (token,job['id'])).fetchone() + db.execute("UPDATE attachments SET status='processing',error_code=NULL,updated_at=clock_timestamp() WHERE id=%s", (attachment['id'],)) + audit(db,job['id'],'claimed',attempt=job['attempts'],version=job['pipeline_version']) + return job,attachment + + +def process_bytes(storage, attachment, version, folder): + source=folder/'source' + if not attachment['staging_key']: + raise Permanent('staging_missing') + try: + obj=storage.get(attachment['staging_key']) + except ClientError as exc: + if exc.response['Error']['Code'] in ('404','NoSuchKey'): + raise Permanent('staging_missing') from None + raise + size=0; digest=hashlib.sha256() + try: + with source.open('wb') as file: + while block:=obj['Body'].read(65536): + size+=len(block) + if size>MAX_BYTES: + raise Permanent('size_limit') + digest.update(block); file.write(block) + finally: + obj['Body'].close() + if size!=attachment['size_bytes'] or digest.hexdigest()!=attachment['sha256']: + raise Permanent('checksum_mismatch') + try: + with tel.span('image.render'): + rendering=subprocess.run([sys.executable,'-m','src.render',str(source),str(folder),str(version)], + capture_output=True,text=True,timeout=25) + except subprocess.TimeoutExpired: + raise Permanent('processing_timeout') from None + if rendering.returncode: + raise Permanent('invalid_image_or_resource_limit') + variants=json.loads(rendering.stdout) + # Version is part of every final key. Never use an unversioned mutable alias. + key=f'originals/{attachment["id"]}/v{version}' + with source.open('rb') as file: + storage.put(key,file,size,attachment['content_type'],attachment['sha256']) + for variant in variants: + variant['object_key']=f'variants/{attachment["id"]}/v{version}/{variant["name"]}' + with (folder/variant['name']).open('rb') as file: + storage.put(variant['object_key'],file,variant['size_bytes'],variant['content_type'],variant['sha256']) + return key,variants + + +def publish_result(db, job, key, variants): + with db.transaction(): + current=db.execute('SELECT * FROM jobs WHERE id=%s FOR UPDATE', (job['id'],)).fetchone() + att=db.execute('SELECT pipeline_version FROM attachments WHERE id=%s FOR UPDATE', (job['attachment_id'],)).fetchone() + if current['status']!='processing' or current['lease_token']!=job['lease_token'] or current['lease_until']<=datetime.now(timezone.utc): + return False + if att['pipeline_version']!=job['pipeline_version']: + db.execute("UPDATE jobs SET status='superseded',lease_token=NULL,lease_until=NULL,updated_at=clock_timestamp() WHERE id=%s",(job['id'],)) + audit(db,job['id'],'stale_commit_ignored') + return False + db.execute("""UPDATE attachments SET status='ready',storage_state='ready',object_key=%s, + variants=%s,error_code=NULL,updated_at=clock_timestamp() WHERE id=%s""", + (key,Jsonb(variants),job['attachment_id'])) + db.execute("UPDATE jobs SET status='done',error_code=NULL,lease_token=NULL,lease_until=NULL,updated_at=clock_timestamp() WHERE id=%s",(job['id'],)) + audit(db,job['id'],'ready',attempt=job['attempts'],version=job['pipeline_version']) + return True + + +def failed_attempt(db, job, exc): + permanent=isinstance(exc,Permanent) + final=permanent or job['attempts']>=MAX_ATTEMPTS + code=str(exc) if permanent else ('retry_exhausted' if final else 'storage_or_processing_unavailable') + delay=min(30,2**job['attempts'])+random.uniform(0,.5) + state='failed' if final else 'queued' + with db.transaction(): + row=db.execute("""UPDATE jobs SET status=%s,error_code=%s,lease_token=NULL,lease_until=NULL, + next_attempt_at=clock_timestamp()+(%s*interval '1 second'),updated_at=clock_timestamp() + WHERE id=%s AND status='processing' AND lease_token=%s RETURNING id""", + (state,code,delay,job['id'],job['lease_token'])).fetchone() + if not row: return + db.execute("UPDATE attachments SET status=%s,error_code=%s,updated_at=clock_timestamp() WHERE id=%s AND pipeline_version=%s", + (state,code if final else None,job['attachment_id'],job['pipeline_version'])) + db.execute('UPDATE outbox SET published_at=NULL WHERE job_id=%s',(job['id'],)) + audit(db,job['id'],state,error_code=code,attempt=job['attempts'],retry_delay_seconds=round(delay,3)) + + +def handle(item): + with database() as db: + claimed=claim(db,item) + if claimed is None: return 'noop' + job,attachment=claimed + fault=take_fault(db,job['id']) + if fault=='before_effect': crash(fault,job['id'],71) + storage=Storage() + try: + if fault=='transient': raise RuntimeError('synthetic_transient') + if fault=='permanent': raise Permanent('synthetic_permanent') + with tempfile.TemporaryDirectory(prefix='job-') as directory: + key,variants=process_bytes(storage,attachment,job['pipeline_version'],Path(directory)) + if fault=='after_effect': crash(fault,job['id'],72) + with tel.span('db.attachment.commit',attributes={'db.system.name':'postgresql'}): + done=publish_result(db,job,key,variants) + if done: + tel.ready_duration.record((datetime.now(timezone.utc)-attachment['accepted_at']).total_seconds(),{'pipeline_version':str(job['pipeline_version'])}) + if fault=='after_commit': crash(fault,job['id'],73) + # Cleanup is independently repeatable. Failure cannot roll back ready. + if done and attachment['staging_key']: + try: + storage.delete(attachment['staging_key']) + db.execute("UPDATE attachments SET staging_key=NULL WHERE id=%s AND pipeline_version=%s AND status='ready' AND staging_key=%s", + (attachment['id'],job['pipeline_version'],attachment['staging_key'])) + except Exception: + print(json.dumps({'event':'staging_cleanup_deferred'}),flush=True) + return 'ready' if done else 'superseded' + except Exception as exc: + failed_attempt(db,job,exc) + return 'failed' if isinstance(exc,Permanent) or job['attempts']>=MAX_ATTEMPTS else 'retry' + finally: + storage.client.close() + + +def main(): + tel.setup('messenger-worker') + tel.worker_capacity.set(1,{'process_instance':tel.instance}) + tel.worker_busy.set(0,{'process_instance':tel.instance}) + signal.signal(signal.SIGTERM,lambda *_:stop.set()) + signal.signal(signal.SIGINT,lambda *_:stop.set()) + consumer='worker-'+uuid4().hex + while not stop.is_set(): + try: + with connect() as client: + entry=receive(client,consumer) + if not entry: + tel.process_metrics() + continue + message_id,fields=entry + try: item=parse(fields.get('job','')) + except (ValueError,KeyError,TypeError): + print(json.dumps({'event':'invalid_broker_payload'}),flush=True) + acknowledge(client,message_id) + continue + started=time.monotonic() + with tel.span('attachment.consume',kind=tel.trace.SpanKind.CONSUMER,carrier=item, + attributes={'messaging.system':'redis','messaging.destination.name':'attachment-jobs'}) as current: + tel.worker_busy.set(1,{'process_instance':tel.instance}) + try: outcome=handle(item) + finally: tel.worker_busy.set(0,{'process_instance':tel.instance}) + acknowledge(client,message_id) + duration=time.monotonic()-started + attrs={'job_type':'attachment.process.v1','outcome':outcome} + tel.job_count.add(1,attrs); tel.job_duration.record(duration,attrs) + if outcome in ('retry','failed'): current.set_status(tel.trace.Status(tel.trace.StatusCode.ERROR)) + tel.event('job_finished',job_id=item['job_id'],attempt=item['attempt'],outcome=outcome,duration_seconds=round(duration,6)) + tel.process_metrics() + except Exception as exc: + # No ack on uncertain DB/transport result; lease/outbox re-drive intent. + tel.event('worker_retry',error_type=type(exc).__name__) + stop.wait(1) + + +if __name__=='__main__': main()