lab7: безопасность, mTLS, OpenBao и PKI lifecycle

This commit is contained in:
Vladislav Kunetskiy
2026-11-10 10:58:07 +03:00
parent 3d216fbd50
commit 3441f2269a
183 changed files with 216667 additions and 3165 deletions
+43 -134
View File
@@ -1,145 +1,66 @@
# Copy to .env for your LOCAL synthetic test environment; never commit .env.
# Values below are the variables this implementation actually reads
# (viper: section.name -> SECTION_NAME, see internal/config/config.go).
#
# Mapping to the logical names suggested by the skeleton:
# APP_HOST / APP_PORT -> SERVER_HOST / SERVER_PORT
# SESSION_STORE=postgres -> server-side sessions live in PostgreSQL (SESSION_TTL_SECONDS)
# DATABASE_URL_FILE -> unused: POSTGRES_* below pass no secret files
# CACHE_URL_FILE -> unused: REDIS_* below pass no secret files
# API_REPLICAS -> number of API replicas of the stand (compose.yaml)
#
# APP_ENV selects config/<env>/config.yaml; the implementation supports only `dev`.
# Local synthetic stand. Copy to .env; this file contains NO credential values.
# make prepare generates role keys/backend secrets; operator root/unseal state
# stays outside the checkout under ~/.local/share/mtusi-lab7/<project> (0700).
COMPOSE_PROJECT_NAME=mtusi-messenger-lab6
LAB7_SECRETS_DIR=secrets/lab7
BASE_URL=https://localhost:8443
CA_FILE=secrets/lab7/pki/operator/current/ca.crt
PUBLIC_PORT=8443
S3_PORT=8333
BAO_PORT=8200
GRAFANA_PORT=3000
PROMETHEUS_PORT=9090
LOKI_PORT=3100
TEMPO_PORT=3200
BROKER_MANAGEMENT_PORT=15671
LB_STATS_PORT=8404
# Operator-local integration ports (only docker-compose.local.yaml publishes them).
TEST_POSTGRES_PORT=15432
TEST_REDIS_PORT=16379
# Service identities/CA/CRL are per-role mounts, set explicitly in compose.yaml:
# TLS_CA_FILE=/run/identity/current/ca.crt
# TLS_CERT_FILE=/run/identity/current/tls.crt
# TLS_KEY_FILE=/run/identity/current/tls.key
# TLS_CRL_FILE=/run/identity/current/ca.crl
# TLS_VERSION_FILE=/run/identity/current-version (atomic immutable-version selector)
# BAO_ADDR=https://openbao:8200; BAO_ROLE=api/worker/relay;
# BAO_KV_PATH=secret/data/<role>; credentials fetched by cert-auth at startup.
# Password PHC parameters: Argon2id v19 m=19456 KiB,t=2,p=1 (measured in REPORT).
# Shared login allowance: account8/minute, sourceIP120/minute, global16/second.
# Hashing concurrency: at most2 derivations per API replica; no unbounded queue.
APP_ENV=dev
SERVER_HOST=0.0.0.0
SERVER_PORT=8080
SERVER_READ_HEADER_TIMEOUT=10s
SERVER_READ_TIMEOUT=60s
SERVER_SHUTDOWN_TIMEOUT=10s
# Предел размера тела запроса (байт): защищает реплику от чтения огромного тела
# до валидации. Для вложений LAB4 (до 10 MiB) значение нужно поднять.
SERVER_MAX_BODY_BYTES=262144
LOG_LEVEL=info
LOG_FORMAT=json
# Synthetic credentials for the local stand only; override in .env for anything else.
POSTGRES_HOST=localhost
POSTGRES_PORT=5432
POSTGRES_DATABASE=messenger
POSTGRES_USER=messenger
POSTGRES_PASSWORD=messenger
POSTGRES_SSL_MODE=disable
POSTGRES_MAX_CONNS=10
POSTGRES_MIN_CONNS=1
POSTGRES_MAX_CONN_LIFETIME=1h
POSTGRES_MAX_CONN_IDLE_TIME=30m
POSTGRES_CONNECT_TIMEOUT=5s
POSTGRES_QUERY_TIMEOUT=5s
REDIS_ENABLED=true
REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_PASSWORD=
REDIS_DB=0
# -1 disables go-redis retries; 0 keeps the library default (3 retries).
REDIS_MAX_RETRIES=-1
REDIS_DIAL_TIMEOUT=300ms
REDIS_READ_TIMEOUT=200ms
REDIS_WRITE_TIMEOUT=200ms
REDIS_POOL_SIZE=10
CACHE_ENABLED=true
CACHE_CHAT_LIST_TTL=5m
CACHE_LOCK_TTL=10s
CACHE_LOCK_WAIT_TIMEOUT=2s
SESSION_TTL_SECONDS=3600
# Retention of a message Idempotency-Key in the shared store; contract 1.3.0
# requires at least 24 h.
IDEMPOTENCY_TTL_SECONDS=86400
# Lab3 stand (compose.yaml): number of API replicas behind the LB and per-replica
# CPU/RAM limits. Track 1 varies them to compare 1/2/4 replicas at a fixed total
# budget, e.g. API_REPLICAS=4 API_CPU_LIMIT=0.25 API_MEM_LIMIT=192M.
API_REPLICAS=2
API_CPU_LIMIT=0.50
API_MEM_LIMIT=256M
# Connections of ONE API replica to PostgreSQL; the total is replicas × value.
# Track 1 checks whether the shared connection budget becomes the saturation
# point: at 4 replicas the default 10 means 40 connections against one database.
POSTGRES_MAX_CONNS=10
# CPU quota of the shared database. Track 1 shows it is the stand's saturation
# point: the API uses a fraction of its budget while PostgreSQL sits at its own.
POSTGRES_CPU_LIMIT=0.50
# Memory quota of the shared database. The track 1 series r/g/pool were measured
# with 512M, the db1cpu control — with 384M (see evidence/track1/profile-*.json).
POSTGRES_MEM_LIMIT=192M
# Loopback port of the HAProxy operator page (UP/DOWN of every replica).
LB_STATS_PORT=8404
# --- Lab4: private S3 object store (SeaweedFS) -------------------------------
# Synthetic local application credentials. infra/s3/s3.json must contain the
# same app values; scripts/check_s3_creds.py enforces that before the stand starts.
# Admin credentials live only in infra/s3/s3.json and s3-init defaults; never put
# them in .env, because the API service loads this file.
S3_ENDPOINT=http://localhost:8333
S3_PUBLIC_ENDPOINT=http://127.0.0.1:8333
S3_PORT=8333
S3_REGION=us-east-1
POSTGRES_MEM_LIMIT=320M
POSTGRES_MAX_CONNS=10
S3_BUCKET=messenger-attachments
S3_ACCESS_KEY_ID=lab4app
S3_SECRET_ACCESS_KEY=lab4app-secret
# Attachment limits from contract 1.5.0.
MAX_UPLOAD_BYTES=10485760
MAX_IMAGE_PIXELS=40000000
# Presigned upload lifetime and the sweeper's safety window.
S3_PRESIGN_TTL=5m
S3_SWEEP_INTERVAL=1m
S3_SWEEP_GRACE=10m
# --- Lab5: durable queues and async image processing -------------------------
# Synthetic broker credentials for the local Compose stand. The relay/worker
# connect inside the compose network; the management UI is published only on
# loopback by compose.yaml.
BROKER_USER=messenger
BROKER_PASSWORD=messenger
BROKER_VHOST=messenger
BROKER_URL=amqp://messenger:messenger@broker:5672/messenger
BROKER_EXCHANGE=attachments.jobs
BROKER_QUEUE=attachment.process.v1
BROKER_DLX=attachments.dlx
BROKER_DLQ=attachment.process.dead
BROKER_MANAGEMENT_PORT=15672
BROKER_CPU_LIMIT=0.50
BROKER_MEM_LIMIT=384M
# Worker process bounds. Concurrency=1 is the safe default for a 40 MP image on
# the course VM; raise it together with WORKER_MEM_LIMIT.
WORKER_CONCURRENCY=1
WORKER_PREFETCH=1
WORKER_CPU_LIMIT=1.00
WORKER_MEM_LIMIT=1G
WORKER_SHUTDOWN_TIMEOUT=30s
WORKER_HEALTH_PORT=8081
# Shared job contract. The API chooses the pipeline version for new uploads.
BROKER_CPU_LIMIT=0.50
BROKER_MEM_LIMIT=384M
PROCESSING_PIPELINE_VERSION=1
PROCESSING_MAX_ATTEMPTS=5
PROCESSING_JOB_TIMEOUT=120s
PROCESSING_LEASE_TTL=180s
PROCESSING_HEARTBEAT=30s
PROCESSING_JOB_TIMEOUT=60s
PROCESSING_LEASE_TTL=90s
PROCESSING_HEARTBEAT=15s
PROCESSING_RETRY_BASE=2s
PROCESSING_RETRY_CAP=60s
# Outbox relay and lease reaper.
OUTBOX_POLL_INTERVAL=1s
OUTBOX_CLAIM_TTL=30s
OUTBOX_BATCH=20
@@ -148,9 +69,6 @@ OUTBOX_RECONCILE_AFTER=5m
OUTBOX_RETENTION=168h
RELAY_CPU_LIMIT=0.25
RELAY_MEM_LIMIT=128M
RELAY_HEALTH_PORT=8082
# Staging cleanup and admission control.
STAGING_ORPHAN_GRACE=1h
STAGING_FAILED_RETENTION=168h
ADMISSION_MAX_PENDING_PER_USER=20
@@ -158,19 +76,10 @@ ADMISSION_MAX_PENDING=200
ADMISSION_MAX_STAGED_BYTES=2147483648
ADMISSION_MAX_CONCURRENT_UPLOADS=8
# --- Lab6: observability -----------------------------------------------------
# SDK/Collector settings; OTLP traffic must never carry message bodies,
# attachment bytes, credentials or user/chat/message ids as metric labels.
# Service names are set per service in compose.yaml (API/worker/relay must differ).
OTEL_EXPORTER_OTLP_ENDPOINT=http://otel-collector:4318
OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
OTEL_RESOURCE_ATTRIBUTES=deployment.environment.name=lab
OTEL_METRIC_EXPORT_INTERVAL=15000
# Telemetry is part of the full stand, not a plaintext optional profile.
TELEMETRY_ENABLED=1
PROMETHEUS_PORT=9090
LOKI_PORT=3100
TEMPO_PORT=3200
GRAFANA_PORT=3000
OTEL_TRACES_SAMPLER=always_on
OTEL_METRIC_EXPORT_INTERVAL=5000
OTEL_COLLECTOR_CPU_LIMIT=0.25
OTEL_COLLECTOR_MEM_LIMIT=192M
PROMETHEUS_CPU_LIMIT=0.50