ЛР 7 — БВТ2303 — Вейнмайер — на 5 #29
@@ -18,3 +18,5 @@ __pycache__
|
||||
node_modules
|
||||
evidence
|
||||
.DS_Store
|
||||
bin
|
||||
experiments
|
||||
|
||||
@@ -39,3 +39,16 @@ BAO_CACERT=/run/secrets/bao-ca.crt
|
||||
ARGON2_MEMORY_KIB=19456
|
||||
ARGON2_ITERATIONS=2
|
||||
ARGON2_PARALLELISM=1
|
||||
# --- Решение lab7 (сопоставление — REPORT.md) ---
|
||||
# В compose: DATABASE_URL_FILE/CACHE_URL_FILE/S3_*_FILE/BROKER_URL_FILE НЕ используются приложением:
|
||||
# роль БД, ключ S3, ACL Redis сервис получает из OpenBao по своему сертификату
|
||||
# (BAO_ROLE, BAO_KV_PATH задаёт compose для каждого сервиса); broker — mTLS + SASL EXTERNAL.
|
||||
SECRETS_REFRESH=30s
|
||||
ARGON2_MAX_CONCURRENT=2
|
||||
LOGIN_RATE_PER_USER=10
|
||||
LOGIN_RATE_PER_IP=60
|
||||
LOGIN_RATE_WINDOW_SECONDS=60
|
||||
LB_PORT=8443
|
||||
GRAFANA_PORT=3000
|
||||
BAO_PORT=8200
|
||||
COLLECTOR_CONFIG=collector.yaml
|
||||
|
||||
@@ -0,0 +1,166 @@
|
||||
# Реальный прогон Docker-стенда lab7 на GitHub-hosted runner.
|
||||
# Нужен потому, что на машине разработки нет аппаратной виртуализации для Docker Desktop.
|
||||
# Все результаты — настоящие прогоны; публикуются в ветку lab7-results.
|
||||
name: lab7 stand
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [lab7]
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
concurrency:
|
||||
group: lab7-stand-${{ github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
env:
|
||||
PYTHONUTF8: "1"
|
||||
|
||||
jobs:
|
||||
# Unit-тесты и интеграционный fault-injection pipeline (трек 5) на настоящем PostgreSQL.
|
||||
go-tests:
|
||||
name: Go unit + интеграционный fault-injection
|
||||
runs-on: ubuntu-24.04
|
||||
timeout-minutes: 20
|
||||
services:
|
||||
postgres:
|
||||
image: postgres:16.4-alpine
|
||||
env:
|
||||
POSTGRES_USER: it
|
||||
POSTGRES_PASSWORD: it
|
||||
POSTGRES_DB: postgres
|
||||
ports: ["5432:5432"]
|
||||
options: >-
|
||||
--health-cmd "pg_isready -U it" --health-interval 2s --health-timeout 2s --health-retries 30
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: "1.26.11"
|
||||
- name: cwebp для теста варианта optimized
|
||||
run: sudo apt-get update -qq && sudo apt-get install -y -qq webp > /dev/null && cwebp -version
|
||||
- name: go test
|
||||
env:
|
||||
TEST_DATABASE_URL: postgres://it:it@localhost:5432/postgres?sslmode=disable
|
||||
run: |
|
||||
mkdir -p evidence/track2
|
||||
go test ./... -count=1 2>&1 | tee evidence/go_test.txt
|
||||
go test ./internal/worker/ -run Pipeline -count=1 -v 2>&1 | grep -E '^(=== RUN|--- |PASS|FAIL|ok)|FAULT INJECTION|duplicate|lease|stale|noop|attempt failed|early delivery' \
|
||||
| tee evidence/track2/pipeline_fault_injection.txt
|
||||
go test ./internal/imaging/ -run OptimizedWebP -count=1 -v 2>&1 | tee evidence/webp_test.txt
|
||||
go test ./internal/telemetry/ ./internal/transport/http/middleware/ ./internal/worker/ -run 'Telemetry|Trace|Route|Propag' -count=1 -v 2>&1 \
|
||||
| grep -E '^(=== RUN|--- |PASS|FAIL|ok)' | tee evidence/telemetry_tests.txt
|
||||
go test ./internal/tlsutil/ ./internal/service/ -count=1 -v 2>&1 | grep -E '^(=== RUN|--- |PASS|FAIL|ok)|handshake error' | tee evidence/security_unit_tests.txt
|
||||
- uses: actions/upload-artifact@v4
|
||||
if: always()
|
||||
with:
|
||||
name: evidence-go
|
||||
path: evidence/
|
||||
|
||||
stand:
|
||||
name: Стенд — ${{ matrix.part }}
|
||||
runs-on: ubuntu-24.04
|
||||
timeout-minutes: 150
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
part: [base, security, pipeline, track1]
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: "3.12"
|
||||
- name: Bootstrap стенда (PKI, OpenBao init/unseal, сервисные credentials) и запуск
|
||||
shell: bash
|
||||
run: |
|
||||
set -o pipefail
|
||||
mkdir -p evidence
|
||||
chmod +x scripts/*.sh infra/s3/init.sh
|
||||
sh scripts/init-secrets.sh && sh scripts/pki.sh init
|
||||
mkdir -p secrets/operator && touch secrets/operator/redis_users.acl secrets/operator/s3_users.txt
|
||||
docker compose --env-file .env config --quiet
|
||||
for img in $(docker compose --profile ops config --images | sort -u | grep -v -e '-api:local' -e '-probe:local'); do
|
||||
if docker pull -q "$img" > /dev/null 2>> evidence/pull_${{ matrix.part }}.log; then echo "ok $img"; else echo "FAIL $img"; fi
|
||||
done | tee -a evidence/pull_${{ matrix.part }}.log
|
||||
docker compose build 2>&1 | tail -20 > evidence/build_${{ matrix.part }}.log
|
||||
docker compose --profile test build probe 2>&1 | tail -5 >> evidence/build_${{ matrix.part }}.log
|
||||
python scripts/bootstrap.py all 2>&1 | tee evidence/bootstrap_${{ matrix.part }}.log
|
||||
- name: make check + доказательства (${{ matrix.part }})
|
||||
run: |
|
||||
make check PYTHON=python
|
||||
PYTHON=python PROBE_UID=$(id -u) sh scripts/collect-evidence.sh ${{ matrix.part }}
|
||||
- name: Окружение runner
|
||||
if: always()
|
||||
run: |
|
||||
mkdir -p evidence
|
||||
{ nproc; free -m; docker version --format '{{.Server.Version}}'; docker compose version; } > evidence/runner_${{ matrix.part }}.txt
|
||||
docker compose ps -a > evidence/docker_ps_final_${{ matrix.part }}.txt || true
|
||||
for c in $(docker compose ps -aq); do docker inspect -f '{{.Name}} restarts={{.RestartCount}} oom_killed={{.State.OOMKilled}} exit={{.State.ExitCode}}' "$c"; done > evidence/containers_state_${{ matrix.part }}.txt || true
|
||||
docker compose logs --no-color --tail 300 > evidence/compose_logs_${{ matrix.part }}.log 2>&1 || true
|
||||
docker compose logs --no-color api worker relay 2>&1 | grep -v '"msg":"http request"' | tail -3000 > evidence/app_logs_${{ matrix.part }}.log || true
|
||||
- uses: actions/upload-artifact@v4
|
||||
if: always()
|
||||
with:
|
||||
name: evidence-${{ matrix.part }}
|
||||
path: evidence/
|
||||
|
||||
# Сканы зависимостей и образов: сырые отчёты + разбор применимости в REPORT.md.
|
||||
scan:
|
||||
name: govulncheck + Trivy
|
||||
runs-on: ubuntu-24.04
|
||||
timeout-minutes: 30
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: "1.26.11"
|
||||
- name: govulncheck (достижимые уязвимости Go-кода)
|
||||
run: |
|
||||
mkdir -p evidence/scan
|
||||
go install golang.org/x/vuln/cmd/govulncheck@v1.1.4
|
||||
$(go env GOPATH)/bin/govulncheck ./... > evidence/scan/govulncheck.txt 2>&1 || true
|
||||
tail -30 evidence/scan/govulncheck.txt
|
||||
- name: Trivy (образ приложения и образы стенда)
|
||||
run: |
|
||||
docker build -q -t mtusi2026lab7-api:local . > /dev/null
|
||||
for img in mtusi2026lab7-api:local postgres:16.4-alpine redis:7.4.1-alpine rabbitmq:4.0.9-alpine haproxy:3.0.5-alpine openbao/openbao:2.1.0; do
|
||||
f=evidence/scan/trivy_$(echo "$img" | tr '/:' '__').json
|
||||
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock aquasec/trivy:0.58.1 image --quiet --format json --severity HIGH,CRITICAL --scanners vuln "$img" > "$f" 2>/dev/null || true
|
||||
python3 -c "import json,sys;d=json.load(open('$f'));r=[v for x in d.get('Results',[]) for v in (x.get('Vulnerabilities') or [])];print('$img', len(r), 'HIGH/CRITICAL', sorted({v['PkgName'] for v in r})[:15])" | tee -a evidence/scan/trivy_summary.txt || true
|
||||
done
|
||||
- uses: actions/upload-artifact@v4
|
||||
if: always()
|
||||
with:
|
||||
name: evidence-scan
|
||||
path: evidence/
|
||||
|
||||
publish:
|
||||
name: Публикация результатов в ветку lab7-results
|
||||
needs: [go-tests, stand, scan]
|
||||
if: always()
|
||||
runs-on: ubuntu-24.04
|
||||
permissions:
|
||||
contents: write
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/download-artifact@v4
|
||||
with:
|
||||
path: collected
|
||||
- name: Commit в lab7-results
|
||||
run: |
|
||||
git config user.name "github-actions[bot]"
|
||||
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
|
||||
git checkout -q --orphan lab7-results
|
||||
git rm -rf -q .
|
||||
{ echo "source_commit=${{ github.sha }}"
|
||||
echo "run=${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
|
||||
echo "go_tests=${{ needs.go-tests.result }}"
|
||||
echo "stand=${{ needs.stand.result }}"
|
||||
echo "scan=${{ needs.scan.result }}"; } > collected/RUN.txt
|
||||
cp -r collected/. .
|
||||
rm -rf collected
|
||||
git add -A
|
||||
git commit -q -m "results for ${{ github.sha }}"
|
||||
git push -f origin lab7-results
|
||||
@@ -30,3 +30,6 @@ coverage/
|
||||
.vscode/
|
||||
# Keep small, sanitized evidence summaries in evidence/ under version control.
|
||||
# Inspect git diff --cached: ignore rules are not a secret scanner.
|
||||
|
||||
# Пакет исходников (правило secrets/ выше — для каталога секретов стенда)
|
||||
!/internal/secrets/
|
||||
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
# ============================================================
|
||||
# Stage 1: builder — компилируем статический бинарник
|
||||
# ============================================================
|
||||
# Go 1.26.11 (патчи stdlib, см. REPORT.md: govulncheck). Тег с полной версией.
|
||||
FROM golang:1.26.11-alpine AS builder
|
||||
|
||||
WORKDIR /src
|
||||
|
||||
# Сначала манифесты зависимостей — кэшируем слой.
|
||||
COPY go.mod go.sum ./
|
||||
RUN go mod download
|
||||
|
||||
# Затем исходники.
|
||||
COPY . .
|
||||
|
||||
# Статический бинарник с оптимизациями:
|
||||
# CGO_ENABLED=0 — статическая линковка (не требует libc)
|
||||
# -ldflags="-s -w" — убираем отладочную информацию
|
||||
# -trimpath — убираем пути сборки из бинарника
|
||||
RUN CGO_ENABLED=0 GOOS=linux go build \
|
||||
-ldflags="-s -w -X github.com/charawein/mtusi2026lab7/internal/telemetry.Version=lab7" \
|
||||
-trimpath \
|
||||
-o /out/ \
|
||||
./cmd/api ./cmd/reconcile ./cmd/pipeline ./cmd/secprobe
|
||||
|
||||
# ============================================================
|
||||
# Stage «probe»: ТОЛЬКО для отрицательных тестов lab7 (docker compose --profile test).
|
||||
# Инструмент проверки прав не входит в образ приложения (финальная стадия ниже).
|
||||
# ============================================================
|
||||
FROM alpine:3.20@sha256:d9e853e87e55526f6b2917df91a2115c36dd7c696a35be12163d44e6e2a4b6bc AS probe
|
||||
RUN apk --no-cache add ca-certificates curl openssl
|
||||
COPY --from=builder /out/secprobe /usr/local/bin/secprobe
|
||||
USER 65534:65534
|
||||
ENTRYPOINT ["secprobe"]
|
||||
|
||||
# ============================================================
|
||||
# Stage 2: runtime — минимальный образ только с бинарником
|
||||
# ============================================================
|
||||
FROM alpine:3.20@sha256:d9e853e87e55526f6b2917df91a2115c36dd7c696a35be12163d44e6e2a4b6bc
|
||||
|
||||
# ca-certificates — для HTTPS в lab2+
|
||||
# tzdata — для корректной работы с временными зонами
|
||||
# libwebp-tools — cwebp для варианта optimized (WebP) в worker.
|
||||
# apk upgrade: исправления базового слоя (Trivy: musl CVE-2026-107891 исправлен в 1.2.5-r4).
|
||||
RUN apk --no-cache upgrade && apk --no-cache add ca-certificates tzdata libwebp-tools
|
||||
|
||||
# Непривилегированный пользователь (UID/GID 1001).
|
||||
RUN addgroup -g 1001 -S appgroup && \
|
||||
adduser -u 1001 -S appuser -G appgroup && \
|
||||
mkdir -p /var/lib/messenger/fault && chown appuser:appgroup /var/lib/messenger/fault
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Копируем бинарник и сразу выставляем владельца.
|
||||
COPY --from=builder --chown=appuser:appgroup /out/api /app/api
|
||||
# reconcile — сверка PostgreSQL и S3 (сервис reconciler и ручной запуск).
|
||||
COPY --from=builder --chown=appuser:appgroup /out/reconcile /app/reconcile
|
||||
# pipeline — worker, relay (outbox) и операторские команды (replay, failed, reprocess).
|
||||
COPY --from=builder --chown=appuser:appgroup /out/pipeline /app/pipeline
|
||||
|
||||
# Переключаемся на непривилегированного пользователя.
|
||||
USER 1001:1001
|
||||
|
||||
# Информативно: какой порт слушает приложение.
|
||||
EXPOSE 8443
|
||||
|
||||
# Healthcheck: readiness (БД + Redis + не в режиме drain).
|
||||
HEALTHCHECK --interval=5s --timeout=2s --start-period=20s --retries=3 \
|
||||
CMD wget --spider -q http://127.0.0.1:8081/health/ready || exit 1
|
||||
|
||||
# Exec-форма CMD — критично для доставки SIGTERM в приложение.
|
||||
CMD ["/app/api"]
|
||||
@@ -1,10 +1,10 @@
|
||||
PYTHON ?= python3
|
||||
BASE_URL ?= https://localhost:8443
|
||||
BASE_URL ?= http://localhost:8080
|
||||
CA_FILE ?=
|
||||
ACTION_SCRIPT ?=
|
||||
TLS_ARGS = $(if $(CA_FILE),--ca-file "$(CA_FILE)",)
|
||||
|
||||
.PHONY: help check validate test load test-persistence test-failover test-security
|
||||
.PHONY: help check validate test load test-persistence test-failover up down test-files test-pipeline test-faults failed replay evidence
|
||||
|
||||
help:
|
||||
@echo "check: offline structure; validate: full OpenAPI (requirements-dev.txt); test: running API; load: synthetic writes"
|
||||
@@ -29,5 +29,35 @@ test-failover:
|
||||
@test -n "$(ACTION_SCRIPT)" || (echo "Set ACTION_SCRIPT to your implemented executable stop-one hook"; exit 2)
|
||||
$(PYTHON) tests/resilience.py --mode failover --action-script "$(ACTION_SCRIPT)" --base-url "$(BASE_URL)" $(TLS_ARGS)
|
||||
|
||||
test-security:
|
||||
$(PYTHON) tests/security.py --base-url "$(BASE_URL)" $(TLS_ARGS)
|
||||
# --- Студенческие цели (lab5) ---
|
||||
up:
|
||||
sh scripts/init-secrets.sh
|
||||
sh scripts/pki.sh init
|
||||
docker compose --env-file .env build
|
||||
docker compose --profile test build probe
|
||||
$(PYTHON) scripts/bootstrap.py all
|
||||
|
||||
down:
|
||||
docker compose --env-file .env stop
|
||||
|
||||
test-files:
|
||||
$(PYTHON) student-tests/attachments_negative.py --base-url "$(BASE_URL)"
|
||||
|
||||
# Сценарии pipeline на стенде: make test-pipeline SCENARIO=demo (список — student-tests/pipeline_ops.py)
|
||||
SCENARIO ?= demo
|
||||
test-pipeline:
|
||||
$(PYTHON) student-tests/pipeline_ops.py $(SCENARIO) --base-url "$(BASE_URL)"
|
||||
|
||||
# Интеграционный fault-injection pipeline (трек 5); нужен PostgreSQL: TEST_DATABASE_URL=postgres://...
|
||||
test-faults:
|
||||
go test ./internal/worker/ -run Pipeline -count=1 -v
|
||||
|
||||
failed:
|
||||
docker compose run --rm --no-deps -T --entrypoint /app/pipeline relay failed
|
||||
|
||||
# make replay ID=<attachment_id>
|
||||
replay:
|
||||
docker compose run --rm --no-deps -T --entrypoint /app/pipeline relay replay $(ID) --actor operator
|
||||
|
||||
evidence:
|
||||
sh scripts/collect-evidence.sh all
|
||||
|
||||
@@ -1,37 +1,198 @@
|
||||
# Отчёт — лабораторная 7
|
||||
|
||||
- Автор, группа: TODO
|
||||
- Целевая оценка; выбранный трек 5, если нужен: TODO
|
||||
- Commit/PR: TODO после публикации
|
||||
- Использованные источники, библиотеки и помощь ИИ: TODO
|
||||
- Автор, группа: Вейнмайер Андрей Андреевич, БВТ2303
|
||||
- Целевая оценка: **5** — уровни 3 и 4 полностью + **трек 1 «Компрометация worker»**
|
||||
- Commit/PR: ветка `solution/bvt2303-weinmaier` в `Weinmaier_Andrew/mtusi2026lab7`; доказательства — прогон
|
||||
https://github.com/CharaWein/2026_lab3/actions/runs/43267046991 (commit `a414221`, все части `success`), файлы в `evidence/`
|
||||
- Источники: README и материалы курса (OWASP Password Storage, OWASP File Upload, документация OpenBao: cert auth,
|
||||
policies, production hardening; Docker security), документация RabbitMQ (TLS, access control), PostgreSQL (`pg_hba`,
|
||||
`sslmode`), MinIO (policies), Redis (ACL, TLS). Библиотеки: pgx v5, go-redis v9, minio-go v7, amqp091-go,
|
||||
golang.org/x/crypto/argon2, OpenTelemetry Go SDK.
|
||||
- Помощь ИИ: ИИ-ассистент использовался при реализации и отладке; все результаты ниже — реальные прогоны, ссылки на них приведены.
|
||||
|
||||
## Запуск из чистого clone
|
||||
|
||||
TODO: версии runtime/образов, prerequisites, команды создания локальных secrets/.env, build, миграций, запуска, ожидания готовности, тестов и остановки. Указать необходимые действия оператора. Не вставлять секреты. Отдельно указать безопасную остановку и команду намеренного удаления учебных данных.
|
||||
Версии: Docker 28 / Compose v2.38 (так в прогоне), Go 1.26.11 (только для `go test`), Python 3.9+, `openssl` в PATH.
|
||||
Образы закреплены по версиям в `compose.yaml` (postgres 16.4, redis 7.4.1, MinIO 2025-04-22, RabbitMQ 4.0.9,
|
||||
HAProxy 3.0.5, OpenBao 2.1.0, OTel Collector 0.116.1, Prometheus 3.1.0, Loki 3.3.2, Tempo 2.6.1, Grafana 11.4.0).
|
||||
|
||||
```sh
|
||||
sh scripts/init-secrets.sh # пароли и ключи оператора в secrets/ (вне Git, 600), значения не печатаются
|
||||
sh scripts/pki.sh init # CA стенда, CA телеметрии, leaf-сертификаты сервисов (ECDSA P-256)
|
||||
docker compose build && docker compose --profile test build probe
|
||||
python3 scripts/bootstrap.py all # OpenBao: init (3 доли, порог 2) + unseal + политики + cert-роли + KV;
|
||||
# роли БД, пользователи MinIO/RabbitMQ, ACL Redis; миграции; запуск стенда
|
||||
make test BASE_URL=https://localhost:8443 CA_FILE=secrets/pki/ca.crt
|
||||
```
|
||||
|
||||
`make up` выполняет те же шаги. Действия оператора:
|
||||
- после любого рестарта OpenBao он запечатан — `python3 scripts/bootstrap.py unseal` (берёт 2 доли из
|
||||
`secrets/operator/bao-init.json`; в эксплуатации доли хранятся у разных людей);
|
||||
- `scripts/restart.sh` — перезапуск всех процессов и хранилищ с unseal;
|
||||
- ротации: `bootstrap.py rotate-db|rotate-s3 <svc>`, `scripts/pki.sh rotate <имя> [CN]`, `bootstrap.py worker-identity gN`,
|
||||
`bootstrap.py revoke-tokens <svc>`.
|
||||
|
||||
Остановка без потери данных: `docker compose stop` (volumes сохраняются). Намеренное удаление учебных данных:
|
||||
`docker compose down -v` и удаление каталога `secrets/` (CA, доли unseal, пароли) — после этого стенд создаётся заново.
|
||||
|
||||
Все проверки этой работы: `sh scripts/collect-evidence.sh all` (части `base`, `security`, `pipeline`, `track1`).
|
||||
|
||||
## Архитектура и решения
|
||||
|
||||
TODO: схема процессов/хранилищ, источник истины, транзакционные границы, ограничения. Что перенесено из lab6, что изменено в этой работе. Соответствие переменных из .env.example реальной конфигурации.
|
||||
```
|
||||
клиент ──HTTPS 8443 (127.0.0.1)──► HAProxy lb ──mTLS (identity lb)──► api ×2 ──TLS──► PostgreSQL / Redis / MinIO
|
||||
│ ▲
|
||||
outbox (PostgreSQL) ─► relay ──AMQPS+mTLS──► RabbitMQ ──► worker
|
||||
все сервисы ──cert auth (тот же сертификат)──► OpenBao (секреты своего пути KV) (CN relay-g1 / worker-g1)
|
||||
api/worker/relay ──OTLP/HTTPS + mTLS (CA телеметрии)──► Collector ──mTLS──► Tempo / Loki ◄─HTTPS+mTLS── Grafana, Prometheus
|
||||
```
|
||||
|
||||
Сети: `front` (lb), `back` (приложения и хранилища), `telemetry`. Наружу опубликованы только `127.0.0.1:8443` (TLS ingress),
|
||||
`127.0.0.1:3000` (Grafana, HTTPS) и `127.0.0.1:8200` (OpenBao для оператора).
|
||||
|
||||
Что перенесено из lab6 без изменения смысла: контракт API, outbox → RabbitMQ → worker, идемпотентность, пайплайн вложений,
|
||||
наблюдаемость (трассы сквозь очередь, SLO, дашборд). Что изменено:
|
||||
|
||||
- **PKI** (`scripts/pki.sh`): корневой CA стенда, отдельный CA клиентов телеметрии, leaf на 30 дней с identity
|
||||
`CN=<роль>` + `URI:spiffe://messenger/<роль>`; ключи CA только у оператора.
|
||||
- **mTLS LB→API** — двойная проверка: HAProxy проверяет сервер (`verifyhost api`), API требует клиентский сертификат,
|
||||
проверяет цепочку **и** allowlist identity (`spiffe://messenger/lb`) и список отозванных serial
|
||||
(`internal/tlsutil`). Сертификаты перечитываются при изменении файла — ротация без рестарта.
|
||||
- **TLS ко всем хранилищам**: PostgreSQL `sslmode=verify-full` + `pg_hba` только `hostssl … scram-sha-256`;
|
||||
Redis только TLS-порт (`port 0`), ACL с отдельным пользователем; MinIO по HTTPS; RabbitMQ только AMQPS 5671
|
||||
с обязательным клиентским сертификатом и SASL EXTERNAL (пользователь = CN, паролей нет); Collector и бэкенды
|
||||
телеметрии — mTLS. Полная таблица связей — `contracts/trust-matrix.md`.
|
||||
- **OpenBao** не в dev-mode: file storage на volume, TLS, Shamir 3/2, audit log. Сервис входит своим клиентским
|
||||
сертификатом (auth/cert, роль = сервис), policy даёт `read` только на `secret/data/messenger/<сервис>`, токен
|
||||
15 мин / максимум 1 ч. Секреты обновляются каждые 30 s, при отказе OpenBao процесс работает на кэше.
|
||||
- **Least privilege**: роли БД `app_api`, `app_worker`, `app_relay`, `app_reconciler`
|
||||
(`migrations/0007_service_roles.up.sql`), пользователи MinIO с правами на префиксы, раздельные пользователи RabbitMQ;
|
||||
топологию очередей создаёт оператор (`infra/rabbitmq/definitions.json`), у приложений нет права configure.
|
||||
- **Пароли**: Argon2id m=19 MiB, t=2, p=1 (минимум OWASP), rehash старых hash при входе, не более 2 одновременных
|
||||
вычислений на реплику; лимит входа в Redis (общий для реплик); сессионный токен хранится как SHA-256; тело JSON ≤ 64 KiB.
|
||||
- **Hardening** контейнеров: non-root, `cap_drop: ALL`, `no-new-privileges`, `read_only` + tmpfs, лимиты CPU/RAM/pids,
|
||||
без docker.sock и host network.
|
||||
|
||||
Переменные из `.env.example` (`BAO_ADDR`, `BAO_ROLE`, `SECRETS_REFRESH`, `ARGON2_*`, `LOGIN_RATE_PER_USER/IP` и
|
||||
переменные lab6) подставляются в `compose.yaml` (якорь `x-app-env`). Значения, которые не должны меняться через `.env`,
|
||||
заданы в `compose.yaml` напрямую (`API_ALLOWED_CLIENTS`, `REVOKED_SERIALS_FILE`, пути к сертификатам);
|
||||
`CLAIM_RETRY_DELAY` имеет значение по умолчанию в коде (3 s). Секретов в переменных нет — только пути к файлам и адрес OpenBao.
|
||||
|
||||
## Доказательства критериев
|
||||
|
||||
| Критерий README | Команда/сценарий | Наблюдаемый результат | Файл доказательства |
|
||||
| --- | --- | --- | --- |
|
||||
| Публичный smoke | make test | TODO | TODO |
|
||||
| Остальные пункты уровня 3 | TODO | TODO | TODO |
|
||||
| Все пункты уровня 4, если заявлен | TODO | TODO | TODO |
|
||||
| Выбранный трек 5, если заявлен | TODO | TODO | TODO |
|
||||
| Публичный smoke через HTTPS | `make test`, `tests/security.py` | PASS: API-сценарий lab7; доверенный HTTPS работает, недоверенный CA отклонён | `evidence/base/smoke.txt`, `test_security.txt` |
|
||||
| Внешний TLS: CA, hostname, версия | `security_ops.py tls-external` | TLS 1.3 с CA стенда; чужое имя → hostname mismatch; чужой trust store → unable to get local issuer; TLS 1.1 → отказ; порты 8080, 8404, 9090, 5432, 6379, 9000, 5672, 4318 на хосте закрыты | `evidence/security/tls-external.json` |
|
||||
| mTLS LB→API | `security_ops.py mtls` | без сертификата → `certificate required`; сертификат чужого CA → отказ; доверенный CA с identity `attacker` или `worker` → `bad certificate`; identity `lb` → 200; plaintext HTTP на 8443 → 400 | `evidence/security/mtls.json` (`lb_to_api`) |
|
||||
| TLS к DB, S3, broker, Collector, бэкендам, OpenBao | `security_ops.py mtls` (servers) | TLS с проверкой сервера у всех; plaintext не обслуживается (Redis не отвечает на PING без TLS, AMQP 5672 закрыт); бэкенды телеметрии без клиентского сертификата отказывают; PostgreSQL `sslmode=disable` → отказ `pg_hba` | `evidence/security/mtls.json` (`servers`) |
|
||||
| OpenBao не в dev-mode, scoped policy, нет root в app | `security_ops.py openbao` | каждый сервис читает только свой путь: чужие пути, list, запись, запись policy, создание токена, seal → 403; сертификат worker под ролью api → login 400; в контейнерах нет токена в env, только сертификаты | `evidence/security/openbao.json` |
|
||||
| Hardening | `security_ops.py hardening` | api/worker/relay/reconciler: UID 1001, read-only, `cap_drop ALL`, `no-new-privileges`, лимиты (api 256 MiB/0.5 CPU/256 pids, worker 768 MiB); нигде нет privileged, docker.sock, host network | `evidence/security/hardening.json` |
|
||||
| Argon2id, ACL, logout, лимиты | `security_ops.py acl` | hash `argon2id m=19456,t=2,p=1`; посторонний → 404 на метаданные, контент и прикрепление чужого файла; подделка `X-User-Id` → 404/401; после logout → 401; JSON 65 KiB → 413; лимит: 10 × 401, затем 429 с `Retry-After: 58`, обслужили 2 реплики (счётчик общий) | `evidence/security/acl.json` |
|
||||
| Отказ реплики, перезапуск, rolling update через HTTPS | `make test-failover`, `test-persistence`, rolling update | подтверждённые данные и сессии сохранены; rolling update под нагрузкой: 11 673 запроса, 0 ошибок, 129.7 RPS, p99 90 ms | `evidence/base/failover_*.txt`, `persistence.txt`, `rolling_update_load.json` |
|
||||
| **4:** mTLS broker и Collector, разные identities | `security_ops.py mtls` | RabbitMQ: чужой CA → отказ; доверенный CA с CN `attacker`/`lb` → 403 (нет такого пользователя). worker: только consume своей очереди; publish, DLQ, declare, delete → отказ. relay: только publish. Collector: сертификаты основного CA (lb, worker) → `certificate required`; принимает только CA телеметрии | `evidence/security/mtls.json` (`broker`, `collector`) |
|
||||
| **4:** rehash, бюджет login DoS, общий rate limit | `security_ops.py acl`, `argon2` | rehash `m=65536,t=1,p=4` → `m=19456,t=2,p=1`; hash 71.9 ms (p50, 1 ядро); всплеск 120 параллельных входов: 59 × 401, 61 × 429 за 2.92 s, память API (пик) 197 / 131 MiB при лимите 256 MiB | `evidence/security/argon2.json` |
|
||||
| **4:** ротация secret и leaf без пересборки, отзыв identity | `security_ops.py rotation` | пароль роли БД `app_api`: старый → отказ, API → 200; ключ S3 worker: загрузка → ready; leaf `api`: serial `1909…0123` → `8c64…9308` без рестарта; leaf `lb`: старый отвергнут (`bad certificate`), новый → 200; под нагрузкой 34 548 запросов, 6 ошибок (0.017 %), p99 39.5 ms; образы не пересобирались | `evidence/security/rotation.json` |
|
||||
| **4:** expiry и sealed OpenBao | `security_ops.py lifecycle` | токен api с TTL 20 s / максимум 45 s: 8 входов за 100 s, 0 сбоев обновления, 200/200 запросов OK; OpenBao запечатан 33 s: 8 667 запросов, 0 ошибок; загрузка во время sealed → ready; рестарт worker во время sealed — не стартует без секретов, задание ждёт в `queued`, после unseal ready через 0.5 s | `evidence/security/lifecycle.json` |
|
||||
| **4:** scan с разбором применимости | govulncheck, Trivy | Go-код: 0 достижимых уязвимостей; образ приложения: 0 HIGH/CRITICAL; сторонние образы — разбор и порядок обновления | `evidence/scan/TRIAGE.md`, `govulncheck.txt`, `trivy_summary.txt` |
|
||||
| **4:** модель угроз ≥ 6 угроз с тестами | — | 10 угроз (T1–T10): путь, инвариант, контроль, отрицательный тест, остаточный риск | `security/THREAT_MODEL.md` |
|
||||
| **4:** worker ограничен по CPU/RAM/времени | compose, `pipeline_ops.py` | 1 CPU / 768 MiB / 128 pids, `JOB_TIMEOUT`, бюджет пикселей; пайплайн lab5/6 работает поверх TLS: demo, crash-effect (восстановление на 2-й попытке за 15.7 s), transient (3 попытки → ready), failed-replay | `evidence/pipeline/*.json` |
|
||||
| **4:** нет утечек в телеметрии | `security_ops.py leaks` | пароль, токен, текст сообщения, Basic-заголовок: 0 совпадений в Loki, в 20 трассах Tempo и в stdout | `evidence/security/leaks.json` |
|
||||
| **5, трек 1:** компрометация worker | `student-tests/compromise.py` | см. раздел ниже | `evidence/track1/track1/compromise.json` |
|
||||
|
||||
TODO: добавить отдельную строку для каждого заявленного критерия. PASS без команды и наблюдения не является доказательством. Проверка инфраструктурного hook требует подтверждения, какие реальные процессы/хранилища перезапущены.
|
||||
## Трек 1. Компрометация worker
|
||||
|
||||
**Гипотеза.** Если у worker только права, нужные для обработки вложений, то кража его identity (сертификат, ключ и всё,
|
||||
что он через них получает) не даёт доступа к паролям, сообщениям и чужим файлам. Если identity и секреты отзываются
|
||||
без рестарта, обработка восстанавливается без потери принятых заданий.
|
||||
|
||||
**Методика** (`student-tests/compromise.py`, изолированный стенд CI):
|
||||
1. **До least privilege** (модель lab6) — временные учётки с правами worker из lab6: владелец БД, общий ключ S3 на весь bucket,
|
||||
администратор RabbitMQ; проверяются тем же зондом `secprobe` (в образ приложения он не входит).
|
||||
2. **После** — зонд с украденным сертификатом worker: вход в OpenBao → его секреты → матрица операций.
|
||||
3. **Реакция под нагрузкой**: всё время идут загрузки (одна каждые 2 s), выполняются шаги отзыва и ротации.
|
||||
4. **Проверка**: украденное больше не работает, все принятые задания (202) дошли до ready.
|
||||
|
||||
**Матрица последствий** (allowed / denied, из `comparison` в `compromise.json`):
|
||||
|
||||
| Операция | До (lab6) | После (lab7) |
|
||||
| --- | --- | --- |
|
||||
| БД: чтение `users.password_hash`, `messages`, `chat_members` | allowed | denied |
|
||||
| БД: вставка сообщения, смена `attachments.owner_id`, удаление вложений | allowed | denied |
|
||||
| БД: `TRUNCATE jobs`, `CREATE TABLE`, `CREATE ROLE` | allowed | denied |
|
||||
| БД: чтение `jobs`, смена `jobs.state` / `attachments.status`, вставка вариантов | allowed | allowed (нужно для работы) |
|
||||
| S3: list bucket / всех bucket | allowed | denied |
|
||||
| S3: put `s/`, `a/`; get/delete `o/`, `v/`, `a/` | allowed | denied |
|
||||
| S3: get и delete `s/`, put `v/` и `o/` | allowed | allowed (нужно для работы) |
|
||||
| RabbitMQ: publish задания, чтение DLQ, создание очереди | allowed | denied |
|
||||
| RabbitMQ: consume `attachment.process` | allowed | allowed (нужно для работы) |
|
||||
| API в обход LB с сертификатом worker | allowed (HTTP :8080) | denied (`bad certificate`) |
|
||||
| OpenBao: чужие пути, list, запись, policy, seal | — (секреты файлами) | denied (403) |
|
||||
|
||||
**Реакция** (`response_steps`, время от начала):
|
||||
|
||||
| t, s | Шаг | Длительность, s |
|
||||
| --- | --- | --- |
|
||||
| 0.0 | новая identity: сертификат CN `worker-g2` (файл перезаписан на месте) | 0.1 |
|
||||
| 0.1 | OpenBao: cert-роль worker → только CN `worker-g2`; RabbitMQ: создан `worker-g2`, `worker-g1` удалён, его соединения закрыты | 17.1 |
|
||||
| 17.2 | отзыв всех токенов OpenBao, выданных worker | 3.7 |
|
||||
| 20.9 | ротация пароля роли `app_worker` и разрыв её соединений | 1.3 |
|
||||
| 22.2 | ротация secret key S3 `svc-worker` | 5.2 |
|
||||
|
||||
**Результат:**
|
||||
- после реакции украденный сертификат: вход в OpenBao → 400, RabbitMQ → 403, API → `bad certificate`;
|
||||
старый пароль БД → `password authentication failed`; старый ключ S3 → `SignatureDoesNotMatch` на все 15 операций;
|
||||
- обработка восстановилась **без рестарта** worker (`worker_restarts: 0`): первая загрузка после реакции дошла до ready
|
||||
через 0.5 s; в логах worker — `secrets.login` (вход с новым сертификатом) и `secrets.version`;
|
||||
- **задания не потеряны**: принято 27 (из них 21 во время реакции), ошибок загрузки 0, итог — 27 ready.
|
||||
|
||||
**Что пришлось исправить, чтобы реакция проходила под нагрузкой** (найдено прогонами, каждый с ссылкой в истории CI):
|
||||
1. Клиент OpenBao переиспользовал keep-alive TLS-соединение со старым сертификатом — вход шёл с отозванной identity.
|
||||
Теперь перед cert login простаивающие соединения закрываются.
|
||||
2. Ключ S3 меняется в MinIO раньше, чем worker читает новую версию секрета (окно до 30 s), — задания сжигали попытки
|
||||
и уходили в failed. Теперь при `InvalidAccessKeyId`/`SignatureDoesNotMatch` worker сразу перечитывает секрет и
|
||||
повторяет операцию (`internal/platform`, тест `internal/storage/autherr_test.go`); при ошибке БД 28P01 — аналогично.
|
||||
3. При неудачном claim сообщение возвращалось в очередь раз в секунду, и quorum-очередь (`x-delivery-limit=10`)
|
||||
уводила его в DLQ за ~10 s — задание оставалось `queued` без сообщения. Теперь перед requeue пауза
|
||||
`CLAIM_RETRY_DELAY` (3 s).
|
||||
|
||||
**Ограничения трека.** Worker по природе читает исходные изображения (`s/`) и пишет варианты: до ротации атакующий может
|
||||
подменить результат обработки. Право read на очередь в RabbitMQ разрешает и `queue.purge` — его нельзя отнять, не сломав
|
||||
consume (в зонде purge не выполняется, чтобы не разрушать очередь; риск описан в модели угроз, T3). Сертификат телеметрии
|
||||
worker (CA телеметрии) в процедуре не перевыпускался: украденный, он по-прежнему позволяет отправлять в Collector
|
||||
поддельную телеметрию (`otlp: ingest allowed` после реакции) — следующий шаг процедуры.
|
||||
|
||||
## Эксперименты и отказы
|
||||
|
||||
TODO: гипотеза, hardware/лимиты, версии, объём данных, профиль нагрузки, concurrency/arrival rate, длительность/прогрев, повторы, успешные RPS, ошибки, p50/p95/p99, CPU/RAM. Сохранить raw summary без tokens и объяснить ограничения измерения.
|
||||
Стенд CI: GitHub runner, 2 vCPU, 7.9 GiB RAM, Docker 28.0.4. Нагрузка — closed-loop POST сообщений без автоматических
|
||||
повторов; percentiles только по успешным запросам; у closed-loop есть coordinated omission.
|
||||
|
||||
| Воздействие | Что ожидаем | Что наблюдали | Время восстановления / потеря данных |
|
||||
| --- | --- | --- | --- |
|
||||
| TODO | TODO | TODO | TODO |
|
||||
| Ротация пароля БД api, ключа S3 worker, leaf api и lb под нагрузкой (3 потока, 138 s) | без рестарта и пересборки, единичные ошибки | 34 548 запросов, 6 ошибок (0.017 %), 249.5 RPS, p50/p95/p99 10.1/23.1/39.5 ms | API → 200 с первой попытки после ротации; потерь нет |
|
||||
| OpenBao запечатан (2 потока, 35 s) | работающие процессы живут на кэше, новые не стартуют | 8 667 запросов, 0 ошибок, p99 24.9 ms; рестарт worker во время sealed — ждёт; задание в `queued` | ready через 0.5 s после unseal; потерь нет |
|
||||
| Короткий TTL токена (20 s, максимум 45 s) | renew, затем повторный вход без сбоев | 8 входов за 100 s, 0 сбоев обновления, 200/200 OK | — |
|
||||
| Всплеск 120 параллельных входов с одного IP | лимит до Argon2id, память ограничена | 59 × 401, 61 × 429 за 2.92 s; пик памяти API 197 MiB (лимит 256) | — |
|
||||
| Компрометация worker (трек 1) | отзыв без рестарта, без потери заданий | см. трек 1 | обработка через 0.5 s после реакции; 27/27 ready |
|
||||
| Остановка API-реплики, рестарт хранилищ (lab3–6 через HTTPS) | данные и сессии сохранены | PASS | см. `evidence/base` |
|
||||
| Падение worker после побочного эффекта (lab5) | повтор после истечения lease | восстановление на попытке 2 за 15.7 s | потерь нет |
|
||||
|
||||
Бюджет Argon2id (`evidence/security/argon2.json`, 1 ядро): m=19 MiB t=2 — 71.9 ms (13.9 hash/s); m=46 MiB t=1 — 82.8 ms;
|
||||
m=19 MiB t=3 — 83.2 ms; m=64 MiB t=1 p=4 (параметры lab2–6) — 109.4 ms; m=64 MiB t=3 — 273.6 ms. Выбран минимум
|
||||
OWASP: он даёт ~14 входов/с на ядро, а 2 слота на реплику ограничивают память Argon2id до 76 MiB на стенд
|
||||
(2 реплики × 2 × 19 MiB) и пропускную способность до ~56 hash/s; лимиты 10/мин на username и 60/мин на IP отсекают
|
||||
перебор до вычисления hash.
|
||||
|
||||
## Ограничения и следующие шаги
|
||||
|
||||
TODO: какие отказы выдерживаются и какие нет; что не реализовано; где учебное упрощение; какое улучшение подтверждено, а какое пока гипотеза.
|
||||
- **Redis без mTLS**: TLS с проверкой сервера + ACL-пользователь с паролем из OpenBao; клиентский сертификат сервер не
|
||||
требует (отражено в trust matrix).
|
||||
- **Сторонние образы** с известными HIGH/CRITICAL (OpenSSL 3.3.2 и др.) не обновлены — разбор и порядок обновления в
|
||||
`evidence/scan/TRIAGE.md`; первым — HAProxy как единственный внешний TLS endpoint.
|
||||
- PostgreSQL, Redis, RabbitMQ и OpenBao работают от root образа с минимальным набором capabilities (CHOWN, DAC_OVERRIDE,
|
||||
FOWNER, SETUID/SETGID) — их entrypoint меняет владельца volume и сбрасывает привилегии; `read_only` для них не включён.
|
||||
- Потерянное сообщение RabbitMQ (purge скомпрометированным worker, превышение delivery-limit) не переиздаётся
|
||||
автоматически: задание остаётся `queued` в PostgreSQL, срабатывает алерт возраста старейшей работы, восстановление ручное.
|
||||
- Доли unseal в учебном стенде лежат у одного оператора в `secrets/operator`; в эксплуатации — у разных людей.
|
||||
- Сертификат телеметрии worker не входит в процедуру отзыва (см. трек 1).
|
||||
- Измерения сделаны на одном runner CI, по одному прогону сценария; это подтверждение поведения, а не статистика производительности.
|
||||
|
||||
+212
@@ -0,0 +1,212 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/charawein/mtusi2026lab7/internal/config"
|
||||
"github.com/charawein/mtusi2026lab7/internal/platform"
|
||||
"github.com/charawein/mtusi2026lab7/internal/repository/postgres"
|
||||
redisrepo "github.com/charawein/mtusi2026lab7/internal/repository/redis"
|
||||
"github.com/charawein/mtusi2026lab7/internal/service"
|
||||
"github.com/charawein/mtusi2026lab7/internal/telemetry"
|
||||
"github.com/charawein/mtusi2026lab7/internal/tlsutil"
|
||||
transporthttp "github.com/charawein/mtusi2026lab7/internal/transport/http"
|
||||
)
|
||||
|
||||
func main() {
|
||||
cfg := config.Load()
|
||||
slog.SetDefault(slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{Level: cfg.LogLevel})))
|
||||
// OTLP → Collector: трассы, метрики, логи (service.name=messenger-api,
|
||||
// service.instance.id = X-Instance-Id реплики). Логи дублируются JSON в stdout.
|
||||
shutdownTelemetry, err := telemetry.Setup(context.Background(), "messenger-api", cfg.InstanceID, cfg.LogLevel)
|
||||
if err != nil {
|
||||
slog.Error("telemetry setup", "err", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
defer func() {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
_ = shutdownTelemetry(ctx)
|
||||
}()
|
||||
|
||||
// Lab7: identity сервиса (сертификат) → OpenBao (cert auth) → роль БД, ACL Redis,
|
||||
// ключ S3 этого сервиса. Без BAO_ADDR — режим файлов lab6 (локальная разработка).
|
||||
bootCtx, bootCancel := context.WithTimeout(context.Background(), 90*time.Second)
|
||||
plat, err := platform.New(bootCtx, cfg)
|
||||
bootCancel()
|
||||
if err != nil {
|
||||
slog.Error("platform (tls/openbao)", "err", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
pool, err := plat.PG(ctx, cfg.DBPoolMax)
|
||||
cancel()
|
||||
if err != nil {
|
||||
slog.Error("connect to postgres", "err", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
defer pool.Close()
|
||||
|
||||
rctx, rcancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
redisClient, err := plat.Redis(rctx)
|
||||
rcancel()
|
||||
if err != nil {
|
||||
slog.Error("connect to redis", "err", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
defer redisClient.Close()
|
||||
|
||||
store, err := plat.S3()
|
||||
if err != nil {
|
||||
slog.Error("s3 client", "err", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
userRepo := postgres.NewUserRepository(pool)
|
||||
chatRepo := postgres.NewChatRepository(pool)
|
||||
msgRepo := postgres.NewMessageRepository(pool)
|
||||
sessRepo := redisrepo.NewSessionRepository(redisClient)
|
||||
|
||||
userSvc := service.NewUserService(userRepo)
|
||||
chatSvc := service.NewChatService(chatRepo, userRepo)
|
||||
|
||||
var msgCache *redisrepo.MessageCache
|
||||
if cfg.CacheEnabled {
|
||||
msgCache = redisrepo.NewMessageCache(redisClient, cfg.CacheInvalidation)
|
||||
}
|
||||
msgSvc := service.NewMessageService(msgRepo, chatRepo, msgCache, cfg.IdempotencyTTL)
|
||||
|
||||
attSvc := service.NewAttachmentService(postgres.NewAttachmentRepository(pool), chatRepo, store,
|
||||
cfg.MaxUploadBytes, cfg.MaxImagePixels, cfg.PipelineVersion, cfg.JobMaxAttempts)
|
||||
authSvc := service.NewAuthService(userRepo, sessRepo, cfg.SessionTTL())
|
||||
|
||||
// draining выставляется по SIGTERM: /health/ready начинает отвечать 503,
|
||||
// LB исключает реплику, и только затем закрывается listener.
|
||||
var draining atomic.Bool
|
||||
router := transporthttp.NewRouter(userSvc, chatSvc, msgSvc, attSvc, authSvc, pool, redisClient, cfg.InstanceID, &draining)
|
||||
|
||||
// Очистка просроченных ключей идемпотентности. Запрос идемпотентен,
|
||||
// поэтому параллельный запуск на всех репликах безопасен.
|
||||
cleanupCtx, cleanupStop := context.WithCancel(context.Background())
|
||||
defer cleanupStop()
|
||||
go func() {
|
||||
t := time.NewTicker(time.Hour)
|
||||
defer t.Stop()
|
||||
for {
|
||||
select {
|
||||
case <-cleanupCtx.Done():
|
||||
return
|
||||
case <-t.C:
|
||||
ctx, cancel := context.WithTimeout(cleanupCtx, 30*time.Second)
|
||||
if n, err := msgRepo.DeleteExpiredKeys(ctx, cfg.IdempotencyTTL); err != nil {
|
||||
slog.Warn("idempotency cleanup failed", "err", err)
|
||||
} else if n > 0 {
|
||||
slog.Info("idempotency keys expired", "deleted", n)
|
||||
}
|
||||
cancel()
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
srv := &http.Server{
|
||||
Addr: cfg.Addr(),
|
||||
Handler: router,
|
||||
// Ошибки TLS-рукопожатия (чужой CA, запрещённая identity) — в лог без шума stdlib.
|
||||
ErrorLog: slog.NewLogLogger(slog.Default().Handler(), slog.LevelWarn),
|
||||
ReadHeaderTimeout: 5 * time.Second,
|
||||
// Загрузка до 10 MiB должна уложиться в ReadTimeout; медленный клиент
|
||||
// дольше не держит соединение и память.
|
||||
ReadTimeout: 30 * time.Second,
|
||||
WriteTimeout: 35 * time.Second,
|
||||
IdleTimeout: 60 * time.Second,
|
||||
}
|
||||
|
||||
// Внутренний endpoint метрик для экспериментов (трек 1). Порт не публикуется
|
||||
// и не проксируется LB: читается только через docker exec внутри контейнера.
|
||||
internalSrv := &http.Server{
|
||||
Addr: cfg.InternalAddr,
|
||||
Handler: transporthttp.NewInternalStatsHandler(pool, cfg),
|
||||
ReadHeaderTimeout: 2 * time.Second,
|
||||
}
|
||||
go func() {
|
||||
if err := internalSrv.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) {
|
||||
slog.Warn("internal stats server failed", "err", err)
|
||||
}
|
||||
}()
|
||||
defer internalSrv.Close()
|
||||
|
||||
// Lab7: бизнес-API только по mTLS — клиент обязан предъявить сертификат CA стенда
|
||||
// с identity из API_ALLOWED_CLIENTS (по умолчанию lb). Plaintext-порта нет.
|
||||
if cfg.TLSCertFile != "" {
|
||||
kp, err := tlsutil.NewKeyPair(cfg.TLSCertFile, cfg.TLSKeyFile)
|
||||
if err != nil {
|
||||
slog.Error("api certificate", "err", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
tc, err := tlsutil.ServerMTLSRevocable(cfg.TLSCAFile, kp, tlsutil.NewRevoked(os.Getenv("REVOKED_SERIALS_FILE")),
|
||||
strings.Split(cfg.AllowedClients, ",")...)
|
||||
if err != nil {
|
||||
slog.Error("api mtls config", "err", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
srv.TLSConfig = tc
|
||||
}
|
||||
// Health для docker healthcheck: только 127.0.0.1 внутри контейнера, только
|
||||
// /health/live и /health/ready — обхода бизнес-API через него нет.
|
||||
healthSrv := &http.Server{Addr: cfg.HealthAddr, Handler: transporthttp.NewHealthMux(pool, redisClient, &draining),
|
||||
ReadHeaderTimeout: 2 * time.Second}
|
||||
go func() {
|
||||
if err := healthSrv.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) {
|
||||
slog.Warn("health listener failed", "err", err)
|
||||
}
|
||||
}()
|
||||
defer healthSrv.Close()
|
||||
|
||||
errCh := make(chan error, 1)
|
||||
go func() {
|
||||
slog.Info("server starting", "addr", cfg.Addr(), "instance_id", cfg.InstanceID, "mtls", srv.TLSConfig != nil)
|
||||
var err error
|
||||
if srv.TLSConfig != nil {
|
||||
err = srv.ListenAndServeTLS("", "")
|
||||
} else {
|
||||
err = srv.ListenAndServe()
|
||||
}
|
||||
if err != nil && !errors.Is(err, http.ErrServerClosed) {
|
||||
errCh <- err
|
||||
}
|
||||
}()
|
||||
|
||||
sigCtx, stop := signal.NotifyContext(context.Background(), syscall.SIGTERM, syscall.SIGINT)
|
||||
defer stop()
|
||||
|
||||
select {
|
||||
case err := <-errCh:
|
||||
slog.Error("server failed", "err", err)
|
||||
os.Exit(1)
|
||||
case <-sigCtx.Done():
|
||||
slog.Info("shutdown signal received, draining", "delay", cfg.DrainDelay)
|
||||
}
|
||||
|
||||
// Перестаём быть ready и даём LB время заметить это (inter*fall у HAProxy),
|
||||
// продолжая обслуживать уже направленные к нам запросы.
|
||||
draining.Store(true)
|
||||
time.Sleep(cfg.DrainDelay)
|
||||
|
||||
shutdownCtx, cancel := context.WithTimeout(context.Background(), cfg.ShutdownTimeout)
|
||||
defer cancel()
|
||||
if err := srv.Shutdown(shutdownCtx); err != nil {
|
||||
slog.Error("graceful shutdown failed", "err", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
slog.Info("server stopped")
|
||||
}
|
||||
@@ -0,0 +1,487 @@
|
||||
// Command pipeline — асинхронная обработка вложений (lab5) с телеметрией (lab6).
|
||||
//
|
||||
// pipeline worker потребитель broker (сервис worker)
|
||||
// pipeline relay outbox → broker, возврат истёкших lease, очистка staging
|
||||
// pipeline failed реестр failed-заданий (JSON)
|
||||
// pipeline replay <attachment_id> [--version N] [--actor NAME] явный повтор failed
|
||||
// pipeline reprocess <attachment_id> --version N работа новой версии (трек 5)
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"github.com/charawein/mtusi2026lab7/internal/service"
|
||||
"github.com/jackc/pgx/v5/pgconn"
|
||||
"io"
|
||||
"log/slog"
|
||||
"os"
|
||||
"os/signal"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/charawein/mtusi2026lab7/internal/broker"
|
||||
"github.com/charawein/mtusi2026lab7/internal/config"
|
||||
"github.com/charawein/mtusi2026lab7/internal/imaging"
|
||||
"github.com/charawein/mtusi2026lab7/internal/platform"
|
||||
"github.com/charawein/mtusi2026lab7/internal/repository/postgres"
|
||||
"github.com/charawein/mtusi2026lab7/internal/storage"
|
||||
"github.com/charawein/mtusi2026lab7/internal/telemetry"
|
||||
"github.com/charawein/mtusi2026lab7/internal/worker"
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/codes"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
)
|
||||
|
||||
func main() {
|
||||
slog.SetDefault(slog.New(slog.NewJSONHandler(os.Stdout, nil)))
|
||||
if len(os.Args) < 2 {
|
||||
fmt.Fprintln(os.Stderr, "usage: pipeline worker|relay|failed|replay|reprocess")
|
||||
os.Exit(2)
|
||||
}
|
||||
switch os.Args[1] {
|
||||
case "argon2-bench":
|
||||
os.Exit(argon2Bench())
|
||||
case "argon2-hash":
|
||||
os.Exit(argon2Hash())
|
||||
}
|
||||
cfg := config.Load()
|
||||
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGTERM, syscall.SIGINT)
|
||||
defer stop()
|
||||
|
||||
// Телеметрия только у долгоживущих процессов; служебные команды (failed,
|
||||
// replay) пишут JSON в stdout. service.name: messenger-worker / messenger-relay
|
||||
// (OTEL_SERVICE_NAME из compose имеет приоритет).
|
||||
if os.Args[1] == "worker" || os.Args[1] == "relay" {
|
||||
host, _ := os.Hostname()
|
||||
shutdown, err := telemetry.Setup(ctx, "messenger-"+os.Args[1], host, slog.LevelInfo)
|
||||
if err != nil {
|
||||
slog.Error("telemetry setup", "err", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
defer func() {
|
||||
sctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
_ = shutdown(sctx)
|
||||
}()
|
||||
}
|
||||
|
||||
// Lab7: identity сервиса (сертификат) → OpenBao → роль БД/ключ S3 этого сервиса.
|
||||
plat, err := platform.New(ctx, cfg)
|
||||
if err != nil {
|
||||
slog.Error("platform (tls/openbao)", "err", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
pool, err := plat.PG(ctx, int32(cfg.WorkerConcurrency+4))
|
||||
if err != nil {
|
||||
slog.Error("connect to postgres", "err", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
defer pool.Close()
|
||||
repo := postgres.NewPipelineRepository(pool)
|
||||
platformRef = plat
|
||||
|
||||
switch os.Args[1] {
|
||||
case "worker":
|
||||
code := runWorker(ctx, cfg, repo)
|
||||
if code != 0 {
|
||||
os.Exit(code)
|
||||
}
|
||||
case "relay":
|
||||
code := runRelay(ctx, cfg, repo)
|
||||
if code != 0 {
|
||||
os.Exit(code)
|
||||
}
|
||||
case "failed":
|
||||
jobs, err := repo.FailedJobs(ctx, 200)
|
||||
if err != nil {
|
||||
slog.Error("failed jobs", "err", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
out, _ := json.MarshalIndent(jobs, "", " ")
|
||||
fmt.Println(string(out))
|
||||
case "replay", "reprocess":
|
||||
fs := flag.NewFlagSet(os.Args[1], flag.ExitOnError)
|
||||
version := fs.Int("version", cfg.PipelineVersion, "pipeline version")
|
||||
actor := fs.String("actor", "operator", "who requested the replay (audit)")
|
||||
if len(os.Args) < 3 {
|
||||
fmt.Fprintln(os.Stderr, "attachment_id required")
|
||||
os.Exit(2)
|
||||
}
|
||||
_ = fs.Parse(os.Args[3:])
|
||||
var jobID string
|
||||
if os.Args[1] == "replay" {
|
||||
jobID, err = repo.Replay(ctx, os.Args[2], *version, *actor)
|
||||
} else {
|
||||
jobID, err = repo.Reprocess(ctx, os.Args[2], *version, cfg.JobMaxAttempts)
|
||||
}
|
||||
out, _ := json.Marshal(map[string]any{"command": os.Args[1], "attachment_id": os.Args[2], "version": *version,
|
||||
"job_id": jobID, "ok": err == nil, "error": errString(err)})
|
||||
fmt.Println(string(out))
|
||||
if err != nil {
|
||||
os.Exit(3)
|
||||
}
|
||||
default:
|
||||
fmt.Fprintln(os.Stderr, "unknown command", os.Args[1])
|
||||
os.Exit(2)
|
||||
}
|
||||
}
|
||||
|
||||
func errString(err error) string {
|
||||
if err == nil {
|
||||
return ""
|
||||
}
|
||||
return err.Error()
|
||||
}
|
||||
|
||||
func faultPoints() map[string]bool {
|
||||
m := map[string]bool{}
|
||||
for _, p := range strings.Split(os.Getenv("FAULT_POINTS"), ",") {
|
||||
if p = strings.TrimSpace(p); p != "" {
|
||||
m[p] = true
|
||||
}
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
var platformRef *platform.Platform
|
||||
|
||||
func brokerTLS() *tls.Config {
|
||||
tc, err := platformRef.BrokerTLS()
|
||||
if err != nil {
|
||||
slog.Error("broker tls", "err", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
return tc
|
||||
}
|
||||
|
||||
func newStore(cfg config.Config) storage.Store {
|
||||
store, err := platformRef.S3()
|
||||
if err != nil {
|
||||
slog.Error("s3 client", "err", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
return store
|
||||
}
|
||||
|
||||
func runWorker(ctx context.Context, cfg config.Config, repo *postgres.PipelineRepository) int {
|
||||
host, _ := os.Hostname()
|
||||
owner := fmt.Sprintf("%s:%d", host, os.Getpid())
|
||||
w := worker.New(repo, newStore(cfg), imaging.CWebP, worker.Config{
|
||||
Owner: owner, Lease: cfg.JobTimeout, JobTimeout: cfg.JobTimeout,
|
||||
MaxBytes: cfg.MaxUploadBytes, MaxPixels: cfg.MaxImagePixels, PixelBudget: cfg.PixelBudget,
|
||||
WebPQuality: cfg.WebPQuality, RetryBase: cfg.RetryBaseDelay, RetryMax: cfg.RetryMaxDelay,
|
||||
FaultPoints: faultPoints(), FaultDir: faultDir(), DeleteStaging: true,
|
||||
ClaimRetryDelay: envDuration("CLAIM_RETRY_DELAY", 3*time.Second), OnClaimError: onDBError,
|
||||
})
|
||||
slog.Info("worker starting", "event", "worker.start", "owner", owner, "concurrency", cfg.WorkerConcurrency, "lease", cfg.JobTimeout)
|
||||
// Ёмкость worker (saturation = messenger.worker.busy / capacity).
|
||||
capacity, _ := telemetry.Meter().Int64ObservableGauge("messenger.worker.capacity", metric.WithUnit("{job}"),
|
||||
metric.WithDescription("Concurrent job slots of this worker (prefetch)"))
|
||||
_, _ = telemetry.Meter().RegisterCallback(func(_ context.Context, o metric.Observer) error {
|
||||
o.ObserveInt64(capacity, int64(cfg.WorkerConcurrency))
|
||||
return nil
|
||||
}, capacity)
|
||||
tracer := telemetry.Tracer()
|
||||
backoff := time.Second
|
||||
for ctx.Err() == nil {
|
||||
cons, deliveries, err := broker.NewConsumer(cfg.BrokerURL, cfg.WorkerConcurrency, "worker-"+owner, brokerTLS(),
|
||||
os.Getenv("BROKER_DECLARE") != "false")
|
||||
if err != nil {
|
||||
slog.Warn("broker unavailable, retrying", "err", err, "in", backoff)
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
case <-time.After(backoff):
|
||||
}
|
||||
backoff = min(backoff*2, 30*time.Second)
|
||||
continue
|
||||
}
|
||||
backoff = time.Second
|
||||
var wg sync.WaitGroup
|
||||
for i := 0; i < cfg.WorkerConcurrency; i++ {
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
for d := range deliveries {
|
||||
// Consumer span — дочерний для producer span relay (W3C traceparent
|
||||
// из заголовков AMQP), тот — для upload: одна трасса от HTTP до S3/DB.
|
||||
mctx := otel.GetTextMapPropagator().Extract(context.WithoutCancel(ctx), broker.HeaderCarrier(d.Headers))
|
||||
mctx, span := tracer.Start(mctx, broker.Queue+" process", trace.WithSpanKind(trace.SpanKindConsumer),
|
||||
trace.WithAttributes(
|
||||
attribute.String("messaging.system", "rabbitmq"),
|
||||
attribute.String("messaging.operation.type", "process"),
|
||||
attribute.String("messaging.destination.name", broker.Queue),
|
||||
attribute.String("messaging.message.id", d.MessageId),
|
||||
attribute.Bool("messaging.rabbitmq.redelivered", d.Redelivered),
|
||||
))
|
||||
decision := w.Handle(mctx, d.Body)
|
||||
span.SetAttributes(attribute.String("messenger.delivery.decision", decision.String()))
|
||||
span.End()
|
||||
switch decision {
|
||||
case worker.Ack:
|
||||
_ = d.Ack(false)
|
||||
case worker.Requeue:
|
||||
time.Sleep(time.Second)
|
||||
_ = d.Nack(false, true)
|
||||
case worker.Reject:
|
||||
_ = d.Nack(false, false) // → DLX attachment.dead
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
// Graceful: прекращаем получать новые сообщения, дорабатываем текущие.
|
||||
slog.Info("shutdown: cancel consumer, finishing in-flight jobs")
|
||||
cons.Cancel("worker-" + owner)
|
||||
done := make(chan struct{})
|
||||
go func() { wg.Wait(); close(done) }()
|
||||
select {
|
||||
case <-done:
|
||||
case <-time.After(cfg.JobTimeout):
|
||||
slog.Warn("shutdown timeout: unacked jobs will be redelivered")
|
||||
}
|
||||
cons.Close()
|
||||
return 0
|
||||
case <-waitAll(&wg):
|
||||
slog.Warn("broker connection lost, reconnecting")
|
||||
cons.Close()
|
||||
}
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func waitAll(wg *sync.WaitGroup) <-chan struct{} {
|
||||
ch := make(chan struct{})
|
||||
go func() { wg.Wait(); close(ch) }()
|
||||
return ch
|
||||
}
|
||||
|
||||
func runRelay(ctx context.Context, cfg config.Config, repo *postgres.PipelineRepository) int {
|
||||
store := newStore(cfg)
|
||||
points := faultPoints()
|
||||
afterPublish := func() { worker.Fault(points, faultDir(), "relay.after_publish", os.Exit) }
|
||||
var pub *broker.Publisher
|
||||
defer func() {
|
||||
if pub != nil {
|
||||
pub.Close()
|
||||
}
|
||||
}()
|
||||
tPublish := time.NewTicker(300 * time.Millisecond)
|
||||
tSweep := time.NewTicker(5 * time.Second)
|
||||
tClean := time.NewTicker(time.Minute)
|
||||
defer tPublish.Stop()
|
||||
defer tSweep.Stop()
|
||||
defer tClean.Stop()
|
||||
slog.Info("relay starting", "event", "relay.start")
|
||||
registerQueueGauges(repo)
|
||||
tracer := telemetry.Tracer()
|
||||
published, _ := telemetry.Meter().Int64Counter("messenger.outbox.published", metric.WithUnit("{message}"),
|
||||
metric.WithDescription("Outbox messages confirmed by broker"))
|
||||
publishDur, _ := telemetry.Meter().Float64Histogram("messenger.outbox.publish.duration", metric.WithUnit("s"),
|
||||
metric.WithDescription("Publish + publisher confirm latency"))
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return 0
|
||||
case <-tPublish.C:
|
||||
if pub == nil || pub.Closed() {
|
||||
p, err := broker.NewPublisher(cfg.BrokerURL, brokerTLS(), os.Getenv("BROKER_DECLARE") != "false")
|
||||
if err != nil {
|
||||
slog.Warn("broker unavailable; outbox keeps messages", "err", err)
|
||||
continue
|
||||
}
|
||||
pub = p
|
||||
}
|
||||
for {
|
||||
// Цикл опроса outbox не трассируется (Unsampled); producer span каждого
|
||||
// сообщения — дочерний для span, записавшего его в outbox (upload/попытка).
|
||||
n, err := repo.PublishDue(telemetry.Unsampled(ctx), 100, func(c context.Context, m postgres.OutboxMessage) error {
|
||||
pctx := telemetry.ExtractMap(context.WithoutCancel(ctx), m.Trace)
|
||||
pctx, span := tracer.Start(pctx, broker.Queue+" publish", trace.WithSpanKind(trace.SpanKindProducer),
|
||||
trace.WithAttributes(
|
||||
attribute.String("messaging.system", "rabbitmq"),
|
||||
attribute.String("messaging.operation.type", "publish"),
|
||||
attribute.String("messaging.destination.name", broker.Exchange),
|
||||
attribute.String("messaging.message.id", m.JobID),
|
||||
attribute.Float64("messenger.outbox.wait_seconds", time.Since(m.Created).Seconds()),
|
||||
))
|
||||
start := time.Now()
|
||||
err := pub.Publish(pctx, m.JobID, m.Payload)
|
||||
res := "ok"
|
||||
if err != nil {
|
||||
res = "error"
|
||||
span.RecordError(err)
|
||||
span.SetStatus(codes.Error, "publish failed")
|
||||
}
|
||||
publishDur.Record(pctx, time.Since(start).Seconds(), metric.WithAttributes(attribute.String("outcome", res)))
|
||||
if err == nil {
|
||||
published.Add(pctx, 1)
|
||||
}
|
||||
span.End()
|
||||
return err
|
||||
}, afterPublish)
|
||||
if err != nil {
|
||||
slog.Warn("outbox publish failed; will retry", "err", err)
|
||||
break
|
||||
}
|
||||
if n > 0 {
|
||||
slog.Info("outbox published", "messages", n)
|
||||
}
|
||||
if n < 100 {
|
||||
break
|
||||
}
|
||||
}
|
||||
case <-tSweep.C:
|
||||
if n, err := repo.SweepExpiredLeases(telemetry.Unsampled(ctx)); err != nil {
|
||||
slog.Warn("lease sweep failed", "err", err)
|
||||
} else if n > 0 {
|
||||
slog.Warn("expired leases requeued", "jobs", n)
|
||||
}
|
||||
case <-tClean.C:
|
||||
cleanStaging(telemetry.Unsampled(ctx), cfg, repo, store)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// cleanStaging удаляет staging после безопасной публикации (ready, ≥10 мин назад —
|
||||
// fallback, если worker не удалил сразу) и у failed старше STAGING_RETENTION.
|
||||
func cleanStaging(ctx context.Context, cfg config.Config, repo *postgres.PipelineRepository, store storage.Store) {
|
||||
cands, err := repo.StagingToClean(ctx, 10*time.Minute, cfg.StagingRetention, 200)
|
||||
if err != nil {
|
||||
slog.Warn("staging cleanup query failed", "err", err)
|
||||
return
|
||||
}
|
||||
for _, c := range cands {
|
||||
if err := store.Delete(ctx, c.Key); err != nil && !errors.Is(err, storage.ErrNotFound) {
|
||||
slog.Warn("staging delete failed", "key", c.Key, "err", err)
|
||||
continue
|
||||
}
|
||||
_ = repo.ClearStaging(ctx, c.AttachmentID, c.Key)
|
||||
}
|
||||
if len(cands) > 0 {
|
||||
slog.Info("staging cleaned", "objects", len(cands))
|
||||
}
|
||||
}
|
||||
|
||||
// registerQueueGauges — глубина очереди и возраст старейшей работы по PostgreSQL
|
||||
// (источник истины; broker-метрики RabbitMQ собираются Prometheus отдельно).
|
||||
func registerQueueGauges(repo *postgres.PipelineRepository) {
|
||||
m := telemetry.Meter()
|
||||
jobs, _ := m.Int64ObservableGauge("messenger.jobs.backlog", metric.WithUnit("{job}"),
|
||||
metric.WithDescription("Jobs by state (queued, processing, failed)"))
|
||||
oldest, _ := m.Float64ObservableGauge("messenger.jobs.oldest_age", metric.WithUnit("s"),
|
||||
metric.WithDescription("Age of the oldest unfinished job (queued or processing)"))
|
||||
outbox, _ := m.Int64ObservableGauge("messenger.outbox.pending", metric.WithUnit("{message}"),
|
||||
metric.WithDescription("Due outbox messages not yet confirmed by broker"))
|
||||
outboxAge, _ := m.Float64ObservableGauge("messenger.outbox.oldest_age", metric.WithUnit("s"),
|
||||
metric.WithDescription("Age of the oldest due unpublished outbox message"))
|
||||
q := attribute.String("queue", broker.Queue)
|
||||
_, _ = m.RegisterCallback(func(ctx context.Context, o metric.Observer) error {
|
||||
qctx, cancel := context.WithTimeout(telemetry.Unsampled(ctx), 2*time.Second)
|
||||
defer cancel()
|
||||
st, err := repo.QueueStats(qctx)
|
||||
if err != nil {
|
||||
return nil // нет данных — пропуск точки, а не ошибка экспорта
|
||||
}
|
||||
o.ObserveInt64(jobs, st.Queued, metric.WithAttributes(q, attribute.String("state", "queued")))
|
||||
o.ObserveInt64(jobs, st.Processing, metric.WithAttributes(q, attribute.String("state", "processing")))
|
||||
o.ObserveInt64(jobs, st.Failed, metric.WithAttributes(q, attribute.String("state", "failed")))
|
||||
o.ObserveFloat64(oldest, st.OldestQueuedAge, metric.WithAttributes(q))
|
||||
o.ObserveInt64(outbox, st.OutboxPending)
|
||||
o.ObserveFloat64(outboxAge, st.OldestOutboxAge)
|
||||
return nil
|
||||
}, jobs, oldest, outbox, outboxAge)
|
||||
}
|
||||
|
||||
// argon2Bench — время одного Argon2id-хэша для набора параметров на ЭТОМ контейнере
|
||||
// (его лимитах CPU/RAM): основа выбора ARGON2_* и бюджета login DoS (REPORT.md).
|
||||
func argon2Bench() int {
|
||||
fs := flag.NewFlagSet("argon2-bench", flag.ExitOnError)
|
||||
n := fs.Int("n", 10, "hashes per parameter set")
|
||||
_ = fs.Parse(os.Args[2:])
|
||||
sets := []service.Argon2Params{
|
||||
{MemoryKiB: 19456, Iterations: 2, Parallelism: 1}, // OWASP минимум, базовая конфигурация курса
|
||||
{MemoryKiB: 47104, Iterations: 1, Parallelism: 1}, // OWASP-эквивалент с большей памятью
|
||||
{MemoryKiB: 19456, Iterations: 3, Parallelism: 1},
|
||||
{MemoryKiB: 65536, Iterations: 1, Parallelism: 4}, // параметры lab2–6 (для rehash)
|
||||
{MemoryKiB: 65536, Iterations: 3, Parallelism: 1},
|
||||
}
|
||||
out := []map[string]any{}
|
||||
for _, p := range sets {
|
||||
var ds []float64
|
||||
for i := 0; i < *n; i++ {
|
||||
t := time.Now()
|
||||
if _, err := service.HashWith("benchmark-password-123", p); err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
return 1
|
||||
}
|
||||
ds = append(ds, float64(time.Since(t).Microseconds())/1000)
|
||||
}
|
||||
sort.Float64s(ds)
|
||||
out = append(out, map[string]any{"m_kib": p.MemoryKiB, "t": p.Iterations, "p": p.Parallelism,
|
||||
"ms_p50": ds[len(ds)/2], "ms_max": ds[len(ds)-1], "hashes_per_s_one_core": 1000 / ds[len(ds)/2]})
|
||||
}
|
||||
b, _ := json.MarshalIndent(map[string]any{"current": service.CurrentArgon2(), "results": out}, "", " ")
|
||||
fmt.Println(string(b))
|
||||
return 0
|
||||
}
|
||||
|
||||
// argon2Hash — hash пароля (stdin) с заданными параметрами: имитация hash старой
|
||||
// конфигурации для проверки rehash при входе.
|
||||
func argon2Hash() int {
|
||||
fs := flag.NewFlagSet("argon2-hash", flag.ExitOnError)
|
||||
m := fs.Uint("m", 65536, "memory KiB")
|
||||
t := fs.Uint("t", 1, "iterations")
|
||||
p := fs.Uint("p", 4, "parallelism")
|
||||
_ = fs.Parse(os.Args[2:])
|
||||
b, _ := io.ReadAll(io.LimitReader(os.Stdin, 1024))
|
||||
h, err := service.HashWith(strings.TrimSpace(string(b)), service.Argon2Params{MemoryKiB: uint32(*m), Iterations: uint32(*t), Parallelism: uint8(*p)})
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
return 1
|
||||
}
|
||||
fmt.Println(h)
|
||||
return 0
|
||||
}
|
||||
|
||||
// faultDir — каталог маркеров точек сбоя (FAULT_DIR, volume в compose).
|
||||
func faultDir() string {
|
||||
if d := os.Getenv("FAULT_DIR"); d != "" {
|
||||
return d
|
||||
}
|
||||
return os.TempDir()
|
||||
}
|
||||
|
||||
// onDBError: PostgreSQL отверг пароль роли (28P01 — оператор ротировал его раньше,
|
||||
// чем наступило плановое обновление секрета) → внеочередное чтение из OpenBao.
|
||||
func onDBError(ctx context.Context, err error) {
|
||||
if platformRef == nil || platformRef.Secrets == nil || err == nil {
|
||||
return
|
||||
}
|
||||
var pe *pgconn.PgError
|
||||
authFailed := errors.As(err, &pe) && pe.Code == "28P01"
|
||||
// Ошибка установления соединения pgx не всегда отдаёт PgError через errors.As.
|
||||
if !authFailed && !strings.Contains(err.Error(), "SQLSTATE 28P01") {
|
||||
return
|
||||
}
|
||||
if platformRef.Secrets.SyncNow(ctx) {
|
||||
slog.InfoContext(ctx, "db credentials refreshed after auth error", "event", "secrets.db_auth_retry",
|
||||
"version", platformRef.Secrets.Version())
|
||||
}
|
||||
}
|
||||
|
||||
func envDuration(k string, def time.Duration) time.Duration {
|
||||
if d, err := time.ParseDuration(os.Getenv(k)); err == nil && d >= 0 {
|
||||
return d
|
||||
}
|
||||
return def
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
// Command reconcile сверяет PostgreSQL и S3 и безопасно убирает расхождения.
|
||||
//
|
||||
// reconcile # dry-run, grace 1h, отчёт JSON в stdout
|
||||
// reconcile --apply # исправить
|
||||
// reconcile --apply --interval 10m # фоновый режим (сервис reconciler в compose)
|
||||
//
|
||||
// Grace period должен быть больше максимальной длительности загрузки
|
||||
// (ReadTimeout 30 s + PUT) с запасом на расхождение часов; значения < 5m
|
||||
// разрешены только с --unsafe-short-grace (для тестов).
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
"github.com/charawein/mtusi2026lab7/internal/platform"
|
||||
"log/slog"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/charawein/mtusi2026lab7/internal/config"
|
||||
"github.com/charawein/mtusi2026lab7/internal/reconcile"
|
||||
"github.com/charawein/mtusi2026lab7/internal/repository/postgres"
|
||||
)
|
||||
|
||||
func main() {
|
||||
apply := flag.Bool("apply", false, "apply fixes (default: dry-run, report only)")
|
||||
grace := flag.Duration("grace", time.Hour, "do not touch objects/intents/quarantine younger than this")
|
||||
unsafe := flag.Bool("unsafe-short-grace", false, "allow grace < 5m (tests only)")
|
||||
interval := flag.Duration("interval", 0, "repeat every interval (0 = run once)")
|
||||
flag.Parse()
|
||||
|
||||
slog.SetDefault(slog.New(slog.NewJSONHandler(os.Stderr, nil)))
|
||||
if *grace < 5*time.Minute && !*unsafe {
|
||||
fmt.Fprintln(os.Stderr, "grace < 5m is unsafe: in-flight uploads could be deleted; pass --unsafe-short-grace for tests")
|
||||
os.Exit(2)
|
||||
}
|
||||
|
||||
cfg := config.Load()
|
||||
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGTERM, syscall.SIGINT)
|
||||
defer stop()
|
||||
|
||||
plat, err := platform.New(ctx, cfg)
|
||||
if err != nil {
|
||||
slog.Error("platform (tls/openbao)", "err", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
pool, err := plat.PG(ctx, 4)
|
||||
if err != nil {
|
||||
slog.Error("connect to postgres", "err", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
defer pool.Close()
|
||||
store, err := plat.S3()
|
||||
if err != nil {
|
||||
slog.Error("s3 client", "err", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
repo := postgres.NewAttachmentRepository(pool)
|
||||
|
||||
runOnce := func() int {
|
||||
unlock, ok, err := repo.TryLock(ctx)
|
||||
if err != nil {
|
||||
slog.Error("advisory lock", "err", err)
|
||||
return 1
|
||||
}
|
||||
if !ok {
|
||||
slog.Warn("another reconciler is running, skipping this pass")
|
||||
return 3
|
||||
}
|
||||
defer unlock()
|
||||
var now time.Time
|
||||
if err := pool.QueryRow(ctx, `SELECT now()`).Scan(&now); err != nil {
|
||||
slog.Error("db time", "err", err)
|
||||
return 1
|
||||
}
|
||||
rep, err := reconcile.Run(ctx, repo, store, reconcile.Options{
|
||||
Prefix: "", Grace: *grace, Apply: *apply, Now: now, // весь bucket: a/, s/, o/, v/
|
||||
})
|
||||
out, _ := json.Marshal(rep)
|
||||
fmt.Println(string(out))
|
||||
if err != nil {
|
||||
slog.Error("reconcile pass failed", "err", err)
|
||||
return 1
|
||||
}
|
||||
slog.Info("reconcile pass done", "dry_run", rep.DryRun, "found", rep.Found, "fixed", rep.Fixed,
|
||||
"rows", rep.RowsScanned, "objects", rep.ObjectsScanned, "ms", rep.DurationMS)
|
||||
if len(rep.Errors) > 0 {
|
||||
return 4
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
if *interval <= 0 {
|
||||
os.Exit(runOnce())
|
||||
}
|
||||
t := time.NewTicker(*interval)
|
||||
defer t.Stop()
|
||||
for {
|
||||
runOnce()
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
case <-t.C:
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,564 @@
|
||||
// Command secprobe — инструмент ОТРИЦАТЕЛЬНЫХ проверок lab7 (только тестовый образ
|
||||
// target=probe, в образ приложения не входит). Проверяет, что разрешено/запрещено
|
||||
// предъявителю конкретной identity, и печатает JSON-матрицу allowed/denied.
|
||||
//
|
||||
// secprobe tls -addr api:8443 -name api [-cert c -key k] [-ca ca] [-path /health/ready]
|
||||
// secprobe amqp -cert c -key k права в RabbitMQ (SASL EXTERNAL по CN)
|
||||
// secprobe otlp -cert c -key k ingest в Collector
|
||||
// secprobe db -user u -password-file f права роли PostgreSQL (TLS verify-full)
|
||||
// secprobe s3 -access a -secret-file f права ключа S3 по префиксам
|
||||
// secprobe bao -cert c -key k -role r -path p OpenBao: свой/чужой путь, запись, sys
|
||||
// secprobe compromise -cert c -key k -otel-cert -otel-key -role r -path p
|
||||
// всё сразу от имени сервиса: вход в OpenBao его сертификатом, чтение его
|
||||
// секретов, затем DB/S3/AMQP/OTLP с ними (модель «получены права worker»)
|
||||
//
|
||||
// Секреты не печатаются; в выводе только имена операций и allowed/denied/ошибка.
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"crypto/x509"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/minio/minio-go/v7"
|
||||
"github.com/minio/minio-go/v7/pkg/credentials"
|
||||
amqp "github.com/rabbitmq/amqp091-go"
|
||||
)
|
||||
|
||||
type result map[string]any
|
||||
|
||||
func main() {
|
||||
if len(os.Args) < 2 {
|
||||
fmt.Fprintln(os.Stderr, "usage: secprobe tls|amqp|otlp|db|s3|bao|compromise ...")
|
||||
os.Exit(2)
|
||||
}
|
||||
fs := flag.NewFlagSet(os.Args[1], flag.ExitOnError)
|
||||
addr := fs.String("addr", "", "host:port")
|
||||
name := fs.String("name", "", "TLS server name")
|
||||
ca := fs.String("ca", "/pki/ca.crt", "CA file")
|
||||
cert := fs.String("cert", "", "client certificate")
|
||||
key := fs.String("key", "", "client key")
|
||||
otelCert := fs.String("otel-cert", "", "telemetry client certificate")
|
||||
otelKey := fs.String("otel-key", "", "telemetry client key")
|
||||
path := fs.String("path", "/health/ready", "HTTP path / KV path")
|
||||
role := fs.String("role", "", "OpenBao cert role")
|
||||
user := fs.String("user", "", "db user")
|
||||
pwFile := fs.String("password-file", "", "file with db password")
|
||||
access := fs.String("access", "", "s3 access key")
|
||||
secretFile := fs.String("secret-file", "", "file with s3 secret key")
|
||||
sslmode := fs.String("sslmode", "verify-full", "postgres sslmode")
|
||||
stdinSecret := fs.Bool("stdin", false, "read password/secret from stdin")
|
||||
send := fs.String("send", "", "plaintext bytes to send (plain)")
|
||||
_ = fs.Parse(os.Args[2:])
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
|
||||
defer cancel()
|
||||
|
||||
var out result
|
||||
switch os.Args[1] {
|
||||
case "tls":
|
||||
out = probeTLS(*addr, *name, *ca, *cert, *key, *path, *send)
|
||||
case "amqp":
|
||||
out = probeAMQP(*ca, *cert, *key)
|
||||
case "otlp":
|
||||
out = probeOTLP(*ca, *cert, *key)
|
||||
case "db":
|
||||
pw := readFile(*pwFile)
|
||||
if *stdinSecret {
|
||||
pw = readStdin()
|
||||
}
|
||||
out = probeDB(ctx, *ca, *user, pw, *sslmode)
|
||||
case "s3":
|
||||
sec := readFile(*secretFile)
|
||||
if *stdinSecret {
|
||||
sec = readStdin()
|
||||
}
|
||||
out = probeS3(ctx, *ca, *access, sec)
|
||||
case "plain":
|
||||
out = probePlain(*addr, *send)
|
||||
case "bao":
|
||||
out = probeBao(*ca, *cert, *key, *role, *path)
|
||||
case "compromise":
|
||||
out = compromise(ctx, *ca, *cert, *key, *otelCert, *otelKey, *role, *path)
|
||||
default:
|
||||
fmt.Fprintln(os.Stderr, "unknown command")
|
||||
os.Exit(2)
|
||||
}
|
||||
b, _ := json.MarshalIndent(out, "", " ")
|
||||
fmt.Println(string(b))
|
||||
}
|
||||
|
||||
func readStdin() string {
|
||||
b, _ := io.ReadAll(io.LimitReader(os.Stdin, 4096))
|
||||
return strings.TrimSpace(string(b))
|
||||
}
|
||||
|
||||
// probePlain — отвечает ли порт по plaintext-протоколу (без TLS).
|
||||
func probePlain(addr, send string) result {
|
||||
c, err := net.DialTimeout("tcp", addr, 5*time.Second)
|
||||
if err != nil {
|
||||
return result{"addr": addr, "plaintext": "no listener (" + short(err) + ")"}
|
||||
}
|
||||
defer c.Close()
|
||||
_ = c.SetDeadline(time.Now().Add(5 * time.Second))
|
||||
payload := strings.ReplaceAll(send, `\r\n`, "\r\n") // CRLF в аргументе как \r\n
|
||||
_, _ = c.Write([]byte(payload))
|
||||
buf := make([]byte, 256)
|
||||
n, err := c.Read(buf)
|
||||
reply := string(buf[:n])
|
||||
if len(reply) > 80 {
|
||||
reply = reply[:80]
|
||||
}
|
||||
return result{"addr": addr, "reply_bytes": n, "reply_prefix": fmt.Sprintf("%q", reply), "read_err": errString(err)}
|
||||
}
|
||||
|
||||
func errString(err error) string {
|
||||
if err == nil {
|
||||
return ""
|
||||
}
|
||||
return short(err)
|
||||
}
|
||||
|
||||
func readFile(p string) string {
|
||||
if p == "" {
|
||||
return ""
|
||||
}
|
||||
b, err := os.ReadFile(p)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
return strings.TrimSpace(string(b))
|
||||
}
|
||||
|
||||
func pool(ca string) *x509.CertPool {
|
||||
p := x509.NewCertPool()
|
||||
b, _ := os.ReadFile(ca)
|
||||
p.AppendCertsFromPEM(b)
|
||||
return p
|
||||
}
|
||||
|
||||
func tlsConf(ca, cert, key, name string) (*tls.Config, error) {
|
||||
c := &tls.Config{RootCAs: pool(ca), ServerName: name, MinVersion: tls.VersionTLS12}
|
||||
if cert != "" {
|
||||
kp, err := tls.LoadX509KeyPair(cert, key)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
c.Certificates = []tls.Certificate{kp}
|
||||
}
|
||||
return c, nil
|
||||
}
|
||||
|
||||
// classify — причина отказа TLS: сервер отверг клиента (alert), клиент отверг сервер, сеть.
|
||||
func classify(err error) string {
|
||||
if err == nil {
|
||||
return "ok"
|
||||
}
|
||||
s := err.Error()
|
||||
var uae x509.UnknownAuthorityError
|
||||
var hne x509.HostnameError
|
||||
switch {
|
||||
case errors.As(err, &uae):
|
||||
return "client_rejected_server: unknown authority"
|
||||
case errors.As(err, &hne):
|
||||
return "client_rejected_server: hostname mismatch"
|
||||
case strings.Contains(s, "certificate required"):
|
||||
return "server_rejected: certificate required"
|
||||
case strings.Contains(s, "unknown certificate authority") || strings.Contains(s, "unknown ca"):
|
||||
return "server_rejected: unknown certificate authority"
|
||||
case strings.Contains(s, "bad certificate"):
|
||||
return "server_rejected: bad certificate"
|
||||
case strings.Contains(s, "access denied") || strings.Contains(s, "handshake failure"):
|
||||
return "server_rejected: " + s
|
||||
case strings.Contains(s, "connection reset") || strings.Contains(s, "EOF") || strings.Contains(s, "broken pipe"):
|
||||
return "server_rejected: connection closed after handshake (" + s + ")"
|
||||
}
|
||||
var ne net.Error
|
||||
if errors.As(err, &ne) {
|
||||
return "network: " + s
|
||||
}
|
||||
return "error: " + s
|
||||
}
|
||||
|
||||
func probeTLS(addr, name, ca, cert, key, path, send string) result {
|
||||
tc, err := tlsConf(ca, cert, key, name)
|
||||
if err != nil {
|
||||
return result{"result": "error: " + err.Error()}
|
||||
}
|
||||
if send != "" {
|
||||
// Не-HTTP протокол (Redis): рукопожатие с проверкой сертификата сервера + команда.
|
||||
c, err := tls.DialWithDialer(&net.Dialer{Timeout: 5 * time.Second}, "tcp", addr, tc)
|
||||
if err != nil {
|
||||
return result{"addr": addr, "result": classify(err)}
|
||||
}
|
||||
defer c.Close()
|
||||
_ = c.SetDeadline(time.Now().Add(5 * time.Second))
|
||||
if _, err := c.Write([]byte(strings.ReplaceAll(send, `\r\n`, "\r\n"))); err != nil {
|
||||
return result{"addr": addr, "result": classify(err)}
|
||||
}
|
||||
buf := make([]byte, 128)
|
||||
n, err := c.Read(buf)
|
||||
if n == 0 {
|
||||
return result{"addr": addr, "result": classify(err)}
|
||||
}
|
||||
return result{"addr": addr, "result": "ok", "reply_prefix": strings.TrimSpace(string(buf[:n])),
|
||||
"server_serial": c.ConnectionState().PeerCertificates[0].SerialNumber.Text(16)}
|
||||
}
|
||||
// TLS 1.3: отказ сервера в клиентском сертификате приходит после рукопожатия —
|
||||
// поэтому делаем реальный HTTP-запрос и классифицируем его ошибку.
|
||||
cl := &http.Client{Timeout: 10 * time.Second, Transport: &http.Transport{TLSClientConfig: tc, DisableKeepAlives: true}}
|
||||
resp, err := cl.Get("https://" + addr + path)
|
||||
if err != nil {
|
||||
return result{"addr": addr, "result": classify(err)}
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
serial := ""
|
||||
if resp.TLS != nil && len(resp.TLS.PeerCertificates) > 0 {
|
||||
serial = resp.TLS.PeerCertificates[0].SerialNumber.Text(16)
|
||||
}
|
||||
return result{"addr": addr, "result": "ok", "status": resp.StatusCode, "instance": resp.Header.Get("X-Instance-Id"),
|
||||
"server_serial": serial}
|
||||
}
|
||||
|
||||
// ---------------- RabbitMQ ----------------
|
||||
|
||||
func probeAMQP(ca, cert, key string) result {
|
||||
tc, err := tlsConf(ca, cert, key, "rabbitmq")
|
||||
if err != nil {
|
||||
return result{"connect": "error: " + err.Error()}
|
||||
}
|
||||
cfg := amqp.Config{TLSClientConfig: tc, SASL: []amqp.Authentication{&amqp.ExternalAuth{}}, Heartbeat: 10 * time.Second}
|
||||
conn, err := amqp.DialConfig("amqps://rabbitmq:5671/", cfg)
|
||||
if err != nil {
|
||||
return result{"connect": "denied: " + short(err)}
|
||||
}
|
||||
defer conn.Close()
|
||||
res := result{"connect": "allowed"}
|
||||
try := func(label string, f func(ch *amqp.Channel) error) {
|
||||
ch, err := conn.Channel()
|
||||
if err != nil {
|
||||
res[label] = "error: " + short(err)
|
||||
return
|
||||
}
|
||||
defer ch.Close()
|
||||
if err := f(ch); err != nil {
|
||||
res[label] = "denied: " + short(err)
|
||||
return
|
||||
}
|
||||
res[label] = "allowed"
|
||||
}
|
||||
try("publish attachments (job)", func(ch *amqp.Channel) error {
|
||||
if err := ch.Confirm(false); err != nil {
|
||||
return err
|
||||
}
|
||||
dc, err := ch.PublishWithDeferredConfirm("attachments", "process", true, false,
|
||||
amqp.Publishing{ContentType: "application/json", Body: []byte(`{"probe":true}`)})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
ok, err := dc.WaitContext(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !ok {
|
||||
return errors.New("nack")
|
||||
}
|
||||
return nil
|
||||
})
|
||||
try("consume attachment.process", func(ch *amqp.Channel) error {
|
||||
_, err := ch.Consume("attachment.process", "probe", false, true, false, false, nil)
|
||||
if err == nil {
|
||||
_ = ch.Cancel("probe", false) // неподтверждённое вернётся в очередь
|
||||
}
|
||||
return err
|
||||
})
|
||||
try("consume attachment.dead (DLQ)", func(ch *amqp.Channel) error {
|
||||
_, err := ch.Consume("attachment.dead", "probe-dlq", false, true, false, false, nil)
|
||||
return err
|
||||
})
|
||||
try("declare queue evil", func(ch *amqp.Channel) error {
|
||||
_, err := ch.QueueDeclare("evil.probe", false, true, false, false, nil)
|
||||
return err
|
||||
})
|
||||
// queue.purge в RabbitMQ авторизуется правом read — оно у worker есть по необходимости
|
||||
// (consume). Зонд purge НЕ выполняет: это разрушило бы очередь стенда. Остаточный
|
||||
// риск описан в security/THREAT_MODEL.md (обнаружение — возраст старейшей queued-работы).
|
||||
try("delete queue attachment.process", func(ch *amqp.Channel) error {
|
||||
_, err := ch.QueueDelete("attachment.process", true, true, false) // ifUnused+ifEmpty: не разрушает
|
||||
return err
|
||||
})
|
||||
return res
|
||||
}
|
||||
|
||||
func short(err error) string {
|
||||
s := err.Error()
|
||||
if len(s) > 160 {
|
||||
s = s[:160]
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
// ---------------- Collector ----------------
|
||||
|
||||
func probeOTLP(ca, cert, key string) result {
|
||||
tc, err := tlsConf(ca, cert, key, "otel-collector")
|
||||
if err != nil {
|
||||
return result{"ingest": "error: " + err.Error()}
|
||||
}
|
||||
cl := &http.Client{Timeout: 10 * time.Second, Transport: &http.Transport{TLSClientConfig: tc, DisableKeepAlives: true}}
|
||||
// Пустой ExportTraceServiceRequest (protobuf длины 0) — валидный запрос без данных.
|
||||
resp, err := cl.Post("https://otel-collector:4318/v1/traces", "application/x-protobuf", bytes.NewReader(nil))
|
||||
if err != nil {
|
||||
return result{"ingest": classify(err)}
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
return result{"ingest": "allowed", "status": resp.StatusCode}
|
||||
}
|
||||
|
||||
// ---------------- PostgreSQL ----------------
|
||||
|
||||
func probeDB(ctx context.Context, ca, user, password, sslmode string) result {
|
||||
dsn := fmt.Sprintf("postgres://%s@postgres:5432/messenger?sslmode=%s&sslrootcert=%s", user, sslmode, ca)
|
||||
cc, err := pgx.ParseConfig(dsn)
|
||||
if err != nil {
|
||||
return result{"connect": "error: " + err.Error()}
|
||||
}
|
||||
cc.Password = password
|
||||
conn, err := pgx.ConnectConfig(ctx, cc)
|
||||
if err != nil {
|
||||
return result{"connect": "denied: " + short(err)}
|
||||
}
|
||||
defer conn.Close(ctx)
|
||||
res := result{"connect": "allowed", "role": user}
|
||||
// Каждая проверка — в транзакции с ROLLBACK: ничего не меняется даже при «allowed».
|
||||
try := func(label, sql string) {
|
||||
tx, err := conn.Begin(ctx)
|
||||
if err != nil {
|
||||
res[label] = "error: " + short(err)
|
||||
return
|
||||
}
|
||||
defer tx.Rollback(ctx)
|
||||
if _, err := tx.Exec(ctx, sql); err != nil {
|
||||
if strings.Contains(err.Error(), "permission denied") {
|
||||
res[label] = "denied"
|
||||
} else {
|
||||
res[label] = "error: " + short(err)
|
||||
}
|
||||
return
|
||||
}
|
||||
res[label] = "allowed"
|
||||
}
|
||||
try("read users.password_hash", `SELECT password_hash FROM users LIMIT 1`)
|
||||
try("read messages", `SELECT text FROM messages LIMIT 1`)
|
||||
try("read chat_members", `SELECT * FROM chat_members LIMIT 1`)
|
||||
try("insert message", `INSERT INTO messages (id, chat_id, sender_id, text, created_at)
|
||||
SELECT gen_random_uuid(), chat_id, user_id, 'probe', now() FROM chat_members LIMIT 1`)
|
||||
try("read jobs", `SELECT job_id FROM jobs LIMIT 1`)
|
||||
try("update jobs.state", `UPDATE jobs SET state = state WHERE false`)
|
||||
try("update attachments.owner_id", `UPDATE attachments SET owner_id = owner_id WHERE false`)
|
||||
try("update attachments.status", `UPDATE attachments SET status = status WHERE false`)
|
||||
try("delete attachments", `DELETE FROM attachments WHERE false`)
|
||||
try("insert attachment_variants", `INSERT INTO attachment_variants SELECT * FROM attachment_variants WHERE false`)
|
||||
try("truncate jobs", `TRUNCATE jobs CASCADE`)
|
||||
try("create table", `CREATE TABLE probe_evil (x int)`)
|
||||
try("create role", `CREATE ROLE probe_evil`)
|
||||
return res
|
||||
}
|
||||
|
||||
// ---------------- S3 ----------------
|
||||
|
||||
func probeS3(ctx context.Context, ca, access, secret string) result {
|
||||
tr, _ := minio.DefaultTransport(true)
|
||||
tr.TLSClientConfig = &tls.Config{RootCAs: pool(ca), MinVersion: tls.VersionTLS12}
|
||||
c, err := minio.New("s3:9000", &minio.Options{Creds: credentials.NewStaticV4(access, secret, ""), Secure: true,
|
||||
Transport: tr, BucketLookup: minio.BucketLookupPath, MaxRetries: 1})
|
||||
if err != nil {
|
||||
return result{"client": "error: " + err.Error()}
|
||||
}
|
||||
const b = "messenger-attachments"
|
||||
res := result{}
|
||||
verdict := func(err error) string {
|
||||
if err == nil {
|
||||
return "allowed"
|
||||
}
|
||||
code := minio.ToErrorResponse(err).Code
|
||||
switch code {
|
||||
case "AccessDenied", "InvalidAccessKeyId", "SignatureDoesNotMatch":
|
||||
return "denied (" + code + ")"
|
||||
case "NoSuchKey":
|
||||
return "allowed (no such key)"
|
||||
}
|
||||
return "error: " + short(err)
|
||||
}
|
||||
probe := "probe-" + fmt.Sprint(time.Now().UnixNano())
|
||||
for _, p := range []string{"s/", "o/", "v/", "a/"} {
|
||||
_, err := c.PutObject(ctx, b, p+probe, bytes.NewReader([]byte("x")), 1, minio.PutObjectOptions{})
|
||||
res["put "+p+"*"] = verdict(err)
|
||||
if err == nil {
|
||||
defer c.RemoveObject(context.Background(), b, p+probe, minio.RemoveObjectOptions{})
|
||||
}
|
||||
o, err := c.GetObject(ctx, b, p+"no-such-"+probe, minio.GetObjectOptions{})
|
||||
if err == nil {
|
||||
_, err = io.ReadAll(o)
|
||||
}
|
||||
res["get "+p+"*"] = verdict(err)
|
||||
err = c.RemoveObject(ctx, b, p+"no-such-"+probe, minio.RemoveObjectOptions{})
|
||||
res["delete "+p+"*"] = verdict(err)
|
||||
}
|
||||
n, err := 0, error(nil)
|
||||
for o := range c.ListObjects(ctx, b, minio.ListObjectsOptions{Recursive: true, MaxKeys: 10}) {
|
||||
if o.Err != nil {
|
||||
err = o.Err
|
||||
break
|
||||
}
|
||||
n++
|
||||
if n > 10 {
|
||||
break
|
||||
}
|
||||
}
|
||||
res["list bucket"] = verdict(err)
|
||||
res["make bucket"] = verdict(c.MakeBucket(ctx, "evil-"+probe[len(probe)-8:], minio.MakeBucketOptions{}))
|
||||
_, err = c.ListBuckets(ctx)
|
||||
res["list all buckets"] = verdict(err)
|
||||
return res
|
||||
}
|
||||
|
||||
// ---------------- OpenBao ----------------
|
||||
|
||||
type bao struct {
|
||||
cl *http.Client
|
||||
token string
|
||||
}
|
||||
|
||||
func newBao(ca, cert, key string) (*bao, error) {
|
||||
tc, err := tlsConf(ca, cert, key, "openbao")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &bao{cl: &http.Client{Timeout: 10 * time.Second, Transport: &http.Transport{TLSClientConfig: tc}}}, nil
|
||||
}
|
||||
|
||||
func (b *bao) do(method, path string, body any) (int, map[string]any, error) {
|
||||
var rd io.Reader
|
||||
if body != nil {
|
||||
j, _ := json.Marshal(body)
|
||||
rd = bytes.NewReader(j)
|
||||
}
|
||||
req, _ := http.NewRequest(method, "https://openbao:8200"+path, rd)
|
||||
if b.token != "" {
|
||||
req.Header.Set("X-Vault-Token", b.token)
|
||||
}
|
||||
resp, err := b.cl.Do(req)
|
||||
if err != nil {
|
||||
return 0, nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
var m map[string]any
|
||||
_ = json.NewDecoder(resp.Body).Decode(&m)
|
||||
return resp.StatusCode, m, nil
|
||||
}
|
||||
|
||||
func (b *bao) login(role string) error {
|
||||
code, m, err := b.do("POST", "/v1/auth/cert/login", map[string]any{"name": role})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if code != 200 {
|
||||
return fmt.Errorf("login %d", code)
|
||||
}
|
||||
b.token, _ = m["auth"].(map[string]any)["client_token"].(string)
|
||||
return nil
|
||||
}
|
||||
|
||||
func verdictHTTP(code int, err error) string {
|
||||
switch {
|
||||
case err != nil:
|
||||
return "error: " + short(err)
|
||||
case code == 200 || code == 204:
|
||||
return "allowed"
|
||||
case code == 403:
|
||||
return "denied (403)"
|
||||
case code == 404:
|
||||
return "not found (404)"
|
||||
}
|
||||
return fmt.Sprintf("status %d", code)
|
||||
}
|
||||
|
||||
func probeBao(ca, cert, key, role, path string) result {
|
||||
b, err := newBao(ca, cert, key)
|
||||
if err != nil {
|
||||
return result{"login": "error: " + err.Error()}
|
||||
}
|
||||
if err := b.login(role); err != nil {
|
||||
return result{"login": "denied: " + short(err)}
|
||||
}
|
||||
res := result{"login": "allowed"}
|
||||
code, _, err := b.do("GET", "/v1/secret/data/"+path, nil)
|
||||
res["read own "+path] = verdictHTTP(code, err)
|
||||
for _, other := range []string{"messenger/api", "messenger/worker", "messenger/relay", "messenger/reconciler"} {
|
||||
if other == path {
|
||||
continue
|
||||
}
|
||||
code, _, err := b.do("GET", "/v1/secret/data/"+other, nil)
|
||||
res["read "+other] = verdictHTTP(code, err)
|
||||
}
|
||||
code, _, err = b.do("POST", "/v1/secret/data/"+path, map[string]any{"data": map[string]string{"x": "y"}})
|
||||
res["write own secret"] = verdictHTTP(code, err)
|
||||
code, _, err = b.do("LIST", "/v1/secret/metadata/messenger", nil)
|
||||
res["list secrets"] = verdictHTTP(code, err)
|
||||
code, _, err = b.do("PUT", "/v1/sys/policies/acl/evil", map[string]any{"policy": `path "*" { capabilities = ["sudo","read"] }`})
|
||||
res["write policy"] = verdictHTTP(code, err)
|
||||
code, _, err = b.do("POST", "/v1/auth/token/create", map[string]any{"policies": []string{"messenger-api"}})
|
||||
res["create token with other policy"] = verdictHTTP(code, err)
|
||||
code, _, err = b.do("PUT", "/v1/sys/seal", nil)
|
||||
res["seal openbao"] = verdictHTTP(code, err)
|
||||
return res
|
||||
}
|
||||
|
||||
// ---------------- полная модель компрометации сервиса ----------------
|
||||
|
||||
func compromise(ctx context.Context, ca, cert, key, otelCert, otelKey, role, path string) result {
|
||||
res := result{"identity_cert": cert}
|
||||
res["openbao"] = probeBao(ca, cert, key, role, path)
|
||||
b, err := newBao(ca, cert, key)
|
||||
if err == nil {
|
||||
err = b.login(role)
|
||||
}
|
||||
if err != nil {
|
||||
res["stolen_secrets"] = "none: openbao login denied (" + short(err) + ")"
|
||||
} else {
|
||||
code, m, err := b.do("GET", "/v1/secret/data/"+path, nil)
|
||||
if err != nil || code != 200 {
|
||||
res["stolen_secrets"] = fmt.Sprintf("none: read %d", code)
|
||||
} else {
|
||||
d, _ := m["data"].(map[string]any)["data"].(map[string]any)
|
||||
keys := []string{}
|
||||
for k := range d {
|
||||
keys = append(keys, k)
|
||||
}
|
||||
res["stolen_secrets"] = keys // только имена
|
||||
str := func(k string) string { s, _ := d[k].(string); return s }
|
||||
res["db"] = probeDB(ctx, ca, str("db_user"), str("db_password"), "verify-full")
|
||||
res["s3"] = probeS3(ctx, ca, str("s3_access_key"), str("s3_secret_key"))
|
||||
}
|
||||
}
|
||||
res["amqp"] = probeAMQP(ca, cert, key)
|
||||
if otelCert != "" {
|
||||
res["otlp"] = probeOTLP(ca, otelCert, otelKey)
|
||||
}
|
||||
res["api_as_lb"] = probeTLS("api:8443", "api", ca, cert, key, "/api/v1/users/me", "")
|
||||
return res
|
||||
}
|
||||
+663
@@ -0,0 +1,663 @@
|
||||
# Lab7 — защищённый мессенджер. Карта доверия: contracts/trust-matrix.md, угрозы: security/THREAT_MODEL.md.
|
||||
#
|
||||
# клиент ─TLS(:8443, CA стенда)→ lb ─mTLS(identity lb)→ api × 2
|
||||
# api / relay / worker / reconciler:
|
||||
# ─TLS verify-full + своя роль БД→ postgres ─TLS + ACL user→ redis (только api)
|
||||
# ─TLS + свой ключ/префиксы→ s3 (MinIO) ─mTLS, SASL EXTERNAL (CN)→ rabbitmq (relay, worker)
|
||||
# ─mTLS (CA телеметрии)→ otel-collector ─mTLS→ tempo / loki; prometheus ─mTLS→ collector
|
||||
# ─TLS + cert auth (тот же сертификат сервиса)→ openbao: роль/ключи БД, S3, Redis
|
||||
# grafana ─mTLS→ prometheus / loki / tempo; оператор → grafana (HTTPS, 127.0.0.1:3000)
|
||||
#
|
||||
# Секреты и ключи создаёт оператор (scripts/bootstrap.py → secrets/, вне Git); в образах их нет.
|
||||
# Запуск из чистого clone: python3 scripts/bootstrap.py all
|
||||
name: mtusi2026lab7
|
||||
|
||||
x-hardened: &hardened
|
||||
# Процессы приложения: non-root (uid 1001 образа), без capabilities, без повышения
|
||||
# привилегий, корневая ФС только чтение; запись — в ограниченный tmpfs /tmp.
|
||||
read_only: true
|
||||
cap_drop: [ALL]
|
||||
security_opt: [no-new-privileges:true]
|
||||
tmpfs:
|
||||
- /tmp:size=64m,mode=1777
|
||||
|
||||
x-app-env: &app-env
|
||||
APP_HOST: 0.0.0.0
|
||||
APP_PORT: "8443"
|
||||
APP_ENV: ${APP_ENV:-lab}
|
||||
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
|
||||
SESSION_STORE: redis
|
||||
IDEMPOTENCY_TTL_SECONDS: ${IDEMPOTENCY_TTL_SECONDS:-86400}
|
||||
DRAIN_DELAY: ${DRAIN_DELAY:-3s}
|
||||
SHUTDOWN_TIMEOUT: ${SHUTDOWN_TIMEOUT:-8s}
|
||||
DB_POOL_MAX: ${DB_POOL_MAX:-20}
|
||||
CACHE_INVALIDATION: ${CACHE_INVALIDATION:-version}
|
||||
S3_ENDPOINT: https://s3:9000
|
||||
S3_REGION: ${S3_REGION:-us-east-1}
|
||||
S3_BUCKET: ${S3_BUCKET:-messenger-attachments}
|
||||
MAX_UPLOAD_BYTES: ${MAX_UPLOAD_BYTES:-10485760}
|
||||
MAX_IMAGE_PIXELS: ${MAX_IMAGE_PIXELS:-40000000}
|
||||
PIPELINE_VERSION: ${PIPELINE_VERSION:-1}
|
||||
JOB_MAX_ATTEMPTS: ${JOB_MAX_ATTEMPTS:-5}
|
||||
JOB_TIMEOUT_SECONDS: ${JOB_TIMEOUT_SECONDS:-60}
|
||||
WORKER_CONCURRENCY: ${WORKER_CONCURRENCY:-2}
|
||||
STAGING_RETENTION_SECONDS: ${STAGING_RETENTION_SECONDS:-86400}
|
||||
WEBP_QUALITY: ${WEBP_QUALITY:-80}
|
||||
WORKER_PIXEL_BUDGET: ${WORKER_PIXEL_BUDGET:-60000000}
|
||||
RETRY_BASE_DELAY: ${RETRY_BASE_DELAY:-2s}
|
||||
RETRY_MAX_DELAY: ${RETRY_MAX_DELAY:-60s}
|
||||
# TLS: CA стенда и сертификат сервиса (у каждого сервиса свой, под одинаковыми именами)
|
||||
TLS_CA_FILE: /run/secrets/ca.crt
|
||||
TLS_CERT_FILE: /run/secrets/service.crt
|
||||
TLS_KEY_FILE: /run/secrets/service.key
|
||||
# PostgreSQL: адрес; роль и пароль — из OpenBao (secret/messenger/<сервис>)
|
||||
DATABASE_HOST: postgres
|
||||
DATABASE_NAME: messenger
|
||||
REDIS_ADDR: redis:6379
|
||||
BROKER_URL: amqps://rabbitmq:5671/
|
||||
# OpenBao: cert auth тем же сертификатом сервиса, без статического токена
|
||||
BAO_ADDR: https://openbao:8200
|
||||
BAO_CACERT: /run/secrets/ca.crt
|
||||
SECRETS_REFRESH: ${SECRETS_REFRESH:-30s}
|
||||
# Argon2id (обоснование — REPORT.md, замер на стенде)
|
||||
ARGON2_MEMORY_KIB: ${ARGON2_MEMORY_KIB:-19456}
|
||||
ARGON2_ITERATIONS: ${ARGON2_ITERATIONS:-2}
|
||||
ARGON2_PARALLELISM: ${ARGON2_PARALLELISM:-1}
|
||||
ARGON2_MAX_CONCURRENT: ${ARGON2_MAX_CONCURRENT:-2}
|
||||
LOGIN_RATE_PER_USER: ${LOGIN_RATE_PER_USER:-10}
|
||||
LOGIN_RATE_PER_IP: ${LOGIN_RATE_PER_IP:-60}
|
||||
LOGIN_RATE_WINDOW_SECONDS: ${LOGIN_RATE_WINDOW_SECONDS:-60}
|
||||
# OpenTelemetry: HTTPS к Collector, клиентский сертификат CA телеметрии
|
||||
OTEL_EXPORTER_OTLP_ENDPOINT: https://otel-collector:4318
|
||||
OTEL_EXPORTER_OTLP_PROTOCOL: http/protobuf
|
||||
OTEL_EXPORTER_OTLP_CERTIFICATE: /run/secrets/ca.crt
|
||||
OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATE: /run/secrets/otel.crt
|
||||
OTEL_EXPORTER_OTLP_CLIENT_KEY: /run/secrets/otel.key
|
||||
OTEL_RESOURCE_ATTRIBUTES: deployment.environment.name=lab
|
||||
OTEL_TRACES_SAMPLER: ${OTEL_TRACES_SAMPLER:-parentbased_always_on}
|
||||
OTEL_TRACES_SAMPLER_ARG: ${OTEL_TRACES_SAMPLER_ARG:-1.0}
|
||||
|
||||
services:
|
||||
lb:
|
||||
image: haproxy:3.0.5-alpine
|
||||
<<: *hardened
|
||||
ports:
|
||||
- "127.0.0.1:${LB_PORT:-8443}:8443" # единственный публичный вход, только TLS
|
||||
environment:
|
||||
LB_BALANCE: ${LB_BALANCE:-roundrobin}
|
||||
volumes:
|
||||
- ./infra/haproxy/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro
|
||||
secrets:
|
||||
- { source: ca_crt, target: ca.crt }
|
||||
- { source: lb_public_pem, target: lb-public.pem }
|
||||
- { source: lb_pem, target: lb.pem }
|
||||
depends_on:
|
||||
api:
|
||||
condition: service_healthy
|
||||
restart: unless-stopped
|
||||
networks: [front]
|
||||
deploy:
|
||||
resources:
|
||||
limits: { cpus: "0.50", memory: 128M, pids: 256 }
|
||||
|
||||
api:
|
||||
build: .
|
||||
image: mtusi2026lab7-api:local
|
||||
<<: *hardened
|
||||
environment:
|
||||
<<: *app-env
|
||||
OTEL_SERVICE_NAME: messenger-api
|
||||
BAO_ROLE: api
|
||||
BAO_KV_PATH: messenger/api
|
||||
API_ALLOWED_CLIENTS: lb
|
||||
REVOKED_SERIALS_FILE: /run/secrets/revoked.txt
|
||||
secrets:
|
||||
- { source: ca_crt, target: ca.crt }
|
||||
- { source: revoked_serials, target: revoked.txt }
|
||||
- { source: api_crt, target: service.crt }
|
||||
- { source: api_key, target: service.key }
|
||||
- { source: api_otel_crt, target: otel.crt }
|
||||
- { source: api_otel_key, target: otel.key }
|
||||
depends_on:
|
||||
postgres: { condition: service_healthy }
|
||||
redis: { condition: service_healthy }
|
||||
openbao: { condition: service_started }
|
||||
healthcheck:
|
||||
test: ["CMD", "wget", "--spider", "-q", "http://127.0.0.1:8081/health/ready"]
|
||||
interval: 5s
|
||||
timeout: 2s
|
||||
retries: 3
|
||||
start_period: 20s
|
||||
stop_grace_period: 15s
|
||||
restart: unless-stopped
|
||||
networks: [front, back, telemetry]
|
||||
deploy:
|
||||
replicas: ${API_REPLICAS:-2}
|
||||
resources:
|
||||
limits: { cpus: "${API_CPUS:-0.50}", memory: "${API_MEMORY:-256M}", pids: 256 }
|
||||
|
||||
# Миграции — инструмент оператора: владелец схемы messenger, TLS verify-full.
|
||||
migrate:
|
||||
image: migrate/migrate:v4.17.0
|
||||
volumes:
|
||||
- ./migrations:/migrations:ro
|
||||
secrets:
|
||||
- { source: ca_crt, target: ca.crt }
|
||||
- database_url
|
||||
entrypoint: ["/bin/sh", "-c", "exec migrate -path /migrations -database \"$$(cat /run/secrets/database_url)\" up"]
|
||||
read_only: true
|
||||
cap_drop: [ALL]
|
||||
security_opt: [no-new-privileges:true]
|
||||
depends_on:
|
||||
postgres: { condition: service_healthy }
|
||||
restart: "no"
|
||||
profiles: [ops]
|
||||
networks: [back]
|
||||
|
||||
# PostgreSQL: TLS (ключ копируется в каталог postgres с правами 600 — требование PostgreSQL),
|
||||
# pg_hba: сетевой доступ только hostssl + scram. Stateful-исключение из read_only: entrypoint
|
||||
# образа делает chown/su-exec, поэтому оставлены нужные для этого capabilities.
|
||||
postgres:
|
||||
image: postgres:16.4-alpine
|
||||
entrypoint: ["sh", "-c"]
|
||||
command:
|
||||
- >-
|
||||
install -o postgres -g postgres -m 600 /run/secrets/postgres.key /var/lib/postgresql/server.key &&
|
||||
install -o postgres -g postgres -m 644 /run/secrets/postgres.crt /var/lib/postgresql/server.crt &&
|
||||
exec docker-entrypoint.sh postgres -c max_connections=100 -c ssl=on
|
||||
-c ssl_cert_file=/var/lib/postgresql/server.crt -c ssl_key_file=/var/lib/postgresql/server.key
|
||||
-c ssl_min_protocol_version=TLSv1.2 -c hba_file=/etc/postgresql/pg_hba.conf -c password_encryption=scram-sha-256
|
||||
environment:
|
||||
POSTGRES_USER: messenger
|
||||
POSTGRES_PASSWORD_FILE: /run/secrets/postgres_password
|
||||
POSTGRES_DB: messenger
|
||||
secrets:
|
||||
- postgres_password
|
||||
- { source: postgres_crt, target: postgres.crt }
|
||||
- { source: postgres_key, target: postgres.key }
|
||||
volumes:
|
||||
- pg_data:/var/lib/postgresql/data
|
||||
- ./infra/postgres/pg_hba.conf:/etc/postgresql/pg_hba.conf:ro
|
||||
cap_drop: [ALL]
|
||||
cap_add: [CHOWN, DAC_OVERRIDE, FOWNER, SETUID, SETGID]
|
||||
security_opt: [no-new-privileges:true]
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -U messenger -d messenger"]
|
||||
interval: 5s
|
||||
timeout: 3s
|
||||
retries: 10
|
||||
restart: unless-stopped
|
||||
networks: [back]
|
||||
deploy:
|
||||
resources:
|
||||
limits: { cpus: "1.00", memory: 512M, pids: 512 }
|
||||
|
||||
# Redis: только TLS (plaintext-порт 0), ACL из файла оператора (пароли — SHA-256),
|
||||
# пользователь default выключен.
|
||||
redis:
|
||||
image: redis:7.4.1-alpine
|
||||
command:
|
||||
- redis-server
|
||||
- --port
|
||||
- "0"
|
||||
- --tls-port
|
||||
- "6379"
|
||||
- --tls-cert-file
|
||||
- /run/secrets/redis.crt
|
||||
- --tls-key-file
|
||||
- /run/secrets/redis.key
|
||||
- --tls-ca-cert-file
|
||||
- /run/secrets/ca.crt
|
||||
- --tls-auth-clients
|
||||
- "no"
|
||||
- --aclfile
|
||||
- /run/secrets/redis_users.acl
|
||||
- --appendonly
|
||||
- "yes"
|
||||
- --appendfsync
|
||||
- everysec
|
||||
secrets:
|
||||
- { source: ca_crt, target: ca.crt }
|
||||
- { source: redis_crt, target: redis.crt }
|
||||
- { source: redis_key, target: redis.key }
|
||||
- redis_users.acl
|
||||
volumes:
|
||||
- redis_data:/data
|
||||
cap_drop: [ALL]
|
||||
cap_add: [CHOWN, SETUID, SETGID, DAC_OVERRIDE]
|
||||
security_opt: [no-new-privileges:true]
|
||||
healthcheck:
|
||||
test: ["CMD", "redis-cli", "--tls", "--cacert", "/run/secrets/ca.crt", "-h", "redis", "--user", "healthcheck", "--pass", "x", "--no-auth-warning", "ping"]
|
||||
interval: 5s
|
||||
timeout: 3s
|
||||
retries: 10
|
||||
restart: unless-stopped
|
||||
networks: [back]
|
||||
deploy:
|
||||
resources:
|
||||
limits: { cpus: "0.50", memory: 256M, pids: 256 }
|
||||
|
||||
# MinIO RELEASE.2025-04-22 (Bitnami, по digest): только HTTPS, консоль выключена, порты не публикуются.
|
||||
s3:
|
||||
image: bitnamilegacy/minio:2025.4.22@sha256:50cec18ac4184af4671a78aedd5554942c8ae105d51a465fa82037949046da01
|
||||
entrypoint: ["/bin/bash", "-c"]
|
||||
command:
|
||||
- >-
|
||||
mkdir -p /tmp/certs/CAs && cp /run/secrets/s3.crt /tmp/certs/public.crt && cp /run/secrets/s3.key /tmp/certs/private.key &&
|
||||
cp /run/secrets/ca.crt /tmp/certs/CAs/ca.crt &&
|
||||
export MINIO_ROOT_USER="$$(cat /run/secrets/s3_root_user)" MINIO_ROOT_PASSWORD="$$(cat /run/secrets/s3_root_password)";
|
||||
exec /opt/bitnami/minio/bin/minio server /bitnami/minio/data --address :9000 --certs-dir /tmp/certs
|
||||
environment:
|
||||
MINIO_BROWSER: "off"
|
||||
secrets:
|
||||
- s3_root_user
|
||||
- s3_root_password
|
||||
- { source: ca_crt, target: ca.crt }
|
||||
- { source: s3_crt, target: s3.crt }
|
||||
- { source: s3_key, target: s3.key }
|
||||
volumes:
|
||||
- s3_data:/bitnami/minio/data
|
||||
<<: *hardened
|
||||
healthcheck:
|
||||
test: ["CMD", "bash", "-c", "exec 3<>/dev/tcp/127.0.0.1/9000"]
|
||||
interval: 5s
|
||||
timeout: 3s
|
||||
retries: 20
|
||||
restart: unless-stopped
|
||||
networks: [back]
|
||||
deploy:
|
||||
resources:
|
||||
limits: { cpus: "0.50", memory: 512M, pids: 256 }
|
||||
|
||||
# Bootstrap MinIO (запускает scripts/bootstrap.py): bucket, политики по префиксам, пользователи сервисов.
|
||||
s3-init:
|
||||
image: bitnamilegacy/minio-client:2025.4.16@sha256:8a86e441decf053093c5977d49290298295f850c7843652f93e970ab15871dd1
|
||||
entrypoint: ["/bin/sh", "/init/init.sh"]
|
||||
environment:
|
||||
S3_BUCKET: ${S3_BUCKET:-messenger-attachments}
|
||||
PATH: /opt/bitnami/minio-client/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
||||
MC_CONFIG_DIR: /tmp/.mc
|
||||
secrets:
|
||||
- s3_root_user
|
||||
- s3_root_password
|
||||
- s3_users
|
||||
- { source: ca_crt, target: ca.crt }
|
||||
volumes:
|
||||
- ./infra/s3:/init:ro
|
||||
<<: *hardened
|
||||
depends_on:
|
||||
s3: { condition: service_healthy }
|
||||
restart: "no"
|
||||
profiles: [ops]
|
||||
networks: [back]
|
||||
|
||||
reconciler:
|
||||
image: mtusi2026lab7-api:local
|
||||
<<: *hardened
|
||||
entrypoint: ["/app/reconcile", "--apply", "--interval", "${RECONCILE_INTERVAL:-10m}", "--grace", "${RECONCILE_GRACE:-1h}"]
|
||||
environment:
|
||||
<<: *app-env
|
||||
BAO_ROLE: reconciler
|
||||
BAO_KV_PATH: messenger/reconciler
|
||||
secrets:
|
||||
- { source: ca_crt, target: ca.crt }
|
||||
- { source: reconciler_crt, target: service.crt }
|
||||
- { source: reconciler_key, target: service.key }
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pgrep -x reconcile >/dev/null || pidof reconcile >/dev/null"]
|
||||
interval: 10s
|
||||
timeout: 3s
|
||||
retries: 3
|
||||
start_period: 5s
|
||||
depends_on:
|
||||
postgres: { condition: service_healthy }
|
||||
openbao: { condition: service_started }
|
||||
restart: unless-stopped
|
||||
networks: [back]
|
||||
deploy:
|
||||
resources:
|
||||
limits: { cpus: "0.25", memory: 128M, pids: 128 }
|
||||
|
||||
# RabbitMQ: только AMQPS (5671) с обязательным клиентским сертификатом, SASL EXTERNAL.
|
||||
rabbitmq:
|
||||
image: rabbitmq:4.0.9-alpine
|
||||
hostname: rabbitmq
|
||||
volumes:
|
||||
- rabbitmq_data:/var/lib/rabbitmq
|
||||
- ./infra/rabbitmq/rabbitmq.conf:/etc/rabbitmq/conf.d/30-lab7.conf:ro
|
||||
- ./infra/rabbitmq/enabled_plugins:/etc/rabbitmq/enabled_plugins:ro
|
||||
- ./infra/rabbitmq/definitions.json:/etc/rabbitmq/lab7-definitions.json:ro
|
||||
secrets:
|
||||
- { source: ca_crt, target: ca.crt }
|
||||
- { source: rabbitmq_crt, target: rabbitmq.crt }
|
||||
- { source: rabbitmq_key, target: rabbitmq.key }
|
||||
cap_drop: [ALL]
|
||||
cap_add: [CHOWN, DAC_OVERRIDE, FOWNER, SETUID, SETGID]
|
||||
security_opt: [no-new-privileges:true]
|
||||
healthcheck:
|
||||
test: ["CMD", "rabbitmq-diagnostics", "-q", "check_port_connectivity"]
|
||||
interval: 5s
|
||||
timeout: 10s
|
||||
retries: 30
|
||||
start_period: 15s
|
||||
restart: unless-stopped
|
||||
networks: [back, telemetry]
|
||||
deploy:
|
||||
resources:
|
||||
limits: { cpus: "0.50", memory: 512M, pids: 512 }
|
||||
|
||||
relay:
|
||||
image: mtusi2026lab7-api:local
|
||||
<<: *hardened
|
||||
volumes:
|
||||
- fault_state:/var/lib/messenger/fault
|
||||
entrypoint: ["/app/pipeline", "relay"]
|
||||
environment:
|
||||
<<: *app-env
|
||||
OTEL_SERVICE_NAME: messenger-relay
|
||||
BAO_ROLE: relay
|
||||
BAO_KV_PATH: messenger/relay
|
||||
BROKER_DECLARE: "false" # топология — у оператора (definitions.json)
|
||||
FAULT_POINTS: ${RELAY_FAULT_POINTS:-}
|
||||
FAULT_DIR: /var/lib/messenger/fault
|
||||
secrets:
|
||||
- { source: ca_crt, target: ca.crt }
|
||||
- { source: relay_crt, target: service.crt }
|
||||
- { source: relay_key, target: service.key }
|
||||
- { source: relay_otel_crt, target: otel.crt }
|
||||
- { source: relay_otel_key, target: otel.key }
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pgrep -x pipeline >/dev/null || pidof pipeline >/dev/null"]
|
||||
interval: 10s
|
||||
timeout: 3s
|
||||
retries: 3
|
||||
start_period: 5s
|
||||
depends_on:
|
||||
postgres: { condition: service_healthy }
|
||||
rabbitmq: { condition: service_healthy }
|
||||
openbao: { condition: service_started }
|
||||
restart: unless-stopped
|
||||
networks: [back, telemetry]
|
||||
deploy:
|
||||
resources:
|
||||
limits: { cpus: "0.25", memory: 128M, pids: 128 }
|
||||
|
||||
# Worker: отдельная identity (CN worker-gN): своя роль БД, ключ S3 только s/ v/ o/,
|
||||
# в RabbitMQ — только чтение attachment.process. CPU/RAM/время ограничены.
|
||||
worker:
|
||||
image: mtusi2026lab7-api:local
|
||||
<<: *hardened
|
||||
tmpfs:
|
||||
- /tmp:size=256m,mode=1777 # cwebp: временный PNG/WebP одного изображения
|
||||
volumes:
|
||||
- fault_state:/var/lib/messenger/fault # маркеры точек сбоя (тесты; tmpfs очищается при restart)
|
||||
entrypoint: ["/app/pipeline", "worker"]
|
||||
environment:
|
||||
<<: *app-env
|
||||
OTEL_SERVICE_NAME: messenger-worker
|
||||
BAO_ROLE: worker
|
||||
BAO_KV_PATH: messenger/worker
|
||||
BROKER_DECLARE: "false"
|
||||
FAULT_POINTS: ${WORKER_FAULT_POINTS:-}
|
||||
FAULT_DIR: /var/lib/messenger/fault
|
||||
GOMEMLIMIT: ${WORKER_GOMEMLIMIT:-560MiB}
|
||||
secrets:
|
||||
- { source: ca_crt, target: ca.crt }
|
||||
- { source: worker_crt, target: service.crt }
|
||||
- { source: worker_key, target: service.key }
|
||||
- { source: worker_otel_crt, target: otel.crt }
|
||||
- { source: worker_otel_key, target: otel.key }
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pgrep -x pipeline >/dev/null || pidof pipeline >/dev/null"]
|
||||
interval: 10s
|
||||
timeout: 3s
|
||||
retries: 3
|
||||
start_period: 5s
|
||||
stop_grace_period: 70s
|
||||
depends_on:
|
||||
postgres: { condition: service_healthy }
|
||||
rabbitmq: { condition: service_healthy }
|
||||
openbao: { condition: service_started }
|
||||
restart: unless-stopped
|
||||
networks: [back, telemetry]
|
||||
deploy:
|
||||
replicas: ${WORKER_REPLICAS:-1}
|
||||
resources:
|
||||
limits: { cpus: "${WORKER_CPUS:-1.00}", memory: "${WORKER_MEMORY:-768M}", pids: 128 }
|
||||
|
||||
# OpenBao: не dev-mode, файловое хранилище на volume, TLS. Init/unseal — оператор
|
||||
# (scripts/bootstrap.py); после рестарта OpenBao запечатан до unseal, приложения
|
||||
# продолжают работать на полученных ранее секретах.
|
||||
openbao:
|
||||
image: openbao/openbao:2.1.0
|
||||
# Конфиг вне /openbao/config: entrypoint образа сам добавляет -config=/openbao/config,
|
||||
# и тот же файл, загруженный дважды, дал бы два listener на одном порту.
|
||||
command: ["server", "-config=/openbao/lab7/config.hcl"]
|
||||
environment:
|
||||
SKIP_SETCAP: "true"
|
||||
volumes:
|
||||
- ./infra/openbao/config.hcl:/openbao/lab7/config.hcl:ro
|
||||
- ./infra/openbao/policies:/openbao/policies:ro
|
||||
- bao_data:/openbao/file
|
||||
secrets:
|
||||
- { source: ca_crt, target: ca.crt }
|
||||
- { source: openbao_crt, target: openbao.crt }
|
||||
- { source: openbao_key, target: openbao.key }
|
||||
cap_drop: [ALL]
|
||||
cap_add: [CHOWN, DAC_OVERRIDE, FOWNER, SETUID, SETGID]
|
||||
security_opt: [no-new-privileges:true]
|
||||
ports:
|
||||
- "127.0.0.1:${BAO_PORT:-8200}:8200" # только оператору на хосте, TLS
|
||||
restart: unless-stopped
|
||||
networks: [back]
|
||||
deploy:
|
||||
resources:
|
||||
limits: { cpus: "0.50", memory: 256M, pids: 256 }
|
||||
|
||||
# ---------------- Наблюдаемость (lab6), всё по TLS/mTLS ----------------
|
||||
otel-collector:
|
||||
image: otel/opentelemetry-collector-contrib:0.116.1
|
||||
<<: *hardened
|
||||
command: ["--config=/etc/otelcol/${COLLECTOR_CONFIG:-collector.yaml}"]
|
||||
volumes:
|
||||
- ./infra/otel:/etc/otelcol:ro
|
||||
secrets:
|
||||
- { source: ca_crt, target: ca.crt }
|
||||
- { source: tca_crt, target: tca.crt }
|
||||
- { source: otel_collector_crt, target: otel-collector.crt }
|
||||
- { source: otel_collector_key, target: otel-collector.key }
|
||||
restart: unless-stopped
|
||||
networks: [telemetry]
|
||||
deploy:
|
||||
resources:
|
||||
limits: { cpus: "0.50", memory: 256M, pids: 256 }
|
||||
|
||||
prometheus:
|
||||
image: prom/prometheus:v3.1.0
|
||||
<<: *hardened
|
||||
command:
|
||||
- --config.file=/etc/prometheus/prometheus.yml
|
||||
- --web.config.file=/etc/prometheus/web.yml
|
||||
- --storage.tsdb.path=/prometheus
|
||||
- --storage.tsdb.retention.time=7d
|
||||
- --enable-feature=exemplar-storage
|
||||
volumes:
|
||||
- ./infra/prometheus:/etc/prometheus:ro
|
||||
- prometheus_data:/prometheus
|
||||
secrets:
|
||||
- { source: ca_crt, target: ca.crt }
|
||||
- { source: prometheus_crt, target: prometheus.crt }
|
||||
- { source: prometheus_key, target: prometheus.key }
|
||||
restart: unless-stopped
|
||||
networks: [telemetry]
|
||||
deploy:
|
||||
resources:
|
||||
limits: { cpus: "0.50", memory: 512M, pids: 256 }
|
||||
|
||||
loki:
|
||||
image: grafana/loki:3.3.2
|
||||
<<: *hardened
|
||||
command: ["-config.file=/etc/loki/loki.yaml"]
|
||||
volumes:
|
||||
- ./infra/loki/loki.yaml:/etc/loki/loki.yaml:ro
|
||||
- loki_data:/loki
|
||||
secrets:
|
||||
- { source: ca_crt, target: ca.crt }
|
||||
- { source: loki_crt, target: loki.crt }
|
||||
- { source: loki_key, target: loki.key }
|
||||
restart: unless-stopped
|
||||
networks: [telemetry]
|
||||
deploy:
|
||||
resources:
|
||||
limits: { cpus: "0.50", memory: 1G, pids: 256 }
|
||||
|
||||
tempo-init:
|
||||
image: &tempo-image grafana/tempo:2.6.1
|
||||
user: root
|
||||
entrypoint: ["chown", "10001:10001", "/var/tempo"]
|
||||
cap_drop: [ALL]
|
||||
cap_add: [CHOWN]
|
||||
security_opt: [no-new-privileges:true]
|
||||
volumes:
|
||||
- tempo_data:/var/tempo
|
||||
restart: "no"
|
||||
networks: [telemetry]
|
||||
tempo:
|
||||
image: *tempo-image
|
||||
<<: *hardened
|
||||
command: ["-config.file=/etc/tempo/tempo.yaml"]
|
||||
volumes:
|
||||
- ./infra/tempo/tempo.yaml:/etc/tempo/tempo.yaml:ro
|
||||
- tempo_data:/var/tempo
|
||||
secrets:
|
||||
- { source: ca_crt, target: ca.crt }
|
||||
- { source: tempo_crt, target: tempo.crt }
|
||||
- { source: tempo_key, target: tempo.key }
|
||||
depends_on:
|
||||
tempo-init: { condition: service_completed_successfully }
|
||||
restart: unless-stopped
|
||||
networks: [telemetry]
|
||||
deploy:
|
||||
resources:
|
||||
limits: { cpus: "0.50", memory: 1G, pids: 256 }
|
||||
|
||||
grafana:
|
||||
image: grafana/grafana:11.4.0
|
||||
cap_drop: [ALL]
|
||||
security_opt: [no-new-privileges:true]
|
||||
environment:
|
||||
GF_SERVER_PROTOCOL: https
|
||||
GF_SERVER_CERT_FILE: /run/secrets/grafana.crt
|
||||
GF_SERVER_CERT_KEY: /run/secrets/grafana.key
|
||||
GF_SECURITY_ADMIN_USER: admin
|
||||
GF_SECURITY_ADMIN_PASSWORD__FILE: /run/secrets/grafana_admin_password
|
||||
GF_USERS_ALLOW_SIGN_UP: "false"
|
||||
GF_ANALYTICS_REPORTING_ENABLED: "false"
|
||||
GF_ANALYTICS_CHECK_FOR_UPDATES: "false"
|
||||
GF_AUTH_ANONYMOUS_ENABLED: "false"
|
||||
secrets:
|
||||
- grafana_admin_password
|
||||
- { source: ca_crt, target: ca.crt }
|
||||
- { source: grafana_crt, target: grafana.crt }
|
||||
- { source: grafana_key, target: grafana.key }
|
||||
volumes:
|
||||
- ./infra/grafana/provisioning:/etc/grafana/provisioning:ro
|
||||
- ./infra/grafana/dashboards:/var/lib/grafana/dashboards:ro
|
||||
- grafana_data:/var/lib/grafana
|
||||
ports:
|
||||
- "127.0.0.1:${GRAFANA_PORT:-3000}:3000" # оператор, HTTPS
|
||||
depends_on:
|
||||
prometheus: { condition: service_started }
|
||||
loki: { condition: service_started }
|
||||
tempo: { condition: service_started }
|
||||
healthcheck:
|
||||
test: ["CMD", "wget", "-q", "--spider", "--no-check-certificate", "https://localhost:3000/api/health"]
|
||||
interval: 5s
|
||||
timeout: 3s
|
||||
retries: 30
|
||||
restart: unless-stopped
|
||||
networks: [telemetry]
|
||||
deploy:
|
||||
resources:
|
||||
limits: { cpus: "0.50", memory: 256M, pids: 256 }
|
||||
|
||||
# Тестовый зонд отрицательных проверок (profile test): во всех сетях, сертификаты
|
||||
# стенда и тестовые (чужой CA, запрещённая identity) — только чтение.
|
||||
probe:
|
||||
build:
|
||||
context: .
|
||||
target: probe
|
||||
image: mtusi2026lab7-probe:local
|
||||
<<: *hardened
|
||||
user: "${PROBE_UID:-1001}" # каталог secrets/pki — 700 владельца стенда
|
||||
volumes:
|
||||
- ./secrets/pki:/pki:ro
|
||||
profiles: [test]
|
||||
networks: [front, back, telemetry]
|
||||
|
||||
networks:
|
||||
front:
|
||||
back:
|
||||
telemetry:
|
||||
|
||||
secrets:
|
||||
# оператор (scripts/init-secrets.sh, scripts/bootstrap.py) — значения вне Git
|
||||
postgres_password: { file: ./secrets/postgres_password }
|
||||
database_url: { file: ./secrets/database_url }
|
||||
s3_root_user: { file: ./secrets/s3_root_user }
|
||||
s3_root_password: { file: ./secrets/s3_root_password }
|
||||
grafana_admin_password: { file: ./secrets/grafana_admin_password }
|
||||
s3_users: { file: ./secrets/operator/s3_users.txt }
|
||||
redis_users.acl: { file: ./secrets/operator/redis_users.acl }
|
||||
# PKI (scripts/pki.sh): CA — только сертификаты; ключи CA в контейнеры не попадают
|
||||
ca_crt: { file: ./secrets/pki/ca.crt }
|
||||
tca_crt: { file: ./secrets/pki/tca.crt }
|
||||
revoked_serials: { file: ./secrets/pki/revoked.txt }
|
||||
lb_public_pem: { file: ./secrets/pki/lb-public.pem }
|
||||
lb_pem: { file: ./secrets/pki/lb.pem }
|
||||
api_crt: { file: ./secrets/pki/api.crt }
|
||||
api_key: { file: ./secrets/pki/api.key }
|
||||
api_otel_crt: { file: ./secrets/pki/api-otel.crt }
|
||||
api_otel_key: { file: ./secrets/pki/api-otel.key }
|
||||
worker_crt: { file: ./secrets/pki/worker.crt }
|
||||
worker_key: { file: ./secrets/pki/worker.key }
|
||||
worker_otel_crt: { file: ./secrets/pki/worker-otel.crt }
|
||||
worker_otel_key: { file: ./secrets/pki/worker-otel.key }
|
||||
relay_crt: { file: ./secrets/pki/relay.crt }
|
||||
relay_key: { file: ./secrets/pki/relay.key }
|
||||
relay_otel_crt: { file: ./secrets/pki/relay-otel.crt }
|
||||
relay_otel_key: { file: ./secrets/pki/relay-otel.key }
|
||||
reconciler_crt: { file: ./secrets/pki/reconciler.crt }
|
||||
reconciler_key: { file: ./secrets/pki/reconciler.key }
|
||||
postgres_crt: { file: ./secrets/pki/postgres.crt }
|
||||
postgres_key: { file: ./secrets/pki/postgres.key }
|
||||
redis_crt: { file: ./secrets/pki/redis.crt }
|
||||
redis_key: { file: ./secrets/pki/redis.key }
|
||||
s3_crt: { file: ./secrets/pki/s3.crt }
|
||||
s3_key: { file: ./secrets/pki/s3.key }
|
||||
rabbitmq_crt: { file: ./secrets/pki/rabbitmq.crt }
|
||||
rabbitmq_key: { file: ./secrets/pki/rabbitmq.key }
|
||||
openbao_crt: { file: ./secrets/pki/openbao.crt }
|
||||
openbao_key: { file: ./secrets/pki/openbao.key }
|
||||
otel_collector_crt: { file: ./secrets/pki/otel-collector.crt }
|
||||
otel_collector_key: { file: ./secrets/pki/otel-collector.key }
|
||||
prometheus_crt: { file: ./secrets/pki/prometheus.crt }
|
||||
prometheus_key: { file: ./secrets/pki/prometheus.key }
|
||||
loki_crt: { file: ./secrets/pki/loki.crt }
|
||||
loki_key: { file: ./secrets/pki/loki.key }
|
||||
tempo_crt: { file: ./secrets/pki/tempo.crt }
|
||||
tempo_key: { file: ./secrets/pki/tempo.key }
|
||||
grafana_crt: { file: ./secrets/pki/grafana.crt }
|
||||
grafana_key: { file: ./secrets/pki/grafana.key }
|
||||
|
||||
volumes:
|
||||
fault_state:
|
||||
bao_data:
|
||||
prometheus_data:
|
||||
loki_data:
|
||||
tempo_data:
|
||||
grafana_data:
|
||||
rabbitmq_data:
|
||||
s3_data:
|
||||
pg_data:
|
||||
redis_data:
|
||||
+31
-31
@@ -1,37 +1,37 @@
|
||||
# Матрица доверия — заполнить в решении lab7
|
||||
# Матрица доверия — решение lab7
|
||||
|
||||
Это обязательная матрица покрытия. Для каждой строки укажите реальный порт, endpoint, CA, service identity, проверку SAN/ACL, срок жизни credentials и команду положительного/отрицательного теста. TLS шифрует и подтверждает сервер; mTLS также проверяет клиента. При доверенном CA всё равно нужно ограничивать разрешённую identity. Plaintext hop допустим только внутри закрытого локального transport/proxy boundary, без опубликованного обхода; границу и rationale нужно доказать.
|
||||
TLS шифрует и подтверждает сервер; mTLS также проверяет клиента. Везде, где сервер доверяет CA, отдельно ограничена допустимая identity клиента (allowlist URI SAN / CN → пользователь / отдельный CA). Plaintext-связей между процессами нет: исключения (локальные health/metrics listener-ы) перечислены ниже и не дают доступа к бизнес-API или данным.
|
||||
|
||||
**PKI стенда** (`scripts/pki.sh`, ECDSA P-256, ключи — `secrets/pki`, вне Git):
|
||||
* `ca` — корневой CA стенда (10 лет). Ключ CA — только у оператора (`secrets/pki/ca.key`, 600), в контейнеры попадает лишь `ca.crt`.
|
||||
* `tca` — отдельный CA клиентов телеметрии: Collector принимает OTLP только с сертификатами этого CA.
|
||||
* leaf-сертификаты сервисов — 30 дней (`LEAF_DAYS`), identity `CN=<роль>` + `URI:spiffe://messenger/<роль>`; ротация — `scripts/pki.sh rotate <имя> [новый CN]` (перезапись на месте; старый serial — в `secrets/pki/revoked.txt`).
|
||||
* `rogue-ca`, `attacker` — только для отрицательных тестов (`secrets/pki/test`).
|
||||
|
||||
Отрицательные проверки — `student-tests/security_ops.py` (через тестовый контейнер `probe` с инструментом `cmd/secprobe`, которого нет в образе приложения), результаты — `evidence/security/*.json`.
|
||||
|
||||
| Связь | Минимум на 3 | Дополнительно на 4 | Доказательство / конфиг |
|
||||
| --- | --- | --- | --- |
|
||||
| Клиент → 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 |
|
||||
| Клиент → ingress/LB | HTTPS `127.0.0.1:8443`, TLS ≥ 1.2, сертификат `lb-public` (SAN localhost, 127.0.0.1) от CA стенда; Bearer-сессия (токен 256 бит, в Redis — SHA-256 токена, TTL `SESSION_TTL_SECONDS`) | Logout/expiry → 401; лимит входа общий для реплик (Redis): 10/мин на username, 60/мин на IP → 429 + Retry-After (слот резервируется до Argon2id, успешный вход его возвращает — считаются неудачные попытки); Argon2id не вычисляется при превышении | `infra/haproxy/haproxy.cfg`; `security_ops.py tls-external`, `acl`; `tests/security.py` |
|
||||
| LB → API (все реплики) | mTLS: HAProxy `ssl verify required ca-file ca.crt verifyhost api crt lb.pem`; API `RequireAndVerifyClientCert` + allowlist identity `spiffe://messenger/lb` (`API_ALLOWED_CLIENTS`). Порт API 8443 не опубликован, plaintext-порта нет | Ротация leaf `api` (перечитывается без рестарта) и `lb` (новый cert + reload HAProxy); старый `lb` отвергается по `revoked.txt` | `internal/tlsutil`, `cmd/api/main.go`; `security_ops.py mtls` (нет cert / чужой CA / identity attacker / identity worker → отказ, lb → 200), `rotation` |
|
||||
| API/worker → PostgreSQL | TLS `sslmode=verify-full` (CA стенда, имя `postgres`); `pg_hba`: только `hostssl … scram-sha-256`, `hostnossl … reject`. Роли: `app_api`, `app_worker`, `app_relay`, `app_reconciler` с минимальными GRANT (у worker нет `users`, `messages`, `chats`; UPDATE — по столбцам) | Пароль роли — в OpenBao; ротация `bootstrap.py rotate-db <svc>`: новые соединения берут новый пароль (BeforeConnect), старые закрываются (lifetime 10 мин или `pg_terminate_backend` при отзыве) | `migrations/0007_service_roles.up.sql`, `infra/postgres/pg_hba.conf`; `security_ops.py mtls` (sslmode=disable → отказ), `rotation` (старый пароль → отказ), `compromise.py` (матрица прав роли worker) |
|
||||
| API/worker → S3 | HTTPS (MinIO `--certs-dir`, CA стенда); пользователь на сервис: `svc-api` (PUT s/, GET o/ v/ a/ s/, DELETE s/), `svc-worker` (GET s/, PUT v/ o/, DELETE s/), `svc-relay` (DELETE s/), `svc-reconciler` (LIST, GET/DELETE — сверка) | Отказ по чужому префиксу (worker: PUT s/, GET o/, LIST → AccessDenied); ротация `bootstrap.py rotate-s3 <svc>` без рестарта (minio-go перечитывает ключ при смене версии KV) | `infra/s3/init.sh`; `compromise.py`, `security_ops.py rotation` |
|
||||
| API/worker → broker | AMQPS 5671, `listeners.tcp = none`; разные identities: relay = CN `relay-g1` (только write в exchange `attachments`), worker = CN `worker-g1` (только read `attachment.process`); configure нет ни у кого — топологию (quorum-очереди, DLX) создаёт оператор импортом `infra/rabbitmq/definitions.json` | mTLS обязателен (`fail_if_no_peer_cert`), SASL EXTERNAL: пользователь = CN; сертификат того же CA с CN `lb`/`attacker` → нет такого пользователя → отказ; паролей нет | `infra/rabbitmq/rabbitmq.conf`, `infra/rabbitmq/definitions.json`, `bootstrap.py rabbit_users`; `security_ops.py mtls` (матрица прав relay/worker) |
|
||||
| API/worker → Collector | OTLP/HTTPS 4318, сертификат Collector от CA стенда; ingest разрешён только с клиентским сертификатом CA телеметрии | Раздельные identities `api`/`worker`/`relay` (CN) в CA телеметрии; сертификат основного CA (lb, worker) → отказ | `infra/otel/collector.yaml`, `OTEL_EXPORTER_OTLP_*CERTIFICATE*`; `security_ops.py mtls` |
|
||||
| Collector → telemetry backends | mTLS: Collector → Tempo (gRPC 4317) и Loki (HTTPS 3100) с сертификатом `otel-collector`; Prometheus забирает метрики Collector (8889) по mTLS сертификатом `prometheus` | Backend-ы требуют клиентский сертификат CA стенда (без cert → отказ); ротация — `pki.sh rotate otel-collector` + перезапуск Collector | `infra/tempo/tempo.yaml`, `infra/loki/loki.yaml`, `infra/prometheus/prometheus.yml`; `security_ops.py mtls` (servers) |
|
||||
| Grafana → data sources | HTTPS к Prometheus/Loki/Tempo, проверка сервера (`tlsAuthWithCACert`, `serverName`), клиентский сертификат `grafana` | Без клиентского сертификата backend отказывает (проверено зондом) | `infra/grafana/provisioning/datasources/datasources.yaml`, `infra/prometheus/web.yml` |
|
||||
| API/worker/agent → OpenBao | HTTPS 8200 (CA стенда); auth/cert тем же сертификатом сервиса (роль = сервис, `allowed_common_names`); policy `messenger-<сервис>`: read только `secret/data/messenger/<сервис>` | Токен TTL 15 мин, renewable до 1 ч, затем повторный login; отзыв: `bootstrap.py revoke-tokens <svc>`, смена CN роли (`worker-identity g2`); sealed → процессы работают на кэше, новые не стартуют до unseal | `infra/openbao/*`, `internal/secrets`; `security_ops.py openbao`, `lifecycle`; `compromise.py` |
|
||||
| Оператор → OpenBao/Grafana/S3 admin | OpenBao и Grafana — только `127.0.0.1` хоста, HTTPS; Grafana — admin-пароль (secret); OpenBao — root token и доли unseal у оператора (`secrets/operator`, 600); MinIO admin — root-учётка только в `s3`/`s3-init` | Роли разделены: приложения не имеют root token, admin-доступа к MinIO/RabbitMQ/PostgreSQL; консоль MinIO выключена, management UI RabbitMQ не установлен | `compose.yaml` ports; `security_ops.py hardening`, `openbao` |
|
||||
| API → Redis | TLS 6379, `port 0` (plaintext выключен), ACL: `default off`, пользователь `api` (только ключи `session:*`, `messages:*`, `rl:*`, нужные команды), пароль — SHA-256 в ACL-файле, значение — в OpenBao | Ротация: новое значение в KV + перегенерация ACL-файла + `ACL LOAD`; mTLS не включён (сервер не требует клиентский сертификат — остаточное ограничение) | redis command в `compose.yaml`, `bootstrap.py write_backend_files`; `security_ops.py mtls` (plaintext PING без ответа) |
|
||||
| Replication/кластерные каналы | N/A: каждый компонент — один узел; RabbitMQ без кластера (Erlang distribution — внутри контейнера) | N/A | — |
|
||||
|
||||
Нет выбранного компонента — отметьте N/A с причиной, а не оставляйте пустую строку. Внутренний публичный health listener, если нужен, минимален и изолирован; через него нельзя обращаться к бизнес-API без mTLS. Отдельно задокументируйте scrape/health/bootstrap каналы: они тоже не должны создавать обход.
|
||||
## Служебные каналы (scrape / health / bootstrap)
|
||||
|
||||
## Обязательные отрицательные проверки
|
||||
|
||||
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.
|
||||
| Канал | Защита | Почему не обход |
|
||||
| --- | --- | --- |
|
||||
| Health API `127.0.0.1:8081` внутри контейнера | Только loopback контейнера, только `/health/live`, `/health/ready` | Не слушает сеть; бизнес-маршрутов нет |
|
||||
| Internal stats API `127.0.0.1:9090` | Только loopback | Пул соединений, без данных пользователей |
|
||||
| Метрики Collector о себе `:8888` (сеть telemetry, HTTP) | Только сеть telemetry | Счётчики Collector, без данных приложений и без ingest; plaintext — осознанное исключение |
|
||||
| RabbitMQ Prometheus `:15691` | TLS + клиентский сертификат | Только метрики очередей |
|
||||
| Bootstrap оператора (`scripts/bootstrap.py`) | `docker compose exec` на хосте оператора; root token из `secrets/operator` | Не сетевой интерфейс; значения не печатаются |
|
||||
| `migrate`, `s3-init` (profile ops) | Запускаются оператором; TLS verify-full / HTTPS | Не работают постоянно, приложениям недоступны |
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
source_commit=a414221d756744e90c2b9b498b66f386a3a7d062
|
||||
run=https://github.com/CharaWein/2026_lab3/actions/runs/43267046991
|
||||
go_tests=success
|
||||
stand=success
|
||||
scan=success
|
||||
@@ -0,0 +1,5 @@
|
||||
# Доказательства
|
||||
|
||||
Храните небольшие обезличенные результаты: команды и stdout проверок, JSON/CSV агрегатов нагрузки, EXPLAIN, dashboard JSON, текст разбора отказа. Укажите дату, commit, аппаратные лимиты и профиль нагрузки.
|
||||
|
||||
Не добавляйте .env, session tokens, cookies, приватные ключи, credentials, реальные сообщения, raw dumps и signed URLs. Для скриншотов скрывайте секреты. Большие логи/бинарные traces сохраняйте отдельно по правилам преподавателя; одного скриншота без методики недостаточно.
|
||||
@@ -0,0 +1,17 @@
|
||||
/mtusi2026lab7-api-3 restarts=0 oom_killed=false exit=0
|
||||
/mtusi2026lab7-api-4 restarts=0 oom_killed=false exit=0
|
||||
/mtusi2026lab7-grafana-1 restarts=0 oom_killed=false exit=0
|
||||
/mtusi2026lab7-lb-1 restarts=0 oom_killed=false exit=0
|
||||
/mtusi2026lab7-loki-1 restarts=0 oom_killed=false exit=0
|
||||
/mtusi2026lab7-openbao-1 restarts=0 oom_killed=false exit=0
|
||||
/mtusi2026lab7-otel-collector-1 restarts=0 oom_killed=false exit=0
|
||||
/mtusi2026lab7-postgres-1 restarts=0 oom_killed=false exit=0
|
||||
/mtusi2026lab7-prometheus-1 restarts=0 oom_killed=false exit=0
|
||||
/mtusi2026lab7-rabbitmq-1 restarts=0 oom_killed=false exit=0
|
||||
/mtusi2026lab7-reconciler-1 restarts=0 oom_killed=false exit=0
|
||||
/mtusi2026lab7-redis-1 restarts=0 oom_killed=false exit=0
|
||||
/mtusi2026lab7-relay-1 restarts=0 oom_killed=false exit=0
|
||||
/mtusi2026lab7-s3-1 restarts=0 oom_killed=false exit=0
|
||||
/mtusi2026lab7-tempo-1 restarts=0 oom_killed=false exit=0
|
||||
/mtusi2026lab7-tempo-init-1 restarts=0 oom_killed=false exit=0
|
||||
/mtusi2026lab7-worker-1 restarts=0 oom_killed=false exit=0
|
||||
@@ -0,0 +1,19 @@
|
||||
2026-11-12T17:17:50Z
|
||||
Docker Compose version v2.38.2
|
||||
NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
|
||||
mtusi2026lab7-api-1 mtusi2026lab7-api:local "/app/api" api 9 seconds ago Up 6 seconds (healthy) 8443/tcp
|
||||
mtusi2026lab7-api-2 mtusi2026lab7-api:local "/app/api" api 8 seconds ago Up 7 seconds (healthy) 8443/tcp
|
||||
mtusi2026lab7-grafana-1 grafana/grafana:11.4.0 "/run.sh" grafana 8 seconds ago Up 6 seconds (healthy) 127.0.0.1:3000->3000/tcp
|
||||
mtusi2026lab7-lb-1 haproxy:3.0.5-alpine "docker-entrypoint.s…" lb 8 seconds ago Up Less than a second 127.0.0.1:8443->8443/tcp
|
||||
mtusi2026lab7-loki-1 grafana/loki:3.3.2 "/usr/bin/loki -conf…" loki 8 seconds ago Up 8 seconds 3100/tcp
|
||||
mtusi2026lab7-openbao-1 openbao/openbao:2.1.0 "docker-entrypoint.s…" openbao About a minute ago Up About a minute 127.0.0.1:8200->8200/tcp
|
||||
mtusi2026lab7-otel-collector-1 otel/opentelemetry-collector-contrib:0.116.1 "/otelcol-contrib --…" otel-collector 8 seconds ago Up 8 seconds 4317-4318/tcp, 55678-55679/tcp
|
||||
mtusi2026lab7-postgres-1 postgres:16.4-alpine "sh -c 'install -o p…" postgres 58 seconds ago Up 57 seconds (healthy) 5432/tcp
|
||||
mtusi2026lab7-prometheus-1 prom/prometheus:v3.1.0 "/bin/prometheus --c…" prometheus 9 seconds ago Up 8 seconds 9090/tcp
|
||||
mtusi2026lab7-rabbitmq-1 rabbitmq:4.0.9-alpine "docker-entrypoint.s…" rabbitmq 58 seconds ago Up 57 seconds (healthy) 4369/tcp, 5671-5672/tcp, 15691-15692/tcp, 25672/tcp
|
||||
mtusi2026lab7-reconciler-1 mtusi2026lab7-api:local "/app/reconcile --ap…" reconciler 8 seconds ago Up 7 seconds (healthy) 8443/tcp
|
||||
mtusi2026lab7-redis-1 redis:7.4.1-alpine "docker-entrypoint.s…" redis 58 seconds ago Up 41 seconds (healthy) 6379/tcp
|
||||
mtusi2026lab7-relay-1 mtusi2026lab7-api:local "/app/pipeline relay" relay 9 seconds ago Up 7 seconds (healthy) 8443/tcp
|
||||
mtusi2026lab7-s3-1 bitnamilegacy/minio:2025.4.22@sha256:50cec18ac4184af4671a78aedd5554942c8ae105d51a465fa82037949046da01 "/bin/bash -c 'mkdir…" s3 58 seconds ago Up 57 seconds (healthy) 9000-9001/tcp
|
||||
mtusi2026lab7-tempo-1 grafana/tempo:2.6.1 "/tempo -config.file…" tempo 8 seconds ago Up 7 seconds
|
||||
mtusi2026lab7-worker-1 mtusi2026lab7-api:local "/app/pipeline worker" worker 8 seconds ago Up 7 seconds (healthy) 8443/tcp
|
||||
@@ -0,0 +1,18 @@
|
||||
NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
|
||||
mtusi2026lab7-api-3 mtusi2026lab7-api:local "/app/api" api 53 seconds ago Up 52 seconds (healthy) 8443/tcp
|
||||
mtusi2026lab7-api-4 mtusi2026lab7-api:local "/app/api" api 41 seconds ago Up 40 seconds (healthy) 8443/tcp
|
||||
mtusi2026lab7-grafana-1 grafana/grafana:11.4.0 "/run.sh" grafana 6 minutes ago Up 5 minutes (healthy) 127.0.0.1:3000->3000/tcp
|
||||
mtusi2026lab7-lb-1 haproxy:3.0.5-alpine "docker-entrypoint.s…" lb 6 minutes ago Up 5 minutes 127.0.0.1:8443->8443/tcp
|
||||
mtusi2026lab7-loki-1 grafana/loki:3.3.2 "/usr/bin/loki -conf…" loki 6 minutes ago Up 5 minutes 3100/tcp
|
||||
mtusi2026lab7-openbao-1 openbao/openbao:2.1.0 "docker-entrypoint.s…" openbao 7 minutes ago Up 5 minutes 127.0.0.1:8200->8200/tcp
|
||||
mtusi2026lab7-otel-collector-1 otel/opentelemetry-collector-contrib:0.116.1 "/otelcol-contrib --…" otel-collector 6 minutes ago Up 5 minutes 4317-4318/tcp, 55678-55679/tcp
|
||||
mtusi2026lab7-postgres-1 postgres:16.4-alpine "sh -c 'install -o p…" postgres 7 minutes ago Up 5 minutes (healthy) 5432/tcp
|
||||
mtusi2026lab7-prometheus-1 prom/prometheus:v3.1.0 "/bin/prometheus --c…" prometheus 6 minutes ago Up 5 minutes 9090/tcp
|
||||
mtusi2026lab7-rabbitmq-1 rabbitmq:4.0.9-alpine "docker-entrypoint.s…" rabbitmq 7 minutes ago Up 5 minutes (healthy) 4369/tcp, 5671-5672/tcp, 15691-15692/tcp, 25672/tcp
|
||||
mtusi2026lab7-reconciler-1 mtusi2026lab7-api:local "/app/reconcile --ap…" reconciler 6 minutes ago Up 5 minutes (healthy) 8443/tcp
|
||||
mtusi2026lab7-redis-1 redis:7.4.1-alpine "docker-entrypoint.s…" redis 7 minutes ago Up 5 minutes (healthy) 6379/tcp
|
||||
mtusi2026lab7-relay-1 mtusi2026lab7-api:local "/app/pipeline relay" relay 6 minutes ago Up 5 minutes (healthy) 8443/tcp
|
||||
mtusi2026lab7-s3-1 bitnamilegacy/minio:2025.4.22@sha256:50cec18ac4184af4671a78aedd5554942c8ae105d51a465fa82037949046da01 "/bin/bash -c 'mkdir…" s3 7 minutes ago Up 5 minutes (healthy) 9000-9001/tcp
|
||||
mtusi2026lab7-tempo-1 grafana/tempo:2.6.1 "/tempo -config.file…" tempo 6 minutes ago Up 5 minutes
|
||||
mtusi2026lab7-tempo-init-1 grafana/tempo:2.6.1 "chown 10001:10001 /…" tempo-init 6 minutes ago Exited (0) 6 minutes ago
|
||||
mtusi2026lab7-worker-1 mtusi2026lab7-api:local "/app/pipeline worker" worker 6 minutes ago Up 5 minutes (healthy) 8443/tcp
|
||||
@@ -0,0 +1,16 @@
|
||||
mtusi2026lab7-api-4 0.51% 17.5MiB / 256MiB
|
||||
mtusi2026lab7-api-3 0.63% 17.07MiB / 256MiB
|
||||
mtusi2026lab7-grafana-1 0.03% 53.66MiB / 256MiB
|
||||
mtusi2026lab7-tempo-1 0.96% 139.4MiB / 1GiB
|
||||
mtusi2026lab7-lb-1 0.33% 14.51MiB / 128MiB
|
||||
mtusi2026lab7-otel-collector-1 2.16% 57.52MiB / 256MiB
|
||||
mtusi2026lab7-reconciler-1 3.81% 5.465MiB / 128MiB
|
||||
mtusi2026lab7-loki-1 0.35% 97.61MiB / 1GiB
|
||||
mtusi2026lab7-worker-1 3.15% 12.34MiB / 768MiB
|
||||
mtusi2026lab7-prometheus-1 0.72% 42.93MiB / 512MiB
|
||||
mtusi2026lab7-relay-1 0.21% 12.42MiB / 128MiB
|
||||
mtusi2026lab7-postgres-1 0.25% 60.77MiB / 512MiB
|
||||
mtusi2026lab7-rabbitmq-1 4.61% 77.87MiB / 512MiB
|
||||
mtusi2026lab7-redis-1 0.44% 4.168MiB / 256MiB
|
||||
mtusi2026lab7-s3-1 0.04% 208.1MiB / 512MiB
|
||||
mtusi2026lab7-openbao-1 0.33% 21.78MiB / 256MiB
|
||||
@@ -0,0 +1,8 @@
|
||||
Executing explicit failover hook; hook output suppressed to avoid leaking secrets.
|
||||
{"observed_instances_before": 2, "successful_writes": 138, "failed_attempts": 0, "first_recovery_seconds": 3.653}
|
||||
PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence.
|
||||
-- контейнеры api после stop-one:
|
||||
mtusi2026lab7-api-1 0538735e7e2e Up 29 seconds (healthy)
|
||||
mtusi2026lab7-api-2 7943a102220b Exited (0) 11 seconds ago
|
||||
mtusi2026lab7-api-1 Up 36 seconds (healthy)
|
||||
mtusi2026lab7-api-2 Up 6 seconds (healthy)
|
||||
@@ -0,0 +1,8 @@
|
||||
Executing explicit failover hook; hook output suppressed to avoid leaking secrets.
|
||||
{"observed_instances_before": 2, "successful_writes": 138, "failed_attempts": 0, "first_recovery_seconds": 3.634}
|
||||
PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence.
|
||||
-- контейнеры api после stop-one:
|
||||
mtusi2026lab7-api-1 0538735e7e2e Up 52 seconds (healthy)
|
||||
mtusi2026lab7-api-2 7943a102220b Exited (0) 11 seconds ago
|
||||
mtusi2026lab7-api-1 Up 58 seconds (healthy)
|
||||
mtusi2026lab7-api-2 Up 5 seconds (healthy)
|
||||
@@ -0,0 +1,88 @@
|
||||
{
|
||||
"rounds": 10,
|
||||
"parallel_per_round": 16,
|
||||
"distinct_instances_seen": 2,
|
||||
"duplicates_found": 0,
|
||||
"per_round": [
|
||||
{
|
||||
"round": 0,
|
||||
"requests": 16,
|
||||
"status_201": 16,
|
||||
"distinct_messages": 1,
|
||||
"stored": 1,
|
||||
"instances": 2
|
||||
},
|
||||
{
|
||||
"round": 1,
|
||||
"requests": 16,
|
||||
"status_201": 16,
|
||||
"distinct_messages": 1,
|
||||
"stored": 1,
|
||||
"instances": 2
|
||||
},
|
||||
{
|
||||
"round": 2,
|
||||
"requests": 16,
|
||||
"status_201": 16,
|
||||
"distinct_messages": 1,
|
||||
"stored": 1,
|
||||
"instances": 2
|
||||
},
|
||||
{
|
||||
"round": 3,
|
||||
"requests": 16,
|
||||
"status_201": 16,
|
||||
"distinct_messages": 1,
|
||||
"stored": 1,
|
||||
"instances": 2
|
||||
},
|
||||
{
|
||||
"round": 4,
|
||||
"requests": 16,
|
||||
"status_201": 16,
|
||||
"distinct_messages": 1,
|
||||
"stored": 1,
|
||||
"instances": 2
|
||||
},
|
||||
{
|
||||
"round": 5,
|
||||
"requests": 16,
|
||||
"status_201": 16,
|
||||
"distinct_messages": 1,
|
||||
"stored": 1,
|
||||
"instances": 2
|
||||
},
|
||||
{
|
||||
"round": 6,
|
||||
"requests": 16,
|
||||
"status_201": 16,
|
||||
"distinct_messages": 1,
|
||||
"stored": 1,
|
||||
"instances": 2
|
||||
},
|
||||
{
|
||||
"round": 7,
|
||||
"requests": 16,
|
||||
"status_201": 16,
|
||||
"distinct_messages": 1,
|
||||
"stored": 1,
|
||||
"instances": 2
|
||||
},
|
||||
{
|
||||
"round": 8,
|
||||
"requests": 16,
|
||||
"status_201": 16,
|
||||
"distinct_messages": 1,
|
||||
"stored": 1,
|
||||
"instances": 2
|
||||
},
|
||||
{
|
||||
"round": 9,
|
||||
"requests": 16,
|
||||
"status_201": 16,
|
||||
"distinct_messages": 1,
|
||||
"stored": 1,
|
||||
"instances": 2
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
bitnamilegacy/minio:2025.4.22@sha256:50cec18ac4184af4671a78aedd5554942c8ae105d51a465fa82037949046da01 bitnamilegacy/minio@sha256:50cec18ac4184af4671a78aedd5554942c8ae105d51a465fa82037949046da01
|
||||
grafana/grafana:11.4.0 grafana/grafana@sha256:d8ea37798ccc41061a62ab080f2676dda6bf7815558499f901bdb0f533a456fb
|
||||
grafana/loki:3.3.2 grafana/loki@sha256:8af2de1abbdd7aa92b27c9bcc96f0f4140c9096b507c77921ffddf1c6ad6c48f
|
||||
grafana/tempo:2.6.1 grafana/tempo@sha256:ef4384fce6e8ad22b95b243d8fc165628cda655376fd50e7850536ad89d71d50
|
||||
haproxy:3.0.5-alpine haproxy@sha256:43a2591a6a62a41dd22edb4452880e9c70de489fbd7c54ffb52d035cccbfe949
|
||||
mtusi2026lab7-api:local
|
||||
local-build
|
||||
openbao/openbao:2.1.0 openbao/openbao@sha256:7de07aa6df3937d44c96c2d65c188b2d4a70546f2a764ad4510301305af6a223
|
||||
otel/opentelemetry-collector-contrib:0.116.1 otel/opentelemetry-collector-contrib@sha256:d0ebf65280da2e1b1491d1b93648281afd353d4b9ea19160090303cec9a233bd
|
||||
postgres:16.4-alpine postgres@sha256:5660c2cbfea50c7a9127d17dc4e48543eedd3d7a41a595a2dfa572471e37e64c
|
||||
prom/prometheus:v3.1.0 prom/prometheus@sha256:6559acbd5d770b15bb3c954629ce190ac3cbbdb2b7f1c30f0385c4e05104e218
|
||||
rabbitmq:4.0.9-alpine rabbitmq@sha256:0a09ddfd00a1ef2e58f497d731e9b2814ef3bebb3668069185c54d085352d2b9
|
||||
redis:7.4.1-alpine redis@sha256:c1e88455c85225310bbea54816e9c3f4b5295815e6dbf80c34d40afc6df28275
|
||||
@@ -0,0 +1,2 @@
|
||||
6e304db1ea6a4190 10
|
||||
749718ebe6b58adb 10
|
||||
@@ -0,0 +1,36 @@
|
||||
-- до:
|
||||
mtusi2026lab7-api-1 Up 58 seconds (healthy)
|
||||
mtusi2026lab7-api-2 Up 5 seconds (healthy)
|
||||
mtusi2026lab7-grafana-1 Up 58 seconds (healthy)
|
||||
mtusi2026lab7-lb-1 Up 52 seconds
|
||||
mtusi2026lab7-loki-1 Up About a minute
|
||||
mtusi2026lab7-openbao-1 Up About a minute
|
||||
mtusi2026lab7-otel-collector-1 Up About a minute
|
||||
mtusi2026lab7-postgres-1 Up About a minute (healthy)
|
||||
mtusi2026lab7-prometheus-1 Up About a minute
|
||||
mtusi2026lab7-rabbitmq-1 Up About a minute (healthy)
|
||||
mtusi2026lab7-reconciler-1 Up 59 seconds (healthy)
|
||||
mtusi2026lab7-redis-1 Up About a minute (healthy)
|
||||
mtusi2026lab7-relay-1 Up 59 seconds (healthy)
|
||||
mtusi2026lab7-s3-1 Up About a minute (healthy)
|
||||
mtusi2026lab7-tempo-1 Up 59 seconds
|
||||
mtusi2026lab7-worker-1 Up 59 seconds (healthy)
|
||||
Executing explicit persistence hook; hook output suppressed to avoid leaking secrets.
|
||||
PASS: persistence preserved confirmed data and existing session. Hook scope needs operator evidence.
|
||||
-- после:
|
||||
mtusi2026lab7-api-1 Up 6 seconds (healthy)
|
||||
mtusi2026lab7-api-2 Up 7 seconds (healthy)
|
||||
mtusi2026lab7-grafana-1 Up 24 seconds (healthy)
|
||||
mtusi2026lab7-lb-1 Up Less than a second
|
||||
mtusi2026lab7-loki-1 Up 23 seconds
|
||||
mtusi2026lab7-openbao-1 Up 15 seconds
|
||||
mtusi2026lab7-otel-collector-1 Up 24 seconds
|
||||
mtusi2026lab7-postgres-1 Up 24 seconds (healthy)
|
||||
mtusi2026lab7-prometheus-1 Up 24 seconds
|
||||
mtusi2026lab7-rabbitmq-1 Up 23 seconds (healthy)
|
||||
mtusi2026lab7-reconciler-1 Up 7 seconds (healthy)
|
||||
mtusi2026lab7-redis-1 Up 24 seconds (healthy)
|
||||
mtusi2026lab7-relay-1 Up 7 seconds (healthy)
|
||||
mtusi2026lab7-s3-1 Up 24 seconds (healthy)
|
||||
mtusi2026lab7-tempo-1 Up 23 seconds
|
||||
mtusi2026lab7-worker-1 Up 7 seconds (healthy)
|
||||
@@ -0,0 +1,3 @@
|
||||
PASS: whitespace-only password rejected with 400 (3 variants)
|
||||
PASS: Redis ACL -incr: message visible on every next read (3 in history)
|
||||
PASS: Redis ACL -incr -del -unlink -scan: message visible on every next read (4 in history)
|
||||
@@ -0,0 +1,92 @@
|
||||
-- до:
|
||||
mtusi2026lab7-api-1 0538735e7e2e Up 3 minutes (healthy)
|
||||
mtusi2026lab7-api-2 7943a102220b Up 3 minutes (healthy)
|
||||
#1 [internal] load local bake definitions
|
||||
#1 reading from stdin 380B done
|
||||
#1 DONE 0.0s
|
||||
|
||||
#2 [internal] load build definition from Dockerfile
|
||||
#2 transferring dockerfile: 3.85kB done
|
||||
#2 DONE 0.0s
|
||||
|
||||
#3 [internal] load metadata for docker.io/library/alpine:3.20@sha256:d9e853e87e55526f6b2917df91a2115c36dd7c696a35be12163d44e6e2a4b6bc
|
||||
#3 DONE 0.0s
|
||||
|
||||
#4 [internal] load metadata for docker.io/library/golang:1.26.11-alpine
|
||||
#4 DONE 0.1s
|
||||
|
||||
#5 [internal] load .dockerignore
|
||||
#5 transferring context: 212B 0.0s done
|
||||
#5 DONE 0.0s
|
||||
|
||||
#6 [builder 1/6] FROM docker.io/library/golang:1.26.11-alpine@sha256:ae52b5bc6ed045a9ed26ab03dc19327a802a9cc9aa8b27ed57f5c6b60579b0bb
|
||||
#6 DONE 0.0s
|
||||
|
||||
#7 [stage-2 1/7] FROM docker.io/library/alpine:3.20@sha256:d9e853e87e55526f6b2917df91a2115c36dd7c696a35be12163d44e6e2a4b6bc
|
||||
#7 DONE 0.0s
|
||||
|
||||
#8 [internal] load build context
|
||||
#8 transferring context: 10.70kB 0.1s done
|
||||
#8 DONE 0.1s
|
||||
|
||||
#9 [stage-2 4/7] WORKDIR /app
|
||||
#9 CACHED
|
||||
|
||||
#10 [builder 3/6] COPY go.mod go.sum ./
|
||||
#10 CACHED
|
||||
|
||||
#11 [builder 5/6] COPY . .
|
||||
#11 CACHED
|
||||
|
||||
#12 [stage-2 2/7] RUN apk --no-cache upgrade && apk --no-cache add ca-certificates tzdata libwebp-tools
|
||||
#12 CACHED
|
||||
|
||||
#13 [stage-2 5/7] COPY --from=builder --chown=appuser:appgroup /out/api /app/api
|
||||
#13 CACHED
|
||||
|
||||
#14 [builder 4/6] RUN go mod download
|
||||
#14 CACHED
|
||||
|
||||
#15 [builder 2/6] WORKDIR /src
|
||||
#15 CACHED
|
||||
|
||||
#16 [builder 6/6] RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w -X github.com/charawein/mtusi2026lab7/internal/telemetry.Version=lab7" -trimpath -o /out/ ./cmd/api ./cmd/reconcile ./cmd/pipeline ./cmd/secprobe
|
||||
#16 CACHED
|
||||
|
||||
#17 [stage-2 6/7] COPY --from=builder --chown=appuser:appgroup /out/reconcile /app/reconcile
|
||||
#17 CACHED
|
||||
|
||||
#18 [stage-2 3/7] RUN addgroup -g 1001 -S appgroup && adduser -u 1001 -S appuser -G appgroup && mkdir -p /var/lib/messenger/fault && chown appuser:appgroup /var/lib/messenger/fault
|
||||
#18 CACHED
|
||||
|
||||
#19 [stage-2 7/7] COPY --from=builder --chown=appuser:appgroup /out/pipeline /app/pipeline
|
||||
#19 CACHED
|
||||
|
||||
#20 exporting to image
|
||||
#20 exporting layers done
|
||||
#20 writing image sha256:e830a7fdf17500a1a527dd395f504ccf04238c2f523d963b02d01cb64fd0d9a9 done
|
||||
#20 naming to docker.io/library/mtusi2026lab7-api:local done
|
||||
#20 DONE 0.0s
|
||||
|
||||
#21 resolving provenance for metadata file
|
||||
#21 DONE 0.0s
|
||||
api Built
|
||||
Container mtusi2026lab7-postgres-1 Running
|
||||
no change
|
||||
Container mtusi2026lab7-api-1 Running
|
||||
Container mtusi2026lab7-api-2 Running
|
||||
Container mtusi2026lab7-api-3 Creating
|
||||
Container mtusi2026lab7-api-3 Created
|
||||
Container mtusi2026lab7-api-3 Starting
|
||||
Container mtusi2026lab7-api-3 Started
|
||||
replaced /mtusi2026lab7-api-1
|
||||
Container mtusi2026lab7-api-2 Running
|
||||
Container mtusi2026lab7-api-3 Running
|
||||
Container mtusi2026lab7-api-4 Creating
|
||||
Container mtusi2026lab7-api-4 Created
|
||||
Container mtusi2026lab7-api-4 Starting
|
||||
Container mtusi2026lab7-api-4 Started
|
||||
replaced /mtusi2026lab7-api-2
|
||||
mtusi2026lab7-api-3 2027815d9c51 mtusi2026lab7-api:local Up 25 seconds (healthy)
|
||||
mtusi2026lab7-api-4 919473005fb8 mtusi2026lab7-api:local Up 13 seconds (healthy)
|
||||
-- замена заняла 62 s (внутри 90 s нагрузки)
|
||||
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"lab": 7,
|
||||
"workload": "closed-loop POST messages; no automatic retries",
|
||||
"requested_duration_seconds": 90.0,
|
||||
"elapsed_seconds": 90.022,
|
||||
"concurrency": 4,
|
||||
"successful_requests": 11673,
|
||||
"failed_requests": 0,
|
||||
"error_ratio": 0.0,
|
||||
"successful_rps": 129.669,
|
||||
"successful_latency_ms": {
|
||||
"p50": 26.667,
|
||||
"p95": 59.833,
|
||||
"p99": 89.961
|
||||
},
|
||||
"note": "Latency percentiles cover successes only. Timeouts/errors are counted separately; closed-loop has coordinated omission and client overhead."
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
2
|
||||
total used free shared buff/cache available
|
||||
Mem: 7932 1948 1527 101 4872 5983
|
||||
Swap: 3071 0 3071
|
||||
28.0.4
|
||||
Docker Compose version v2.38.2
|
||||
@@ -0,0 +1 @@
|
||||
PASS: lab7 public API scenario; infrastructure and grading evidence remain separate.
|
||||
@@ -0,0 +1 @@
|
||||
PASS: trusted HTTPS works; untrusted CA rejected. This does NOT verify internal mTLS, OpenBao or hardening.
|
||||
@@ -0,0 +1,5 @@
|
||||
# Доказательства
|
||||
|
||||
Храните небольшие обезличенные результаты: команды и stdout проверок, JSON/CSV агрегатов нагрузки, EXPLAIN, dashboard JSON, текст разбора отказа. Укажите дату, commit, аппаратные лимиты и профиль нагрузки.
|
||||
|
||||
Не добавляйте .env, session tokens, cookies, приватные ключи, credentials, реальные сообщения, raw dumps и signed URLs. Для скриншотов скрывайте секреты. Большие логи/бинарные traces сохраняйте отдельно по правилам преподавателя; одного скриншота без методики недостаточно.
|
||||
@@ -0,0 +1,24 @@
|
||||
? github.com/charawein/mtusi2026lab7/cmd/api [no test files]
|
||||
? github.com/charawein/mtusi2026lab7/cmd/pipeline [no test files]
|
||||
? github.com/charawein/mtusi2026lab7/cmd/reconcile [no test files]
|
||||
? github.com/charawein/mtusi2026lab7/cmd/secprobe [no test files]
|
||||
? github.com/charawein/mtusi2026lab7/internal/broker [no test files]
|
||||
? github.com/charawein/mtusi2026lab7/internal/config [no test files]
|
||||
? github.com/charawein/mtusi2026lab7/internal/domain [no test files]
|
||||
ok github.com/charawein/mtusi2026lab7/internal/imagecheck 0.022s
|
||||
ok github.com/charawein/mtusi2026lab7/internal/imaging 0.767s
|
||||
? github.com/charawein/mtusi2026lab7/internal/platform [no test files]
|
||||
ok github.com/charawein/mtusi2026lab7/internal/reconcile 0.012s
|
||||
? github.com/charawein/mtusi2026lab7/internal/repository [no test files]
|
||||
? github.com/charawein/mtusi2026lab7/internal/repository/postgres [no test files]
|
||||
? github.com/charawein/mtusi2026lab7/internal/repository/redis [no test files]
|
||||
? github.com/charawein/mtusi2026lab7/internal/secrets [no test files]
|
||||
ok github.com/charawein/mtusi2026lab7/internal/service 0.009s
|
||||
ok github.com/charawein/mtusi2026lab7/internal/storage 0.005s
|
||||
ok github.com/charawein/mtusi2026lab7/internal/telemetry 0.015s
|
||||
ok github.com/charawein/mtusi2026lab7/internal/tlsutil 4.229s
|
||||
? github.com/charawein/mtusi2026lab7/internal/transport/http [no test files]
|
||||
ok github.com/charawein/mtusi2026lab7/internal/transport/http/middleware 0.005s
|
||||
? github.com/charawein/mtusi2026lab7/internal/transport/httputil [no test files]
|
||||
ok github.com/charawein/mtusi2026lab7/internal/worker 6.961s
|
||||
? github.com/charawein/mtusi2026lab7/student-tests/genfixtures [no test files]
|
||||
@@ -0,0 +1,16 @@
|
||||
=== RUN TestTLSIdentityAllowlistRevocationAndReload
|
||||
2026/11/12 17:14:23 http: TLS handshake error from 127.0.0.1:37240: tls: client didn't provide a certificate
|
||||
2026/11/12 17:14:23 http: TLS handshake error from 127.0.0.1:37246: client identity not allowed: [attacker]
|
||||
2026/11/12 17:14:23 http: TLS handshake error from 127.0.0.1:37254: tls: failed to verify certificate: x509: certificate signed by unknown authority
|
||||
2026/11/12 17:14:25 http: TLS handshake error from 127.0.0.1:44556: client identity not allowed: certificate revoked
|
||||
--- PASS: TestTLSIdentityAllowlistRevocationAndReload (4.22s)
|
||||
PASS
|
||||
ok github.com/charawein/mtusi2026lab7/internal/tlsutil 4.226s
|
||||
=== RUN TestPutValidatedClassifiesCause
|
||||
--- PASS: TestPutValidatedClassifiesCause (0.00s)
|
||||
=== RUN TestValidatePassword
|
||||
--- PASS: TestValidatePassword (0.00s)
|
||||
=== RUN TestValidateText
|
||||
--- PASS: TestValidateText (0.00s)
|
||||
PASS
|
||||
ok github.com/charawein/mtusi2026lab7/internal/service 0.006s
|
||||
@@ -0,0 +1,18 @@
|
||||
=== RUN TestTracePropagationMapAndAMQP
|
||||
--- PASS: TestTracePropagationMapAndAMQP (0.00s)
|
||||
=== RUN TestTraceUnsampledSuppressesBackgroundSpans
|
||||
--- PASS: TestTraceUnsampledSuppressesBackgroundSpans (0.00s)
|
||||
=== RUN TestTraceLogCorrelation
|
||||
--- PASS: TestTraceLogCorrelation (0.00s)
|
||||
=== RUN TestTelemetrySetupBuildsProviders
|
||||
--- PASS: TestTelemetrySetupBuildsProviders (0.01s)
|
||||
PASS
|
||||
ok github.com/charawein/mtusi2026lab7/internal/telemetry 0.011s
|
||||
=== RUN TestTelemetryRouteTemplateAndStatus
|
||||
--- PASS: TestTelemetryRouteTemplateAndStatus (0.00s)
|
||||
PASS
|
||||
ok github.com/charawein/mtusi2026lab7/internal/transport/http/middleware 0.006s
|
||||
=== RUN TestPipelineTracePropagationThroughOutbox
|
||||
--- PASS: TestPipelineTracePropagationThroughOutbox (0.70s)
|
||||
PASS
|
||||
ok github.com/charawein/mtusi2026lab7/internal/worker 0.705s
|
||||
@@ -0,0 +1,39 @@
|
||||
=== RUN TestPipelineHappyPathAndDuplicate
|
||||
2026/11/12 17:14:12 INFO duplicate delivery of finished job: ack without work job_id=171265b2-fafc-4d50-a4be-f79e7b3a46f4 attachment_id=240061d5-1d00-40f7-928a-d8fc1d9f2263 version=1 event=job.duplicate
|
||||
--- PASS: TestPipelineHappyPathAndDuplicate (0.24s)
|
||||
=== RUN TestPipelineConcurrentDuplicateIsBusy
|
||||
2026/11/12 17:14:12 INFO job leased by another worker: ack duplicate job_id=4563f346-08b5-4df9-b910-4ef28949eff5 attachment_id=50d6d2d9-545c-4367-99d7-1e0905d4aa81 version=1 event=job.duplicate owner=slow-worker
|
||||
--- PASS: TestPipelineConcurrentDuplicateIsBusy (0.17s)
|
||||
=== RUN TestPipelineCrashAfterSideEffectBeforeCommit
|
||||
2026/11/12 17:14:14 WARN FAULT INJECTION: crashing point=worker.after_side_effect
|
||||
2026/11/12 17:14:14 INFO job leased by another worker: ack duplicate job_id=a2119a53-ef46-42e2-87c2-3374ef5d364a attachment_id=6af36eaf-d341-4f59-8437-6d0a41a41c94 version=1 event=job.duplicate owner=w-fd7888
|
||||
--- PASS: TestPipelineCrashAfterSideEffectBeforeCommit (3.05s)
|
||||
=== RUN TestPipelineCrashAfterCommitBeforeAck
|
||||
2026/11/12 17:14:15 WARN FAULT INJECTION: crashing point=worker.after_commit
|
||||
2026/11/12 17:14:15 INFO duplicate delivery of finished job: ack without work job_id=764d00c1-7085-4f4d-8f0e-e5d1fce0d526 attachment_id=e8964090-117a-4651-b075-a04ab5935c70 version=1 event=job.duplicate
|
||||
--- PASS: TestPipelineCrashAfterCommitBeforeAck (0.17s)
|
||||
=== RUN TestPipelineRelayCrashAfterPublishDuplicates
|
||||
2026/11/12 17:14:15 INFO duplicate delivery of finished job: ack without work job_id=3e545245-fc57-4d3c-82f1-95e7b0f21cc3 attachment_id=2f86dba8-b3d1-4a79-8f6d-9c4d3041d350 version=1 event=job.duplicate
|
||||
--- PASS: TestPipelineRelayCrashAfterPublishDuplicates (0.17s)
|
||||
=== RUN TestPipelineVersionReorderAndStaleJob
|
||||
2026/11/12 17:14:15 INFO duplicate delivery of finished job: ack without work job_id=59e6b1aa-a4ce-4008-b6bd-3ed7918367d5 attachment_id=e440373b-b9fd-4654-9745-d814262eb7eb version=1 event=job.duplicate
|
||||
--- PASS: TestPipelineVersionReorderAndStaleJob (0.20s)
|
||||
=== RUN TestPipelineLostLeaseFencing
|
||||
--- PASS: TestPipelineLostLeaseFencing (0.69s)
|
||||
=== RUN TestPipelineTransientRetryWithBackoff
|
||||
2026/11/12 17:14:16 WARN attempt failed job_id=fc0ed4e9-3a91-4fb8-ab2d-29543335a3d7 attachment_id=abeb1248-ee98-46e7-ac2e-29d868dd7efe version=1 event=job.retry attempt=1 code=processing_failed final=false backoff=145.861651ms
|
||||
2026/11/12 17:14:16 INFO early delivery before backoff: ack, outbox will redeliver job_id=fc0ed4e9-3a91-4fb8-ab2d-29543335a3d7 attachment_id=abeb1248-ee98-46e7-ac2e-29d868dd7efe version=1 event=job.not_due
|
||||
--- PASS: TestPipelineTransientRetryWithBackoff (0.69s)
|
||||
=== RUN TestPipelinePermanentFailureAndReplay
|
||||
2026/11/12 17:14:17 WARN attempt failed job_id=95e8e0c1-b10c-469c-b708-6b547cc2042c attachment_id=78f28e8b-ddd6-42f0-b80c-5b01a708f0fa version=1 event=job.failed attempt=1 code=checksum_mismatch final=true backoff=132.23852ms
|
||||
--- PASS: TestPipelinePermanentFailureAndReplay (0.20s)
|
||||
=== RUN TestPipelineRetryExhausted
|
||||
2026/11/12 17:14:17 WARN attempt failed job_id=b86ec031-3705-40a5-a96d-219da34c55cb attachment_id=ef57db6e-fc00-44c1-aa33-29bbd3cb53e6 version=1 event=job.retry attempt=1 code=processing_failed final=false backoff=115.778267ms
|
||||
2026/11/12 17:14:18 WARN attempt failed job_id=b86ec031-3705-40a5-a96d-219da34c55cb attachment_id=ef57db6e-fc00-44c1-aa33-29bbd3cb53e6 version=1 event=job.retry attempt=2 code=processing_failed final=false backoff=212.923342ms
|
||||
2026/11/12 17:14:18 WARN attempt failed job_id=b86ec031-3705-40a5-a96d-219da34c55cb attachment_id=ef57db6e-fc00-44c1-aa33-29bbd3cb53e6 version=1 event=job.failed attempt=3 code=processing_failed final=true backoff=346.808043ms
|
||||
--- PASS: TestPipelineRetryExhausted (1.63s)
|
||||
=== RUN TestPipelineTracePropagationThroughOutbox
|
||||
2026/11/12 17:14:19 WARN attempt failed job_id=d3e37ccd-f331-4f2d-add2-5f4f0c07dc82 attachment_id=71e4e1cd-a9a5-418c-867c-d1956ca5d5fd version=1 event=job.retry attempt=1 code=processing_failed final=false backoff=192.048206ms
|
||||
--- PASS: TestPipelineTracePropagationThroughOutbox (0.67s)
|
||||
PASS
|
||||
ok github.com/charawein/mtusi2026lab7/internal/worker 7.886s
|
||||
@@ -0,0 +1,4 @@
|
||||
=== RUN TestOptimizedWebP
|
||||
--- PASS: TestOptimizedWebP (0.34s)
|
||||
PASS
|
||||
ok github.com/charawein/mtusi2026lab7/internal/imaging 0.350s
|
||||
@@ -0,0 +1,5 @@
|
||||
# Доказательства
|
||||
|
||||
Храните небольшие обезличенные результаты: команды и stdout проверок, JSON/CSV агрегатов нагрузки, EXPLAIN, dashboard JSON, текст разбора отказа. Укажите дату, commit, аппаратные лимиты и профиль нагрузки.
|
||||
|
||||
Не добавляйте .env, session tokens, cookies, приватные ключи, credentials, реальные сообщения, raw dumps и signed URLs. Для скриншотов скрывайте секреты. Большие логи/бинарные traces сохраняйте отдельно по правилам преподавателя; одного скриншота без методики недостаточно.
|
||||
@@ -0,0 +1,17 @@
|
||||
/mtusi2026lab7-api-1 restarts=0 oom_killed=false exit=0
|
||||
/mtusi2026lab7-api-2 restarts=0 oom_killed=false exit=0
|
||||
/mtusi2026lab7-grafana-1 restarts=0 oom_killed=false exit=0
|
||||
/mtusi2026lab7-lb-1 restarts=0 oom_killed=false exit=0
|
||||
/mtusi2026lab7-loki-1 restarts=0 oom_killed=false exit=0
|
||||
/mtusi2026lab7-openbao-1 restarts=0 oom_killed=false exit=0
|
||||
/mtusi2026lab7-otel-collector-1 restarts=0 oom_killed=false exit=0
|
||||
/mtusi2026lab7-postgres-1 restarts=0 oom_killed=false exit=0
|
||||
/mtusi2026lab7-prometheus-1 restarts=0 oom_killed=false exit=0
|
||||
/mtusi2026lab7-rabbitmq-1 restarts=0 oom_killed=false exit=0
|
||||
/mtusi2026lab7-reconciler-1 restarts=0 oom_killed=false exit=0
|
||||
/mtusi2026lab7-redis-1 restarts=0 oom_killed=false exit=0
|
||||
/mtusi2026lab7-relay-1 restarts=0 oom_killed=false exit=0
|
||||
/mtusi2026lab7-s3-1 restarts=0 oom_killed=false exit=0
|
||||
/mtusi2026lab7-tempo-1 restarts=0 oom_killed=false exit=0
|
||||
/mtusi2026lab7-tempo-init-1 restarts=0 oom_killed=false exit=0
|
||||
/mtusi2026lab7-worker-1 restarts=0 oom_killed=false exit=0
|
||||
@@ -0,0 +1,18 @@
|
||||
NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
|
||||
mtusi2026lab7-api-1 mtusi2026lab7-api:local "/app/api" api About a minute ago Up About a minute (healthy) 8443/tcp
|
||||
mtusi2026lab7-api-2 mtusi2026lab7-api:local "/app/api" api About a minute ago Up About a minute (healthy) 8443/tcp
|
||||
mtusi2026lab7-grafana-1 grafana/grafana:11.4.0 "/run.sh" grafana About a minute ago Up About a minute (healthy) 127.0.0.1:3000->3000/tcp
|
||||
mtusi2026lab7-lb-1 haproxy:3.0.5-alpine "docker-entrypoint.s…" lb About a minute ago Up About a minute 127.0.0.1:8443->8443/tcp
|
||||
mtusi2026lab7-loki-1 grafana/loki:3.3.2 "/usr/bin/loki -conf…" loki About a minute ago Up About a minute 3100/tcp
|
||||
mtusi2026lab7-openbao-1 openbao/openbao:2.1.0 "docker-entrypoint.s…" openbao 2 minutes ago Up 2 minutes 127.0.0.1:8200->8200/tcp
|
||||
mtusi2026lab7-otel-collector-1 otel/opentelemetry-collector-contrib:0.116.1 "/otelcol-contrib --…" otel-collector About a minute ago Up About a minute 4317-4318/tcp, 55678-55679/tcp
|
||||
mtusi2026lab7-postgres-1 postgres:16.4-alpine "sh -c 'install -o p…" postgres 2 minutes ago Up 2 minutes (healthy) 5432/tcp
|
||||
mtusi2026lab7-prometheus-1 prom/prometheus:v3.1.0 "/bin/prometheus --c…" prometheus About a minute ago Up About a minute 9090/tcp
|
||||
mtusi2026lab7-rabbitmq-1 rabbitmq:4.0.9-alpine "docker-entrypoint.s…" rabbitmq 2 minutes ago Up About a minute (healthy) 4369/tcp, 5671-5672/tcp, 15691-15692/tcp, 25672/tcp
|
||||
mtusi2026lab7-reconciler-1 mtusi2026lab7-api:local "/app/reconcile --ap…" reconciler About a minute ago Up About a minute (healthy) 8443/tcp
|
||||
mtusi2026lab7-redis-1 redis:7.4.1-alpine "docker-entrypoint.s…" redis 2 minutes ago Up 2 minutes (healthy) 6379/tcp
|
||||
mtusi2026lab7-relay-1 mtusi2026lab7-api:local "/app/pipeline relay" relay About a minute ago Up About a minute (healthy) 8443/tcp
|
||||
mtusi2026lab7-s3-1 bitnamilegacy/minio:2025.4.22@sha256:50cec18ac4184af4671a78aedd5554942c8ae105d51a465fa82037949046da01 "/bin/bash -c 'mkdir…" s3 2 minutes ago Up 38 seconds (healthy) 9000-9001/tcp
|
||||
mtusi2026lab7-tempo-1 grafana/tempo:2.6.1 "/tempo -config.file…" tempo About a minute ago Up About a minute
|
||||
mtusi2026lab7-tempo-init-1 grafana/tempo:2.6.1 "chown 10001:10001 /…" tempo-init About a minute ago Exited (0) About a minute ago
|
||||
mtusi2026lab7-worker-1 mtusi2026lab7-api:local "/app/pipeline worker" worker 53 seconds ago Up 30 seconds (healthy) 8443/tcp
|
||||
@@ -0,0 +1,16 @@
|
||||
mtusi2026lab7-worker-1 0.01% 14.95MiB / 768MiB
|
||||
mtusi2026lab7-grafana-1 3.10% 69.02MiB / 256MiB
|
||||
mtusi2026lab7-tempo-1 0.45% 61.38MiB / 1GiB
|
||||
mtusi2026lab7-lb-1 0.24% 13.18MiB / 128MiB
|
||||
mtusi2026lab7-relay-1 0.15% 11.93MiB / 128MiB
|
||||
mtusi2026lab7-reconciler-1 0.00% 5.191MiB / 128MiB
|
||||
mtusi2026lab7-api-2 0.21% 53.95MiB / 256MiB
|
||||
mtusi2026lab7-otel-collector-1 1.03% 48.32MiB / 256MiB
|
||||
mtusi2026lab7-loki-1 0.40% 61.48MiB / 1GiB
|
||||
mtusi2026lab7-prometheus-1 0.43% 38.57MiB / 512MiB
|
||||
mtusi2026lab7-api-1 0.15% 67.27MiB / 256MiB
|
||||
mtusi2026lab7-postgres-1 2.44% 59.49MiB / 512MiB
|
||||
mtusi2026lab7-s3-1 0.03% 211.7MiB / 512MiB
|
||||
mtusi2026lab7-redis-1 0.41% 3.969MiB / 256MiB
|
||||
mtusi2026lab7-rabbitmq-1 0.13% 76.74MiB / 512MiB
|
||||
mtusi2026lab7-openbao-1 0.27% 23.18MiB / 256MiB
|
||||
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"scenario": "crash-effect",
|
||||
"result": {
|
||||
"attachment_id": "c5db77aa-2a97-4eb8-a77a-d90e17d95e70",
|
||||
"job_id": "7cc02c86-a5dc-44a7-baeb-f17c9198f1a5",
|
||||
"worker_restarts": 1,
|
||||
"attempt": 2,
|
||||
"seconds_to_ready": 15.7,
|
||||
"events": "enqueued,claimed,lease_expired_requeued,claimed,done",
|
||||
"invariants": {
|
||||
"status": "ready",
|
||||
"published_version": 1,
|
||||
"objects_per_version": {
|
||||
"1": 3
|
||||
}
|
||||
},
|
||||
"variants": {
|
||||
"thumbnail": [
|
||||
256,
|
||||
160
|
||||
],
|
||||
"crop": [
|
||||
128,
|
||||
128
|
||||
],
|
||||
"optimized": [
|
||||
320,
|
||||
200
|
||||
],
|
||||
"optimized_bytes": 2462,
|
||||
"original_bytes": 111817
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
{
|
||||
"scenario": "demo",
|
||||
"result": {
|
||||
"attachment_id": "a9f29281-fb61-4dc2-be1a-bb051d221790",
|
||||
"job_id": "208a569c-127b-4997-8598-f8ce2afc6843",
|
||||
"job_state": "done",
|
||||
"attempt": 1,
|
||||
"timeline": [
|
||||
"worker stopped",
|
||||
"upload 202 queued id=a9f29281-fb61-4dc2-be1a-bb051d221790",
|
||||
"message 201 with queued attachment",
|
||||
"content 409, other messages OK",
|
||||
"api and rabbitmq restarted (volumes kept), outbox published=1",
|
||||
"rabbitmq queues after restart: {'attachment.dead': 0, 'attachment.process': 1}",
|
||||
"worker started → ready in 1.3 s"
|
||||
],
|
||||
"variants": {
|
||||
"thumbnail": [
|
||||
256,
|
||||
160
|
||||
],
|
||||
"crop": [
|
||||
128,
|
||||
128
|
||||
],
|
||||
"optimized": [
|
||||
320,
|
||||
200
|
||||
],
|
||||
"optimized_bytes": 2462,
|
||||
"original_bytes": 111817
|
||||
},
|
||||
"invariants": {
|
||||
"status": "ready",
|
||||
"published_version": 1,
|
||||
"objects_per_version": {
|
||||
"1": 3
|
||||
}
|
||||
},
|
||||
"events": "enqueued,claimed,done"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
{
|
||||
"scenario": "failed-replay",
|
||||
"result": {
|
||||
"attachment_id": "03387194-01c7-4af3-8c05-2494b53db329",
|
||||
"failed_error_code": "checksum_mismatch",
|
||||
"content_while_failed": 409,
|
||||
"attach_failed_to_message": 409,
|
||||
"registry_listed": true,
|
||||
"replay": {
|
||||
"attachment_id": "03387194-01c7-4af3-8c05-2494b53db329",
|
||||
"command": "replay",
|
||||
"error": "",
|
||||
"job_id": "c56192e9-dc8c-400b-a33b-09e66e0ecd3d",
|
||||
"ok": true,
|
||||
"version": 1
|
||||
},
|
||||
"replay_after_success": {
|
||||
"attachment_id": "03387194-01c7-4af3-8c05-2494b53db329",
|
||||
"command": "replay",
|
||||
"error": "conflict: job is done, only failed jobs can be replayed",
|
||||
"job_id": "c56192e9-dc8c-400b-a33b-09e66e0ecd3d",
|
||||
"ok": false,
|
||||
"version": 1
|
||||
},
|
||||
"final_status": "ready",
|
||||
"events": "enqueued,claimed,failed,replay,claimed,done,replay_refused",
|
||||
"dlq_messages": 1,
|
||||
"invariants": {
|
||||
"status": "ready",
|
||||
"published_version": 1,
|
||||
"objects_per_version": {
|
||||
"1": 3
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,925 @@
|
||||
{
|
||||
"scenario": "signals",
|
||||
"result": {
|
||||
"request": {
|
||||
"request_id": "obs-msg-cce45e31e6b242e6",
|
||||
"trace_id": "54ff4aa532f0179348c36bde4be6e8d2",
|
||||
"spans": [
|
||||
{
|
||||
"service": "messenger-api",
|
||||
"name": "POST /api/v1/chats/{chat_id}/messages",
|
||||
"kind": "SPAN_KIND_SERVER",
|
||||
"ms": 2.4,
|
||||
"parent": null,
|
||||
"outcome": null,
|
||||
"attempt": null,
|
||||
"status": ""
|
||||
},
|
||||
{
|
||||
"service": "messenger-api",
|
||||
"name": "get",
|
||||
"kind": "SPAN_KIND_CLIENT",
|
||||
"ms": 0.08,
|
||||
"parent": "messenger-api: POST /api/v1/chats/{chat_id}/messages",
|
||||
"outcome": null,
|
||||
"attempt": null,
|
||||
"status": ""
|
||||
},
|
||||
{
|
||||
"service": "messenger-api",
|
||||
"name": "ttl",
|
||||
"kind": "SPAN_KIND_CLIENT",
|
||||
"ms": 0.03,
|
||||
"parent": "messenger-api: POST /api/v1/chats/{chat_id}/messages",
|
||||
"outcome": null,
|
||||
"attempt": null,
|
||||
"status": ""
|
||||
},
|
||||
{
|
||||
"service": "messenger-api",
|
||||
"name": "pool.acquire",
|
||||
"kind": "SPAN_KIND_CLIENT",
|
||||
"ms": 0.01,
|
||||
"parent": "messenger-api: POST /api/v1/chats/{chat_id}/messages",
|
||||
"outcome": null,
|
||||
"attempt": null,
|
||||
"status": ""
|
||||
},
|
||||
{
|
||||
"service": "messenger-api",
|
||||
"name": "SELECT",
|
||||
"kind": "SPAN_KIND_CLIENT",
|
||||
"ms": 0.22,
|
||||
"parent": "messenger-api: POST /api/v1/chats/{chat_id}/messages",
|
||||
"outcome": null,
|
||||
"attempt": null,
|
||||
"status": ""
|
||||
},
|
||||
{
|
||||
"service": "messenger-api",
|
||||
"name": "pool.acquire",
|
||||
"kind": "SPAN_KIND_CLIENT",
|
||||
"ms": 0.0,
|
||||
"parent": "messenger-api: POST /api/v1/chats/{chat_id}/messages",
|
||||
"outcome": null,
|
||||
"attempt": null,
|
||||
"status": ""
|
||||
},
|
||||
{
|
||||
"service": "messenger-api",
|
||||
"name": "SELECT",
|
||||
"kind": "SPAN_KIND_CLIENT",
|
||||
"ms": 0.17,
|
||||
"parent": "messenger-api: POST /api/v1/chats/{chat_id}/messages",
|
||||
"outcome": null,
|
||||
"attempt": null,
|
||||
"status": ""
|
||||
},
|
||||
{
|
||||
"service": "messenger-api",
|
||||
"name": "pool.acquire",
|
||||
"kind": "SPAN_KIND_CLIENT",
|
||||
"ms": 0.0,
|
||||
"parent": "messenger-api: POST /api/v1/chats/{chat_id}/messages",
|
||||
"outcome": null,
|
||||
"attempt": null,
|
||||
"status": ""
|
||||
},
|
||||
{
|
||||
"service": "messenger-api",
|
||||
"name": "BEGIN",
|
||||
"kind": "SPAN_KIND_CLIENT",
|
||||
"ms": 0.07,
|
||||
"parent": "messenger-api: POST /api/v1/chats/{chat_id}/messages",
|
||||
"outcome": null,
|
||||
"attempt": null,
|
||||
"status": ""
|
||||
},
|
||||
{
|
||||
"service": "messenger-api",
|
||||
"name": "DELETE",
|
||||
"kind": "SPAN_KIND_CLIENT",
|
||||
"ms": 0.2,
|
||||
"parent": "messenger-api: POST /api/v1/chats/{chat_id}/messages",
|
||||
"outcome": null,
|
||||
"attempt": null,
|
||||
"status": ""
|
||||
},
|
||||
{
|
||||
"service": "messenger-api",
|
||||
"name": "INSERT",
|
||||
"kind": "SPAN_KIND_CLIENT",
|
||||
"ms": 0.21,
|
||||
"parent": "messenger-api: POST /api/v1/chats/{chat_id}/messages",
|
||||
"outcome": null,
|
||||
"attempt": null,
|
||||
"status": ""
|
||||
},
|
||||
{
|
||||
"service": "messenger-api",
|
||||
"name": "INSERT",
|
||||
"kind": "SPAN_KIND_CLIENT",
|
||||
"ms": 0.62,
|
||||
"parent": "messenger-api: POST /api/v1/chats/{chat_id}/messages",
|
||||
"outcome": null,
|
||||
"attempt": null,
|
||||
"status": ""
|
||||
}
|
||||
],
|
||||
"log": {
|
||||
"line": "http request",
|
||||
"labels": {
|
||||
"detected_level": "info",
|
||||
"event": "http.request",
|
||||
"request_id": "obs-msg-cce45e31e6b242e6",
|
||||
"route": "/api/v1/chats/{chat_id}/messages",
|
||||
"service_name": "messenger-api",
|
||||
"severity_text": "INFO",
|
||||
"span_id": "19644ee5c6ed3f4f",
|
||||
"status": "201",
|
||||
"trace_id": "54ff4aa532f0179348c36bde4be6e8d2"
|
||||
}
|
||||
}
|
||||
},
|
||||
"upload": {
|
||||
"request_id": "obs-upload-93e4699646f94751",
|
||||
"trace_id": "c305c32ab42753aedfec890c69c52ced",
|
||||
"services": [
|
||||
"messenger-api",
|
||||
"messenger-relay",
|
||||
"messenger-worker"
|
||||
],
|
||||
"links": {
|
||||
"api server → relay producer": true,
|
||||
"relay producer → worker consumer": true,
|
||||
"worker consumer → S3 PUT": true,
|
||||
"worker consumer → image.decode": true
|
||||
},
|
||||
"span_count": 56,
|
||||
"worker_db_spans": [
|
||||
"BEGIN",
|
||||
"COMMIT",
|
||||
"INSERT",
|
||||
"SELECT",
|
||||
"UPDATE",
|
||||
"batch start",
|
||||
"pool.acquire"
|
||||
],
|
||||
"tree": [
|
||||
{
|
||||
"service": "messenger-api",
|
||||
"name": "POST /api/v1/chats/{chat_id}/attachments",
|
||||
"kind": "SPAN_KIND_SERVER",
|
||||
"ms": 11.88,
|
||||
"parent": null,
|
||||
"outcome": null,
|
||||
"attempt": null,
|
||||
"status": ""
|
||||
},
|
||||
{
|
||||
"service": "messenger-api",
|
||||
"name": "get",
|
||||
"kind": "SPAN_KIND_CLIENT",
|
||||
"ms": 0.13,
|
||||
"parent": "messenger-api: POST /api/v1/chats/{chat_id}/attachments",
|
||||
"outcome": null,
|
||||
"attempt": null,
|
||||
"status": ""
|
||||
},
|
||||
{
|
||||
"service": "messenger-api",
|
||||
"name": "ttl",
|
||||
"kind": "SPAN_KIND_CLIENT",
|
||||
"ms": 0.04,
|
||||
"parent": "messenger-api: POST /api/v1/chats/{chat_id}/attachments",
|
||||
"outcome": null,
|
||||
"attempt": null,
|
||||
"status": ""
|
||||
},
|
||||
{
|
||||
"service": "messenger-api",
|
||||
"name": "pool.acquire",
|
||||
"kind": "SPAN_KIND_CLIENT",
|
||||
"ms": 0.01,
|
||||
"parent": "messenger-api: POST /api/v1/chats/{chat_id}/attachments",
|
||||
"outcome": null,
|
||||
"attempt": null,
|
||||
"status": ""
|
||||
},
|
||||
{
|
||||
"service": "messenger-api",
|
||||
"name": "SELECT",
|
||||
"kind": "SPAN_KIND_CLIENT",
|
||||
"ms": 0.17,
|
||||
"parent": "messenger-api: POST /api/v1/chats/{chat_id}/attachments",
|
||||
"outcome": null,
|
||||
"attempt": null,
|
||||
"status": ""
|
||||
},
|
||||
{
|
||||
"service": "messenger-api",
|
||||
"name": "pool.acquire",
|
||||
"kind": "SPAN_KIND_CLIENT",
|
||||
"ms": 0.01,
|
||||
"parent": "messenger-api: POST /api/v1/chats/{chat_id}/attachments",
|
||||
"outcome": null,
|
||||
"attempt": null,
|
||||
"status": ""
|
||||
},
|
||||
{
|
||||
"service": "messenger-api",
|
||||
"name": "SELECT",
|
||||
"kind": "SPAN_KIND_CLIENT",
|
||||
"ms": 0.26,
|
||||
"parent": "messenger-api: POST /api/v1/chats/{chat_id}/attachments",
|
||||
"outcome": null,
|
||||
"attempt": null,
|
||||
"status": ""
|
||||
},
|
||||
{
|
||||
"service": "messenger-api",
|
||||
"name": "SELECT",
|
||||
"kind": "SPAN_KIND_CLIENT",
|
||||
"ms": 0.1,
|
||||
"parent": "messenger-api: SELECT",
|
||||
"outcome": null,
|
||||
"attempt": null,
|
||||
"status": ""
|
||||
},
|
||||
{
|
||||
"service": "messenger-api",
|
||||
"name": "pool.acquire",
|
||||
"kind": "SPAN_KIND_CLIENT",
|
||||
"ms": 0.0,
|
||||
"parent": "messenger-api: POST /api/v1/chats/{chat_id}/attachments",
|
||||
"outcome": null,
|
||||
"attempt": null,
|
||||
"status": ""
|
||||
},
|
||||
{
|
||||
"service": "messenger-api",
|
||||
"name": "INSERT",
|
||||
"kind": "SPAN_KIND_CLIENT",
|
||||
"ms": 0.72,
|
||||
"parent": "messenger-api: POST /api/v1/chats/{chat_id}/attachments",
|
||||
"outcome": null,
|
||||
"attempt": null,
|
||||
"status": ""
|
||||
},
|
||||
{
|
||||
"service": "messenger-api",
|
||||
"name": "INSERT",
|
||||
"kind": "SPAN_KIND_CLIENT",
|
||||
"ms": 0.11,
|
||||
"parent": "messenger-api: INSERT",
|
||||
"outcome": null,
|
||||
"attempt": null,
|
||||
"status": ""
|
||||
},
|
||||
{
|
||||
"service": "messenger-api",
|
||||
"name": "S3 PUT",
|
||||
"kind": "SPAN_KIND_CLIENT",
|
||||
"ms": 4.88,
|
||||
"parent": "messenger-api: POST /api/v1/chats/{chat_id}/attachments",
|
||||
"outcome": null,
|
||||
"attempt": null,
|
||||
"status": ""
|
||||
},
|
||||
{
|
||||
"service": "messenger-api",
|
||||
"name": "pool.acquire",
|
||||
"kind": "SPAN_KIND_CLIENT",
|
||||
"ms": 0.01,
|
||||
"parent": "messenger-api: POST /api/v1/chats/{chat_id}/attachments",
|
||||
"outcome": null,
|
||||
"attempt": null,
|
||||
"status": ""
|
||||
},
|
||||
{
|
||||
"service": "messenger-api",
|
||||
"name": "BEGIN",
|
||||
"kind": "SPAN_KIND_CLIENT",
|
||||
"ms": 0.1,
|
||||
"parent": "messenger-api: POST /api/v1/chats/{chat_id}/attachments",
|
||||
"outcome": null,
|
||||
"attempt": null,
|
||||
"status": ""
|
||||
},
|
||||
{
|
||||
"service": "messenger-api",
|
||||
"name": "UPDATE",
|
||||
"kind": "SPAN_KIND_CLIENT",
|
||||
"ms": 0.61,
|
||||
"parent": "messenger-api: POST /api/v1/chats/{chat_id}/attachments",
|
||||
"outcome": null,
|
||||
"attempt": null,
|
||||
"status": ""
|
||||
},
|
||||
{
|
||||
"service": "messenger-api",
|
||||
"name": "UPDATE",
|
||||
"kind": "SPAN_KIND_CLIENT",
|
||||
"ms": 0.1,
|
||||
"parent": "messenger-api: UPDATE",
|
||||
"outcome": null,
|
||||
"attempt": null,
|
||||
"status": ""
|
||||
},
|
||||
{
|
||||
"service": "messenger-api",
|
||||
"name": "INSERT",
|
||||
"kind": "SPAN_KIND_CLIENT",
|
||||
"ms": 0.87,
|
||||
"parent": "messenger-api: POST /api/v1/chats/{chat_id}/attachments",
|
||||
"outcome": null,
|
||||
"attempt": null,
|
||||
"status": ""
|
||||
},
|
||||
{
|
||||
"service": "messenger-api",
|
||||
"name": "INSERT",
|
||||
"kind": "SPAN_KIND_CLIENT",
|
||||
"ms": 0.28,
|
||||
"parent": "messenger-api: INSERT",
|
||||
"outcome": null,
|
||||
"attempt": null,
|
||||
"status": ""
|
||||
},
|
||||
{
|
||||
"service": "messenger-api",
|
||||
"name": "INSERT",
|
||||
"kind": "SPAN_KIND_CLIENT",
|
||||
"ms": 0.92,
|
||||
"parent": "messenger-api: POST /api/v1/chats/{chat_id}/attachments",
|
||||
"outcome": null,
|
||||
"attempt": null,
|
||||
"status": ""
|
||||
},
|
||||
{
|
||||
"service": "messenger-api",
|
||||
"name": "INSERT",
|
||||
"kind": "SPAN_KIND_CLIENT",
|
||||
"ms": 0.25,
|
||||
"parent": "messenger-api: INSERT",
|
||||
"outcome": null,
|
||||
"attempt": null,
|
||||
"status": ""
|
||||
},
|
||||
{
|
||||
"service": "messenger-api",
|
||||
"name": "INSERT",
|
||||
"kind": "SPAN_KIND_CLIENT",
|
||||
"ms": 1.94,
|
||||
"parent": "messenger-api: POST /api/v1/chats/{chat_id}/attachments",
|
||||
"outcome": null,
|
||||
"attempt": null,
|
||||
"status": ""
|
||||
},
|
||||
{
|
||||
"service": "messenger-api",
|
||||
"name": "INSERT",
|
||||
"kind": "SPAN_KIND_CLIENT",
|
||||
"ms": 1.37,
|
||||
"parent": "messenger-api: INSERT",
|
||||
"outcome": null,
|
||||
"attempt": null,
|
||||
"status": ""
|
||||
},
|
||||
{
|
||||
"service": "messenger-api",
|
||||
"name": "COMMIT",
|
||||
"kind": "SPAN_KIND_CLIENT",
|
||||
"ms": 0.61,
|
||||
"parent": "messenger-api: POST /api/v1/chats/{chat_id}/attachments",
|
||||
"outcome": null,
|
||||
"attempt": null,
|
||||
"status": ""
|
||||
},
|
||||
{
|
||||
"service": "messenger-relay",
|
||||
"name": "attachment.process publish",
|
||||
"kind": "SPAN_KIND_PRODUCER",
|
||||
"ms": 1.07,
|
||||
"parent": "messenger-api: POST /api/v1/chats/{chat_id}/attachments",
|
||||
"outcome": null,
|
||||
"attempt": null,
|
||||
"status": ""
|
||||
},
|
||||
{
|
||||
"service": "messenger-worker",
|
||||
"name": "attachment.process process",
|
||||
"kind": "SPAN_KIND_CONSUMER",
|
||||
"ms": 30.84,
|
||||
"parent": "messenger-relay: attachment.process publish",
|
||||
"outcome": "done",
|
||||
"attempt": "1",
|
||||
"status": ""
|
||||
},
|
||||
{
|
||||
"service": "messenger-worker",
|
||||
"name": "pool.acquire",
|
||||
"kind": "SPAN_KIND_CLIENT",
|
||||
"ms": 0.28,
|
||||
"parent": "messenger-worker: attachment.process process",
|
||||
"outcome": null,
|
||||
"attempt": null,
|
||||
"status": ""
|
||||
},
|
||||
{
|
||||
"service": "messenger-worker",
|
||||
"name": "BEGIN",
|
||||
"kind": "SPAN_KIND_CLIENT",
|
||||
"ms": 0.07,
|
||||
"parent": "messenger-worker: attachment.process process",
|
||||
"outcome": null,
|
||||
"attempt": null,
|
||||
"status": ""
|
||||
},
|
||||
{
|
||||
"service": "messenger-worker",
|
||||
"name": "SELECT",
|
||||
"kind": "SPAN_KIND_CLIENT",
|
||||
"ms": 0.26,
|
||||
"parent": "messenger-worker: attachment.process process",
|
||||
"outcome": null,
|
||||
"attempt": null,
|
||||
"status": ""
|
||||
},
|
||||
{
|
||||
"service": "messenger-worker",
|
||||
"name": "SELECT",
|
||||
"kind": "SPAN_KIND_CLIENT",
|
||||
"ms": 0.08,
|
||||
"parent": "messenger-worker: attachment.process process",
|
||||
"outcome": null,
|
||||
"attempt": null,
|
||||
"status": ""
|
||||
},
|
||||
{
|
||||
"service": "messenger-worker",
|
||||
"name": "SELECT",
|
||||
"kind": "SPAN_KIND_CLIENT",
|
||||
"ms": 0.17,
|
||||
"parent": "messenger-worker: attachment.process process",
|
||||
"outcome": null,
|
||||
"attempt": null,
|
||||
"status": ""
|
||||
},
|
||||
{
|
||||
"service": "messenger-worker",
|
||||
"name": "UPDATE",
|
||||
"kind": "SPAN_KIND_CLIENT",
|
||||
"ms": 0.2,
|
||||
"parent": "messenger-worker: attachment.process process",
|
||||
"outcome": null,
|
||||
"attempt": null,
|
||||
"status": ""
|
||||
},
|
||||
{
|
||||
"service": "messenger-worker",
|
||||
"name": "UPDATE",
|
||||
"kind": "SPAN_KIND_CLIENT",
|
||||
"ms": 0.21,
|
||||
"parent": "messenger-worker: attachment.process process",
|
||||
"outcome": null,
|
||||
"attempt": null,
|
||||
"status": ""
|
||||
},
|
||||
{
|
||||
"service": "messenger-worker",
|
||||
"name": "INSERT",
|
||||
"kind": "SPAN_KIND_CLIENT",
|
||||
"ms": 0.1,
|
||||
"parent": "messenger-worker: attachment.process process",
|
||||
"outcome": null,
|
||||
"attempt": null,
|
||||
"status": ""
|
||||
},
|
||||
{
|
||||
"service": "messenger-worker",
|
||||
"name": "COMMIT",
|
||||
"kind": "SPAN_KIND_CLIENT",
|
||||
"ms": 0.13,
|
||||
"parent": "messenger-worker: attachment.process process",
|
||||
"outcome": null,
|
||||
"attempt": null,
|
||||
"status": ""
|
||||
},
|
||||
{
|
||||
"service": "messenger-worker",
|
||||
"name": "S3 HEAD",
|
||||
"kind": "SPAN_KIND_CLIENT",
|
||||
"ms": 0.91,
|
||||
"parent": "messenger-worker: attachment.process process",
|
||||
"outcome": null,
|
||||
"attempt": null,
|
||||
"status": ""
|
||||
},
|
||||
{
|
||||
"service": "messenger-worker",
|
||||
"name": "S3 GET",
|
||||
"kind": "SPAN_KIND_CLIENT",
|
||||
"ms": 1.19,
|
||||
"parent": "messenger-worker: attachment.process process",
|
||||
"outcome": null,
|
||||
"attempt": null,
|
||||
"status": ""
|
||||
},
|
||||
{
|
||||
"service": "messenger-worker",
|
||||
"name": "image.decode",
|
||||
"kind": "SPAN_KIND_INTERNAL",
|
||||
"ms": 1.74,
|
||||
"parent": "messenger-worker: attachment.process process",
|
||||
"outcome": null,
|
||||
"attempt": null,
|
||||
"status": ""
|
||||
},
|
||||
{
|
||||
"service": "messenger-worker",
|
||||
"name": "image.variants",
|
||||
"kind": "SPAN_KIND_INTERNAL",
|
||||
"ms": 16.56,
|
||||
"parent": "messenger-worker: attachment.process process",
|
||||
"outcome": null,
|
||||
"attempt": null,
|
||||
"status": ""
|
||||
},
|
||||
{
|
||||
"service": "messenger-worker",
|
||||
"name": "S3 PUT",
|
||||
"kind": "SPAN_KIND_CLIENT",
|
||||
"ms": 1.29,
|
||||
"parent": "messenger-worker: attachment.process process",
|
||||
"outcome": null,
|
||||
"attempt": null,
|
||||
"status": ""
|
||||
},
|
||||
{
|
||||
"service": "messenger-worker",
|
||||
"name": "S3 PUT",
|
||||
"kind": "SPAN_KIND_CLIENT",
|
||||
"ms": 0.99,
|
||||
"parent": "messenger-worker: attachment.process process",
|
||||
"outcome": null,
|
||||
"attempt": null,
|
||||
"status": ""
|
||||
}
|
||||
],
|
||||
"worker_log_events": [
|
||||
"job.claimed",
|
||||
"job.done"
|
||||
]
|
||||
},
|
||||
"metrics": {
|
||||
"found": {
|
||||
"http requests (counter = _count)": {
|
||||
"series": 16,
|
||||
"names": [
|
||||
"http_server_request_duration_seconds_count"
|
||||
]
|
||||
},
|
||||
"http duration histogram (s)": {
|
||||
"series": 224,
|
||||
"names": [
|
||||
"http_server_request_duration_seconds_bucket"
|
||||
]
|
||||
},
|
||||
"jobs processed by outcome": {
|
||||
"series": 6,
|
||||
"names": [
|
||||
"messenger_jobs_processed_total"
|
||||
]
|
||||
},
|
||||
"job duration histogram (s)": {
|
||||
"series": 56,
|
||||
"names": [
|
||||
"messenger_job_duration_seconds_bucket"
|
||||
]
|
||||
},
|
||||
"time to ready histogram (s)": {
|
||||
"series": 28,
|
||||
"names": [
|
||||
"messenger_attachment_time_to_ready_seconds_bucket"
|
||||
]
|
||||
},
|
||||
"queue backlog by state": {
|
||||
"series": 3,
|
||||
"names": [
|
||||
"messenger_jobs_backlog"
|
||||
]
|
||||
},
|
||||
"oldest job age (s)": {
|
||||
"series": 1,
|
||||
"names": [
|
||||
"messenger_jobs_oldest_age_seconds"
|
||||
]
|
||||
},
|
||||
"outbox pending": {
|
||||
"series": 1,
|
||||
"names": [
|
||||
"messenger_outbox_pending"
|
||||
]
|
||||
},
|
||||
"rabbitmq queue messages": {
|
||||
"series": 2,
|
||||
"names": [
|
||||
"rabbitmq_queue_messages_ready"
|
||||
]
|
||||
},
|
||||
"worker busy": {
|
||||
"series": 2,
|
||||
"names": [
|
||||
"messenger_worker_busy"
|
||||
]
|
||||
},
|
||||
"worker capacity": {
|
||||
"series": 2,
|
||||
"names": [
|
||||
"messenger_worker_capacity"
|
||||
]
|
||||
},
|
||||
"db pool acquired": {
|
||||
"series": 5,
|
||||
"names": [
|
||||
"pgxpool_acquired_connections"
|
||||
]
|
||||
},
|
||||
"db pool waits": {
|
||||
"series": 10,
|
||||
"names": [
|
||||
"pgxpool_empty_acquire_total",
|
||||
"pgxpool_empty_acquire_wait_time_nanoseconds_total"
|
||||
]
|
||||
},
|
||||
"process cpu": {
|
||||
"series": 10,
|
||||
"names": [
|
||||
"process_cpu_time_seconds_total"
|
||||
]
|
||||
},
|
||||
"go memory": {
|
||||
"series": 10,
|
||||
"names": [
|
||||
"go_memory_used_bytes"
|
||||
]
|
||||
}
|
||||
},
|
||||
"labels_total": 129,
|
||||
"forbidden_labels": [],
|
||||
"http_route_values": [
|
||||
"/api/v1/attachments/{attachment_id}",
|
||||
"/api/v1/attachments/{attachment_id}/content",
|
||||
"/api/v1/auth/sessions",
|
||||
"/api/v1/chats",
|
||||
"/api/v1/chats/{chat_id}/attachments",
|
||||
"/api/v1/chats/{chat_id}/messages",
|
||||
"/api/v1/users",
|
||||
"/health/live",
|
||||
"/health/ready"
|
||||
],
|
||||
"example_series_labels": [
|
||||
"__name__",
|
||||
"http_request_method",
|
||||
"http_response_status_class",
|
||||
"http_response_status_code",
|
||||
"http_route",
|
||||
"instance",
|
||||
"job"
|
||||
]
|
||||
},
|
||||
"leak_check": {
|
||||
"loki:password": 0,
|
||||
"loki:session_token": 0,
|
||||
"loki:message_text": 0,
|
||||
"loki:bearer_header": 0,
|
||||
"tempo:password": 0,
|
||||
"tempo:session_token": 0,
|
||||
"tempo:message_text": 0,
|
||||
"tempo:bearer_header": 0,
|
||||
"stdout:password": 0,
|
||||
"stdout:session_token": 0,
|
||||
"stdout:message_text": 0,
|
||||
"stdout:bearer_header": 0
|
||||
},
|
||||
"grafana": {
|
||||
"datasources": [
|
||||
"loki:loki",
|
||||
"prometheus:prometheus",
|
||||
"tempo:tempo"
|
||||
],
|
||||
"dashboard": "Messenger — API, worker, очередь",
|
||||
"panels": 30,
|
||||
"prometheus_targets": 39,
|
||||
"targets_without_data_now": [
|
||||
{
|
||||
"panel": "Ready быстрее 30 s (5m)",
|
||||
"legend": "",
|
||||
"series": 0
|
||||
}
|
||||
],
|
||||
"targets": [
|
||||
{
|
||||
"panel": "RPS API (бизнес)",
|
||||
"legend": "",
|
||||
"series": 1
|
||||
},
|
||||
{
|
||||
"panel": "Доля 5xx (1m)",
|
||||
"legend": "",
|
||||
"series": 1
|
||||
},
|
||||
{
|
||||
"panel": "Быстрее 250 ms (5m)",
|
||||
"legend": "",
|
||||
"series": 1
|
||||
},
|
||||
{
|
||||
"panel": "Ready быстрее 30 s (5m)",
|
||||
"legend": "",
|
||||
"series": 0
|
||||
},
|
||||
{
|
||||
"panel": "Старейшая job",
|
||||
"legend": "",
|
||||
"series": 1
|
||||
},
|
||||
{
|
||||
"panel": "Alerts firing",
|
||||
"legend": "",
|
||||
"series": 1
|
||||
},
|
||||
{
|
||||
"panel": "RPS по маршруту и классу ответа",
|
||||
"legend": "{{http_route}} {{http_response_status_class}}",
|
||||
"series": 9
|
||||
},
|
||||
{
|
||||
"panel": "Задержка API p50 / p95 / p99 (все реплики)",
|
||||
"legend": "p50",
|
||||
"series": 1
|
||||
},
|
||||
{
|
||||
"panel": "Задержка API p50 / p95 / p99 (все реплики)",
|
||||
"legend": "p95",
|
||||
"series": 1
|
||||
},
|
||||
{
|
||||
"panel": "Задержка API p50 / p95 / p99 (все реплики)",
|
||||
"legend": "p99",
|
||||
"series": 1
|
||||
},
|
||||
{
|
||||
"panel": "Доля ошибок 5xx и 4xx",
|
||||
"legend": "5xx / все",
|
||||
"series": 1
|
||||
},
|
||||
{
|
||||
"panel": "Доля ошибок 5xx и 4xx",
|
||||
"legend": "4xx / все (ошибки клиента)",
|
||||
"series": 1
|
||||
},
|
||||
{
|
||||
"panel": "p95 по маршруту",
|
||||
"legend": "{{http_route}}",
|
||||
"series": 7
|
||||
},
|
||||
{
|
||||
"panel": "Запросы в обработке (in-flight) по реплике",
|
||||
"legend": "{{instance}}",
|
||||
"series": 2
|
||||
},
|
||||
{
|
||||
"panel": "Jobs по исходу (rate)",
|
||||
"legend": "{{outcome}}",
|
||||
"series": 5
|
||||
},
|
||||
{
|
||||
"panel": "Длительность обработки job p50 / p95 / p99",
|
||||
"legend": "p50",
|
||||
"series": 1
|
||||
},
|
||||
{
|
||||
"panel": "Длительность обработки job p50 / p95 / p99",
|
||||
"legend": "p95",
|
||||
"series": 1
|
||||
},
|
||||
{
|
||||
"panel": "Длительность обработки job p50 / p95 / p99",
|
||||
"legend": "p99",
|
||||
"series": 1
|
||||
},
|
||||
{
|
||||
"panel": "Время до ready (202 → ready) p50 / p95",
|
||||
"legend": "p50",
|
||||
"series": 1
|
||||
},
|
||||
{
|
||||
"panel": "Время до ready (202 → ready) p50 / p95",
|
||||
"legend": "p95",
|
||||
"series": 1
|
||||
},
|
||||
{
|
||||
"panel": "Очередь: jobs по состоянию (PostgreSQL)",
|
||||
"legend": "{{state}}",
|
||||
"series": 3
|
||||
},
|
||||
{
|
||||
"panel": "Очередь: jobs по состоянию (PostgreSQL)",
|
||||
"legend": "outbox не опубликовано",
|
||||
"series": 1
|
||||
},
|
||||
{
|
||||
"panel": "Возраст старейшей job / outbox",
|
||||
"legend": "job (queued/processing)",
|
||||
"series": 1
|
||||
},
|
||||
{
|
||||
"panel": "Возраст старейшей job / outbox",
|
||||
"legend": "outbox",
|
||||
"series": 1
|
||||
},
|
||||
{
|
||||
"panel": "RabbitMQ: сообщения в очередях",
|
||||
"legend": "ready {{queue}}",
|
||||
"series": 2
|
||||
},
|
||||
{
|
||||
"panel": "RabbitMQ: сообщения в очередях",
|
||||
"legend": "unacked {{queue}}",
|
||||
"series": 2
|
||||
},
|
||||
{
|
||||
"panel": "Saturation worker (busy / capacity)",
|
||||
"legend": "занято слотов",
|
||||
"series": 1
|
||||
},
|
||||
{
|
||||
"panel": "Publish outbox → broker (confirm) p95",
|
||||
"legend": "p95",
|
||||
"series": 1
|
||||
},
|
||||
{
|
||||
"panel": "Publish outbox → broker (confirm) p95",
|
||||
"legend": "сообщений/с",
|
||||
"series": 1
|
||||
},
|
||||
{
|
||||
"panel": "Пул БД: занято / ожидания",
|
||||
"legend": "занято {{job}}",
|
||||
"series": 3
|
||||
},
|
||||
{
|
||||
"panel": "Пул БД: занято / ожидания",
|
||||
"legend": "max {{job}}",
|
||||
"series": 3
|
||||
},
|
||||
{
|
||||
"panel": "Пул БД: занято / ожидания",
|
||||
"legend": "ожиданий/с {{job}}",
|
||||
"series": 3
|
||||
},
|
||||
{
|
||||
"panel": "CPU процессов",
|
||||
"legend": "{{job}} {{instance}}",
|
||||
"series": 8
|
||||
},
|
||||
{
|
||||
"panel": "Память Go (used)",
|
||||
"legend": "{{job}} {{instance}}",
|
||||
"series": 5
|
||||
},
|
||||
{
|
||||
"panel": "Collector: принято / отправлено / потеряно spans",
|
||||
"legend": "принято",
|
||||
"series": 1
|
||||
},
|
||||
{
|
||||
"panel": "Collector: принято / отправлено / потеряно spans",
|
||||
"legend": "отправлено",
|
||||
"series": 1
|
||||
},
|
||||
{
|
||||
"panel": "Collector: принято / отправлено / потеряно spans",
|
||||
"legend": "не доставлено",
|
||||
"series": 1
|
||||
},
|
||||
{
|
||||
"panel": "Collector: принято / отправлено / потеряно spans",
|
||||
"legend": "отклонено (memory_limiter)",
|
||||
"series": 1
|
||||
},
|
||||
{
|
||||
"panel": "Collector: принято / отправлено / потеряно spans",
|
||||
"legend": "очередь экспортёров",
|
||||
"series": 1
|
||||
}
|
||||
]
|
||||
},
|
||||
"attachment": {
|
||||
"id": "acee78cc-11ee-453d-9696-426654a97f27",
|
||||
"status": "ready"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"scenario": "transient",
|
||||
"result": {
|
||||
"attachment_id": "570e91a8-1d7c-425f-9d03-170050581f4a",
|
||||
"attempts": 3,
|
||||
"final_status": "ready",
|
||||
"retry_details": "processing_failed; next_attempt=2 in 1.999s | processing_failed; next_attempt=3 in 3.134s",
|
||||
"events": "enqueued,claimed,retry_scheduled,claimed,retry_scheduled,claimed,done",
|
||||
"invariants": {
|
||||
"status": "ready",
|
||||
"published_version": 1,
|
||||
"objects_per_version": {
|
||||
"1": 3
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
2
|
||||
total used free shared buff/cache available
|
||||
Mem: 7776 1885 1172 90 5114 5890
|
||||
Swap: 3071 0 3071
|
||||
28.0.4
|
||||
Docker Compose version v2.38.2
|
||||
@@ -0,0 +1,5 @@
|
||||
# Доказательства
|
||||
|
||||
Храните небольшие обезличенные результаты: команды и stdout проверок, JSON/CSV агрегатов нагрузки, EXPLAIN, dashboard JSON, текст разбора отказа. Укажите дату, commit, аппаратные лимиты и профиль нагрузки.
|
||||
|
||||
Не добавляйте .env, session tokens, cookies, приватные ключи, credentials, реальные сообщения, raw dumps и signed URLs. Для скриншотов скрывайте секреты. Большие логи/бинарные traces сохраняйте отдельно по правилам преподавателя; одного скриншота без методики недостаточно.
|
||||
@@ -0,0 +1,33 @@
|
||||
# Разбор сканирования зависимостей и образов
|
||||
|
||||
Прогон: https://github.com/CharaWein/2026_lab3/actions/runs/43267046991 (commit a414221).
|
||||
Инструменты: govulncheck v1.1.4 (Go-код, анализ достижимости), Trivy 0.58.1 (`--severity HIGH,CRITICAL --scanners vuln`).
|
||||
Полные JSON Trivy в репозиторий не кладутся (около 1.7 MiB); здесь сводка и решения.
|
||||
|
||||
## Код приложения (govulncheck)
|
||||
|
||||
`govulncheck.txt`: **0 уязвимостей в вызываемом коде**. В модулях-зависимостях найдено 2 уязвимости, но код
|
||||
их не вызывает (символов нет в графе вызовов) — неприменимо.
|
||||
|
||||
История: на Go 1.26.0 govulncheck показывал 38 достижимых уязвимостей стандартной библиотеки
|
||||
(crypto/tls, net/http, crypto/x509 — всё это используется: TLS-сервер API, mTLS-клиенты). Исправлено переходом
|
||||
на Go 1.26.11 (`go.mod toolchain`, `golang:1.26.11-alpine` в Dockerfile) и `golang.org/x/net v0.62.0`.
|
||||
|
||||
## Образ приложения mtusi2026lab7-api:local
|
||||
|
||||
**0 HIGH/CRITICAL.** До исправления — 2 HIGH: musl / musl-utils CVE-2026-107891 (1.2.5-r3, исправлено в 1.2.5-r4).
|
||||
Исправление — `apk --no-cache upgrade` в runtime-слое Dockerfile.
|
||||
|
||||
## Сторонние образы стенда
|
||||
|
||||
| Образ | HIGH/CRITICAL | Есть исправленная версия | Где | Применимость и решение |
|
||||
| --- | --- | --- | --- | --- |
|
||||
| postgres:16.4-alpine | 31 (OS) + 60 (gosu) | все | OpenSSL 3.3.2, libxml2/libxslt, musl, zlib; `gosu` собран Go 1.18 | OpenSSL: PostgreSQL принимает TLS только из сети `back` (порт не опубликован) — ошибки разбора сертификатов/CMS/PKCS#12 достижимы лишь для процесса внутри стенда; libxml2/libxslt — только XML-функции SQL, приложение их не вызывает; `gosu` работает один раз при старте (смена пользователя), сетевых обработчиков Go не содержит. **Решение:** обновить до последнего патча 16.x (тот же major, миграции не нужны) — следующий шаг. |
|
||||
| redis:7.4.1-alpine | 23 (OS) + 60 (gosu) | все | OpenSSL, musl, zlib; `gosu` | TLS-порт Redis только в сети `back`, plaintext выключен (`port 0`), ACL `default off`. **Решение:** обновить до последнего 7.4.x. |
|
||||
| haproxy:3.0.5-alpine | 23 (OS) | все | OpenSSL 3.3.2, musl, zlib | **Самое применимое**: HAProxy — единственный TLS ingress, опубликован на `127.0.0.1:8443` и терминирует TLS клиентов. CVE-2025-15467 (переполнение при разборе) и CVE-2026-28387 (use-after-free) касаются OpenSSL, который обрабатывает внешние handshake. Смягчение сейчас: публикация только на loopback хоста, TLS ≥ 1.2. **Решение:** обновить до последнего 3.0.x — первое в списке. |
|
||||
| openbao/openbao:2.1.0 | 28 (OS) + 63 (bin/bao) | 87 из 91 | OpenSSL, musl, libcap; в бинарнике — stdlib Go, x/crypto, x/net, grpc, go-jose, docker/docker | OpenBao слушает только сеть `back` и `127.0.0.1` хоста. Модули docker/docker и pgproto3 относятся к неиспользуемым плагинам (secrets engines Docker/PostgreSQL у нас не включены); stdlib/x/net/x/crypto — применимы к его TLS-листенеру. **Решение:** обновить до актуального 2.x (данные — file storage, совместимы). |
|
||||
| rabbitmq:4.0.9-alpine | 0 | — | — | — |
|
||||
|
||||
Итого: в собственном коде и образе HIGH/CRITICAL нет; в сторонних образах находки есть, почти все имеют исправленную
|
||||
версию, но обновление версий сторонних компонентов в этой работе не сделано — оно меняет поведение стенда и требует
|
||||
отдельного прогона всех сценариев. Это осознанно оставленный риск с порядком обновления: haproxy → openbao → postgres → redis.
|
||||
@@ -0,0 +1,9 @@
|
||||
=== Symbol Results ===
|
||||
|
||||
No vulnerabilities found.
|
||||
|
||||
Your code is affected by 0 vulnerabilities.
|
||||
This scan also found 0 vulnerabilities in packages you import and 2
|
||||
vulnerabilities in modules you require, but your code doesn't appear to call
|
||||
these vulnerabilities.
|
||||
Use '-show verbose' for more details.
|
||||
@@ -0,0 +1,6 @@
|
||||
mtusi2026lab7-api:local 0 HIGH/CRITICAL []
|
||||
postgres:16.4-alpine 91 HIGH/CRITICAL ['libcrypto3', 'libssl3', 'libxml2', 'libxslt', 'musl', 'musl-utils', 'stdlib', 'xz-libs', 'zlib']
|
||||
redis:7.4.1-alpine 83 HIGH/CRITICAL ['libcrypto3', 'libssl3', 'musl', 'musl-utils', 'stdlib', 'zlib']
|
||||
rabbitmq:4.0.9-alpine 0 HIGH/CRITICAL []
|
||||
haproxy:3.0.5-alpine 23 HIGH/CRITICAL ['libcrypto3', 'libssl3', 'musl', 'musl-utils', 'zlib']
|
||||
openbao/openbao:2.1.0 91 HIGH/CRITICAL ['github.com/docker/docker', 'github.com/go-jose/go-jose/v3', 'github.com/golang-jwt/jwt/v4', 'github.com/golang-jwt/jwt/v5', 'github.com/jackc/pgproto3/v2', 'github.com/klauspost/compress', 'go.opentelemetry.io/otel/sdk', 'golang.org/x/crypto', 'golang.org/x/net', 'golang.org/x/oauth2', 'golang.org/x/text', 'google.golang.org/grpc', 'libcap', 'libcap-getcap', 'libcap-setcap']
|
||||
@@ -0,0 +1,5 @@
|
||||
# Доказательства
|
||||
|
||||
Храните небольшие обезличенные результаты: команды и stdout проверок, JSON/CSV агрегатов нагрузки, EXPLAIN, dashboard JSON, текст разбора отказа. Укажите дату, commit, аппаратные лимиты и профиль нагрузки.
|
||||
|
||||
Не добавляйте .env, session tokens, cookies, приватные ключи, credentials, реальные сообщения, raw dumps и signed URLs. Для скриншотов скрывайте секреты. Большие логи/бинарные traces сохраняйте отдельно по правилам преподавателя; одного скриншота без методики недостаточно.
|
||||
@@ -0,0 +1,17 @@
|
||||
/mtusi2026lab7-api-1 restarts=0 oom_killed=false exit=0
|
||||
/mtusi2026lab7-api-2 restarts=0 oom_killed=false exit=0
|
||||
/mtusi2026lab7-grafana-1 restarts=0 oom_killed=false exit=0
|
||||
/mtusi2026lab7-lb-1 restarts=0 oom_killed=false exit=0
|
||||
/mtusi2026lab7-loki-1 restarts=0 oom_killed=false exit=0
|
||||
/mtusi2026lab7-openbao-1 restarts=0 oom_killed=false exit=0
|
||||
/mtusi2026lab7-otel-collector-1 restarts=0 oom_killed=false exit=0
|
||||
/mtusi2026lab7-postgres-1 restarts=0 oom_killed=false exit=0
|
||||
/mtusi2026lab7-prometheus-1 restarts=0 oom_killed=false exit=0
|
||||
/mtusi2026lab7-rabbitmq-1 restarts=0 oom_killed=false exit=0
|
||||
/mtusi2026lab7-reconciler-1 restarts=0 oom_killed=false exit=0
|
||||
/mtusi2026lab7-redis-1 restarts=0 oom_killed=false exit=0
|
||||
/mtusi2026lab7-relay-1 restarts=0 oom_killed=false exit=0
|
||||
/mtusi2026lab7-s3-1 restarts=0 oom_killed=false exit=0
|
||||
/mtusi2026lab7-tempo-1 restarts=0 oom_killed=false exit=0
|
||||
/mtusi2026lab7-tempo-init-1 restarts=0 oom_killed=false exit=0
|
||||
/mtusi2026lab7-worker-1 restarts=0 oom_killed=false exit=0
|
||||
@@ -0,0 +1,18 @@
|
||||
NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
|
||||
mtusi2026lab7-api-1 mtusi2026lab7-api:local "/app/api" api 5 minutes ago Up 2 minutes (healthy) 8443/tcp
|
||||
mtusi2026lab7-api-2 mtusi2026lab7-api:local "/app/api" api 5 minutes ago Up 2 minutes (healthy) 8443/tcp
|
||||
mtusi2026lab7-grafana-1 grafana/grafana:11.4.0 "/run.sh" grafana 6 minutes ago Up 6 minutes (healthy) 127.0.0.1:3000->3000/tcp
|
||||
mtusi2026lab7-lb-1 haproxy:3.0.5-alpine "docker-entrypoint.s…" lb 6 minutes ago Up 6 minutes 127.0.0.1:8443->8443/tcp
|
||||
mtusi2026lab7-loki-1 grafana/loki:3.3.2 "/usr/bin/loki -conf…" loki 6 minutes ago Up 6 minutes 3100/tcp
|
||||
mtusi2026lab7-openbao-1 openbao/openbao:2.1.0 "docker-entrypoint.s…" openbao 7 minutes ago Up 5 minutes 127.0.0.1:8200->8200/tcp
|
||||
mtusi2026lab7-otel-collector-1 otel/opentelemetry-collector-contrib:0.116.1 "/otelcol-contrib --…" otel-collector 6 minutes ago Up 6 minutes 4317-4318/tcp, 55678-55679/tcp
|
||||
mtusi2026lab7-postgres-1 postgres:16.4-alpine "sh -c 'install -o p…" postgres 7 minutes ago Up 7 minutes (healthy) 5432/tcp
|
||||
mtusi2026lab7-prometheus-1 prom/prometheus:v3.1.0 "/bin/prometheus --c…" prometheus 6 minutes ago Up 6 minutes 9090/tcp
|
||||
mtusi2026lab7-rabbitmq-1 rabbitmq:4.0.9-alpine "docker-entrypoint.s…" rabbitmq 7 minutes ago Up 7 minutes (healthy) 4369/tcp, 5671-5672/tcp, 15691-15692/tcp, 25672/tcp
|
||||
mtusi2026lab7-reconciler-1 mtusi2026lab7-api:local "/app/reconcile --ap…" reconciler 6 minutes ago Up 6 minutes (healthy) 8443/tcp
|
||||
mtusi2026lab7-redis-1 redis:7.4.1-alpine "docker-entrypoint.s…" redis 7 minutes ago Up 7 minutes (healthy) 6379/tcp
|
||||
mtusi2026lab7-relay-1 mtusi2026lab7-api:local "/app/pipeline relay" relay 6 minutes ago Up 6 minutes (healthy) 8443/tcp
|
||||
mtusi2026lab7-s3-1 bitnamilegacy/minio:2025.4.22@sha256:50cec18ac4184af4671a78aedd5554942c8ae105d51a465fa82037949046da01 "/bin/bash -c 'mkdir…" s3 7 minutes ago Up 7 minutes (healthy) 9000-9001/tcp
|
||||
mtusi2026lab7-tempo-1 grafana/tempo:2.6.1 "/tempo -config.file…" tempo 6 minutes ago Up 6 minutes
|
||||
mtusi2026lab7-tempo-init-1 grafana/tempo:2.6.1 "chown 10001:10001 /…" tempo-init 6 minutes ago Exited (0) 6 minutes ago
|
||||
mtusi2026lab7-worker-1 mtusi2026lab7-api:local "/app/pipeline worker" worker 6 minutes ago Up About a minute (healthy) 8443/tcp
|
||||
@@ -0,0 +1,16 @@
|
||||
mtusi2026lab7-api-2 2.01% 129.7MiB / 256MiB
|
||||
mtusi2026lab7-api-1 2.02% 112.4MiB / 256MiB
|
||||
mtusi2026lab7-grafana-1 0.20% 56.66MiB / 256MiB
|
||||
mtusi2026lab7-lb-1 0.28% 21.39MiB / 128MiB
|
||||
mtusi2026lab7-tempo-1 0.19% 188.7MiB / 1GiB
|
||||
mtusi2026lab7-relay-1 0.17% 12.81MiB / 128MiB
|
||||
mtusi2026lab7-worker-1 0.01% 14.2MiB / 768MiB
|
||||
mtusi2026lab7-otel-collector-1 0.18% 57.44MiB / 256MiB
|
||||
mtusi2026lab7-loki-1 0.36% 109.2MiB / 1GiB
|
||||
mtusi2026lab7-prometheus-1 0.33% 41.64MiB / 512MiB
|
||||
mtusi2026lab7-reconciler-1 0.00% 5.207MiB / 128MiB
|
||||
mtusi2026lab7-redis-1 0.44% 6.051MiB / 256MiB
|
||||
mtusi2026lab7-rabbitmq-1 0.14% 92.3MiB / 512MiB
|
||||
mtusi2026lab7-s3-1 5.80% 402.9MiB / 512MiB
|
||||
mtusi2026lab7-postgres-1 0.25% 100.3MiB / 512MiB
|
||||
mtusi2026lab7-openbao-1 0.27% 22MiB / 256MiB
|
||||
@@ -0,0 +1,6 @@
|
||||
2
|
||||
total used free shared buff/cache available
|
||||
Mem: 7776 2486 427 114 5283 5289
|
||||
Swap: 3071 0 3071
|
||||
28.0.4
|
||||
Docker Compose version v2.38.2
|
||||
@@ -0,0 +1,39 @@
|
||||
{
|
||||
"scenario": "acl",
|
||||
"result": {
|
||||
"outsider_metadata": 404,
|
||||
"outsider_content": 404,
|
||||
"attach_foreign_file": 404,
|
||||
"fake_x_user_id_with_eve_token": 404,
|
||||
"x_user_id_without_token": 401,
|
||||
"after_logout": 401,
|
||||
"json_body_65KiB": 413,
|
||||
"stored_hash_params": "argon2id m=19456,t=2,p=1",
|
||||
"rehash": {
|
||||
"before": "m=65536,t=1,p=4",
|
||||
"after": "m=19456,t=2,p=1"
|
||||
},
|
||||
"login_rate_limit": {
|
||||
"codes": [
|
||||
401,
|
||||
401,
|
||||
401,
|
||||
401,
|
||||
401,
|
||||
401,
|
||||
401,
|
||||
401,
|
||||
401,
|
||||
401,
|
||||
429,
|
||||
429,
|
||||
429,
|
||||
429
|
||||
],
|
||||
"retry_after": "58",
|
||||
"served_by_replicas": 2
|
||||
},
|
||||
"correct_password_while_limited": 429,
|
||||
"after_ttl_expiry": 401
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
{
|
||||
"scenario": "argon2",
|
||||
"result": {
|
||||
"bench": {
|
||||
"current": {
|
||||
"MemoryKiB": 19456,
|
||||
"Iterations": 2,
|
||||
"Parallelism": 1
|
||||
},
|
||||
"results": [
|
||||
{
|
||||
"hashes_per_s_one_core": 13.908012405947067,
|
||||
"m_kib": 19456,
|
||||
"ms_max": 78.569,
|
||||
"ms_p50": 71.901,
|
||||
"p": 1,
|
||||
"t": 2
|
||||
},
|
||||
{
|
||||
"hashes_per_s_one_core": 12.071900237816434,
|
||||
"m_kib": 47104,
|
||||
"ms_max": 101.575,
|
||||
"ms_p50": 82.837,
|
||||
"p": 1,
|
||||
"t": 1
|
||||
},
|
||||
{
|
||||
"hashes_per_s_one_core": 12.013166430407725,
|
||||
"m_kib": 19456,
|
||||
"ms_max": 107.157,
|
||||
"ms_p50": 83.242,
|
||||
"p": 1,
|
||||
"t": 3
|
||||
},
|
||||
{
|
||||
"hashes_per_s_one_core": 9.137927883473143,
|
||||
"m_kib": 65536,
|
||||
"ms_max": 209.469,
|
||||
"ms_p50": 109.434,
|
||||
"p": 4,
|
||||
"t": 1
|
||||
},
|
||||
{
|
||||
"hashes_per_s_one_core": 3.6552245952752567,
|
||||
"m_kib": 65536,
|
||||
"ms_max": 295.643,
|
||||
"ms_p50": 273.581,
|
||||
"p": 1,
|
||||
"t": 3
|
||||
}
|
||||
]
|
||||
},
|
||||
"login_latency_ms_sequential": [
|
||||
62.4,
|
||||
26.9,
|
||||
26.6,
|
||||
26.9,
|
||||
26.4,
|
||||
26.2,
|
||||
27.7,
|
||||
27.2
|
||||
],
|
||||
"dos_burst": {
|
||||
"attempts": 120,
|
||||
"seconds": 2.92,
|
||||
"codes": {
|
||||
"401": 59,
|
||||
"429": 61
|
||||
},
|
||||
"api_mem_peak_mib": [
|
||||
197.0,
|
||||
131.2
|
||||
],
|
||||
"api_mem_before_mib": [
|
||||
66.0,
|
||||
67.2
|
||||
]
|
||||
},
|
||||
"budget": {
|
||||
"hash_ms_p50": 71.901,
|
||||
"argon2_slots_per_replica": 2,
|
||||
"replicas": 2,
|
||||
"max_hashes_per_s_stand": 55.6,
|
||||
"argon2_memory_bound_mib": 76.0,
|
||||
"per_ip_limit_per_min": 60,
|
||||
"per_user_limit_per_min": 10
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,313 @@
|
||||
{
|
||||
"scenario": "hardening",
|
||||
"result": {
|
||||
"api": {
|
||||
"user": "1001:1001",
|
||||
"read_only": true,
|
||||
"privileged": false,
|
||||
"cap_drop": [
|
||||
"ALL"
|
||||
],
|
||||
"cap_add": null,
|
||||
"no_new_privileges": true,
|
||||
"network_mode": "mtusi2026lab7_back",
|
||||
"pid_mode": "",
|
||||
"docker_sock": false,
|
||||
"memory_limit_mib": 256,
|
||||
"nano_cpus": 500000000,
|
||||
"pids_limit": 256,
|
||||
"published": [],
|
||||
"process_uid": "1001"
|
||||
},
|
||||
"grafana": {
|
||||
"user": "472",
|
||||
"read_only": false,
|
||||
"privileged": false,
|
||||
"cap_drop": [
|
||||
"ALL"
|
||||
],
|
||||
"cap_add": null,
|
||||
"no_new_privileges": true,
|
||||
"network_mode": "mtusi2026lab7_telemetry",
|
||||
"pid_mode": "",
|
||||
"docker_sock": false,
|
||||
"memory_limit_mib": 256,
|
||||
"nano_cpus": 500000000,
|
||||
"pids_limit": 256,
|
||||
"published": [
|
||||
"127.0.0.1:3000->3000/tcp"
|
||||
]
|
||||
},
|
||||
"lb": {
|
||||
"user": "haproxy",
|
||||
"read_only": true,
|
||||
"privileged": false,
|
||||
"cap_drop": [
|
||||
"ALL"
|
||||
],
|
||||
"cap_add": null,
|
||||
"no_new_privileges": true,
|
||||
"network_mode": "mtusi2026lab7_front",
|
||||
"pid_mode": "",
|
||||
"docker_sock": false,
|
||||
"memory_limit_mib": 128,
|
||||
"nano_cpus": 500000000,
|
||||
"pids_limit": 256,
|
||||
"published": [
|
||||
"127.0.0.1:8443->8443/tcp"
|
||||
]
|
||||
},
|
||||
"loki": {
|
||||
"user": "10001",
|
||||
"read_only": true,
|
||||
"privileged": false,
|
||||
"cap_drop": [
|
||||
"ALL"
|
||||
],
|
||||
"cap_add": null,
|
||||
"no_new_privileges": true,
|
||||
"network_mode": "mtusi2026lab7_telemetry",
|
||||
"pid_mode": "",
|
||||
"docker_sock": false,
|
||||
"memory_limit_mib": 1024,
|
||||
"nano_cpus": 500000000,
|
||||
"pids_limit": 256,
|
||||
"published": []
|
||||
},
|
||||
"openbao": {
|
||||
"user": "root(image default)",
|
||||
"read_only": false,
|
||||
"privileged": false,
|
||||
"cap_drop": [
|
||||
"ALL"
|
||||
],
|
||||
"cap_add": [
|
||||
"CAP_CHOWN",
|
||||
"CAP_DAC_OVERRIDE",
|
||||
"CAP_FOWNER",
|
||||
"CAP_SETGID",
|
||||
"CAP_SETUID"
|
||||
],
|
||||
"no_new_privileges": true,
|
||||
"network_mode": "mtusi2026lab7_back",
|
||||
"pid_mode": "",
|
||||
"docker_sock": false,
|
||||
"memory_limit_mib": 256,
|
||||
"nano_cpus": 500000000,
|
||||
"pids_limit": 256,
|
||||
"published": [
|
||||
"127.0.0.1:8200->8200/tcp"
|
||||
]
|
||||
},
|
||||
"otel-collector": {
|
||||
"user": "10001",
|
||||
"read_only": true,
|
||||
"privileged": false,
|
||||
"cap_drop": [
|
||||
"ALL"
|
||||
],
|
||||
"cap_add": null,
|
||||
"no_new_privileges": true,
|
||||
"network_mode": "mtusi2026lab7_telemetry",
|
||||
"pid_mode": "",
|
||||
"docker_sock": false,
|
||||
"memory_limit_mib": 256,
|
||||
"nano_cpus": 500000000,
|
||||
"pids_limit": 256,
|
||||
"published": []
|
||||
},
|
||||
"postgres": {
|
||||
"user": "root(image default)",
|
||||
"read_only": false,
|
||||
"privileged": false,
|
||||
"cap_drop": [
|
||||
"ALL"
|
||||
],
|
||||
"cap_add": [
|
||||
"CAP_CHOWN",
|
||||
"CAP_DAC_OVERRIDE",
|
||||
"CAP_FOWNER",
|
||||
"CAP_SETGID",
|
||||
"CAP_SETUID"
|
||||
],
|
||||
"no_new_privileges": true,
|
||||
"network_mode": "mtusi2026lab7_back",
|
||||
"pid_mode": "",
|
||||
"docker_sock": false,
|
||||
"memory_limit_mib": 512,
|
||||
"nano_cpus": 1000000000,
|
||||
"pids_limit": 512,
|
||||
"published": []
|
||||
},
|
||||
"prometheus": {
|
||||
"user": "nobody",
|
||||
"read_only": true,
|
||||
"privileged": false,
|
||||
"cap_drop": [
|
||||
"ALL"
|
||||
],
|
||||
"cap_add": null,
|
||||
"no_new_privileges": true,
|
||||
"network_mode": "mtusi2026lab7_telemetry",
|
||||
"pid_mode": "",
|
||||
"docker_sock": false,
|
||||
"memory_limit_mib": 512,
|
||||
"nano_cpus": 500000000,
|
||||
"pids_limit": 256,
|
||||
"published": []
|
||||
},
|
||||
"rabbitmq": {
|
||||
"user": "root(image default)",
|
||||
"read_only": false,
|
||||
"privileged": false,
|
||||
"cap_drop": [
|
||||
"ALL"
|
||||
],
|
||||
"cap_add": [
|
||||
"CAP_CHOWN",
|
||||
"CAP_DAC_OVERRIDE",
|
||||
"CAP_FOWNER",
|
||||
"CAP_SETGID",
|
||||
"CAP_SETUID"
|
||||
],
|
||||
"no_new_privileges": true,
|
||||
"network_mode": "mtusi2026lab7_back",
|
||||
"pid_mode": "",
|
||||
"docker_sock": false,
|
||||
"memory_limit_mib": 512,
|
||||
"nano_cpus": 500000000,
|
||||
"pids_limit": 512,
|
||||
"published": []
|
||||
},
|
||||
"reconciler": {
|
||||
"user": "1001:1001",
|
||||
"read_only": true,
|
||||
"privileged": false,
|
||||
"cap_drop": [
|
||||
"ALL"
|
||||
],
|
||||
"cap_add": null,
|
||||
"no_new_privileges": true,
|
||||
"network_mode": "mtusi2026lab7_back",
|
||||
"pid_mode": "",
|
||||
"docker_sock": false,
|
||||
"memory_limit_mib": 128,
|
||||
"nano_cpus": 250000000,
|
||||
"pids_limit": 128,
|
||||
"published": [],
|
||||
"process_uid": "1001"
|
||||
},
|
||||
"redis": {
|
||||
"user": "root(image default)",
|
||||
"read_only": false,
|
||||
"privileged": false,
|
||||
"cap_drop": [
|
||||
"ALL"
|
||||
],
|
||||
"cap_add": [
|
||||
"CAP_CHOWN",
|
||||
"CAP_DAC_OVERRIDE",
|
||||
"CAP_SETGID",
|
||||
"CAP_SETUID"
|
||||
],
|
||||
"no_new_privileges": true,
|
||||
"network_mode": "mtusi2026lab7_back",
|
||||
"pid_mode": "",
|
||||
"docker_sock": false,
|
||||
"memory_limit_mib": 256,
|
||||
"nano_cpus": 500000000,
|
||||
"pids_limit": 256,
|
||||
"published": []
|
||||
},
|
||||
"relay": {
|
||||
"user": "1001:1001",
|
||||
"read_only": true,
|
||||
"privileged": false,
|
||||
"cap_drop": [
|
||||
"ALL"
|
||||
],
|
||||
"cap_add": null,
|
||||
"no_new_privileges": true,
|
||||
"network_mode": "mtusi2026lab7_back",
|
||||
"pid_mode": "",
|
||||
"docker_sock": false,
|
||||
"memory_limit_mib": 128,
|
||||
"nano_cpus": 250000000,
|
||||
"pids_limit": 128,
|
||||
"published": [],
|
||||
"process_uid": "1001"
|
||||
},
|
||||
"s3": {
|
||||
"user": "1001",
|
||||
"read_only": true,
|
||||
"privileged": false,
|
||||
"cap_drop": [
|
||||
"ALL"
|
||||
],
|
||||
"cap_add": null,
|
||||
"no_new_privileges": true,
|
||||
"network_mode": "mtusi2026lab7_back",
|
||||
"pid_mode": "",
|
||||
"docker_sock": false,
|
||||
"memory_limit_mib": 512,
|
||||
"nano_cpus": 500000000,
|
||||
"pids_limit": 256,
|
||||
"published": []
|
||||
},
|
||||
"tempo": {
|
||||
"user": "10001:10001",
|
||||
"read_only": true,
|
||||
"privileged": false,
|
||||
"cap_drop": [
|
||||
"ALL"
|
||||
],
|
||||
"cap_add": null,
|
||||
"no_new_privileges": true,
|
||||
"network_mode": "mtusi2026lab7_telemetry",
|
||||
"pid_mode": "",
|
||||
"docker_sock": false,
|
||||
"memory_limit_mib": 1024,
|
||||
"nano_cpus": 500000000,
|
||||
"pids_limit": 256,
|
||||
"published": []
|
||||
},
|
||||
"tempo-init": {
|
||||
"user": "root",
|
||||
"read_only": false,
|
||||
"privileged": false,
|
||||
"cap_drop": [
|
||||
"ALL"
|
||||
],
|
||||
"cap_add": [
|
||||
"CAP_CHOWN"
|
||||
],
|
||||
"no_new_privileges": true,
|
||||
"network_mode": "mtusi2026lab7_telemetry",
|
||||
"pid_mode": "",
|
||||
"docker_sock": false,
|
||||
"memory_limit_mib": 0,
|
||||
"nano_cpus": 0,
|
||||
"pids_limit": null,
|
||||
"published": []
|
||||
},
|
||||
"worker": {
|
||||
"user": "1001:1001",
|
||||
"read_only": true,
|
||||
"privileged": false,
|
||||
"cap_drop": [
|
||||
"ALL"
|
||||
],
|
||||
"cap_add": null,
|
||||
"no_new_privileges": true,
|
||||
"network_mode": "mtusi2026lab7_back",
|
||||
"pid_mode": "",
|
||||
"docker_sock": false,
|
||||
"memory_limit_mib": 768,
|
||||
"nano_cpus": 1000000000,
|
||||
"pids_limit": 128,
|
||||
"published": [],
|
||||
"process_uid": "1001"
|
||||
},
|
||||
"_image_sensitive_files": []
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"scenario": "leaks",
|
||||
"result": {
|
||||
"loki:password": 0,
|
||||
"loki:token": 0,
|
||||
"loki:message_text": 0,
|
||||
"loki:basic_header": 0,
|
||||
"tempo:password": 0,
|
||||
"tempo:token": 0,
|
||||
"tempo:message_text": 0,
|
||||
"tempo:basic_header": 0,
|
||||
"stdout:password": 0,
|
||||
"stdout:token": 0,
|
||||
"stdout:message_text": 0,
|
||||
"stdout:basic_header": 0,
|
||||
"traces_scanned": 20
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
{
|
||||
"scenario": "lifecycle",
|
||||
"result": {
|
||||
"api_openbao_logins_in_100s": 8,
|
||||
"api_refresh_failures": 0,
|
||||
"api_requests_ok": 200,
|
||||
"upload_while_sealed": "ready",
|
||||
"worker_restart_while_sealed": true,
|
||||
"upload_accepted_while_worker_blocked": "queued",
|
||||
"ready_seconds_after_unseal": 0.5,
|
||||
"final_status": "ready",
|
||||
"sealed_seconds": 33,
|
||||
"load_while_sealed": {
|
||||
"requests": 8667,
|
||||
"ok": 8667,
|
||||
"errors": 0,
|
||||
"error_ratio": 0.0,
|
||||
"ok_rps": 248.5,
|
||||
"seconds": 34.9,
|
||||
"latency_ms_all_ok": {
|
||||
"p50": 6.49,
|
||||
"p95": 15.21,
|
||||
"p99": 24.87
|
||||
},
|
||||
"latency_ms_outside_faults": {
|
||||
"p50": 6.49,
|
||||
"p95": 15.21,
|
||||
"p99": 24.87
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
{
|
||||
"scenario": "mtls",
|
||||
"result": {
|
||||
"lb_to_api": {
|
||||
"no_client_cert": {
|
||||
"addr": "api:8443",
|
||||
"result": "server_rejected: certificate required"
|
||||
},
|
||||
"foreign_ca_cert_cn_lb": {
|
||||
"addr": "api:8443",
|
||||
"result": "server_rejected: certificate required"
|
||||
},
|
||||
"trusted_ca_identity_attacker": {
|
||||
"addr": "api:8443",
|
||||
"result": "server_rejected: bad certificate"
|
||||
},
|
||||
"trusted_ca_identity_worker": {
|
||||
"addr": "api:8443",
|
||||
"result": "server_rejected: bad certificate"
|
||||
},
|
||||
"identity_lb": {
|
||||
"addr": "api:8443",
|
||||
"instance": "449a818793bd6549",
|
||||
"result": "ok",
|
||||
"server_serial": "190915b35397e474b2c7e012b34b0123",
|
||||
"status": 200
|
||||
},
|
||||
"plaintext_http": {
|
||||
"addr": "api:8443",
|
||||
"read_err": "",
|
||||
"reply_bytes": 76,
|
||||
"reply_prefix": "\"HTTP/1.0 400 Bad Request\\r\\n\\r\\nClient sent an HTTP request to an HTTPS server.\\n\""
|
||||
}
|
||||
},
|
||||
"broker": {
|
||||
"foreign_ca": {
|
||||
"connect": "denied: Exception (501) Reason: \"remote error: tls: certificate required\""
|
||||
},
|
||||
"trusted_ca_cn_attacker": {
|
||||
"connect": "denied: Exception (403) Reason: \"username or password not allowed\""
|
||||
},
|
||||
"trusted_ca_cn_lb": {
|
||||
"connect": "denied: Exception (403) Reason: \"username or password not allowed\""
|
||||
},
|
||||
"worker": {
|
||||
"connect": "allowed",
|
||||
"consume attachment.dead (DLQ)": "denied: Exception (403) Reason: \"ACCESS_REFUSED - read access to queue 'attachment.dead' in vhost '/' refused for user 'worker-g1'\"",
|
||||
"consume attachment.process": "allowed",
|
||||
"declare queue evil": "denied: Exception (403) Reason: \"ACCESS_REFUSED - configure access to queue 'evil.probe' in vhost '/' refused for user 'worker-g1'\"",
|
||||
"delete queue attachment.process": "denied: Exception (403) Reason: \"ACCESS_REFUSED - configure access to queue 'attachment.process' in vhost '/' refused for user 'worker-g1'\"",
|
||||
"publish attachments (job)": "denied: nack"
|
||||
},
|
||||
"relay": {
|
||||
"connect": "allowed",
|
||||
"consume attachment.dead (DLQ)": "denied: Exception (403) Reason: \"ACCESS_REFUSED - read access to queue 'attachment.dead' in vhost '/' refused for user 'relay-g1'\"",
|
||||
"consume attachment.process": "denied: Exception (403) Reason: \"ACCESS_REFUSED - read access to queue 'attachment.process' in vhost '/' refused for user 'relay-g1'\"",
|
||||
"declare queue evil": "denied: Exception (403) Reason: \"ACCESS_REFUSED - configure access to queue 'evil.probe' in vhost '/' refused for user 'relay-g1'\"",
|
||||
"delete queue attachment.process": "denied: Exception (403) Reason: \"ACCESS_REFUSED - configure access to queue 'attachment.process' in vhost '/' refused for user 'relay-g1'\"",
|
||||
"publish attachments (job)": "allowed"
|
||||
},
|
||||
"plaintext_5672": {
|
||||
"addr": "rabbitmq:5672",
|
||||
"plaintext": "no listener (dial tcp 172.18.0.6:5672: connect: connection refused)"
|
||||
}
|
||||
},
|
||||
"collector": {
|
||||
"no_client_cert": {
|
||||
"ingest": "server_rejected: certificate required"
|
||||
},
|
||||
"foreign_ca": {
|
||||
"ingest": "server_rejected: certificate required"
|
||||
},
|
||||
"main_ca_cert_lb": {
|
||||
"ingest": "server_rejected: certificate required"
|
||||
},
|
||||
"main_ca_cert_worker": {
|
||||
"ingest": "server_rejected: certificate required"
|
||||
},
|
||||
"telemetry_ca_worker": {
|
||||
"ingest": "allowed",
|
||||
"status": 200
|
||||
},
|
||||
"plaintext_http": {
|
||||
"addr": "otel-collector:4318",
|
||||
"read_err": "",
|
||||
"reply_bytes": 76,
|
||||
"reply_prefix": "\"HTTP/1.0 400 Bad Request\\r\\n\\r\\nClient sent an HTTP request to an HTTPS server.\\n\""
|
||||
}
|
||||
},
|
||||
"servers": {
|
||||
"redis": {
|
||||
"tls_verified": "ok",
|
||||
"tls_status": null,
|
||||
"plaintext_reply": "\"\\x15\\x03\\x03\\x00\\x02\\x02\\x16\"",
|
||||
"plaintext": null
|
||||
},
|
||||
"s3": {
|
||||
"tls_verified": "ok",
|
||||
"tls_status": 403,
|
||||
"plaintext_reply": "\"HTTP/1.0 400 Bad Request\\r\\n\\r\\nClient sent an HTTP request to an HTTPS server.\\n\"",
|
||||
"plaintext": null
|
||||
},
|
||||
"openbao": {
|
||||
"tls_verified": "ok",
|
||||
"tls_status": 404,
|
||||
"plaintext_reply": "\"HTTP/1.0 400 Bad Request\\r\\n\\r\\nClient sent an HTTP request to an HTTPS server.\\n\"",
|
||||
"plaintext": null
|
||||
},
|
||||
"tempo": {
|
||||
"tls_verified": "ok",
|
||||
"tls_status": 404,
|
||||
"plaintext_reply": "\"HTTP/1.0 400 Bad Request\\r\\n\\r\\nClient sent an HTTP request to an HTTPS server.\\n\"",
|
||||
"plaintext": null,
|
||||
"without_client_cert": "server_rejected: certificate required"
|
||||
},
|
||||
"loki": {
|
||||
"tls_verified": "ok",
|
||||
"tls_status": 404,
|
||||
"plaintext_reply": "\"HTTP/1.0 400 Bad Request\\r\\n\\r\\nClient sent an HTTP request to an HTTPS server.\\n\"",
|
||||
"plaintext": null,
|
||||
"without_client_cert": "server_rejected: certificate required"
|
||||
},
|
||||
"prometheus": {
|
||||
"tls_verified": "ok",
|
||||
"tls_status": 200,
|
||||
"plaintext_reply": "\"HTTP/1.0 400 Bad Request\\r\\n\\r\\nClient sent an HTTP request to an HTTPS server.\\n\"",
|
||||
"plaintext": null,
|
||||
"without_client_cert": "server_rejected: certificate required"
|
||||
},
|
||||
"collector-metrics": {
|
||||
"tls_verified": "ok",
|
||||
"tls_status": 404,
|
||||
"plaintext_reply": "\"HTTP/1.0 400 Bad Request\\r\\n\\r\\nClient sent an HTTP request to an HTTPS server.\\n\"",
|
||||
"plaintext": null,
|
||||
"without_client_cert": "server_rejected: certificate required"
|
||||
},
|
||||
"rabbitmq-metrics": {
|
||||
"tls_verified": "ok",
|
||||
"tls_status": 404,
|
||||
"plaintext_reply": "\"\\x15\\x03\\x01\\x00\\x02\\x02\\n\"",
|
||||
"plaintext": null,
|
||||
"without_client_cert": "server_rejected: certificate required"
|
||||
},
|
||||
"postgres": {
|
||||
"sslmode_disable": "denied: failed to connect to `user=app_api database=messenger`: 172.18.0.3:5432 (postgres): server error: FATAL: pg_hba.conf rejects connection for host \"172.18.0.12\", "
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
{
|
||||
"scenario": "openbao",
|
||||
"result": {
|
||||
"api": {
|
||||
"create token with other policy": "denied (403)",
|
||||
"list secrets": "denied (403)",
|
||||
"login": "allowed",
|
||||
"read messenger/reconciler": "denied (403)",
|
||||
"read messenger/relay": "denied (403)",
|
||||
"read messenger/worker": "denied (403)",
|
||||
"read own messenger/api": "allowed",
|
||||
"seal openbao": "denied (403)",
|
||||
"write own secret": "denied (403)",
|
||||
"write policy": "denied (403)"
|
||||
},
|
||||
"worker": {
|
||||
"create token with other policy": "denied (403)",
|
||||
"list secrets": "denied (403)",
|
||||
"login": "allowed",
|
||||
"read messenger/api": "denied (403)",
|
||||
"read messenger/reconciler": "denied (403)",
|
||||
"read messenger/relay": "denied (403)",
|
||||
"read own messenger/worker": "allowed",
|
||||
"seal openbao": "denied (403)",
|
||||
"write own secret": "denied (403)",
|
||||
"write policy": "denied (403)"
|
||||
},
|
||||
"relay": {
|
||||
"create token with other policy": "denied (403)",
|
||||
"list secrets": "denied (403)",
|
||||
"login": "allowed",
|
||||
"read messenger/api": "denied (403)",
|
||||
"read messenger/reconciler": "denied (403)",
|
||||
"read messenger/worker": "denied (403)",
|
||||
"read own messenger/relay": "allowed",
|
||||
"seal openbao": "denied (403)",
|
||||
"write own secret": "denied (403)",
|
||||
"write policy": "denied (403)"
|
||||
},
|
||||
"reconciler": {
|
||||
"create token with other policy": "denied (403)",
|
||||
"list secrets": "denied (403)",
|
||||
"login": "allowed",
|
||||
"read messenger/api": "denied (403)",
|
||||
"read messenger/relay": "denied (403)",
|
||||
"read messenger/worker": "denied (403)",
|
||||
"read own messenger/reconciler": "allowed",
|
||||
"seal openbao": "denied (403)",
|
||||
"write own secret": "denied (403)",
|
||||
"write policy": "denied (403)"
|
||||
},
|
||||
"worker_cert_as_api_role": {
|
||||
"login": "denied: login 400"
|
||||
},
|
||||
"attacker_cert": {
|
||||
"login": "denied: login 400"
|
||||
},
|
||||
"app_containers": {
|
||||
"api": {
|
||||
"env_has_token": false,
|
||||
"secret_files": [
|
||||
"ca.crt",
|
||||
"otel.crt",
|
||||
"otel.key",
|
||||
"revoked.txt",
|
||||
"service.crt",
|
||||
"service.key"
|
||||
]
|
||||
},
|
||||
"worker": {
|
||||
"env_has_token": false,
|
||||
"secret_files": [
|
||||
"ca.crt",
|
||||
"otel.crt",
|
||||
"otel.key",
|
||||
"service.crt",
|
||||
"service.key"
|
||||
]
|
||||
},
|
||||
"relay": {
|
||||
"env_has_token": false,
|
||||
"secret_files": [
|
||||
"ca.crt",
|
||||
"otel.crt",
|
||||
"otel.key",
|
||||
"service.crt",
|
||||
"service.key"
|
||||
]
|
||||
},
|
||||
"reconciler": {
|
||||
"env_has_token": false,
|
||||
"secret_files": [
|
||||
"ca.crt",
|
||||
"service.crt",
|
||||
"service.key"
|
||||
]
|
||||
}
|
||||
},
|
||||
"status": {
|
||||
"initialized": true,
|
||||
"sealed": false,
|
||||
"storage_type": "file",
|
||||
"t": 2,
|
||||
"n": 3,
|
||||
"version": "2.1.0"
|
||||
},
|
||||
"after_restart_sealed": true,
|
||||
"after_unseal": "allowed"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
{
|
||||
"scenario": "rotation",
|
||||
"result": {
|
||||
"db_old_password": "denied: failed to connect to `user=app_api database=messenger`: 172.18.0.3:5432 (postgres): failed SASL auth: FATAL: password authentication failed for user \"app_api\" (",
|
||||
"api_after_db_rotation_attempts": [
|
||||
200
|
||||
],
|
||||
"upload_after_s3_rotation": "ready",
|
||||
"api_leaf_serial": {
|
||||
"before": "190915b35397e474b2c7e012b34b0123",
|
||||
"after": "8c644302db8edab1a2e3fedb2c729308"
|
||||
},
|
||||
"old_lb_cert_after_revocation": "server_rejected: bad certificate",
|
||||
"new_lb_cert": 200,
|
||||
"load_during_rotations": {
|
||||
"requests": 34548,
|
||||
"ok": 34542,
|
||||
"errors": 6,
|
||||
"error_ratio": 0.00017,
|
||||
"ok_rps": 249.5,
|
||||
"seconds": 138.4,
|
||||
"latency_ms_all_ok": {
|
||||
"p50": 10.06,
|
||||
"p95": 23.1,
|
||||
"p99": 39.52
|
||||
},
|
||||
"latency_ms_outside_faults": {
|
||||
"p50": 10.06,
|
||||
"p95": 23.1,
|
||||
"p99": 39.52
|
||||
}
|
||||
},
|
||||
"seconds": 138,
|
||||
"images_rebuilt": false
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"scenario": "tls-external",
|
||||
"result": {
|
||||
"public_security_py": "PASS: trusted HTTPS works; untrusted CA rejected. This does NOT verify internal mTLS, OpenBao or hardening.",
|
||||
"trusted_ca_localhost": "ok TLSv1.3",
|
||||
"wrong_hostname": "cert_verify_error: Hostname mismatch, certificate is not valid for 'messenger.example'.",
|
||||
"foreign_ca_trust_store": "cert_verify_error: unable to get local issuer certificate",
|
||||
"tls_1_1": "ssl_error: NO_PROTOCOLS_AVAILABLE",
|
||||
"host_port_8080": "closed",
|
||||
"host_port_8404": "closed",
|
||||
"host_port_9090": "closed",
|
||||
"host_port_5432": "closed",
|
||||
"host_port_6379": "closed",
|
||||
"host_port_9000": "closed",
|
||||
"host_port_5672": "closed",
|
||||
"host_port_4318": "closed"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
# Доказательства
|
||||
|
||||
Храните небольшие обезличенные результаты: команды и stdout проверок, JSON/CSV агрегатов нагрузки, EXPLAIN, dashboard JSON, текст разбора отказа. Укажите дату, commit, аппаратные лимиты и профиль нагрузки.
|
||||
|
||||
Не добавляйте .env, session tokens, cookies, приватные ключи, credentials, реальные сообщения, raw dumps и signed URLs. Для скриншотов скрывайте секреты. Большие логи/бинарные traces сохраняйте отдельно по правилам преподавателя; одного скриншота без методики недостаточно.
|
||||
@@ -0,0 +1,17 @@
|
||||
/mtusi2026lab7-api-1 restarts=0 oom_killed=false exit=0
|
||||
/mtusi2026lab7-api-2 restarts=0 oom_killed=false exit=0
|
||||
/mtusi2026lab7-grafana-1 restarts=0 oom_killed=false exit=0
|
||||
/mtusi2026lab7-lb-1 restarts=0 oom_killed=false exit=0
|
||||
/mtusi2026lab7-loki-1 restarts=0 oom_killed=false exit=0
|
||||
/mtusi2026lab7-openbao-1 restarts=0 oom_killed=false exit=0
|
||||
/mtusi2026lab7-otel-collector-1 restarts=0 oom_killed=false exit=0
|
||||
/mtusi2026lab7-postgres-1 restarts=0 oom_killed=false exit=0
|
||||
/mtusi2026lab7-prometheus-1 restarts=0 oom_killed=false exit=0
|
||||
/mtusi2026lab7-rabbitmq-1 restarts=0 oom_killed=false exit=0
|
||||
/mtusi2026lab7-reconciler-1 restarts=0 oom_killed=false exit=0
|
||||
/mtusi2026lab7-redis-1 restarts=0 oom_killed=false exit=0
|
||||
/mtusi2026lab7-relay-1 restarts=0 oom_killed=false exit=0
|
||||
/mtusi2026lab7-s3-1 restarts=0 oom_killed=false exit=0
|
||||
/mtusi2026lab7-tempo-1 restarts=0 oom_killed=false exit=0
|
||||
/mtusi2026lab7-tempo-init-1 restarts=0 oom_killed=false exit=0
|
||||
/mtusi2026lab7-worker-1 restarts=0 oom_killed=false exit=0
|
||||
@@ -0,0 +1,18 @@
|
||||
NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
|
||||
mtusi2026lab7-api-1 mtusi2026lab7-api:local "/app/api" api About a minute ago Up About a minute (healthy) 8443/tcp
|
||||
mtusi2026lab7-api-2 mtusi2026lab7-api:local "/app/api" api About a minute ago Up About a minute (healthy) 8443/tcp
|
||||
mtusi2026lab7-grafana-1 grafana/grafana:11.4.0 "/run.sh" grafana About a minute ago Up About a minute (healthy) 127.0.0.1:3000->3000/tcp
|
||||
mtusi2026lab7-lb-1 haproxy:3.0.5-alpine "docker-entrypoint.s…" lb About a minute ago Up About a minute 127.0.0.1:8443->8443/tcp
|
||||
mtusi2026lab7-loki-1 grafana/loki:3.3.2 "/usr/bin/loki -conf…" loki About a minute ago Up About a minute 3100/tcp
|
||||
mtusi2026lab7-openbao-1 openbao/openbao:2.1.0 "docker-entrypoint.s…" openbao 2 minutes ago Up 2 minutes 127.0.0.1:8200->8200/tcp
|
||||
mtusi2026lab7-otel-collector-1 otel/opentelemetry-collector-contrib:0.116.1 "/otelcol-contrib --…" otel-collector About a minute ago Up About a minute 4317-4318/tcp, 55678-55679/tcp
|
||||
mtusi2026lab7-postgres-1 postgres:16.4-alpine "sh -c 'install -o p…" postgres 2 minutes ago Up 2 minutes (healthy) 5432/tcp
|
||||
mtusi2026lab7-prometheus-1 prom/prometheus:v3.1.0 "/bin/prometheus --c…" prometheus About a minute ago Up About a minute 9090/tcp
|
||||
mtusi2026lab7-rabbitmq-1 rabbitmq:4.0.9-alpine "docker-entrypoint.s…" rabbitmq 2 minutes ago Up 2 minutes (healthy) 4369/tcp, 5671-5672/tcp, 15691-15692/tcp, 25672/tcp
|
||||
mtusi2026lab7-reconciler-1 mtusi2026lab7-api:local "/app/reconcile --ap…" reconciler About a minute ago Up About a minute (healthy) 8443/tcp
|
||||
mtusi2026lab7-redis-1 redis:7.4.1-alpine "docker-entrypoint.s…" redis 2 minutes ago Up About a minute (healthy) 6379/tcp
|
||||
mtusi2026lab7-relay-1 mtusi2026lab7-api:local "/app/pipeline relay" relay About a minute ago Up About a minute (healthy) 8443/tcp
|
||||
mtusi2026lab7-s3-1 bitnamilegacy/minio:2025.4.22@sha256:50cec18ac4184af4671a78aedd5554942c8ae105d51a465fa82037949046da01 "/bin/bash -c 'mkdir…" s3 2 minutes ago Up 2 minutes (healthy) 9000-9001/tcp
|
||||
mtusi2026lab7-tempo-1 grafana/tempo:2.6.1 "/tempo -config.file…" tempo About a minute ago Up About a minute
|
||||
mtusi2026lab7-tempo-init-1 grafana/tempo:2.6.1 "chown 10001:10001 /…" tempo-init About a minute ago Exited (0) About a minute ago
|
||||
mtusi2026lab7-worker-1 mtusi2026lab7-api:local "/app/pipeline worker" worker About a minute ago Up About a minute (healthy) 8443/tcp
|
||||
@@ -0,0 +1,16 @@
|
||||
mtusi2026lab7-grafana-1 0.08% 65.02MiB / 256MiB
|
||||
mtusi2026lab7-lb-1 0.30% 13.46MiB / 128MiB
|
||||
mtusi2026lab7-tempo-1 0.02% 40.2MiB / 1GiB
|
||||
mtusi2026lab7-api-1 0.22% 67.7MiB / 256MiB
|
||||
mtusi2026lab7-otel-collector-1 0.69% 45.99MiB / 256MiB
|
||||
mtusi2026lab7-reconciler-1 0.00% 5.035MiB / 128MiB
|
||||
mtusi2026lab7-worker-1 0.16% 17.5MiB / 768MiB
|
||||
mtusi2026lab7-loki-1 0.69% 49.43MiB / 1GiB
|
||||
mtusi2026lab7-prometheus-1 0.36% 35.24MiB / 512MiB
|
||||
mtusi2026lab7-api-2 0.18% 67.39MiB / 256MiB
|
||||
mtusi2026lab7-relay-1 0.30% 11.89MiB / 128MiB
|
||||
mtusi2026lab7-s3-1 0.03% 459.4MiB / 512MiB
|
||||
mtusi2026lab7-postgres-1 0.23% 54.02MiB / 512MiB
|
||||
mtusi2026lab7-redis-1 0.41% 3.93MiB / 256MiB
|
||||
mtusi2026lab7-rabbitmq-1 0.99% 91.57MiB / 512MiB
|
||||
mtusi2026lab7-openbao-1 0.26% 23.14MiB / 256MiB
|
||||
@@ -0,0 +1,6 @@
|
||||
2
|
||||
total used free shared buff/cache available
|
||||
Mem: 7932 2086 1102 90 5148 5845
|
||||
Swap: 3071 0 3071
|
||||
28.0.4
|
||||
Docker Compose version v2.38.2
|
||||
@@ -0,0 +1,299 @@
|
||||
{
|
||||
"before_least_privilege": {
|
||||
"db": {
|
||||
"connect": "allowed",
|
||||
"create role": "allowed",
|
||||
"create table": "allowed",
|
||||
"delete attachments": "allowed",
|
||||
"insert attachment_variants": "allowed",
|
||||
"insert message": "allowed",
|
||||
"read chat_members": "allowed",
|
||||
"read jobs": "allowed",
|
||||
"read messages": "allowed",
|
||||
"read users.password_hash": "allowed",
|
||||
"role": "messenger",
|
||||
"truncate jobs": "allowed",
|
||||
"update attachments.owner_id": "allowed",
|
||||
"update attachments.status": "allowed",
|
||||
"update jobs.state": "allowed"
|
||||
},
|
||||
"s3": {
|
||||
"delete a/*": "allowed",
|
||||
"delete o/*": "allowed",
|
||||
"delete s/*": "allowed",
|
||||
"delete v/*": "allowed",
|
||||
"get a/*": "allowed (no such key)",
|
||||
"get o/*": "allowed (no such key)",
|
||||
"get s/*": "allowed (no such key)",
|
||||
"get v/*": "allowed (no such key)",
|
||||
"list all buckets": "allowed",
|
||||
"list bucket": "allowed",
|
||||
"make bucket": "denied (AccessDenied)",
|
||||
"put a/*": "allowed",
|
||||
"put o/*": "allowed",
|
||||
"put s/*": "allowed",
|
||||
"put v/*": "allowed"
|
||||
},
|
||||
"amqp": {
|
||||
"connect": "allowed",
|
||||
"consume attachment.dead (DLQ)": "allowed",
|
||||
"consume attachment.process": "allowed",
|
||||
"declare queue evil": "allowed",
|
||||
"delete queue attachment.process": "denied: Exception (540) Reason: \"NOT_IMPLEMENTED - cannot delete queue 'attachment.process' in vhost '/'. queue.delete operations with if-unused flag set are not suppor",
|
||||
"publish attachments (job)": "allowed"
|
||||
},
|
||||
"otlp": "allowed (lab6: OTLP по HTTP без аутентификации, любой процесс сети telemetry)",
|
||||
"api_as_lb": "allowed (lab6: API на :8080 по HTTP, доступен из сети front/back)",
|
||||
"openbao": "n/a (lab6: секреты всех нужных сервисов — файлами в контейнере)"
|
||||
},
|
||||
"after_least_privilege": {
|
||||
"amqp": {
|
||||
"connect": "allowed",
|
||||
"consume attachment.dead (DLQ)": "denied: Exception (403) Reason: \"ACCESS_REFUSED - read access to queue 'attachment.dead' in vhost '/' refused for user 'worker-g1'\"",
|
||||
"consume attachment.process": "allowed",
|
||||
"declare queue evil": "denied: Exception (403) Reason: \"ACCESS_REFUSED - configure access to queue 'evil.probe' in vhost '/' refused for user 'worker-g1'\"",
|
||||
"delete queue attachment.process": "denied: Exception (403) Reason: \"ACCESS_REFUSED - configure access to queue 'attachment.process' in vhost '/' refused for user 'worker-g1'\"",
|
||||
"publish attachments (job)": "denied: nack"
|
||||
},
|
||||
"api_as_lb": {
|
||||
"addr": "api:8443",
|
||||
"result": "server_rejected: bad certificate"
|
||||
},
|
||||
"db": {
|
||||
"connect": "allowed",
|
||||
"create role": "denied",
|
||||
"create table": "denied",
|
||||
"delete attachments": "denied",
|
||||
"insert attachment_variants": "allowed",
|
||||
"insert message": "denied",
|
||||
"read chat_members": "denied",
|
||||
"read jobs": "allowed",
|
||||
"read messages": "denied",
|
||||
"read users.password_hash": "denied",
|
||||
"role": "app_worker",
|
||||
"truncate jobs": "denied",
|
||||
"update attachments.owner_id": "denied",
|
||||
"update attachments.status": "allowed",
|
||||
"update jobs.state": "allowed"
|
||||
},
|
||||
"identity_cert": "/pki/worker.crt",
|
||||
"openbao": {
|
||||
"create token with other policy": "denied (403)",
|
||||
"list secrets": "denied (403)",
|
||||
"login": "allowed",
|
||||
"read messenger/api": "denied (403)",
|
||||
"read messenger/reconciler": "denied (403)",
|
||||
"read messenger/relay": "denied (403)",
|
||||
"read own messenger/worker": "allowed",
|
||||
"seal openbao": "denied (403)",
|
||||
"write own secret": "denied (403)",
|
||||
"write policy": "denied (403)"
|
||||
},
|
||||
"otlp": {
|
||||
"ingest": "allowed",
|
||||
"status": 200
|
||||
},
|
||||
"s3": {
|
||||
"delete a/*": "denied (AccessDenied)",
|
||||
"delete o/*": "denied (AccessDenied)",
|
||||
"delete s/*": "allowed",
|
||||
"delete v/*": "denied (AccessDenied)",
|
||||
"get a/*": "denied (AccessDenied)",
|
||||
"get o/*": "denied (AccessDenied)",
|
||||
"get s/*": "allowed (no such key)",
|
||||
"get v/*": "denied (AccessDenied)",
|
||||
"list all buckets": "denied (AccessDenied)",
|
||||
"list bucket": "denied (AccessDenied)",
|
||||
"make bucket": "denied (AccessDenied)",
|
||||
"put a/*": "denied (AccessDenied)",
|
||||
"put o/*": "allowed",
|
||||
"put s/*": "denied (AccessDenied)",
|
||||
"put v/*": "allowed"
|
||||
},
|
||||
"stolen_secrets": [
|
||||
"db_password",
|
||||
"db_user",
|
||||
"s3_access_key",
|
||||
"s3_secret_key"
|
||||
]
|
||||
},
|
||||
"response_steps": [
|
||||
{
|
||||
"step": "новая identity: сертификат CN worker-g2 (перезапись файла на месте)",
|
||||
"at_s": 0.0,
|
||||
"took_s": 0.1
|
||||
},
|
||||
{
|
||||
"step": "OpenBao cert-роль worker → только CN worker-g2; RabbitMQ: worker-g2 создан, worker-g1 удалён (соединения закрыты)",
|
||||
"at_s": 0.1,
|
||||
"took_s": 17.1
|
||||
},
|
||||
{
|
||||
"step": "отзыв всех токенов OpenBao, выданных worker",
|
||||
"at_s": 17.2,
|
||||
"took_s": 3.7
|
||||
},
|
||||
{
|
||||
"step": "ротация пароля роли БД app_worker + разрыв её соединений",
|
||||
"at_s": 20.9,
|
||||
"took_s": 1.3
|
||||
},
|
||||
{
|
||||
"step": "ротация secret key S3 svc-worker",
|
||||
"at_s": 22.2,
|
||||
"took_s": 5.2
|
||||
}
|
||||
],
|
||||
"processing_restored_seconds_after_response": 0.5,
|
||||
"worker_recovery_log_events": [
|
||||
"secrets.login",
|
||||
"secrets.version"
|
||||
],
|
||||
"worker_restarts": 0,
|
||||
"stolen_identity_after_response": {
|
||||
"amqp": {
|
||||
"connect": "denied: Exception (403) Reason: \"username or password not allowed\""
|
||||
},
|
||||
"api_as_lb": {
|
||||
"addr": "api:8443",
|
||||
"result": "server_rejected: bad certificate"
|
||||
},
|
||||
"identity_cert": "/pki/test/worker-stolen.crt",
|
||||
"openbao": {
|
||||
"login": "denied: login 400"
|
||||
},
|
||||
"otlp": {
|
||||
"ingest": "allowed",
|
||||
"status": 200
|
||||
},
|
||||
"stolen_secrets": "none: openbao login denied (login 400)",
|
||||
"db_with_stolen_password": "denied: failed to connect to `user=app_worker database=messenger`: 172.18.0.5:5432 (postgres): failed SASL auth: FATAL: password authentication failed for user \"app_wor",
|
||||
"s3_with_stolen_key": {
|
||||
"delete a/*": "denied (SignatureDoesNotMatch)",
|
||||
"delete o/*": "denied (SignatureDoesNotMatch)",
|
||||
"delete s/*": "denied (SignatureDoesNotMatch)",
|
||||
"delete v/*": "denied (SignatureDoesNotMatch)",
|
||||
"get a/*": "denied (SignatureDoesNotMatch)",
|
||||
"get o/*": "denied (SignatureDoesNotMatch)",
|
||||
"get s/*": "denied (SignatureDoesNotMatch)",
|
||||
"get v/*": "denied (SignatureDoesNotMatch)",
|
||||
"list all buckets": "denied (SignatureDoesNotMatch)",
|
||||
"list bucket": "denied (SignatureDoesNotMatch)",
|
||||
"make bucket": "denied (SignatureDoesNotMatch)",
|
||||
"put a/*": "denied (SignatureDoesNotMatch)",
|
||||
"put o/*": "denied (SignatureDoesNotMatch)",
|
||||
"put s/*": "denied (SignatureDoesNotMatch)",
|
||||
"put v/*": "denied (SignatureDoesNotMatch)"
|
||||
}
|
||||
},
|
||||
"tasks": {
|
||||
"accepted_202": 27,
|
||||
"upload_errors": 0,
|
||||
"final": {
|
||||
"ready": 27
|
||||
},
|
||||
"accepted_during_response": 21
|
||||
},
|
||||
"comparison": {
|
||||
"before": {
|
||||
"db: connect": "allowed",
|
||||
"db: create role": "allowed",
|
||||
"db: create table": "allowed",
|
||||
"db: delete attachments": "allowed",
|
||||
"db: insert attachment_variants": "allowed",
|
||||
"db: insert message": "allowed",
|
||||
"db: read chat_members": "allowed",
|
||||
"db: read jobs": "allowed",
|
||||
"db: read messages": "allowed",
|
||||
"db: read users.password_hash": "allowed",
|
||||
"db: role": "messenger",
|
||||
"db: truncate jobs": "allowed",
|
||||
"db: update attachments.owner_id": "allowed",
|
||||
"db: update attachments.status": "allowed",
|
||||
"db: update jobs.state": "allowed",
|
||||
"s3: delete a/*": "allowed",
|
||||
"s3: delete o/*": "allowed",
|
||||
"s3: delete s/*": "allowed",
|
||||
"s3: delete v/*": "allowed",
|
||||
"s3: get a/*": "allowed (no such key)",
|
||||
"s3: get o/*": "allowed (no such key)",
|
||||
"s3: get s/*": "allowed (no such key)",
|
||||
"s3: get v/*": "allowed (no such key)",
|
||||
"s3: list all buckets": "allowed",
|
||||
"s3: list bucket": "allowed",
|
||||
"s3: make bucket": "denied (AccessDenied)",
|
||||
"s3: put a/*": "allowed",
|
||||
"s3: put o/*": "allowed",
|
||||
"s3: put s/*": "allowed",
|
||||
"s3: put v/*": "allowed",
|
||||
"amqp: connect": "allowed",
|
||||
"amqp: consume attachment.dead (DLQ)": "allowed",
|
||||
"amqp: consume attachment.process": "allowed",
|
||||
"amqp: declare queue evil": "allowed",
|
||||
"amqp: delete queue attachment.process": "denied: Exception (540) Reason: \"NOT_IMPLEMENTED - cannot delete queue 'attachment.process' in vhost '/'. queue.delete operations with if-unused flag set are not suppor",
|
||||
"amqp: publish attachments (job)": "allowed",
|
||||
"otlp": "allowed (lab6: OTLP по HTTP без аутентификации, любой процесс сети telemetry)",
|
||||
"api_as_lb": "allowed (lab6: API на :8080 по HTTP, доступен из сети front/back)",
|
||||
"openbao": "n/a (lab6: секреты всех нужных сервисов — файлами в контейнере)"
|
||||
},
|
||||
"after": {
|
||||
"amqp: connect": "allowed",
|
||||
"amqp: consume attachment.dead (DLQ)": "denied: Exception (403) Reason: \"ACCESS_REFUSED - read access to queue 'attachment.dead' in vhost '/' refused for user 'worker-g1'\"",
|
||||
"amqp: consume attachment.process": "allowed",
|
||||
"amqp: declare queue evil": "denied: Exception (403) Reason: \"ACCESS_REFUSED - configure access to queue 'evil.probe' in vhost '/' refused for user 'worker-g1'\"",
|
||||
"amqp: delete queue attachment.process": "denied: Exception (403) Reason: \"ACCESS_REFUSED - configure access to queue 'attachment.process' in vhost '/' refused for user 'worker-g1'\"",
|
||||
"amqp: publish attachments (job)": "denied: nack",
|
||||
"api_as_lb: addr": "api:8443",
|
||||
"api_as_lb: result": "server_rejected: bad certificate",
|
||||
"db: connect": "allowed",
|
||||
"db: create role": "denied",
|
||||
"db: create table": "denied",
|
||||
"db: delete attachments": "denied",
|
||||
"db: insert attachment_variants": "allowed",
|
||||
"db: insert message": "denied",
|
||||
"db: read chat_members": "denied",
|
||||
"db: read jobs": "allowed",
|
||||
"db: read messages": "denied",
|
||||
"db: read users.password_hash": "denied",
|
||||
"db: role": "app_worker",
|
||||
"db: truncate jobs": "denied",
|
||||
"db: update attachments.owner_id": "denied",
|
||||
"db: update attachments.status": "allowed",
|
||||
"db: update jobs.state": "allowed",
|
||||
"identity_cert": "/pki/worker.crt",
|
||||
"openbao: create token with other policy": "denied (403)",
|
||||
"openbao: list secrets": "denied (403)",
|
||||
"openbao: login": "allowed",
|
||||
"openbao: read messenger/api": "denied (403)",
|
||||
"openbao: read messenger/reconciler": "denied (403)",
|
||||
"openbao: read messenger/relay": "denied (403)",
|
||||
"openbao: read own messenger/worker": "allowed",
|
||||
"openbao: seal openbao": "denied (403)",
|
||||
"openbao: write own secret": "denied (403)",
|
||||
"openbao: write policy": "denied (403)",
|
||||
"otlp: ingest": "allowed",
|
||||
"otlp: status": 200,
|
||||
"s3: delete a/*": "denied (AccessDenied)",
|
||||
"s3: delete o/*": "denied (AccessDenied)",
|
||||
"s3: delete s/*": "allowed",
|
||||
"s3: delete v/*": "denied (AccessDenied)",
|
||||
"s3: get a/*": "denied (AccessDenied)",
|
||||
"s3: get o/*": "denied (AccessDenied)",
|
||||
"s3: get s/*": "allowed (no such key)",
|
||||
"s3: get v/*": "denied (AccessDenied)",
|
||||
"s3: list all buckets": "denied (AccessDenied)",
|
||||
"s3: list bucket": "denied (AccessDenied)",
|
||||
"s3: make bucket": "denied (AccessDenied)",
|
||||
"s3: put a/*": "denied (AccessDenied)",
|
||||
"s3: put o/*": "allowed",
|
||||
"s3: put s/*": "denied (AccessDenied)",
|
||||
"s3: put v/*": "allowed",
|
||||
"stolen_secrets": [
|
||||
"db_password",
|
||||
"db_user",
|
||||
"s3_access_key",
|
||||
"s3_secret_key"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
module github.com/charawein/mtusi2026lab7
|
||||
|
||||
go 1.26.0
|
||||
|
||||
// Сборка и govulncheck — Go 1.26.11: в 1.26.0 govulncheck нашёл 38 достижимых
|
||||
// уязвимостей стандартной библиотеки (net/http, crypto/tls, crypto/x509 …).
|
||||
toolchain go1.26.11
|
||||
|
||||
require (
|
||||
github.com/exaring/otelpgx v0.13.0
|
||||
github.com/google/uuid v1.6.0
|
||||
github.com/jackc/pgx/v5 v5.11.0
|
||||
github.com/minio/minio-go/v7 v7.4.1
|
||||
github.com/rabbitmq/amqp091-go v1.16.0
|
||||
github.com/redis/go-redis/extra/redisotel/v9 v9.23.0
|
||||
github.com/redis/go-redis/v9 v9.23.0
|
||||
go.opentelemetry.io/contrib/bridges/otelslog v0.21.0
|
||||
go.opentelemetry.io/contrib/instrumentation/host v0.72.0
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.72.0
|
||||
go.opentelemetry.io/contrib/instrumentation/runtime v0.72.0
|
||||
go.opentelemetry.io/otel v1.47.0
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.23.0
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.47.0
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.47.0
|
||||
go.opentelemetry.io/otel/log v1.47.0
|
||||
go.opentelemetry.io/otel/metric v1.47.0
|
||||
go.opentelemetry.io/otel/sdk v1.47.0
|
||||
go.opentelemetry.io/otel/sdk/log v1.47.0
|
||||
go.opentelemetry.io/otel/sdk/metric v1.47.0
|
||||
go.opentelemetry.io/otel/trace v1.47.0
|
||||
golang.org/x/crypto v0.58.0
|
||||
golang.org/x/image v0.47.0
|
||||
golang.org/x/sync v0.25.0
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/cenkalti/backoff/v5 v5.0.3 // indirect
|
||||
github.com/cespare/xxhash/v2 v2.3.0 // indirect
|
||||
github.com/dustin/go-humanize v1.0.1 // indirect
|
||||
github.com/ebitengine/purego v0.11.1 // indirect
|
||||
github.com/felixge/httpsnoop v1.1.0 // indirect
|
||||
github.com/go-logr/logr v1.4.4 // indirect
|
||||
github.com/go-logr/stdr v1.2.2 // indirect
|
||||
github.com/go-ole/go-ole v1.3.0 // indirect
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.30.0 // indirect
|
||||
github.com/jackc/pgpassfile v1.0.0 // indirect
|
||||
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
|
||||
github.com/jackc/puddle/v2 v2.2.2 // indirect
|
||||
github.com/klauspost/compress v1.19.2 // indirect
|
||||
github.com/klauspost/cpuid/v2 v2.4.0 // indirect
|
||||
github.com/klauspost/crc32 v1.3.0 // indirect
|
||||
github.com/lufia/plan9stats v0.0.0-20260802145828-341c2f0c90b5 // indirect
|
||||
github.com/minio/crc64nvme v1.1.1 // indirect
|
||||
github.com/minio/md5-simd v1.1.2 // indirect
|
||||
github.com/philhofer/fwd v1.2.0 // indirect
|
||||
github.com/power-devops/perfstat v0.0.0-20260916203055-22a1a467d9f0 // indirect
|
||||
github.com/redis/go-redis/extra/rediscmd/v9 v9.23.0 // indirect
|
||||
github.com/rs/xid v1.6.0 // indirect
|
||||
github.com/shirou/gopsutil/v4 v4.26.9 // indirect
|
||||
github.com/tinylib/msgp v1.6.4 // indirect
|
||||
github.com/tklauser/go-sysconf v0.4.0 // indirect
|
||||
github.com/tklauser/numcpus v0.12.0 // indirect
|
||||
github.com/yusufpapurcu/wmi v1.2.4 // indirect
|
||||
github.com/zeebo/xxh3 v1.1.0 // indirect
|
||||
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.47.0 // indirect
|
||||
go.opentelemetry.io/proto/otlp v1.11.0 // indirect
|
||||
go.uber.org/atomic v1.12.0 // indirect
|
||||
go.yaml.in/yaml/v3 v3.0.5 // indirect
|
||||
golang.org/x/net v0.62.0 // indirect
|
||||
golang.org/x/sys v0.49.0 // indirect
|
||||
golang.org/x/text v0.43.0 // indirect
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20260928230214-8a89bd6388cc // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20260928230214-8a89bd6388cc // indirect
|
||||
google.golang.org/grpc v1.83.2 // indirect
|
||||
google.golang.org/protobuf v1.36.12 // indirect
|
||||
gopkg.in/ini.v1 v1.67.3 // indirect
|
||||
)
|
||||
@@ -0,0 +1,174 @@
|
||||
github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
|
||||
github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c=
|
||||
github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=
|
||||
github.com/bsm/gomega v1.27.10/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0=
|
||||
github.com/cenkalti/backoff/v5 v5.0.3 h1:ZN+IMa753KfX5hd8vVaMixjnqRZ3y8CuJKRKj1xcsSM=
|
||||
github.com/cenkalti/backoff/v5 v5.0.3/go.mod h1:rkhZdG3JZukswDf7f0cwqPNk4K0sa+F97BxZthm/crw=
|
||||
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
|
||||
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
|
||||
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
|
||||
github.com/ebitengine/purego v0.11.1 h1:2zpWRSQNVKN4eKsKO9eM1ILDgWfYMY9GwqRmK6XeQ/0=
|
||||
github.com/ebitengine/purego v0.11.1/go.mod h1:DCHPP08djqhNSoTfImcnHYQRZmd0qhakvrozqaEYhGQ=
|
||||
github.com/exaring/otelpgx v0.13.0 h1:Vi0I2GWRS3nnVzgr73L/XbSLqthR0h6A1rm4Wt3W4aA=
|
||||
github.com/exaring/otelpgx v0.13.0/go.mod h1:3OojrUKhhy3lTbYIMBijP3YjMey/jo14eHAW5cXcUdk=
|
||||
github.com/felixge/httpsnoop v1.1.0 h1:3YtUj32ZZkqZtt3sZZsClsymw/QDuVfpNhoA31zeORc=
|
||||
github.com/felixge/httpsnoop v1.1.0/go.mod h1:Zqxgdd+1Rkcz8euOqdr7lqgCRJztwr5hp9vDSi5UZCE=
|
||||
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
||||
github.com/go-logr/logr v1.4.4 h1:tG4xh9yMsRCAiodLVTxyrkzSZ9+o0L1Kg/+cPVcbP/8=
|
||||
github.com/go-logr/logr v1.4.4/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
|
||||
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
|
||||
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
|
||||
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
|
||||
github.com/go-ole/go-ole v1.3.0 h1:Dt6ye7+vXGIKZ7Xtk4s6/xVdGDQynvom7xCFEdWr6uE=
|
||||
github.com/go-ole/go-ole v1.3.0/go.mod h1:5LS6F96DhAwUc7C+1HLexzMXY1xGRSryjyPPKW6zv78=
|
||||
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
|
||||
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
|
||||
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
|
||||
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
|
||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.30.0 h1:/Tnpcb2E0Pz/tN9s3bfEY2Q8ePCEX9iuS+cneUwncnw=
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.30.0/go.mod h1:zOBXOsUaBSjKgmH4OGzV1esUpR3oUSCPYVd2cUBjKYY=
|
||||
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
|
||||
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
|
||||
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo=
|
||||
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
|
||||
github.com/jackc/pgx/v5 v5.11.0 h1:IzBBtyK9AHqf98cctWFifYSci2hgQR/cd56wB4p+ogg=
|
||||
github.com/jackc/pgx/v5 v5.11.0/go.mod h1:mal1tBGAFfLHvZzaYh77YS/eC6IX9OWbRV1QIIM0Jn4=
|
||||
github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo=
|
||||
github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
|
||||
github.com/klauspost/compress v1.19.2 h1:hMRETovs/pu/dVWN7zIT1PGG8t509MwT6bO7XSi26R8=
|
||||
github.com/klauspost/compress v1.19.2/go.mod h1:cwPg85FWrGar70rWktvGQj8/hthj3wpl0PGDogxkrSQ=
|
||||
github.com/klauspost/cpuid/v2 v2.0.1/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
|
||||
github.com/klauspost/cpuid/v2 v2.4.0 h1:S6Hrbc7+ywsr0r+RLapfGBHfyefhCTwEh3A0tV913Dw=
|
||||
github.com/klauspost/cpuid/v2 v2.4.0/go.mod h1:19jmZ9mjzoF//ddRSUsv0zfBTJWh3QJh9FNxZTMrGxU=
|
||||
github.com/klauspost/crc32 v1.3.0 h1:sSmTt3gUt81RP655XGZPElI0PelVTZ6YwCRnPSupoFM=
|
||||
github.com/klauspost/crc32 v1.3.0/go.mod h1:D7kQaZhnkX/Y0tstFGf8VUzv2UofNGqCjnC3zdHB0Hw=
|
||||
github.com/lufia/plan9stats v0.0.0-20260802145828-341c2f0c90b5 h1:eveIIGn4BGM3qknO74omf6HYr30/exH+eVUTuAgwjZ0=
|
||||
github.com/lufia/plan9stats v0.0.0-20260802145828-341c2f0c90b5/go.mod h1:autxFIvghDt3jPTLoqZ9OZ7s9qTGNAWmYCjVFWPX/zg=
|
||||
github.com/minio/crc64nvme v1.1.1 h1:8dwx/Pz49suywbO+auHCBpCtlW1OfpcLN7wYgVR6wAI=
|
||||
github.com/minio/crc64nvme v1.1.1/go.mod h1:eVfm2fAzLlxMdUGc0EEBGSMmPwmXD5XiNRpnu9J3bvg=
|
||||
github.com/minio/md5-simd v1.1.2 h1:Gdi1DZK69+ZVMoNHRXJyNcxrMA4dSxoYHZSQbirFg34=
|
||||
github.com/minio/md5-simd v1.1.2/go.mod h1:MzdKDxYpY2BT9XQFocsiZf/NKVtR7nkE4RoEpN+20RM=
|
||||
github.com/minio/minio-go/v7 v7.4.1 h1:PtU/zIOfQRWZ+QydXAZysc+xZYHdG+BBR4Z6TUvy73w=
|
||||
github.com/minio/minio-go/v7 v7.4.1/go.mod h1:nQnQi7zTfXR4lREtYXZQWqo5aw0Rqv+ZqCGrTORygRk=
|
||||
github.com/philhofer/fwd v1.2.0 h1:e6DnBTl7vGY+Gz322/ASL4Gyp1FspeMvx1RNDoToZuM=
|
||||
github.com/philhofer/fwd v1.2.0/go.mod h1:RqIHx9QI14HlwKwm98g9Re5prTQ6LdeRQn+gXJFxsJM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/power-devops/perfstat v0.0.0-20260916203055-22a1a467d9f0 h1:XA01Vk/wv9YikCi1V51yRzIHPMT5of9+cMpZoZvDn/M=
|
||||
github.com/power-devops/perfstat v0.0.0-20260916203055-22a1a467d9f0/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE=
|
||||
github.com/rabbitmq/amqp091-go v1.16.0 h1:1O8oQqnj9hLACoo6CVMgn57z2pLWXvgemhh4GsquV+Y=
|
||||
github.com/rabbitmq/amqp091-go v1.16.0/go.mod h1:Hy4jKW5kQART1u+JkDTF9YYOQUHXqMuhrgxOEeS7G4o=
|
||||
github.com/redis/go-redis/extra/rediscmd/v9 v9.23.0 h1:YOQCtePRR/cBrxtZB5u2ueYei3zGJm1n0KB2tvth0k0=
|
||||
github.com/redis/go-redis/extra/rediscmd/v9 v9.23.0/go.mod h1:BzBb5fEjIwijUn8VVkXfQUwFTGyk2vGIVU19zv2GhsM=
|
||||
github.com/redis/go-redis/extra/redisotel/v9 v9.23.0 h1:EBQ01zUjwarZZ4IoSTQNU9EEc223eB9tpSun6n5EaUU=
|
||||
github.com/redis/go-redis/extra/redisotel/v9 v9.23.0/go.mod h1:4xBZ7QF+cd90pc58g+cXH1aLJBgOGd4Gp5BBQvNtPn0=
|
||||
github.com/redis/go-redis/v9 v9.23.0 h1:/TTVdJa8BRNsybwwGGnmiYktHNlUXtbOQxlWpHBPL3s=
|
||||
github.com/redis/go-redis/v9 v9.23.0/go.mod h1:EWP2UUk+XDaI1s5nQB5mablZN6vccXlmBQTyfnF87D0=
|
||||
github.com/rs/xid v1.6.0 h1:fV591PaemRlL6JfRxGDEPl69wICngIQ3shQtzfy2gxU=
|
||||
github.com/rs/xid v1.6.0/go.mod h1:7XoLgs4eV+QndskICGsho+ADou8ySMSjJKDIan90Nz0=
|
||||
github.com/shirou/gopsutil/v4 v4.26.9 h1:CaBo/hBFqvlJoLvAQEKdHdf5GD97/MN2ACfyv63+2Ig=
|
||||
github.com/shirou/gopsutil/v4 v4.26.9/go.mod h1:nKH+8wX2zxr/mDbsR+AAy6Qd2z4ZOQ7wfQaEp+yrYmg=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
||||
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
|
||||
github.com/stretchr/testify v1.12.1 h1:EuwCh5fleGS7H32xRwO3wRGT7DxrDhLAT6FF8MpWDWE=
|
||||
github.com/stretchr/testify v1.12.1/go.mod h1:MDEgiDPPsNp5cuIrHPPCyornHKgEVbtFUmoNlxoYthg=
|
||||
github.com/tinylib/msgp v1.6.4 h1:mOwYbyYDLPj35mkA2BjjYejgJk9BuHxDdvRnb6v2ZcQ=
|
||||
github.com/tinylib/msgp v1.6.4/go.mod h1:RSp0LW9oSxFut3KzESt5Voq4GVWyS+PSulT77roAqEA=
|
||||
github.com/tklauser/go-sysconf v0.4.0 h1:7H0uAN+7RkwWRaxhYXDLqa5V3LPrJeV8wmD9dRUgPQU=
|
||||
github.com/tklauser/go-sysconf v0.4.0/go.mod h1:8mTNWyog7H+MpKijp4VmKJAd2bbYQ2zuUwkYRbUArPI=
|
||||
github.com/tklauser/numcpus v0.12.0 h1:NR85qdvHA9pFse3x3weVZ0r0ST8R6l5RHbZrlRaqob4=
|
||||
github.com/tklauser/numcpus v0.12.0/go.mod h1:ABHeXzJnr/qqwguhClkZKT1/8VABcYrsyUiUGobwWJg=
|
||||
github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0=
|
||||
github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
|
||||
github.com/zeebo/assert v1.3.0 h1:g7C04CbJuIDKNPFHmsk4hwZDO5O+kntRxzaUoNXj+IQ=
|
||||
github.com/zeebo/assert v1.3.0/go.mod h1:Pq9JiuJQpG8JLJdtkwrJESF0Foym2/D9XMU5ciN/wJ0=
|
||||
github.com/zeebo/xxh3 v1.1.0 h1:s7DLGDK45Dyfg7++yxI0khrfwq9661w9EN78eP/UZVs=
|
||||
github.com/zeebo/xxh3 v1.1.0/go.mod h1:IisAie1LELR4xhVinxWS5+zf1lA4p0MW4T+w+W07F5s=
|
||||
go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64=
|
||||
go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y=
|
||||
go.opentelemetry.io/contrib/bridges/otelslog v0.21.0 h1:/CdgE52i1OEPHhsGUqrggYNRaZy4v4YgVenGd52dRBI=
|
||||
go.opentelemetry.io/contrib/bridges/otelslog v0.21.0/go.mod h1:9pBdbVbuehIDzxN4accnzzxEUPT8Nq7grbZMo+J1VN4=
|
||||
go.opentelemetry.io/contrib/instrumentation/host v0.72.0 h1:DqxFkQ1eCzAQNPJNog2+tL9k3OaULuiYHiZaz2Waq54=
|
||||
go.opentelemetry.io/contrib/instrumentation/host v0.72.0/go.mod h1:Jn5AUVzW8ZWjm4S1uRMlio5gZxVpmXRr/2PmdESRE7Y=
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.72.0 h1:LxwW/9ctSCv+QkE/cLR7M91ZIkXNMqJtEMi1vCw9U8s=
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.72.0/go.mod h1:tOsftB4SslBwwErVEPaenU2RpThXWPIU8DoJHEC4dyw=
|
||||
go.opentelemetry.io/contrib/instrumentation/runtime v0.72.0 h1:rv8t3kKjyC2/9D99L1MZt4tJSZO4aYUmHus7L//iKKg=
|
||||
go.opentelemetry.io/contrib/instrumentation/runtime v0.72.0/go.mod h1:ZzG+JmzLLvKzx6tMeLrw2l7F8ik2GeRZJALoPBqnM0c=
|
||||
go.opentelemetry.io/otel v1.47.0 h1:j7ALJ/zgkS7Z6aeJW09p8VC9804bC+PpeTfCD4XPnOM=
|
||||
go.opentelemetry.io/otel v1.47.0/go.mod h1:8wS9O2qfXrYrzp6hIF/HOYJJf/wIhFPhR2xLuP+iXQU=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.23.0 h1:5WVp40k2fJHuc5BtNTgKk+EugKFT8Eg3lywFfCPI/nE=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.23.0/go.mod h1:59nH0RYCGHRlwt15WyioeSYINBbuObeBpTowPhEKWHY=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.47.0 h1:7kszRN4Ze5GeAkUnBjBSUIunVBMA+mZIG04auueqguM=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.47.0/go.mod h1:CLzakYy8jOdkBfcveCWYkeKJxujcF4xPhh2Z7IfE98U=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.47.0 h1:julhjPeUH/q/7hinbSdDdqt5h7Zw9YWmRlWRhI0jd54=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.47.0/go.mod h1:Ao2mz688LH/tFf0yMAenidq6k2YNSx6SIY2q6jDACck=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.47.0 h1:aXZXsZ012wOgVkqaiQv+Z/d8V0xKjmg70F6m4CE94lc=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.47.0/go.mod h1:ziu1gUIJhAaxM3EV1e3Ralk5AAyL1UOYz3lJJ4VSI38=
|
||||
go.opentelemetry.io/otel/log v1.47.0 h1:cOTS1CcLbSQeZKanGJ+0JpF/+t4PELi3O3bbl2lqCcI=
|
||||
go.opentelemetry.io/otel/log v1.47.0/go.mod h1:9byitSQ5pLC6PpqwGXjqdMKya6ZTswHRZh2vvXT33nw=
|
||||
go.opentelemetry.io/otel/metric v1.47.0 h1:4PptaldXx3Eat1XjMZ68pPJEs5wrhlemctZE9a3UdWY=
|
||||
go.opentelemetry.io/otel/metric v1.47.0/go.mod h1:ADGSXxRrXM6bjbvLo535EstVFlPpPYZm4LBKixjDHwU=
|
||||
go.opentelemetry.io/otel/metric/x v0.69.0 h1:DjRLr15H83v+hCW7JA9NoJvOkYTtmq5YoDRbe9deYpM=
|
||||
go.opentelemetry.io/otel/metric/x v0.69.0/go.mod h1:uVvsMPMFFyj/HUQfrUnH3JjnOQ1dwFDorgFLRBasM0k=
|
||||
go.opentelemetry.io/otel/sdk v1.47.0 h1:zWXEr4j2lFefG87TU6Yg8a7ngfohIKFZHKp0Hf5hC6I=
|
||||
go.opentelemetry.io/otel/sdk v1.47.0/go.mod h1:VUc24kiOeoGsxG8G9ULx3fWKvB7jMhnGE8Oi607lgR0=
|
||||
go.opentelemetry.io/otel/sdk/log v1.47.0 h1:W4N/ZfgpkRRnmARnqYoQ6BrWA0mrj8IzVDNLlpmUJZY=
|
||||
go.opentelemetry.io/otel/sdk/log v1.47.0/go.mod h1:Wu74Z2EmOKXi2FleSNAb0Hyau2G+r5kubSEMJw5aAMs=
|
||||
go.opentelemetry.io/otel/sdk/log/logtest v0.23.0 h1:j3pm42QCrKYYLLkI6OrV1QHFkUfDA6/4EP+Y1PzggLg=
|
||||
go.opentelemetry.io/otel/sdk/log/logtest v0.23.0/go.mod h1:zt0gEnuTZgDvqvczHwYswz93eqMaIr6upTTsdV/HUlU=
|
||||
go.opentelemetry.io/otel/sdk/metric v1.47.0 h1:lfISg2j93VT6yqdk9OfUaZmw/GfcZqCCV3jdXtsPnKw=
|
||||
go.opentelemetry.io/otel/sdk/metric v1.47.0/go.mod h1:ypLp+mW1Nt2x+Szt3b5/i1syodyts49lMOwxpDI3VGw=
|
||||
go.opentelemetry.io/otel/trace v1.47.0 h1:JOjX/Oci8K94QHddo+bbfya/Ai/nf6/dt9ZfrFNWSrM=
|
||||
go.opentelemetry.io/otel/trace v1.47.0/go.mod h1:jNaSLa2PZEYFG6fRjJABAu+bw4FS08uDmPg28lTghu0=
|
||||
go.opentelemetry.io/proto/otlp v1.11.0 h1:5rrYs0Ykyj50sdU/JU0x8etU+LubXWb+gED6TbEdMIk=
|
||||
go.opentelemetry.io/proto/otlp v1.11.0/go.mod h1:SmVizdCOAm3XBtG1g1NnOdhW6jtddT72hLMhv8VwA8E=
|
||||
go.uber.org/atomic v1.12.0 h1:BvcXdFKuviU4fTL/f+SxdQ5qJX/Jix8pAkgdUcb3XOE=
|
||||
go.uber.org/atomic v1.12.0/go.mod h1:I6c4cg+6HCxRjfjSsYtApoFILnpc0CGUdGkXVqbYVNk=
|
||||
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
|
||||
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
|
||||
go.yaml.in/yaml/v3 v3.0.5 h1:N6y/pJk8buWs9NY5ERU2HSMfm+IuD/OtfdAnq6kESPw=
|
||||
go.yaml.in/yaml/v3 v3.0.5/go.mod h1:HVTZu1O7/Vkt2N+BFy8Zza+lnLsABggaTM2ZpNIGuKg=
|
||||
golang.org/x/crypto v0.58.0 h1:COkYLr4k7nDI4r6QtMML2AfzeIswWHAJthLS6K/M/54=
|
||||
golang.org/x/crypto v0.58.0/go.mod h1:Xh+kl5A+M0gMiWDytH2Hhr5Z7WbNCpv/eB/EFgfSk+w=
|
||||
golang.org/x/image v0.47.0 h1:za/8gVz++PPZqmZJBNSISICN5Rrj5zixP/8K++fgmqo=
|
||||
golang.org/x/image v0.47.0/go.mod h1:IkN5o4A7vq55vXN8FWjjnhg9Rs2GOtffqsSi9mWAKYE=
|
||||
golang.org/x/net v0.60.0 h1:79p50tfZlm0J9YfoDsSi639qSXNGVwEzOPLCxM2FsYU=
|
||||
golang.org/x/net v0.60.0/go.mod h1:2DA/G1UfVbCpQPeWTmMPGY7Cs2PkBkwu743bVX5PIVg=
|
||||
golang.org/x/net v0.62.0 h1:18ELalfM5+XNRwzM2nYqXsZQ9ByS1uhj2O/U7+5jqRY=
|
||||
golang.org/x/net v0.62.0/go.mod h1:WgDCOTH8iwtB66T4/GfI94AHo/hhdb7Hah9NDseQfiI=
|
||||
golang.org/x/sync v0.25.0 h1:dJnifr0nMV8/SBnBvdo4eSGGnrc3O4FFx6IqvtLcmRs=
|
||||
golang.org/x/sync v0.25.0/go.mod h1:sUUOizhqBxiL6pEWpqNLUiaJn1ShEbZ6BBqskPbjZm0=
|
||||
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.49.0 h1:XbzkgYJHdqh/8m2Uu0W/dQv8nktxx4BFHp1M0gROTXA=
|
||||
golang.org/x/sys v0.49.0/go.mod h1:hNLxWAXmnKAxqDtdwIYC4bM9oQPEecfsnNMuSxOs3og=
|
||||
golang.org/x/text v0.43.0 h1:1QivrlhwAsnMOcqgOdl9my7s9OyZl8O5/UGUTJVXoWc=
|
||||
golang.org/x/text v0.43.0/go.mod h1:hbSIYA/amXcRXTFSZqh8tWHEoqRvvbKPJ2uz/KU+a+s=
|
||||
gonum.org/v1/gonum v0.17.0 h1:VbpOemQlsSMrYmn7T2OUvQ4dqxQXU+ouZFQsZOx50z4=
|
||||
gonum.org/v1/gonum v0.17.0/go.mod h1:El3tOrEuMpv2UdMrbNlKEh9vd86bmQ6vqIcDwxEOc1E=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20260928230214-8a89bd6388cc h1:rZHRz0ogq4Pid1IKtA/ivHi8XONVF5tqUQXA2TtgpkE=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20260928230214-8a89bd6388cc/go.mod h1:K/n0XLazCJHjD73YuMyNJsN38BPPy1kfFnKxUXaThFU=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20260928230214-8a89bd6388cc h1:4bNTbnb44EqGVy9HaQxSY2jnafSUdgV3qHtedvNpDKg=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20260928230214-8a89bd6388cc/go.mod h1:OaIUM3+LpYcK2GXM4FTmhWoIq371Owdr+Cc7/BsYHHc=
|
||||
google.golang.org/grpc v1.83.2 h1:EManeRomTObA0BU7I8vXgg/78uE5MJ9M8B39EX2WscU=
|
||||
google.golang.org/grpc v1.83.2/go.mod h1:YPI1hK3kDked6iHvgX3tR0y+nX/qpMFKhPgFsokw1S8=
|
||||
google.golang.org/protobuf v1.36.12 h1:pJOKDDOyeXErUroCihFAd5LQuwXBSpVnKGrj5o/fwxc=
|
||||
google.golang.org/protobuf v1.36.12/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/ini.v1 v1.67.3 h1:iM9Lhz5MRSGhHVGGwCuzG9KO8PoirCXj/m/qTmOJJQw=
|
||||
gopkg.in/ini.v1 v1.67.3/go.mod h1:x/cyOwCgZqOkJoDIJ3c1KNHMo10+nLGAhh+kn3Zizss=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
@@ -0,0 +1,35 @@
|
||||
# Runbooks alert-ов мессенджера
|
||||
|
||||
Все шаги выполняются только по сохранённым наблюдениям: Grafana (dashboard «Messenger — API, worker, очередь», Explore → Prometheus / Loki / Tempo). Доступ к контейнерам нужен только для устранения причины, не для поиска.
|
||||
|
||||
## MessengerHighErrorRate
|
||||
|
||||
**Условие:** доля 5xx среди бизнес-запросов (все маршруты, кроме `/health/*`) за 1 минуту > 5% при ≥ 0.5 запроса/с, 30 s подряд. 4xx — ошибки клиента — не учитываются.
|
||||
|
||||
1. Dashboard → «Доля ошибок 5xx и 4xx» и «p95 по маршруту»: один маршрут или все? Если все — общая зависимость (БД, Redis, S3); если один — его обработчик.
|
||||
2. «Пул БД: занято / ожидания»: `pgxpool_acquired_connections` упёрся в `pgxpool_max_connections` и растут ожидания (`pgxpool_empty_acquire_total`) — БД не отдаёт соединения или запросы висят.
|
||||
3. Explore → Tempo: `{resource.service.name="messenger-api" && span.http.response.status_code >= 500}`. Открыть трассу и посмотреть, какой дочерний span занимает время:
|
||||
* длинный `query …` / `acquire` (PostgreSQL) — проблема БД (блокировка, недоступность); подтвердить в БД `pg_stat_activity` (wait_event = Lock);
|
||||
* длинный `S3 …` — хранилище файлов;
|
||||
* дочерние spans короткие, а server span длинный — медленный сам обработчик/тело запроса.
|
||||
4. Explore → Loki: `{service_name="messenger-api"} | detected_level=~"error|ERROR"` за то же окно; по `trace_id` из лога — переход в трассу.
|
||||
5. Устранить причину; alert перейдёт в resolved, когда окно 1m очистится от ошибок.
|
||||
|
||||
## MessengerQueueLagGrowing
|
||||
|
||||
**Условие:** старейшая незавершённая job (queued/processing) старше 60 s, 30 s подряд. Возраст считается по PostgreSQL (источник истины), не по брокеру.
|
||||
|
||||
1. Dashboard → «Очередь: jobs по состоянию»: растёт `queued` при нулевом `processing` — задания никто не берёт; растёт `processing` — worker берёт, но не завершает.
|
||||
2. «Jobs по исходу (rate)»: нет `done` — worker стоит; много `retry`/`requeue` — worker работает, но падает на зависимости (S3/БД).
|
||||
3. `messenger_worker_capacity` есть? Нет серии ≥ 1 мин → worker не запущен (сработает и `MessengerWorkerAbsent`).
|
||||
4. «RabbitMQ: сообщения в очередях»: ready растёт — сообщения есть, потребителя нет; ready = 0 при queued в БД — relay не публикует outbox (см. «outbox не опубликовано» и возраст outbox).
|
||||
5. Tempo: последние `attachment.process process` (worker) и `attachment.process publish` (relay) — что выполнялось последним; Loki `{service_name="messenger-worker"}` — последние события (`worker.start`, `job.retry`, `shutdown`).
|
||||
6. После запуска/починки worker backlog уменьшается (панель возраста падает до 0), alert — resolved.
|
||||
|
||||
## MessengerWorkerAbsent
|
||||
|
||||
Нет метрик ни одного worker 1 минуту (серии исчезают через 1 мин после остановки процесса: `metric_expiration` Collector). Проверить `docker compose ps worker`, логи запуска (`worker.start`) и доступность Collector (если Collector недоступен, исчезают метрики всех сервисов — смотреть `MessengerTelemetryExportFailing` и метрики самого Collector).
|
||||
|
||||
## MessengerTelemetryExportFailing
|
||||
|
||||
Collector не может доставить spans/логи в Tempo/Loki (после ограниченной очереди и 60 s повторов данные отбрасываются, счётчики `otelcol_exporter_send_failed_*`). Бизнес-API не затронут. Проверить доступность Tempo/Loki, `otelcol_exporter_queue_size` относительно `otelcol_exporter_queue_capacity`. Потерянные за время отказа трассы/логи не восстанавливаются; метрики приложения при этом продолжают собираться (Prometheus забирает их напрямую из Collector).
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,9 @@
|
||||
apiVersion: 1
|
||||
providers:
|
||||
- name: messenger
|
||||
folder: Messenger
|
||||
type: file
|
||||
disableDeletion: true
|
||||
allowUiUpdates: false
|
||||
options:
|
||||
path: /var/lib/grafana/dashboards
|
||||
@@ -0,0 +1,65 @@
|
||||
# Источники Grafana: Grafana сама данные не хранит — только запрашивает.
|
||||
# Lab7: к каждому источнику — HTTPS с проверкой сервера по CA стенда и клиентским
|
||||
# сертификатом Grafana (mTLS).
|
||||
# Связи: метрика (exemplar) → трасса; лог (trace_id) → трасса; трасса → логи.
|
||||
apiVersion: 1
|
||||
datasources:
|
||||
- name: Prometheus
|
||||
uid: prometheus
|
||||
type: prometheus
|
||||
access: proxy
|
||||
url: https://prometheus:9090
|
||||
isDefault: true
|
||||
secureJsonData:
|
||||
tlsCACert: $__file{/run/secrets/ca.crt}
|
||||
tlsClientCert: $__file{/run/secrets/grafana.crt}
|
||||
tlsClientKey: $__file{/run/secrets/grafana.key}
|
||||
jsonData:
|
||||
tlsAuth: true
|
||||
tlsAuthWithCACert: true
|
||||
serverName: prometheus
|
||||
timeInterval: 5s
|
||||
exemplarTraceIdDestinations:
|
||||
- name: trace_id
|
||||
datasourceUid: tempo
|
||||
- name: Loki
|
||||
uid: loki
|
||||
type: loki
|
||||
access: proxy
|
||||
url: https://loki:3100
|
||||
secureJsonData:
|
||||
tlsCACert: $__file{/run/secrets/ca.crt}
|
||||
tlsClientCert: $__file{/run/secrets/grafana.crt}
|
||||
tlsClientKey: $__file{/run/secrets/grafana.key}
|
||||
jsonData:
|
||||
tlsAuth: true
|
||||
tlsAuthWithCACert: true
|
||||
serverName: loki
|
||||
derivedFields:
|
||||
- name: trace
|
||||
matcherType: label
|
||||
matcherRegex: trace_id
|
||||
datasourceUid: tempo
|
||||
url: "$${__value.raw}"
|
||||
- name: Tempo
|
||||
uid: tempo
|
||||
type: tempo
|
||||
access: proxy
|
||||
url: https://tempo:3200
|
||||
secureJsonData:
|
||||
tlsCACert: $__file{/run/secrets/ca.crt}
|
||||
tlsClientCert: $__file{/run/secrets/grafana.crt}
|
||||
tlsClientKey: $__file{/run/secrets/grafana.key}
|
||||
jsonData:
|
||||
tlsAuth: true
|
||||
tlsAuthWithCACert: true
|
||||
serverName: tempo
|
||||
tracesToLogsV2:
|
||||
datasourceUid: loki
|
||||
filterByTraceID: true
|
||||
spanStartTimeShift: "-5m"
|
||||
spanEndTimeShift: "5m"
|
||||
serviceMap:
|
||||
datasourceUid: prometheus
|
||||
nodeGraph:
|
||||
enabled: true
|
||||
@@ -0,0 +1,55 @@
|
||||
# HAProxy — единственная публичная точка входа. Lab7:
|
||||
# клиент → LB: TLS 1.2+ на :8443 (сертификат CN/SAN localhost, 127.0.0.1, CA стенда);
|
||||
# LB → API: mTLS — LB проверяет сервер (CA + имя api) и предъявляет свой клиентский
|
||||
# сертификат identity spiffe://messenger/lb (API пускает только её). Plaintext нет.
|
||||
# Backend-адреса — из встроенного DNS Docker (service name "api").
|
||||
|
||||
global
|
||||
log stdout format raw local0 info
|
||||
maxconn 2048
|
||||
ssl-default-bind-options ssl-min-ver TLSv1.2
|
||||
ssl-default-server-options ssl-min-ver TLSv1.2
|
||||
|
||||
defaults
|
||||
mode http
|
||||
log global
|
||||
option httplog
|
||||
option dontlognull
|
||||
timeout connect 2s
|
||||
timeout client 30s
|
||||
timeout server 15s
|
||||
timeout http-request 10s
|
||||
timeout queue 5s
|
||||
retries 2
|
||||
retry-on conn-failure
|
||||
option redispatch 1
|
||||
|
||||
resolvers docker
|
||||
nameserver dns 127.0.0.11:53
|
||||
resolve_retries 3
|
||||
timeout resolve 1s
|
||||
timeout retry 1s
|
||||
hold valid 5s
|
||||
hold other 5s
|
||||
hold refused 5s
|
||||
hold nx 2s
|
||||
hold timeout 5s
|
||||
hold obsolete 2s
|
||||
accepted_payload_size 8192
|
||||
|
||||
frontend public
|
||||
bind :8443 ssl crt /run/secrets/lb-public.pem alpn http/1.1
|
||||
# Тело больше 11 MiB отклоняется на входе (вложение ≤ 10 MiB, JSON ≤ 64 KiB — в API).
|
||||
http-request deny deny_status 413 if { req.hdr_val(content-length) gt 11534336 }
|
||||
# IP клиента — только из соединения; присланный клиентом X-Forwarded-For заменяется.
|
||||
http-request set-header X-Forwarded-For %[src]
|
||||
http-request set-header X-Forwarded-Proto https
|
||||
default_backend api
|
||||
|
||||
backend api
|
||||
balance "${LB_BALANCE}"
|
||||
option httpchk
|
||||
http-check send meth GET uri /health/ready
|
||||
http-check expect status 200
|
||||
default-server check inter 1s fastinter 500ms downinter 1s fall 2 rise 2 resolvers docker resolve-prefer ipv4 init-addr none ssl verify required ca-file /run/secrets/ca.crt crt /run/secrets/lb.pem verifyhost api sni str(api)
|
||||
server-template api 8 api:8443
|
||||
@@ -0,0 +1,45 @@
|
||||
# Loki 3 — хранилище логов. Приём OTLP (/otlp) от Collector: service.name и др.
|
||||
# resource attributes → индексные метки (service_name, …), атрибуты записи
|
||||
# (event, trace_id, span_id, severity) → structured metadata, без индексации.
|
||||
auth_enabled: false
|
||||
# Lab7: HTTP (OTLP-приём от Collector, запросы Grafana) — mTLS по CA стенда.
|
||||
server:
|
||||
http_listen_port: 3100
|
||||
grpc_listen_port: 9096
|
||||
log_level: warn
|
||||
http_tls_config:
|
||||
cert_file: /run/secrets/loki.crt
|
||||
key_file: /run/secrets/loki.key
|
||||
client_auth_type: RequireAndVerifyClientCert
|
||||
client_ca_file: /run/secrets/ca.crt
|
||||
common:
|
||||
instance_addr: 127.0.0.1
|
||||
path_prefix: /loki
|
||||
storage:
|
||||
filesystem:
|
||||
chunks_directory: /loki/chunks
|
||||
rules_directory: /loki/rules
|
||||
replication_factor: 1
|
||||
ring:
|
||||
kvstore:
|
||||
store: inmemory
|
||||
schema_config:
|
||||
configs:
|
||||
- from: 2024-01-01
|
||||
store: tsdb
|
||||
object_store: filesystem
|
||||
schema: v13
|
||||
index:
|
||||
prefix: index_
|
||||
period: 24h
|
||||
limits_config:
|
||||
allow_structured_metadata: true
|
||||
retention_period: 168h
|
||||
ingestion_rate_mb: 8
|
||||
ingestion_burst_size_mb: 16
|
||||
compactor:
|
||||
working_directory: /loki/compactor
|
||||
retention_enabled: true
|
||||
delete_request_store: filesystem
|
||||
analytics:
|
||||
reporting_enabled: false
|
||||
@@ -0,0 +1,17 @@
|
||||
# OpenBao — не dev-mode: файловое хранилище на volume, TLS listener.
|
||||
# Unseal: Shamir 3 доли / порог 2, доли у оператора (scripts/bao.sh), не в Git и не рядом с OpenBao.
|
||||
ui = false
|
||||
api_addr = "https://openbao:8200"
|
||||
log_level = "warn"
|
||||
|
||||
storage "file" {
|
||||
path = "/openbao/file"
|
||||
}
|
||||
|
||||
listener "tcp" {
|
||||
address = "0.0.0.0:8200"
|
||||
tls_cert_file = "/run/secrets/openbao.crt"
|
||||
tls_key_file = "/run/secrets/openbao.key"
|
||||
tls_client_ca_file = "/run/secrets/ca.crt" # клиентские сертификаты сервисов → auth/cert
|
||||
tls_min_version = "tls12"
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
# Policy сервиса api: чтение ТОЛЬКО своего секрета KV v2 (mount secret/).
|
||||
# Нет list/write, нет чужих путей, нет sys/ (политики, unseal, audit).
|
||||
path "secret/data/messenger/api" {
|
||||
capabilities = ["read"]
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
# Policy сервиса reconciler: чтение ТОЛЬКО своего секрета KV v2 (mount secret/).
|
||||
# Нет list/write, нет чужих путей, нет sys/ (политики, unseal, audit).
|
||||
path "secret/data/messenger/reconciler" {
|
||||
capabilities = ["read"]
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
# Policy сервиса relay: чтение ТОЛЬКО своего секрета KV v2 (mount secret/).
|
||||
# Нет list/write, нет чужих путей, нет sys/ (политики, unseal, audit).
|
||||
path "secret/data/messenger/relay" {
|
||||
capabilities = ["read"]
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
# Policy сервиса worker: чтение ТОЛЬКО своего секрета KV v2 (mount secret/).
|
||||
# Нет list/write, нет чужих путей, нет sys/ (политики, unseal, audit).
|
||||
path "secret/data/messenger/worker" {
|
||||
capabilities = ["read"]
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
# ВАРИАНТ ТРЕКА 1 (tail sampling): SDK отправляет 100% spans, Collector хранит
|
||||
# только трассы с ошибкой, медленные (≥ 250 ms) и 10% остальных.
|
||||
#
|
||||
# OpenTelemetry Collector (contrib) — приём OTLP от API/relay/worker и раздача
|
||||
# по хранилищам: traces → Tempo, logs → Loki (OTLP/HTTP), metrics → Prometheus (pull).
|
||||
#
|
||||
# Ограничение памяти и буферов:
|
||||
# memory_limiter — первым в каждом pipeline: при превышении soft limit Collector
|
||||
# отказывает receiver-у (SDK получает ошибку и отбрасывает данные по своей
|
||||
# ограниченной очереди), вместо бесконечного роста RSS;
|
||||
# batch — пакеты до 1024 элементов / 2 s;
|
||||
# sending_queue (in-memory, queue_size пакетов) + retry_on_failure (≤ 60 s) —
|
||||
# размер подобран так, чтобы очередь целиком (20 пакетов × 1024 spans) помещалась
|
||||
# ниже soft limit memory_limiter: при queue_size 200 и пакетах до 2048 очередь при
|
||||
# отказе Tempo упиралась в hard limit, и Collector отвергал НОВЫЕ данные (прогон 4);
|
||||
# при недоступном Tempo/Loki данные ждут ограниченное время в ограниченной
|
||||
# очереди, затем отбрасываются и считаются в otelcol_exporter_send_failed_*.
|
||||
# Метрики не буферизуются вовсе: exporter prometheus хранит только текущее
|
||||
# cumulative-состояние серий, Prometheus забирает его сам (pull).
|
||||
# Lab7: приём OTLP только по HTTPS с клиентским сертификатом отдельного CA телеметрии
|
||||
# (tca): сертификаты LB/хранилищ, даже от основного CA стенда, ingest не получают.
|
||||
receivers:
|
||||
otlp:
|
||||
protocols:
|
||||
http:
|
||||
endpoint: 0.0.0.0:4318
|
||||
tls:
|
||||
cert_file: /run/secrets/otel-collector.crt
|
||||
key_file: /run/secrets/otel-collector.key
|
||||
client_ca_file: /run/secrets/tca.crt
|
||||
min_version: "1.2"
|
||||
|
||||
processors:
|
||||
# Решение по трассе целиком через decision_wait после её первого span;
|
||||
# num_traces ограничивает память буфера решений. decision_wait должен быть больше
|
||||
# самой длинной трассы: при 5 s терялась часть ошибок по таймауту обработчика (5 s) —
|
||||
# решение принималось раньше, чем приходил корневой span со статусом ERROR (прогон 3).
|
||||
tail_sampling:
|
||||
decision_wait: 10s
|
||||
num_traces: 20000
|
||||
expected_new_traces_per_sec: 200
|
||||
policies:
|
||||
- name: errors
|
||||
type: status_code
|
||||
status_code: { status_codes: [ERROR] }
|
||||
- name: slow
|
||||
type: latency
|
||||
latency: { threshold_ms: 250 }
|
||||
- name: baseline
|
||||
type: probabilistic
|
||||
probabilistic: { sampling_percentage: 10 }
|
||||
memory_limiter:
|
||||
check_interval: 1s
|
||||
limit_mib: 200
|
||||
spike_limit_mib: 50
|
||||
batch:
|
||||
send_batch_size: 1024
|
||||
send_batch_max_size: 1024
|
||||
timeout: 2s
|
||||
# Защита от утечек на случай ошибки инструментирования: такие ключи не должны
|
||||
# появляться, но если появятся — удаляются до экспорта.
|
||||
attributes/scrub:
|
||||
actions:
|
||||
- { key: http.request.header.authorization, action: delete }
|
||||
- { key: http.request.header.cookie, action: delete }
|
||||
- { key: authorization, action: delete }
|
||||
- { key: password, action: delete }
|
||||
- { key: token, action: delete }
|
||||
- { key: db.query.parameters, action: delete }
|
||||
|
||||
exporters:
|
||||
otlp/tempo:
|
||||
endpoint: tempo:4317
|
||||
tls: # mTLS к Tempo: CA стенда + сертификат Collector
|
||||
ca_file: /run/secrets/ca.crt
|
||||
cert_file: /run/secrets/otel-collector.crt
|
||||
key_file: /run/secrets/otel-collector.key
|
||||
sending_queue:
|
||||
enabled: true
|
||||
num_consumers: 2
|
||||
queue_size: 20 # ≤ 20 пакетов × ≤ 1024 элемента: очередь помещается в memory_limiter
|
||||
retry_on_failure:
|
||||
enabled: true
|
||||
initial_interval: 1s
|
||||
max_interval: 10s
|
||||
max_elapsed_time: 60s
|
||||
otlphttp/loki:
|
||||
endpoint: https://loki:3100/otlp
|
||||
tls: # mTLS к Loki
|
||||
ca_file: /run/secrets/ca.crt
|
||||
cert_file: /run/secrets/otel-collector.crt
|
||||
key_file: /run/secrets/otel-collector.key
|
||||
sending_queue:
|
||||
enabled: true
|
||||
num_consumers: 2
|
||||
queue_size: 20 # ≤ 20 пакетов × ≤ 1024 элемента: очередь помещается в memory_limiter
|
||||
retry_on_failure:
|
||||
enabled: true
|
||||
initial_interval: 1s
|
||||
max_interval: 10s
|
||||
max_elapsed_time: 60s
|
||||
prometheus:
|
||||
endpoint: 0.0.0.0:8889
|
||||
tls: # Prometheus забирает метрики по mTLS (сертификат CA стенда)
|
||||
cert_file: /run/secrets/otel-collector.crt
|
||||
key_file: /run/secrets/otel-collector.key
|
||||
client_ca_file: /run/secrets/ca.crt
|
||||
enable_open_metrics: true # exemplars (trace_id) в histogram buckets
|
||||
metric_expiration: 1m # серии остановленного процесса исчезают через 1 мин (absent() в alerts)
|
||||
|
||||
service:
|
||||
telemetry:
|
||||
logs:
|
||||
level: warn
|
||||
metrics:
|
||||
level: detailed
|
||||
readers:
|
||||
- pull:
|
||||
exporter:
|
||||
prometheus:
|
||||
host: 0.0.0.0
|
||||
port: 8888
|
||||
pipelines:
|
||||
traces:
|
||||
receivers: [otlp]
|
||||
processors: [memory_limiter, tail_sampling, attributes/scrub, batch]
|
||||
exporters: [otlp/tempo]
|
||||
metrics:
|
||||
receivers: [otlp]
|
||||
processors: [memory_limiter, batch]
|
||||
exporters: [prometheus]
|
||||
logs:
|
||||
receivers: [otlp]
|
||||
processors: [memory_limiter, attributes/scrub, batch]
|
||||
exporters: [otlphttp/loki]
|
||||
@@ -0,0 +1,114 @@
|
||||
# OpenTelemetry Collector (contrib) — приём OTLP от API/relay/worker и раздача
|
||||
# по хранилищам: traces → Tempo, logs → Loki (OTLP/HTTP), metrics → Prometheus (pull).
|
||||
#
|
||||
# Ограничение памяти и буферов:
|
||||
# memory_limiter — первым в каждом pipeline: при превышении soft limit Collector
|
||||
# отказывает receiver-у (SDK получает ошибку и отбрасывает данные по своей
|
||||
# ограниченной очереди), вместо бесконечного роста RSS;
|
||||
# batch — пакеты до 1024 элементов / 2 s;
|
||||
# sending_queue (in-memory, queue_size пакетов) + retry_on_failure (≤ 60 s) —
|
||||
# размер подобран так, чтобы очередь целиком (20 пакетов × 1024 spans) помещалась
|
||||
# ниже soft limit memory_limiter: при queue_size 200 и пакетах до 2048 очередь при
|
||||
# отказе Tempo упиралась в hard limit, и Collector отвергал НОВЫЕ данные (прогон 4);
|
||||
# при недоступном Tempo/Loki данные ждут ограниченное время в ограниченной
|
||||
# очереди, затем отбрасываются и считаются в otelcol_exporter_send_failed_*.
|
||||
# Метрики не буферизуются вовсе: exporter prometheus хранит только текущее
|
||||
# cumulative-состояние серий, Prometheus забирает его сам (pull).
|
||||
# Lab7: приём OTLP только по HTTPS с клиентским сертификатом отдельного CA телеметрии
|
||||
# (tca): сертификаты LB/хранилищ, даже от основного CA стенда, ingest не получают.
|
||||
receivers:
|
||||
otlp:
|
||||
protocols:
|
||||
http:
|
||||
endpoint: 0.0.0.0:4318
|
||||
tls:
|
||||
cert_file: /run/secrets/otel-collector.crt
|
||||
key_file: /run/secrets/otel-collector.key
|
||||
client_ca_file: /run/secrets/tca.crt
|
||||
min_version: "1.2"
|
||||
|
||||
processors:
|
||||
memory_limiter:
|
||||
check_interval: 1s
|
||||
limit_mib: 200
|
||||
spike_limit_mib: 50
|
||||
batch:
|
||||
send_batch_size: 1024
|
||||
send_batch_max_size: 1024
|
||||
timeout: 2s
|
||||
# Защита от утечек на случай ошибки инструментирования: такие ключи не должны
|
||||
# появляться, но если появятся — удаляются до экспорта.
|
||||
attributes/scrub:
|
||||
actions:
|
||||
- { key: http.request.header.authorization, action: delete }
|
||||
- { key: http.request.header.cookie, action: delete }
|
||||
- { key: authorization, action: delete }
|
||||
- { key: password, action: delete }
|
||||
- { key: token, action: delete }
|
||||
- { key: db.query.parameters, action: delete }
|
||||
|
||||
exporters:
|
||||
otlp/tempo:
|
||||
endpoint: tempo:4317
|
||||
tls: # mTLS к Tempo: CA стенда + сертификат Collector
|
||||
ca_file: /run/secrets/ca.crt
|
||||
cert_file: /run/secrets/otel-collector.crt
|
||||
key_file: /run/secrets/otel-collector.key
|
||||
sending_queue:
|
||||
enabled: true
|
||||
num_consumers: 2
|
||||
queue_size: 20 # ≤ 20 пакетов × ≤ 1024 элемента: очередь помещается в memory_limiter
|
||||
retry_on_failure:
|
||||
enabled: true
|
||||
initial_interval: 1s
|
||||
max_interval: 10s
|
||||
max_elapsed_time: 60s
|
||||
otlphttp/loki:
|
||||
endpoint: https://loki:3100/otlp
|
||||
tls: # mTLS к Loki
|
||||
ca_file: /run/secrets/ca.crt
|
||||
cert_file: /run/secrets/otel-collector.crt
|
||||
key_file: /run/secrets/otel-collector.key
|
||||
sending_queue:
|
||||
enabled: true
|
||||
num_consumers: 2
|
||||
queue_size: 20 # ≤ 20 пакетов × ≤ 1024 элемента: очередь помещается в memory_limiter
|
||||
retry_on_failure:
|
||||
enabled: true
|
||||
initial_interval: 1s
|
||||
max_interval: 10s
|
||||
max_elapsed_time: 60s
|
||||
prometheus:
|
||||
endpoint: 0.0.0.0:8889
|
||||
tls: # Prometheus забирает метрики по mTLS (сертификат CA стенда)
|
||||
cert_file: /run/secrets/otel-collector.crt
|
||||
key_file: /run/secrets/otel-collector.key
|
||||
client_ca_file: /run/secrets/ca.crt
|
||||
enable_open_metrics: true # exemplars (trace_id) в histogram buckets
|
||||
metric_expiration: 1m # серии остановленного процесса исчезают через 1 мин (absent() в alerts)
|
||||
|
||||
service:
|
||||
telemetry:
|
||||
logs:
|
||||
level: warn
|
||||
metrics:
|
||||
level: detailed
|
||||
readers:
|
||||
- pull:
|
||||
exporter:
|
||||
prometheus:
|
||||
host: 0.0.0.0
|
||||
port: 8888
|
||||
pipelines:
|
||||
traces:
|
||||
receivers: [otlp]
|
||||
processors: [memory_limiter, attributes/scrub, batch]
|
||||
exporters: [otlp/tempo]
|
||||
metrics:
|
||||
receivers: [otlp]
|
||||
processors: [memory_limiter, batch]
|
||||
exporters: [prometheus]
|
||||
logs:
|
||||
receivers: [otlp]
|
||||
processors: [memory_limiter, attributes/scrub, batch]
|
||||
exporters: [otlphttp/loki]
|
||||
@@ -0,0 +1,7 @@
|
||||
# Lab7: сетевой доступ к PostgreSQL только по TLS (hostssl) и только SCRAM.
|
||||
# local — psql оператора внутри контейнера (docker compose exec); по сети не доступно.
|
||||
# TYPE DATABASE USER ADDRESS METHOD
|
||||
local all all trust
|
||||
hostssl messenger messenger,app_api,app_worker,app_relay,app_reconciler all scram-sha-256
|
||||
hostnossl all all all reject
|
||||
host all all all reject
|
||||
@@ -0,0 +1,61 @@
|
||||
# Prometheus — хранилище метрик (TSDB на volume, retention 7d) и вычисление alerts.
|
||||
# Lab7: все scrape — HTTPS с проверкой сервера по CA и клиентским сертификатом
|
||||
# Prometheus (mTLS); UI/API Prometheus — тоже mTLS (web.yml), наружу не публикуется.
|
||||
# Исключение: внутренние метрики Collector (:8888, только сеть telemetry, без данных приложений).
|
||||
# Метрики приложения приходят OTLP → Collector → exporter prometheus (:8889):
|
||||
# honor_labels сохраняет job=service.name и instance=service.instance.id реплики.
|
||||
global:
|
||||
scrape_interval: 5s
|
||||
evaluation_interval: 5s
|
||||
external_labels:
|
||||
deployment_environment: lab
|
||||
|
||||
rule_files:
|
||||
- /etc/prometheus/rules/*.yml
|
||||
|
||||
scrape_configs:
|
||||
- job_name: otel-collector-app
|
||||
honor_labels: true
|
||||
scheme: https
|
||||
tls_config:
|
||||
ca_file: /run/secrets/ca.crt
|
||||
cert_file: /run/secrets/prometheus.crt
|
||||
key_file: /run/secrets/prometheus.key
|
||||
static_configs:
|
||||
- targets: ["otel-collector:8889"]
|
||||
- job_name: otel-collector
|
||||
static_configs:
|
||||
- targets: ["otel-collector:8888"]
|
||||
- job_name: rabbitmq
|
||||
metrics_path: /metrics/per-object # глубина очередей attachment.process / attachment.dead
|
||||
scheme: https
|
||||
tls_config:
|
||||
ca_file: /run/secrets/ca.crt
|
||||
cert_file: /run/secrets/prometheus.crt
|
||||
key_file: /run/secrets/prometheus.key
|
||||
static_configs:
|
||||
- targets: ["rabbitmq:15691"]
|
||||
- job_name: loki
|
||||
scheme: https
|
||||
tls_config:
|
||||
ca_file: /run/secrets/ca.crt
|
||||
cert_file: /run/secrets/prometheus.crt
|
||||
key_file: /run/secrets/prometheus.key
|
||||
static_configs:
|
||||
- targets: ["loki:3100"]
|
||||
- job_name: tempo
|
||||
scheme: https
|
||||
tls_config:
|
||||
ca_file: /run/secrets/ca.crt
|
||||
cert_file: /run/secrets/prometheus.crt
|
||||
key_file: /run/secrets/prometheus.key
|
||||
static_configs:
|
||||
- targets: ["tempo:3200"]
|
||||
- job_name: prometheus
|
||||
scheme: https
|
||||
tls_config:
|
||||
ca_file: /run/secrets/ca.crt
|
||||
cert_file: /run/secrets/prometheus.crt
|
||||
key_file: /run/secrets/prometheus.key
|
||||
static_configs:
|
||||
- targets: ["localhost:9090"]
|
||||
@@ -0,0 +1,61 @@
|
||||
# Recording rules (SLI) и alert rules. Состояние alerts — локально в Prometheus
|
||||
# (/api/v1/alerts, Grafana → Alerting); доставка наружу не настроена (не требуется).
|
||||
# Runbooks: infra/RUNBOOKS.md.
|
||||
#
|
||||
# SLI/SLO (окно SLO — 28 дней; на стенде проверяются короткие окна):
|
||||
# доступность API: доля бизнес-запросов (кроме /health/*) без 5xx ≥ 99.5%;
|
||||
# задержка API: доля бизнес-запросов быстрее 250 ms ≥ 95%;
|
||||
# время до ready: доля вложений, ставших ready быстрее 30 s после 202, ≥ 95%.
|
||||
groups:
|
||||
- name: messenger-sli
|
||||
interval: 5s
|
||||
rules:
|
||||
- record: messenger:http_requests:rate1m
|
||||
expr: sum(rate(http_server_request_duration_seconds_count{job="messenger-api", http_route!~"/health/.*"}[1m]))
|
||||
- record: messenger:http_errors:rate1m
|
||||
expr: sum(rate(http_server_request_duration_seconds_count{job="messenger-api", http_route!~"/health/.*", http_response_status_class="5xx"}[1m])) or vector(0)
|
||||
- record: messenger:http_error_ratio:rate1m
|
||||
expr: messenger:http_errors:rate1m / messenger:http_requests:rate1m
|
||||
- record: messenger:http_fast_ratio:rate5m
|
||||
expr: |
|
||||
sum(rate(http_server_request_duration_seconds_bucket{job="messenger-api", http_route!~"/health/.*", le="0.25"}[5m]))
|
||||
/ sum(rate(http_server_request_duration_seconds_count{job="messenger-api", http_route!~"/health/.*"}[5m]))
|
||||
- record: messenger:time_to_ready_fast_ratio:rate5m
|
||||
expr: |
|
||||
sum(rate(messenger_attachment_time_to_ready_seconds_bucket{le="30"}[5m]))
|
||||
/ sum(rate(messenger_attachment_time_to_ready_seconds_count[5m]))
|
||||
|
||||
- name: messenger-alerts
|
||||
interval: 5s
|
||||
rules:
|
||||
- alert: MessengerHighErrorRate
|
||||
expr: messenger:http_error_ratio:rate1m > 0.05 and messenger:http_requests:rate1m > 0.5
|
||||
for: 30s
|
||||
labels: { severity: page }
|
||||
annotations:
|
||||
summary: "API 5xx > 5% бизнес-запросов (окно 1m, 30s подряд)"
|
||||
description: "Доля 5xx {{ $value | humanizePercentage }}. Числитель — 5xx, знаменатель — все запросы кроме /health/*; 4xx (ошибки клиента) не считаются."
|
||||
runbook: "infra/RUNBOOKS.md#messengerhigherrorrate"
|
||||
- alert: MessengerQueueLagGrowing
|
||||
expr: max(messenger_jobs_oldest_age_seconds) > 60
|
||||
for: 30s
|
||||
labels: { severity: page }
|
||||
annotations:
|
||||
summary: "Старейшая незавершённая job старше 60 s"
|
||||
description: "Возраст {{ $value | humanizeDuration }}: задания принимаются (202), но не завершаются — worker остановлен/перегружен или broker недоступен."
|
||||
runbook: "infra/RUNBOOKS.md#messengerqueuelaggrowing"
|
||||
- alert: MessengerWorkerAbsent
|
||||
expr: absent(messenger_worker_capacity)
|
||||
for: 1m
|
||||
labels: { severity: warning }
|
||||
annotations:
|
||||
summary: "Нет метрик ни одного worker 1 минуту"
|
||||
runbook: "infra/RUNBOOKS.md#messengerworkerabsent"
|
||||
- alert: MessengerTelemetryExportFailing
|
||||
expr: (sum(rate({__name__=~"otelcol_exporter_send_failed_spans(_total)?"}[1m])) or vector(0)) + (sum(rate({__name__=~"otelcol_exporter_send_failed_log_records(_total)?"}[1m])) or vector(0)) > 0
|
||||
for: 30s
|
||||
labels: { severity: warning }
|
||||
annotations:
|
||||
summary: "Collector не может доставить spans/logs в Tempo/Loki"
|
||||
description: "Данные отбрасываются после ограниченной очереди и 60 s повторов; API не затронут."
|
||||
runbook: "infra/RUNBOOKS.md#messengertelemetryexportfailing"
|
||||
@@ -0,0 +1,7 @@
|
||||
# Веб/API Prometheus: TLS + обязательный клиентский сертификат CA стенда (Grafana, сам Prometheus).
|
||||
tls_server_config:
|
||||
cert_file: /run/secrets/prometheus.crt
|
||||
key_file: /run/secrets/prometheus.key
|
||||
client_auth_type: RequireAndVerifyClientCert
|
||||
client_ca_file: /run/secrets/ca.crt
|
||||
min_version: TLS12
|
||||
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"rabbit_version": "4.0.9",
|
||||
"vhosts": [{"name": "/"}],
|
||||
"exchanges": [
|
||||
{"name": "attachments", "vhost": "/", "type": "direct", "durable": true, "auto_delete": false, "internal": false, "arguments": {}},
|
||||
{"name": "attachments.dlx", "vhost": "/", "type": "fanout", "durable": true, "auto_delete": false, "internal": false, "arguments": {}}
|
||||
],
|
||||
"queues": [
|
||||
{"name": "attachment.dead", "vhost": "/", "durable": true, "auto_delete": false, "arguments": {"x-queue-type": "quorum"}},
|
||||
{"name": "attachment.process", "vhost": "/", "durable": true, "auto_delete": false,
|
||||
"arguments": {"x-queue-type": "quorum", "x-dead-letter-exchange": "attachments.dlx", "x-delivery-limit": 10}}
|
||||
],
|
||||
"bindings": [
|
||||
{"source": "attachments", "vhost": "/", "destination": "attachment.process", "destination_type": "queue", "routing_key": "process", "arguments": {}},
|
||||
{"source": "attachments.dlx", "vhost": "/", "destination": "attachment.dead", "destination_type": "queue", "routing_key": "", "arguments": {}}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
[rabbitmq_prometheus,rabbitmq_auth_mechanism_ssl].
|
||||
@@ -0,0 +1,21 @@
|
||||
# Lab7: AMQP только по TLS с обязательным клиентским сертификатом (mTLS).
|
||||
# Аутентификация SASL EXTERNAL: пользователь RabbitMQ = CN сертификата (relay-g1,
|
||||
# worker-g1). Паролей у сервисных пользователей нет; права — set_permissions (bootstrap).
|
||||
listeners.tcp = none
|
||||
listeners.ssl.default = 5671
|
||||
ssl_options.cacertfile = /run/secrets/ca.crt
|
||||
ssl_options.certfile = /run/secrets/rabbitmq.crt
|
||||
ssl_options.keyfile = /run/secrets/rabbitmq.key
|
||||
ssl_options.verify = verify_peer
|
||||
ssl_options.fail_if_no_peer_cert = true
|
||||
ssl_options.versions.1 = tlsv1.3
|
||||
ssl_options.versions.2 = tlsv1.2
|
||||
auth_mechanisms.1 = EXTERNAL
|
||||
ssl_cert_login_from = common_name
|
||||
# Метрики очередей для Prometheus — по TLS (15691); значения не содержат данных сообщений.
|
||||
prometheus.ssl.port = 15691
|
||||
prometheus.ssl.cacertfile = /run/secrets/ca.crt
|
||||
prometheus.ssl.certfile = /run/secrets/rabbitmq.crt
|
||||
prometheus.ssl.keyfile = /run/secrets/rabbitmq.key
|
||||
prometheus.ssl.verify = verify_peer
|
||||
prometheus.ssl.fail_if_no_peer_cert = true
|
||||
@@ -0,0 +1,59 @@
|
||||
#!/bin/sh
|
||||
# Идемпотентный bootstrap MinIO (lab7): приватный bucket и ОТДЕЛЬНЫЙ пользователь на каждый
|
||||
# сервис с политикой по префиксам ключей (least privilege). Root — только у s3 и s3-init.
|
||||
#
|
||||
# svc-api PUT s/* (staging при загрузке), GET o/* v/* a/* (скачивание), DELETE s/* (компенсация)
|
||||
# svc-worker GET s/* (исходник), PUT v/* o/* (варианты, публикация оригинала), DELETE s/*
|
||||
# svc-relay DELETE s/* (очистка staging)
|
||||
# svc-reconciler LIST bucket, GET/DELETE * — сверка всего bucket (единственная широкая роль)
|
||||
#
|
||||
# Ключи сервисов приходят из secrets/operator/s3_users.txt (генерирует scripts/bootstrap.py,
|
||||
# источник истины — OpenBao). Повторный запуск обновляет секреты (ротация). Значения не печатаются.
|
||||
set -eu
|
||||
: "${S3_BUCKET:?}"
|
||||
ROOT_USER=$(cat /run/secrets/s3_root_user)
|
||||
ROOT_PASS=$(cat /run/secrets/s3_root_password)
|
||||
B=$S3_BUCKET
|
||||
|
||||
# mc проверяет сертификат MinIO по CA стенда (каталог certs/CAs конфигурации mc).
|
||||
mkdir -p "${MC_CONFIG_DIR:-$HOME/.mc}/certs/CAs" && cp /run/secrets/ca.crt "${MC_CONFIG_DIR:-$HOME/.mc}/certs/CAs/ca.crt"
|
||||
mc alias set local https://s3:9000 "$ROOT_USER" "$ROOT_PASS" >/dev/null
|
||||
mc mb --ignore-existing "local/$B"
|
||||
mc anonymous set none "local/$B" >/dev/null
|
||||
|
||||
stmt() { # actions resources
|
||||
printf '{"Effect":"Allow","Action":[%s],"Resource":[%s]}' "$1" "$2"
|
||||
}
|
||||
obj() { for p in "$@"; do printf '"arn:aws:s3:::%s/%s*",' "$B" "$p"; done | sed 's/,$//'; }
|
||||
|
||||
policy() { # name statements...
|
||||
name=$1; shift
|
||||
body=$(printf '%s,' "$@" | sed 's/,$//')
|
||||
printf '{"Version":"2012-10-17","Statement":[%s]}' "$body" > "/tmp/$name.json"
|
||||
mc admin policy create local "$name" "/tmp/$name.json" >/dev/null
|
||||
}
|
||||
|
||||
policy messenger-svc-api \
|
||||
"$(stmt '"s3:PutObject"' "$(obj s/)")" \
|
||||
"$(stmt '"s3:GetObject"' "$(obj o/ v/ a/ s/)")" \
|
||||
"$(stmt '"s3:DeleteObject"' "$(obj s/)")"
|
||||
policy messenger-svc-worker \
|
||||
"$(stmt '"s3:GetObject"' "$(obj s/)")" \
|
||||
"$(stmt '"s3:PutObject"' "$(obj v/ o/)")" \
|
||||
"$(stmt '"s3:DeleteObject"' "$(obj s/)")"
|
||||
policy messenger-svc-relay \
|
||||
"$(stmt '"s3:DeleteObject"' "$(obj s/)")"
|
||||
policy messenger-svc-reconciler \
|
||||
"$(stmt '"s3:ListBucket","s3:GetBucketLocation"' "\"arn:aws:s3:::$B\"")" \
|
||||
"$(stmt '"s3:GetObject","s3:DeleteObject"' "$(obj '')")"
|
||||
|
||||
if [ -s /run/secrets/s3_users ]; then
|
||||
while read -r svc key secret; do
|
||||
[ -n "$svc" ] || continue
|
||||
mc admin user add local "$key" "$secret" >/dev/null # для существующего — смена секрета
|
||||
if ! mc admin policy entities local --user "$key" 2>/dev/null | grep -q "messenger-svc-$svc"; then
|
||||
mc admin policy attach local "messenger-svc-$svc" --user "$key" >/dev/null
|
||||
fi
|
||||
done < /run/secrets/s3_users
|
||||
fi
|
||||
echo "s3 bootstrap ok: bucket=$B private, per-service users with prefix policies"
|
||||
@@ -0,0 +1,41 @@
|
||||
# Tempo 2 — хранилище трасс (локальный backend на volume). Приём OTLP gRPC от
|
||||
# Collector; поиск TraceQL и выдача трассы по ID для Grafana.
|
||||
stream_over_http_enabled: true
|
||||
# Lab7: HTTP API (Grafana, Prometheus) и OTLP-приём — mTLS по CA стенда.
|
||||
server:
|
||||
http_listen_port: 3200
|
||||
log_level: warn
|
||||
http_tls_config:
|
||||
cert_file: /run/secrets/tempo.crt
|
||||
key_file: /run/secrets/tempo.key
|
||||
client_auth_type: RequireAndVerifyClientCert
|
||||
client_ca_file: /run/secrets/ca.crt
|
||||
distributor:
|
||||
receivers:
|
||||
otlp:
|
||||
protocols:
|
||||
grpc:
|
||||
endpoint: 0.0.0.0:4317
|
||||
tls:
|
||||
cert_file: /run/secrets/tempo.crt
|
||||
key_file: /run/secrets/tempo.key
|
||||
client_ca_file: /run/secrets/ca.crt
|
||||
# Явный адрес frontend для querier в single-binary: автоматическая настройка после
|
||||
# рестарта Tempo оставляла запросы без ответа (прогон 4, отказ backend).
|
||||
querier:
|
||||
frontend_worker:
|
||||
frontend_address: 127.0.0.1:9095
|
||||
ingester:
|
||||
max_block_duration: 5m
|
||||
compactor:
|
||||
compaction:
|
||||
block_retention: 168h
|
||||
storage:
|
||||
trace:
|
||||
backend: local
|
||||
wal:
|
||||
path: /var/tempo/wal
|
||||
local:
|
||||
path: /var/tempo/blocks
|
||||
usage_report:
|
||||
reporting_enabled: false
|
||||
@@ -0,0 +1,207 @@
|
||||
// Package broker — RabbitMQ для заданий обработки вложений.
|
||||
//
|
||||
// Топология (объявляется идемпотентно при каждом подключении):
|
||||
//
|
||||
// exchange attachments (direct, durable) ──process──► queue attachment.process
|
||||
// quorum-очередь (реплицируемый журнал на диске), x-delivery-limit=10:
|
||||
// сообщение, которое 10 раз вернулось без ack (poison), уходит в DLX
|
||||
// exchange attachments.dlx (fanout, durable) ──► queue attachment.dead (реестр «мёртвых»)
|
||||
//
|
||||
// Publisher confirm подтверждает, что broker устойчиво ПРИНЯЛ сообщение (записал
|
||||
// в quorum-журнал); consumer ack подтверждает, что worker устойчиво ОБРАБОТАЛ его.
|
||||
// Это разные границы: между ними сообщение может быть доставлено несколько раз.
|
||||
package broker
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
amqp "github.com/rabbitmq/amqp091-go"
|
||||
"go.opentelemetry.io/otel"
|
||||
)
|
||||
|
||||
// HeaderCarrier — заголовки AMQP как TextMapCarrier (traceparent, tracestate).
|
||||
type HeaderCarrier amqp.Table
|
||||
|
||||
func (c HeaderCarrier) Get(key string) string {
|
||||
if v, ok := c[key].(string); ok {
|
||||
return v
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (c HeaderCarrier) Set(key, value string) { c[key] = value }
|
||||
|
||||
func (c HeaderCarrier) Keys() []string {
|
||||
keys := make([]string, 0, len(c))
|
||||
for k := range c {
|
||||
keys = append(keys, k)
|
||||
}
|
||||
return keys
|
||||
}
|
||||
|
||||
const (
|
||||
Exchange = "attachments"
|
||||
RoutingKey = "process"
|
||||
Queue = "attachment.process"
|
||||
DeadExchange = "attachments.dlx"
|
||||
DeadQueue = "attachment.dead"
|
||||
DeliveryLimit = 10
|
||||
)
|
||||
|
||||
// Declare объявляет топологию; повторный вызов с теми же аргументами — no-op.
|
||||
func Declare(ch *amqp.Channel) error {
|
||||
if err := ch.ExchangeDeclare(Exchange, "direct", true, false, false, false, nil); err != nil {
|
||||
return fmt.Errorf("declare exchange: %w", err)
|
||||
}
|
||||
if err := ch.ExchangeDeclare(DeadExchange, "fanout", true, false, false, false, nil); err != nil {
|
||||
return fmt.Errorf("declare dlx: %w", err)
|
||||
}
|
||||
if _, err := ch.QueueDeclare(DeadQueue, true, false, false, false, amqp.Table{"x-queue-type": "quorum"}); err != nil {
|
||||
return fmt.Errorf("declare dead queue: %w", err)
|
||||
}
|
||||
if err := ch.QueueBind(DeadQueue, "", DeadExchange, false, nil); err != nil {
|
||||
return fmt.Errorf("bind dead queue: %w", err)
|
||||
}
|
||||
args := amqp.Table{
|
||||
"x-queue-type": "quorum",
|
||||
"x-dead-letter-exchange": DeadExchange,
|
||||
"x-delivery-limit": int32(DeliveryLimit),
|
||||
}
|
||||
if _, err := ch.QueueDeclare(Queue, true, false, false, false, args); err != nil {
|
||||
return fmt.Errorf("declare queue: %w", err)
|
||||
}
|
||||
if err := ch.QueueBind(Queue, RoutingKey, Exchange, false, nil); err != nil {
|
||||
return fmt.Errorf("bind queue: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Publisher публикует с publisher confirms.
|
||||
type Publisher struct {
|
||||
conn *amqp.Connection
|
||||
ch *amqp.Channel
|
||||
}
|
||||
|
||||
// Dial — соединение с broker. С tc (lab7): amqps, mTLS и SASL EXTERNAL — имя
|
||||
// пользователя RabbitMQ = CN клиентского сертификата, пароля нет вовсе.
|
||||
func Dial(url, name string, tc *tls.Config) (*amqp.Connection, error) {
|
||||
cfg := amqp.Config{Heartbeat: 10 * time.Second, Properties: amqp.Table{"connection_name": name}}
|
||||
if tc != nil {
|
||||
cfg.TLSClientConfig = tc
|
||||
cfg.SASL = []amqp.Authentication{&amqp.ExternalAuth{}}
|
||||
}
|
||||
return amqp.DialConfig(url, cfg)
|
||||
}
|
||||
|
||||
// NewPublisher. declare=true — объявить топологию (relay; права configure только на
|
||||
// имена топологии). Worker топологию не объявляет (configure "^$").
|
||||
func NewPublisher(url string, tc *tls.Config, declare bool) (*Publisher, error) {
|
||||
conn, err := Dial(url, "relay", tc)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("dial broker: %w", err)
|
||||
}
|
||||
ch, err := conn.Channel()
|
||||
if err != nil {
|
||||
conn.Close()
|
||||
return nil, err
|
||||
}
|
||||
if declare {
|
||||
if err := Declare(ch); err != nil {
|
||||
conn.Close()
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if err := ch.Confirm(false); err != nil {
|
||||
conn.Close()
|
||||
return nil, fmt.Errorf("enable confirms: %w", err)
|
||||
}
|
||||
return &Publisher{conn: conn, ch: ch}, nil
|
||||
}
|
||||
|
||||
func (p *Publisher) Closed() bool { return p.conn.IsClosed() || p.ch.IsClosed() }
|
||||
|
||||
func (p *Publisher) Close() { _ = p.conn.Close() }
|
||||
|
||||
// Publish отправляет persistent-сообщение и ждёт confirm (ack от broker).
|
||||
// nack или таймаут — ошибка: outbox не помечается опубликованным.
|
||||
// W3C trace context из ctx (producer span) уходит в заголовки AMQP traceparent/tracestate.
|
||||
func (p *Publisher) Publish(ctx context.Context, messageID string, body []byte) error {
|
||||
headers := amqp.Table{}
|
||||
otel.GetTextMapPropagator().Inject(ctx, HeaderCarrier(headers))
|
||||
ctx, cancel := context.WithTimeout(ctx, 10*time.Second)
|
||||
defer cancel()
|
||||
dc, err := p.ch.PublishWithDeferredConfirmWithContext(ctx, Exchange, RoutingKey, true, false, amqp.Publishing{
|
||||
ContentType: "application/json",
|
||||
DeliveryMode: amqp.Persistent,
|
||||
MessageId: messageID,
|
||||
Timestamp: time.Now(),
|
||||
Type: "attachment.process.v1",
|
||||
Headers: headers,
|
||||
Body: body,
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("publish: %w", err)
|
||||
}
|
||||
ok, err := dc.WaitContext(ctx)
|
||||
if err != nil {
|
||||
return fmt.Errorf("publish confirm: %w", err)
|
||||
}
|
||||
if !ok {
|
||||
return errors.New("publish nacked by broker")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Consumer — подписка с ручным ack и prefetch.
|
||||
type Consumer struct {
|
||||
conn *amqp.Connection
|
||||
ch *amqp.Channel
|
||||
}
|
||||
|
||||
func NewConsumer(url string, prefetch int, name string, tc *tls.Config, declare bool) (*Consumer, <-chan amqp.Delivery, error) {
|
||||
conn, err := Dial(url, name, tc)
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("dial broker: %w", err)
|
||||
}
|
||||
ch, err := conn.Channel()
|
||||
if err != nil {
|
||||
conn.Close()
|
||||
return nil, nil, err
|
||||
}
|
||||
if declare {
|
||||
if err := Declare(ch); err != nil {
|
||||
conn.Close()
|
||||
return nil, nil, err
|
||||
}
|
||||
}
|
||||
// prefetch = максимум неподтверждённых сообщений у этого worker:
|
||||
// ограничивает конкуренцию и не даёт одному worker забрать всю очередь.
|
||||
if err := ch.Qos(prefetch, 0, false); err != nil {
|
||||
conn.Close()
|
||||
return nil, nil, fmt.Errorf("qos: %w", err)
|
||||
}
|
||||
deliveries, err := ch.Consume(Queue, name, false, false, false, false, nil)
|
||||
if err != nil {
|
||||
conn.Close()
|
||||
return nil, nil, fmt.Errorf("consume: %w", err)
|
||||
}
|
||||
return &Consumer{conn: conn, ch: ch}, deliveries, nil
|
||||
}
|
||||
|
||||
// Cancel прекращает получение новых сообщений; неподтверждённые вернутся в очередь.
|
||||
func (c *Consumer) Cancel(name string) { _ = c.ch.Cancel(name, false) }
|
||||
|
||||
func (c *Consumer) Close() { _ = c.conn.Close() }
|
||||
|
||||
// Ping проверяет соединение (для readiness/heartbeat-проверок).
|
||||
func Ping(url string) error {
|
||||
conn, err := amqp.DialConfig(url, amqp.Config{Heartbeat: 10 * time.Second})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return conn.Close()
|
||||
}
|
||||
@@ -0,0 +1,185 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"encoding/hex"
|
||||
"log/slog"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
Host string
|
||||
Port string
|
||||
Env string
|
||||
SessionTTLSeconds int
|
||||
DatabaseURL string
|
||||
CacheURL string
|
||||
SessionStore string
|
||||
LogLevel slog.Level
|
||||
ShutdownTimeout time.Duration
|
||||
CacheEnabled bool
|
||||
InstanceID string
|
||||
IdempotencyTTL time.Duration
|
||||
DrainDelay time.Duration
|
||||
DBPoolMax int32
|
||||
CacheInvalidation string
|
||||
InternalAddr string
|
||||
S3Endpoint string
|
||||
S3Region string
|
||||
S3Bucket string
|
||||
S3AccessKey string
|
||||
S3SecretKey string
|
||||
MaxUploadBytes int64
|
||||
MaxImagePixels int64
|
||||
// Pipeline (lab5)
|
||||
BrokerURL string
|
||||
PipelineVersion int
|
||||
JobMaxAttempts int
|
||||
JobTimeout time.Duration
|
||||
WorkerConcurrency int
|
||||
StagingRetention time.Duration
|
||||
WebPQuality int
|
||||
PixelBudget int64
|
||||
RetryBaseDelay time.Duration
|
||||
RetryMaxDelay time.Duration
|
||||
// Lab7: TLS и OpenBao
|
||||
TLSCAFile string // CA стенда (проверка серверов и клиентов)
|
||||
TLSCertFile string // сертификат сервиса (mTLS-клиент / сервер API)
|
||||
TLSKeyFile string
|
||||
BaoAddr string
|
||||
BaoCACert string
|
||||
BaoRole string // роль auth/cert
|
||||
BaoKVPath string // messenger/<сервис> в KV v2 secret/
|
||||
SecretsRefresh time.Duration
|
||||
HealthAddr string // локальный plaintext health listener (только 127.0.0.1)
|
||||
AllowedClients string // identity клиентов API (URI SAN), через запятую
|
||||
}
|
||||
|
||||
func Load() Config {
|
||||
return Config{
|
||||
Host: getEnv("APP_HOST", "0.0.0.0"),
|
||||
Port: getEnv("APP_PORT", "8080"),
|
||||
Env: getEnv("APP_ENV", "lab"),
|
||||
SessionTTLSeconds: getInt("SESSION_TTL_SECONDS", 3600),
|
||||
DatabaseURL: readSecretFile("DATABASE_URL_FILE"),
|
||||
CacheURL: readSecretFile("CACHE_URL_FILE"),
|
||||
SessionStore: getEnv("SESSION_STORE", "postgres"),
|
||||
LogLevel: parseLevel(getEnv("LOG_LEVEL", "info")),
|
||||
ShutdownTimeout: parseDuration(getEnv("SHUTDOWN_TIMEOUT", "8s")),
|
||||
CacheEnabled: getEnv("CACHE_ENABLED", "true") == "true",
|
||||
InstanceID: instanceID(),
|
||||
IdempotencyTTL: time.Duration(getInt("IDEMPOTENCY_TTL_SECONDS", 86400)) * time.Second,
|
||||
DrainDelay: parseDuration(getEnv("DRAIN_DELAY", "3s")),
|
||||
DBPoolMax: int32(max(1, getInt("DB_POOL_MAX", 20))),
|
||||
CacheInvalidation: getEnv("CACHE_INVALIDATION", "version"),
|
||||
InternalAddr: getEnv("INTERNAL_ADDR", "127.0.0.1:9090"),
|
||||
S3Endpoint: getEnv("S3_ENDPOINT", "http://s3:9000"),
|
||||
S3Region: getEnv("S3_REGION", "us-east-1"),
|
||||
S3Bucket: getEnv("S3_BUCKET", "messenger-attachments"),
|
||||
S3AccessKey: readSecretFile("S3_ACCESS_KEY_ID_FILE"),
|
||||
S3SecretKey: readSecretFile("S3_SECRET_ACCESS_KEY_FILE"),
|
||||
MaxUploadBytes: int64(getInt("MAX_UPLOAD_BYTES", 10*1024*1024)),
|
||||
MaxImagePixels: int64(getInt("MAX_IMAGE_PIXELS", 40_000_000)),
|
||||
BrokerURL: firstNonEmpty(getEnv("BROKER_URL", ""), readSecretFile("BROKER_URL_FILE")), // lab7: amqps без пароля (EXTERNAL)
|
||||
PipelineVersion: max(1, getInt("PIPELINE_VERSION", 1)),
|
||||
JobMaxAttempts: max(1, getInt("JOB_MAX_ATTEMPTS", 5)),
|
||||
JobTimeout: time.Duration(max(5, getInt("JOB_TIMEOUT_SECONDS", 60))) * time.Second,
|
||||
WorkerConcurrency: max(1, getInt("WORKER_CONCURRENCY", 2)),
|
||||
StagingRetention: time.Duration(max(60, getInt("STAGING_RETENTION_SECONDS", 86400))) * time.Second,
|
||||
WebPQuality: min(100, max(1, getInt("WEBP_QUALITY", 80))),
|
||||
PixelBudget: int64(max(1_000_000, getInt("WORKER_PIXEL_BUDGET", 60_000_000))),
|
||||
RetryBaseDelay: parseDuration(getEnv("RETRY_BASE_DELAY", "2s")),
|
||||
RetryMaxDelay: parseDuration(getEnv("RETRY_MAX_DELAY", "60s")),
|
||||
TLSCAFile: getEnv("TLS_CA_FILE", ""),
|
||||
TLSCertFile: getEnv("TLS_CERT_FILE", ""),
|
||||
TLSKeyFile: getEnv("TLS_KEY_FILE", ""),
|
||||
BaoAddr: getEnv("BAO_ADDR", ""),
|
||||
BaoCACert: getEnv("BAO_CACERT", getEnv("TLS_CA_FILE", "")),
|
||||
BaoRole: getEnv("BAO_ROLE", ""),
|
||||
BaoKVPath: getEnv("BAO_KV_PATH", ""),
|
||||
SecretsRefresh: parseDuration(getEnv("SECRETS_REFRESH", "30s")),
|
||||
HealthAddr: getEnv("HEALTH_ADDR", "127.0.0.1:8081"),
|
||||
AllowedClients: getEnv("API_ALLOWED_CLIENTS", "lb"),
|
||||
}
|
||||
}
|
||||
|
||||
// instanceID — идентификатор реплики для X-Instance-Id. По умолчанию hostname,
|
||||
// который в Docker равен короткому ID контейнера: так stop-one.sh однозначно
|
||||
// находит контейнер. В lab7 его заменит непрозрачный alias.
|
||||
func instanceID() string {
|
||||
if v := os.Getenv("INSTANCE_ID"); v != "" {
|
||||
return v
|
||||
}
|
||||
// Lab7: случайный alias реплики (не hostname/IP контейнера). Для stop-one.sh он
|
||||
// записывается в /tmp/instance-id (tmpfs контейнера).
|
||||
var b [8]byte
|
||||
if _, err := rand.Read(b[:]); err != nil {
|
||||
return "unknown"
|
||||
}
|
||||
id := hex.EncodeToString(b[:])
|
||||
_ = os.WriteFile(os.TempDir()+"/instance-id", []byte(id), 0o644)
|
||||
return id
|
||||
}
|
||||
|
||||
func (c Config) SessionTTL() time.Duration {
|
||||
return time.Duration(c.SessionTTLSeconds) * time.Second
|
||||
}
|
||||
|
||||
func (c Config) Addr() string { return c.Host + ":" + c.Port }
|
||||
|
||||
func getEnv(key, def string) string {
|
||||
if v := os.Getenv(key); v != "" {
|
||||
return v
|
||||
}
|
||||
return def
|
||||
}
|
||||
|
||||
func getInt(key string, def int) int {
|
||||
if v := os.Getenv(key); v != "" {
|
||||
if n, err := strconv.Atoi(v); err == nil {
|
||||
return n
|
||||
}
|
||||
}
|
||||
return def
|
||||
}
|
||||
|
||||
func readSecretFile(envKey string) string {
|
||||
path := os.Getenv(envKey)
|
||||
if path == "" {
|
||||
return ""
|
||||
}
|
||||
b, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
slog.Warn("secret file not readable", "path", path, "err", err)
|
||||
return ""
|
||||
}
|
||||
return strings.TrimSpace(string(b))
|
||||
}
|
||||
|
||||
func parseLevel(s string) slog.Level {
|
||||
var l slog.Level
|
||||
if err := l.UnmarshalText([]byte(s)); err != nil {
|
||||
return slog.LevelInfo
|
||||
}
|
||||
return l
|
||||
}
|
||||
|
||||
func parseDuration(s string) time.Duration {
|
||||
d, err := time.ParseDuration(s)
|
||||
if err != nil {
|
||||
return 8 * time.Second
|
||||
}
|
||||
return d
|
||||
}
|
||||
|
||||
func firstNonEmpty(v ...string) string {
|
||||
for _, x := range v {
|
||||
if x != "" {
|
||||
return x
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
package domain
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
AttachmentUploading = "uploading" // внутреннее намерение до 202, клиенту не видно
|
||||
AttachmentQueued = "queued"
|
||||
AttachmentProcessing = "processing"
|
||||
AttachmentReady = "ready"
|
||||
AttachmentFailed = "failed"
|
||||
AttachmentMissing = "missing" // карантин reconciler
|
||||
)
|
||||
|
||||
// Variant — результат обработки одной версии pipeline.
|
||||
type Variant struct {
|
||||
Name string `json:"name"`
|
||||
ContentType string `json:"content_type"`
|
||||
SizeBytes int64 `json:"size_bytes"`
|
||||
Width int `json:"width"`
|
||||
Height int `json:"height"`
|
||||
SHA256 string `json:"sha256"`
|
||||
ObjectKey string `json:"-"`
|
||||
PipelineVersion int `json:"-"`
|
||||
}
|
||||
|
||||
// Attachment — метаданные вложения. Ключи S3 никогда не уходят клиенту.
|
||||
type Attachment struct {
|
||||
ID string
|
||||
ChatID string
|
||||
OwnerID string
|
||||
Filename string
|
||||
ObjectKey string // текущее место оригинала: staging до ready, конечный prefix после
|
||||
StagingKey string // staging-объект, пока он не удалён после публикации
|
||||
Status string
|
||||
ContentType string
|
||||
SizeBytes int64
|
||||
SHA256 string
|
||||
ErrorCode string
|
||||
PipelineVersion int // версия, чей результат опубликован (0 — ещё нет)
|
||||
Variants []Variant
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
}
|
||||
|
||||
// MarshalJSON — представление по контракту: queued/processing/ready/failed,
|
||||
// варианты текущей опубликованной версии, error_code только у failed.
|
||||
func (a Attachment) MarshalJSON() ([]byte, error) {
|
||||
variants := a.Variants
|
||||
if variants == nil {
|
||||
variants = []Variant{}
|
||||
}
|
||||
var errCode *string
|
||||
if a.Status == AttachmentFailed && a.ErrorCode != "" {
|
||||
ec := a.ErrorCode
|
||||
errCode = &ec
|
||||
}
|
||||
return json.Marshal(struct {
|
||||
ID string `json:"id"`
|
||||
ChatID string `json:"chat_id"`
|
||||
OwnerID string `json:"owner_id"`
|
||||
Filename string `json:"filename"`
|
||||
ContentType string `json:"content_type"`
|
||||
SizeBytes int64 `json:"size_bytes"`
|
||||
SHA256 string `json:"sha256"`
|
||||
Status string `json:"status"`
|
||||
Variants []Variant `json:"variants"`
|
||||
ErrorCode *string `json:"error_code"`
|
||||
CreatedAt string `json:"created_at"`
|
||||
UpdatedAt string `json:"updated_at"`
|
||||
}{
|
||||
ID: a.ID, ChatID: a.ChatID, OwnerID: a.OwnerID, Filename: a.Filename,
|
||||
ContentType: a.ContentType, SizeBytes: a.SizeBytes, SHA256: a.SHA256,
|
||||
Status: a.Status, Variants: variants, ErrorCode: errCode,
|
||||
CreatedAt: a.CreatedAt.UTC().Truncate(time.Second).Format(time.RFC3339),
|
||||
UpdatedAt: a.UpdatedAt.UTC().Truncate(time.Second).Format(time.RFC3339),
|
||||
})
|
||||
}
|
||||
|
||||
// Job — сообщение broker по contracts/jobs.schema.json. Только ID и служебные
|
||||
// поля: ни байтов, ни URL, ни credentials.
|
||||
type Job struct {
|
||||
SchemaVersion int `json:"schema_version"`
|
||||
JobID string `json:"job_id"`
|
||||
Type string `json:"type"`
|
||||
AttachmentID string `json:"attachment_id"`
|
||||
PipelineVersion int `json:"pipeline_version"`
|
||||
Attempt int `json:"attempt"`
|
||||
CreatedAt string `json:"created_at"`
|
||||
Traceparent string `json:"traceparent,omitempty"`
|
||||
}
|
||||
|
||||
const JobType = "attachment.process.v1"
|
||||
@@ -0,0 +1,30 @@
|
||||
package domain
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Chat struct {
|
||||
ID string `json:"id"`
|
||||
Title string `json:"title"`
|
||||
MemberIDs []string `json:"member_ids"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
|
||||
func (c Chat) MarshalJSON() ([]byte, error) {
|
||||
type Alias Chat
|
||||
members := c.MemberIDs
|
||||
if members == nil {
|
||||
members = []string{}
|
||||
}
|
||||
return json.Marshal(&struct {
|
||||
Alias
|
||||
MemberIDs []string `json:"member_ids"`
|
||||
CreatedAt string `json:"created_at"`
|
||||
}{
|
||||
Alias: Alias(c),
|
||||
MemberIDs: members,
|
||||
CreatedAt: c.CreatedAt.UTC().Truncate(time.Second).Format(time.RFC3339),
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package domain
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Message struct {
|
||||
ID string `json:"id"`
|
||||
ChatID string `json:"chat_id"`
|
||||
SenderID string `json:"sender_id"`
|
||||
Text string `json:"text"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
// AttachmentIDs — в порядке отправки; всегда массив (пустой, если вложений нет).
|
||||
AttachmentIDs []string `json:"attachment_ids"`
|
||||
}
|
||||
|
||||
func (m Message) MarshalJSON() ([]byte, error) {
|
||||
type Alias Message
|
||||
if m.AttachmentIDs == nil {
|
||||
m.AttachmentIDs = []string{}
|
||||
}
|
||||
return json.Marshal(&struct {
|
||||
Alias
|
||||
CreatedAt string `json:"created_at"`
|
||||
}{
|
||||
Alias: Alias(m),
|
||||
CreatedAt: m.CreatedAt.UTC().Truncate(time.Second).Format(time.RFC3339),
|
||||
})
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user