From 32795a92acdb479fff78bd3ec5ca2768ab80c66f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=B0=D1=81=D0=B8=D0=BB=D1=8C=D0=B5=D0=B2=20=D0=9D?= =?UTF-8?q?=D0=B8=D0=BA=D0=B8=D1=82=D0=B0?= Date: Mon, 16 Nov 2026 11:57:32 +0300 Subject: [PATCH] Implement TLS identities, scoped OpenBao access and worker security study --- .dockerignore | 29 +- .gitignore | 6 + Dockerfile | 20 + Makefile | 25 + compose.yaml | 755 +++++++++++++ infra/filer.toml | 3 + infra/grafana/dashboards/messenger.json | 450 ++++++++ .../provisioning/dashboards/dashboards.yaml | 7 + .../provisioning/datasources/datasources.yaml | 27 + infra/haproxy.cfg | 38 + infra/observability/alerts.yaml | 24 + infra/observability/collector.yaml | 87 ++ infra/observability/loki.yaml | 34 + infra/observability/prometheus.yaml | 26 + infra/observability/tempo.yaml | 24 + infra/openbao.hcl | 12 + infra/pg-entrypoint.sh | 6 + infra/pg_hba.conf | 3 + migrations/001_initial.sql | 35 + migrations/002_idempotency.sql | 10 + migrations/003_unicode_storage.sql | 13 + migrations/004_attachments.sql | 35 + migrations/005_attachment_only_message.sql | 3 + migrations/006_jobs.sql | 49 + migrations/007_observability.sql | 2 + migrations/008_security.sql | 16 + migrations/009_telemetry_acceptance.sql | 4 + migrations/010_login_window_cleanup.sql | 1 + pyproject.toml | 32 + research/auth_budget.py | 115 ++ research/compromise.py | 108 ++ research/sealed.py | 71 ++ scripts/bao_operator.py | 115 ++ scripts/bootstrap.py | 340 ++++++ scripts/restart.sh | 9 + scripts/rotate_identity.py | 91 ++ scripts/security_checks.py | 217 ++++ scripts/stop-one.sh | 4 + scripts/stop_one.py | 22 + src/messenger/__init__.py | 1 + src/messenger/__main__.py | 12 + src/messenger/app.py | 384 +++++++ src/messenger/attachments.py | 176 +++ src/messenger/baseline_db_probe.py | 81 ++ src/messenger/baseline_queue_probe.py | 65 ++ src/messenger/baseline_s3_probe.py | 88 ++ src/messenger/config.py | 14 + src/messenger/domain.py | 63 ++ src/messenger/image_pipeline.py | 82 ++ src/messenger/image_validation.py | 146 +++ src/messenger/jobctl.py | 123 ++ src/messenger/jobs.py | 345 ++++++ src/messenger/kdf_probe.py | 49 + src/messenger/migrate.py | 32 + src/messenger/models.py | 71 ++ src/messenger/postgres.py | 365 ++++++ src/messenger/revoked_probe.py | 60 + src/messenger/secrets_provider.py | 59 + src/messenger/secure_entry.py | 35 + src/messenger/security_probe.py | 108 ++ src/messenger/storage.py | 106 ++ src/messenger/storage_bootstrap.py | 30 + src/messenger/telemetry.py | 357 ++++++ src/messenger/tls_gateway.py | 272 +++++ src/messenger/transport_probe.py | 132 +++ src/messenger/worker.py | 292 +++++ student-tests/test_api.py | 201 ++++ student-tests/test_attachments.py | 203 ++++ student-tests/test_cursor_format.py | 39 + student-tests/test_cursor_http.py | 49 + student-tests/test_edgecases.py | 99 ++ student-tests/test_image_edges.py | 229 ++++ student-tests/test_jobs.py | 72 ++ student-tests/test_json_encoding.py | 169 +++ student-tests/test_pipeline.py | 46 + student-tests/test_sessions.py | 62 + student-tests/test_tls_boundary.py | 231 ++++ uv.lock | 1001 +++++++++++++++++ 78 files changed, 8798 insertions(+), 19 deletions(-) create mode 100644 Dockerfile create mode 100644 compose.yaml create mode 100644 infra/filer.toml create mode 100644 infra/grafana/dashboards/messenger.json create mode 100644 infra/grafana/provisioning/dashboards/dashboards.yaml create mode 100644 infra/grafana/provisioning/datasources/datasources.yaml create mode 100644 infra/haproxy.cfg create mode 100644 infra/observability/alerts.yaml create mode 100644 infra/observability/collector.yaml create mode 100644 infra/observability/loki.yaml create mode 100644 infra/observability/prometheus.yaml create mode 100644 infra/observability/tempo.yaml create mode 100644 infra/openbao.hcl create mode 100755 infra/pg-entrypoint.sh create mode 100644 infra/pg_hba.conf create mode 100644 migrations/001_initial.sql create mode 100644 migrations/002_idempotency.sql create mode 100644 migrations/003_unicode_storage.sql create mode 100644 migrations/004_attachments.sql create mode 100644 migrations/005_attachment_only_message.sql create mode 100644 migrations/006_jobs.sql create mode 100644 migrations/007_observability.sql create mode 100644 migrations/008_security.sql create mode 100644 migrations/009_telemetry_acceptance.sql create mode 100644 migrations/010_login_window_cleanup.sql create mode 100644 pyproject.toml create mode 100644 research/auth_budget.py create mode 100644 research/compromise.py create mode 100644 research/sealed.py create mode 100644 scripts/bao_operator.py create mode 100644 scripts/bootstrap.py create mode 100755 scripts/restart.sh create mode 100644 scripts/rotate_identity.py create mode 100644 scripts/security_checks.py create mode 100755 scripts/stop-one.sh create mode 100644 scripts/stop_one.py create mode 100644 src/messenger/__init__.py create mode 100644 src/messenger/__main__.py create mode 100644 src/messenger/app.py create mode 100644 src/messenger/attachments.py create mode 100644 src/messenger/baseline_db_probe.py create mode 100644 src/messenger/baseline_queue_probe.py create mode 100644 src/messenger/baseline_s3_probe.py create mode 100644 src/messenger/config.py create mode 100644 src/messenger/domain.py create mode 100644 src/messenger/image_pipeline.py create mode 100644 src/messenger/image_validation.py create mode 100644 src/messenger/jobctl.py create mode 100644 src/messenger/jobs.py create mode 100644 src/messenger/kdf_probe.py create mode 100644 src/messenger/migrate.py create mode 100644 src/messenger/models.py create mode 100644 src/messenger/postgres.py create mode 100644 src/messenger/revoked_probe.py create mode 100644 src/messenger/secrets_provider.py create mode 100644 src/messenger/secure_entry.py create mode 100644 src/messenger/security_probe.py create mode 100644 src/messenger/storage.py create mode 100644 src/messenger/storage_bootstrap.py create mode 100644 src/messenger/telemetry.py create mode 100644 src/messenger/tls_gateway.py create mode 100644 src/messenger/transport_probe.py create mode 100644 src/messenger/worker.py create mode 100644 student-tests/test_api.py create mode 100644 student-tests/test_attachments.py create mode 100644 student-tests/test_cursor_format.py create mode 100644 student-tests/test_cursor_http.py create mode 100644 student-tests/test_edgecases.py create mode 100644 student-tests/test_image_edges.py create mode 100644 student-tests/test_jobs.py create mode 100644 student-tests/test_json_encoding.py create mode 100644 student-tests/test_pipeline.py create mode 100644 student-tests/test_sessions.py create mode 100644 student-tests/test_tls_boundary.py create mode 100644 uv.lock diff --git a/.dockerignore b/.dockerignore index bc16e55..e8f399b 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,20 +1,11 @@ -.git -.github -.env -.env.* -!.env.example +* +!pyproject.toml +!uv.lock +!src/ +!src/** +!migrations/ +!migrations/** + +operator-private secrets -certs -volumes -data -backups -*.key -*.pem -*.p12 -*.pfx -*.jks -.venv -__pycache__ -node_modules -evidence -.DS_Store +.env diff --git a/.gitignore b/.gitignore index b5a7189..9846e0a 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,9 @@ coverage/ .vscode/ # Keep small, sanitized evidence summaries in evidence/ under version control. # Inspect git diff --cached: ignore rules are not a secret scanner. +.pytest_cache/ +.ruff_cache/ + +operator-private/ +secrets/ +.env diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..a56a90e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,20 @@ +FROM python:3.12-slim@sha256:646fb0bca3dd3ea1bcc6feb72c17ed16eed6e10cffc732fcc1478bd3e7f02d7b AS build +COPY --from=ghcr.io/astral-sh/uv:0.11.7 /uv /usr/local/bin/uv +WORKDIR /app +COPY pyproject.toml uv.lock ./ +RUN uv sync --locked --no-dev --no-install-project --python /usr/local/bin/python + +FROM python:3.12-slim@sha256:646fb0bca3dd3ea1bcc6feb72c17ed16eed6e10cffc732fcc1478bd3e7f02d7b +RUN apt-get update && apt-get upgrade -y && apt-get install -y --no-install-recommends libjpeg-turbo-progs && rm -rf /var/lib/apt/lists/* +RUN python -m pip uninstall --yes pip +ARG VCS_REF=uncommitted +LABEL org.opencontainers.image.revision=$VCS_REF +ENV PYTHONUNBUFFERED=1 PYTHONDONTWRITEBYTECODE=1 PYTHONPATH=/app/src PATH=/app/.venv/bin:$PATH +WORKDIR /app +COPY --from=build /app/.venv /app/.venv +COPY src ./src +COPY migrations ./migrations +USER 10001:10001 +EXPOSE 8080 +HEALTHCHECK --interval=3s --timeout=2s --start-period=5s --retries=5 CMD ["python", "-c", "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8080/health/ready', timeout=1)"] +CMD ["python", "-m", "messenger"] diff --git a/Makefile b/Makefile index 5ad43ad..47c4653 100644 --- a/Makefile +++ b/Makefile @@ -31,3 +31,28 @@ test-failover: test-security: $(PYTHON) tests/security.py --base-url "$(BASE_URL)" $(TLS_ARGS) + +# Student implementation; teacher acceptance targets remain unchanged. +PUBLIC_PORT ?= 8447 +BASE_URL = https://localhost:$(PUBLIC_PORT) +CA_FILE = $(CURDIR)/secrets/ca.pem +bootstrap: + python3 scripts/bootstrap.py +build: + VCS_REF=$$(git rev-parse HEAD) docker compose build +init: bootstrap build + docker compose up -d postgres openbao cache cache-tls broker broker-tls storage s3 storage-tls + python3 scripts/bao_operator.py init +up: init + VCS_REF=$$(git rev-parse HEAD) docker compose up -d --wait +unseal: + python3 scripts/bao_operator.py unseal +migrate: + docker compose run --rm migrate +down: + docker compose down +student-test: + BASE_URL=$(BASE_URL) SSL_CERT_FILE=$(CA_FILE) uv run --locked pytest -q +lint: + uv run --locked ruff check src student-tests scripts +.PHONY: bootstrap build init up unseal migrate down student-test lint diff --git a/compose.yaml b/compose.yaml new file mode 100644 index 0000000..acc0e1c --- /dev/null +++ b/compose.yaml @@ -0,0 +1,755 @@ +name: mtusi-vasilev-lab7 +x-hardening: + cpus: 0.25 + mem_limit: 128m + pids_limit: 96 + cap_drop: &id001 + - ALL + security_opt: &id002 + - no-new-privileges:true + read_only: true + tmpfs: &id003 + - /tmp:size=16m,noexec,nosuid +x-environment: + BAO_ADDR: https://openbao:8200 + S3_ENDPOINT: https://storage:8443 + S3_BUCKET: messenger + S3_CA_FILE: /run/tls/ca.pem + SSL_CERT_FILE: /run/tls/ca.pem + JOB_MAX_ATTEMPTS: ${JOB_MAX_ATTEMPTS:-5} + JOB_LEASE_SECONDS: ${JOB_LEASE_SECONDS:-45} + SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600} + OTEL_EXPORTER_OTLP_ENDPOINT: https://collector:4318 + OTEL_EXPORTER_OTLP_CERTIFICATE: /run/tls/ca.pem + OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATE: /run/tls/identity/cert.pem + OTEL_EXPORTER_OTLP_CLIENT_KEY: /run/tls/identity/key.pem + OTEL_ENABLED: '1' + OTEL_METRIC_INTERVAL_MS: '5000' +x-application: + cpus: 0.5 + mem_limit: 512m + pids_limit: 96 + cap_drop: *id001 + security_opt: *id002 + read_only: true + tmpfs: *id003 + image: ${API_IMAGE:-mtusi-vasilev:lab7} + build: &id004 + context: . + args: + VCS_REF: ${VCS_REF:-uncommitted} + stop_grace_period: 8s +services: + postgres: + image: postgres:17.10-alpine + entrypoint: + - /etc/pg-entrypoint.sh + environment: + POSTGRES_USER: messenger + POSTGRES_DB: messenger + POSTGRES_PASSWORD_FILE: /run/secrets/postgres_password + secrets: + - postgres_password + volumes: + - postgres_data:/var/lib/postgresql/data + - ./secrets/pki/postgres:/run/tls/identity:ro + - ./secrets/ca.pem:/run/tls/ca.pem:ro + - ./infra/pg-entrypoint.sh:/etc/pg-entrypoint.sh:ro + - ./infra/pg_hba.conf:/etc/postgresql/pg_hba.conf:ro + - ./secrets/db_roles.sql:/docker-entrypoint-initdb.d/01_roles.sql:ro + cpus: 0.75 + mem_limit: 768m + command: + - postgres + - -c + - fsync=on + - -c + - ssl=on + - -c + - ssl_cert_file=/run/tls/identity/cert.pem + - -c + - ssl_key_file=/tmp/postgres-key.pem + - -c + - ssl_ca_file=/run/tls/ca.pem + - -c + - hba_file=/etc/postgresql/pg_hba.conf + healthcheck: + test: + - CMD-SHELL + - pg_isready -U messenger -d messenger + interval: 2s + timeout: 2s + retries: 20 + openbao: + cpus: 0.25 + mem_limit: 192m + pids_limit: 96 + cap_drop: *id001 + security_opt: *id002 + read_only: true + tmpfs: *id003 + image: ghcr.io/openbao/openbao:2.5.2 + user: 100:1000 + command: + - server + - -config=/etc/openbao.hcl + ports: + - 127.0.0.1:18207:8200 + volumes: + - bao_data:/bao/data + - ./infra/openbao.hcl:/etc/openbao.hcl:ro + - ./secrets/pki/openbao:/run/tls/identity:ro + - ./secrets/ca.pem:/run/tls/ca.pem:ro + depends_on: + state-init: + condition: service_completed_successfully + cache: + cpus: 0.25 + mem_limit: 128m + pids_limit: 96 + cap_drop: *id001 + security_opt: *id002 + read_only: true + tmpfs: *id003 + image: valkey/valkey:8.1.3-alpine + command: + - /run/secrets/cache_config + secrets: + - cache_config + user: 1000:1000 + entrypoint: + - valkey-server + cache-tls: + cpus: 0.5 + mem_limit: 64m + pids_limit: 96 + cap_drop: *id001 + security_opt: *id002 + read_only: true + tmpfs: *id003 + image: ${API_IMAGE:-mtusi-vasilev:lab7} + build: *id004 + stop_grace_period: 8s + network_mode: service:cache + command: + - python + - -m + - messenger.tls_gateway + - --config + - /run/tls/gateway.json + volumes: + - ./secrets/pki/cache:/run/tls/identity:ro + - ./secrets/ca.pem:/run/tls/ca.pem:ro + - ./secrets/revoked.json:/run/tls/revoked.json:ro + - ./secrets/cache_gateway.json:/run/tls/gateway.json:ro + healthcheck: + disable: true + broker: + cpus: 0.25 + mem_limit: 192m + pids_limit: 96 + cap_drop: *id001 + security_opt: *id002 + read_only: true + tmpfs: *id003 + image: valkey/valkey:8.1.3-alpine + command: + - /run/secrets/broker_config + secrets: + - broker_config + volumes: + - broker_data:/data + depends_on: + state-init: + condition: service_completed_successfully + user: 1000:1000 + entrypoint: + - valkey-server + broker-tls: + cpus: 0.5 + mem_limit: 64m + pids_limit: 96 + cap_drop: *id001 + security_opt: *id002 + read_only: true + tmpfs: *id003 + image: ${API_IMAGE:-mtusi-vasilev:lab7} + build: *id004 + stop_grace_period: 8s + network_mode: service:broker + command: + - python + - -m + - messenger.tls_gateway + - --config + - /run/tls/gateway.json + volumes: + - ./secrets/pki/broker:/run/tls/identity:ro + - ./secrets/ca.pem:/run/tls/ca.pem:ro + - ./secrets/revoked.json:/run/tls/revoked.json:ro + - ./secrets/broker_gateway.json:/run/tls/gateway.json:ro + healthcheck: + disable: true + storage: + image: chrislusf/seaweedfs:4.15@sha256:1593bd2a98964f5d4df83fa7db2b3d4ee7b20190813cc5bf8c3200e0e70d346e + command: + - server + - -dir=/data + - -ip=127.0.0.1 + - -ip.bind=127.0.0.1 + - -filer + - -volume.max=32 + - -volume.preStopSeconds=0 + - -master.volumeSizeLimitMB=64 + volumes: + - s3_data:/data + - ./infra/filer.toml:/etc/seaweedfs/filer.toml:ro + cpus: 0.5 + mem_limit: 512m + cap_drop: + - ALL + security_opt: + - no-new-privileges:true + healthcheck: + test: + - CMD-SHELL + - wget -q -O /dev/null http://127.0.0.1:9333/dir/status + interval: 2s + timeout: 2s + retries: 25 + depends_on: + state-init: + condition: service_completed_successfully + user: 1000:1000 + entrypoint: + - /usr/bin/weed + s3: + image: chrislusf/seaweedfs:4.15@sha256:1593bd2a98964f5d4df83fa7db2b3d4ee7b20190813cc5bf8c3200e0e70d346e + network_mode: service:storage + command: + - s3 + - -filer=127.0.0.1:8888 + - -ip.bind=127.0.0.1 + - -config=/run/secrets/s3_config + - -port=8333 + - -port.iceberg=0 + secrets: + - s3_config + depends_on: + storage: + condition: service_healthy + cpus: 0.25 + mem_limit: 256m + cap_drop: + - ALL + security_opt: + - no-new-privileges:true + user: 1000:1000 + entrypoint: + - /usr/bin/weed + storage-tls: + cpus: 0.5 + mem_limit: 96m + pids_limit: 96 + cap_drop: *id001 + security_opt: *id002 + read_only: true + tmpfs: *id003 + image: ${API_IMAGE:-mtusi-vasilev:lab7} + build: *id004 + stop_grace_period: 8s + network_mode: service:storage + command: + - python + - -m + - messenger.tls_gateway + - --config + - /run/tls/gateway.json + volumes: + - ./secrets/pki/storage:/run/tls/identity:ro + - ./secrets/ca.pem:/run/tls/ca.pem:ro + - ./secrets/revoked.json:/run/tls/revoked.json:ro + - ./secrets/storage_gateway.json:/run/tls/gateway.json:ro + healthcheck: + disable: true + migrate: + cpus: 0.5 + mem_limit: 512m + pids_limit: 96 + cap_drop: *id001 + security_opt: *id002 + read_only: true + tmpfs: *id003 + image: ${API_IMAGE:-mtusi-vasilev:lab7} + build: *id004 + stop_grace_period: 8s + command: + - python + - -m + - messenger.migrate + environment: + DATABASE_URL_FILE: /run/secrets/admin_database_url + secrets: + - admin_database_url + volumes: + - ./secrets/ca.pem:/run/tls/ca.pem:ro + healthcheck: + disable: true + depends_on: + postgres: + condition: service_healthy + s3-bootstrap: + cpus: 0.5 + mem_limit: 512m + pids_limit: 96 + cap_drop: *id001 + security_opt: *id002 + read_only: true + tmpfs: *id003 + image: ${API_IMAGE:-mtusi-vasilev:lab7} + build: *id004 + stop_grace_period: 8s + command: + - python + - -m + - messenger.storage_bootstrap + environment: + S3_ENDPOINT: https://storage:8443 + S3_ADMIN_ACCESS_KEY_FILE: /run/secrets/admin_s3_access_key + S3_ADMIN_SECRET_KEY_FILE: /run/secrets/admin_s3_secret_key + secrets: + - admin_s3_access_key + - admin_s3_secret_key + volumes: + - ./secrets/pki/operator:/run/tls/identity:ro + - ./secrets/ca.pem:/run/tls/ca.pem:ro + healthcheck: + disable: true + depends_on: + storage-tls: + condition: service_started + api: + cpus: 0.5 + mem_limit: 512m + pids_limit: 96 + cap_drop: *id001 + security_opt: *id002 + read_only: true + tmpfs: *id003 + image: ${API_IMAGE:-mtusi-vasilev:lab7} + build: *id004 + stop_grace_period: 8s + command: + - python + - -m + - messenger.secure_entry + environment: + BAO_ADDR: https://openbao:8200 + S3_ENDPOINT: https://storage:8443 + S3_BUCKET: messenger + S3_CA_FILE: /run/tls/ca.pem + SSL_CERT_FILE: /run/tls/ca.pem + JOB_MAX_ATTEMPTS: ${JOB_MAX_ATTEMPTS:-5} + JOB_LEASE_SECONDS: ${JOB_LEASE_SECONDS:-45} + SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600} + OTEL_EXPORTER_OTLP_ENDPOINT: https://collector:4318 + OTEL_EXPORTER_OTLP_CERTIFICATE: /run/tls/ca.pem + OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATE: /run/tls/identity/cert.pem + OTEL_EXPORTER_OTLP_CLIENT_KEY: /run/tls/identity/key.pem + BAO_ROLE: api + TLS_GATEWAY_CONFIG: /run/tls/gateway.json + OTEL_ENABLED: '1' + OTEL_METRIC_INTERVAL_MS: '5000' + volumes: + - ./secrets/pki/api:/run/tls/identity:ro + - ./secrets/ca.pem:/run/tls/ca.pem:ro + - ./secrets/revoked.json:/run/tls/revoked.json:ro + - ./secrets/api_gateway.json:/run/tls/gateway.json:ro + deploy: + replicas: ${API_REPLICAS:-2} + depends_on: + migrate: + condition: service_completed_successfully + s3-bootstrap: + condition: service_completed_successfully + cache-tls: + condition: service_started + dispatcher: + cpus: 0.5 + mem_limit: 192m + pids_limit: 96 + cap_drop: *id001 + security_opt: *id002 + read_only: true + tmpfs: *id003 + image: ${API_IMAGE:-mtusi-vasilev:lab7} + build: *id004 + stop_grace_period: 8s + command: + - python + - -m + - messenger.worker + - --dispatcher + environment: + BAO_ADDR: https://openbao:8200 + S3_ENDPOINT: https://storage:8443 + S3_BUCKET: messenger + S3_CA_FILE: /run/tls/ca.pem + SSL_CERT_FILE: /run/tls/ca.pem + JOB_MAX_ATTEMPTS: ${JOB_MAX_ATTEMPTS:-5} + JOB_LEASE_SECONDS: ${JOB_LEASE_SECONDS:-45} + SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600} + OTEL_EXPORTER_OTLP_ENDPOINT: https://collector:4318 + OTEL_EXPORTER_OTLP_CERTIFICATE: /run/tls/ca.pem + OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATE: /run/tls/identity/cert.pem + OTEL_EXPORTER_OTLP_CLIENT_KEY: /run/tls/identity/key.pem + BAO_ROLE: dispatcher + OTEL_ENABLED: '1' + OTEL_METRIC_INTERVAL_MS: '5000' + volumes: + - ./secrets/pki/dispatcher:/run/tls/identity:ro + - ./secrets/ca.pem:/run/tls/ca.pem:ro + healthcheck: + disable: true + restart: unless-stopped + depends_on: + migrate: + condition: service_completed_successfully + broker-tls: + condition: service_started + worker: + cpus: 0.75 + mem_limit: 896m + pids_limit: 96 + cap_drop: *id001 + security_opt: *id002 + read_only: true + tmpfs: + - /tmp:size=32m,noexec,nosuid + image: ${API_IMAGE:-mtusi-vasilev:lab7} + build: *id004 + stop_grace_period: 30s + command: + - python + - -m + - messenger.worker + environment: + BAO_ADDR: https://openbao:8200 + S3_ENDPOINT: https://storage:8443 + S3_BUCKET: messenger + S3_CA_FILE: /run/tls/ca.pem + SSL_CERT_FILE: /run/tls/ca.pem + JOB_MAX_ATTEMPTS: ${JOB_MAX_ATTEMPTS:-5} + JOB_LEASE_SECONDS: ${JOB_LEASE_SECONDS:-45} + SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600} + OTEL_EXPORTER_OTLP_ENDPOINT: https://collector:4318 + OTEL_EXPORTER_OTLP_CERTIFICATE: /run/tls/ca.pem + OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATE: /run/tls/identity/cert.pem + OTEL_EXPORTER_OTLP_CLIENT_KEY: /run/tls/identity/key.pem + BAO_ROLE: worker + OTEL_ENABLED: '1' + OTEL_METRIC_INTERVAL_MS: '5000' + volumes: + - ./secrets/pki/worker:/run/tls/identity:ro + - ./secrets/ca.pem:/run/tls/ca.pem:ro + healthcheck: + disable: true + restart: unless-stopped + depends_on: + migrate: + condition: service_completed_successfully + broker-tls: + condition: service_started + s3-bootstrap: + condition: service_completed_successfully + lb: + cpus: 0.25 + mem_limit: 128m + pids_limit: 96 + cap_drop: *id001 + security_opt: *id002 + read_only: true + tmpfs: *id003 + image: haproxy:3.2-alpine@sha256:96ec3c75a9264ba94e733eeacb44051ed6e7b79bb77a73c2c36f236b6423f1f0 + ports: + - 127.0.0.1:${PUBLIC_PORT:-8447}:8443 + volumes: + - ./infra/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro + - ./secrets/pki/lb:/run/tls/identity:ro + - ./secrets/ca.pem:/run/tls/ca.pem:ro + depends_on: + api: + condition: service_healthy + healthcheck: + test: + - CMD-SHELL + - test -S /tmp/haproxy.sock + interval: 2s + timeout: 2s + retries: 20 + collector: + cpus: 0.25 + mem_limit: 256m + pids_limit: 96 + cap_drop: *id001 + security_opt: *id002 + read_only: true + tmpfs: *id003 + image: otel/opentelemetry-collector-contrib:0.123.0 + command: + - --config=/etc/otelcol/config.yaml + volumes: + - ./infra/observability/collector.yaml:/etc/otelcol/config.yaml:ro + - ./secrets/pki/collector:/run/tls/identity:ro + - ./secrets/ca.pem:/run/tls/ca.pem:ro + prometheus: + cpus: 0.25 + mem_limit: 256m + pids_limit: 96 + cap_drop: *id001 + security_opt: *id002 + read_only: true + tmpfs: *id003 + image: prom/prometheus:v3.2.1 + command: + - --config.file=/etc/prometheus/prometheus.yml + - --storage.tsdb.path=/prometheus + - --storage.tsdb.retention.time=24h + - --web.listen-address=127.0.0.1:9090 + volumes: + - ./infra/observability/prometheus.yaml:/etc/prometheus/prometheus.yml:ro + - ./infra/observability/alerts.yaml:/etc/prometheus/alerts.yaml:ro + - prometheus_data:/prometheus + - ./secrets/pki/prometheus:/run/tls/identity:ro + - ./secrets/ca.pem:/run/tls/ca.pem:ro + ports: + - 127.0.0.1:19097:9443 + depends_on: + state-init: + condition: service_completed_successfully + loki: + cpus: 0.25 + mem_limit: 384m + pids_limit: 96 + cap_drop: *id001 + security_opt: *id002 + read_only: true + tmpfs: *id003 + image: grafana/loki:3.4.2 + command: + - -config.file=/etc/loki/config.yaml + volumes: + - ./infra/observability/loki.yaml:/etc/loki/config.yaml:ro + - loki_data:/loki + depends_on: + state-init: + condition: service_completed_successfully + tempo: + cpus: 0.25 + mem_limit: 768m + environment: + GOMEMLIMIT: 512MiB + pids_limit: 96 + cap_drop: *id001 + security_opt: *id002 + read_only: true + tmpfs: *id003 + image: grafana/tempo:2.7.2 + command: + - -config.file=/etc/tempo/config.yaml + volumes: + - ./infra/observability/tempo.yaml:/etc/tempo/config.yaml:ro + - tempo_data:/var/tempo + depends_on: + state-init: + condition: service_completed_successfully + grafana: + cpus: 0.25 + mem_limit: 256m + pids_limit: 96 + cap_drop: *id001 + security_opt: *id002 + read_only: true + tmpfs: *id003 + image: grafana/grafana:11.6.0 + environment: + GF_AUTH_ANONYMOUS_ENABLED: 'false' + GF_AUTH_DISABLE_LOGIN_FORM: 'false' + GF_USERS_ALLOW_SIGN_UP: 'false' + GF_ANALYTICS_REPORTING_ENABLED: 'false' + GF_ANALYTICS_CHECK_FOR_UPDATES: 'false' + GF_SECURITY_ADMIN_PASSWORD__FILE: /run/secrets/grafana_password + GF_SERVER_PROTOCOL: https + GF_SERVER_CERT_FILE: /run/tls/identity/cert.pem + GF_SERVER_CERT_KEY: /run/tls/identity/key.pem + volumes: + - ./secrets/grafana-provisioning/datasources:/etc/grafana/provisioning/datasources:ro + - ./infra/grafana/provisioning/dashboards:/etc/grafana/provisioning/dashboards:ro + - ./infra/grafana/dashboards:/var/lib/grafana/dashboards:ro + - grafana_data:/var/lib/grafana + - ./secrets/pki/grafana:/run/tls/identity:ro + - ./secrets/ca.pem:/run/tls/ca.pem:ro + ports: + - 127.0.0.1:13007:3000 + secrets: + - grafana_password + depends_on: + state-init: + condition: service_completed_successfully + collector-tls: + cpus: 0.5 + mem_limit: 64m + pids_limit: 96 + cap_drop: *id001 + security_opt: *id002 + read_only: true + tmpfs: *id003 + image: ${API_IMAGE:-mtusi-vasilev:lab7} + build: *id004 + stop_grace_period: 8s + network_mode: service:collector + command: + - python + - -m + - messenger.tls_gateway + - --config + - /run/tls/gateway.json + volumes: + - ./secrets/pki/collector:/run/tls/identity:ro + - ./secrets/ca.pem:/run/tls/ca.pem:ro + - ./secrets/revoked.json:/run/tls/revoked.json:ro + - ./secrets/collector_gateway.json:/run/tls/gateway.json:ro + healthcheck: + disable: true + prometheus-tls: + cpus: 0.5 + mem_limit: 64m + pids_limit: 96 + cap_drop: *id001 + security_opt: *id002 + read_only: true + tmpfs: *id003 + image: ${API_IMAGE:-mtusi-vasilev:lab7} + build: *id004 + stop_grace_period: 8s + network_mode: service:prometheus + command: + - python + - -m + - messenger.tls_gateway + - --config + - /run/tls/gateway.json + volumes: + - ./secrets/pki/prometheus:/run/tls/identity:ro + - ./secrets/ca.pem:/run/tls/ca.pem:ro + - ./secrets/revoked.json:/run/tls/revoked.json:ro + - ./secrets/prometheus_gateway.json:/run/tls/gateway.json:ro + healthcheck: + disable: true + loki-tls: + cpus: 0.5 + mem_limit: 64m + pids_limit: 96 + cap_drop: *id001 + security_opt: *id002 + read_only: true + tmpfs: *id003 + image: ${API_IMAGE:-mtusi-vasilev:lab7} + build: *id004 + stop_grace_period: 8s + network_mode: service:loki + command: + - python + - -m + - messenger.tls_gateway + - --config + - /run/tls/gateway.json + volumes: + - ./secrets/pki/loki:/run/tls/identity:ro + - ./secrets/ca.pem:/run/tls/ca.pem:ro + - ./secrets/revoked.json:/run/tls/revoked.json:ro + - ./secrets/loki_gateway.json:/run/tls/gateway.json:ro + healthcheck: + disable: true + tempo-tls: + cpus: 0.5 + mem_limit: 64m + pids_limit: 96 + cap_drop: *id001 + security_opt: *id002 + read_only: true + tmpfs: *id003 + image: ${API_IMAGE:-mtusi-vasilev:lab7} + build: *id004 + stop_grace_period: 8s + network_mode: service:tempo + command: + - python + - -m + - messenger.tls_gateway + - --config + - /run/tls/gateway.json + volumes: + - ./secrets/pki/tempo:/run/tls/identity:ro + - ./secrets/ca.pem:/run/tls/ca.pem:ro + - ./secrets/revoked.json:/run/tls/revoked.json:ro + - ./secrets/tempo_gateway.json:/run/tls/gateway.json:ro + healthcheck: + disable: true + state-init: + cpus: 0.5 + mem_limit: 64m + pids_limit: 96 + cap_drop: *id001 + security_opt: *id002 + read_only: true + tmpfs: *id003 + image: ${API_IMAGE:-mtusi-vasilev:lab7} + build: *id004 + stop_grace_period: 8s + user: 0:0 + command: + - python + - -c + - import os; pairs=[('/state/bao',100),('/state/broker',1000),('/state/storage',1000),('/state/prometheus',65534),('/state/loki',10001),('/state/tempo',10001),('/state/grafana',472)]; + [(os.chown(root,uid,uid),[os.chown(os.path.join(root,n),uid,uid) for n in dirs+files]) + for path,uid in pairs for root,dirs,files in os.walk(path)] + cap_add: + - CHOWN + - DAC_OVERRIDE + healthcheck: + disable: true + volumes: + - bao_data:/state/bao + - broker_data:/state/broker + - s3_data:/state/storage + - prometheus_data:/state/prometheus + - loki_data:/state/loki + - tempo_data:/state/tempo + - grafana_data:/state/grafana +volumes: + postgres_data: null + s3_data: null + broker_data: null + bao_data: null + prometheus_data: {} + loki_data: {} + tempo_data: {} + grafana_data: {} +secrets: + postgres_password: + file: ./secrets/postgres_password + cache_config: + file: ./secrets/cache_config + broker_config: + file: ./secrets/broker_config + s3_config: + file: ./secrets/s3_config + admin_database_url: + file: ./secrets/admin_database_url + admin_s3_access_key: + file: ./secrets/admin_s3_access_key + admin_s3_secret_key: + file: ./secrets/admin_s3_secret_key + grafana_password: + file: ./secrets/grafana_password diff --git a/infra/filer.toml b/infra/filer.toml new file mode 100644 index 0000000..a11e5de --- /dev/null +++ b/infra/filer.toml @@ -0,0 +1,3 @@ +[leveldb2] +enabled = true +dir = "/data/filerldb2" diff --git a/infra/grafana/dashboards/messenger.json b/infra/grafana/dashboards/messenger.json new file mode 100644 index 0000000..8df6fd1 --- /dev/null +++ b/infra/grafana/dashboards/messenger.json @@ -0,0 +1,450 @@ +{ + "uid": "messenger-overview", + "title": "Messenger: API and image pipeline", + "schemaVersion": 39, + "version": 1, + "refresh": "5s", + "time": { + "from": "now-15m", + "to": "now" + }, + "panels": [ + { + "id": 1, + "title": "Business RPS", + "type": "timeseries", + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "targets": [ + { + "refId": "A", + "expr": "sum(rate(messenger_http_requests_total[1m]))" + } + ], + "gridPos": { + "h": 8, + "w": 12, + "x": 0, + "y": 0 + }, + "fieldConfig": { + "defaults": { + "unit": "reqps" + }, + "overrides": [] + } + }, + { + "id": 2, + "title": "Business 5xx ratio", + "type": "timeseries", + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "targets": [ + { + "refId": "A", + "expr": "sum(rate(messenger_http_requests_total{status_class=\"5xx\"}[1m])) / clamp_min(sum(rate(messenger_http_requests_total[1m])),0.001)" + } + ], + "gridPos": { + "h": 8, + "w": 12, + "x": 12, + "y": 0 + }, + "fieldConfig": { + "defaults": { + "unit": "percentunit" + }, + "overrides": [] + } + }, + { + "id": 3, + "title": "HTTP latency quantiles", + "type": "timeseries", + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "targets": [ + { + "refId": "A", + "expr": "histogram_quantile(0.5, sum by (le) (rate(messenger_http_duration_seconds_bucket[1m])))", + "legendFormat": "p50" + }, + { + "refId": "B", + "expr": "histogram_quantile(0.95, sum by (le) (rate(messenger_http_duration_seconds_bucket[1m])))", + "legendFormat": "p95" + }, + { + "refId": "C", + "expr": "histogram_quantile(0.99, sum by (le) (rate(messenger_http_duration_seconds_bucket[1m])))", + "legendFormat": "p99" + } + ], + "gridPos": { + "h": 8, + "w": 12, + "x": 0, + "y": 8 + }, + "fieldConfig": { + "defaults": { + "unit": "s" + }, + "overrides": [] + } + }, + { + "id": 4, + "title": "Job outcomes", + "type": "timeseries", + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "targets": [ + { + "refId": "A", + "expr": "sum by (outcome) (rate(messenger_jobs_total[1m]))" + } + ], + "gridPos": { + "h": 8, + "w": 12, + "x": 12, + "y": 8 + }, + "fieldConfig": { + "defaults": { + "unit": "ops" + }, + "overrides": [] + } + }, + { + "id": 5, + "title": "Job p95 processing", + "type": "timeseries", + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "targets": [ + { + "refId": "A", + "expr": "histogram_quantile(0.95, sum by (le) (rate(messenger_job_duration_seconds_bucket[1m])))" + } + ], + "gridPos": { + "h": 8, + "w": 12, + "x": 0, + "y": 16 + }, + "fieldConfig": { + "defaults": { + "unit": "s" + }, + "overrides": [] + } + }, + { + "id": 6, + "title": "End-to-end p95 to ready", + "type": "timeseries", + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "targets": [ + { + "refId": "A", + "expr": "histogram_quantile(0.95, sum by (le) (rate(messenger_attachment_ready_duration_seconds_bucket[1m])))" + } + ], + "gridPos": { + "h": 8, + "w": 12, + "x": 12, + "y": 16 + }, + "fieldConfig": { + "defaults": { + "unit": "s" + }, + "overrides": [] + } + }, + { + "id": 7, + "title": "Outstanding jobs", + "type": "timeseries", + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "targets": [ + { + "refId": "A", + "expr": "max(messenger_queue_depth)" + } + ], + "gridPos": { + "h": 8, + "w": 12, + "x": 0, + "y": 24 + }, + "fieldConfig": { + "defaults": { + "unit": "short" + }, + "overrides": [] + } + }, + { + "id": 8, + "title": "Oldest outstanding age", + "type": "timeseries", + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "targets": [ + { + "refId": "A", + "expr": "max(messenger_queue_oldest_age_seconds)" + } + ], + "gridPos": { + "h": 8, + "w": 12, + "x": 12, + "y": 24 + }, + "fieldConfig": { + "defaults": { + "unit": "s" + }, + "overrides": [] + } + }, + { + "id": 9, + "title": "DB pool used", + "type": "timeseries", + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "targets": [ + { + "refId": "A", + "expr": "messenger_db_pool_used" + } + ], + "gridPos": { + "h": 8, + "w": 12, + "x": 0, + "y": 32 + }, + "fieldConfig": { + "defaults": { + "unit": "short" + }, + "overrides": [] + } + }, + { + "id": 10, + "title": "DB pool waiting", + "type": "timeseries", + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "targets": [ + { + "refId": "A", + "expr": "messenger_db_pool_waiting" + } + ], + "gridPos": { + "h": 8, + "w": 12, + "x": 12, + "y": 32 + }, + "fieldConfig": { + "defaults": { + "unit": "short" + }, + "overrides": [] + } + }, + { + "id": 11, + "title": "Worker busy/capacity", + "type": "timeseries", + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "targets": [ + { + "refId": "A", + "expr": "messenger_worker_busy / messenger_worker_capacity" + } + ], + "gridPos": { + "h": 8, + "w": 12, + "x": 0, + "y": 40 + }, + "fieldConfig": { + "defaults": { + "unit": "percentunit" + }, + "overrides": [] + } + }, + { + "id": 12, + "title": "Process resident memory", + "type": "timeseries", + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "targets": [ + { + "refId": "A", + "expr": "messenger_process_memory_bytes" + } + ], + "gridPos": { + "h": 8, + "w": 12, + "x": 12, + "y": 40 + }, + "fieldConfig": { + "defaults": { + "unit": "bytes" + }, + "overrides": [] + } + }, + { + "id": 13, + "title": "Process CPU (100%=1 core)", + "type": "timeseries", + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "targets": [ + { + "refId": "A", + "expr": "messenger_process_cpu_percent" + } + ], + "gridPos": { + "h": 8, + "w": 12, + "x": 0, + "y": 48 + }, + "fieldConfig": { + "defaults": { + "unit": "percent" + }, + "overrides": [] + } + }, + { + "id": 14, + "title": "Sampling decisions", + "type": "timeseries", + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "targets": [ + { + "refId": "A", + "expr": "sum by (decision) (rate(messenger_http_trace_decisions_total[1m]))" + } + ], + "gridPos": { + "h": 8, + "w": 12, + "x": 12, + "y": 48 + }, + "fieldConfig": { + "defaults": { + "unit": "ops" + }, + "overrides": [] + } + }, + { + "id": 15, + "title": "Collector failed span sends", + "type": "timeseries", + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "targets": [ + { + "refId": "A", + "expr": "rate(otelcol_exporter_send_failed_spans_total[1m])" + } + ], + "gridPos": { + "h": 8, + "w": 12, + "x": 0, + "y": 56 + }, + "fieldConfig": { + "defaults": { + "unit": "ops" + }, + "overrides": [] + } + }, + { + "id": 99, + "title": "Structured application logs (trace_id and request_id)", + "type": "logs", + "datasource": { + "type": "loki", + "uid": "loki" + }, + "targets": [ + { + "refId": "A", + "expr": "{service_name=~\"messenger-api|messenger-worker\"}" + } + ], + "gridPos": { + "h": 9, + "w": 24, + "x": 0, + "y": 64 + } + } + ] +} \ No newline at end of file diff --git a/infra/grafana/provisioning/dashboards/dashboards.yaml b/infra/grafana/provisioning/dashboards/dashboards.yaml new file mode 100644 index 0000000..a1c102a --- /dev/null +++ b/infra/grafana/provisioning/dashboards/dashboards.yaml @@ -0,0 +1,7 @@ +apiVersion: 1 +providers: + - name: messenger + folder: Messenger + type: file + options: + path: /var/lib/grafana/dashboards diff --git a/infra/grafana/provisioning/datasources/datasources.yaml b/infra/grafana/provisioning/datasources/datasources.yaml new file mode 100644 index 0000000..7747829 --- /dev/null +++ b/infra/grafana/provisioning/datasources/datasources.yaml @@ -0,0 +1,27 @@ +apiVersion: 1 +datasources: + - name: Prometheus + uid: prometheus + type: prometheus + access: proxy + url: http://prometheus:9090 + isDefault: true + editable: false + - name: Loki + uid: loki + type: loki + access: proxy + url: http://loki:3100 + editable: false + jsonData: + derivedFields: + - datasourceUid: tempo + matcherRegex: '"trace_id": "([a-f0-9]{32})"' + name: TraceID + url: '$${__value.raw}' + - name: Tempo + uid: tempo + type: tempo + access: proxy + url: http://tempo:3200 + editable: false diff --git a/infra/haproxy.cfg b/infra/haproxy.cfg new file mode 100644 index 0000000..a86b845 --- /dev/null +++ b/infra/haproxy.cfg @@ -0,0 +1,38 @@ +global + log stdout format raw local0 + maxconn 256 + stats socket /tmp/haproxy.sock mode 600 level user + ssl-default-bind-options ssl-min-ver TLSv1.2 no-tls-tickets + ssl-default-server-options ssl-min-ver TLSv1.2 no-tls-tickets + +defaults + mode http + log global + timeout connect 1s + timeout client 20s + timeout server 15s + timeout check 2s + timeout queue 2s + retries 0 + +resolvers docker + nameserver dns 127.0.0.11:53 + resolve_retries 3 + timeout resolve 1s + timeout retry 1s + hold valid 1s + hold obsolete 1s + hold nx 1s + +frontend public + bind :8443 ssl crt /run/tls/identity/combined.pem + http-request set-var(txn.lb_request_id) uuid() + http-request return status 503 content-type application/json lf-string '{"error":{"code":"unavailable","message":"No ready API","request_id":"%[var(txn.lb_request_id)]"}}' hdr X-Request-Id '%[var(txn.lb_request_id)]' if { nbsrv(apis) eq 0 } + default_backend apis + +backend apis + balance roundrobin + option httpchk GET /health/ready + http-check expect status 200 + default-server inter 1s fastinter 500ms downinter 1s fall 2 rise 2 + server-template api 1-8 api:9443 ssl verify required ca-file /run/tls/ca.pem crt /run/tls/identity/combined.pem verifyhost api sni str(api) check check-sni api resolvers docker resolve-prefer ipv4 init-addr libc,none diff --git a/infra/observability/alerts.yaml b/infra/observability/alerts.yaml new file mode 100644 index 0000000..bf7776f --- /dev/null +++ b/infra/observability/alerts.yaml @@ -0,0 +1,24 @@ +groups: + - name: messenger-slo + rules: + - alert: MessengerHighErrorRate + expr: sum(rate(messenger_http_requests_total{status_class="5xx"}[1m])) / clamp_min(sum(rate(messenger_http_requests_total[1m])), 0.001) > 0.05 + for: 10s + labels: {severity: warning} + annotations: + summary: Business HTTP 5xx ratio above 5% over 1 minute + runbook_url: file:RUNBOOK.md#api-errors + - alert: MessengerQueueLag + expr: max(messenger_queue_oldest_age_seconds) > 15 and max(messenger_queue_depth) > 0 + for: 10s + labels: {severity: warning} + annotations: + summary: Outstanding attachment job age above 15 seconds + runbook_url: file:RUNBOOK.md#queue-lag + - alert: MessengerTelemetryUnavailable + expr: up{job="messenger"} == 0 + for: 10s + labels: {severity: warning} + annotations: + summary: Collector metrics unavailable + runbook_url: file:RUNBOOK.md#telemetry-unavailable diff --git a/infra/observability/collector.yaml b/infra/observability/collector.yaml new file mode 100644 index 0000000..016c883 --- /dev/null +++ b/infra/observability/collector.yaml @@ -0,0 +1,87 @@ +extensions: + health_check: + endpoint: 127.0.0.1:13133 +receivers: + otlp: + protocols: + http: + endpoint: 127.0.0.1:14318 +processors: + memory_limiter: + check_interval: 1s + limit_mib: 160 + spike_limit_mib: 32 + batch: + timeout: 1s + send_batch_size: 128 + send_batch_max_size: 256 +exporters: + prometheus: + endpoint: 127.0.0.1:19464 + metric_expiration: 15m + resource_to_telemetry_conversion: + enabled: true + otlphttp/tempo: + endpoint: https://tempo:44318 + tls: + ca_file: /run/tls/ca.pem + cert_file: /run/tls/identity/cert.pem + key_file: /run/tls/identity/key.pem + timeout: 2s + sending_queue: + queue_size: 128 + num_consumers: 1 + retry_on_failure: + initial_interval: 1s + max_interval: 2s + max_elapsed_time: 5s + otlphttp/loki: + endpoint: https://loki:9443/otlp + timeout: 2s + sending_queue: + queue_size: 128 + num_consumers: 1 + retry_on_failure: + initial_interval: 1s + max_interval: 2s + max_elapsed_time: 5s + tls: + ca_file: /run/tls/ca.pem + cert_file: /run/tls/identity/cert.pem + key_file: /run/tls/identity/key.pem +service: + extensions: + - health_check + telemetry: + metrics: + readers: + - pull: + exporter: + prometheus: + host: 127.0.0.1 + port: 18888 + pipelines: + traces: + receivers: + - otlp + processors: + - memory_limiter + - batch + exporters: + - otlphttp/tempo + metrics: + receivers: + - otlp + processors: + - memory_limiter + - batch + exporters: + - prometheus + logs: + receivers: + - otlp + processors: + - memory_limiter + - batch + exporters: + - otlphttp/loki diff --git a/infra/observability/loki.yaml b/infra/observability/loki.yaml new file mode 100644 index 0000000..fac5199 --- /dev/null +++ b/infra/observability/loki.yaml @@ -0,0 +1,34 @@ +auth_enabled: false +server: + http_listen_port: 3100 + http_listen_address: 127.0.0.1 + grpc_listen_address: 127.0.0.1 +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: 24h +compactor: + working_directory: /loki/compactor + retention_enabled: true + delete_request_store: filesystem +analytics: + reporting_enabled: false diff --git a/infra/observability/prometheus.yaml b/infra/observability/prometheus.yaml new file mode 100644 index 0000000..227870e --- /dev/null +++ b/infra/observability/prometheus.yaml @@ -0,0 +1,26 @@ +global: + scrape_interval: 5s + evaluation_interval: 5s +rule_files: +- /etc/prometheus/alerts.yaml +scrape_configs: +- job_name: messenger + static_configs: + - targets: + - collector:9464 + scheme: https + tls_config: + ca_file: /run/tls/ca.pem + cert_file: /run/tls/identity/cert.pem + key_file: /run/tls/identity/key.pem + server_name: collector +- job_name: collector + static_configs: + - targets: + - collector:8888 + scheme: https + tls_config: + ca_file: /run/tls/ca.pem + cert_file: /run/tls/identity/cert.pem + key_file: /run/tls/identity/key.pem + server_name: collector diff --git a/infra/observability/tempo.yaml b/infra/observability/tempo.yaml new file mode 100644 index 0000000..408a5f9 --- /dev/null +++ b/infra/observability/tempo.yaml @@ -0,0 +1,24 @@ +server: + http_listen_port: 3200 + http_listen_address: 127.0.0.1 + grpc_listen_address: 127.0.0.1 +distributor: + receivers: + otlp: + protocols: + http: + endpoint: 127.0.0.1:4318 +ingester: + max_block_duration: 1m +compactor: + compaction: + block_retention: 24h +storage: + trace: + backend: local + wal: + path: /var/tempo/wal + local: + path: /var/tempo/blocks +usage_report: + reporting_enabled: false diff --git a/infra/openbao.hcl b/infra/openbao.hcl new file mode 100644 index 0000000..59d3d56 --- /dev/null +++ b/infra/openbao.hcl @@ -0,0 +1,12 @@ +ui = true +disable_mlock = true +storage "file" { path = "/bao/data" } +listener "tcp" { + address = "0.0.0.0:8200" + tls_cert_file = "/run/tls/identity/cert.pem" + tls_key_file = "/run/tls/identity/key.pem" + tls_client_ca_file = "/run/tls/ca.pem" + tls_require_and_verify_client_cert = true + tls_min_version = "tls12" +} +api_addr = "https://openbao:8200" diff --git a/infra/pg-entrypoint.sh b/infra/pg-entrypoint.sh new file mode 100755 index 0000000..52748dd --- /dev/null +++ b/infra/pg-entrypoint.sh @@ -0,0 +1,6 @@ +#!/bin/sh +set -eu +cp /run/tls/identity/key.pem /tmp/postgres-key.pem +chown postgres:postgres /tmp/postgres-key.pem +chmod 600 /tmp/postgres-key.pem +exec docker-entrypoint.sh "$@" diff --git a/infra/pg_hba.conf b/infra/pg_hba.conf new file mode 100644 index 0000000..845cab3 --- /dev/null +++ b/infra/pg_hba.conf @@ -0,0 +1,3 @@ +local all all trust +hostnossl all all 0.0.0.0/0 reject +hostssl messenger api,worker,dispatcher,messenger 0.0.0.0/0 scram-sha-256 diff --git a/migrations/001_initial.sql b/migrations/001_initial.sql new file mode 100644 index 0000000..2d05d33 --- /dev/null +++ b/migrations/001_initial.sql @@ -0,0 +1,35 @@ +CREATE TABLE users ( + id uuid PRIMARY KEY, + username text NOT NULL UNIQUE CHECK (username ~ '^[a-z0-9_]{3,32}$'), + display_name text NOT NULL CHECK (char_length(display_name) BETWEEN 1 AND 100), + password_hash text NOT NULL, + created_at timestamptz NOT NULL +); +CREATE TABLE chats ( + id uuid PRIMARY KEY, + title text NOT NULL CHECK (char_length(title) BETWEEN 1 AND 100), + created_at timestamptz NOT NULL +); +CREATE TABLE members ( + chat_id uuid NOT NULL REFERENCES chats(id), + user_id uuid NOT NULL REFERENCES users(id), + position integer NOT NULL CHECK (position >= 0), + PRIMARY KEY(chat_id,user_id), + UNIQUE(chat_id,position) +); +CREATE INDEX members_user_idx ON members(user_id,chat_id); +CREATE TABLE messages ( + id uuid PRIMARY KEY, + chat_id uuid NOT NULL, + sender_id uuid NOT NULL, + text text NOT NULL CHECK (char_length(text) BETWEEN 1 AND 4000), + created_at timestamptz NOT NULL, + FOREIGN KEY(chat_id,sender_id) REFERENCES members(chat_id,user_id) +); +CREATE INDEX messages_history_idx ON messages(chat_id,created_at,id); +CREATE TABLE sessions ( + token_digest text PRIMARY KEY, + user_id uuid NOT NULL REFERENCES users(id), + expires_at timestamptz NOT NULL +); +CREATE INDEX sessions_expiry_idx ON sessions(expires_at); diff --git a/migrations/002_idempotency.sql b/migrations/002_idempotency.sql new file mode 100644 index 0000000..3ca4308 --- /dev/null +++ b/migrations/002_idempotency.sql @@ -0,0 +1,10 @@ +CREATE TABLE message_requests ( + actor_id uuid NOT NULL REFERENCES users(id), + chat_id uuid NOT NULL REFERENCES chats(id), + key text NOT NULL, + body_digest text NOT NULL, + response jsonb NOT NULL, + expires_at timestamptz NOT NULL, + PRIMARY KEY(actor_id,chat_id,key) +); +CREATE INDEX message_requests_expiry_idx ON message_requests(expires_at); diff --git a/migrations/003_unicode_storage.sql b/migrations/003_unicode_storage.sql new file mode 100644 index 0000000..c79d6b9 --- /dev/null +++ b/migrations/003_unicode_storage.sql @@ -0,0 +1,13 @@ +-- PostgreSQL text rejects U+0000, while the API accepts Unicode code points. +-- Preserve UTF-8 losslessly. API validation enforces code point limits; the DB +-- additionally bounds byte lengths, without stripping or replacing characters. +ALTER TABLE users DROP CONSTRAINT users_display_name_check; +ALTER TABLE users ALTER COLUMN display_name TYPE bytea USING convert_to(display_name,'UTF8'); +ALTER TABLE users ADD CHECK (octet_length(display_name) BETWEEN 1 AND 400); +ALTER TABLE chats DROP CONSTRAINT chats_title_check; +ALTER TABLE chats ALTER COLUMN title TYPE bytea USING convert_to(title,'UTF8'); +ALTER TABLE chats ADD CHECK (octet_length(title) BETWEEN 1 AND 400); +ALTER TABLE messages DROP CONSTRAINT messages_text_check; +ALTER TABLE messages ALTER COLUMN text TYPE bytea USING convert_to(text,'UTF8'); +ALTER TABLE messages ADD CHECK (octet_length(text) BETWEEN 1 AND 16000); +ALTER TABLE message_requests ALTER COLUMN response TYPE bytea USING convert_to(response::text,'UTF8'); diff --git a/migrations/004_attachments.sql b/migrations/004_attachments.sql new file mode 100644 index 0000000..63273db --- /dev/null +++ b/migrations/004_attachments.sql @@ -0,0 +1,35 @@ +CREATE TABLE attachments ( + id uuid PRIMARY KEY, + chat_id uuid NOT NULL REFERENCES chats(id), + owner_id uuid NOT NULL REFERENCES users(id), + filename text NOT NULL, + content_type text NOT NULL CHECK (content_type IN ('image/png','image/jpeg')), + size_bytes bigint NOT NULL CHECK (size_bytes BETWEEN 1 AND 10485760), + sha256 text NOT NULL, + status text NOT NULL CONSTRAINT attachments_status_check CHECK (status IN ('queued','processing','ready','failed')), + error_code text, + created_at timestamptz NOT NULL, + updated_at timestamptz NOT NULL, + object_key text NOT NULL UNIQUE, + UNIQUE(id,chat_id) +); +CREATE TABLE message_attachments ( + message_id uuid NOT NULL REFERENCES messages(id), + attachment_id uuid NOT NULL REFERENCES attachments(id), + position integer NOT NULL CHECK (position BETWEEN 0 AND 9), + PRIMARY KEY(message_id,attachment_id), + UNIQUE(message_id,position) +); +CREATE INDEX message_attachments_attachment_idx ON message_attachments(attachment_id); +CREATE TABLE upload_intents ( + id uuid PRIMARY KEY, + object_key text NOT NULL UNIQUE, + created_at timestamptz NOT NULL +); +CREATE INDEX upload_intents_created_idx ON upload_intents(created_at,id); +CREATE TABLE attachment_reconcile_audit ( + id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY, + event text NOT NULL, + object_key text NOT NULL, + happened_at timestamptz NOT NULL DEFAULT now() +); diff --git a/migrations/005_attachment_only_message.sql b/migrations/005_attachment_only_message.sql new file mode 100644 index 0000000..054d8ce --- /dev/null +++ b/migrations/005_attachment_only_message.sql @@ -0,0 +1,3 @@ +-- Empty text is valid only when the API supplies at least one attachment. +ALTER TABLE messages DROP CONSTRAINT messages_text_check; +ALTER TABLE messages ADD CONSTRAINT messages_text_check CHECK (octet_length(text) <= 16000); diff --git a/migrations/006_jobs.sql b/migrations/006_jobs.sql new file mode 100644 index 0000000..a713762 --- /dev/null +++ b/migrations/006_jobs.sql @@ -0,0 +1,49 @@ +ALTER TABLE attachments DROP CONSTRAINT IF EXISTS attachments_status_check; +ALTER TABLE attachments ADD CONSTRAINT attachments_status_check + CHECK (status IN ('queued','processing','ready','failed')); +ALTER TABLE attachments ADD COLUMN pipeline_version integer NOT NULL DEFAULT 1 CHECK (pipeline_version > 0); +ALTER TABLE attachments ADD COLUMN variants jsonb NOT NULL DEFAULT '[]'; +ALTER TABLE attachments ADD COLUMN stage_key text; + +CREATE TABLE attachment_jobs ( + id uuid PRIMARY KEY, + attachment_id uuid NOT NULL REFERENCES attachments(id), + pipeline_version integer NOT NULL CHECK (pipeline_version > 0), + source_key text, + state text NOT NULL CHECK (state IN ('queued','processing','ready','failed','superseded')), + attempt integer NOT NULL DEFAULT 0 CHECK (attempt >= 0), + attempt_limit integer NOT NULL CHECK (attempt_limit > 0), + lease_id uuid, + lease_until timestamptz, + available_at timestamptz NOT NULL DEFAULT now(), + error_code text, + created_at timestamptz NOT NULL DEFAULT now(), + updated_at timestamptz NOT NULL DEFAULT now(), + UNIQUE(attachment_id,pipeline_version) +); +CREATE INDEX jobs_recovery_idx ON attachment_jobs(state,lease_until); +CREATE TABLE job_outbox ( + job_id uuid PRIMARY KEY REFERENCES attachment_jobs(id), + published_at timestamptz +); +CREATE TABLE job_audit ( + id bigserial PRIMARY KEY, + job_id uuid NOT NULL REFERENCES attachment_jobs(id), + event text NOT NULL, + attempt integer NOT NULL, + created_at timestamptz NOT NULL DEFAULT now() +); +CREATE TABLE failed_jobs ( + job_id uuid PRIMARY KEY REFERENCES attachment_jobs(id), + error_code text NOT NULL, + failed_at timestamptz NOT NULL DEFAULT now(), + replay_count integer NOT NULL DEFAULT 0 +); +CREATE TABLE test_faults ( + id bigserial PRIMARY KEY, + point text NOT NULL, + attachment_id uuid, + action text NOT NULL CHECK (action IN ('crash','pause','error')), + reached_at timestamptz, + released boolean NOT NULL DEFAULT false +); diff --git a/migrations/007_observability.sql b/migrations/007_observability.sql new file mode 100644 index 0000000..299ca4f --- /dev/null +++ b/migrations/007_observability.sql @@ -0,0 +1,2 @@ +ALTER TABLE attachment_jobs ADD COLUMN traceparent text; +ALTER TABLE attachment_jobs ADD COLUMN tracestate text; diff --git a/migrations/008_security.sql b/migrations/008_security.sql new file mode 100644 index 0000000..8f72e0c --- /dev/null +++ b/migrations/008_security.sql @@ -0,0 +1,16 @@ +CREATE TABLE login_windows ( + bucket text PRIMARY KEY, + window_start timestamptz NOT NULL, + count integer NOT NULL CHECK (count > 0) +); +REVOKE CREATE ON SCHEMA public FROM PUBLIC; +GRANT USAGE ON SCHEMA public TO api,worker,dispatcher; +GRANT SELECT,INSERT,UPDATE,DELETE ON users,chats,members,messages,sessions,message_requests,attachments,message_attachments,upload_intents,attachment_reconcile_audit,attachment_jobs,job_outbox,job_audit,failed_jobs,login_windows TO api; +GRANT SELECT ON attachments,attachment_jobs,job_outbox,failed_jobs TO worker,dispatcher; +GRANT UPDATE(status,error_code,object_key,variants,updated_at,stage_key) ON attachments TO worker,dispatcher; +GRANT UPDATE(state,attempt,lease_id,lease_until,available_at,error_code,updated_at) ON attachment_jobs TO worker,dispatcher; +GRANT UPDATE(published_at) ON job_outbox TO worker,dispatcher; +GRANT INSERT ON job_audit TO worker,dispatcher; +GRANT INSERT,UPDATE ON failed_jobs TO worker,dispatcher; +GRANT USAGE,SELECT ON SEQUENCE job_audit_id_seq TO api,worker,dispatcher; +GRANT USAGE,SELECT ON SEQUENCE attachment_reconcile_audit_id_seq TO api; diff --git a/migrations/009_telemetry_acceptance.sql b/migrations/009_telemetry_acceptance.sql new file mode 100644 index 0000000..db0432d --- /dev/null +++ b/migrations/009_telemetry_acceptance.sql @@ -0,0 +1,4 @@ +ALTER TABLE attachment_jobs ADD COLUMN accepted_at timestamptz; +UPDATE attachment_jobs SET accepted_at=created_at; +ALTER TABLE attachment_jobs ALTER COLUMN accepted_at SET NOT NULL; +ALTER TABLE attachment_jobs ALTER COLUMN accepted_at SET DEFAULT clock_timestamp(); diff --git a/migrations/010_login_window_cleanup.sql b/migrations/010_login_window_cleanup.sql new file mode 100644 index 0000000..6f1bdfd --- /dev/null +++ b/migrations/010_login_window_cleanup.sql @@ -0,0 +1 @@ +CREATE INDEX login_windows_expiry_idx ON login_windows(window_start); diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..7001689 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,32 @@ +[project] +name = "mtusi-messenger" +version = "1.0.0" +requires-python = ">=3.12,<3.13" +dependencies = [ + "fastapi", + "uvicorn", + "psycopg[binary,pool]", + "redis", + "argon2-cffi", + "boto3>=1.43,<2", + "pillow>=13.0.0,<14", + "opentelemetry-sdk==1.45.2", + "opentelemetry-exporter-otlp-proto-http==1.45.2", + "psutil>=7,<8", +] + +[dependency-groups] +dev = ["pytest", "httpx", "ruff", "openapi-spec-validator", "jsonschema"] + +[tool.ruff] +target-version = "py312" +line-length = 100 +include = ["src/**/*.py", "student-tests/**/*.py", "research/**/*.py"] + +[tool.pytest.ini_options] +testpaths = ["student-tests"] +pythonpath = ["src", "tests"] + +[tool.ruff.lint] +select = ["E4", "E7", "E9", "F", "I", "UP", "B"] +ignore = ["B008"] # FastAPI dependencies are declared in endpoint signatures. diff --git a/research/auth_budget.py b/research/auth_budget.py new file mode 100644 index 0000000..4599799 --- /dev/null +++ b/research/auth_budget.py @@ -0,0 +1,115 @@ +#!/usr/bin/env python3 +"""Shared-replica login window and real weak-hash rehash regression.""" + +import base64 +import json +import subprocess +import sys +import time +from pathlib import Path + +from argon2 import PasswordHasher + +ROOT = Path(__file__).resolve().parents[1] +sys.path.insert(0, str(ROOT / "tests")) +from client import Client, check # noqa: E402 + + +def sql(query): + result = subprocess.run( + [ + "docker", + "compose", + "exec", + "-T", + "postgres", + "psql", + "-U", + "messenger", + "-d", + "messenger", + "-At", + "-v", + "ON_ERROR_STOP=1", + ], + cwd=ROOT, + input=query, + text=True, + capture_output=True, + check=True, + ) + return result.stdout.strip() + + +def main(): + c = Client("https://localhost:8447", str(ROOT / "secrets/ca.pem")) + actor = c.user("rehash") + password = actor["registration"]["password"] + weak = PasswordHasher(time_cost=1, memory_cost=8192, parallelism=1).hash(password) + sql("UPDATE users SET password_hash='" + weak + "' WHERE id='" + actor["id"] + "';") + authorization = ( + "Basic " + + base64.b64encode((actor["registration"]["username"] + ":" + password).encode()).decode() + ) + c.call( + "POST", + "/api/v1/auth/sessions", + 201, + headers={"Authorization": authorization}, + schema="Session", + ) + upgraded = sql("SELECT password_hash FROM users WHERE id='" + actor["id"] + "';") + check( + upgraded != weak and "$m=65536,t=2,p=1$" in upgraded, + "successful login did not upgrade hash", + ) + time.sleep(10.2) + wrong = ( + "Basic " + + base64.b64encode((actor["registration"]["username"] + ":incorrect").encode()).decode() + ) + rows = [] + for _ in range(12): + response = c.call( + "POST", "/api/v1/auth/sessions", expected=[401, 429], headers={"Authorization": wrong} + ) + rows.append( + { + "status": response["status"], + "instance": response["headers"]["X-Instance-Id"], + "retry_after": response["headers"].get("Retry-After"), + "milliseconds": round(response["elapsed"] * 1000, 3), + } + ) + sql( + "UPDATE sessions SET expires_at=now()-interval '1 second' WHERE user_id='" + + actor["id"] + + "';" + ) + expiry_rows = [] + for _ in range(4): + expired = c.call("GET", "/api/v1/users/me", expected=401, actor=actor) + expiry_rows.append( + {"status": expired["status"], "instance": expired["headers"]["X-Instance-Id"]} + ) + result = { + "weak_hash_upgraded": True, + "expired_session_requests": expiry_rows, + "expired_session_denied_both_replicas": len({r["instance"] for r in expiry_rows}) >= 2, + "configured_memory_kib": 65536, + "time_cost": 2, + "parallelism": 1, + "requests": rows, + "distinct_api_instances": len({r["instance"] for r in rows}), + "passed": len({r["instance"] for r in expiry_rows}) >= 2 + and sum(r["status"] == 401 for r in rows) == 10 + and all(r["status"] == 429 and r["retry_after"] == "10" for r in rows[10:]) + and len({r["instance"] for r in rows}) >= 2, + } + (ROOT / "evidence/auth-budget.json").write_text(json.dumps(result, indent=2) + "\n") + check(result["passed"], "shared login window failed") + print(json.dumps({k: v for k, v in result.items() if k != "requests"})) + + +if __name__ == "__main__": + main() diff --git a/research/compromise.py b/research/compromise.py new file mode 100644 index 0000000..3ca7814 --- /dev/null +++ b/research/compromise.py @@ -0,0 +1,108 @@ +#!/usr/bin/env python3 +"""Accepted jobs survive worker identity revoke + working-secret rotation.""" + +import hashlib +import json +import subprocess +import sys +import time +from pathlib import Path + +ROOT = Path(__file__).resolve().parents[1] +sys.path.insert(0, str(ROOT / "tests")) +from client import Client, check # noqa: E402 + + +def docker(*args): + return subprocess.check_output(["docker", "compose", *args], cwd=ROOT, text=True).strip() + + +def images(): + ids = docker("ps", "-q", "api", "worker").split() + return sorted( + set( + subprocess.check_output( + ["docker", "inspect", "--format", "{{.Image}}", *ids], text=True + ).split() + ) + ) + + +def main(): + c = Client("https://localhost:8447", str(ROOT / "secrets/ca.pem")) + alice, bob, _, chat = c.bootstrap() + before = images() + docker("stop", "worker") + accepted = [c.attachment(alice, chat) for _ in range(3)] + start = time.monotonic() + rotate = subprocess.run( + [sys.executable, "scripts/rotate_identity.py"], cwd=ROOT, text=True, capture_output=True + ) + check(rotate.returncode == 0, "operator rotation failed; inspect private operator execution") + errors = 0 + deadline = time.monotonic() + 90 + pending = {a[0]["id"] for a in accepted} + while pending and time.monotonic() < deadline: + for att, _ in accepted: + if att["id"] not in pending: + continue + result = c.call( + "GET", + "/api/v1/attachments/" + att["id"], + expected=[200, 503], + actor=alice, + schema=None, + ) + if result["status"] == 503: + errors += 1 + else: + body = json.loads(result["bytes"]) + check(body["status"] != "failed", "accepted task became failed") + if body["status"] == "ready": + pending.remove(att["id"]) + time.sleep(0.2) + check(not pending, "accepted jobs did not recover") + rows = [] + for att, original in accepted: + downloaded = c.call("GET", "/api/v1/attachments/" + att["id"] + "/content", actor=bob)[ + "bytes" + ] + thumbnail = c.call( + "GET", "/api/v1/attachments/" + att["id"] + "/content?variant=thumbnail", actor=bob + )["bytes"] + sha = hashlib.sha256(original).hexdigest() + rows.append( + { + "attachment_id": att["id"], + "original_sha256": sha, + "download_sha256": hashlib.sha256(downloaded).hexdigest(), + "thumbnail_sha256": hashlib.sha256(thumbnail).hexdigest(), + "thumbnail_nonempty": bool(thumbnail), + "accepted_original_sha_matches": sha == att["sha256"], + } + ) + after = images() + result = { + "accepted_jobs": 3, + "ready_jobs": len(rows), + "recovery_seconds": round(time.monotonic() - start, 3), + "observed_api_503": errors, + "images_before": before, + "images_after": after, + "image_unchanged": before == after, + "rows": rows, + "passed": before == after + and all( + r["original_sha256"] == r["download_sha256"] + and r["thumbnail_nonempty"] + and r["accepted_original_sha_matches"] + for r in rows + ), + } + (ROOT / "evidence/compromise-recovery.json").write_text(json.dumps(result, indent=2) + "\n") + check(result["passed"], "recovery invariant failed") + print(json.dumps({k: v for k, v in result.items() if k != "rows"})) + + +if __name__ == "__main__": + main() diff --git a/research/sealed.py b/research/sealed.py new file mode 100644 index 0000000..c6c4da2 --- /dev/null +++ b/research/sealed.py @@ -0,0 +1,71 @@ +#!/usr/bin/env python3 +"""Fail closed after the service-auth lease expires, then bounded recovery.""" + +import json +import subprocess +import sys +import time +from pathlib import Path + +ROOT = Path(__file__).resolve().parents[1] +sys.path.insert(0, str(ROOT / "tests")) +from client import Client, check # noqa: E402 + + +def operator(action): + subprocess.run( + [sys.executable, "scripts/bao_operator.py", action], + cwd=ROOT, + check=True, + capture_output=True, + ) + + +def main(): + c = Client("https://localhost:8447", str(ROOT / "secrets/ca.pem")) + actor = c.user("sealed") + c.call("GET", "/api/v1/users/me", actor=actor, schema="User") + start = time.monotonic() + operator("seal") + rows = [] + try: + while time.monotonic() - start < 33: + live = c.call("GET", "/health/live", schema="Health") + response = c.call( + "GET", "/api/v1/users/me", expected=[200, 503], actor=actor + ) + rows.append( + { + "seconds": round(time.monotonic() - start, 3), + "live": live["status"], + "business": response["status"], + } + ) + time.sleep(1) + check(rows[-1]["business"] == 503, "service used credentials beyond lease") + finally: + unseal_start = time.monotonic() + operator("unseal") + for _ in range(20): + response = c.call("GET", "/health/ready", expected=[200, 503]) + if response["status"] == 200: + break + time.sleep(0.25) + c.call("GET", "/api/v1/users/me", actor=actor, schema="User") + result = { + "lease_seconds": 30, + "local_cache_max_seconds": 29, + "rows": rows, + "first_business_503_seconds": next( + (r["seconds"] for r in rows if r["business"] == 503), None + ), + "recovery_seconds": round(time.monotonic() - unseal_start, 3), + "passed": rows[-1]["business"] == 503 and response["status"] == 200, + } + (ROOT / "evidence/sealed-expiry.json").write_text(json.dumps(result, indent=2) + "\n") + check(result["passed"], "recovery failed") + print(json.dumps({k: v for k, v in result.items() if k != "rows"})) + + +if __name__ == "__main__": + main() diff --git a/scripts/bao_operator.py b/scripts/bao_operator.py new file mode 100644 index 0000000..68d591e --- /dev/null +++ b/scripts/bao_operator.py @@ -0,0 +1,115 @@ +#!/usr/bin/env python3 +"""Explicit operator init/unseal/configuration. Never prints credential values.""" + +import argparse +import json +import os +import ssl +import time +import urllib.error +import urllib.request +from pathlib import Path + +ROOT = Path(__file__).resolve().parents[1] +PRIVATE = ROOT / "secrets" +OPERATOR = ROOT / "operator-private" + + +def call(path, data=None, *, method=None, token=True): + ctx = ssl.create_default_context(cafile=str(PRIVATE / "ca.pem")) + ctx.load_cert_chain(PRIVATE / "pki/operator/cert.pem", PRIVATE / "pki/operator/key.pem") + headers = {"Content-Type": "application/json"} + if token: + headers["X-Vault-Token"] = (OPERATOR / "root-token").read_text().strip() + req = urllib.request.Request( + os.getenv("BAO_OPERATOR_ADDR", "https://localhost:18207") + "/v1/" + path, + data=json.dumps(data).encode() if data is not None else None, + headers=headers, + method=method, + ) + with urllib.request.urlopen(req, context=ctx, timeout=5) as response: + raw = response.read() + return json.loads(raw) if raw else {} + + +def unseal(): + for share in json.loads((OPERATOR / "unseal-shares.json").read_text())[:2]: + result = call("sys/unseal", {"key": share}, token=False) + if result["sealed"]: + raise RuntimeError("OpenBao remained sealed") + + +def configure(): + try: + call("sys/mounts/secret", {"type": "kv", "options": {"version": "2"}}) + except urllib.error.HTTPError as exc: + if exc.code != 400: + raise + try: + call("sys/auth/cert", {"type": "cert"}) + except urllib.error.HTTPError as exc: + if exc.code != 400: + raise + seed = json.loads((PRIVATE / "bao_seed.json").read_text()) + for role, values in seed.items(): + policy = ( + 'path "secret/data/services/' + + role + + '" { capabilities = ["read"] }\npath "auth/token/lookup-self" { capabilities = ["read"] }\npath "auth/token/renew-self" { capabilities = ["update"] }\n' + ) + call("sys/policies/acl/" + role, {"policy": policy}, method="PUT") + call( + "auth/cert/certs/" + role, + { + "display_name": role, + "certificate": (PRIVATE / "pki" / role / "cert.pem").read_text(), + "allowed_common_names": role, + "token_policies": [role], + "token_no_default_policy": True, + "token_ttl": "30s", + "token_max_ttl": "60s", + }, + ) + call("secret/data/services/" + role, {"data": values}) + try: + call("sys/audit/file", {"type": "file", "options": {"file_path": "/bao/data/audit.jsonl"}}) + except urllib.error.HTTPError as exc: + if exc.code != 400: + raise + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument("action", choices=["init", "unseal", "configure", "seal"]) + args = parser.parse_args() + os.umask(0o077) + if args.action == "init": + for _attempt in range(30): + try: + status = call("sys/init", token=False) + break + except (OSError, urllib.error.URLError): + time.sleep(1) + else: + raise RuntimeError("OpenBao TLS endpoint unavailable") + if not status["initialized"]: + result = call( + "sys/init", {"secret_shares": 3, "secret_threshold": 2}, method="PUT", token=False + ) + (OPERATOR / "root-token").write_text(result["root_token"]) + (OPERATOR / "unseal-shares.json").write_text(json.dumps(result["keys_base64"])) + (OPERATOR / "root-token").chmod(0o600) + (OPERATOR / "unseal-shares.json").chmod(0o600) + unseal() + configure() + elif args.action == "unseal": + unseal() + elif args.action == "configure": + configure() + else: + call("sys/seal", {}, method="PUT") + print("OpenBao operator action complete; credential values were not printed.") + + +if __name__ == "__main__": + main() diff --git a/scripts/bootstrap.py b/scripts/bootstrap.py new file mode 100644 index 0000000..5ac03ba --- /dev/null +++ b/scripts/bootstrap.py @@ -0,0 +1,340 @@ +#!/usr/bin/env python3 +"""Idempotent local PKI/secrets bootstrap. Operator material never enters containers.""" + +import json +import os +import secrets +import subprocess +from pathlib import Path + +ROOT = Path(__file__).resolve().parents[1] +PRIVATE = ROOT / "secrets" +OPERATOR = ROOT / "operator-private" +ROLES = ( + "api", + "worker", + "dispatcher", + "lb", + "postgres", + "storage", + "broker", + "cache", + "collector", + "prometheus", + "loki", + "tempo", + "grafana", + "openbao", + "operator", +) + + +def write(path, text, mode=0o644): + if not path.exists(): + path.write_text(text) + path.chmod(mode) + + +def run(*args): + subprocess.run( + ["openssl", *args], check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL + ) + + +def certificate(name, replace=False): + dest = PRIVATE / "pki" / name + dest.mkdir(parents=True, exist_ok=True) + dest.chmod(0o755) + if (dest / "cert.pem").exists() and not replace: + valid = subprocess.run( + ["openssl", "x509", "-in", str(dest / "cert.pem"), "-checkend", "3600", "-noout"], + capture_output=True, + ) + if valid.returncode == 0: + return + key, csr = dest / "key.pem", OPERATOR / (name + ".csr") + run("genpkey", "-algorithm", "EC", "-pkeyopt", "ec_paramgen_curve:P-256", "-out", str(key)) + run("req", "-new", "-key", str(key), "-subj", f"/CN={name}", "-out", str(csr)) + ext = OPERATOR / (name + ".ext") + names = f"DNS:{name}" + if name in { + "lb", + "api", + "postgres", + "broker", + "cache", + "collector", + "prometheus", + "loki", + "tempo", + "openbao", + "grafana", + "storage", + }: + names += ",DNS:localhost,IP:127.0.0.1" + ext.write_text( + f"subjectAltName={names}\nbasicConstraints=critical,CA:FALSE\nkeyUsage=critical,digitalSignature,keyEncipherment\nextendedKeyUsage=serverAuth,clientAuth\n" + ) + run( + "x509", + "-req", + "-in", + str(csr), + "-CA", + str(OPERATOR / "ca.pem"), + "-CAkey", + str(OPERATOR / "ca-key.pem"), + "-set_serial", + str(secrets.randbits(127) or 1), + "-days", + "2", + "-extfile", + str(ext), + "-out", + str(dest / "cert.pem"), + ) + key.chmod(0o644) + (dest / "combined.pem").write_text((dest / "cert.pem").read_text() + key.read_text()) + (dest / "combined.pem").chmod(0o644) + + +def main(): + os.umask(0o077) + for folder in (PRIVATE, OPERATOR): + folder.mkdir(exist_ok=True) + folder.chmod(0o700) + if not (OPERATOR / "ca-key.pem").exists(): + run( + "genpkey", + "-algorithm", + "EC", + "-pkeyopt", + "ec_paramgen_curve:P-256", + "-out", + str(OPERATOR / "ca-key.pem"), + ) + run( + "req", + "-x509", + "-new", + "-key", + str(OPERATOR / "ca-key.pem"), + "-subj", + "/CN=MTUSI Lab7 local CA", + "-days", + "365", + "-addext", + "basicConstraints=critical,CA:TRUE", + "-addext", + "keyUsage=critical,keyCertSign,cRLSign", + "-out", + str(OPERATOR / "ca.pem"), + ) + (PRIVATE / "ca.pem").write_text((OPERATOR / "ca.pem").read_text()) + (PRIVATE / "ca.pem").chmod(0o644) + (PRIVATE / "pki").mkdir(exist_ok=True) + (PRIVATE / "pki").chmod(0o755) + for name in ROLES: + certificate(name) + write(PRIVATE / "revoked.json", "[]") + for name in ( + "postgres_password", + "api_db_password", + "worker_db_password", + "dispatcher_db_password", + "cache_password", + "cache_worker_password", + "cache_dispatcher_password", + "broker_worker_password", + "broker_dispatcher_password", + "broker_admin_password", + "grafana_password", + ): + write(PRIVATE / name, secrets.token_urlsafe(32)) + for role in ("api", "worker", "admin", "study_wide"): + write(PRIVATE / (role + "_s3_access"), role + "-" + secrets.token_hex(12)) + write(PRIVATE / (role + "_s3_secret"), secrets.token_urlsafe(32)) + + def value(name): + return (PRIVATE / name).read_text().strip() + + identities = [] + for role in ("api", "worker", "admin", "study_wide"): + identities.append( + { + "name": role, + "credentials": [ + { + "accessKey": value(role + "_s3_access"), + "secretKey": value(role + "_s3_secret"), + } + ], + "actions": ["Admin", "Read", "Write", "List"] + if role == "admin" + else (["Read:security-study", "Write:security-study", "List:security-study"] if role == "study_wide" else ["Read:messenger", "Write:messenger", "List:messenger"]), + } + ) + (PRIVATE / "s3_config").write_text(json.dumps({"identities": identities})) + (PRIVATE / "s3_config").chmod(0o644) + write( + PRIVATE / "cache_config", + 'bind 127.0.0.1\nport 6379\nprotected-mode yes\nsave ""\nmaxmemory 64mb\nmaxmemory-policy allkeys-lru\nuser default off\nuser api on >' + + value("cache_password") + + " ~user:v1:* +get +setex +ping +hello +client|setinfo\nuser worker on >" + + value("cache_worker_password") + + " +ping +hello +client|setinfo\nuser dispatcher on >" + + value("cache_dispatcher_password") + + " +ping +hello +client|setinfo\n", + ) + write( + PRIVATE / "broker_config", + 'bind 127.0.0.1\nport 6379\nprotected-mode yes\nappendonly yes\nappendfsync always\nsave ""\ndir /data\nmaxmemory 128mb\nmaxmemory-policy noeviction\nuser default off\nuser operator on >' + + value("broker_admin_password") + + " ~* &* +@all\nuser dispatcher on >" + + value("broker_dispatcher_password") + + " ~attachment-jobs:v1 +xadd +ping +hello +client|setinfo\nuser worker on >" + + value("broker_worker_password") + + " ~attachment-jobs:v1 +xgroup|create +xreadgroup +xautoclaim +xack +xdel +ping +hello +client|setinfo\n", + ) + pg = "postgresql://{role}:{password}@postgres:5432/messenger?sslmode=verify-full&sslrootcert=/run/tls/ca.pem" + values = {} + for role in ("api", "worker", "dispatcher"): + values[role] = { + "DATABASE_URL": pg.format(role=role, password=value(role + "_db_password")), + "CACHE_URL": "rediss://" + + role + + ":" + + value("cache_password" if role == "api" else "cache_" + role + "_password") + + "@cache:6380/0?ssl_cert_reqs=required&ssl_ca_certs=/run/tls/ca.pem&ssl_certfile=/run/tls/identity/cert.pem&ssl_keyfile=/run/tls/identity/key.pem", + } + if role in {"worker", "dispatcher"}: + values[role]["BROKER_URL"] = ( + "rediss://" + + role + + ":" + + value("broker_" + role + "_password") + + "@broker:6380/0?ssl_cert_reqs=required&ssl_ca_certs=/run/tls/ca.pem&ssl_certfile=/run/tls/identity/cert.pem&ssl_keyfile=/run/tls/identity/key.pem" + ) + if role in {"api", "worker"}: + values[role].update( + S3_ACCESS_KEY=value(role + "_s3_access"), S3_SECRET_KEY=value(role + "_s3_secret") + ) + write(PRIVATE / "bao_seed.json", json.dumps(values)) + write( + PRIVATE / "admin_database_url", + pg.format(role="messenger", password=value("postgres_password")), + ) + write(PRIVATE / "admin_s3_access_key", value("admin_s3_access")) + write(PRIVATE / "admin_s3_secret_key", value("admin_s3_secret")) + write( + PRIVATE / "db_roles.sql", + "\n".join( + f"CREATE ROLE {role} LOGIN PASSWORD '{value(role + '_db_password')}';" + for role in ("api", "worker", "dispatcher") + ), + ) + gateways = { + "api": {"port": 9443, "upstream": 8080, "allowed": ["lb"]}, + "broker": { + "port": 6380, + "upstream": 6379, + "allowed": ["worker", "dispatcher", "operator"], + }, + "cache": { + "port": 6380, + "upstream": 6379, + "allowed": ["api", "worker", "dispatcher", "operator"], + }, + "storage": { + "port": 8443, + "upstream": 8333, + "allowed": ["api", "worker", "operator"], + "http": True, + "s3": True, + }, + "collector": [ + { + "port": 4318, + "upstream": 14318, + "allowed": ["api", "worker", "dispatcher", "operator"], + }, + {"port": 9464, "upstream": 19464, "allowed": ["prometheus", "operator"]}, + {"port": 8888, "upstream": 18888, "allowed": ["prometheus", "operator"]}, + ], + "prometheus": { + "http": True, + "backend": "prometheus", + "port": 9443, + "upstream": 9090, + "allowed": ["grafana", "operator"], + }, + "loki": { + "http": True, + "backend": "loki", + "port": 9443, + "upstream": 3100, + "allowed": ["collector", "grafana", "operator"], + }, + "tempo": [ + { + "port": 9443, + "upstream": 3200, + "allowed": ["grafana", "operator"], + "http": True, + "backend": "tempo", + }, + {"port": 44318, "upstream": 4318, "allowed": ["collector", "operator"]}, + ], + } + for role, configs in gateways.items(): + for item in configs if isinstance(configs, list) else [configs]: + item.update( + cert="/run/tls/identity/cert.pem", + key="/run/tls/identity/key.pem", + ca="/run/tls/ca.pem", + ) + (PRIVATE / (role + "_gateway.json")).write_text(json.dumps(configs)) + (PRIVATE / (role + "_gateway.json")).chmod(0o644) + provisioning = PRIVATE / "grafana-provisioning" / "datasources" + provisioning.mkdir(parents=True, exist_ok=True) + provisioning.parent.chmod(0o755) + provisioning.chmod(0o755) + datasources = [] + for name in ("prometheus", "loki", "tempo"): + item = { + "name": name.title(), + "uid": name, + "type": name, + "access": "proxy", + "url": f"https://{name}:9443", + "editable": False, + "jsonData": {"tlsAuth": True, "tlsAuthWithCACert": True, "serverName": name}, + "secureJsonData": { + "tlsCACert": (PRIVATE / "ca.pem").read_text(), + "tlsClientCert": (PRIVATE / "pki/grafana/cert.pem").read_text(), + "tlsClientKey": (PRIVATE / "pki/grafana/key.pem").read_text(), + }, + } + if name == "prometheus": + item["isDefault"] = True + if name == "loki": + item["jsonData"]["derivedFields"] = [ + { + "datasourceUid": "tempo", + "matcherRegex": '"trace_id": "([a-f0-9]{32})"', + "name": "TraceID", + "url": "$${__value.raw}", + } + ] + datasources.append(item) + (provisioning / "datasources.yaml").write_text( + json.dumps({"apiVersion": 1, "datasources": datasources}) + ) + (provisioning / "datasources.yaml").chmod(0o644) + if not (ROOT / ".env").exists(): + (ROOT / ".env").write_text("PUBLIC_PORT=8447\nSESSION_TTL_SECONDS=3600\n") + print("Local PKI and scoped credential material ready; operator CA stays outside containers.") + + +if __name__ == "__main__": + main() diff --git a/scripts/restart.sh b/scripts/restart.sh new file mode 100755 index 0000000..6eb21eb --- /dev/null +++ b/scripts/restart.sh @@ -0,0 +1,9 @@ +#!/bin/sh +set -eu +cd "$(dirname "$0")/.." +# Namespace-sharing gateways are stopped before their backing services restart. +# Unseal is an explicit operator action; shares never enter application containers. +docker compose stop +docker compose up -d postgres openbao cache cache-tls broker broker-tls storage s3 storage-tls +python3 scripts/bao_operator.py unseal +docker compose up -d --wait diff --git a/scripts/rotate_identity.py b/scripts/rotate_identity.py new file mode 100644 index 0000000..4bba9a0 --- /dev/null +++ b/scripts/rotate_identity.py @@ -0,0 +1,91 @@ +#!/usr/bin/env python3 +"""Operator-driven worker revoke/cert renewal and DB credential rotation, no rebuild.""" + +import importlib.util +import json +import secrets +import ssl +import subprocess +from pathlib import Path + +ROOT = Path(__file__).resolve().parents[1] + + +def main(): + spec = importlib.util.spec_from_file_location("bootstrap", ROOT / "scripts/bootstrap.py") + bootstrap = importlib.util.module_from_spec(spec) + spec.loader.exec_module(bootstrap) + old = ROOT / "secrets/pki/worker" + cert = ssl._ssl._test_decode_cert(str(old / "cert.pem")) + snapshot = ROOT / "operator-private/revoked-worker" + snapshot.mkdir(exist_ok=True, mode=0o700) + for name in ("cert.pem", "key.pem"): + (snapshot / name).write_bytes((old / name).read_bytes()) + (snapshot / name).chmod(0o600) + seed_before = json.loads((ROOT / "secrets/bao_seed.json").read_text()) + (snapshot / "material.json").write_text(json.dumps(seed_before["worker"])) + (snapshot / "material.json").chmod(0o644) + # The containing operator-private directory stays 0700 on the host. This + # disposable old-material mount is used only by the explicit negative probe. + for name in ("cert.pem", "key.pem"): + (snapshot / name).chmod(0o644) + snapshot.chmod(0o755) + revoked = ROOT / "secrets/revoked.json" + serials = json.loads(revoked.read_text()) + serials.append(cert["serialNumber"].lstrip("0").lower()) + revoked.write_text(json.dumps(sorted(set(serials)))) + subprocess.run( + ["docker", "compose", "stop", "worker"], cwd=ROOT, check=True, capture_output=True + ) + bootstrap.certificate("worker", replace=True) + password = secrets.token_urlsafe(32) + # psql receives SQL through stdin, never a process argument/output containing + # credentials. The operator/admin role is confined to this explicit command. + sql = f"ALTER ROLE worker PASSWORD '{password}'; SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE usename='worker' AND pid<>pg_backend_pid();" + subprocess.run( + [ + "docker", + "compose", + "exec", + "-T", + "postgres", + "psql", + "-U", + "messenger", + "-d", + "messenger", + "-v", + "ON_ERROR_STOP=1", + ], + cwd=ROOT, + input=sql, + text=True, + check=True, + capture_output=True, + ) + path = ROOT / "secrets/worker_db_password" + path.write_text(password) + seed_path = ROOT / "secrets/bao_seed.json" + seed = json.loads(seed_path.read_text()) + seed["worker"]["DATABASE_URL"] = ( + "postgresql://worker:" + + password + + "@postgres:5432/messenger?sslmode=verify-full&sslrootcert=/run/tls/ca.pem" + ) + seed_path.write_text(json.dumps(seed)) + subprocess.run( + ["python3", "scripts/bao_operator.py", "configure"], + cwd=ROOT, + check=True, + capture_output=True, + ) + subprocess.run( + ["docker", "compose", "start", "worker"], cwd=ROOT, check=True, capture_output=True + ) + print( + "Worker identity revoked and replaced; database credential rotated; worker resumed without image rebuild." + ) + + +if __name__ == "__main__": + main() diff --git a/scripts/security_checks.py b/scripts/security_checks.py new file mode 100644 index 0000000..33ef416 --- /dev/null +++ b/scripts/security_checks.py @@ -0,0 +1,217 @@ +#!/usr/bin/env python3 +"""Explicit operator probes; test identities never become application mounts.""" + +import argparse +import json +import os +import subprocess +from pathlib import Path + +ROOT = Path(__file__).resolve().parents[1] + + +def run(args, *, output=None): + result = subprocess.run(args, cwd=ROOT, check=True, capture_output=True, text=True) + if output: + (ROOT / "evidence" / output).write_text(result.stdout) + else: + print(result.stdout, end="") + return result.stdout + + +def foreign_certificate(): + path = ROOT / "secrets/pki/foreign" + path.mkdir(exist_ok=True, mode=0o755) + run( + [ + "openssl", + "req", + "-x509", + "-newkey", + "ec", + "-pkeyopt", + "ec_paramgen_curve:P-256", + "-nodes", + "-keyout", + str(path / "key.pem"), + "-out", + str(path / "cert.pem"), + "-days", + "1", + "-subj", + "/CN=foreign", + "-addext", + "subjectAltName=DNS:lb,DNS:worker,DNS:api", + ] + ) + for item in path.iterdir(): + item.chmod(0o644) + + +def audit_container(module, *, material=False): + command = [ + "docker", + "compose", + "run", + "--rm", + "--no-deps", + "-e", + "BAO_ROLE=", + "-e", + "OTEL_ENABLED=0", + "-v", + str(ROOT / "secrets/pki") + ":/run/audit-identities:ro", + ] + if material: + # Only selected synthetic/admin S3 credential files, never Bao root/shares. + path = ROOT / "operator-private/s3-study-material" + path.mkdir(exist_ok=True, mode=0o755) + for name in ( + "admin_s3_access", + "admin_s3_secret", + "study_wide_s3_access", + "study_wide_s3_secret", + "worker_s3_access", + "worker_s3_secret", + ): + (path / name).write_bytes((ROOT / "secrets" / name).read_bytes()) + (path / name).chmod(0o644) + command += ["-v", str(path) + ":/run/audit-material:ro"] + command += ["api", "python", "-m", module] + return command + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument("probe", choices=["transport", "policies", "baseline", "revoked", "kdf"]) + args = parser.parse_args() + os.umask(0o077) + if args.probe == "transport": + foreign_certificate() + run(audit_container("messenger.transport_probe"), output="transport-matrix.json") + elif args.probe == "policies": + run( + [ + "docker", + "compose", + "run", + "--rm", + "--no-deps", + "worker", + "python", + "-m", + "messenger.security_probe", + ], + output="worker-policy-final.json", + ) + elif args.probe == "baseline": + run( + [ + "docker", + "compose", + "run", + "--rm", + "--no-deps", + "migrate", + "python", + "-m", + "messenger.baseline_db_probe", + ], + output="baseline-db.json", + ) + run( + [ + "docker", + "compose", + "exec", + "-T", + "broker", + "valkey-server", + "--port", + "6378", + "--bind", + "127.0.0.1", + "--save", + "", + "--appendonly", + "no", + "--daemonize", + "yes", + "--pidfile", + "/tmp/security-study.pid", + "--logfile", + "/tmp/security-study.log", + ] + ) + broker = run(["docker", "compose", "ps", "-q", "broker"]).strip() + config = json.loads( + subprocess.check_output( + ["docker", "compose", "config", "--format", "json"], cwd=ROOT, text=True + ) + ) + app_image = config["services"]["api"]["image"] + run( + [ + "docker", + "run", + "--rm", + "--network", + "container:" + broker, + "--read-only", + "--cap-drop", + "ALL", + "--security-opt", + "no-new-privileges", + "--memory", + "128m", + "--cpus", + "0.5", + app_image, + "python", + "-m", + "messenger.baseline_queue_probe", + ], + output="baseline-queue.json", + ) + run( + audit_container("messenger.baseline_s3_probe", material=True), output="baseline-s3.json" + ) + elif args.probe == "revoked": + run( + [ + "docker", + "compose", + "run", + "--rm", + "--no-deps", + "-v", + str(ROOT / "operator-private/revoked-worker") + ":/run/old-worker:ro", + "worker", + "python", + "-m", + "messenger.revoked_probe", + ], + output="revoked-identity.json", + ) + else: + run( + [ + "docker", + "compose", + "run", + "--rm", + "--no-deps", + "-e", + "OTEL_ENABLED=0", + "worker", + "python", + "-m", + "messenger.kdf_probe", + ], + output="argon2-budget.json", + ) + print(json.dumps({"probe": args.probe, "passed": True})) + + +if __name__ == "__main__": + main() diff --git a/scripts/stop-one.sh b/scripts/stop-one.sh new file mode 100755 index 0000000..3d9eb6a --- /dev/null +++ b/scripts/stop-one.sh @@ -0,0 +1,4 @@ +#!/bin/sh +set -eu +cd "$(dirname "$0")/.." +python3 scripts/stop_one.py diff --git a/scripts/stop_one.py b/scripts/stop_one.py new file mode 100644 index 0000000..df82545 --- /dev/null +++ b/scripts/stop_one.py @@ -0,0 +1,22 @@ +"""Map a process alias to its real container, then leave exactly it stopped.""" +import json +import os +import subprocess +from pathlib import Path + +wanted = os.environ["TARGET_INSTANCE_ID"] +ids = subprocess.check_output(["docker", "compose", "ps", "-q", "api"], text=True).split() +for cid in ids: + result = subprocess.run( + ["docker", "exec", cid, "python", "-c", + "import urllib.request; r=urllib.request.urlopen('http://127.0.0.1:8080/health/live'); print(r.headers['X-Instance-Id'])"], + text=True, capture_output=True, check=False, + ) + if result.returncode == 0 and result.stdout.strip() == wanted: + subprocess.run(["docker", "stop", "--time", "8", cid], check=True, stdout=subprocess.DEVNULL) + receipt = {"stopped_container": cid, "instance_id": wanted} + Path("evidence/last-stopped.json").write_text(json.dumps(receipt)) + print(json.dumps(receipt)) + break +else: + raise SystemExit("Target instance not found among this project's API containers") diff --git a/src/messenger/__init__.py b/src/messenger/__init__.py new file mode 100644 index 0000000..58ffea1 --- /dev/null +++ b/src/messenger/__init__.py @@ -0,0 +1 @@ +"""Учебный REST-мессенджер.""" diff --git a/src/messenger/__main__.py b/src/messenger/__main__.py new file mode 100644 index 0000000..5b5cda1 --- /dev/null +++ b/src/messenger/__main__.py @@ -0,0 +1,12 @@ +import os + +import uvicorn + +uvicorn.run( + "messenger.app:app", + host=os.getenv("APP_HOST", "0.0.0.0"), + port=int(os.getenv("APP_PORT", "8080")), + workers=1, + access_log=False, + timeout_graceful_shutdown=5, +) diff --git a/src/messenger/app.py b/src/messenger/app.py new file mode 100644 index 0000000..6296c2c --- /dev/null +++ b/src/messenger/app.py @@ -0,0 +1,384 @@ +import base64 +import binascii +import json +import logging +import os +import re +import time +from contextlib import asynccontextmanager +from threading import BoundedSemaphore +from uuid import uuid4 + +from fastapi import Depends, FastAPI, Request, Response +from fastapi.exceptions import RequestValidationError +from fastapi.responses import JSONResponse +from opentelemetry import propagate +from opentelemetry.trace import SpanKind, Status, StatusCode +from starlette.concurrency import run_in_threadpool +from starlette.exceptions import HTTPException + +from . import telemetry +from .attachments import AttachmentService +from .domain import Failure, boundary, identifier, page +from .models import CreateChat, CreateMessage, CreateUser +from .postgres import PostgresStore +from .secrets_provider import refresh +from .storage import ObjectStorage + +logger = logging.getLogger("messenger") +logging.basicConfig(level=os.getenv("LOG_LEVEL", "INFO"), format="%(message)s") +INSTANCE_ID = telemetry.INSTANCE_ID + +CODES = { + 400: "invalid_request", + 401: "unauthorized", + 404: "not_found", + 409: "conflict", + 413: "payload_too_large", + 415: "unsupported_media_type", + 429: "rate_limited", + 503: "unavailable", + 500: "internal_error", +} + + +@asynccontextmanager +async def lifespan(app): + app.state.telemetry = telemetry.setup("messenger-api") + app.state.store = PostgresStore() + app.state.telemetry.start_background(app.state.store) + app.state.storage = ObjectStorage() + app.state.attachments = AttachmentService(app.state.store, app.state.storage) + app.state.upload_slots = BoundedSemaphore(1) + logger.info(json.dumps({"event": "started", "storage": "postgres"})) + yield + logger.info(json.dumps({"event": "stopped"})) + app.state.telemetry.close() + app.state.storage.close() + app.state.store.close() + + +app = FastAPI(lifespan=lifespan, docs_url=None, redoc_url=None, openapi_url=None) + + +def error(request, status, message, headers=None): + return JSONResponse( + { + "error": { + "code": CODES.get(status, "invalid_request"), + "message": message, + "request_id": request.state.request_id, + } + }, + status_code=status, + headers=headers, + ) + + +async def invalid_json_encoding(request: Request): + path = request.url.path + if request.method != "POST" or not ( + path in {"/api/v1/users", "/api/v1/chats"} + or re.fullmatch(r"/api/v1/chats/[^/]+/messages", path) + ): + return False + raw = await request.body() + try: + raw.decode("utf-8") + except UnicodeDecodeError: + return True + # Literal NUL is invalid JSON; it also prevents json.loads(bytes) from + # autodetecting BOM-less UTF-16/32. Escaped JSON \u0000 remains valid. + return b"\x00" in raw + + +@app.middleware("http") +async def request_log(request: Request, call_next): + request.state.request_id = str(uuid4()) + start = time.perf_counter() + observed = not request.url.path.startswith("/health/") + if not observed: + try: + if request.url.path != "/health/live": + await run_in_threadpool(refresh) + response = await call_next(request) + except Failure as exc: + response = error(request, exc.status, exc.message, exc.headers) + response.headers["X-Request-Id"] = request.state.request_id + response.headers["X-Instance-Id"] = INSTANCE_ID + return response + method = ( + request.method + if request.method in {"GET", "POST", "DELETE", "PUT", "PATCH", "HEAD", "OPTIONS"} + else "OTHER" + ) + context = propagate.extract(dict(request.headers)) + with telemetry.operation("HTTP " + method, context=context, kind=SpanKind.SERVER) as span: + try: + await run_in_threadpool(refresh) + if ( + request.method == "POST" + and request.url.path == "/api/v1/auth/sessions" + and await request.body() + ): + response = error(request, 400, "Вход не принимает тело запроса") + elif await invalid_json_encoding(request): + response = error(request, 400, "JSON должен быть закодирован в UTF-8") + else: + response = await call_next(request) + except Failure as exc: + response = error(request, exc.status, exc.message, exc.headers) + except Exception: + logger.error( + json.dumps({"event": "unexpected_error", "request_id": request.state.request_id}) + ) + response = error(request, 500, "Внутренняя ошибка") + response.headers["X-Request-Id"] = request.state.request_id + response.headers["X-Instance-Id"] = INSTANCE_ID + response.headers["X-Trace-Id"] = format(span.get_span_context().trace_id, "032x") + response.headers["X-Trace-Sampled"] = "true" if span.is_recording() else "false" + route = getattr(request.scope.get("route"), "path", "unknown") + elapsed = time.perf_counter() - start + attrs = { + "method": method, + "route": route, + "status_class": str(response.status_code // 100) + "xx", + } + span.update_name(method + " " + route) + span.set_attributes( + { + "http.request.method": method, + "http.route": route, + "http.response.status_code": response.status_code, + } + ) + if response.status_code >= 500: + span.set_status(Status(StatusCode.ERROR, "server_error")) + t = telemetry.current() + if observed and t: + t.requests.add(1, attrs) + t.http_duration.record(elapsed, attrs) + t.sampling.add(1, {"decision": "sampled" if span.is_recording() else "not_sampled"}) + logger.info( + json.dumps( + { + "event": "request", + "request_id": request.state.request_id, + **attrs, + "status": response.status_code, + "duration_ms": round(elapsed * 1000, 3), + } + ) + ) + return response + + +@app.exception_handler(Failure) +async def domain_error(request, exc): + return error(request, exc.status, exc.message, exc.headers) + + +@app.exception_handler(RequestValidationError) +async def validation_error(request, exc): + return error(request, 400, "Неверный JSON или поля запроса") + + +@app.exception_handler(HTTPException) +async def http_error(request, exc): + return error(request, exc.status_code, "Неверный запрос", exc.headers) + + +def bearer_failure(): + return Failure( + 401, "Требуется действующая сессия", {"WWW-Authenticate": 'Bearer realm="messenger"'} + ) + + +def bearer(request): + parts = request.headers.get("Authorization", "").split() + if len(parts) != 2 or parts[0].lower() != "bearer": + raise bearer_failure() + return parts[1] + + +def actor(request: Request): + user = request.app.state.store.authenticate(bearer(request)) + if user is None: + raise bearer_failure() + return user + + +@app.post("/api/v1/auth/sessions", status_code=201) +def login(request: Request): + headers = {"WWW-Authenticate": 'Basic realm="messenger", charset="UTF-8"'} + parts = request.headers.get("Authorization", "").split() + try: + if len(parts) != 2 or parts[0].lower() != "basic" or len(parts[1]) > 2048: + raise ValueError + decoded = base64.b64decode(parts[1], validate=True).decode("utf-8") + username, password = decoded.split(":", 1) + if not re.fullmatch(r"[a-z0-9_]{3,32}", username) or not 12 <= len(password) <= 128: + raise ValueError + except (ValueError, UnicodeError, binascii.Error): + raise Failure(401, "Неверные учётные данные", headers) from None + session = request.app.state.store.login(username, password) + if session is None: + raise Failure(401, "Неверные учётные данные", headers) + return session + + +@app.delete("/api/v1/auth/sessions/current", status_code=204) +def logout(request: Request, user=Depends(actor)): + if not request.app.state.store.logout(bearer(request)): + raise bearer_failure() + return Response(status_code=204) + + +def pagination(request, scope): + allowed = {"limit", "cursor"} + if any(k not in allowed for k in request.query_params): + raise Failure(400, "Неизвестный параметр запроса") + if any(len(request.query_params.getlist(k)) > 1 for k in allowed): + raise Failure(400, "Повторный параметр запроса") + value = request.query_params.get("limit", "50") + if len(value) > 3 or not re.fullmatch(r"[0-9]+", value) or not 1 <= int(value) <= 100: + raise Failure(400, "limit должен быть целым от 1 до 100") + return int(value), boundary(scope, request.query_params.get("cursor")) + + +@app.get("/health/live") +def live(): + return {"status": "ok"} + + +@app.get("/health/ready") +def ready(request: Request): + if not request.app.state.store.ready() or not request.app.state.storage.ready(): + raise Failure(503, "Хранилище недоступно") + return {"status": "ok"} + + +@app.post("/api/v1/users", status_code=201) +def register(data: CreateUser, request: Request): + return request.app.state.store.register(data.model_dump(mode="json")) + + +@app.get("/api/v1/users/me") +def me(user=Depends(actor)): + return user + + +@app.post("/api/v1/chats", status_code=201) +def create_chat(data: CreateChat, request: Request, user=Depends(actor)): + return request.app.state.store.create_chat(user["id"], data.model_dump(mode="json")) + + +@app.get("/api/v1/chats") +def chats(request: Request, user=Depends(actor)): + scope = "chats:" + user["id"] + limit, after = pagination(request, scope) + return page(request.app.state.store.list_chats(user["id"], after, limit), limit, scope) + + +@app.get("/api/v1/chats/{chat_id}") +def chat(chat_id: str, request: Request, user=Depends(actor)): + return request.app.state.store.chat(user["id"], identifier(chat_id)) + + +@app.post("/api/v1/chats/{chat_id}/messages", status_code=201) +def send(chat_id: str, data: CreateMessage, request: Request, user=Depends(actor)): + key = request.headers.get("Idempotency-Key", "") + if not re.fullmatch(r"[A-Za-z0-9._:-]{1,128}", key): + raise Failure(400, "Требуется корректный Idempotency-Key") + return request.app.state.store.send( + user["id"], identifier(chat_id), data.text, key, [str(a) for a in data.attachment_ids] + ) + + +@app.get("/api/v1/chats/{chat_id}/messages") +def history(chat_id: str, request: Request, user=Depends(actor)): + cid = identifier(chat_id) + scope = "messages:" + cid + limit, after = pagination(request, scope) + return page(request.app.state.store.history(user["id"], cid, after, limit), limit, scope) + + +@app.post("/api/v1/chats/{chat_id}/attachments", status_code=202) +async def upload_attachment(chat_id: str, request: Request, user=Depends(actor)): + import asyncio + import tempfile + + from starlette.concurrency import run_in_threadpool + + from .attachments import MAX_BYTES, filename_valid + + if ( + set(request.query_params) != {"filename"} + or len(request.query_params.getlist("filename")) != 1 + ): + raise Failure(400, "Требуется одно имя файла") + filename = filename_valid(request.query_params["filename"]) + cid = identifier(chat_id) + await run_in_threadpool(request.app.state.store.chat, user["id"], cid) + content_type = request.headers.get("content-type", "").lower() + if content_type not in {"image/png", "image/jpeg"}: + raise Failure(415, "Ожидается PNG или JPEG") + if not request.app.state.upload_slots.acquire(blocking=False): + raise Failure(429, "Все места загрузки заняты", {"Retry-After": "1"}) + try: + with tempfile.SpooledTemporaryFile(max_size=256 * 1024) as spool: + size = 0 + try: + async with asyncio.timeout(15): + async for chunk in request.stream(): + size += len(chunk) + if size > MAX_BYTES: + raise Failure(413, "Файл больше 10 MiB") + spool.write(chunk) + except TimeoutError: + raise Failure(400, "Истекло время загрузки") from None + spool.seek(0) + return await run_in_threadpool( + request.app.state.attachments.upload, + user["id"], + cid, + filename, + content_type, + spool, + size, + ) + finally: + request.app.state.upload_slots.release() + + +@app.get("/api/v1/attachments/{attachment_id}") +def attachment_metadata(attachment_id: str, request: Request, user=Depends(actor)): + return request.app.state.attachments.metadata(user["id"], identifier(attachment_id)) + + +@app.get("/api/v1/attachments/{attachment_id}/content") +def attachment_content(attachment_id: str, request: Request, user=Depends(actor)): + from fastapi.responses import StreamingResponse + + if ( + any(k != "variant" for k in request.query_params) + or len(request.query_params.getlist("variant")) > 1 + ): + raise Failure(400, "Неверный вариант") + variant = request.query_params.get("variant", "original") + if variant not in {"original", "thumbnail", "crop", "optimized"}: + raise Failure(400, "Неверный вариант") + obj = request.app.state.attachments.content(user["id"], identifier(attachment_id), variant) + + def chunks(): + try: + while data := obj["Body"].read(64 * 1024): + yield data + finally: + obj["Body"].close() + + return StreamingResponse( + chunks(), + media_type=obj["ContentType"], + headers={"Content-Length": str(obj["ContentLength"])}, + ) diff --git a/src/messenger/attachments.py b/src/messenger/attachments.py new file mode 100644 index 0000000..db58d23 --- /dev/null +++ b/src/messenger/attachments.py @@ -0,0 +1,176 @@ +"""Durable asynchronous intake with full bounded validation before acceptance.""" + +import hashlib +import json +import os +import signal +import subprocess +import sys +import unicodedata +from pathlib import Path +from uuid import uuid4 + +from .domain import Failure, timestamp +from .jobs import Jobs, fault +from .postgres import public + +MAX_BYTES = 10 * 1024 * 1024 +MAX_PIXELS = 40_000_000 +PUBLIC_FIELDS = ( + "id", + "chat_id", + "owner_id", + "filename", + "content_type", + "size_bytes", + "sha256", + "status", + "error_code", + "created_at", + "updated_at", +) + + +def filename_valid(name): + if not isinstance(name, str) or not 1 <= len(name) <= 255 or not name.strip(): + raise Failure(400, "Неверное имя файла") + if any(c in "/\\" or unicodedata.category(c) == "Cc" for c in name): + raise Failure(400, "Неверное имя файла") + return name + + +def validate_image(fileobj, declared_type): + if declared_type not in {"image/png", "image/jpeg"}: + raise Failure(415, "Ожидается PNG или JPEG") + fileobj.seek(0) + encoded = fileobj.read(MAX_BYTES + 1) + if len(encoded) > MAX_BYTES: + raise Failure(413, "Файл больше 10 MiB") + try: + with subprocess.Popen( + [sys.executable, "-m", "messenger.image_validation", declared_type], + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + start_new_session=True, + env={ + "PATH": os.environ.get("PATH", os.defpath), + "PYTHONPATH": str(Path(__file__).resolve().parents[1]), + "PYTHONDONTWRITEBYTECODE": "1", + "LANG": "C.UTF-8", + }, + ) as process: + try: + output, _ = process.communicate(input=encoded, timeout=5) + except subprocess.TimeoutExpired: + # The validator can itself run djpeg: kill its whole process group + # before releasing the upload slot, not only the Python parent. + try: + os.killpg(process.pid, signal.SIGKILL) + except ProcessLookupError: + pass # The child may have exited at the timeout boundary. + process.communicate() + raise Failure(415, "Изображение не прошло ограниченную проверку") from None + if process.returncode: + try: + os.killpg(process.pid, signal.SIGKILL) + except ProcessLookupError: + pass + raise Failure(415, "Изображение не прошло ограниченную проверку") + except OSError: + raise Failure(503, "Проверка изображения временно недоступна") from None + finally: + del encoded + try: + outcome = json.loads(output) + except (ValueError, UnicodeError): + raise Failure(415, "Повреждённое изображение") from None + if not isinstance(outcome, dict): + raise Failure(415, "Изображение не прошло ограниченную проверку") + if "error" in outcome: + status = outcome["error"] + if type(status) is not int or status not in {413, 415}: + status = 415 + raise Failure(status, "Изображение не прошло ограниченную проверку") + values = outcome.get("ok") + if not isinstance(values, list) or len(values) != 3: + raise Failure(415, "Изображение не прошло ограниченную проверку") + fileobj.seek(0) + return tuple(values) + + +def metadata_public(row): + return {**public({k: row[k] for k in PUBLIC_FIELDS}), "variants": row["variants"]} + + +class AttachmentService: + def __init__(self, store, storage): + self.store = store + self.storage = storage + self.jobs = Jobs(store) + + def upload(self, actor, cid, filename, content_type, fileobj, size): + filename_valid(filename) + if not 1 <= size <= MAX_BYTES: + raise Failure(413 if size > MAX_BYTES else 415, "Неверный размер изображения") + validate_image(fileobj, content_type) + digest = hashlib.file_digest(fileobj, "sha256").hexdigest() + aid = str(uuid4()) + key = "staging/" + aid + now = timestamp() + with self.store.connection() as conn: + self.store._chat(conn, actor, cid) + conn.execute( + "INSERT INTO upload_intents(id,object_key,created_at) VALUES (%s,%s,%s)", + (aid, key, now), + ) + # Keep the intent locked throughout PUT/finalization: reconciler skips live + # uploads even if a slow request crosses the grace boundary. + with self.store.connection() as conn, conn.transaction(): + intent = conn.execute( + "SELECT id FROM upload_intents WHERE id=%s FOR UPDATE", (aid,) + ).fetchone() + if not intent: + raise Failure(503, "Загрузка больше не активна") + self.storage.put(key, fileobj, size, content_type) + fault(self.store, "after_staging", aid) + row = conn.execute( + "INSERT INTO attachments(id,chat_id,owner_id,filename,content_type,size_bytes,sha256," + "status,error_code,created_at,updated_at,object_key,stage_key) " + "VALUES (%s,%s,%s,%s,%s,%s,%s,'queued',NULL,%s,%s,%s,%s) RETURNING *", + (aid, cid, actor, filename, content_type, size, digest, now, now, key, key), + ).fetchone() + self.jobs.enqueue(conn, aid, key) + conn.execute("DELETE FROM upload_intents WHERE id=%s", (aid,)) + # Never delete S3 on an ambiguous COMMIT: the transaction may have committed. + fault(self.store, "after_upload_commit", aid) + return metadata_public(row) + + def metadata(self, actor, aid): + with self.store.connection() as conn: + row = conn.execute( + "SELECT a.* FROM attachments a JOIN members m ON m.chat_id=a.chat_id " + "WHERE a.id=%s AND m.user_id=%s", + (aid, actor), + ).fetchone() + if not row: + raise Failure(404, "Объект не найден") + return metadata_public(row) + + def content(self, actor, aid, variant="original"): + with self.store.connection() as conn: + row = conn.execute( + "SELECT a.* FROM attachments a JOIN members m ON m.chat_id=a.chat_id " + "WHERE a.id=%s AND m.user_id=%s", + (aid, actor), + ).fetchone() + if not row: + raise Failure(404, "Объект не найден") + if row["status"] != "ready": + raise Failure(409, "Вложение не готово") + key = row["object_key"] + if variant != "original": + if variant not in {v["name"] for v in row["variants"]}: + raise Failure(404, "Вариант не найден") + key = key.rsplit("/", 1)[0] + "/" + variant + return self.storage.get(key) diff --git a/src/messenger/baseline_db_probe.py b/src/messenger/baseline_db_probe.py new file mode 100644 index 0000000..2101ff8 --- /dev/null +++ b/src/messenger/baseline_db_probe.py @@ -0,0 +1,81 @@ +"""Same SQL with actual PG roles, confined to a disposable synthetic schema.""" + +import json +import secrets + +import psycopg +from psycopg import sql + +from .config import secret + + +def main(): + suffix = secrets.token_hex(5) + schema, wide, limited = (prefix + suffix for prefix in ("study_", "wide_", "limited_")) + admin = psycopg.connect(secret("DATABASE_URL"), autocommit=True) + rows = [] + try: + # SET ROLE is an explicit operator act. Both NOLOGIN test roles have no + # grants on application tables. Wide owns ONLY the synthetic namespace. + for role in (wide, limited): + admin.execute(sql.SQL("CREATE ROLE {} NOLOGIN").format(sql.Identifier(role))) + admin.execute( + sql.SQL("CREATE SCHEMA {} AUTHORIZATION {}").format( + sql.Identifier(schema), sql.Identifier(wide) + ) + ) + admin.execute(sql.SQL("SET search_path TO {}").format(sql.Identifier(schema))) + admin.execute(sql.SQL("SET ROLE {}").format(sql.Identifier(wide))) + admin.execute("CREATE TABLE users(password_hash text); CREATE TABLE jobs(id int)") + admin.execute( + sql.SQL("GRANT USAGE ON SCHEMA {} TO {}; GRANT SELECT ON jobs TO {}").format( + sql.Identifier(schema), sql.Identifier(limited), sql.Identifier(limited) + ) + ) + admin.execute("RESET ROLE") + for label, role in (("wide", wide), ("limited", limited)): + admin.execute(sql.SQL("SET ROLE {}").format(sql.Identifier(role))) + assert admin.execute("SELECT current_user").fetchone()[0] == role + for name, query, restricted_expected in ( + ("read_password_hash", "SELECT password_hash FROM users LIMIT 0", False), + ("create_table", "CREATE TABLE forbidden(id int)", False), + ("read_jobs", "SELECT id FROM jobs LIMIT 0", True), + ): + try: + admin.execute(query) + allowed = True + if name == "create_table": + admin.execute("DROP TABLE forbidden") + except psycopg.errors.InsufficientPrivilege: + allowed = False + rows.append( + { + "role": label, + "operation": name, + "allowed": allowed, + "expected": restricted_expected if label == "limited" else True, + } + ) + admin.execute("RESET ROLE") + passed = all(r["allowed"] == r["expected"] for r in rows) + print( + json.dumps( + { + "scope": "disposable synthetic schema; operator SET ROLE to NOLOGIN roles", + "rows": rows, + "passed": passed, + } + ) + ) + if not passed: + raise SystemExit(1) + finally: + admin.execute("RESET ROLE") + admin.execute(sql.SQL("DROP SCHEMA IF EXISTS {} CASCADE").format(sql.Identifier(schema))) + for role in (limited, wide): + admin.execute(sql.SQL("DROP ROLE IF EXISTS {}").format(sql.Identifier(role))) + admin.close() + + +if __name__ == "__main__": + main() diff --git a/src/messenger/baseline_queue_probe.py b/src/messenger/baseline_queue_probe.py new file mode 100644 index 0000000..7bf8b56 --- /dev/null +++ b/src/messenger/baseline_queue_probe.py @@ -0,0 +1,65 @@ +"""Isolated loopback-only Valkey control: same operations before/after ACL narrowing.""" + +import json +import secrets + +import redis + + +def main(): + admin = redis.Redis(host="127.0.0.1", port=6378, decode_responses=True) + wide_pass, limited_pass = secrets.token_urlsafe(24), secrets.token_urlsafe(24) + admin.execute_command( + "ACL", "SETUSER", "wide", "on", ">" + wide_pass, "~security-study:*", "+@all" + ) + admin.execute_command( + "ACL", + "SETUSER", + "limited", + "on", + ">" + limited_pass, + "~security-study:jobs", + "+ping", + "+xgroup|create", + "+xreadgroup", + "+xautoclaim", + "+xack", + "+xdel", + ) + rows = [] + for role, password in (("wide", wide_pass), ("limited", limited_pass)): + client = redis.Redis( + host="127.0.0.1", port=6378, username=role, password=password, decode_responses=True + ) + for name, operation in ( + ("queue_admin_acl_list", lambda client=client: client.acl_list()), + ( + "queue_publish", + lambda client=client: client.xadd("security-study:jobs", {"body": "synthetic"}), + ), + ( + "queue_other_key_write", + lambda client=client: client.set("security-study:other", "synthetic"), + ), + ): + try: + operation() + allowed = True + except redis.ResponseError: + allowed = False + rows.append({"role": role, "operation": name, "allowed": allowed}) + client.close() + print( + json.dumps( + { + "isolated_port": 6378, + "rows": rows, + "passed": all(r["allowed"] == (r["role"] == "wide") for r in rows), + } + ) + ) + admin.shutdown(nosave=True) + + +if __name__ == "__main__": + main() diff --git a/src/messenger/baseline_s3_probe.py b/src/messenger/baseline_s3_probe.py new file mode 100644 index 0000000..a20b665 --- /dev/null +++ b/src/messenger/baseline_s3_probe.py @@ -0,0 +1,88 @@ +"""Disposable bucket comparison; baseline credentials cannot access messenger.""" + +import json +from pathlib import Path + +import boto3 +from botocore.config import Config +from botocore.exceptions import ClientError + + +def client(access, secret, identity): + return boto3.client( + "s3", + endpoint_url="https://storage:8443", + aws_access_key_id=access, + aws_secret_access_key=secret, + region_name="us-east-1", + verify="/run/tls/ca.pem", + config=Config( + client_cert=( + f"/run/audit-identities/{identity}/cert.pem", + f"/run/audit-identities/{identity}/key.pem", + ), + connect_timeout=2, + read_timeout=3, + retries={"total_max_attempts": 1}, + s3={"addressing_style": "path"}, + request_checksum_calculation="when_required", + response_checksum_validation="when_required", + ), + ) + + +def main(): + root = Path("/run/audit-material") + + def read(name): + return (root / name).read_text().strip() + + admin = client(read("admin_s3_access"), read("admin_s3_secret"), "operator") + wide = client(read("study_wide_s3_access"), read("study_wide_s3_secret"), "operator") + limited = client(read("worker_s3_access"), read("worker_s3_secret"), "worker") + bucket = "security-study" + rows = [] + try: + wide.get_object(Bucket="messenger", Key="private/not-a-real-user-object") + isolated = False + except ClientError as exc: + isolated = exc.response["ResponseMetadata"]["HTTPStatusCode"] == 403 + admin.create_bucket(Bucket=bucket) + admin.put_object(Bucket=bucket, Key="private/synthetic", Body=b"synthetic-not-user-data") + try: + for role, c in (("wide", wide), ("limited", limited)): + for operation in ("read_private", "write_private"): + try: + if operation == "read_private": + response = c.get_object(Bucket=bucket, Key="private/synthetic") + response["Body"].read() + response["Body"].close() + else: + c.put_object(Bucket=bucket, Key="private/written", Body=b"synthetic") + allowed = True + except ClientError as exc: + if exc.response["ResponseMetadata"]["HTTPStatusCode"] != 403: + raise + allowed = False + rows.append({"role": role, "operation": operation, "allowed": allowed}) + print( + json.dumps( + { + "scope": "disposable bucket security-study; broad role has no messenger rights", + "rows": rows, + "wide_role_denied_application_bucket": isolated, + "passed": isolated + and all(row["allowed"] == (row["role"] == "wide") for row in rows), + } + ) + ) + finally: + for key in ("private/synthetic", "private/written"): + admin.delete_object(Bucket=bucket, Key=key) + admin.delete_bucket(Bucket=bucket) + for c in (admin, wide, limited): + c.close() + + +if __name__ == "__main__": + main() diff --git a/src/messenger/config.py b/src/messenger/config.py new file mode 100644 index 0000000..c5ffbbd --- /dev/null +++ b/src/messenger/config.py @@ -0,0 +1,14 @@ +import os +from pathlib import Path + + +def secret(name: str) -> str: + if os.getenv("BAO_ROLE"): + from .secrets_provider import value + + return value(name) + filename = os.environ.get(name + "_FILE") + value = Path(filename).read_text().strip() if filename else os.environ.get(name, "") + if not value: + raise RuntimeError("Отсутствует настройка " + name) + return value diff --git a/src/messenger/domain.py b/src/messenger/domain.py new file mode 100644 index 0000000..7d1a462 --- /dev/null +++ b/src/messenger/domain.py @@ -0,0 +1,63 @@ +import base64 +import json +import re +from datetime import UTC, datetime +from uuid import UUID + + +class Failure(Exception): + def __init__(self, status: int, message: str, headers: dict | None = None): + self.status = status + self.message = message + self.headers = headers or {} + + +def timestamp() -> str: + return datetime.now(UTC).isoformat(timespec="microseconds").replace("+00:00", "Z") + + +def identifier(value: str) -> str: + try: + return str(UUID(value)) + except (ValueError, TypeError, AttributeError): + raise Failure(400, "Некорректный UUID") from None + + +def boundary(scope: str, cursor: str | None) -> tuple[str, str] | None: + if cursor is None: + return None + try: + if not cursor or len(cursor) > 1024 or not re.fullmatch(r"[A-Za-z0-9_-]+", cursor): + raise ValueError + data = json.loads(base64.urlsafe_b64decode(cursor + "=" * (-len(cursor) % 4))) + if ( + not isinstance(data, list) + or len(data) != 4 + or type(data[0]) is not int + or data[0] != 1 + or data[1] != scope + ): + raise ValueError + date, uid = data[2:] + if not isinstance(date, str) or not re.fullmatch( + r"[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(?:\.[0-9]{1,6})?Z", + date, + ): + raise ValueError + datetime.fromisoformat(date.replace("Z", "+00:00")) + if not isinstance(uid, str) or str(UUID(uid)) != uid: + raise ValueError + return date, uid + except (ValueError, TypeError, KeyError, UnicodeError): + raise Failure(400, "Некорректный cursor или область запроса") from None + + +def page(items: list[dict], limit: int, scope: str) -> dict: + more = len(items) > limit + selected = items[:limit] + cursor = None + if more: + last = selected[-1] + payload = json.dumps([1, scope, last["created_at"], last["id"]], separators=(",", ":")) + cursor = base64.urlsafe_b64encode(payload.encode()).decode().rstrip("=") + return {"items": selected, "next_cursor": cursor} diff --git a/src/messenger/image_pipeline.py b/src/messenger/image_pipeline.py new file mode 100644 index 0000000..b298aab --- /dev/null +++ b/src/messenger/image_pipeline.py @@ -0,0 +1,82 @@ +"""Image transformations, run in a bounded child process by the worker.""" + +import hashlib +import json +import sys +from pathlib import Path + +from PIL import Image, ImageOps + +Image.MAX_IMAGE_PIXELS = 40_000_000 + + +def fitted_size(width, height, bound): + """Fit without upscale; integer arithmetic deliberately rounds down.""" + longest = max(width, height) + if longest <= bound: + return width, height + return max(1, width * bound // longest), max(1, height * bound // longest) + + +def render(source, destination, version=1): + if version not in (1, 2): + raise ValueError("unsupported_pipeline") + destination = Path(destination) + with Image.open(source) as image: + if image.width * image.height > 40_000_000: + raise ValueError("pixel_limit") + image.load() + ImageOps.exif_transpose(image, in_place=True) + if "A" in image.getbands() or (image.mode == "P" and "transparency" in image.info): + rgba = image if image.mode == "RGBA" else image.convert("RGBA") + rgb = Image.new("RGB", rgba.size, "white") + alpha = rgba.getchannel("A") + rgb.paste(rgba, mask=alpha) + alpha.close() + if rgba is not image: + rgba.close() + else: + rgb = image if image.mode == "RGB" else image.convert("RGB") + thumbnail = rgb.resize(fitted_size(*rgb.size, 256), Image.Resampling.LANCZOS) + crop = ImageOps.fit(rgb, (128, 128), method=Image.Resampling.LANCZOS, centering=(0.5, 0.5)) + optimized = rgb.resize(fitted_size(*rgb.size, 1280), Image.Resampling.LANCZOS) + variants = [] + for name, variant, kind, mime, options in ( + ("thumbnail", thumbnail, "JPEG", "image/jpeg", {"quality": 85}), + ("crop", crop, "JPEG", "image/jpeg", {"quality": 85}), + ( + "optimized", + optimized, + "WEBP", + "image/webp", + {"quality": 80 if version == 1 else 75, "method": 4}, + ), + ): + # No EXIF/ICC arguments: outputs do not propagate source metadata. + path = destination / name + variant.save(path, format=kind, **options) + data = path.read_bytes() + variants.append( + { + "name": name, + "content_type": mime, + "size_bytes": len(data), + "width": variant.width, + "height": variant.height, + "sha256": hashlib.sha256(data).hexdigest(), + } + ) + variant.close() + if rgb is not image: + rgb.close() + return variants + + +if __name__ == "__main__": + import resource + + resource.setrlimit(resource.RLIMIT_AS, (700 * 1024**2, 700 * 1024**2)) + resource.setrlimit(resource.RLIMIT_CPU, (15, 15)) + source, destination, version = sys.argv[1:] + result = render(source, destination, int(version)) + (Path(destination) / "variants.json").write_text(json.dumps(result)) diff --git a/src/messenger/image_validation.py b/src/messenger/image_validation.py new file mode 100644 index 0000000..13c6988 --- /dev/null +++ b/src/messenger/image_validation.py @@ -0,0 +1,146 @@ +"""Short-lived bounded pixel validation; no DB, credentials or application imports.""" + +import json +import resource +import subprocess +import sys +from io import BytesIO + +from PIL import Image, UnidentifiedImageError + +from .domain import Failure + +MAX_BYTES = 10 * 1024 * 1024 +MAX_PIXELS = 40_000_000 +Image.MAX_IMAGE_PIXELS = MAX_PIXELS + + +def inspect_image(fileobj, declared_type): + if declared_type not in {"image/png", "image/jpeg"}: + raise Failure(415, "Ожидается PNG или JPEG") + try: + fileobj.seek(0) + with Image.open(fileobj) as header: + width, height = header.size + if width * height > MAX_PIXELS: + raise Failure(413, "Слишком много пикселей") + actual = {"PNG": "image/png", "JPEG": "image/jpeg"}.get(header.format) + if actual != declared_type: + raise Failure(415, "Формат изображения не соответствует MIME") + frames = getattr(header, "n_frames", 1) + default_image = bool(getattr(header, "default_image", False)) + if width * height * frames > MAX_PIXELS: + raise Failure(413, "Слишком много пикселей во всех кадрах") + header.verify() + # Drop parsed metadata before the separate strict decoder process starts. + del header + if actual == "image/png": + # verify() checks CRC, but does not compare acTL's frame count with + # every fcTL. Do not let a forged count hide a corrupt later frame. + fileobj.seek(8) + controls = frame_controls = 0 + declared_frames = None + animation_data = False + while True: + chunk_header = fileobj.read(8) + if len(chunk_header) != 8: + raise ValueError("Truncated PNG chunk") + length = int.from_bytes(chunk_header[:4], "big") + kind = chunk_header[4:] + controls += kind == b"acTL" + frame_controls += kind == b"fcTL" + animation_data |= kind == b"fdAT" + if kind == b"acTL": + if length != 8: + raise ValueError("Invalid acTL length") + declared_frames = int.from_bytes(fileobj.read(4), "big") + fileobj.seek(length, 1) # remaining payload plus CRC + else: + fileobj.seek(length + 4, 1) + if kind == b"IEND": + break + if controls: + if ( + controls != 1 + or not declared_frames + or frame_controls != declared_frames + or declared_frames + int(default_image) != frames + ): + raise ValueError("Invalid APNG frame count") + elif frame_controls or animation_data: + raise ValueError("Animation chunks without acTL") + if actual == "image/jpeg": + # Validate scan warnings before allocating Pillow's decoded canvas. + # 384 MiB covers coefficient arrays for <=40M pixels and <=4 channels; + # keeping both full decoded buffers alive could exceed the API cgroup. + fileobj.seek(0) + # A bounded compressed copy avoids sharing buffered file-descriptor + # offsets with the child, and supports BytesIO callers as well. + encoded = fileobj.read(MAX_BYTES + 1) + if len(encoded) > MAX_BYTES: + raise Failure(413, "Файл больше 10 MiB") + try: + decoded = subprocess.run( + ["djpeg", "-strict", "-maxmemory", "384m", "-outfile", "/dev/null"], + input=encoded, + stdout=subprocess.DEVNULL, + stderr=subprocess.PIPE, + timeout=4, + check=False, + ) + except subprocess.TimeoutExpired: + raise Failure(415, "Изображение не прошло ограниченную проверку") from None + finally: + del encoded + if decoded.returncode: + raise Failure(415, "Повреждённое изображение") + # djpeg has already decoded every JPEG pixel, streaming output rows. + # A second Pillow load would overlap full progressive coefficient + # arrays with a 160 MiB CMYK canvas and violate the API's 512 MiB cap. + fileobj.seek(0) + return actual, width, height + # Decode one frame at a time. Pillow may retain a previous APNG canvas + # for compositing, but no list/copies of every decoded frame is collected. + fileobj.seek(0) + with Image.open(fileobj) as image: + decoded_pixels = 0 + for frame in range(frames): + if decoded_pixels + width * height > MAX_PIXELS: + raise Failure(413, "Слишком много пикселей во всех кадрах") + image.seek(frame) + decoded_pixels += image.size[0] * image.size[1] + if decoded_pixels > MAX_PIXELS: + raise Failure(413, "Слишком много пикселей во всех кадрах") + image.load() + # Image's context manager closes its input handle, not the decoded core. + # Releasing the object frees native canvases before hashing/S3 publication. + del image + fileobj.seek(0) + return actual, width, height + except Image.DecompressionBombError: + raise Failure(413, "Слишком много пикселей") from None + except (UnidentifiedImageError, OSError, ValueError, SyntaxError, EOFError): + raise Failure(415, "Повреждённое изображение") from None + + +def main(): + resource.setrlimit(resource.RLIMIT_CORE, (0, 0)) + resource.setrlimit(resource.RLIMIT_CPU, (4, 5)) + if sys.platform == "linux": + resource.setrlimit(resource.RLIMIT_AS, (512 * 1024 * 1024, 512 * 1024 * 1024)) + try: + data = sys.stdin.buffer.read(MAX_BYTES + 1) + if len(data) > MAX_BYTES: + raise Failure(413, "Файл больше 10 MiB") + result = inspect_image(BytesIO(data), sys.argv[1]) + print(json.dumps({"ok": result})) + except Failure as exc: + print(json.dumps({"error": exc.status})) + except MemoryError: + print(json.dumps({"error": 415})) + except Exception: + print(json.dumps({"error": 415})) + + +if __name__ == "__main__": + main() diff --git a/src/messenger/jobctl.py b/src/messenger/jobctl.py new file mode 100644 index 0000000..8c9640a --- /dev/null +++ b/src/messenger/jobctl.py @@ -0,0 +1,123 @@ +"""Local operator commands; no public HTTP replay or arbitrary object paths.""" + +import argparse +import json + +from .domain import Failure +from .jobs import Jobs, fault +from .postgres import PostgresStore +from .storage import ObjectStorage +from .worker import cleanup_ready + + +def cleanup(store, storage, failed_hours=168, intent_seconds=3600): + if failed_hours < 0 or intent_seconds < 0: + raise ValueError("Retention must be nonnegative") + counts = {"ready_staging": 0, "failed_sources": 0, "orphan_intents": 0} + with store.connection() as conn: + ready = conn.execute( + "SELECT id FROM attachments WHERE status='ready' AND stage_key IS NOT NULL" + ).fetchall() + for row in ready: + cleanup_ready(store, storage, row["id"]) + counts["ready_staging"] += 1 + with store.connection() as conn: + candidates = conn.execute( + "SELECT id FROM attachments WHERE status='failed' AND updated_at= current["attempt_limit"]: + final_code = code if permanent else "retry_exhausted" + self._failed(conn, current, final_code) + else: + delay = min(30, 2 ** (current["attempt"] - 1)) + random.uniform(0, 0.5) + conn.execute( + "UPDATE attachment_jobs SET state='queued',error_code=%s,lease_until=NULL," + "available_at=now()+(%s * interval '1 second'),updated_at=now() WHERE id=%s", + (code, delay, job["id"]), + ) + conn.execute( + "UPDATE job_outbox SET published_at=NULL WHERE job_id=%s", (job["id"],) + ) + conn.execute( + "UPDATE attachments SET status='queued',updated_at=now() WHERE id=%s", + (job["attachment_id"],), + ) + self.audit(conn, job["id"], "retry_scheduled", job["attempt"]) + + def _failed(self, conn, job, code): + conn.execute( + "UPDATE attachment_jobs SET state='failed',error_code=%s,lease_until=NULL,updated_at=now() WHERE id=%s", + (code, job["id"]), + ) + conn.execute( + "UPDATE attachments SET status='failed',error_code=%s,updated_at=now() WHERE id=%s", + (code, job["attachment_id"]), + ) + conn.execute( + "INSERT INTO failed_jobs(job_id,error_code) VALUES (%s,%s) " + "ON CONFLICT(job_id) DO UPDATE SET error_code=excluded.error_code,failed_at=now()", + (job["id"], code), + ) + self.audit(conn, job["id"], "failed:" + code, job["attempt"]) + + def recover_one(self): + with self.store.connection() as conn, conn.transaction(): + candidate = conn.execute( + "SELECT a.id FROM attachments a JOIN attachment_jobs j ON j.attachment_id=a.id " + "WHERE j.state='processing' AND j.lease_until= job["attempt_limit"]: + self._failed(conn, job, "retry_exhausted") + else: + conn.execute( + "UPDATE attachment_jobs SET state='queued',lease_until=NULL,available_at=now(),updated_at=now() WHERE id=%s", + (job["id"],), + ) + conn.execute( + "UPDATE attachments SET status='queued',updated_at=now() WHERE id=%s", + (job["attachment_id"],), + ) + conn.execute( + "UPDATE job_outbox SET published_at=NULL WHERE job_id=%s", (job["id"],) + ) + self.audit(conn, job["id"], "lease_recovered", job["attempt"]) + return True + + def replay(self, attachment_id, storage): + with self.store.connection() as conn, conn.transaction(): + a = conn.execute( + "SELECT * FROM attachments WHERE id=%s FOR UPDATE", (attachment_id,) + ).fetchone() + if not a or a["status"] != "failed": + raise Failure(409, "Повтор разрешён только для failed") + job = conn.execute( + "SELECT * FROM attachment_jobs WHERE attachment_id=%s AND pipeline_version=%s FOR UPDATE", + (attachment_id, a["pipeline_version"]), + ).fetchone() + if not job["source_key"] or not storage.exists(job["source_key"]): + raise Failure(409, "Источник больше недоступен") + fault(self.store, "replay_before_commit", attachment_id) + conn.execute( + "UPDATE attachment_jobs SET state='queued',attempt_limit=attempt+%s,available_at=now(),error_code=NULL,updated_at=now() WHERE id=%s", + (self.attempt_limit, job["id"]), + ) + conn.execute( + "UPDATE attachments SET status='queued',error_code=NULL,updated_at=now() WHERE id=%s", + (attachment_id,), + ) + conn.execute("UPDATE job_outbox SET published_at=NULL WHERE job_id=%s", (job["id"],)) + conn.execute( + "UPDATE failed_jobs SET replay_count=replay_count+1 WHERE job_id=%s", (job["id"],) + ) + self.audit(conn, job["id"], "operator_replay", job["attempt"]) + return str(job["id"]) + + def reprocess(self, attachment_id, version, storage): + if version not in (1, 2): + raise Failure(400, "Поддерживаются версии pipeline 1 и 2") + with self.store.connection() as conn, conn.transaction(): + a = conn.execute( + "SELECT * FROM attachments WHERE id=%s FOR UPDATE", (attachment_id,) + ).fetchone() + if not a: + raise Failure(404, "Вложение отсутствует") + if version <= a["pipeline_version"]: + raise Failure(409, "Нужна более новая версия pipeline") + source = a["object_key"] if a["status"] == "ready" else a["stage_key"] + if not source or not storage.exists(source): + raise Failure(409, "Источник больше недоступен") + if a["status"] == "ready" and a["stage_key"] and a["stage_key"].startswith("staging/"): + # A worker can be paused after publishing ready but before its + # staging cleanup. Do not orphan that key when choosing final v1 + # as the new source. Delete stays under the same attachment lock; + # a storage failure leaves the ready version unchanged. + fault(self.store, "reprocess_before_staging_delete", attachment_id) + storage.delete(a["stage_key"]) + conn.execute( + "UPDATE attachment_jobs SET state='superseded',updated_at=now() WHERE attachment_id=%s AND state IN ('queued','processing','failed')", + (attachment_id,), + ) + conn.execute( + "UPDATE attachments SET pipeline_version=%s,status='queued',variants='[]',error_code=NULL,stage_key=%s,updated_at=now() WHERE id=%s", + (version, source, attachment_id), + ) + return self.enqueue(conn, attachment_id, source, version) diff --git a/src/messenger/kdf_probe.py b/src/messenger/kdf_probe.py new file mode 100644 index 0000000..e54a6d0 --- /dev/null +++ b/src/messenger/kdf_probe.py @@ -0,0 +1,49 @@ +"""Measure configured Argon2 costs without keeping passwords or hashes in evidence.""" + +import json +import resource +import statistics +import time +from concurrent.futures import ThreadPoolExecutor + +from argon2 import PasswordHasher + + +def main(): + kdf = PasswordHasher(time_cost=2, memory_cost=65536, parallelism=1) + samples = [] + for _ in range(7): + start = time.perf_counter() + digest = kdf.hash("synthetic-measurement-password") + kdf.verify(digest, "synthetic-measurement-password") + samples.append((time.perf_counter() - start) * 1000) + + def one(_): + start = time.perf_counter() + kdf.hash("synthetic-parallel-password") + return (time.perf_counter() - start) * 1000 + + with ThreadPoolExecutor(max_workers=2) as pool: + parallel = list(pool.map(one, range(4))) + print( + json.dumps( + { + "algorithm": "argon2id", + "memory_kib": 65536, + "time_cost": 2, + "parallelism": 1, + "runs_hash_plus_verify_ms": samples, + "median_hash_plus_verify_ms": statistics.median(samples), + "max_hash_plus_verify_ms": max(samples), + "two_concurrent_hash_ms": parallel, + "process_peak_rss_kib": resource.getrusage(resource.RUSAGE_SELF).ru_maxrss, + "kdf_slots_per_api": 2, + "api_replicas": 2, + "maximum_active_kdf_memory_mib": 256, + } + ) + ) + + +if __name__ == "__main__": + main() diff --git a/src/messenger/migrate.py b/src/messenger/migrate.py new file mode 100644 index 0000000..f448688 --- /dev/null +++ b/src/messenger/migrate.py @@ -0,0 +1,32 @@ +import hashlib +from pathlib import Path + +import psycopg + +from .config import secret + + +def migrate(): + with psycopg.connect(secret("DATABASE_URL")) as conn: + # Serialize independent migration processes without changing application data. + conn.execute("SELECT pg_advisory_xact_lock(2301002)") + conn.execute( + "CREATE TABLE IF NOT EXISTS schema_migrations " + "(name text PRIMARY KEY, checksum text NOT NULL)" + ) + for path in sorted(Path("migrations").glob("*.sql")): + checksum = hashlib.sha256(path.read_bytes()).hexdigest() + old = conn.execute( + "SELECT checksum FROM schema_migrations WHERE name=%s", (path.name,) + ).fetchone() + if old: + if old[0] != checksum: + raise RuntimeError("Изменена применённая миграция: " + path.name) + continue + conn.execute(path.read_text()) + conn.execute("INSERT INTO schema_migrations VALUES (%s,%s)", (path.name, checksum)) + print("Applied", path.name) + + +if __name__ == "__main__": + migrate() diff --git a/src/messenger/models.py b/src/messenger/models.py new file mode 100644 index 0000000..78ff4e1 --- /dev/null +++ b/src/messenger/models.py @@ -0,0 +1,71 @@ +import re +from uuid import UUID + +from pydantic import BaseModel, ConfigDict, Field, StrictStr, field_validator, model_validator + + +class RequestModel(BaseModel): + model_config = ConfigDict(extra="forbid") + + @field_validator("*", mode="after") + @classmethod + def nonblank(cls, value): + if isinstance(value, str): + value.encode("utf-8") + if isinstance(value, str) and not value.strip(): + raise ValueError("Строка не может состоять из пробелов") + return value + + +class CreateUser(RequestModel): + username: StrictStr = Field(pattern=r"^[a-z0-9_]{3,32}$") + display_name: StrictStr = Field(min_length=1, max_length=100) + password: StrictStr = Field(min_length=12, max_length=128) + + @field_validator("username") + @classmethod + def full_username(cls, value): + if not re.fullmatch(r"[a-z0-9_]{3,32}", value): + raise ValueError("Неверное имя пользователя") + return value + + +class CreateChat(RequestModel): + title: StrictStr = Field(min_length=1, max_length=100) + member_ids: list[UUID] = Field(min_length=1, max_length=100) + + @field_validator("member_ids", mode="before") + @classmethod + def string_ids(cls, value): + if not isinstance(value, list) or any(not isinstance(x, str) for x in value): + raise ValueError("Ожидается массив UUID-строк") + return value + + @field_validator("member_ids") + @classmethod + def unique_ids(cls, value): + if len(set(value)) != len(value): + raise ValueError("Участники не должны повторяться") + return value + + +class CreateMessage(BaseModel): + model_config = ConfigDict(extra="forbid") + text: StrictStr = Field(max_length=4000) + attachment_ids: list[UUID] = Field(default_factory=list, max_length=10) + + @field_validator("attachment_ids", mode="before") + @classmethod + def string_ids(cls, value): + if not isinstance(value, list) or any(not isinstance(x, str) for x in value): + raise ValueError("Ожидается массив UUID-строк") + return value + + @model_validator(mode="after") + def content(self): + self.text.encode("utf-8") + if len(set(self.attachment_ids)) != len(self.attachment_ids): + raise ValueError("Вложения не должны повторяться") + if not self.text.strip() and not self.attachment_ids: + raise ValueError("Пустое сообщение без вложений") + return self diff --git a/src/messenger/postgres.py b/src/messenger/postgres.py new file mode 100644 index 0000000..3a5f8d6 --- /dev/null +++ b/src/messenger/postgres.py @@ -0,0 +1,365 @@ +import hashlib +import json +import logging +import os +import secrets +from contextlib import contextmanager +from datetime import UTC, datetime, timedelta +from threading import BoundedSemaphore +from uuid import UUID, uuid4 + +import psycopg +import redis +from argon2 import PasswordHasher +from argon2.exceptions import VerificationError +from psycopg.rows import dict_row +from psycopg_pool import ConnectionPool, PoolTimeout, TooManyRequests + +from .config import secret +from .domain import Failure, timestamp +from .secrets_provider import refresh +from .telemetry import operation + +logger = logging.getLogger("messenger") +KDF_SLOTS = BoundedSemaphore(2) +KDF = PasswordHasher(time_cost=2, memory_cost=65536, parallelism=1) +DUMMY_HASH = KDF.hash("invalid-user-dummy-password") + + +class DeadlineConnection(psycopg.Connection): + def wait(self, gen, interval=0.1, timeout=None): + try: + return super().wait(gen, interval=interval, timeout=timeout or 3.0) + except psycopg.errors._WaitTimeout: + # A paused server cannot complete cancellation. Discard an uncertain + # connection instead of returning it to the pool or waiting forever. + self.pgconn.finish() + raise + + +def public(row): + return { + k: ( + str(v) + if isinstance(v, UUID) + else v.astimezone(UTC).isoformat(timespec="microseconds").replace("+00:00", "Z") + if isinstance(v, datetime) + else bytes(v).decode("utf-8") + if isinstance(v, (bytes, memoryview)) + else v + ) + for k, v in row.items() + if k not in {"password_hash", "token_digest"} + } + + +class PostgresStore: + def __init__(self): + self.pool = ConnectionPool( + secret("DATABASE_URL"), + connection_class=DeadlineConnection, + min_size=1, + max_size=int(os.getenv("POOL_MAX_SIZE", "8")), + timeout=2, + max_waiting=32, + kwargs={ + "autocommit": True, + "row_factory": dict_row, + "connect_timeout": 2, + "options": "-c statement_timeout=2500 -c lock_timeout=1500", + }, + check=ConnectionPool.check_connection, + ) + self.pool.wait(timeout=15) + self.cache = redis.Redis.from_url( + secret("CACHE_URL"), + socket_connect_timeout=0.2, + socket_timeout=0.2, + decode_responses=True, + ) + self.ttl = int(os.getenv("SESSION_TTL_SECONDS", "3600")) + if self.ttl < 1: + raise RuntimeError("SESSION_TTL_SECONDS должен быть положительным") + + @contextmanager + def connection(self): + refresh() + try: + with operation("postgres.transaction", {"db.system.name": "postgresql"}): + with self.pool.connection() as conn: + yield conn + except ( + psycopg.OperationalError, + psycopg.InterfaceError, + PoolTimeout, + TooManyRequests, + psycopg.errors.QueryCanceled, + psycopg.errors.LockNotAvailable, + ): + raise Failure(503, "Хранилище временно недоступно") from None + + def close(self): + self.cache.close() + self.pool.close() + + def ready(self): + try: + with self.connection() as conn: + conn.execute( + "SELECT u.id,u.password_hash,c.id,m.chat_id,msg.id,s.token_digest,r.key," + "a.id,a.stage_key,a.pipeline_version,a.variants,ma.attachment_id,ui.object_key," + "j.id,j.source_key,j.attempt_limit,j.lease_until,j.traceparent,j.tracestate,j.accepted_at,o.job_id,o.published_at," + "audit.job_id,f.error_code FROM users u,chats c,members m,messages msg," + "sessions s,message_requests r,attachments a,message_attachments ma," + "upload_intents ui,attachment_jobs j,job_outbox o,job_audit audit,failed_jobs f " + "WHERE false" + ) + return True + except (Failure, psycopg.Error): + return False + + def _cached_user(self, uid): + key = "user:v1:" + uid + try: + value = self.cache.get(key) + if value: + cached = json.loads(value) + if ( + isinstance(cached, dict) + and cached.get("id") == uid + and set(cached) == {"id", "username", "display_name", "created_at"} + ): + return cached + except (redis.RedisError, ValueError, TypeError): + logger.warning(json.dumps({"event": "cache_bypass"})) + user = self.user(uid) + if user: + try: + self.cache.setex(key, 60, json.dumps(user)) + except redis.RedisError: + logger.warning(json.dumps({"event": "cache_bypass"})) + return user + + def user(self, uid): + with self.connection() as conn: + row = conn.execute( + "SELECT id,username,display_name,created_at FROM users WHERE id=%s", (uid,) + ).fetchone() + return public(row) if row else None + + def register(self, data): + with KDF_SLOTS: + hashed = KDF.hash(data.pop("password")) + uid = str(uuid4()) + try: + with self.connection() as conn: + row = conn.execute( + "INSERT INTO users VALUES (%s,%s,%s,%s,%s) " + "RETURNING id,username,display_name,created_at", + ( + uid, + data["username"], + data["display_name"].encode("utf-8"), + hashed, + timestamp(), + ), + ).fetchone() + return public(row) + except psycopg.errors.UniqueViolation: + raise Failure(409, "Имя пользователя занято") from None + + def login(self, username, password): + self.login_budget(username) + with self.connection() as conn: + row = conn.execute("SELECT * FROM users WHERE username=%s", (username,)).fetchone() + try: + if not KDF_SLOTS.acquire(blocking=False): + raise Failure(429, "Слишком много попыток входа", {"Retry-After": "1"}) + try: + KDF.verify(row["password_hash"] if row else DUMMY_HASH, password) + finally: + KDF_SLOTS.release() + except VerificationError: + return None + if row is None: + return None + if KDF.check_needs_rehash(row["password_hash"]): + with KDF_SLOTS: + upgraded = KDF.hash(password) + with self.connection() as conn: + conn.execute( + "UPDATE users SET password_hash=%s WHERE id=%s AND password_hash=%s", + (upgraded, row["id"], row["password_hash"]), + ) + token = secrets.token_urlsafe(32) + digest = hashlib.sha256(token.encode()).hexdigest() + expires = datetime.now(UTC) + timedelta(seconds=self.ttl) + with self.connection() as conn: + conn.execute("INSERT INTO sessions VALUES (%s,%s,%s)", (digest, row["id"], expires)) + return { + "token": token, + "token_type": "Bearer", + "expires_at": public({"v": expires})["v"], + "user": public(row), + } + + def login_budget(self, username): + key = hashlib.sha256(username.encode("utf-8")).hexdigest() + with self.connection() as conn, conn.transaction(): + # Shared PostgreSQL window, serialized across both API replicas. + conn.execute("SELECT pg_advisory_xact_lock(2301007)") + conn.execute("DELETE FROM login_windows WHERE window_start maximum: + raise Failure(429, "Слишком много попыток входа", {"Retry-After": "10"}) + + def authenticate(self, token): + if not token or len(token) > 512: + return None + digest = hashlib.sha256(token.encode()).hexdigest() + # Session validity always comes from PostgreSQL, including on a cache hit. + with self.connection() as conn: + row = conn.execute( + "SELECT s.user_id FROM sessions s WHERE s.token_digest=%s AND s.expires_at>now()", + (digest,), + ).fetchone() + return self._cached_user(str(row["user_id"])) if row else None + + def logout(self, token): + with self.connection() as conn: + row = conn.execute( + "DELETE FROM sessions WHERE token_digest=%s AND expires_at>now() RETURNING user_id", + (hashlib.sha256(token.encode()).hexdigest(),), + ).fetchone() + return row is not None + + def create_chat(self, actor, data): + if actor not in data["member_ids"]: + raise Failure(400, "Вызывающий должен входить в чат") + cid = str(uuid4()) + try: + with self.connection() as conn, conn.transaction(): + row = conn.execute( + "INSERT INTO chats VALUES (%s,%s,%s) RETURNING *", + (cid, data["title"].encode("utf-8"), timestamp()), + ).fetchone() + for index, uid in enumerate(data["member_ids"]): + conn.execute("INSERT INTO members VALUES (%s,%s,%s)", (cid, uid, index)) + return {**public(row), "member_ids": data["member_ids"]} + except psycopg.errors.ForeignKeyViolation: + raise Failure(400, "Неизвестный участник") from None + + @staticmethod + def _chat(conn, actor, cid): + row = conn.execute( + "SELECT c.* FROM chats c JOIN members m ON m.chat_id=c.id " + "WHERE c.id=%s AND m.user_id=%s", + (cid, actor), + ).fetchone() + if row is None: + raise Failure(404, "Объект не найден") + members = conn.execute( + "SELECT user_id FROM members WHERE chat_id=%s ORDER BY position", (cid,) + ).fetchall() + return {**public(row), "member_ids": [str(m["user_id"]) for m in members]} + + def chat(self, actor, cid): + with self.connection() as conn: + return self._chat(conn, actor, cid) + + def list_chats(self, actor, after, limit): + with self.connection() as conn: + sql = "SELECT c.* FROM chats c JOIN members m ON m.chat_id=c.id WHERE m.user_id=%s" + params = [actor] + if after: + sql += " AND (c.created_at,c.id)>(%s,%s)" + params.extend(after) + sql += " ORDER BY c.created_at,c.id LIMIT %s" + params.append(limit + 1) + rows = conn.execute(sql, params).fetchall() + return [self._chat(conn, actor, str(row["id"])) for row in rows] + + def send(self, actor, cid, text, key, attachment_ids=None): + attachment_ids = attachment_ids or [] + body_digest = hashlib.sha256( + json.dumps( + {"text": text, "attachment_ids": attachment_ids}, + sort_keys=True, + ensure_ascii=False, + separators=(",", ":"), + ).encode() + ).hexdigest() + with self.connection() as conn, conn.transaction(): + self._chat(conn, actor, cid) + # Serializes exactly this semantic key across all API processes. Hash + # collisions can only serialize unrelated requests, never mix results. + scope = json.dumps([actor, "POST", cid, key], separators=(",", ":")) + lock = int.from_bytes(hashlib.sha256(scope.encode()).digest()[:8], "big", signed=True) + conn.execute("SELECT pg_advisory_xact_lock(%s)", (lock,)) + old = conn.execute( + "SELECT body_digest,response FROM message_requests " + "WHERE actor_id=%s AND chat_id=%s AND key=%s AND expires_at>now()", + (actor, cid, key), + ).fetchone() + if old: + if old["body_digest"] != body_digest: + raise Failure(409, "Ключ уже использован для другого сообщения") + return json.loads(bytes(old["response"])) + conn.execute( + "DELETE FROM message_requests WHERE actor_id=%s AND chat_id=%s AND key=%s", + (actor, cid, key), + ) + for aid in attachment_ids: + attachment = conn.execute( + "SELECT id,status FROM attachments WHERE id=%s AND chat_id=%s FOR SHARE", + (aid, cid), + ).fetchone() + if not attachment: + raise Failure(404, "Объект не найден") + if attachment["status"] == "failed": + raise Failure(409, "Вложение недоступно") + row = conn.execute( + "INSERT INTO messages VALUES (%s,%s,%s,%s,%s) RETURNING *", + (str(uuid4()), cid, actor, text.encode("utf-8"), timestamp()), + ).fetchone() + for position, aid in enumerate(attachment_ids): + conn.execute( + "INSERT INTO message_attachments VALUES (%s,%s,%s)", (row["id"], aid, position) + ) + response = {**public(row), "attachment_ids": attachment_ids} + conn.execute( + "INSERT INTO message_requests(actor_id,chat_id,key,body_digest,response,expires_at) " + "VALUES (%s,%s,%s,%s,%s,now()+interval '24 hours')", + (actor, cid, key, body_digest, json.dumps(response).encode("utf-8")), + ) + return response + + def history(self, actor, cid, after, limit): + with self.connection() as conn: + self._chat(conn, actor, cid) + sql = "SELECT * FROM messages WHERE chat_id=%s" + params = [cid] + if after: + sql += " AND (created_at,id)>(%s,%s)" + params.extend(after) + sql += " ORDER BY created_at,id LIMIT %s" + params.append(limit + 1) + result = [] + for row in conn.execute(sql, params).fetchall(): + attachments = conn.execute( + "SELECT attachment_id FROM message_attachments WHERE message_id=%s ORDER BY position", + (row["id"],), + ).fetchall() + result.append( + { + **public(row), + "attachment_ids": [str(a["attachment_id"]) for a in attachments], + } + ) + return result diff --git a/src/messenger/revoked_probe.py b/src/messenger/revoked_probe.py new file mode 100644 index 0000000..eb9a99f --- /dev/null +++ b/src/messenger/revoked_probe.py @@ -0,0 +1,60 @@ +"""Fresh connections with deliberately revoked worker material; no fallback.""" + +import json +import ssl +import urllib.error +import urllib.request +from pathlib import Path + +import psycopg +import redis + + +def main(): + old = json.loads(Path("/run/old-worker/material.json").read_text()) + checks = {} + try: + conn = psycopg.connect(old["DATABASE_URL"], connect_timeout=2) + conn.close() + checks["old_database_password_denied"] = False + except psycopg.OperationalError: + checks["old_database_password_denied"] = True + url = old["BROKER_URL"].replace("/run/tls/identity/", "/run/old-worker/") + broker = redis.Redis.from_url(url, socket_connect_timeout=2, socket_timeout=2) + try: + broker.ping() + checks["old_broker_client_certificate_denied"] = False + except redis.RedisError: + checks["old_broker_client_certificate_denied"] = True + finally: + broker.close() + ctx = ssl.create_default_context(cafile="/run/tls/ca.pem") + ctx.load_cert_chain("/run/old-worker/cert.pem", "/run/old-worker/key.pem") + for name, url, body in ( + ("old_s3_certificate_denied", "https://storage:8443/messenger/staging/probe", None), + ( + "old_bao_certificate_auth_denied", + "https://openbao:8200/v1/auth/cert/login", + b'{"name":"worker"}', + ), + ): + try: + with urllib.request.urlopen( + urllib.request.Request( + url, data=body, headers={"Content-Type": "application/json"} + ), + context=ctx, + timeout=3, + ): + checks[name] = False + except urllib.error.HTTPError as exc: + checks[name] = exc.code in {400, 403} + except (OSError, urllib.error.URLError): + checks[name] = True + print(json.dumps({"checks": checks, "passed": all(checks.values())})) + if not all(checks.values()): + raise SystemExit(1) + + +if __name__ == "__main__": + main() diff --git a/src/messenger/secrets_provider.py b/src/messenger/secrets_provider.py new file mode 100644 index 0000000..df9940c --- /dev/null +++ b/src/messenger/secrets_provider.py @@ -0,0 +1,59 @@ +"""Short-lived OpenBao certificate authentication; no root token or SecretID in app.""" + +import json +import os +import ssl +import threading +import time +import urllib.error +import urllib.request + +from .domain import Failure + +_lock = threading.Lock() +_values = {} +_valid_until = 0.0 + + +def request(path, *, data=None, token=None): + context = ssl.create_default_context(cafile=os.getenv("BAO_CA_FILE", "/run/tls/ca.pem")) + context.load_cert_chain("/run/tls/identity/cert.pem", "/run/tls/identity/key.pem") + headers = {"Content-Type": "application/json"} + if token: + headers["X-Vault-Token"] = token + payload = json.dumps(data).encode() if data is not None else None + req = urllib.request.Request( + os.environ["BAO_ADDR"] + "/v1/" + path, data=payload, headers=headers + ) + with urllib.request.urlopen(req, context=context, timeout=2) as response: + return json.load(response) + + +def refresh(): + global _values, _valid_until + if not os.getenv("BAO_ROLE"): + return + with _lock: + if time.monotonic() < _valid_until: + return + try: + role = os.environ["BAO_ROLE"] + auth = request("auth/cert/login", data={"name": role})["auth"] + values = request("secret/data/services/" + role, token=auth["client_token"])["data"][ + "data" + ] + # Never keep credentials usable beyond the auth token's short lease. + _values = values + _valid_until = time.monotonic() + min(float(auth["lease_duration"]), 30) - 1 + except (OSError, ValueError, KeyError, urllib.error.URLError): + _values = {} + _valid_until = 0 + raise Failure(503, "Сервис секретов временно недоступен") from None + + +def value(name): + refresh() + try: + return _values[name] + except KeyError: + raise RuntimeError("Scoped secret unavailable: " + name) from None diff --git a/src/messenger/secure_entry.py b/src/messenger/secure_entry.py new file mode 100644 index 0000000..1cc80f5 --- /dev/null +++ b/src/messenger/secure_entry.py @@ -0,0 +1,35 @@ +"""Run API TLS boundary and loopback business server in one namespace.""" + +import os +import signal +import subprocess +import sys +import time + + +def main(): + children = [subprocess.Popen([sys.executable, "-m", "messenger.tls_gateway"])] + env = dict(os.environ, APP_HOST="127.0.0.1") + children.append(subprocess.Popen([sys.executable, "-m", "messenger"], env=env)) + + def stop(*_): + for child in children: + child.terminate() + + signal.signal(signal.SIGTERM, stop) + signal.signal(signal.SIGINT, stop) + try: + while all(child.poll() is None for child in children): + time.sleep(0.2) + finally: + stop() + for child in children: + try: + child.wait(timeout=6) + except subprocess.TimeoutExpired: + child.kill() + child.wait() + + +if __name__ == "__main__": + main() diff --git a/src/messenger/security_probe.py b/src/messenger/security_probe.py new file mode 100644 index 0000000..bcfbd63 --- /dev/null +++ b/src/messenger/security_probe.py @@ -0,0 +1,108 @@ +"""Read-only/rollback permission probes plus disposable synthetic prefix objects.""" + +import io +import json +import os +import socket + +import psycopg +import redis + +from .domain import Failure +from .jobs import STREAM, broker_client +from .postgres import PostgresStore +from .secrets_provider import request +from .storage import ObjectStorage + + +def denied(action): + try: + action() + except (psycopg.errors.InsufficientPrivilege, redis.ResponseError, Failure): + return True + return False + + +def main(): + checks = {} + store = PostgresStore() + broker = broker_client() + storage = ObjectStorage() + try: + with store.connection() as conn: + checks["db_identity_worker"] = ( + conn.execute("SELECT current_user AS role").fetchone()["role"] == "worker" + ) + checks["db_business_users_denied"] = denied( + lambda: conn.execute("SELECT password_hash FROM users LIMIT 0") + ) + checks["db_business_messages_denied"] = denied( + lambda: conn.execute("SELECT text FROM messages LIMIT 0") + ) + checks["db_create_denied"] = denied( + lambda: conn.execute("CREATE TABLE security_forbidden(id int)") + ) + checks["db_owner_mutation_denied"] = denied( + lambda: conn.execute("UPDATE attachments SET owner_id=owner_id WHERE false") + ) + checks["db_job_read_allowed"] = ( + conn.execute("SELECT count(*) AS n FROM attachment_jobs").fetchone()["n"] >= 0 + ) + checks["broker_ping_allowed"] = broker.ping() + checks["broker_acl_admin_denied"] = denied(lambda: broker.acl_list()) + checks["broker_publish_denied"] = denied(lambda: broker.xadd(STREAM, {"body": "forbidden"})) + checks["broker_wrong_stream_denied"] = denied(lambda: broker.xlen("other-stream")) + checks["broker_group_destroy_denied"] = denied( + lambda: broker.xgroup_destroy(STREAM, "nonexistent-security-probe") + ) + key = "attachments/security-probe/v1/original" + storage.put(key, io.BytesIO(b"synthetic"), 9, "application/octet-stream") + checks["s3_results_prefix_write_allowed"] = storage.head(key)["ContentLength"] == 9 + checks["s3_staging_write_denied"] = denied( + lambda: storage.put("staging/security-forbidden", io.BytesIO(b"x"), 1, "text/plain") + ) + checks["s3_private_prefix_read_denied"] = denied( + lambda: storage.get("private/security-probe") + ) + auth = request("auth/cert/login", data={"name": "worker"})["auth"]["client_token"] + checks["bao_own_path_allowed"] = bool( + request("secret/data/services/worker", token=auth)["data"]["data"] + ) + import urllib.error + + for name, path, data in ( + ("bao_other_path_denied", "secret/data/services/api", None), + ("bao_policy_write_denied", "sys/policies/acl/forbidden", {"policy": ""}), + ): + try: + request(path, data=data, token=auth) + checks[name] = False + except urllib.error.HTTPError as exc: + checks[name] = exc.code == 403 + for host, port in ( + ("storage", 8333), + ("storage", 9333), + ("storage", 8888), + ("broker", 6379), + ("cache", 6379), + ("api", 8080), + ): + try: + with socket.create_connection((host, port), 1): + checks[f"no_plaintext_bypass_{host}_{port}"] = False + except OSError: + checks[f"no_plaintext_bypass_{host}_{port}"] = True + checks["worker_image_has_no_root_token"] = not os.path.exists( + "/operator-private/root-token" + ) + print(json.dumps({"checks": checks, "passed": all(checks.values())}, sort_keys=True)) + if not all(checks.values()): + raise SystemExit(1) + finally: + storage.close() + broker.close() + store.close() + + +if __name__ == "__main__": + main() diff --git a/src/messenger/storage.py b/src/messenger/storage.py new file mode 100644 index 0000000..5722e43 --- /dev/null +++ b/src/messenger/storage.py @@ -0,0 +1,106 @@ +"""Private S3 access with bounded network waits; never expose storage keys in API.""" + +import os +from contextlib import contextmanager + +import boto3 +from botocore.config import Config +from botocore.exceptions import BotoCoreError, ClientError + +from .config import secret +from .domain import Failure +from .secrets_provider import refresh +from .telemetry import operation + + +class ObjectStorage: + def __init__(self, admin=False): + self.bucket = os.getenv("S3_BUCKET", "messenger") + prefix = "S3_ADMIN" if admin else "S3" + self.client = boto3.client( + "s3", + endpoint_url=os.getenv("S3_ENDPOINT", "http://s3:8333"), + aws_access_key_id=secret(prefix + "_ACCESS_KEY"), + aws_secret_access_key=secret(prefix + "_SECRET_KEY"), + region_name="us-east-1", + verify=os.getenv("S3_CA_FILE", "/run/tls/ca.pem"), + config=Config( + client_cert=("/run/tls/identity/cert.pem", "/run/tls/identity/key.pem"), + connect_timeout=1, + read_timeout=2, + retries={"total_max_attempts": 1}, + s3={"addressing_style": "path"}, + request_checksum_calculation="when_required", + response_checksum_validation="when_required", + ), + ) + + @contextmanager + def boundary(self): + refresh() + try: + with operation("s3.request", {"rpc.system": "aws-api", "rpc.service": "S3"}): + yield + except (BotoCoreError, ClientError): + raise Failure(503, "Хранилище файлов временно недоступно") from None + + def put(self, key, fileobj, size, content_type): + fileobj.seek(0) + with self.boundary(): + self.client.put_object( + Bucket=self.bucket, + Key=key, + Body=fileobj, + ContentLength=size, + ContentType=content_type, + ) + + def get(self, key): + refresh() + try: + with operation("s3.get", {"rpc.system": "aws-api", "rpc.service": "S3"}): + return self.client.get_object(Bucket=self.bucket, Key=key) + except ClientError as exc: + if exc.response.get("Error", {}).get("Code") in {"NoSuchKey", "404"}: + raise Failure(404, "Объект не найден") from None + raise Failure(503, "Хранилище файлов временно недоступно") from None + except BotoCoreError: + raise Failure(503, "Хранилище файлов временно недоступно") from None + + def head(self, key): + refresh() + try: + with operation("s3.head", {"rpc.system": "aws-api", "rpc.service": "S3"}): + return self.client.head_object(Bucket=self.bucket, Key=key) + except ClientError as exc: + if exc.response.get("Error", {}).get("Code") in {"NoSuchKey", "404", "NotFound"}: + return None + raise Failure(503, "Хранилище файлов временно недоступно") from None + except BotoCoreError: + raise Failure(503, "Хранилище файлов временно недоступно") from None + + def exists(self, key): + return self.head(key) is not None + + def delete(self, key): + with self.boundary(): + self.client.delete_object(Bucket=self.bucket, Key=key) + + def objects(self, page_size=100): + with self.boundary(): + paginator = self.client.get_paginator("list_objects_v2") + for page in paginator.paginate( + Bucket=self.bucket, PaginationConfig={"PageSize": page_size} + ): + yield from page.get("Contents", []) + + def ready(self): + try: + with self.boundary(): + self.client.head_bucket(Bucket=self.bucket) + return True + except Failure: + return False + + def close(self): + self.client.close() diff --git a/src/messenger/storage_bootstrap.py b/src/messenger/storage_bootstrap.py new file mode 100644 index 0000000..34d10e6 --- /dev/null +++ b/src/messenger/storage_bootstrap.py @@ -0,0 +1,30 @@ +"""Idempotent private bucket bootstrap; this process alone receives admin keys.""" + +import time + +from botocore.exceptions import BotoCoreError, ClientError + +from .storage import ObjectStorage + + +def main(): + storage = ObjectStorage(admin=True) + for attempt in range(30): + try: + try: + storage.client.head_bucket(Bucket=storage.bucket) + except ClientError as exc: + if exc.response["Error"]["Code"] not in {"404", "NoSuchBucket", "NotFound"}: + raise + storage.client.create_bucket(Bucket=storage.bucket) + print("Private bucket ready; anonymous identity is not configured.") + storage.close() + return + except (ClientError, BotoCoreError): + if attempt == 29: + raise RuntimeError("S3 bootstrap timeout") from None + time.sleep(1) + + +if __name__ == "__main__": + main() diff --git a/src/messenger/telemetry.py b/src/messenger/telemetry.py new file mode 100644 index 0000000..c8ad334 --- /dev/null +++ b/src/messenger/telemetry.py @@ -0,0 +1,357 @@ +"""Bounded OTLP telemetry; technical attributes only, no payload/credential capture.""" + +import json +import logging +import os +import threading +from contextlib import contextmanager +from datetime import UTC, datetime +from uuid import uuid4 + +import psutil +import requests +from opentelemetry import metrics, propagate, trace +from opentelemetry._logs import set_logger_provider +from opentelemetry.exporter.otlp.proto.http._log_exporter import OTLPLogExporter +from opentelemetry.exporter.otlp.proto.http.metric_exporter import OTLPMetricExporter +from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter +from opentelemetry.sdk._logs import LoggerProvider, LoggingHandler +from opentelemetry.sdk._logs.export import BatchLogRecordProcessor +from opentelemetry.sdk.metrics import MeterProvider +from opentelemetry.sdk.metrics.export import PeriodicExportingMetricReader +from opentelemetry.sdk.metrics.view import ExplicitBucketHistogramAggregation, View +from opentelemetry.sdk.resources import Resource +from opentelemetry.sdk.trace import SpanProcessor, TracerProvider +from opentelemetry.sdk.trace.export import BatchSpanProcessor, SpanExportResult +from opentelemetry.sdk.trace.sampling import ParentBased, TraceIdRatioBased +from opentelemetry.trace import SpanKind, Status, StatusCode + +HTTP_BUCKETS = (0.001, 0.0025, 0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10) +JOB_BUCKETS = (0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10, 20, 45, 60, 120) +INSTANCE_ID = str(uuid4()) +_runtime = None + + +class Accounting(dict): + def __init__(self, keys): + super().__init__((key, 0) for key in keys) + self.lock = threading.Lock() + + def add(self, key, value): + with self.lock: + self[key] += value + + def snapshot(self): + with self.lock: + return dict(self) + + +class RecordedSpans(SpanProcessor): + def __init__(self, stats): + self.stats = stats + + def on_start(self, span, parent_context=None): + pass + + def on_end(self, span): + if span.context.trace_flags.sampled: + self.stats.add("spans_recorded", 1) + + +class CountingSession(requests.Session): + """Count actual protobuf HTTP sends, including transport retries, without retaining data.""" + + def __init__(self, stats, signal): + super().__init__() + self.stats, self.signal = stats, signal + + def send(self, request, **kwargs): + self.stats.add(self.signal + "_wire_bytes", len(request.body or b"")) + self.stats.add(self.signal + "_http_sends", 1) + return super().send(request, **kwargs) + + +class ObservedSpanExporter(OTLPSpanExporter): + def __init__(self, stats, **kwargs): + self.stats = stats + super().__init__(**kwargs) + + def export(self, spans): + self.stats.add("spans_in_flight", len(spans)) + try: + result = super().export(spans) + key = "spans_exported" if result == SpanExportResult.SUCCESS else "spans_export_failed" + self.stats.add(key, len(spans)) + return result + except Exception: + self.stats.add("spans_export_failed", len(spans)) + raise + finally: + self.stats.add("spans_in_flight", -len(spans)) + + +class TechnicalLogs(logging.Filter): + def filter(self, record): + return record.name.startswith("messenger") + + +class JsonFormatter(logging.Formatter): + def format(self, record): + try: + event = json.loads(record.getMessage()) + if not isinstance(event, dict): + event = {"event": "application_event"} + except ValueError: + event = {"event": "application_event"} + context = trace.get_current_span().get_span_context() + return json.dumps( + { + **event, + "timestamp": datetime.now(UTC).isoformat(), + "severity": record.levelname, + "service.name": os.getenv("OTEL_SERVICE_NAME", "messenger-api"), + "trace_id": format(context.trace_id, "032x") if context.is_valid else None, + "span_id": format(context.span_id, "016x") if context.is_valid else None, + } + ) + + +class Telemetry: + def __init__(self, service): + self.service = service + self.enabled = os.getenv("OTEL_ENABLED", "1") == "1" + self.busy = 0 + self.providers = [] + self.export_stats = Accounting( + ( + "spans_recorded", + "spans_in_flight", + "spans_exported", + "spans_export_failed", + "traces_wire_bytes", + "traces_http_sends", + "metrics_wire_bytes", + "metrics_http_sends", + "logs_wire_bytes", + "logs_http_sends", + ) + ) + self.stop = threading.Event() + self.thread = None + resource = Resource.create( + { + "service.name": service, + "service.version": os.getenv("SERVICE_VERSION", "lab7-v1"), + "service.instance.id": INSTANCE_ID, + "deployment.environment.name": "lab", + } + ) + os.environ["OTEL_SERVICE_NAME"] = service + root = logging.getLogger() + root.setLevel(logging.INFO) + for handler in root.handlers: + handler.setFormatter(JsonFormatter()) + if not root.handlers: + handler = logging.StreamHandler() + handler.setFormatter(JsonFormatter()) + root.addHandler(handler) + if self.enabled: + endpoint = os.getenv("OTEL_EXPORTER_OTLP_ENDPOINT", "http://collector:4318").rstrip("/") + common = {"timeout": 1.0} + # Standard OTLP environment variables also support HTTPS/mTLS in lab7. + trace_provider = TracerProvider( + resource=resource, + sampler=ParentBased(TraceIdRatioBased(float(os.getenv("OTEL_SAMPLE_RATIO", "1")))), + ) + trace_provider.add_span_processor(RecordedSpans(self.export_stats)) + self.batch_spans = BatchSpanProcessor( + ObservedSpanExporter( + self.export_stats, + endpoint=endpoint + "/v1/traces", + session=CountingSession(self.export_stats, "traces"), + **common, + ), + max_queue_size=256, + max_export_batch_size=64, + schedule_delay_millis=500, + export_timeout_millis=1500, + ) + trace_provider.add_span_processor(self.batch_spans) + trace.set_tracer_provider(trace_provider) + reader = PeriodicExportingMetricReader( + OTLPMetricExporter( + endpoint=endpoint + "/v1/metrics", + session=CountingSession(self.export_stats, "metrics"), + **common, + ), + export_interval_millis=int(os.getenv("OTEL_METRIC_INTERVAL_MS", "5000")), + export_timeout_millis=1500, + ) + meter_provider = MeterProvider( + resource=resource, + metric_readers=[reader], + views=[ + View( + instrument_name="messenger.http.duration", + aggregation=ExplicitBucketHistogramAggregation(HTTP_BUCKETS), + ), + View( + instrument_name="messenger.job.duration", + aggregation=ExplicitBucketHistogramAggregation(JOB_BUCKETS), + ), + View( + instrument_name="messenger.attachment.ready.duration", + aggregation=ExplicitBucketHistogramAggregation(JOB_BUCKETS), + ), + ], + ) + metrics.set_meter_provider(meter_provider) + logger_provider = LoggerProvider(resource=resource) + logger_provider.add_log_record_processor( + BatchLogRecordProcessor( + OTLPLogExporter( + endpoint=endpoint + "/v1/logs", + session=CountingSession(self.export_stats, "logs"), + **common, + ), + max_queue_size=256, + max_export_batch_size=64, + schedule_delay_millis=500, + export_timeout_millis=1500, + ) + ) + set_logger_provider(logger_provider) + otlp_handler = LoggingHandler(level=logging.INFO, logger_provider=logger_provider) + otlp_handler.addFilter(TechnicalLogs()) + # Keep machine-readable JSON in OTLP log body, preserving request ID. + otlp_handler.setFormatter(JsonFormatter()) + root.addHandler(otlp_handler) + self.providers = [trace_provider, meter_provider, logger_provider] + self.tracer = trace.get_tracer("messenger", "1.0") + meter = metrics.get_meter("messenger", "1.0") + self.requests = meter.create_counter("messenger.http.requests", unit="{request}") + self.http_duration = meter.create_histogram("messenger.http.duration", unit="s") + self.sampling = meter.create_counter("messenger.http.trace.decisions", unit="{request}") + self.jobs = meter.create_counter("messenger.jobs", unit="{job}") + self.job_duration = meter.create_histogram("messenger.job.duration", unit="s") + self.ready_duration = meter.create_histogram( + "messenger.attachment.ready.duration", unit="s" + ) + self.queue_depth = meter.create_gauge("messenger.queue.depth", unit="{job}") + self.oldest_age = meter.create_gauge("messenger.queue.oldest.age", unit="s") + self.pool_used = meter.create_gauge("messenger.db.pool.used", unit="{connection}") + self.pool_waiting = meter.create_gauge("messenger.db.pool.waiting", unit="{request}") + self.worker_busy = meter.create_gauge("messenger.worker.busy", unit="{worker}") + self.worker_capacity = meter.create_gauge("messenger.worker.capacity", unit="{worker}") + self.process_cpu = meter.create_gauge("messenger.process.cpu", unit="%") + self.process_memory = meter.create_gauge("messenger.process.memory", unit="By") + self.export_observation = meter.create_gauge("messenger.telemetry.export", unit="{item}") + + def start_background(self, store): + process = psutil.Process() + process.cpu_percent() + + def collect(): + while not self.stop.wait(2): + counts = self.export_stats.snapshot() + # Read-only queue observation of pinned SDK 1.45.2. Conservation + # is evaluated after quiescence, not during concurrent export. + pending = len(self.batch_spans._batch_processor._queue) + counts["spans_pending"] = pending + counts["span_queue_capacity"] = 256 + counts["spans_queue_lost"] = max( + 0, + counts["spans_recorded"] + - counts["spans_exported"] + - counts["spans_export_failed"] + - counts["spans_in_flight"] + - pending, + ) + for name, value in counts.items(): + self.export_observation.set(value, {"observation": name}) + stats = store.pool.get_stats() + self.pool_used.set( + max(0, stats.get("pool_size", 0) - stats.get("pool_available", 0)) + ) + self.pool_waiting.set(stats.get("requests_waiting", 0)) + self.process_cpu.set(process.cpu_percent()) + self.process_memory.set(process.memory_info().rss) + if self.service == "messenger-worker": + self.worker_busy.set(self.busy) + self.worker_capacity.set(1) + if self.service == "messenger-dispatcher": + try: + with store.connection() as conn: + row = conn.execute( + "SELECT count(*) AS depth, COALESCE(EXTRACT(EPOCH FROM now()-min(created_at)),0) AS age FROM attachment_jobs WHERE state IN ('queued','processing')" + ).fetchone() + self.queue_depth.set(row["depth"], {"queue": "attachments"}) + self.oldest_age.set(float(row["age"]), {"queue": "attachments"}) + except Exception: + logging.getLogger("messenger.telemetry").warning( + json.dumps({"event": "queue_observation_unavailable"}) + ) + + if self.enabled: + self.thread = threading.Thread( + target=collect, name="telemetry-observations", daemon=True + ) + self.thread.start() + + def close(self): + self.stop.set() + if self.thread: + self.thread.join(timeout=4) + + # Business shutdown has a fixed budget even if telemetry endpoints are down. + def shutdown_providers(): + for provider in self.providers: + provider.shutdown() + + shutdown = threading.Thread( + target=shutdown_providers, name="telemetry-shutdown", daemon=True + ) + shutdown.start() + shutdown.join(timeout=2) + + +def setup(service): + global _runtime + if _runtime is None: + _runtime = Telemetry(service) + return _runtime + + +def current(): + return _runtime + + +def carrier(): + result = {} + propagate.inject(result) + return {key: result[key] for key in ("traceparent", "tracestate") if key in result} + + +@contextmanager +def operation(name, attributes=None, context=None, kind=SpanKind.CLIENT): + if ( + kind == SpanKind.CLIENT + and context is None + and not trace.get_current_span().get_span_context().is_valid + ): + yield trace.get_current_span() + return + tracer = trace.get_tracer("messenger", "1.0") + with tracer.start_as_current_span( + name, + attributes=attributes or {}, + context=context, + kind=kind, + record_exception=False, + set_status_on_exception=False, + ) as span: + try: + yield span + except BaseException as exc: + span.set_status(Status(StatusCode.ERROR, type(exc).__name__)) + raise diff --git a/src/messenger/tls_gateway.py b/src/messenger/tls_gateway.py new file mode 100644 index 0000000..d1a7d4d --- /dev/null +++ b/src/messenger/tls_gateway.py @@ -0,0 +1,272 @@ +"""Small TLS boundary: exact DNS SAN allowlist, revocation, bounded TCP forwarding. + +The upstream is always loopback in the same network namespace. HTTP mode is used +only for S3 prefix authorization; AWS signatures are still checked by S3 itself. +""" + +import argparse +import http.client +import json +import os +import selectors +import socket +import socketserver +import ssl +import threading +from contextlib import closing +from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer +from pathlib import Path +from urllib.parse import unquote, urlsplit + +MAX_BODY = 10 * 1024 * 1024 + + +def settings(): + return json.loads(Path(os.environ["TLS_GATEWAY_CONFIG"]).read_text()) + + +def role(cert, allowed): + names = {v for k, v in cert.get("subjectAltName", ()) if k == "DNS"} + found = names.intersection(allowed) + if len(found) != 1: + raise ssl.SSLError("service_identity_denied") + revoked = Path(os.getenv("TLS_REVOKED_FILE", "/run/tls/revoked.json")) + serials = json.loads(revoked.read_text()) if revoked.exists() else [] + if cert.get("serialNumber", "").lstrip("0").lower() in serials: + raise ssl.SSLError("certificate_revoked") + return next(iter(found)) + + +def context(cfg): + ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER) + ctx.set_alpn_protocols(["http/1.1"] if cfg.get("http") else ["h2", "http/1.1"]) + ctx.minimum_version = ssl.TLSVersion.TLSv1_2 + ctx.load_cert_chain(cfg["cert"], cfg["key"]) + if cfg.get("allowed"): + ctx.verify_mode = ssl.CERT_REQUIRED + ctx.load_verify_locations(cfg["ca"]) + ctx.options |= ssl.OP_NO_TICKET + return ctx + + +class Boundary: + def process_request(self, request, address): + if not self.slots.acquire(blocking=False): + request.close() + return + try: + super().process_request(request, address) + except Exception: + self.slots.release() + raise + + def process_request_thread(self, request, address): + try: + request.settimeout(2) + wrapped = context(self.cfg).wrap_socket(request, server_side=True) + wrapped.identity = ( + role(wrapped.getpeercert(), self.cfg["allowed"]) + if self.cfg.get("allowed") + else "public" + ) + wrapped.settimeout(15) + super().process_request_thread(wrapped, address) + except (OSError, ValueError): + request.close() + finally: + self.slots.release() + + +class TCPHandler(socketserver.BaseRequestHandler): + def handle(self): + try: + with socket.create_connection( + ("127.0.0.1", self.server.cfg["upstream"]), 2 + ) as upstream: + self.request.setblocking(False) + upstream.setblocking(False) + with selectors.DefaultSelector() as selector: + selector.register(self.request, selectors.EVENT_READ, upstream) + selector.register(upstream, selectors.EVENT_READ, self.request) + while True: + role(self.request.getpeercert(), self.server.cfg["allowed"]) + pending = self.request.pending() + events = selector.select(timeout=0 if pending else 30) + if pending and not any(key.fileobj is self.request for key, _ in events): + events.append((selector.get_key(self.request), selectors.EVENT_READ)) + if not events: + return + for key, _ in events: + # Recheck after the bounded wait: a revoked peer must + # not forward one extra command when it wakes select. + role(self.request.getpeercert(), self.server.cfg["allowed"]) + try: + chunk = key.fileobj.recv(65536) + except ssl.SSLWantReadError: + continue + if not chunk: + return + # Small writes with finite socket timeout prevent unbounded + # per-connection queues when a peer stops consuming. + destination = key.data + destination.settimeout(5) + destination.sendall(chunk) + destination.setblocking(False) + except (OSError, ssl.SSLError): + return + + +class TCPServer(Boundary, socketserver.ThreadingTCPServer): + allow_reuse_address = True + daemon_threads = True + request_queue_size = 64 + + +class HTTPHandler(BaseHTTPRequestHandler): + protocol_version = "HTTP/1.1" + + def handle_expect_100(self): + return True + + def log_message(self, *_): + pass + + def do_GET(self): + self.forward() + + do_HEAD = do_GET + do_PUT = do_GET + do_POST = do_GET + do_DELETE = do_GET + + def forward(self): + self.close_connection = True + cfg = self.server.cfg + identity = self.connection.identity + parsed = urlsplit(self.path) + path = unquote(parsed.path) + parts = path.split("/") + if ( + parsed.scheme + or parsed.netloc + or parsed.fragment + or any(p in {".", ".."} for p in parts) + or "\\" in path + or "%" in parsed.path + or any(ord(c) < 32 for c in path) + ): + self.send_error(403) + return + if cfg.get("backend") and identity != "operator": + allowed = ( + self.command == "GET" + if identity == "grafana" + else ( + identity == "collector" + and cfg["backend"] == "loki" + and self.command == "POST" + and parsed.path == "/otlp/v1/logs" + ) + ) + if not allowed: + self.send_error(403) + return + if cfg.get("s3"): + if ( + self.headers.get("Host", "").lower() != "storage:8443" + or (identity != "operator" and parsed.query) + or self.headers.get("x-amz-copy-source") + ): + self.send_error(403) + return + # A worker can read its sources, write versioned results and remove + # staging. It cannot list buckets, overwrite staging or touch others. + permitted = identity == "operator" + if identity == "api": + permitted = ( + path == "/messenger" + and self.command == "HEAD" + or ( + path.startswith("/messenger/staging/") + and self.command in {"PUT", "GET", "HEAD", "DELETE"} + ) + or ( + path.startswith("/messenger/attachments/") + and self.command in {"GET", "HEAD"} + ) + ) + elif identity == "worker": + permitted = ( + path.startswith("/messenger/staging/") + and self.command in {"GET", "HEAD", "DELETE"} + ) or ( + path.startswith("/messenger/attachments/") + and self.command in {"PUT", "GET", "HEAD"} + ) + if not permitted: + self.send_error(403) + return + try: + length = int(self.headers.get("Content-Length", "0")) + body_limit = MAX_BODY if cfg.get("s3") else 1024 * 1024 + if length < 0 or length > body_limit or self.headers.get("Transfer-Encoding"): + self.send_error(413) + return + if self.headers.get("Expect", "").lower() == "100-continue": + self.wfile.write(b"HTTP/1.1 100 Continue\r\n\r\n") + self.wfile.flush() + body = self.rfile.read(length) + if len(body) != length: + self.send_error(400) + return + headers = { + k: v + for k, v in self.headers.items() + if k.lower() not in {"connection", "proxy-connection", "expect"} + } + with closing( + http.client.HTTPConnection("127.0.0.1", cfg["upstream"], timeout=5) + ) as upstream: + upstream.request(self.command, self.path, body=body, headers=headers) + response = upstream.getresponse() + self.send_response(response.status) + for key, value in response.getheaders(): + if key.lower() not in {"connection", "transfer-encoding", "server", "date"}: + self.send_header(key, value) + self.send_header("Connection", "close") + self.end_headers() + if self.command != "HEAD": + while chunk := response.read(65536): + self.wfile.write(chunk) + except (OSError, ValueError, http.client.HTTPException): + self.close_connection = True + + +class HTTPServer(Boundary, ThreadingHTTPServer): + daemon_threads = True + + +def serve(cfg): + cls = HTTPServer if cfg.get("http") else TCPServer + handler = HTTPHandler if cfg.get("http") else TCPHandler + with cls(("0.0.0.0", cfg["port"]), handler) as server: + server.cfg = cfg + server.slots = threading.BoundedSemaphore(2 if cfg.get("http") else 32) + server.serve_forever(poll_interval=0.2) + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument("--config") + args = parser.parse_args() + cfg = json.loads(Path(args.config).read_text()) if args.config else settings() + listeners = cfg if isinstance(cfg, list) else [cfg] + threads = [threading.Thread(target=serve, args=(item,), daemon=True) for item in listeners] + for thread in threads: + thread.start() + for thread in threads: + thread.join() + + +if __name__ == "__main__": + main() diff --git a/src/messenger/transport_probe.py b/src/messenger/transport_probe.py new file mode 100644 index 0000000..ecd72e8 --- /dev/null +++ b/src/messenger/transport_probe.py @@ -0,0 +1,132 @@ +"""Operator-only network probe: real TLS, exact role authorization and closed raw ports.""" + +import json +import socket +import ssl +from pathlib import Path + +CA = "/run/tls/ca.pem" +IDENTITIES = Path("/run/audit-identities") + + +def exchange(host, port, role, payload, *, hostname=None, trust=True): + context = ( + ssl.create_default_context(cafile=CA) if trust else ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT) + ) + if role: + context.load_cert_chain(IDENTITIES / role / "cert.pem", IDENTITIES / role / "key.pem") + context.set_alpn_protocols(["h2"] if port == 44317 else ["http/1.1"]) + try: + with socket.create_connection((host, port), 2) as raw: + with context.wrap_socket(raw, server_hostname=hostname or host) as secured: + secured.settimeout(3) + secured.sendall(payload) + result = secured.recv(4096) + return bool(result), result + except (OSError, ssl.SSLError): + return False, b"" + + +def main(): + checks = {} + # Every gateway is tested positively with its intended role and negatively + # with another valid certificate from the SAME CA, no certificate, foreign + # CA certificate, empty trust and wrong server hostname. + targets = [ + ( + "api", + 9443, + "lb", + b"GET /health/ready HTTP/1.1\r\nHost: api\r\nConnection: close\r\n\r\n", + ), + ("broker", 6380, "worker", b"*1\r\n$4\r\nPING\r\n"), + ("cache", 6380, "api", b"*1\r\n$4\r\nPING\r\n"), + ( + "storage", + 8443, + "worker", + b"HEAD /messenger HTTP/1.1\r\nHost: storage:8443\r\nConnection: close\r\n\r\n", + ), + ( + "collector", + 4318, + "api", + b"POST /v1/traces HTTP/1.1\r\nHost: collector\r\nContent-Type: application/json\r\nContent-Length: 2\r\nConnection: close\r\n\r\n{}", + ), + ( + "collector", + 9464, + "prometheus", + b"GET /metrics HTTP/1.1\r\nHost: collector\r\nConnection: close\r\n\r\n", + ), + ( + "collector", + 8888, + "prometheus", + b"GET /metrics HTTP/1.1\r\nHost: collector\r\nConnection: close\r\n\r\n", + ), + ( + "prometheus", + 9443, + "grafana", + b"GET /api/v1/query?query=up HTTP/1.1\r\nHost: prometheus\r\nConnection: close\r\n\r\n", + ), + ( + "loki", + 9443, + "grafana", + b"GET /loki/api/v1/labels HTTP/1.1\r\nHost: loki\r\nConnection: close\r\n\r\n", + ), + ( + "tempo", + 9443, + "grafana", + b"GET /api/search HTTP/1.1\r\nHost: tempo\r\nConnection: close\r\n\r\n", + ), + ] + for host, port, role, payload in targets: + key = f"{host}_{port}" + ok, response = exchange(host, port, role, payload) + checks[key + "_allowed_identity"] = ok and ( + response.startswith(b"HTTP/1.1") or response.startswith(b"-NOAUTH") + ) + wrong = "worker" if host == "api" else "lb" + for label, identity, hostname, trust in ( + ("wrong_trusted_identity", wrong, None, True), + ("no_client_cert", None, None, True), + ("foreign_ca_client", "foreign", None, True), + ("wrong_server_hostname", role, "invalid.example", True), + ("empty_trust", role, None, False), + ): + ok, _ = exchange(host, port, identity, payload, hostname=hostname, trust=trust) + checks[key + "_" + label + "_denied"] = not ok + otlp = b"POST /v1/traces HTTP/1.1\r\nHost: tempo\r\nContent-Type: application/json\r\nContent-Length: 2\r\nConnection: close\r\n\r\n{}" + checks["tempo_otlp_collector_allowed"] = exchange("tempo", 44318, "collector", otlp)[0] + checks["tempo_otlp_wrong_role_denied"] = not exchange("tempo", 44318, "worker", otlp)[0] + for host, ports in ( + ("api", [8080]), + ("storage", [8333, 8888, 9333]), + ("broker", [6379]), + ("cache", [6379]), + ("collector", [14318, 19464, 18888, 13133]), + ("prometheus", [9090]), + ("loki", [3100]), + ("tempo", [3200, 4317, 4318]), + ): + for port in ports: + try: + with socket.create_connection((host, port), 1): + checks[f"raw_{host}_{port}_closed"] = False + except OSError: + checks[f"raw_{host}_{port}_closed"] = True + # Datasource roles cannot submit arbitrary telemetry or mutate Prometheus. + forbidden = b"POST /otlp/v1/logs HTTP/1.1\r\nHost: loki\r\nContent-Length: 2\r\nConnection: close\r\n\r\n{}" + ok, body = exchange("loki", 9443, "grafana", forbidden) + checks["grafana_loki_write_denied"] = ok and b" 403 " in body.split(b"\r\n", 1)[0] + print(json.dumps({"checks": checks, "passed": all(checks.values())}, sort_keys=True)) + if not all(checks.values()): + raise SystemExit(1) + + +if __name__ == "__main__": + main() diff --git a/src/messenger/worker.py b/src/messenger/worker.py new file mode 100644 index 0000000..914a564 --- /dev/null +++ b/src/messenger/worker.py @@ -0,0 +1,292 @@ +"""Separate serial worker (prefetch=1) and transactional-outbox dispatcher.""" + +import argparse +import hashlib +import json +import logging +import re +import signal +import subprocess +import sys +import tempfile +import time +from datetime import datetime +from pathlib import Path +from uuid import UUID, uuid4 + +import redis +from opentelemetry import propagate, trace +from opentelemetry.trace import SpanKind, Status, StatusCode + +from . import telemetry +from .domain import Failure +from .jobs import GROUP, STREAM, Jobs, broker_client, fault +from .postgres import PostgresStore +from .secrets_provider import refresh +from .storage import ObjectStorage + +logger = logging.getLogger("messenger.worker") +logging.basicConfig(level=logging.INFO, format="%(message)s") +stopping = False +MAX_JOB_BYTES = 8192 + + +def stop(signum, frame): + global stopping + stopping = True + + +def process(job, jobs, storage): + fault(jobs.store, "before_effect", job["attachment_id"]) + with tempfile.TemporaryDirectory(prefix="image-job-") as directory: + root = Path(directory) + source = root / "source" + response = storage.get(job["source_key"]) + try: + if response["ContentLength"] > 10_485_760: + raise ValueError("invalid_image") + with source.open("wb") as target: + while block := response["Body"].read(64 * 1024): + target.write(block) + if target.tell() > 10_485_760: + raise ValueError("invalid_image") + finally: + response["Body"].close() + with source.open("rb") as file: + digest = hashlib.file_digest(file, "sha256").hexdigest() + if digest != job["source_sha256"] or source.stat().st_size != job["source_size"]: + raise ValueError("invalid_image") + # Resize executes outside the API and is bounded in wall time, CPU and address space. + result = subprocess.run( + [ + sys.executable, + "-m", + "messenger.image_pipeline", + str(source), + directory, + str(job["pipeline_version"]), + ], + timeout=20, + capture_output=True, + check=False, + ) + if result.returncode: + raise ValueError("invalid_image") + variants = json.loads((root / "variants.json").read_text()) + prefix = f"attachments/{job['attachment_id']}/v{job['pipeline_version']}" + with source.open("rb") as file: + storage.put( + prefix + "/original", file, source.stat().st_size, job["source_content_type"] + ) + for variant in variants: + path = root / variant["name"] + with path.open("rb") as file: + storage.put( + prefix + "/" + variant["name"], + file, + variant["size_bytes"], + variant["content_type"], + ) + fault(jobs.store, "after_effect", job["attachment_id"]) + published = jobs.complete(job, prefix + "/original", variants) + if published: + fault(jobs.store, "after_result_commit", job["attachment_id"]) + cleanup_ready(jobs.store, storage, job["attachment_id"]) + return published + + +def cleanup_ready(store, storage, attachment_id): + # Same row lock as reprocess/replay: cannot delete a source chosen by a new job. + with store.connection() as conn, conn.transaction(): + a = conn.execute( + "SELECT * FROM attachments WHERE id=%s FOR UPDATE", (attachment_id,) + ).fetchone() + if ( + a + and a["status"] == "ready" + and a["stage_key"] + and a["stage_key"].startswith("staging/") + ): + storage.delete(a["stage_key"]) + conn.execute("UPDATE attachments SET stage_key=NULL WHERE id=%s", (attachment_id,)) + + +def validate_delivery(body): + if not isinstance(body, (str, bytes, bytearray)): + raise ValueError("invalid_job") + encoded = body.encode("utf-8") if isinstance(body, str) else body + if len(encoded) > MAX_JOB_BYTES: + raise ValueError("invalid_job") + try: + data = json.loads(encoded) + except RecursionError: + raise ValueError("invalid_job") from None + expected = { + "schema_version", + "job_id", + "type", + "attachment_id", + "pipeline_version", + "attempt", + "created_at", + } + optional = {"traceparent", "tracestate"} + if not isinstance(data, dict) or not expected <= set(data) or set(data) - expected - optional: + raise ValueError("invalid_job") + if ( + type(data["schema_version"]) is not int + or data["schema_version"] != 1 + or data["type"] != "attachment.process.v1" + ): + raise ValueError("invalid_job") + if not isinstance(data["job_id"], str) or not isinstance(data["attachment_id"], str): + raise ValueError("invalid_job") + for field in ("job_id", "attachment_id"): + canonical = str(UUID(data[field])) + if data[field].lower() != canonical: + raise ValueError("invalid_job") + # RFC UUID hex is case-insensitive; PostgreSQL and state comparisons use + # the same canonical spelling, so a valid uppercase delivery is not lost. + data[field] = canonical + if type(data["pipeline_version"]) is not int or data["pipeline_version"] < 1: + raise ValueError("invalid_job") + if type(data["attempt"]) is not int or data["attempt"] < 1: + raise ValueError("invalid_job") + created = data["created_at"] + if ( + not isinstance(created, str) + or len(created) > 64 + or not re.fullmatch( + r"[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(?:\.[0-9]+)?Z", created + ) + ): + raise ValueError("invalid_job") + datetime.fromisoformat(created[:-1] + "+00:00") + if "traceparent" in data and ( + not isinstance(data["traceparent"], str) + or not re.fullmatch(r"00-[0-9a-f]{32}-[0-9a-f]{16}-[0-9a-f]{2}", data["traceparent"]) + ): + raise ValueError("invalid_job") + if "tracestate" in data and ( + not isinstance(data["tracestate"], str) or len(data["tracestate"]) > 512 + ): + raise ValueError("invalid_job") + return data + + +def consume_one(store, jobs, storage, broker, entry): + entry_id, fields = entry + try: + body = validate_delivery(fields.get("body", fields.get(b"body"))) + except (KeyError, ValueError, TypeError): + logger.error(json.dumps({"event": "invalid_delivery"})) + broker.xack(STREAM, GROUP, entry_id) + broker.xdel(STREAM, entry_id) + return + with telemetry.operation( + "attachments consume", context=propagate.extract(body), kind=SpanKind.CONSUMER + ): + consume_job(store, jobs, storage, broker, body) + # Durable state owns recovery even when notification acknowledgements repeat. + broker.xack(STREAM, GROUP, entry_id) + broker.xdel(STREAM, entry_id) + + +def consume_job(store, jobs, storage, broker, body): + job = jobs.claim(body["job_id"], body["attachment_id"], body["pipeline_version"]) + t = telemetry.current() + started = time.perf_counter() + outcome = "duplicate" + if job: + try: + if t: + t.busy = 1 + outcome = "success" if process(job, jobs, storage) else "superseded" + except ValueError: + jobs.fail(job, "invalid_image", permanent=True) + outcome = "failed" + except (Failure, subprocess.TimeoutExpired, OSError, RuntimeError) as exc: + logger.warning( + json.dumps( + {"event": "job_retry", "job_id": str(job["id"]), "kind": type(exc).__name__} + ) + ) + jobs.fail(job, "processing_failed") + outcome = "retry" if job["attempt"] < job["attempt_limit"] else "failed" + finally: + if t: + t.busy = 0 + attrs = {"job_type": "attachment.process.v1", "outcome": outcome} + t.jobs.add(1, attrs) + t.job_duration.record(time.perf_counter() - started, attrs) + span = trace.get_current_span() + span.set_attributes({"job.type": "attachment.process.v1", "job.outcome": outcome}) + if outcome in {"failed", "retry"}: + span.set_status(Status(StatusCode.ERROR, "processing_failed")) + logger.info(json.dumps({"event": "job_finished", "outcome": outcome})) + else: + trace.get_current_span().set_attributes( + {"job.type": "attachment.process.v1", "job.outcome": "duplicate"} + ) + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument("--dispatcher", action="store_true") + args = parser.parse_args() + signal.signal(signal.SIGTERM, stop) + signal.signal(signal.SIGINT, stop) + t = telemetry.setup("messenger-dispatcher" if args.dispatcher else "messenger-worker") + store = PostgresStore() + t.start_background(store) + jobs = Jobs(store) + broker = broker_client() + storage = None if args.dispatcher else ObjectStorage() + consumer = "worker-" + str(uuid4()) + last_claim = 0 + try: + while not stopping: + try: + refresh() + if args.dispatcher: + jobs.recover_one() + if not jobs.publish_one(broker): + time.sleep(0.2) + continue + try: + broker.xgroup_create(STREAM, GROUP, id="0", mkstream=True) + except redis.ResponseError as exc: + if "BUSYGROUP" not in str(exc): + raise + entries = [] + if time.monotonic() - last_claim >= 5: + claimed = broker.xautoclaim( + STREAM, + GROUP, + consumer, + min_idle_time=jobs.lease_seconds * 1000, + start_id="0-0", + count=1, + ) + entries = claimed[1] + last_claim = time.monotonic() + if not entries: + batches = broker.xreadgroup(GROUP, consumer, {STREAM: ">"}, count=1, block=500) + entries = batches[0][1] if batches else [] + for entry in entries: + consume_one(store, jobs, storage, broker, entry) + except (redis.RedisError, Failure) as exc: + logger.warning( + json.dumps({"event": "dependency_retry", "kind": type(exc).__name__}) + ) + time.sleep(0.5) + finally: + broker.close() + if storage is not None: + storage.close() + t.close() + store.close() + + +if __name__ == "__main__": + main() diff --git a/student-tests/test_api.py b/student-tests/test_api.py new file mode 100644 index 0000000..5aac1cd --- /dev/null +++ b/student-tests/test_api.py @@ -0,0 +1,201 @@ +import base64 +import os +import threading +import uuid +from concurrent.futures import ThreadPoolExecutor +from urllib.parse import quote + +import pytest +from client import LAB, Client + + +@pytest.fixture +def scenario(): + c = Client(os.environ.get("BASE_URL", "http://127.0.0.1:8085")) + return c, *c.bootstrap() + + +@pytest.mark.parametrize( + "body", + [ + {"text": ""}, + {"text": " \n\t"}, + {"text": 1}, + {"text": True}, + {"text": None}, + {"text": "x", "sender_id": str(uuid.uuid4())}, + {"text": "x", "unknown": 1}, + {"text": "x" * 4001}, + {}, + [], + ], +) +def test_invalid_message(scenario, body): + c, alice, _, _, chat = scenario + c.call( + "POST", + f"/api/v1/chats/{chat['id']}/messages", + 400, + actor=alice, + body=body, + headers={"Idempotency-Key": uuid.uuid4().hex}, + ) + + +def test_malformed_json(scenario): + c, alice, _, _, chat = scenario + c.call( + "POST", + f"/api/v1/chats/{chat['id']}/messages", + 400, + actor=alice, + raw=b'{"text":', + headers={"Content-Type": "application/json", "Idempotency-Key": uuid.uuid4().hex}, + ) + + +def test_acl_and_unknown_chat(scenario): + c, alice, _, eve, chat = scenario + for cid in [chat["id"], str(uuid.uuid4())]: + for suffix in ["", "/messages"]: + c.call("GET", f"/api/v1/chats/{cid}{suffix}", 404, actor=eve) + c.call( + "POST", + f"/api/v1/chats/{cid}/messages", + 404, + actor=eve, + body={"text": "x"}, + headers={"Idempotency-Key": uuid.uuid4().hex}, + ) + c.call("GET", "/api/v1/chats/not-a-uuid", 400, actor=alice) + + +@pytest.mark.parametrize("name", ["ab", "UPPER", "a-b", "a" * 33, "имя", "abc\n"]) +def test_username_validation(scenario, name): + c, alice, *_ = scenario + body = {**alice["registration"], "username": name} + c.call("POST", "/api/v1/users", 400, body=body) + + +def test_unicode_and_limits(scenario): + c, alice, _, _, chat = scenario + text = "Ё👩‍💻漢字" * 500 + assert c.message(alice, chat, text)["json"]["text"] == text + c.call( + "POST", + "/api/v1/users", + 400, + body={ + **alice["registration"], + "username": "u_" + uuid.uuid4().hex[:12], + "display_name": " ", + }, + ) + + +@pytest.mark.parametrize("value", ["0", "101", "1.5", "true", "-1", "", "1&limit=2"]) +def test_invalid_limit(scenario, value): + c, alice, _, _, chat = scenario + c.call("GET", f"/api/v1/chats/{chat['id']}/messages?limit={value}", 400, actor=alice) + + +def test_pagination_and_cursor_scope(scenario): + c, alice, bob, _, chat = scenario + expected = [c.message(alice, chat, str(i))["json"] for i in range(13)] + path = f"/api/v1/chats/{chat['id']}/messages" + result, cursor, first = [], None, None + for i in range(20): + url = path + f"?limit={2 if i == 0 else 3}" + if cursor: + url += "&cursor=" + quote(cursor, safe="") + data = c.call("GET", url, actor=bob, schema="MessagePage")["json"] + result += data["items"] + cursor = data["next_cursor"] + first = first or cursor + if cursor is None: + break + assert result == sorted(expected, key=lambda m: (m["created_at"], m["id"])) + other = c.call( + "POST", + "/api/v1/chats", + 201, + actor=alice, + body={"title": "другой", "member_ids": [alice["id"]]}, + schema="Chat", + )["json"] + c.call("GET", f"/api/v1/chats/{other['id']}/messages?cursor={first}", 400, actor=alice) + c.call("GET", path + "?cursor=broken", 400, actor=alice) + + +def test_chat_validation_and_atomicity(scenario): + c, alice, bob, _, _ = scenario + before = c.call("GET", "/api/v1/chats?limit=100", actor=alice, schema="ChatPage")["json"] + for members in [ + [bob["id"]], + [alice["id"], alice["id"]], + [alice["id"], str(uuid.uuid4())], + [], + [123], + ]: + c.call( + "POST", + "/api/v1/chats", + 400, + actor=alice, + body={"title": "не должен появиться", "member_ids": members}, + ) + after = c.call("GET", "/api/v1/chats?limit=100", actor=alice, schema="ChatPage")["json"] + assert before == after + + +def test_concurrent_messages(scenario): + c, alice, bob, _, chat = scenario + barrier = threading.Barrier(10) + + def sender(i): + local = Client(c.base) + barrier.wait() + return [local.message(alice, chat, f"{i}:{j}")["json"] for j in range(10)] + + with ThreadPoolExecutor(max_workers=10) as pool: + sent = [m for batch in pool.map(sender, range(10)) for m in batch] + data = c.call( + "GET", f"/api/v1/chats/{chat['id']}/messages?limit=100", actor=bob, schema="MessagePage" + )["json"] + assert len(sent) == len({m["id"] for m in sent}) == len(data["items"]) == 100 + assert {m["id"] for m in sent} == {m["id"] for m in data["items"]} + assert data["next_cursor"] is None + + +def test_registration_race(scenario): + c, alice, *_ = scenario + body = {**alice["registration"], "username": "race_" + uuid.uuid4().hex[:12]} + barrier = threading.Barrier(10) + + def register(_): + local = Client(c.base) + barrier.wait() + return local.call("POST", "/api/v1/users", [201, 409], body=body)["status"] + + with ThreadPoolExecutor(max_workers=10) as pool: + statuses = list(pool.map(register, range(10))) + assert statuses.count(201) == 1 + assert statuses.count(409) == 9 + + +@pytest.mark.skipif(LAB < 2, reason="Сессии появляются в ЛР2") +def test_sessions(scenario): + c, alice, _, eve, _ = scenario + credential = base64.b64encode( + (alice["registration"]["username"] + ":wrong-password").encode() + ).decode() + c.call("POST", "/api/v1/auth/sessions", 401, headers={"Authorization": "Basic " + credential}) + c.call("GET", "/api/v1/users/me", 401, headers={"X-User-Id": alice["id"]}) + assert ( + c.call( + "GET", "/api/v1/users/me", actor=alice, headers={"X-User-Id": eve["id"]}, schema="User" + )["json"] + == alice["user"] + ) + c.call("DELETE", "/api/v1/auth/sessions/current", 204, actor=alice) + c.call("GET", "/api/v1/users/me", 401, actor=alice) diff --git a/student-tests/test_attachments.py b/student-tests/test_attachments.py new file mode 100644 index 0000000..72bf474 --- /dev/null +++ b/student-tests/test_attachments.py @@ -0,0 +1,203 @@ +"""Black-box regressions derived from the contract and teacher review comments.""" + +import hashlib +import os +import struct +import uuid +import zlib +from io import BytesIO +from urllib.parse import quote + +import pytest +from client import Client +from PIL import Image + + +@pytest.fixture(scope="module") +def scenario(): + c = Client(os.environ.get("BASE_URL", "http://127.0.0.1:8085")) + return c, *c.bootstrap() + + +def image_bytes(fmt="PNG", size=(32, 20)): + stream = BytesIO() + Image.new("RGB", size, (100, 130, 200)).save(stream, fmt) + return stream.getvalue() + + +def upload(scenario, data=None, name="sample.png", mime="image/png", actor=None, status=202): + c, alice, _, _, chat = scenario + return c.call( + "POST", + f"/api/v1/chats/{chat['id']}/attachments?filename={quote(name, safe='')}", + status, + actor=actor or alice, + raw=data if data is not None else image_bytes(), + headers={"Content-Type": mime}, + schema="Attachment" if status == 202 else None, + ) + + +def test_roundtrip_acl_and_variant(scenario): + c, alice, bob, eve, chat = scenario + data = image_bytes() + a = upload(scenario, data)["json"] + assert a["sha256"] == hashlib.sha256(data).hexdigest() + assert a["status"] == "queued" + a = c.wait_ready(alice, a) + assert {v["name"] for v in a["variants"]} == {"thumbnail", "crop", "optimized"} + path = f"/api/v1/attachments/{a['id']}" + assert c.call("GET", path + "/content", 200, actor=bob)["bytes"] == data + c.call("GET", path, 404, actor=eve) + c.call("GET", path + "/content", 404, actor=eve) + c.call("GET", path + "/content?variant=thumbnail", 200, actor=alice) + c.call("GET", path + "/content?variant=unknown", 400, actor=alice) + message = c.call( + "POST", + f"/api/v1/chats/{chat['id']}/messages", + 201, + actor=alice, + body={"text": "", "attachment_ids": [a["id"]]}, + headers={"Idempotency-Key": uuid.uuid4().hex}, + schema="Message", + )["json"] + assert message["text"] == "" and message["attachment_ids"] == [a["id"]] + + +@pytest.mark.parametrize( + "name", [" ", "../x.png", "a\\b.png", "a\0.png", "a\x7f.png", "a\x85.png", "a\n.png"] +) +def test_bad_filename(scenario, name): + upload(scenario, name=name, status=400) + + +def chunk(kind, data): + return struct.pack(">I", len(data)) + kind + data + struct.pack(">I", zlib.crc32(kind + data)) + + +def png_with_data(data, width=1, height=1, color=2, palette=b""): + return ( + b"\x89PNG\r\n\x1a\n" + + chunk(b"IHDR", struct.pack(">IIBBBBB", width, height, 8, color, 0, 0, 0)) + + (chunk(b"PLTE", palette) if palette else b"") + + chunk(b"IDAT", data) + + chunk(b"IEND", b"") + ) + + +@pytest.mark.parametrize( + "data,mime", + [ + (image_bytes()[:33], "image/png"), + (image_bytes()[:-15], "image/png"), + (png_with_data(b"broken-zlib"), "image/png"), + (png_with_data(zlib.compress(b"\x05\0\0\0")), "image/png"), + (png_with_data(zlib.compress(b"\0\0"), color=3, palette=bytes(771)), "image/png"), + (bytes.fromhex("ffd8ffc0000b080001000101011100ffda0008010100003f00ffd9"), "image/jpeg"), + (bytes.fromhex("ffd8ffc00008080001000101ffda0002ffd9"), "image/jpeg"), + (image_bytes(), "image/jpeg"), + (b"not-an-image", "image/png"), + ], +) +def test_corrupt_or_spoofed_image(scenario, data, mime): + upload(scenario, data=data, mime=mime, status=415) + + +@pytest.mark.parametrize("size", [(8000, 5001), (20000, 10000)]) +def test_pixel_limit_before_decode(scenario, size): + data = png_with_data(b"", width=size[0], height=size[1]) + upload(scenario, data=data, status=413) + + +def test_byte_limit_and_exact_boundary(scenario): + data = image_bytes() + exact = data + bytes(10 * 1024 * 1024 - len(data)) + a = upload(scenario, data=exact)["json"] + assert a["size_bytes"] == len(exact) + upload(scenario, data=exact + b"x", status=413) + + +@pytest.mark.parametrize( + "body", + [ + {"attachment_ids": []}, + {"text": None}, + {"text": "x", "attachment_ids": None}, + {"text": "x", "attachment_ids": [123]}, + ], +) +def test_strict_message_fields(scenario, body): + c, alice, _, _, chat = scenario + c.call( + "POST", + f"/api/v1/chats/{chat['id']}/messages", + 400, + actor=alice, + body=body, + headers={"Idempotency-Key": uuid.uuid4().hex}, + ) + + +def test_foreign_unknown_and_ordered_attachments(scenario): + c, alice, _, _, chat = scenario + first, second = upload(scenario)["json"], upload(scenario)["json"] + other = c.call( + "POST", + "/api/v1/chats", + 201, + actor=alice, + body={"title": "other", "member_ids": [alice["id"]]}, + schema="Chat", + )["json"] + for aid in [first["id"], str(uuid.uuid4())]: + c.call( + "POST", + f"/api/v1/chats/{other['id']}/messages", + 404, + actor=alice, + body={"text": "", "attachment_ids": [aid]}, + headers={"Idempotency-Key": uuid.uuid4().hex}, + ) + key = uuid.uuid4().hex + body = {"text": "with files", "attachment_ids": [second["id"], first["id"]]} + p = f"/api/v1/chats/{chat['id']}/messages" + sent = c.call( + "POST", p, 201, actor=alice, body=body, headers={"Idempotency-Key": key}, schema="Message" + )["json"] + repeat = c.call( + "POST", p, 201, actor=alice, body=body, headers={"Idempotency-Key": key}, schema="Message" + )["json"] + assert repeat == sent + c.call( + "POST", + p, + 409, + actor=alice, + body={**body, "attachment_ids": list(reversed(body["attachment_ids"]))}, + headers={"Idempotency-Key": key}, + ) + history = c.call("GET", p, 200, actor=alice, schema="MessagePage")["json"]["items"] + assert next(m for m in history if m["id"] == sent["id"]) == sent + + +def test_nul_message_roundtrip(scenario): + c, alice, _, _, chat = scenario + assert c.message(alice, chat, "abc\0def")["json"]["text"] == "abc\0def" + + +def test_truncated_jpeg_with_forged_eoi(scenario): + import random + + stream = BytesIO() + Image.frombytes("RGB", (512, 512), random.Random(42).randbytes(512 * 512 * 3)).save( + stream, "JPEG", quality=95 + ) + original = stream.getvalue() + upload(scenario, data=original, name="real.jpg", mime="image/jpeg") + upload( + scenario, + data=original[: len(original) // 2] + b"\xff\xd9", + name="broken.jpg", + mime="image/jpeg", + status=415, + ) diff --git a/student-tests/test_cursor_format.py b/student-tests/test_cursor_format.py new file mode 100644 index 0000000..ceb15c5 --- /dev/null +++ b/student-tests/test_cursor_format.py @@ -0,0 +1,39 @@ +import base64 +import json +from uuid import uuid4 + +import pytest + +from messenger.domain import Failure, boundary + + +@pytest.mark.parametrize( + "version,date", + [ + (True, "2026-01-01T00:00:00Z"), + (1.0, "2026-01-01T00:00:00Z"), + (1, "2026-W01-1T00:00:00Z"), + (1, "20260101T000000Z"), + (1, "2026-01-01 00:00:00Z"), + (1, "2026-01-01X00:00:00Z"), + (1, "2026-02-30T00:00:00Z"), + (1, "2026-01-01T00:00:00.1234567Z"), + ], +) +def test_boundary_rejects_python_iso_extensions(version, date): + payload = [version, "scope", date, str(uuid4())] + cursor = base64.urlsafe_b64encode(json.dumps(payload).encode()).decode().rstrip("=") + with pytest.raises(Failure) as error: + boundary("scope", cursor) + assert error.value.status == 400 + + +@pytest.mark.parametrize( + "date", ["2026-01-01T00:00:00Z", "2026-01-01T00:00:00.1Z", "2026-01-01T00:00:00.123456Z"] +) +def test_boundary_preserves_generated_format(date): + uid = str(uuid4()) + cursor = ( + base64.urlsafe_b64encode(json.dumps([1, "scope", date, uid]).encode()).decode().rstrip("=") + ) + assert boundary("scope", cursor) == (date, uid) diff --git a/student-tests/test_cursor_http.py b/student-tests/test_cursor_http.py new file mode 100644 index 0000000..558b04e --- /dev/null +++ b/student-tests/test_cursor_http.py @@ -0,0 +1,49 @@ +import base64 +import json +import os +import uuid + +import pytest +from client import Client + + +@pytest.fixture(scope="module") +def shared(): + client = Client(os.getenv("BASE_URL", "http://127.0.0.1:8085")) + return client, *client.bootstrap() + + +@pytest.mark.parametrize( + "date", + [ + "2026-W01-1T00:00:00Z", + "20260101T000000Z", + "2026-01-01 00:00:00Z", + "2026-01-01X00:00:00Z", + "2026-01-01T00:00:00+00:00", + "2026-02-30T00:00:00Z", + "2026-01-01T24:00:00Z", + "2026-01-01T00:00:00.1234567Z", + ], +) +def test_cursor_rejects_noncanonical_dates_over_http(shared, date): + c, alice, _, _, chat = shared + for path, scope in [ + ("/api/v1/chats", "chats:" + alice["id"]), + (f"/api/v1/chats/{chat['id']}/messages", "messages:" + chat["id"]), + ]: + payload = [1, scope, date, str(uuid.uuid4())] + cursor = base64.urlsafe_b64encode(json.dumps(payload).encode()).decode().rstrip("=") + c.call("GET", path + "?cursor=" + cursor, 400, actor=alice) + + +@pytest.mark.parametrize("version", [True, 1.0]) +def test_cursor_rejects_noninteger_version_over_http(shared, version): + c, alice, _, _, chat = shared + for path, scope in [ + ("/api/v1/chats", "chats:" + alice["id"]), + (f"/api/v1/chats/{chat['id']}/messages", "messages:" + chat["id"]), + ]: + payload = [version, scope, "2026-01-01T00:00:00Z", str(uuid.uuid4())] + cursor = base64.urlsafe_b64encode(json.dumps(payload).encode()).decode().rstrip("=") + c.call("GET", path + "?cursor=" + cursor, 400, actor=alice) diff --git a/student-tests/test_edgecases.py b/student-tests/test_edgecases.py new file mode 100644 index 0000000..f5d3d47 --- /dev/null +++ b/student-tests/test_edgecases.py @@ -0,0 +1,99 @@ +import base64 +import json +import os +import uuid +from urllib.parse import quote + +import pytest +from client import LAB, Client + + +@pytest.fixture +def edge_scenario(): + client = Client(os.environ.get("BASE_URL", "http://127.0.0.1:8085")) + return client, *client.bootstrap() + + +def encoded_cursor(value): + return base64.urlsafe_b64encode(json.dumps(value).encode()).decode().rstrip("=") + + +@pytest.mark.parametrize("identity", ["missing", "malformed", "unknown"]) +def test_invalid_identity(edge_scenario, identity): + client, _, _, _, chat = edge_scenario + headers = {} + if identity == "malformed": + headers["X-User-Id"] = "not-a-uuid" + elif identity == "unknown": + headers["X-User-Id"] = str(uuid.uuid4()) + for path in ["/api/v1/users/me", "/api/v1/chats", f"/api/v1/chats/{chat['id']}/messages"]: + client.call("GET", path, 401, headers=headers) + + +@pytest.mark.parametrize("uid", [None, [], {}, 123, True, "not-a-uuid"]) +def test_cursor_rejects_non_uuid_boundary(edge_scenario, uid): + client, alice, _, _, chat = edge_scenario + payload = [1, "messages:" + chat["id"], "2026-10-30T12:00:00.000000Z", uid] + cursor = quote(encoded_cursor(payload), safe="") + client.call("GET", f"/api/v1/chats/{chat['id']}/messages?cursor={cursor}", 400, actor=alice) + + +@pytest.mark.parametrize( + "payload", [None, {}, [], [1], [1, "wrong-scope", "2026-10-30T12:00:00Z", str(uuid.uuid4())]] +) +def test_cursor_rejects_wrong_shape(edge_scenario, payload): + client, alice, _, _, chat = edge_scenario + cursor = quote(encoded_cursor(payload), safe="") + client.call("GET", f"/api/v1/chats/{chat['id']}/messages?cursor={cursor}", 400, actor=alice) + + +def test_request_id_is_present_and_not_reused(edge_scenario): + client, alice, _, _, _ = edge_scenario + first = client.call("GET", "/health/live", schema="Health") + second = client.call("GET", "/health/ready", schema="Health") + error = client.call("GET", "/api/v1/chats/malformed", 400, actor=alice) + values = [r["headers"]["X-Request-Id"] for r in [first, second, error]] + assert len(set(values)) == 3 + assert error["json"]["error"]["request_id"] == values[-1] + + +def test_unicode_codepoint_boundaries(edge_scenario): + client, alice, _, _, chat = edge_scenario + username = "unicode_" + uuid.uuid4().hex[:12] + registration = {"username": username, "display_name": "😀" * 100} + if LAB >= 2: + registration["password"] = "unicode-test-" + uuid.uuid4().hex + user = client.call( + "POST", + "/api/v1/users", + 201, + body=registration, + schema="User", + )["json"] + assert user["display_name"] == "😀" * 100 + client.call( + "POST", "/api/v1/users", 400, body={"username": username + "x", "display_name": "😀" * 101} + ) + message = client.message(alice, chat, "😀" * 4000)["json"] + assert message["text"] == "😀" * 4000 + client.call( + "POST", f"/api/v1/chats/{chat['id']}/messages", 400, actor=alice, body={"text": "😀" * 4001} + ) + + +def test_empty_history_and_cursor_exhaustion(edge_scenario): + client, alice, _, _, chat = edge_scenario + path = f"/api/v1/chats/{chat['id']}/messages" + empty = client.call("GET", path, actor=alice, schema="MessagePage")["json"] + assert empty == {"items": [], "next_cursor": None} + message = client.message(alice, chat, "одна запись")["json"] + data = client.call("GET", path + "?limit=1", actor=alice, schema="MessagePage")["json"] + assert data == {"items": [message], "next_cursor": None} + + +def test_missing_chat_is_hidden_like_foreign_chat(edge_scenario): + client, _, _, eve, chat = edge_scenario + foreign = client.call("GET", f"/api/v1/chats/{chat['id']}", 404, actor=eve)["json"] + missing = client.call("GET", f"/api/v1/chats/{uuid.uuid4()}", 404, actor=eve)["json"] + assert foreign["error"]["code"] == missing["error"]["code"] == "not_found" + assert foreign["error"]["message"] == missing["error"]["message"] diff --git a/student-tests/test_image_edges.py b/student-tests/test_image_edges.py new file mode 100644 index 0000000..ae0160d --- /dev/null +++ b/student-tests/test_image_edges.py @@ -0,0 +1,229 @@ +"""Full-range JPEG and bounded multi-frame PNG regressions.""" + +import os +import struct +import zlib +from io import BytesIO + +import pytest +from client import Client +from PIL import Image + + +@pytest.fixture(scope="module") +def scenario(): + c = Client(os.getenv("BASE_URL", "http://127.0.0.1:8085")) + return c, *c.bootstrap() + + +def upload(scenario, data, mime, expected): + c, alice, _, _, chat = scenario + result = c.call( + "POST", + f"/api/v1/chats/{chat['id']}/attachments?filename=edge.png", + 202 if expected == 201 else expected, + actor=alice, + raw=data, + headers={"Content-Type": mime}, + schema="Attachment" if expected == 201 else None, + ) + if expected == 201: + result["json"] = c.wait_ready(alice, result["json"]) + return result + + +def progressive_jpeg(): + output = BytesIO() + image = Image.new("RGB", (6000, 6000), "blue") + try: + image.save(output, "JPEG", quality=90, progressive=True, subsampling=0) + finally: + image.close() + return output.getvalue() + + +def apng(size=(16, 16), default_image=False): + output = BytesIO() + first, second = Image.new("RGB", size, "red"), Image.new("RGB", size, "blue") + try: + first.save( + output, + "PNG", + save_all=True, + append_images=[second], + duration=100, + loop=0, + default_image=default_image, + ) + finally: + first.close() + second.close() + return output.getvalue() + + +def broken_later_frame(data): + result, position = bytearray(data[:8]), 8 + while position < len(data): + length = struct.unpack(">I", data[position : position + 4])[0] + kind = data[position + 4 : position + 8] + payload = data[position + 8 : position + 8 + length] + if kind == b"fdAT": + payload = payload[:4] + b"not-a-valid-deflate-stream" + result += ( + struct.pack(">I", len(payload)) + + kind + + payload + + struct.pack(">I", zlib.crc32(kind + payload)) + ) + position += length + 12 + return bytes(result) + + +def test_36m_progressive_jpeg_is_valid_and_unchanged(scenario): + data = progressive_jpeg() + attachment = upload(scenario, data, "image/jpeg", 201)["json"] + c, _, bob, _, _ = scenario + assert ( + c.call("GET", f"/api/v1/attachments/{attachment['id']}/content", actor=bob)["bytes"] == data + ) + + +def test_apng_corrupt_later_frame_is_rejected(scenario): + upload(scenario, broken_later_frame(apng()), "image/png", 415) + + +def test_valid_small_apng_is_accepted_and_unchanged(scenario): + data = apng() + attachment = upload(scenario, data, "image/png", 201)["json"] + c, _, bob, _, _ = scenario + assert ( + c.call("GET", f"/api/v1/attachments/{attachment['id']}/content", actor=bob)["bytes"] == data + ) + + +def test_apng_cumulative_canvas_limit(scenario): + # Two 25M-pixel canvases exceed the total 40M decode budget. + upload(scenario, apng((5000, 5000)), "image/png", 413) + + +def test_apng_forged_frame_count_cannot_hide_bad_frame(scenario): + data = bytearray(broken_later_frame(apng())) + position = 8 + while position < len(data): + length = struct.unpack(">I", data[position : position + 4])[0] + kind = bytes(data[position + 4 : position + 8]) + if kind == b"acTL": + data[position + 8 : position + 12] = struct.pack(">I", 1) + payload = bytes(data[position + 8 : position + 8 + length]) + data[position + 8 + length : position + 12 + length] = struct.pack( + ">I", zlib.crc32(kind + payload) + ) + break + position += length + 12 + upload(scenario, bytes(data), "image/png", 415) + + +def test_apng_zero_count_with_static_fallback_is_rejected(scenario): + # Pillow warns and falls back to one valid static PNG frame. The raw acTL + # count must still be rejected rather than trusting Pillow's n_frames=1. + data = apng() + result, position, controls = bytearray(data[:8]), 8, 0 + while position < len(data): + length = int.from_bytes(data[position : position + 4], "big") + kind = data[position + 4 : position + 8] + payload = data[position + 8 : position + 8 + length] + position += length + 12 + if kind == b"acTL": + payload = bytes(4) + payload[4:] + if kind == b"fcTL": + controls += 1 + if controls > 1: + continue + if kind == b"fdAT": + continue + result += ( + struct.pack(">I", len(payload)) + + kind + + payload + + struct.pack(">I", zlib.crc32(kind + payload)) + ) + upload(scenario, bytes(result), "image/png", 415) + + +def test_apng_exact_cumulative_limit_is_accepted(scenario): + upload(scenario, apng((4000, 5000)), "image/png", 201) + + +def test_40m_cmyk_progressive_jpeg_is_accepted(scenario): + output = BytesIO() + image = Image.new("CMYK", (8000, 5000), (0, 128, 128, 0)) + try: + image.save(output, "JPEG", quality=90, progressive=True, subsampling=0) + finally: + image.close() + data = output.getvalue() + attachment = upload(scenario, data, "image/jpeg", 201)["json"] + c, _, bob, _, _ = scenario + assert ( + c.call("GET", f"/api/v1/attachments/{attachment['id']}/content", actor=bob)["bytes"] == data + ) + + +def test_repeated_large_image_sequence_stays_available(scenario): + # Formerly retained APNG canvases could overlap the next CMYK decoder. + c, _, bob, _, _ = scenario + data = apng((4000, 5000)) + attachment = upload(scenario, data, "image/png", 201)["json"] + assert ( + c.call("GET", f"/api/v1/attachments/{attachment['id']}/content", actor=bob)["bytes"] == data + ) + del data + test_40m_cmyk_progressive_jpeg_is_accepted(scenario) + test_36m_progressive_jpeg_is_valid_and_unchanged(scenario) + data = BytesIO() + image = Image.new("RGB", (16, 16), "green") + image.save(data, "PNG") + image.close() + attachment = upload(scenario, data.getvalue(), "image/png", 201)["json"] + assert ( + c.call("GET", f"/api/v1/attachments/{attachment['id']}/content", actor=bob)["bytes"] + == data.getvalue() + ) + + +@pytest.mark.parametrize("progressive", [False, True]) +def test_small_cmyk_jpeg(progressive, scenario): + output = BytesIO() + image = Image.new("CMYK", (24, 18), (0, 128, 128, 0)) + image.save(output, "JPEG", progressive=progressive) + image.close() + upload(scenario, output.getvalue(), "image/jpeg", 201) + + +def test_invalid_zero_frame_count_is_rejected(scenario): + data = apng() + result, position, controls = bytearray(data[:8]), 8, 0 + while position < len(data): + length = struct.unpack(">I", data[position : position + 4])[0] + kind = data[position + 4 : position + 8] + payload = data[position + 8 : position + 8 + length] + position += length + 12 + if kind == b"fcTL": + controls += 1 + if controls > 1: + continue + if kind == b"fdAT": + continue + if kind == b"acTL": + payload = bytes(4) + payload[4:] + result += ( + struct.pack(">I", len(payload)) + + kind + + payload + + struct.pack(">I", zlib.crc32(kind + payload)) + ) + upload(scenario, bytes(result), "image/png", 415) + + +def test_valid_apng_default_image(scenario): + upload(scenario, apng(default_image=True), "image/png", 201) diff --git a/student-tests/test_jobs.py b/student-tests/test_jobs.py new file mode 100644 index 0000000..ef1053b --- /dev/null +++ b/student-tests/test_jobs.py @@ -0,0 +1,72 @@ +import json + +import pytest + +from messenger.worker import validate_delivery + +VALID = { + "schema_version": 1, + "job_id": "11111111-1111-4111-8111-111111111111", + "type": "attachment.process.v1", + "attachment_id": "22222222-2222-4222-8222-222222222222", + "pipeline_version": 1, + "attempt": 1, + "created_at": "2026-11-06T00:00:00Z", +} + + +@pytest.mark.parametrize( + "key,value", + [ + ("job_id", 123), + ("job_id", []), + ("attachment_id", {}), + ("schema_version", True), + ("pipeline_version", True), + ("attempt", 0), + ("created_at", 123), + ("created_at", "2026-11-06"), + ("created_at", "2026-11-06T12Z"), + ("created_at", "2026-99-99T00:00:00Z"), + ("traceparent", 123), + ("tracestate", []), + ], +) +def test_invalid_envelopes_are_bounded_validation_errors(key, value): + with pytest.raises(ValueError): + validate_delivery(json.dumps({**VALID, key: value})) + + +@pytest.mark.parametrize("body", [b"\xff", "null", "[]", "{}", "not json"]) +def test_invalid_json(body): + with pytest.raises(ValueError): + validate_delivery(body) + + +def test_valid_trace_context(): + body = { + **VALID, + "traceparent": "00-" + "a" * 32 + "-" + "b" * 16 + "-01", + "tracestate": "test=value", + } + assert validate_delivery(json.dumps(body)) == body + + +@pytest.mark.parametrize( + "body", ["[" * 2000 + "]" * 2000, "[" * 20000 + "]" * 20000, b" " * 8193 + b"{}"] +) +def test_deep_and_oversize_envelopes_reject_safely(body): + with pytest.raises(ValueError): + validate_delivery(body) + + +def test_uuid_uppercase_is_normalized_before_storage(): + value = "AAAAAAAA-AAAA-4AAA-8AAA-AAAAAAAAAAAA" + parsed = validate_delivery(json.dumps({**VALID, "job_id": value, "attachment_id": value})) + assert parsed["job_id"] == parsed["attachment_id"] == value.lower() + + +@pytest.mark.parametrize("field", ["job_id", "attachment_id"]) +def test_uuid_urn_is_rejected_before_storage(field): + with pytest.raises(ValueError): + validate_delivery(json.dumps({**VALID, field: "urn:uuid:" + VALID[field]})) diff --git a/student-tests/test_json_encoding.py b/student-tests/test_json_encoding.py new file mode 100644 index 0000000..fe81fd6 --- /dev/null +++ b/student-tests/test_json_encoding.py @@ -0,0 +1,169 @@ +import base64 +import codecs +import json +import os +import uuid +from uuid import uuid4 + +import pytest +from client import Client + +ENCODINGS = [ + "utf-16", + "utf-16-le", + "utf-16-be", + "utf-16-be-bom", + "utf-32", + "utf-32-le", + "utf-32-be", + "utf-32-be-bom", +] + + +def encoded(body, encoding): + text = json.dumps(body, ensure_ascii=False) + if encoding == "utf-16-be-bom": + return codecs.BOM_UTF16_BE + text.encode("utf-16-be") + if encoding == "utf-32-be-bom": + return codecs.BOM_UTF32_BE + text.encode("utf-32-be") + return text.encode(encoding) + + +@pytest.fixture(scope="module") +def encoding_scenario(): + c = Client(os.environ["BASE_URL"]) + return c, *c.bootstrap() + + +@pytest.mark.parametrize("encoding", ENCODINGS) +def test_non_utf8_registration_has_no_write(encoding_scenario, encoding): + c, *_ = encoding_scenario + body = { + "username": "enc_" + uuid.uuid4().hex[:14], + "display_name": "Никита\u0000имя", + "password": "Пароль:тестовый-12345", + } + c.call( + "POST", + "/api/v1/users", + 400, + raw=encoded(body, encoding), + headers={"Content-Type": "application/json"}, + ) + # UNIQUE username proves the rejected request did not insert a user. + created = c.call("POST", "/api/v1/users", 201, body=body, schema="User")["json"] + assert created["display_name"] == body["display_name"] + + +@pytest.mark.parametrize("encoding", ENCODINGS) +def test_non_utf8_chat_has_no_write(encoding_scenario, encoding): + c, alice, *_ = encoding_scenario + before = c.call("GET", "/api/v1/chats?limit=100", actor=alice, schema="ChatPage")["json"] + body = {"title": "Чат\u0000" + uuid.uuid4().hex, "member_ids": [alice["id"]]} + c.call( + "POST", + "/api/v1/chats", + 400, + actor=alice, + raw=encoded(body, encoding), + headers={"Content-Type": "application/json"}, + ) + after = c.call("GET", "/api/v1/chats?limit=100", actor=alice, schema="ChatPage")["json"] + assert before == after + assert ( + c.call("POST", "/api/v1/chats", 201, actor=alice, body=body, schema="Chat")["json"]["title"] + == body["title"] + ) + + +@pytest.mark.parametrize("encoding", ENCODINGS) +def test_non_utf8_message_has_no_write(encoding_scenario, encoding): + c, alice, _, _, chat = encoding_scenario + path = f"/api/v1/chats/{chat['id']}/messages" + key = uuid.uuid4().hex + body = {"text": "Сообщение\u0000" + key} + c.call( + "POST", + path, + 400, + actor=alice, + raw=encoded(body, encoding), + headers={"Content-Type": "application/json", "Idempotency-Key": key}, + ) + history = c.call("GET", path + "?limit=100", actor=alice, schema="MessagePage")["json"]["items"] + assert all(item["text"] != body["text"] for item in history) + good = c.call( + "POST", + path, + 201, + actor=alice, + body=body, + headers={"Idempotency-Key": key}, + schema="Message", + )["json"] + repeat = c.call( + "POST", + path, + 201, + actor=alice, + body=body, + headers={"Idempotency-Key": key}, + schema="Message", + )["json"] + assert good == repeat and good["text"] == body["text"] + + +@pytest.mark.parametrize("encoding", ["utf-8", "utf-8-sig"]) +def test_valid_utf8_registration_and_login(encoding_scenario, encoding): + c, *_ = encoding_scenario + body = { + "username": "utf8_" + uuid.uuid4().hex[:14], + "display_name": "Юникод\u0000😀", + "password": "Пароль:тестовый-12345", + } + user = c.call( + "POST", + "/api/v1/users", + 201, + raw=encoded(body, encoding), + headers={"Content-Type": "application/json"}, + schema="User", + )["json"] + assert user["display_name"] == body["display_name"] + credential = base64.b64encode((body["username"] + ":" + body["password"]).encode()).decode() + session = c.call( + "POST", + "/api/v1/auth/sessions", + 201, + headers={"Authorization": "Basic " + credential}, + schema="Session", + )["json"] + assert session["user"] == user + + +def requests_for(alice, chat): + return [ + ( + "/api/v1/users", + { + "username": "utf_" + uuid4().hex[:12], + "display_name": "Имя\0", + "password": "synthetic-password-123", + }, + ), + ("/api/v1/chats", {"title": "Чат\0", "member_ids": [alice["id"]]}), + (f"/api/v1/chats/{chat['id']}/messages", {"text": "Сообщение\0"}), + ] + + +def test_utf8_and_escaped_nul_remain_valid(encoding_scenario): + c, alice, _, _, chat = encoding_scenario + for path, body in requests_for(alice, chat): + c.call( + "POST", + path, + 201, + actor=alice, + raw=json.dumps(body, ensure_ascii=False).encode("utf-8"), + headers={"Content-Type": "application/json", "Idempotency-Key": uuid4().hex}, + ) diff --git a/student-tests/test_pipeline.py b/student-tests/test_pipeline.py new file mode 100644 index 0000000..90d4ef0 --- /dev/null +++ b/student-tests/test_pipeline.py @@ -0,0 +1,46 @@ +from io import BytesIO + +import pytest +from PIL import Image + +from messenger.image_pipeline import fitted_size, render + + +@pytest.mark.parametrize( + "source,expected", + [((319, 200), (256, 160)), ((320, 200), (256, 160)), ((10, 4), (10, 4)), ((1, 1000), (1, 256))], +) +def test_fits_contract(source, expected): + assert fitted_size(*source, 256) == expected + + +def test_variants_alpha_and_metadata(tmp_path): + source = BytesIO() + Image.new("RGBA", (319, 200), (255, 0, 0, 0)).save(source, "PNG") + source.seek(0) + variants = render(source, tmp_path) + assert {v["name"] for v in variants} == {"thumbnail", "crop", "optimized"} + with Image.open(tmp_path / "thumbnail") as thumb: + assert thumb.format == "JPEG" + assert thumb.size == (256, 160) + assert all(channel > 245 for channel in thumb.getpixel((0, 0))) + assert not thumb.getexif() + with Image.open(tmp_path / "crop") as crop: + assert crop.size == (128, 128) + with Image.open(tmp_path / "optimized") as optimized: + assert optimized.format == "WEBP" + assert optimized.size == (319, 200) + + +def test_exif_orientation_without_upscale(tmp_path): + source = BytesIO() + exif = Image.Exif() + exif[274] = 6 + Image.new("RGB", (80, 40), "blue").save(source, "JPEG", exif=exif) + original = source.getvalue() + source.seek(0) + render(source, tmp_path) + assert source.getvalue() == original + with Image.open(tmp_path / "thumbnail") as thumbnail: + assert thumbnail.size == (40, 80) + assert not thumbnail.getexif() diff --git a/student-tests/test_sessions.py b/student-tests/test_sessions.py new file mode 100644 index 0000000..0519f81 --- /dev/null +++ b/student-tests/test_sessions.py @@ -0,0 +1,62 @@ +import base64 +import uuid + +import pytest +from client import Client + + +@pytest.mark.parametrize("password", ["x" * 11, "x" * 129, "😀" * 129, 123, None, True]) +def test_password_contract(password): + import os + + c = Client(os.environ["BASE_URL"]) + c.call( + "POST", + "/api/v1/users", + 400, + body={ + "username": "pwd_" + uuid.uuid4().hex[:12], + "display_name": "Тест", + "password": password, + }, + ) + + +def test_full_unicode_password_and_colon(): + import os + + c = Client(os.environ["BASE_URL"]) + username = "pwd_" + uuid.uuid4().hex[:12] + password = "😀" * 126 + ":Я" + user = c.call( + "POST", + "/api/v1/users", + 201, + body={"username": username, "display_name": "Пароль128", "password": password}, + schema="User", + )["json"] + good = base64.b64encode((username + ":" + password).encode()).decode() + session = c.call( + "POST", + "/api/v1/auth/sessions", + 201, + headers={"Authorization": "bAsIc " + good}, + schema="Session", + )["json"] + actor = {"id": user["id"], "token": session["token"]} + assert session["user"] == user + bad = base64.b64encode((username + ":" + password[:-1] + "Б").encode()).decode() + c.call("POST", "/api/v1/auth/sessions", 401, headers={"Authorization": "Basic " + bad}) + c.call("GET", "/api/v1/users/me", 401, headers={"Authorization": "Basic " + good}) + c.call("GET", "/api/v1/users/me", actor=actor, schema="User") + c.call("DELETE", "/api/v1/auth/sessions/current", 204, actor=actor) + c.call("GET", "/api/v1/users/me", 401, actor=actor) + + +@pytest.mark.parametrize("credential", ["Basic !invalid", "Basic", "Bearer abc", "", "Basic YTpi"]) +def test_invalid_basic(credential): + import os + + Client(os.environ["BASE_URL"]).call( + "POST", "/api/v1/auth/sessions", 401, headers={"Authorization": credential} + ) diff --git a/student-tests/test_tls_boundary.py b/student-tests/test_tls_boundary.py new file mode 100644 index 0000000..a1705da --- /dev/null +++ b/student-tests/test_tls_boundary.py @@ -0,0 +1,231 @@ +"""Identity and prefix negative probes use a real local TLS server, no mocked TLS.""" + +import http.client +import json +import socket +import socketserver +import ssl +import threading +from pathlib import Path + +import pytest + +from messenger.tls_gateway import HTTPHandler, HTTPServer, TCPHandler, TCPServer, role + +ROOT = Path(__file__).resolve().parents[1] + + +def cfg(name, allowed, upstream, **extra): + return dict( + cert=str(ROOT / f"secrets/pki/{name}/cert.pem"), + key=str(ROOT / f"secrets/pki/{name}/key.pem"), + ca=str(ROOT / "secrets/ca.pem"), + allowed=allowed, + upstream=upstream, + **extra, + ) + + +def client(identity=None): + ctx = ssl.create_default_context(cafile=str(ROOT / "secrets/ca.pem")) + if identity: + ctx.load_cert_chain( + ROOT / f"secrets/pki/{identity}/cert.pem", ROOT / f"secrets/pki/{identity}/key.pem" + ) + return ctx + + +class Echo(socketserver.BaseRequestHandler): + def handle(self): + while data := self.request.recv(1024): + self.request.sendall(data) + + +@pytest.fixture +def tcp_boundary(monkeypatch, tmp_path): + revoked = tmp_path / "revoked.json" + revoked.write_text("[]") + monkeypatch.setenv("TLS_REVOKED_FILE", str(revoked)) + with socketserver.ThreadingTCPServer(("127.0.0.1", 0), Echo) as echo: + threading.Thread(target=echo.serve_forever, daemon=True).start() + with TCPServer(("127.0.0.1", 0), TCPHandler) as proxy: + proxy.cfg = cfg("api", ["lb"], echo.server_address[1]) + proxy.slots = threading.BoundedSemaphore(32) + threading.Thread(target=proxy.serve_forever, daemon=True).start() + yield proxy.server_address[1], revoked + proxy.shutdown() + echo.shutdown() + + +def exchange(port, ctx, hostname="api"): + with socket.create_connection(("127.0.0.1", port), timeout=2) as raw: + with ctx.wrap_socket(raw, server_hostname=hostname) as conn: + conn.sendall(b"positive") + return conn.recv(1024) + + +def test_allowed_lb_identity(tcp_boundary): + assert exchange(tcp_boundary[0], client("lb")) == b"positive" + + +@pytest.mark.parametrize("identity", [None, "worker", "operator"]) +def test_missing_or_trusted_wrong_identity_denied(tcp_boundary, identity): + try: + result = exchange(tcp_boundary[0], client(identity)) + except (OSError, ssl.SSLError): + result = b"" + assert result == b"" + + +def test_wrong_hostname(tcp_boundary): + with pytest.raises(ssl.SSLCertVerificationError): + exchange(tcp_boundary[0], client("lb"), "wrong-service") + + +def test_empty_ca(tcp_boundary): + ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT) + ctx.load_cert_chain(ROOT / "secrets/pki/lb/cert.pem", ROOT / "secrets/pki/lb/key.pem") + with pytest.raises(ssl.SSLCertVerificationError): + exchange(tcp_boundary[0], ctx) + + +def test_revocation_new_connection(tcp_boundary): + port, revoked = tcp_boundary + assert exchange(port, client("lb")) == b"positive" + cert = ssl._ssl._test_decode_cert(str(ROOT / "secrets/pki/lb/cert.pem")) + revoked.write_text(json.dumps([cert["serialNumber"].lstrip("0").lower()])) + try: + result = exchange(port, client("lb")) + except (OSError, ssl.SSLError): + result = b"" + assert result == b"" + + +@pytest.mark.parametrize( + "method,path,headers", + [ + ("PUT", "/messenger/private/secret", {}), + ("PUT", "/messenger/staging/new", {}), + ("GET", "/other-bucket/secret", {}), + ("GET", "/messenger/staging/../private/secret", {}), + ("GET", "/messenger/staging/%2e%2e/private/secret", {}), + ("GET", "/messenger/staging/%252e%252e/private/secret", {}), + ( + "PUT", + "/messenger/attachments/id/v1/original", + {"x-amz-copy-source": "/messenger/private/secret"}, + ), + ("GET", "/messenger?list-type=2", {}), + ("GET", "https://storage:8443/messenger/staging/id", {}), + ("GET", "/messenger/staging/id#fragment", {}), + ], +) +def test_worker_prefix_and_copy_bypasses_denied(tmp_path, monkeypatch, method, path, headers): + revoked = tmp_path / "revoke.json" + revoked.write_text("[]") + monkeypatch.setenv("TLS_REVOKED_FILE", str(revoked)) + with HTTPServer(("127.0.0.1", 0), HTTPHandler) as proxy: + proxy.cfg = cfg("storage", ["api", "worker", "operator"], 1, http=True, s3=True) + proxy.slots = threading.BoundedSemaphore(32) + threading.Thread(target=proxy.serve_forever, daemon=True).start() + conn = http.client.HTTPSConnection( + "127.0.0.1", proxy.server_address[1], context=client("worker"), timeout=2 + ) + conn.request(method, path, headers={"Host": "storage:8443", **headers}) + assert conn.getresponse().status == 403 + conn.close() + proxy.shutdown() + + +def test_exactly_one_allowed_san(): + with pytest.raises(ssl.SSLError): + role({"subjectAltName": [("DNS", "worker"), ("DNS", "lb")]}, ["lb", "worker"]) + + +def test_expired_certificate_rejected(tcp_boundary, tmp_path): + import subprocess + import time + + cert = tmp_path / "expired.pem" + subprocess.run( + [ + "openssl", + "x509", + "-req", + "-in", + str(ROOT / "operator-private/worker.csr"), + "-CA", + str(ROOT / "operator-private/ca.pem"), + "-CAkey", + str(ROOT / "operator-private/ca-key.pem"), + "-set_serial", + "999999", + "-days", + "0", + "-extfile", + str(ROOT / "operator-private/worker.ext"), + "-out", + str(cert), + ], + check=True, + capture_output=True, + ) + time.sleep(1) + ctx = client() + ctx.load_cert_chain(cert, ROOT / "secrets/pki/worker/key.pem") + try: + result = exchange(tcp_boundary[0], ctx) + except (OSError, ssl.SSLError): + result = b"" + assert result == b"" + + +def test_http_forward_preserves_object_bytes(tmp_path, monkeypatch): + from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer + + class Object(BaseHTTPRequestHandler): + def do_GET(self): + body = b"original-bytes" + self.send_response(200) + self.send_header("Content-Length", str(len(body))) + self.end_headers() + self.wfile.write(body) + + def log_message(self, *_): + pass + + revoked = tmp_path / "revoked.json" + revoked.write_text("[]") + monkeypatch.setenv("TLS_REVOKED_FILE", str(revoked)) + with ThreadingHTTPServer(("127.0.0.1", 0), Object) as upstream: + threading.Thread(target=upstream.serve_forever, daemon=True).start() + with HTTPServer(("127.0.0.1", 0), HTTPHandler) as proxy: + proxy.cfg = cfg("storage", ["worker"], upstream.server_address[1], http=True, s3=True) + proxy.slots = threading.BoundedSemaphore(32) + threading.Thread(target=proxy.serve_forever, daemon=True).start() + conn = http.client.HTTPSConnection( + "127.0.0.1", proxy.server_address[1], context=client("worker"), timeout=2 + ) + conn.request("GET", "/messenger/staging/id", headers={"Host": "storage:8443"}) + response = conn.getresponse() + assert response.status == 200 + assert response.read() == b"original-bytes" + conn.close() + proxy.shutdown() + upstream.shutdown() + + +def test_revocation_existing_connection_before_next_command(tcp_boundary): + port, revoked = tcp_boundary + with socket.create_connection(("127.0.0.1", port), timeout=2) as raw: + with client("lb").wrap_socket(raw, server_hostname="api") as conn: + conn.sendall(b"before-revocation") + assert conn.recv(1024) == b"before-revocation" + cert = ssl._ssl._test_decode_cert(str(ROOT / "secrets/pki/lb/cert.pem")) + revoked.write_text(json.dumps([cert["serialNumber"].lstrip("0").lower()])) + try: + conn.sendall(b"must-not-forward") + data = conn.recv(1024) + except OSError: + data = b"" + assert data == b"" diff --git a/uv.lock b/uv.lock new file mode 100644 index 0000000..04920ac --- /dev/null +++ b/uv.lock @@ -0,0 +1,1001 @@ +version = 1 +revision = 3 +requires-python = "==3.12.*" + +[[package]] +name = "annotated-doc" +version = "0.0.5" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/5a/8e/38aa427ed5402449e226975b649c5dc73ccadfefeb95e6aecb8f8ea4b6b6/annotated_doc-0.0.5.tar.gz", hash = "sha256:c7e58ce09192557605d8bbd92836d7e1d520ac9580096042c0bfd197efacf1bb", size = 10758, upload-time = "2026-07-28T13:50:58.129Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/3e/30/e900b21425a860e195f32e37657aa1f7c7f2b1bfb26f03ca209b90933c06/annotated_doc-0.0.5-py3-none-any.whl", hash = "sha256:117bac03a25ede5df5440e855b32d556049ca169ead221505badf432fed4b101", size = 5302, upload-time = "2026-07-28T13:50:57.239Z" }, +] + +[[package]] +name = "annotated-types" +version = "0.8.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/5f/56/a8120250d128bed162cd73c76d45f6ef9991f3e068f62a8ee060afa3104a/annotated_types-0.8.0.tar.gz", hash = "sha256:13b2beaad985e05e2d6407ee4c4f35590b11f8d693a258a561055cac8f64cab7", size = 15893, upload-time = "2026-07-23T20:16:13.995Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/99/91/8acff4f5e50511b911bbccb72b8628a49c68ce14148cd9f6431094859a90/annotated_types-0.8.0-py3-none-any.whl", hash = "sha256:f072f4d804ea359e4eaf198b1af7a8b0943881a87f31bb764f8bf219bb9419e0", size = 13427, upload-time = "2026-07-23T20:16:12.938Z" }, +] + +[[package]] +name = "anyio" +version = "4.15.1" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "idna" }, + { name = "typing-extensions" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/a9/d2/f4d173e22df740bc37b1db102b386ba719b66e95b0f0d751f556b387e6d2/anyio-4.15.1.tar.gz", hash = "sha256:9f28306018cbd6d329e64a36d58256edff76dd996fe423bc957326e578b82a94", size = 276966, upload-time = "2026-09-05T10:42:39.44Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/12/b8/4bd346e22b28902df4d651910f5242c28d84e4a5c2435ca5c3f797ed7e2e/anyio-4.15.1-py3-none-any.whl", hash = "sha256:6152fdbbf9a77fdec97731721bebf7c4c44f7c29b424b0065826173efc7ed101", size = 132079, upload-time = "2026-09-05T10:42:37.923Z" }, +] + +[[package]] +name = "argon2-cffi" +version = "25.1.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "argon2-cffi-bindings" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/0e/89/ce5af8a7d472a67cc819d5d998aa8c82c5d860608c4db9f46f1162d7dab9/argon2_cffi-25.1.0.tar.gz", hash = "sha256:694ae5cc8a42f4c4e2bf2ca0e64e51e23a040c6a517a85074683d3959e1346c1", size = 45706, upload-time = "2025-06-03T06:55:32.073Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/4f/d3/a8b22fa575b297cd6e3e3b0155c7e25db170edf1c74783d6a31a2490b8d9/argon2_cffi-25.1.0-py3-none-any.whl", hash = "sha256:fdc8b074db390fccb6eb4a3604ae7231f219aa669a2652e0f20e16ba513d5741", size = 14657, upload-time = "2025-06-03T06:55:30.804Z" }, +] + +[[package]] +name = "argon2-cffi-bindings" +version = "26.1.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "cffi" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/0b/43/bb8b6e8708d49a5ab36781333af092d9f483b198a2710d01281204640055/argon2_cffi_bindings-26.1.0.tar.gz", hash = "sha256:63505c71542a44b68b1e38060450fb006404170da375feb31af153e7f9c6205d", size = 1790807, upload-time = "2026-08-20T07:44:22.492Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/e7/d2/0ae991f1b2181e5be49007c574710a800ad36c2978683addb3e67c474e55/argon2_cffi_bindings-26.1.0-cp310-abi3-macosx_11_0_arm64.whl", hash = "sha256:21ca0396fe5ec995dd54431c32698189666f9224810acfa752e50d2bd94d9df2", size = 25521, upload-time = "2026-08-20T07:32:43.019Z" }, + { url = "https://files.pythonhosted.org/packages/7e/e4/ad91d8297638aa2258aad4501c306aca99480dfe76ccd638173fa3702db9/argon2_cffi_bindings-26.1.0-cp310-abi3-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:78de2d65e0b9ea7ce9d1b1c3e87297b2d7305a02c266ee2a2d6910daddd7ee69", size = 27177, upload-time = "2026-08-20T07:32:44.158Z" }, + { url = "https://files.pythonhosted.org/packages/6f/86/5363df11b86d02cf3662208e7406496327649cc90eb365bf6f4e8a54a41f/argon2_cffi_bindings-26.1.0-cp310-abi3-manylinux_2_26_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:27f1821903e2ceadcb88ec2b45ef190897b7682449c772f4d9b53e42c520cf29", size = 26597, upload-time = "2026-08-20T07:32:45.172Z" }, + { url = "https://files.pythonhosted.org/packages/f4/b5/a14dcc592652347dad23ee93b278a4da5d2a25c9ed3ebd10d68eea823a4f/argon2_cffi_bindings-26.1.0-cp310-abi3-manylinux_2_34_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:d88e5f7e60f28ae0b0cc6b2f16c43e87cd642a196a86f85e0d8bb6fe016fc16d", size = 27403, upload-time = "2026-08-20T07:32:46.13Z" }, + { url = "https://files.pythonhosted.org/packages/b3/81/b4a20d4902af7f796390bf9245ff83c5217dfa7367efa1d14986956c482b/argon2_cffi_bindings-26.1.0-cp310-abi3-musllinux_1_2_aarch64.whl", hash = "sha256:34b7d9c24a4165a2c61cc8ae11d44d48c9ce2830fb536cb7914e11fdd9962728", size = 27132, upload-time = "2026-08-20T07:32:47.13Z" }, + { url = "https://files.pythonhosted.org/packages/7e/1b/c8de358af07b1c490e0fcb863ef98e46ddb486e45567aca5a60bd68d9daa/argon2_cffi_bindings-26.1.0-cp310-abi3-musllinux_1_2_riscv64.whl", hash = "sha256:224865cbbcb7a2bd1356741dff12b0134df726b6d44bb7b500df8e303cbd9e81", size = 27588, upload-time = "2026-08-20T07:32:48.087Z" }, + { url = "https://files.pythonhosted.org/packages/48/2f/7ee62a6e79f9309f9d9982d301b22a00010adb580c05c8109b94d7b33de0/argon2_cffi_bindings-26.1.0-cp310-abi3-musllinux_1_2_x86_64.whl", hash = "sha256:ffff613aaa9ce6236766e2fc6dc560bb5abde7a2e2416e3db1f9ae395a2b4dd4", size = 26785, upload-time = "2026-08-20T07:32:48.977Z" }, + { url = "https://files.pythonhosted.org/packages/e9/10/960d0ee93d4897741bcaf4799c697dae2d81499f66fd1ed042a7dd54c1f4/argon2_cffi_bindings-26.1.0-cp310-abi3-win32.whl", hash = "sha256:a86c069c91a747a2c4e5c51473590aeb48172fff9b2130d23729a42d98665ecb", size = 23898, upload-time = "2026-08-20T07:32:50.114Z" }, + { url = "https://files.pythonhosted.org/packages/6d/3a/0cc14a05810e6add9bce5e87693334baa2222de5f647fa31781885b6573f/argon2_cffi_bindings-26.1.0-cp310-abi3-win_amd64.whl", hash = "sha256:2c36ff87b5dfaa477d0bd51e9d7f6abdae7c8955d2983c97419085d842154b3e", size = 25730, upload-time = "2026-08-20T07:32:51.091Z" }, + { url = "https://files.pythonhosted.org/packages/4e/db/d83cf2af140547f0b9cdaece05b2dc2dcbf991be4667331d073eff771435/argon2_cffi_bindings-26.1.0-cp310-abi3-win_arm64.whl", hash = "sha256:f9c4420a7a864fe1b86ce35befc95b8e39fb852493b81cf798671ddc265de638", size = 24478, upload-time = "2026-08-20T07:32:52.111Z" }, +] + +[[package]] +name = "attrs" +version = "26.1.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/9a/8e/82a0fe20a541c03148528be8cac2408564a6c9a0cc7e9171802bc1d26985/attrs-26.1.0.tar.gz", hash = "sha256:d03ceb89cb322a8fd706d4fb91940737b6642aa36998fe130a9bc96c985eff32", size = 952055, upload-time = "2026-03-19T14:22:25.026Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/64/b4/17d4b0b2a2dc85a6df63d1157e028ed19f90d4cd97c36717afef2bc2f395/attrs-26.1.0-py3-none-any.whl", hash = "sha256:c647aa4a12dfbad9333ca4e71fe62ddc36f4e63b2d260a37a8b83d2f043ac309", size = 67548, upload-time = "2026-03-19T14:22:23.645Z" }, +] + +[[package]] +name = "boto3" +version = "1.43.125" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "botocore" }, + { name = "jmespath" }, + { name = "s3transfer" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/f2/c2/9285c749ca49c213ad90aa239884d0c5cbbdc58f02c4c44bcc4a3bf59023/boto3-1.43.125.tar.gz", hash = "sha256:5a635a0fbbd51f319e465b809cf043668705defbb9dddaf26ae66747f70b2a49", size = 112651, upload-time = "2026-11-05T20:24:13.843Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/b5/12/1e295c564a8319e6e27353c4c849ec31b0e3857b2614c36c7cc050ca1b9c/boto3-1.43.125-py3-none-any.whl", hash = "sha256:101fe3ee99664e671efb9af65c8e98ec0bceddf6de922ea89685da4adc8c6907", size = 140043, upload-time = "2026-11-05T20:24:12.048Z" }, +] + +[[package]] +name = "botocore" +version = "1.43.125" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "jmespath" }, + { name = "python-dateutil" }, + { name = "urllib3" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/ad/57/6d638614c940c73a750b8a4203989b3edbde5ff7f83cd9031e65cb97d69b/botocore-1.43.125.tar.gz", hash = "sha256:e3ae5ebbfa8033015958a9cb16cef67a0592902ca8afb46ef06e8ae77475183f", size = 16520959, upload-time = "2026-11-05T20:24:08.59Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/3a/c1/0dca9a7ea362219b1e98f7fa8aebca1c19f6516eb91792b82595d7b79dc0/botocore-1.43.125-py3-none-any.whl", hash = "sha256:e3969c8191d3435440037310187d324f37c00da53987ea31df2eceff19a2795a", size = 16223768, upload-time = "2026-11-05T20:24:04.594Z" }, +] + +[[package]] +name = "certifi" +version = "2026.10.23" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/fd/11/b524cbd9bbdaca58608e4cf4053fd463417549e1959fa8d3aa18319f9555/certifi-2026.10.23.tar.gz", hash = "sha256:a9895e6e2758b371e0545e321a3a8fd1fcfd9829ada8824a936dfb16aaaf36cd", size = 136225, upload-time = "2026-10-23T11:36:16.478Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/32/d1/a3652fe2c19134d0d15922177821d863cbd7e842d53a21bbe7e8e3a1b5ac/certifi-2026.10.23-py3-none-any.whl", hash = "sha256:e9b54de76e530bb6cf0ccd036787103acb58fd42ba930ea8bf948ddbaa2f61d1", size = 135082, upload-time = "2026-10-23T11:36:14.763Z" }, +] + +[[package]] +name = "cffi" +version = "2.1.1" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "pycparser", marker = "implementation_name != 'PyPy'" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/9e/ef/008a1939e372c06329a3fce4279c02f328488f3526744906eeec3da7ad5f/cffi-2.1.1.tar.gz", hash = "sha256:dd31f52ea1086513bb9df30f8fcee9b8918323ae067a3d5b78bc826a000712be", size = 530807, upload-time = "2026-08-03T21:21:18.939Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/10/69/43965eccfdead3b9220015fd1320e117be8c6ed01a62ffab76eeb752f5d5/cffi-2.1.1-cp312-cp312-macosx_10_15_x86_64.whl", hash = "sha256:c8c69575568085ba0b1b10c0249d779a214aea6f6522e949a0fc9fb0fcb449d0", size = 184821, upload-time = "2026-08-03T21:19:44.887Z" }, + { url = "https://files.pythonhosted.org/packages/54/7d/16e5a096677b5e313ca80cd5e5170efa3ea44624a82bb111925522da64b1/cffi-2.1.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:f81b3b8f3d4e343550fa4baa0e479bba9f2d29ce9c2e9b51d1ce1718d7442fcf", size = 184719, upload-time = "2026-08-03T21:19:46.129Z" }, + { url = "https://files.pythonhosted.org/packages/56/e6/8941622732edec876dd17d0453dce07317ae96db34f2ec1436c9d3785986/cffi-2.1.1-cp312-cp312-manylinux1_i686.manylinux2014_i686.manylinux_2_17_i686.manylinux_2_5_i686.whl", hash = "sha256:811bd1e21d32de12efca32393a0ab3f5133b54fce9bd44b8bd77ab07da14bf6a", size = 214799, upload-time = "2026-08-03T21:19:47.218Z" }, + { url = "https://files.pythonhosted.org/packages/44/de/f98430906df1545ffde0d543dd124a7a439bc2cd32b36b9c53f805df7333/cffi-2.1.1-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:68e62fe11f30d5ca8289242866f0a5291402d8529ca2178ab8afc5c9694ae890", size = 222389, upload-time = "2026-08-03T21:19:48.331Z" }, + { url = "https://files.pythonhosted.org/packages/6a/5b/717f1526b9957b34456313c31645c5b82b8fb5c3fe9e4752999be7128bfc/cffi-2.1.1-cp312-cp312-manylinux2014_ppc64le.manylinux_2_17_ppc64le.whl", hash = "sha256:4a7c934f7360e8cd64fe9efadcbd10c7c6364f531e432b9a4bf5ccbc9e0e8b50", size = 210249, upload-time = "2026-08-03T21:19:49.543Z" }, + { url = "https://files.pythonhosted.org/packages/64/b3/f8aa4f3e34986c7e4ec45072d1b1b9dd295b6b18007b45518d79726dd725/cffi-2.1.1-cp312-cp312-manylinux2014_s390x.manylinux_2_17_s390x.whl", hash = "sha256:3143d81e29e1e20a9ce10901ec369012947876596f75a222235965f2b7ae832e", size = 208775, upload-time = "2026-08-03T21:19:50.918Z" }, + { url = "https://files.pythonhosted.org/packages/b1/db/dceb9dd5b231e1da801793f8acc9f3c52a7e1afe40bb1aae37e02b0faad5/cffi-2.1.1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:c1453022f490d2459a11819d83ad1d586e9ff65a12ac3e705ffebd46d3685dcf", size = 221822, upload-time = "2026-08-03T21:19:52.054Z" }, + { url = "https://files.pythonhosted.org/packages/a0/d2/6cd24ae3be000a634109c247d1475d62e5616d0dc78c82770942ec384248/cffi-2.1.1-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:208f941bb9d18e768138677f0a6d2ce01f590df56043dda1df1535ac57c88517", size = 225232, upload-time = "2026-08-03T21:19:53.109Z" }, + { url = "https://files.pythonhosted.org/packages/cb/52/3fa190537004dd7f0ab860a6dc7c0175b8667f68d1e618a46f5498d30250/cffi-2.1.1-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:210019b6c7cf07f081b4c54635c8cf744377001350e29cc0f81c4377b4797735", size = 223597, upload-time = "2026-08-03T21:19:54.515Z" }, + { url = "https://files.pythonhosted.org/packages/80/fb/0bb75b7039588c074b37ae99f40d9bfddf990ecb2fbc346ebccd2e56b9be/cffi-2.1.1-cp312-cp312-win32.whl", hash = "sha256:046bfc24911b37851ee1b51aab8bffe713d89c68c6a057b09484ce9fd5f69b4e", size = 175292, upload-time = "2026-08-03T21:19:55.566Z" }, + { url = "https://files.pythonhosted.org/packages/d9/79/615cc094e2fb508cade7de88d3b4f6c4ec2bab695c97bce9153dc65aadf5/cffi-2.1.1-cp312-cp312-win_amd64.whl", hash = "sha256:f53e442b08449d42821fa4a4fba000095af9f62742a500f978a9f557ec44339a", size = 185919, upload-time = "2026-08-03T21:19:56.89Z" }, + { url = "https://files.pythonhosted.org/packages/70/c6/d0ea84713fe46b243a436a18fcd47d639732747e21635c8a27191b06dc30/cffi-2.1.1-cp312-cp312-win_arm64.whl", hash = "sha256:7bde5e4cc5c10140859842b9d383af292b22639a4dffb725314baf45968cef80", size = 180093, upload-time = "2026-08-03T21:19:58.155Z" }, +] + +[[package]] +name = "charset-normalizer" +version = "3.5.2" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/33/1c/f41d4e74c28ab327ff3acd36053f7ea506c55872d7a90b0fa71aa3ab0c89/charset_normalizer-3.5.2.tar.gz", hash = "sha256:39de2a259fc954455c57274dc94c79d5842774e1247a016aff30bc0efed0f4ef", size = 172659, upload-time = "2026-09-30T04:39:23.398Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/e7/c8/693809898870237d82785a03f3b2b58fe4c9f14669f84a7d4e623c92a59e/charset_normalizer-3.5.2-cp312-cp312-macosx_10_13_universal2.whl", hash = "sha256:ed2a239c0ea213acc1908150a3037257083c7c083128f1a4cec2ec4b97dca491", size = 367780, upload-time = "2026-09-30T04:35:30.888Z" }, + { url = "https://files.pythonhosted.org/packages/c9/87/2fea8c13dc24b3ca9c6f803a5b2dfdeae73eb4f9e12c7885ed908ff0433c/charset_normalizer-3.5.2-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:b91363207bd9dc966a691e959bb47f64b30f7ac4b072be9968b366982f7db77c", size = 246730, upload-time = "2026-09-30T04:35:32.286Z" }, + { url = "https://files.pythonhosted.org/packages/a8/9e/09efac30b937722f46d3110ba30b875b24b2e3a266ed746cc4e376a94d80/charset_normalizer-3.5.2-cp312-cp312-manylinux2014_armv7l.manylinux_2_17_armv7l.manylinux_2_31_armv7l.whl", hash = "sha256:38a873987f3be698494da8b2e3085e29da02da7b633dce73e79c699a113d7bf0", size = 237707, upload-time = "2026-09-30T04:35:33.709Z" }, + { url = "https://files.pythonhosted.org/packages/9e/18/70d76670b13686237863a379928d60bd10e021f17d243ab3d7014c4a5f4e/charset_normalizer-3.5.2-cp312-cp312-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:355ad8011081dec5412240c087a9a0c9d4d5039f3ed11a3f13e18c2b29b56c51", size = 273050, upload-time = "2026-09-30T04:35:35.138Z" }, + { url = "https://files.pythonhosted.org/packages/54/e2/77a8b09d5adc013ed07b95b01b8b8fa5441c4e810e83ee7e4aae2fa4d91a/charset_normalizer-3.5.2-cp312-cp312-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:ee21e28f0430bd6dc9086c6e525d5e818a44a5ad19720c8a0ef766792f3eb5e5", size = 270345, upload-time = "2026-09-30T04:35:36.502Z" }, + { url = "https://files.pythonhosted.org/packages/7f/c5/38806a25ab5e65fc178f39affeda20858efafede2fce1ffc2556cfc9fe73/charset_normalizer-3.5.2-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:3d31298449090ab8d47b7b1b2a555ff73cac7ed438a08b7ac160980c7ebed649", size = 257601, upload-time = "2026-09-30T04:35:37.919Z" }, + { url = "https://files.pythonhosted.org/packages/ae/8d/213565184708fdb263ae55e2c04ee1ff748129dd65d48ed0e3502da9c85a/charset_normalizer-3.5.2-cp312-cp312-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:5cde776b7cc66e4f6c99612cea4aa7269aa65863f7a15841b2c264f103822f4e", size = 252222, upload-time = "2026-09-30T04:35:39.544Z" }, + { url = "https://files.pythonhosted.org/packages/7e/24/76d2cefc25472531e4c5c7dfff68865eb1c39b78482f0fdc15b46f047830/charset_normalizer-3.5.2-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:ae4f5fea5b8b8ccff88238cc8569303e5ee95efae67fa62922a311397a71f346", size = 248482, upload-time = "2026-09-30T04:35:41.088Z" }, + { url = "https://files.pythonhosted.org/packages/7d/dc/65a801b66ab4c197e22c433ab25e7ac24324ac6f45a2269aca42cce309bf/charset_normalizer-3.5.2-cp312-cp312-musllinux_1_2_armv7l.whl", hash = "sha256:f7d486c83842422badd511868fd8a9a20e9407ace71564b6af47ce7e60a336c1", size = 241206, upload-time = "2026-09-30T04:35:42.59Z" }, + { url = "https://files.pythonhosted.org/packages/a7/95/ca9b5eabde673002c6f1e7ada1b223916fe18f6d661da7aabd4d643718f1/charset_normalizer-3.5.2-cp312-cp312-musllinux_1_2_ppc64le.whl", hash = "sha256:11a4d68a6ecda3292cb1e50239e111543ba5d709bb62a6b4ea1afcfa729d8875", size = 273190, upload-time = "2026-09-30T04:35:44.347Z" }, + { url = "https://files.pythonhosted.org/packages/2d/8b/803b4d2a3f6e1740f63f1e87b04d14b42f3d4fdfe6ed7d4db2d34102b14f/charset_normalizer-3.5.2-cp312-cp312-musllinux_1_2_riscv64.whl", hash = "sha256:d6734d2ef8a50fbf8445c139477da401f50d62a0606bf00e20ec6d87773fefb1", size = 253527, upload-time = "2026-09-30T04:35:45.915Z" }, + { url = "https://files.pythonhosted.org/packages/a9/55/93c0e5dbd085ae0471346026abbe7e0db9ea2d6fea74e51f0b5a46f233a7/charset_normalizer-3.5.2-cp312-cp312-musllinux_1_2_s390x.whl", hash = "sha256:a815775b6c38d4e0ff7bcffbeba67feded90202bb6a226b8dd35f1c855217413", size = 271285, upload-time = "2026-09-30T04:35:47.49Z" }, + { url = "https://files.pythonhosted.org/packages/95/69/0dbd0e0b9b16cfa816cdfcb3e2e3854a1f680dc07fb1245ea125e7448060/charset_normalizer-3.5.2-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:23851fb4e1b85ed3f6c2a27b777cdfe2e19fb5b38429a8faf38c7542b7665869", size = 260010, upload-time = "2026-09-30T04:35:48.996Z" }, + { url = "https://files.pythonhosted.org/packages/58/9d/e7b88e7b1bf403590c3b573277b5e1e488c68c7a6fbacca310a2c324e90c/charset_normalizer-3.5.2-cp312-cp312-win32.whl", hash = "sha256:db19d07e2e0129e974a0e65d0064fc222a446cd5122c2fd4184d2af9fc734a9e", size = 184125, upload-time = "2026-09-30T04:35:50.777Z" }, + { url = "https://files.pythonhosted.org/packages/eb/e6/e6e083884cbcfd49c64865af05027fe7011be7b2d9179524f099a1b611f3/charset_normalizer-3.5.2-cp312-cp312-win_amd64.whl", hash = "sha256:780fbe7cab297b81dad9fb8dc5eb003c0468ffb0d9e5f65068c53a34661a96bc", size = 207486, upload-time = "2026-09-30T04:35:52.194Z" }, + { url = "https://files.pythonhosted.org/packages/c4/e3/017aea0911ada7405a825c7d937eb3a13009664e2f5b38e8c4bbf2abf894/charset_normalizer-3.5.2-cp312-cp312-win_arm64.whl", hash = "sha256:e2af3aad578aa6bd1384bcf4750fc285e5a9de53f40b7d41e5a0bf748edeb2b3", size = 196734, upload-time = "2026-09-30T04:35:53.636Z" }, + { url = "https://files.pythonhosted.org/packages/8c/ab/176fbfd5b64939c55d652366aa5b9ef1d767af207a3aa6ebeb0d226c484d/charset_normalizer-3.5.2-cp37-abi3-macosx_10_9_universal2.whl", hash = "sha256:4275811936e2f06feff5e598fb42a1b7ae852da8e39605211892b56b81a34efd", size = 331815, upload-time = "2026-09-30T04:38:26.216Z" }, + { url = "https://files.pythonhosted.org/packages/7e/84/371eac6b30bdbcbf2d632a1a01809103459216fcaae61b8b8d922c1bfb8a/charset_normalizer-3.5.2-cp37-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl", hash = "sha256:1c50fe28bbc2ced33386f298650d91218076c05420e6cbd790b913adc41659e7", size = 253276, upload-time = "2026-09-30T04:38:28.032Z" }, + { url = "https://files.pythonhosted.org/packages/43/6f/c4fbae58febff71709c51bc7e18fdfa55341dc382704740f9f0cbf03817b/charset_normalizer-3.5.2-cp37-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:d19fbd981a488e22cd04883659ca6b08f50b5974f9fd7c95655ef6a043e5893f", size = 241239, upload-time = "2026-09-30T04:38:29.732Z" }, + { url = "https://files.pythonhosted.org/packages/61/71/458c3f42164a07d0c5210798e9e704b39e540a6793b05aba67f3a35243a9/charset_normalizer-3.5.2-cp37-abi3-manylinux2014_armv7l.manylinux_2_17_armv7l.manylinux_2_31_armv7l.whl", hash = "sha256:0fed1d06615f022ee3b13caf5e8b180cfea32bb2c5aded8a9d44277afc040f93", size = 231121, upload-time = "2026-09-30T04:38:31.462Z" }, + { url = "https://files.pythonhosted.org/packages/09/54/ab9e89367076f6331bb6c65c4bf14a5361fa5191cb6561bf534f18504e1b/charset_normalizer-3.5.2-cp37-abi3-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:838dcc90063569a0448120554591a1d6c4a4ffe11babf048908793154ab86ade", size = 260350, upload-time = "2026-09-30T04:38:33.239Z" }, + { url = "https://files.pythonhosted.org/packages/7c/c1/061431ecc688d9d76602502cb57cc01e691e682c18f1beb45f9673b5bbd2/charset_normalizer-3.5.2-cp37-abi3-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:2ce45c6627b22c47e390bc91a41c3d13032192e699fa0bea96e9671b373d69b0", size = 255430, upload-time = "2026-09-30T04:38:34.865Z" }, + { url = "https://files.pythonhosted.org/packages/8d/1f/20c8949f0676f7ab811abdeb7f4d7f1cbc6e61ff20bef08b44edeb092bc8/charset_normalizer-3.5.2-cp37-abi3-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:0774bf9bf620249fee3e0b8b9fd3065de213be30f3aa94ce2494b3b638949e26", size = 250612, upload-time = "2026-09-30T04:38:36.649Z" }, + { url = "https://files.pythonhosted.org/packages/2b/9e/46f2fa4c431fc98c4ae76a8cb5bdca54e0341e3cfc3fcfd8e82740250818/charset_normalizer-3.5.2-cp37-abi3-musllinux_1_2_aarch64.whl", hash = "sha256:1db38f4c5496827c1a501846d64d14c3b80c7e6714e406cd7dc36a9899fa1011", size = 242083, upload-time = "2026-09-30T04:38:38.26Z" }, + { url = "https://files.pythonhosted.org/packages/bd/39/559be29a0c0f086e0bba6922babd38916cc5e0b58ced4de13ee01ea05508/charset_normalizer-3.5.2-cp37-abi3-musllinux_1_2_armv7l.whl", hash = "sha256:304d8e4d493af723536393eee0c689eb7813f4a474c8b479dee63f1fdd98f621", size = 232738, upload-time = "2026-09-30T04:38:39.81Z" }, + { url = "https://files.pythonhosted.org/packages/ff/6c/387b0e4f756a282831c1d9fc6aeb6c51ca4507ca202767c8de15ce9b12e2/charset_normalizer-3.5.2-cp37-abi3-musllinux_1_2_ppc64le.whl", hash = "sha256:9b7f416ff0978e2f2249330527f0ad6fa02f4932e6199692d3b52da2048c19e4", size = 260703, upload-time = "2026-09-30T04:38:41.346Z" }, + { url = "https://files.pythonhosted.org/packages/96/92/1fdf015f09ef449f50d3ac4b67c90887c9c318b727daa95cc4f866e6521d/charset_normalizer-3.5.2-cp37-abi3-musllinux_1_2_riscv64.whl", hash = "sha256:01077390b03f7988f11d700a2194e69b119741a86b1a638b1db88891e3eced8e", size = 247622, upload-time = "2026-09-30T04:38:42.937Z" }, + { url = "https://files.pythonhosted.org/packages/dc/3c/8e7b8a5671ad5d433669fb2a76f1a0164df2d9b1718b0206bc2a16d840cc/charset_normalizer-3.5.2-cp37-abi3-musllinux_1_2_s390x.whl", hash = "sha256:7e841fb9010836c992c9f12fcbd43a831de93a5f726fc1ccd8ca1d0268c5014c", size = 257500, upload-time = "2026-09-30T04:38:44.604Z" }, + { url = "https://files.pythonhosted.org/packages/b4/f0/45b579df5cabc1d5d53ea1cc35e8437d3ca768c0acccc7041517cb6fbb32/charset_normalizer-3.5.2-cp37-abi3-musllinux_1_2_x86_64.whl", hash = "sha256:9cae88599c7219005d879f98e5ed53341e9a122af585e1091200358a3003d2a0", size = 255100, upload-time = "2026-09-30T04:38:46.289Z" }, + { url = "https://files.pythonhosted.org/packages/31/68/fdec18a343f5fb3f310588dd478b09ac4799e0b187dbade3a8cd776f03ef/charset_normalizer-3.5.2-cp37-abi3-win32.whl", hash = "sha256:01b0c0d2262a9e28e8484a278c7e1b5d650e3ac8cf2683d2967e25899f208bdf", size = 174499, upload-time = "2026-09-30T04:38:47.999Z" }, + { url = "https://files.pythonhosted.org/packages/9d/8a/b618149cc5207943a0242068d7a27897f56a62947b5a039085f2a22029f8/charset_normalizer-3.5.2-cp37-abi3-win_amd64.whl", hash = "sha256:9f56f72050826f63dcee7a7f55b0a77168cb3bfc553fd405e7f8f9ece75a4036", size = 200092, upload-time = "2026-09-30T04:38:49.707Z" }, + { url = "https://files.pythonhosted.org/packages/03/cf/4c66866fa9e2b1c78e3c911516d1de497a677b7ac60f1eceda74ce777ca3/charset_normalizer-3.5.2-cp37-abi3-win_arm64.whl", hash = "sha256:40ab6bffa02ae10a0581e6c198be7d2d8ca5c2a0c64e4ed3465d766df457573e", size = 294363, upload-time = "2026-09-30T04:38:51.312Z" }, + { url = "https://files.pythonhosted.org/packages/fc/ad/d07d7862a62ffa6d79d68074d14823243dd235a77c45262acbf6adeb28bf/charset_normalizer-3.5.2-py3-none-any.whl", hash = "sha256:b6b751274acb69d77b3323d6b7dbaa3c7fdfc1eb829b7eb61d262f32e1af9685", size = 68872, upload-time = "2026-09-30T04:39:21.828Z" }, +] + +[[package]] +name = "click" +version = "8.5.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/c7/0e/7fa0ef50764b67090eca4114772a2abf8b6148198475e54c660b97caeee6/click-8.5.0.tar.gz", hash = "sha256:ba0d2089de75ea0310e2dde03160e6ca10009947fb95a182f9b54021bb272e34", size = 382235, upload-time = "2026-08-26T13:33:14.56Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/58/50/6c0d534c5f134586a8e1ba4e330569e32f057e33372ae556463212fb4cd3/click-8.5.0-py3-none-any.whl", hash = "sha256:255bc9599cf7748b4b1a446ccc735421bd08a2ae529a8b88597d3de5664ee360", size = 125251, upload-time = "2026-08-26T13:33:12.928Z" }, +] + +[[package]] +name = "colorama" +version = "0.4.6" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/d8/53/6f443c9a4a8358a93a6792e2acffb9d9d5cb0a5cfd8802644b7b1c9a02e4/colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44", size = 27697, upload-time = "2022-10-25T02:36:22.414Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/d1/d6/3965ed04c63042e047cb6a3e6ed1a63a35087b6a609aa3a15ed8ac56c221/colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6", size = 25335, upload-time = "2022-10-25T02:36:20.889Z" }, +] + +[[package]] +name = "fastapi" +version = "0.141.1" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "annotated-doc" }, + { name = "pydantic" }, + { name = "starlette" }, + { name = "typing-extensions" }, + { name = "typing-inspection" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/8a/02/91e3416a8fdd715abb903a952a6bec7cdd8d14eed55d415fc8595524c319/fastapi-0.141.1.tar.gz", hash = "sha256:e8822fc40db1e1858054d7a949a888695bc9bdce70139178e33bd2871a453ca1", size = 425799, upload-time = "2026-07-29T17:18:05.568Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/cb/03/10388a42375ee7e4ac9b94eb2c5c569c8b5795e377e701c9ac3ad63de890/fastapi-0.141.1-py3-none-any.whl", hash = "sha256:bfb91aa2d334c61cb35ba9a116fc123b3d3df31640b801cf57a7a78ec3f603b3", size = 131954, upload-time = "2026-07-29T17:18:04.364Z" }, +] + +[[package]] +name = "googleapis-common-protos" +version = "1.76.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "protobuf" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/62/b6/bc095b23a3e0d978e75c8c18cabe4c11f791837410670e4486f0d539bfba/googleapis_common_protos-1.76.0.tar.gz", hash = "sha256:71db0e44a1d4c2dd024ebad44ca67129cc1e2892e4861df466764749d5ef8642", size = 156250, upload-time = "2026-10-22T23:43:36.263Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/05/6d/78dc67a9e779e594b49bf62604034d3a6aa428a55afc729cafda4b7333e1/googleapis_common_protos-1.76.0-py3-none-any.whl", hash = "sha256:59e13344a9f3651aa201a03e2bee815a3bf43a4baf1f9ff8a9b62a840ce25fac", size = 307707, upload-time = "2026-10-22T23:43:10.445Z" }, +] + +[[package]] +name = "h11" +version = "0.16.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/01/ee/02a2c011bdab74c6fb3c75474d40b3052059d95df7e73351460c8588d963/h11-0.16.0.tar.gz", hash = "sha256:4e35b956cf45792e4caa5885e69fba00bdbc6ffafbfa020300e549b208ee5ff1", size = 101250, upload-time = "2025-04-24T03:35:25.427Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/04/4b/29cac41a4d98d144bf5f6d33995617b185d14b22401f75ca86f384e87ff1/h11-0.16.0-py3-none-any.whl", hash = "sha256:63cf8bbe7522de3bf65932fda1d9c2772064ffb3dae62d55932da54b31cb6c86", size = 37515, upload-time = "2025-04-24T03:35:24.344Z" }, +] + +[[package]] +name = "httpcore" +version = "1.0.9" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "certifi" }, + { name = "h11" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/06/94/82699a10bca87a5556c9c59b5963f2d039dbd239f25bc2a63907a05a14cb/httpcore-1.0.9.tar.gz", hash = "sha256:6e34463af53fd2ab5d807f399a9b45ea31c3dfa2276f15a2c3f00afff6e176e8", size = 85484, upload-time = "2025-04-24T22:06:22.219Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/7e/f5/f66802a942d491edb555dd61e3a9961140fd64c90bce1eafd741609d334d/httpcore-1.0.9-py3-none-any.whl", hash = "sha256:2d400746a40668fc9dec9810239072b40b4484b640a8c38fd654a024c7a1bf55", size = 78784, upload-time = "2025-04-24T22:06:20.566Z" }, +] + +[[package]] +name = "httpx" +version = "0.28.1" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "anyio" }, + { name = "certifi" }, + { name = "httpcore" }, + { name = "idna" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/b1/df/48c586a5fe32a0f01324ee087459e112ebb7224f646c0b5023f5e79e9956/httpx-0.28.1.tar.gz", hash = "sha256:75e98c5f16b0f35b567856f597f06ff2270a374470a5c2392242528e3e3e42fc", size = 141406, upload-time = "2024-12-06T15:37:23.222Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/2a/39/e50c7c3a983047577ee07d2a9e53faf5a69493943ec3f6a384bdc792deb2/httpx-0.28.1-py3-none-any.whl", hash = "sha256:d909fcccc110f8c7faf814ca82a9a4d816bc5a6dbfea25d6591d6985b8ba59ad", size = 73517, upload-time = "2024-12-06T15:37:21.509Z" }, +] + +[[package]] +name = "idna" +version = "3.20" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/f5/08/8eea9d4b8302028f3abb2c0813953f7aec26d33b7a8960ed760e65ff29fa/idna-3.20.tar.gz", hash = "sha256:a7db850025b95ded1eae8a46181a1a6c56c92c96f0e2b005d9ff8dc0210cab44", size = 216463, upload-time = "2026-09-17T14:11:04.752Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/58/a2/bb081bab032533a855d44de1d56f8e8426114ff1ba5d1f07a438a0a654f8/idna-3.20-py3-none-any.whl", hash = "sha256:ab7ae7122974553370f0bdb919e1a960b2cd1bc1ef0276416d896db81c14582c", size = 69583, upload-time = "2026-09-17T14:11:03.168Z" }, +] + +[[package]] +name = "iniconfig" +version = "2.3.1" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/01/e1/2069291243c926a2ff1cd706c7f3eeb9b62144bf60f77c9fb9ff2fb26bd3/iniconfig-2.3.1.tar.gz", hash = "sha256:67f4b9c50da0dedf52af349e7749a80a9057a5031199791b906c3bb3ae878960", size = 21209, upload-time = "2026-10-06T22:48:38.076Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/56/43/4ca9e49d27a1fcf6bece6f6aec0ea46bb9112489b93d4b688fb415457bdb/iniconfig-2.3.1-py3-none-any.whl", hash = "sha256:9121e2c1fdb355232495be3194c8dfe87ccc2d5dee45947b78e68f499790d7a7", size = 7552, upload-time = "2026-10-06T22:48:36.959Z" }, +] + +[[package]] +name = "jmespath" +version = "1.1.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/d3/59/322338183ecda247fb5d1763a6cbe46eff7222eaeebafd9fa65d4bf5cb11/jmespath-1.1.0.tar.gz", hash = "sha256:472c87d80f36026ae83c6ddd0f1d05d4e510134ed462851fd5f754c8c3cbb88d", size = 27377, upload-time = "2026-01-22T16:35:26.279Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/14/2f/967ba146e6d58cf6a652da73885f52fc68001525b4197effc174321d70b4/jmespath-1.1.0-py3-none-any.whl", hash = "sha256:a5663118de4908c91729bea0acadca56526eb2698e83de10cd116ae0f4e97c64", size = 20419, upload-time = "2026-01-22T16:35:24.919Z" }, +] + +[[package]] +name = "jsonschema" +version = "4.26.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "attrs" }, + { name = "jsonschema-specifications" }, + { name = "referencing" }, + { name = "rpds-py" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/b3/fc/e067678238fa451312d4c62bf6e6cf5ec56375422aee02f9cb5f909b3047/jsonschema-4.26.0.tar.gz", hash = "sha256:0c26707e2efad8aa1bfc5b7ce170f3fccc2e4918ff85989ba9ffa9facb2be326", size = 366583, upload-time = "2026-01-07T13:41:07.246Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/69/90/f63fb5873511e014207a475e2bb4e8b2e570d655b00ac19a9a0ca0a385ee/jsonschema-4.26.0-py3-none-any.whl", hash = "sha256:d489f15263b8d200f8387e64b4c3a75f06629559fb73deb8fdfb525f2dab50ce", size = 90630, upload-time = "2026-01-07T13:41:05.306Z" }, +] + +[[package]] +name = "jsonschema-path" +version = "0.5.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "attrs" }, + { name = "pathable" }, + { name = "pyyaml" }, + { name = "referencing" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/39/79/cd02a4df6d9270efdc7d3feefe6edd730b0820c39eeaa107a2faee8322d5/jsonschema_path-0.5.0.tar.gz", hash = "sha256:493b156ba895c97602655b620a8456caa2ce08c1aa389f5a7addec065e6e855c", size = 19597, upload-time = "2026-05-19T20:45:00.971Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/04/2c/9e69d73c4297508be9e3b64a970ea3971b3eb8db64ffc5802d40bd25981f/jsonschema_path-0.5.0-py3-none-any.whl", hash = "sha256:2790a070bc7abb08ea3dbe4d340ece4efadf639223001f020c7503229ba068e2", size = 24077, upload-time = "2026-05-19T20:44:59.225Z" }, +] + +[[package]] +name = "jsonschema-specifications" +version = "2025.9.1" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "referencing" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/19/74/a633ee74eb36c44aa6d1095e7cc5569bebf04342ee146178e2d36600708b/jsonschema_specifications-2025.9.1.tar.gz", hash = "sha256:b540987f239e745613c7a9176f3edb72b832a4ac465cf02712288397832b5e8d", size = 32855, upload-time = "2025-09-08T01:34:59.186Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/41/45/1a4ed80516f02155c51f51e8cedb3c1902296743db0bbc66608a0db2814f/jsonschema_specifications-2025.9.1-py3-none-any.whl", hash = "sha256:98802fee3a11ee76ecaca44429fda8a41bff98b00a0f2838151b113f210cc6fe", size = 18437, upload-time = "2025-09-08T01:34:57.871Z" }, +] + +[[package]] +name = "lazy-object-proxy" +version = "1.13.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/d4/8e/f26b09778fcb26261fdeb4cc2b011975292316529bff9b541a5a02acb976/lazy_object_proxy-1.13.0.tar.gz", hash = "sha256:ce34046cb021d69c72d05ddb83821ecfd4d2d0a5d43a93c5cd01c9e34779cf14", size = 45649, upload-time = "2026-10-17T16:38:01.975Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/5d/a5/98c03827458988def73622e075486fe1ebbb85ae53ac3f21479fbfd9988c/lazy_object_proxy-1.13.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:087eba19ea5ce02ea9eb1749d8fdcfb229eeeaf13abaebecf00d579d306d1fd9", size = 26808, upload-time = "2026-10-17T16:37:42.616Z" }, + { url = "https://files.pythonhosted.org/packages/c3/88/30aa37866ff9122c7b00341396781d30e27ae9d863c2698d1f42bb25a8ab/lazy_object_proxy-1.13.0-cp312-cp312-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl", hash = "sha256:3df6b7db013fbbd00001a43af6b188b545442b4d125b5fddda79366108e02286", size = 71403, upload-time = "2026-10-20T01:05:33.169Z" }, + { url = "https://files.pythonhosted.org/packages/65/fa/099b2931430f87231fa31cc39893d047a1971a57fc7f90df70b9c82961a6/lazy_object_proxy-1.13.0-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:1bdc617c7b6f58aa5e59f514c7d619d7f60b52b343b77c9149d2fbfefc412f3a", size = 70989, upload-time = "2026-10-20T01:05:34.591Z" }, + { url = "https://files.pythonhosted.org/packages/8b/17/87891d3fee9c03764691239745ee3f6b793062b88cf5d029bf515aa0836a/lazy_object_proxy-1.13.0-cp312-cp312-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:47d26b4c5a5ea2d3a1993a1c9509110beb030a2739ca69ebbe516fb04b6842b7", size = 65742, upload-time = "2026-10-20T01:05:36.015Z" }, + { url = "https://files.pythonhosted.org/packages/a9/9a/02acae69e1d0930f9f430d6e4ea77235c72a735672cd8d91164909815fb6/lazy_object_proxy-1.13.0-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:e6261a9c38f629c3566ab5caec3909f5c6f3333a711c7e39f6883715aa38c566", size = 69280, upload-time = "2026-10-20T01:05:37.217Z" }, + { url = "https://files.pythonhosted.org/packages/75/0e/e697f92c1a5410bddf0571077f38684b16fcf3925bb9ba5430355028e0ba/lazy_object_proxy-1.13.0-cp312-cp312-musllinux_1_2_riscv64.whl", hash = "sha256:337b25ac5b0f5103c72343f74eea438ad3216b0a3cc77a3f6e4ec54c80d0256b", size = 65028, upload-time = "2026-10-20T01:05:38.378Z" }, + { url = "https://files.pythonhosted.org/packages/f2/4f/ec5c7f4907305086a55e9372d3deccec369b30e731b92c14d34df455cf4c/lazy_object_proxy-1.13.0-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:faa395d97edfafd3cd0cbd8855473c4673c7e3080fccf31f97a9bcfa7218d7ec", size = 70619, upload-time = "2026-10-20T01:05:39.551Z" }, + { url = "https://files.pythonhosted.org/packages/e9/23/67edce3954b280049b87dfe914fa16400c3ce2f3fa236388cf64a1bba600/lazy_object_proxy-1.13.0-cp312-cp312-win_amd64.whl", hash = "sha256:81437ad7883fe637620bc63a3df3e9974c9a63562e76d7e8a444fe724adccb5c", size = 25815, upload-time = "2026-10-17T16:37:43.889Z" }, + { url = "https://files.pythonhosted.org/packages/21/21/d70d4ca285bb6ed3629ac432ea0910b8f923e50580888e37990b31f3fac9/lazy_object_proxy-1.13.0-cp312-cp312-win_arm64.whl", hash = "sha256:da66d53e0c350e6e6876f2dc060b240dc06cc159ca7f279d59fe4ed48aec2ece", size = 24467, upload-time = "2026-10-17T16:37:44.82Z" }, +] + +[[package]] +name = "mtusi-messenger" +version = "1.0.0" +source = { virtual = "." } +dependencies = [ + { name = "argon2-cffi" }, + { name = "boto3" }, + { name = "fastapi" }, + { name = "opentelemetry-exporter-otlp-proto-http" }, + { name = "opentelemetry-sdk" }, + { name = "pillow" }, + { name = "psutil" }, + { name = "psycopg", extra = ["binary", "pool"] }, + { name = "redis" }, + { name = "uvicorn" }, +] + +[package.dev-dependencies] +dev = [ + { name = "httpx" }, + { name = "jsonschema" }, + { name = "openapi-spec-validator" }, + { name = "pytest" }, + { name = "ruff" }, +] + +[package.metadata] +requires-dist = [ + { name = "argon2-cffi" }, + { name = "boto3", specifier = ">=1.43,<2" }, + { name = "fastapi" }, + { name = "opentelemetry-exporter-otlp-proto-http", specifier = "==1.45.2" }, + { name = "opentelemetry-sdk", specifier = "==1.45.2" }, + { name = "pillow", specifier = ">=13.0.0,<14" }, + { name = "psutil", specifier = ">=7,<8" }, + { name = "psycopg", extras = ["binary", "pool"] }, + { name = "redis" }, + { name = "uvicorn" }, +] + +[package.metadata.requires-dev] +dev = [ + { name = "httpx" }, + { name = "jsonschema" }, + { name = "openapi-spec-validator" }, + { name = "pytest" }, + { name = "ruff" }, +] + +[[package]] +name = "openapi-schema-validator" +version = "0.9.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "jsonschema" }, + { name = "jsonschema-specifications" }, + { name = "pydantic" }, + { name = "pydantic-settings" }, + { name = "referencing" }, + { name = "rfc3339-validator" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/98/e8/ab3f27dbca54ec645f7fab714b640907d5d36c2ebb07e87eebd30bd5c81b/openapi_schema_validator-0.9.0.tar.gz", hash = "sha256:b72db64315b89d21834cd3ffef37e3e6893bc876327be2d366e8424b1029afd3", size = 24686, upload-time = "2026-04-27T17:31:27.606Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/90/c0/5467967d95378b2cfce312e09cbd0c9ab64354a0922379b734f793edd04f/openapi_schema_validator-0.9.0-py3-none-any.whl", hash = "sha256:faa3bbe7c3aa8ca2087ad83f709dc3b7d920283153a570c03e24ea182558aa25", size = 19980, upload-time = "2026-04-27T17:31:25.965Z" }, +] + +[[package]] +name = "openapi-spec-validator" +version = "0.9.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "jsonschema" }, + { name = "jsonschema-path" }, + { name = "lazy-object-proxy" }, + { name = "openapi-schema-validator" }, + { name = "pydantic" }, + { name = "pydantic-settings" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/8f/d2/640b5149cd5688bc0ad1fdbb4df6a2f7b84a093c8d787c27d566132f8b8b/openapi_spec_validator-0.9.0.tar.gz", hash = "sha256:6d648cff6490ebb799dcfe273792f2941c050158854c721f086599d845da78b8", size = 1756839, upload-time = "2026-05-20T09:23:18.871Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/95/d8/321ff889330acca2e3097f3d4f80a40bcc41b6d34d302978ab32c449520b/openapi_spec_validator-0.9.0-py3-none-any.whl", hash = "sha256:222fecffc7714f6d0a6ad62c0e4b66cc2b7dbfafb7b93acfc6c308abbdb51af8", size = 50328, upload-time = "2026-05-20T09:23:17.017Z" }, +] + +[[package]] +name = "opentelemetry-api" +version = "1.45.2" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "typing-extensions" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/19/14/cf3a6b6448849656e1e5f4e2101f3988dc6789724050096aba1bc5ccf592/opentelemetry_api-1.45.2.tar.gz", hash = "sha256:d7b0008e21e5fd61cbe7a7f34ca3b6905a78ab677d9bc395e299359c75cda6b4", size = 73277, upload-time = "2026-10-29T17:29:37.888Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/a9/2d/610db864d7513158cebb8f36cc88e67e73bd6c7aa1905ef18d89e1281c81/opentelemetry_api-1.45.2-py3-none-any.whl", hash = "sha256:2cbd737377e710ee740d261c94e93fa0f08e6d037c18f17513cc0a2d94479a34", size = 60335, upload-time = "2026-10-29T17:29:06.955Z" }, +] + +[[package]] +name = "opentelemetry-exporter-http-transport" +version = "0.66b2" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "opentelemetry-api" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/a6/e6/dbeb3e217418071656232a4028c791060d219f218cef1249b664049d12c0/opentelemetry_exporter_http_transport-0.66b2.tar.gz", hash = "sha256:66d6ed810a515432c8891da9a834464332fd70badeca45bdeeae81b4280c903b", size = 11693, upload-time = "2026-10-29T17:29:39.444Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/a1/b2/c622a101f31c0e6670b82f4264c4e77c161bce415bc6fc158fda0b82e218/opentelemetry_exporter_http_transport-0.66b2-py3-none-any.whl", hash = "sha256:fd5f5b490c099acda1cd7b909d5e8981436bf18cc8c6098d302d114c271720e9", size = 12154, upload-time = "2026-10-29T17:29:10.244Z" }, +] + +[package.optional-dependencies] +requests = [ + { name = "requests" }, +] + +[[package]] +name = "opentelemetry-exporter-otlp-common" +version = "0.66b2" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "opentelemetry-sdk" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/5a/3c/3f2cc8c42bde2620e65024d71e2eb025f7bd0821bb363b52bcc5a3260dbd/opentelemetry_exporter_otlp_common-0.66b2.tar.gz", hash = "sha256:06f5a9b88638e310efa1f1d206cdf6b75393e112aba4e174a963416192bd1028", size = 14325, upload-time = "2026-10-29T17:29:41.701Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/a8/47/b3049e30b339c82e3c7ec1fc692185a5d5a3ba65a94c570bb39b2c0b8424/opentelemetry_exporter_otlp_common-0.66b2-py3-none-any.whl", hash = "sha256:ace86efb75489f925f1ef809856ae5f0c7db534e4afdc624530222228b1236a5", size = 12385, upload-time = "2026-10-29T17:29:13.667Z" }, +] + +[[package]] +name = "opentelemetry-exporter-otlp-proto-common" +version = "1.45.2" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "opentelemetry-proto" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/69/58/239c98b36d9ea317098769957043c251703636a26189c884fba46c1dad84/opentelemetry_exporter_otlp_proto_common-1.45.2.tar.gz", hash = "sha256:f1f2806f3f28ce7938033823e50934fcd91595a39de38e69a28a51e19f40fc6d", size = 18873, upload-time = "2026-10-29T17:29:44.496Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/e6/d6/0f30d38120a949aef70528f845bf539f80df62abb4b8e62fdf69c2b6df5a/opentelemetry_exporter_otlp_proto_common-1.45.2-py3-none-any.whl", hash = "sha256:af483b24217028892f017096731b794b196b785025d2e6808874720fd0b05a80", size = 15392, upload-time = "2026-10-29T17:29:17.913Z" }, +] + +[[package]] +name = "opentelemetry-exporter-otlp-proto-http" +version = "1.45.2" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "googleapis-common-protos" }, + { name = "opentelemetry-api" }, + { name = "opentelemetry-exporter-http-transport", extra = ["requests"] }, + { name = "opentelemetry-exporter-otlp-common" }, + { name = "opentelemetry-exporter-otlp-proto-common" }, + { name = "opentelemetry-proto" }, + { name = "opentelemetry-sdk" }, + { name = "requests" }, + { name = "typing-extensions" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/db/07/b7b01ecb69d02f540e679a9e36f7413d081f225bbbed4469d212ada10bb7/opentelemetry_exporter_otlp_proto_http-1.45.2.tar.gz", hash = "sha256:5984a3fb46bc4628e4e2b85d4a6e72637e03962aae6cf372791137768a4ad939", size = 28843, upload-time = "2026-10-29T17:29:46.15Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/32/65/f64d7d2450217e2989714e1dee15e19bf79a77a313387abac0cac77bc10e/opentelemetry_exporter_otlp_proto_http-1.45.2-py3-none-any.whl", hash = "sha256:6e4d025138829d0ee57946930c2ccad6491ad4d92a958e9c7eea69278fe60cfc", size = 22180, upload-time = "2026-10-29T17:29:20.154Z" }, +] + +[[package]] +name = "opentelemetry-proto" +version = "1.45.2" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "protobuf" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/24/9c/1aa4ce60e9bc72af20dc49c92cc0566825092d92b3d6a277439fb5fb7c01/opentelemetry_proto-1.45.2.tar.gz", hash = "sha256:bd8d23cf770605b0af9b7be2071d26a464fea289d35429abfd2a66226114ad64", size = 46486, upload-time = "2026-10-29T17:29:53.007Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/7e/0d/a0b8f2b9efe2ec1abdf639d3696db9b1563ebeb11d91aac08ba7341e9122/opentelemetry_proto-1.45.2-py3-none-any.whl", hash = "sha256:03a7ca1b43f89fd5b965d5975902bb2515c0c86e2428b456836e9a6149c6235a", size = 72484, upload-time = "2026-10-29T17:29:31.403Z" }, +] + +[[package]] +name = "opentelemetry-sdk" +version = "1.45.2" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "opentelemetry-api" }, + { name = "opentelemetry-semantic-conventions" }, + { name = "typing-extensions" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/7b/1a/74a21d4d6969fb8b432ac397e66112a8167a6deb267ea4559dbaf2fe91ef/opentelemetry_sdk-1.45.2.tar.gz", hash = "sha256:7eec4de13dd21ff3a1670dcb0e02079e692736f94d733dfdce5af461d884248d", size = 221705, upload-time = "2026-10-29T17:29:54.685Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/9f/a5/9a3b793ef48245f2336a16beb2324c2397dbb3f987cd68942f77cca06156/opentelemetry_sdk-1.45.2-py3-none-any.whl", hash = "sha256:ff974ea70ee4f1d51e2ec152db37c2b626c7bf82bb3f7d86114fd8704e7199c6", size = 141756, upload-time = "2026-10-29T17:29:33.722Z" }, +] + +[[package]] +name = "opentelemetry-semantic-conventions" +version = "0.66b2" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "opentelemetry-api" }, + { name = "typing-extensions" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/37/3f/50f95972b50e8e353f5b9342034c9cd17730f1956f009ce6a3fbbd89f9ce/opentelemetry_semantic_conventions-0.66b2.tar.gz", hash = "sha256:7da5f1a5dc4383eb66711d4d3d3e71824d9403ac1559fea021cc103c1a4c4976", size = 150246, upload-time = "2026-10-29T17:29:55.682Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/67/bd/6bf33ed31521c565931c037e9e81bac47c1acb000e850c6e24220e2a0c00/opentelemetry_semantic_conventions-0.66b2-py3-none-any.whl", hash = "sha256:4cbe61e5f9275d57ab31708446e7938ef4291ebbe6a7fca6f7a629c5acae87d8", size = 206280, upload-time = "2026-10-29T17:29:35.062Z" }, +] + +[[package]] +name = "packaging" +version = "26.3" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/7d/fa/3944b40b07da9ce895c0e6303a5ab7d53da063554f534556b134a54d6093/packaging-26.3.tar.gz", hash = "sha256:94edc256424af38762eb31306eed28beb9f0efc50a8837492c9d6fd6004aed79", size = 313412, upload-time = "2026-08-04T18:15:28.737Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/63/34/ba1c580383c9eada3711951fef0795c80b829a078d72188184bcab9dd527/packaging-26.3-py3-none-any.whl", hash = "sha256:d7193f7c8e4e93f444fde0262bf90af30e16fa0ad0ad44cb553c87339b23cd1c", size = 129956, upload-time = "2026-08-04T18:15:27.159Z" }, +] + +[[package]] +name = "pathable" +version = "0.6.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/66/f3/5a20387de9bcd0607871bfc2198ee0e15836da7baa4592ccd7f24c27c986/pathable-0.6.0.tar.gz", hash = "sha256:6404b8b82aef5ff0fd478934137128b99b12212ba35afdde5525ca4f8388ea58", size = 18970, upload-time = "2026-05-19T18:15:11.911Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/a2/e8/6d75ffd9784bce2e93d1ae4415649427e39a53bb172d4672b2b59c6f0a7b/pathable-0.6.0-py3-none-any.whl", hash = "sha256:82c4ca6c98c502ad12e0d4e9779b6210afee93c38990988c8c5d1b49bdcdf566", size = 18983, upload-time = "2026-05-19T18:15:10.728Z" }, +] + +[[package]] +name = "pillow" +version = "13.0.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/ce/a4/9cc30690a394a8305e8be4c9036aa16d0dfddadd09079860b582f562496d/pillow-13.0.0.tar.gz", hash = "sha256:cdcd1ba258178f7356d74170c9a81ba4eab6a5d55748bc402a5a2a6fe6be3510", size = 47058631, upload-time = "2026-10-16T22:18:09.718Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/7a/b8/58d79332229482eb0d27c82973850808c19d37e5bdc14443d3417bd373f5/pillow-13.0.0-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:67c8d44ad89fa7eb88de5d6ef6199b1e03dd24974f85a67639fc8badb801fe79", size = 5568643, upload-time = "2026-10-16T22:15:44.474Z" }, + { url = "https://files.pythonhosted.org/packages/39/4b/f2ed53d83aa44ac19599ac0a54897f867fafb95f406980d1e24083f8cbe3/pillow-13.0.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:fc481f742ccda20e9ed760b8f978dff50f2a4e9bc253ac167fb0a05b0783ef52", size = 4852329, upload-time = "2026-10-16T22:15:46.284Z" }, + { url = "https://files.pythonhosted.org/packages/3b/bb/9e30e8ed18c20800ee327a12107d5249ad8dc444867b3adfcc21654e3c71/pillow-13.0.0-cp312-cp312-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:8bf295fe459343bc6093c8e5e0df60bfa189e0fcb775a22e2c2488fdeccc6c0d", size = 6519309, upload-time = "2026-10-16T22:15:48.14Z" }, + { url = "https://files.pythonhosted.org/packages/e6/99/fdf65cc539e266ab93546c261bdf98411fe165c6e4e13f9dbf597097192b/pillow-13.0.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:42d63be3af4f9b951b199b0a9d23365d37ab14687e6d77b74940432c8515c4ca", size = 7144542, upload-time = "2026-10-16T22:15:50.093Z" }, + { url = "https://files.pythonhosted.org/packages/26/9b/f38b7c4d8f599537e2d1a6d546cec9beef7536ff8f5c49a3f9c78179d8ac/pillow-13.0.0-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:4bd024d567eca931b668978d672dba914d4b8e2628e2c3073a2ad178de8a2620", size = 6618042, upload-time = "2026-10-16T22:15:52.054Z" }, + { url = "https://files.pythonhosted.org/packages/a8/7c/45ee28531f89ee4582967d8a17f7a26d71ca64cd902b93c269590cd60a00/pillow-13.0.0-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:23edf4ec4b6f4f240e8df6e4985e9ee2ced86474632433e55fb1e2548744bf40", size = 7228137, upload-time = "2026-10-16T22:15:54.009Z" }, + { url = "https://files.pythonhosted.org/packages/01/bc/9c2a969cb1b70201d04fa17fd5aedf02a732870b8da86bceaaa30b0ca385/pillow-13.0.0-cp312-cp312-win32.whl", hash = "sha256:02464da86f561f410e13b061ec37c3068a9cb557a095494157742d07b3c24a27", size = 6515423, upload-time = "2026-10-16T22:15:56.25Z" }, + { url = "https://files.pythonhosted.org/packages/ff/cd/73a79ecdc822076002eb24b5e1e4a530b0bb5310fcb6d239abbec877110b/pillow-13.0.0-cp312-cp312-win_amd64.whl", hash = "sha256:ff3fe9eb621fbb9db4c4be33ab946f6bac5f98ab50ca8d3260503653656c961b", size = 7272166, upload-time = "2026-10-16T22:15:58.597Z" }, + { url = "https://files.pythonhosted.org/packages/4a/a3/be5a1236efd085b3984e4305da8f179ae9dab80c991d2ad78f2bd5c4c843/pillow-13.0.0-cp312-cp312-win_arm64.whl", hash = "sha256:c3bc8ee0271387e0b1e3ad0ff893645990a656e79bf9c42f4f734a3642b11d51", size = 2698943, upload-time = "2026-10-16T22:16:00.637Z" }, + { url = "https://files.pythonhosted.org/packages/60/da/f6d644e631c5b370c5d0b899f3ccadd2780aab070b29a110527cf4e1fd2c/pillow-13.0.0-pp312-pypy312_pp80-macosx_10_15_x86_64.whl", hash = "sha256:8619685cad8efc4c38c66d3b36aad854523297c43d748b3b6f0cc03c90ba3463", size = 5523188, upload-time = "2026-10-16T22:17:59.334Z" }, + { url = "https://files.pythonhosted.org/packages/e4/b0/2594f202d743a35d4fe80682bfd96f277e5ca7aecb27cf64ef5bfc1d000b/pillow-13.0.0-pp312-pypy312_pp80-macosx_11_0_arm64.whl", hash = "sha256:7e91e97a929232cdb828889ee6ad0e48d7f40f4ec38818f4e4a8968b2b1af22e", size = 4806808, upload-time = "2026-10-16T22:18:01.188Z" }, + { url = "https://files.pythonhosted.org/packages/8e/ed/d504165ef79af6fafe25c76726cf30f544cc236002f7ed054f1d51adc4ff/pillow-13.0.0-pp312-pypy312_pp80-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:93ff9c9c3663ce23aaa5d0b6b6abac55359e2a0c06c7e30f3771829af816be63", size = 5464358, upload-time = "2026-10-16T22:18:02.779Z" }, + { url = "https://files.pythonhosted.org/packages/7b/fe/a10aba5503ca13e9e009b8bd0a1a4ce5584bdce246245fd6f3a83701369c/pillow-13.0.0-pp312-pypy312_pp80-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:e65dd6e75de67b2362a4fa3e16aa627595f65054dc4ec73d64680c84d592fa61", size = 6043514, upload-time = "2026-10-16T22:18:04.538Z" }, + { url = "https://files.pythonhosted.org/packages/c0/37/66b12dc476041fe523bca29c9d58fbf1ea92a4eaf73acfb9e993948f1191/pillow-13.0.0-pp312-pypy312_pp80-win_amd64.whl", hash = "sha256:567f20f1c75897d7663830da6ea8af719e03d712b1d9ee7f813319f9ece42e5a", size = 7366030, upload-time = "2026-10-16T22:18:06.638Z" }, +] + +[[package]] +name = "pluggy" +version = "1.7.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/bf/db/7fc19e6f2dc92a966727031389fc2e08b558f0f25eb7403c1119ad4713cd/pluggy-1.7.0.tar.gz", hash = "sha256:d1eaa46ebb595891b860ab086b4d09c8588af65ebd4361b8e8f4bb8920b90ba8", size = 123304, upload-time = "2026-10-15T09:50:58.343Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/40/9e/2b38731e0fc536806f16490e1a12d7f0dc2a1235aa8cc07bcc75416a7daa/pluggy-1.7.0-py3-none-any.whl", hash = "sha256:7dd7b0d8832ba3cb632c306926ded123429211b83641b35dc5c41ad2d34f9bec", size = 27082, upload-time = "2026-10-15T09:50:56.808Z" }, +] + +[[package]] +name = "protobuf" +version = "6.33.6" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/66/70/e908e9c5e52ef7c3a6c7902c9dfbb34c7e29c25d2f81ade3856445fd5c94/protobuf-6.33.6.tar.gz", hash = "sha256:a6768d25248312c297558af96a9f9c929e8c4cee0659cb07e780731095f38135", size = 444531, upload-time = "2026-03-18T19:05:00.988Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/fc/9f/2f509339e89cfa6f6a4c4ff50438db9ca488dec341f7e454adad60150b00/protobuf-6.33.6-cp310-abi3-win32.whl", hash = "sha256:7d29d9b65f8afef196f8334e80d6bc1d5d4adedb449971fefd3723824e6e77d3", size = 425739, upload-time = "2026-03-18T19:04:48.373Z" }, + { url = "https://files.pythonhosted.org/packages/76/5d/683efcd4798e0030c1bab27374fd13a89f7c2515fb1f3123efdfaa5eab57/protobuf-6.33.6-cp310-abi3-win_amd64.whl", hash = "sha256:0cd27b587afca21b7cfa59a74dcbd48a50f0a6400cfb59391340ad729d91d326", size = 437089, upload-time = "2026-03-18T19:04:50.381Z" }, + { url = "https://files.pythonhosted.org/packages/5c/01/a3c3ed5cd186f39e7880f8303cc51385a198a81469d53d0fdecf1f64d929/protobuf-6.33.6-cp39-abi3-macosx_10_9_universal2.whl", hash = "sha256:9720e6961b251bde64edfdab7d500725a2af5280f3f4c87e57c0208376aa8c3a", size = 427737, upload-time = "2026-03-18T19:04:51.866Z" }, + { url = "https://files.pythonhosted.org/packages/ee/90/b3c01fdec7d2f627b3a6884243ba328c1217ed2d978def5c12dc50d328a3/protobuf-6.33.6-cp39-abi3-manylinux2014_aarch64.whl", hash = "sha256:e2afbae9b8e1825e3529f88d514754e094278bb95eadc0e199751cdd9a2e82a2", size = 324610, upload-time = "2026-03-18T19:04:53.096Z" }, + { url = "https://files.pythonhosted.org/packages/9b/ca/25afc144934014700c52e05103c2421997482d561f3101ff352e1292fb81/protobuf-6.33.6-cp39-abi3-manylinux2014_s390x.whl", hash = "sha256:c96c37eec15086b79762ed265d59ab204dabc53056e3443e702d2681f4b39ce3", size = 339381, upload-time = "2026-03-18T19:04:54.616Z" }, + { url = "https://files.pythonhosted.org/packages/16/92/d1e32e3e0d894fe00b15ce28ad4944ab692713f2e7f0a99787405e43533a/protobuf-6.33.6-cp39-abi3-manylinux2014_x86_64.whl", hash = "sha256:e9db7e292e0ab79dd108d7f1a94fe31601ce1ee3f7b79e0692043423020b0593", size = 323436, upload-time = "2026-03-18T19:04:55.768Z" }, + { url = "https://files.pythonhosted.org/packages/c4/72/02445137af02769918a93807b2b7890047c32bfb9f90371cbc12688819eb/protobuf-6.33.6-py3-none-any.whl", hash = "sha256:77179e006c476e69bf8e8ce866640091ec42e1beb80b213c3900006ecfba6901", size = 170656, upload-time = "2026-03-18T19:04:59.826Z" }, +] + +[[package]] +name = "psutil" +version = "7.2.2" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/aa/c6/d1ddf4abb55e93cebc4f2ed8b5d6dbad109ecb8d63748dd2b20ab5e57ebe/psutil-7.2.2.tar.gz", hash = "sha256:0746f5f8d406af344fd547f1c8daa5f5c33dbc293bb8d6a16d80b4bb88f59372", size = 493740, upload-time = "2026-01-28T18:14:54.428Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/e7/36/5ee6e05c9bd427237b11b3937ad82bb8ad2752d72c6969314590dd0c2f6e/psutil-7.2.2-cp36-abi3-macosx_10_9_x86_64.whl", hash = "sha256:ed0cace939114f62738d808fdcecd4c869222507e266e574799e9c0faa17d486", size = 129090, upload-time = "2026-01-28T18:15:22.168Z" }, + { url = "https://files.pythonhosted.org/packages/80/c4/f5af4c1ca8c1eeb2e92ccca14ce8effdeec651d5ab6053c589b074eda6e1/psutil-7.2.2-cp36-abi3-macosx_11_0_arm64.whl", hash = "sha256:1a7b04c10f32cc88ab39cbf606e117fd74721c831c98a27dc04578deb0c16979", size = 129859, upload-time = "2026-01-28T18:15:23.795Z" }, + { url = "https://files.pythonhosted.org/packages/b5/70/5d8df3b09e25bce090399cf48e452d25c935ab72dad19406c77f4e828045/psutil-7.2.2-cp36-abi3-manylinux2010_x86_64.manylinux_2_12_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:076a2d2f923fd4821644f5ba89f059523da90dc9014e85f8e45a5774ca5bc6f9", size = 155560, upload-time = "2026-01-28T18:15:25.976Z" }, + { url = "https://files.pythonhosted.org/packages/63/65/37648c0c158dc222aba51c089eb3bdfa238e621674dc42d48706e639204f/psutil-7.2.2-cp36-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:b0726cecd84f9474419d67252add4ac0cd9811b04d61123054b9fb6f57df6e9e", size = 156997, upload-time = "2026-01-28T18:15:27.794Z" }, + { url = "https://files.pythonhosted.org/packages/8e/13/125093eadae863ce03c6ffdbae9929430d116a246ef69866dad94da3bfbc/psutil-7.2.2-cp36-abi3-musllinux_1_2_aarch64.whl", hash = "sha256:fd04ef36b4a6d599bbdb225dd1d3f51e00105f6d48a28f006da7f9822f2606d8", size = 148972, upload-time = "2026-01-28T18:15:29.342Z" }, + { url = "https://files.pythonhosted.org/packages/04/78/0acd37ca84ce3ddffaa92ef0f571e073faa6d8ff1f0559ab1272188ea2be/psutil-7.2.2-cp36-abi3-musllinux_1_2_x86_64.whl", hash = "sha256:b58fabe35e80b264a4e3bb23e6b96f9e45a3df7fb7eed419ac0e5947c61e47cc", size = 148266, upload-time = "2026-01-28T18:15:31.597Z" }, + { url = "https://files.pythonhosted.org/packages/b4/90/e2159492b5426be0c1fef7acba807a03511f97c5f86b3caeda6ad92351a7/psutil-7.2.2-cp37-abi3-win_amd64.whl", hash = "sha256:eb7e81434c8d223ec4a219b5fc1c47d0417b12be7ea866e24fb5ad6e84b3d988", size = 137737, upload-time = "2026-01-28T18:15:33.849Z" }, + { url = "https://files.pythonhosted.org/packages/8c/c7/7bb2e321574b10df20cbde462a94e2b71d05f9bbda251ef27d104668306a/psutil-7.2.2-cp37-abi3-win_arm64.whl", hash = "sha256:8c233660f575a5a89e6d4cb65d9f938126312bca76d8fe087b947b3a1aaac9ee", size = 134617, upload-time = "2026-01-28T18:15:36.514Z" }, +] + +[[package]] +name = "psycopg" +version = "3.3.6" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "typing-extensions" }, + { name = "tzdata", marker = "sys_platform == 'win32'" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/76/26/3ea4ca5eaea1c0debcdf7ee7c1613fbe721dc27a03c461c0817ffd8a0601/psycopg-3.3.6.tar.gz", hash = "sha256:c081f2250df751a943036e42db6df4571c66cd0aabe8291a7a506512b12007d2", size = 168171, upload-time = "2026-09-18T13:22:55.152Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/4e/de/748bd7609c71cae5d737f0ba9192f19329f70180ecda8fff3cac02c5abe3/psycopg-3.3.6-py3-none-any.whl", hash = "sha256:a1db9f7148b06a28606767efaca51fa6f9398c5c0a3810519be69d7000bdb631", size = 215490, upload-time = "2026-09-18T13:15:29.374Z" }, +] + +[package.optional-dependencies] +binary = [ + { name = "psycopg-binary", marker = "implementation_name != 'pypy'" }, +] +pool = [ + { name = "psycopg-pool" }, +] + +[[package]] +name = "psycopg-binary" +version = "3.3.6" +source = { registry = "https://pypi.org/simple" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/e6/01/2cdd1824e58b4467ee0b9498664cd28c42d8794db6b1e35b6bcb834f0044/psycopg_binary-3.3.6-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:3f84dab25e0385692ee13274c68678377e0b1a70ab9d14e56264cbf61f60c62d", size = 4707086, upload-time = "2026-09-18T13:18:05.138Z" }, + { url = "https://files.pythonhosted.org/packages/f6/76/de9948ac06895261c84d5b9fbe283d8f3c5bc9f070691b8d9eaa1b51e322/psycopg_binary-3.3.6-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:612382ac3ed13651c7fa44b5fee9fbf7baaa2ddbc6f500391672682c5f1df9e0", size = 4769607, upload-time = "2026-09-18T13:18:12.83Z" }, + { url = "https://files.pythonhosted.org/packages/76/a9/72436c9915ee4905964689e7f0e182ce7767cc0a0390b3ce703be8177625/psycopg_binary-3.3.6-cp312-cp312-manylinux2014_ppc64le.manylinux_2_17_ppc64le.whl", hash = "sha256:366db6e97e66b37211475f20c4c1324a2dc0dd825e46d4e87f9d599304d276f9", size = 5554134, upload-time = "2026-09-18T13:18:21.175Z" }, + { url = "https://files.pythonhosted.org/packages/0a/42/948bb3d2617795093512613fd96ba380e922992c7908fbc073858147d196/psycopg_binary-3.3.6-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:1679a1cb93fbe5a6d1fd58d82cbddcc6fcb8c61446ba7cae6eb2a7b19bc585de", size = 5235723, upload-time = "2026-09-18T13:18:27.071Z" }, + { url = "https://files.pythonhosted.org/packages/99/47/93e823ff1b0088400703410939c9bda3e63ed9c850b3ee088e8769f4c10b/psycopg_binary-3.3.6-cp312-cp312-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:37d40450659401600e6d043ff586c89a71a69f33cbb8bcdba6cdb2569beecdbe", size = 6833587, upload-time = "2026-09-18T13:18:33.794Z" }, + { url = "https://files.pythonhosted.org/packages/5e/2d/ecc69c847795aa704041a9f5667a6b0938a088cf1853636d762a6938e493/psycopg_binary-3.3.6-cp312-cp312-manylinux_2_38_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:a5165300324efd5a772c48a88ab3a928513ab3979fca76553e62ee815f7b2b9c", size = 5070013, upload-time = "2026-09-18T13:18:39.628Z" }, + { url = "https://files.pythonhosted.org/packages/92/36/6126f0dac21713dcae91404f2a76da18598a6252339a8c669c46370d43b2/psycopg_binary-3.3.6-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:d636338c8f21b0df2f84657b00bc34f9313f826ef93f1155bc743607e4a0c5eb", size = 4597367, upload-time = "2026-09-18T13:18:45.023Z" }, + { url = "https://files.pythonhosted.org/packages/4d/29/7ecfc04243b46c89ffd49924e9c5634ea904ef96c7d0f37e4073623584c1/psycopg_binary-3.3.6-cp312-cp312-musllinux_1_2_ppc64le.whl", hash = "sha256:a4ee3bdd5468a725f2a4d9aab8a74b6d0279f768c8b5d3aeb102c5307ff3d59c", size = 4275419, upload-time = "2026-09-18T13:18:49.299Z" }, + { url = "https://files.pythonhosted.org/packages/6e/90/2f46d2e0de79706ac170df0a3637fe63c4498fc04f131f6049520b78b806/psycopg_binary-3.3.6-cp312-cp312-musllinux_1_2_riscv64.whl", hash = "sha256:289aadd6a00e151203c081f708348ec89f1e483c9b510ef4ac3981f847f01f79", size = 4007358, upload-time = "2026-09-18T13:18:53.944Z" }, + { url = "https://files.pythonhosted.org/packages/03/48/6744e91291b751a8cf12d63d719977974bb94c84ceba913e7ddb2e478e51/psycopg_binary-3.3.6-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:f21d057f3e5f5491067e5b292498073b73847d48799b099803fef100775fcc52", size = 4320156, upload-time = "2026-09-18T13:18:59.258Z" }, + { url = "https://files.pythonhosted.org/packages/1a/9b/94ff7fce53a64d5b286e2ec454e0a025cf3d6e6b4a9189bef16aa5de98b2/psycopg_binary-3.3.6-cp312-cp312-win_amd64.whl", hash = "sha256:e23a66a763fbe83fcc210bc77c27e5a5ea380ebf091c06f34d8561b695e5a40f", size = 3658864, upload-time = "2026-09-18T13:19:06.503Z" }, +] + +[[package]] +name = "psycopg-pool" +version = "3.3.3" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "typing-extensions" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/74/5e/c0664b968b102ff68b811d999c728546c48d5c1eec03e3bbaf88c0cb4472/psycopg_pool-3.3.3.tar.gz", hash = "sha256:df87b5d9d0ad7db37f6cdad4fa8ce113d250f5997f6db38e9a99192fb67f9e1d", size = 32006, upload-time = "2026-09-22T15:53:24.947Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/5d/b4/452c6607a0f479465cd8a9b0d9956919fcb150050c1f83f9f11e6b8ee8dc/psycopg_pool-3.3.3-py3-none-any.whl", hash = "sha256:9b9cd6a4fcec47a410f7e82d408540e7f77b478509e91b44c1a5457a13e5ff37", size = 40304, upload-time = "2026-09-22T15:53:23.712Z" }, +] + +[[package]] +name = "pycparser" +version = "3.12" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/cb/27/eeb9f307bf07060f3d9f9aa0fb8c15b01bdfded0a941e4b2719c7f94cacd/pycparser-3.12.tar.gz", hash = "sha256:f03387877eab82ce01bbdfd0ba7252ee55a90b1c708d5129e2ce915475cf1db6", size = 158785, upload-time = "2026-10-22T13:40:03.56Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/b6/ae/315bbeee126a769cbde43cf4908acb4b40408d8bf8bbf334dd7368d8dadf/pycparser-3.12-py3-none-any.whl", hash = "sha256:a076f3f489b39b43ed13563a1dafe42447445bec2e294154ec5c57fcdda4c85e", size = 62600, upload-time = "2026-10-22T13:40:02.021Z" }, +] + +[[package]] +name = "pydantic" +version = "2.14.2" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "annotated-types" }, + { name = "pydantic-core" }, + { name = "typing-extensions" }, + { name = "typing-inspection" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/9f/d5/b4867fa7c7f04c34997d7d8aad744f64d210bb99d67cf18bf3fb1eea1aed/pydantic-2.14.2.tar.gz", hash = "sha256:fb7b2db6cefe8414dd612edeede49c4c433acb0432b0f92b95024e45f66c505d", size = 911596, upload-time = "2026-10-29T16:37:12.476Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/97/01/c71a71258b58659c72504e5fd65b451f6e36e34dc931d0b237ded213c814/pydantic-2.14.2-py3-none-any.whl", hash = "sha256:7efbf7507b937931cd32a5755acb00ea1cf5ccb1d4e8067a5850d5069e382118", size = 490403, upload-time = "2026-10-29T16:37:10.181Z" }, +] + +[[package]] +name = "pydantic-core" +version = "2.50.2" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "typing-extensions" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/af/8e/23ec1021834e35041fbb2f10946141e6acdfd39379c45cc4d65a4e8a1d98/pydantic_core-2.50.2.tar.gz", hash = "sha256:1b0e8dc3932cf4e9ed5727570325cacc716b9409ffc794a221c0ccc72e8eb775", size = 518711, upload-time = "2026-10-29T16:34:57.465Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/d6/65/6609a66cda909d414c58438f9bd70b1e947fe12c25f6bd40c93121afd7ef/pydantic_core-2.50.2-cp312-cp312-macosx_10_12_x86_64.whl", hash = "sha256:e3d824b6152e1c0fd58dc6266f2de470eb7b2286135294f5f7cd26a0f0693738", size = 2220341, upload-time = "2026-10-29T16:32:10.193Z" }, + { url = "https://files.pythonhosted.org/packages/f9/0b/92463ae7be78d73885487f72c4599902c2cc190378bccaad5718b7495250/pydantic_core-2.50.2-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:596921489390a002d6a5e303384a0f1f98384f8bb550fbf38a1aafa6093da0f9", size = 2093701, upload-time = "2026-10-29T16:32:11.502Z" }, + { url = "https://files.pythonhosted.org/packages/62/d3/24147a1aa22f7eade546172750e1110fd7b2793998057809800d3ebeae4e/pydantic_core-2.50.2-cp312-cp312-manylinux1_i686.manylinux_2_5_i686.whl", hash = "sha256:36d8b9725684ca3bf658b90a101d335fc8cae405bb22196b7b5ef41344913756", size = 2253622, upload-time = "2026-10-29T16:32:13.051Z" }, + { url = "https://files.pythonhosted.org/packages/f6/50/2628ca3c83a0d9a6fda3305fe59b1b28e40c0221e8f234cd1ef86fb64745/pydantic_core-2.50.2-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:43a8fd56f3c681f3cda2d5c842ad28e88241df742dfcbe8fd1dd437a3056e1f6", size = 2114101, upload-time = "2026-10-29T16:32:14.702Z" }, + { url = "https://files.pythonhosted.org/packages/21/c8/cc6d7304a93f91f5e06260ccad71cc7d882489663a37dec009532379fc46/pydantic_core-2.50.2-cp312-cp312-manylinux2014_armv7l.manylinux_2_17_armv7l.whl", hash = "sha256:6f5a432c6c1ef18a1a02a04b3616b8d3f2f88b13faa46caae1ac6559ab202234", size = 2199541, upload-time = "2026-10-29T16:32:16.153Z" }, + { url = "https://files.pythonhosted.org/packages/65/d9/18f44ac5696b3e2b2384cb89c9fbe6ed69860f528e232b9fb46cc5b45a17/pydantic_core-2.50.2-cp312-cp312-manylinux2014_ppc64le.manylinux_2_17_ppc64le.whl", hash = "sha256:5d3cd8be71c4da3c9b42cc92f17e5e3036bdca98bf18555a0e072c3fe87abbb4", size = 2368597, upload-time = "2026-10-29T16:32:17.544Z" }, + { url = "https://files.pythonhosted.org/packages/1d/22/5f2a48ef819a7e1b74fb003a85d27576ad2f9ddf3901b88998ac63ce1e00/pydantic_core-2.50.2-cp312-cp312-manylinux2014_s390x.manylinux_2_17_s390x.whl", hash = "sha256:6a438cb8a3f87f2c49e82e43fb19511d4d5043f53e0787dc4df937ccb904373a", size = 2451701, upload-time = "2026-10-29T16:32:18.956Z" }, + { url = "https://files.pythonhosted.org/packages/08/93/2a6556bbdb8e918175af9d849a5d0b367b5644e41939d040f3a7215b1339/pydantic_core-2.50.2-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:9667637665acba166a7dbbc786f14c50512d3a01f7199e0e1a13b929e92d7c7a", size = 2242782, upload-time = "2026-10-29T16:32:20.381Z" }, + { url = "https://files.pythonhosted.org/packages/90/ed/dd9f29a92257f32eb5b99d5120826186ee0632ecc3aaf6c23e2fab89ed6d/pydantic_core-2.50.2-cp312-cp312-manylinux_2_31_riscv64.whl", hash = "sha256:b3e681208e2d39fde13fbea449ef2736a85ec1ea2afa41e9193a8c536e71dafe", size = 2253706, upload-time = "2026-10-29T16:32:22.293Z" }, + { url = "https://files.pythonhosted.org/packages/11/19/1ccf3bf38eb4ed97d8aeefc558458834ae0ad53fdbb1edf61af7228ea500/pydantic_core-2.50.2-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:6eb6ff07964f39e33c6f57fefe939514e76b8c0d4a694e5663e2e04e80cc1798", size = 2288603, upload-time = "2026-10-29T16:32:23.465Z" }, + { url = "https://files.pythonhosted.org/packages/ea/cd/bae2320fc89a65bcd87bf66ec83aac51b3b43b970a2edece15feb8af64dd/pydantic_core-2.50.2-cp312-cp312-musllinux_1_1_armv7l.whl", hash = "sha256:4eb54c25e3463d73e1e4ed439ffc45d1d7e590df40bc7bb06f11a906afd996c3", size = 2476597, upload-time = "2026-10-29T16:32:24.824Z" }, + { url = "https://files.pythonhosted.org/packages/db/35/1bdb8d52c8e562e95c5e6ebb5784792af568ac6a81470dd546d95f392b60/pydantic_core-2.50.2-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:91238117cd296352f54f24117ff5a227bdea428865dba1244aa0cdd1424c0bc2", size = 2478664, upload-time = "2026-10-29T16:32:26.197Z" }, + { url = "https://files.pythonhosted.org/packages/12/72/0179b40ac6a6b0899c61826f2e3e80f88063f6d821e0dd9641927de46700/pydantic_core-2.50.2-cp312-cp312-win32.whl", hash = "sha256:98722314e12a8e4fa346e0afd3fff2098b5732875ff45592b450a7b589b43c4f", size = 2108820, upload-time = "2026-10-29T16:32:27.736Z" }, + { url = "https://files.pythonhosted.org/packages/b4/fb/679144362d7e5162519d9f6631ec982521417de3196351c6c56485f5b29f/pydantic_core-2.50.2-cp312-cp312-win_amd64.whl", hash = "sha256:b381574614245f18fdb2d6d1aa8f149e225869c47b5ee7f81812de8977817314", size = 2252238, upload-time = "2026-10-29T16:32:29.572Z" }, + { url = "https://files.pythonhosted.org/packages/0f/68/e3ccc885c3e2086ff84d7ca496f45b974a9f0a49ce2da8973aaa3a369a4b/pydantic_core-2.50.2-cp312-cp312-win_arm64.whl", hash = "sha256:f07c965a8aa6d62145f122641f292129984f39a3e3697585b19298a1488287db", size = 2162565, upload-time = "2026-10-29T16:32:30.853Z" }, + { url = "https://files.pythonhosted.org/packages/64/4d/23560b11366b547e3e68a3b8f9c02557cee707effa54fd39dbb3c4fff1fa/pydantic_core-2.50.2-graalpy312-graalpy250_312_native-macosx_10_12_x86_64.whl", hash = "sha256:d18d56c1ec63b304f4bb3c7db7e0d311e61cca1b1c944590a4b13ac39b2ca92b", size = 2204868, upload-time = "2026-10-29T16:34:34.745Z" }, + { url = "https://files.pythonhosted.org/packages/06/58/b9ddfaad189143d6568627166a730b6624ca90bd9a9a4af4854df88d444b/pydantic_core-2.50.2-graalpy312-graalpy250_312_native-macosx_11_0_arm64.whl", hash = "sha256:41ed8abeffda6a880207fdc0cd1343a448cec3cc6b38b53f730c0745f745292d", size = 2049162, upload-time = "2026-10-29T16:34:36.186Z" }, + { url = "https://files.pythonhosted.org/packages/8b/20/99d259bf7835b2f13c6d0b3eb7bcf669fb6349986736fa7a8308a9e620b0/pydantic_core-2.50.2-graalpy312-graalpy250_312_native-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:b7abcfaf66c1dc14c5ed928c349614f223c972a8b021b4be9548dbea6c817371", size = 2112135, upload-time = "2026-10-29T16:34:37.777Z" }, + { url = "https://files.pythonhosted.org/packages/9b/ca/652c8fe599abacafd852479059d209e608596ad3de82f1bff22e9f0f02fe/pydantic_core-2.50.2-graalpy312-graalpy250_312_native-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:9e7460abce637f90e37f8c443559fbd687c38884d05cb69ef265e634945f4324", size = 2270339, upload-time = "2026-10-29T16:34:39.039Z" }, +] + +[[package]] +name = "pydantic-settings" +version = "2.16.2" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "pydantic" }, + { name = "python-dotenv" }, + { name = "typing-extensions" }, + { name = "typing-inspection" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/d0/31/21d21e0e38a8f5f7a7f0cde22820117b6d17d6bc36f348129527f915d7f4/pydantic_settings-2.16.2.tar.gz", hash = "sha256:3dc08ffabed2bbd5dc2dd55ead7b78b4e4c5cd776aecd04310db5f1224caaf46", size = 309225, upload-time = "2026-10-28T11:14:28.066Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/39/88/4131c51ff87b7cd7f82a1194d0c0a2b7ca68c72d9da04c3b7e69ab91a79f/pydantic_settings-2.16.2-py3-none-any.whl", hash = "sha256:8d523e5c129b097686bde019bd6109bff53f4c8c3f63f1ddf9933ffa42e5ab4f", size = 81994, upload-time = "2026-10-28T11:14:26.716Z" }, +] + +[[package]] +name = "pygments" +version = "2.21.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/49/2e/ced460408999b33da6b31b0021b0f37d329e202d4169aeb164493778f25b/pygments-2.21.0.tar.gz", hash = "sha256:610ca751c9bc2492b38eb9a38a7fbc93edbbb2d7182edaf34e66ae493dee5c8c", size = 5005329, upload-time = "2026-08-17T08:02:48.824Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/71/46/17f022dd3e953bf20a04a028a21ec746d942f8d2af30fa0f124fa0e6a684/pygments-2.21.0-py3-none-any.whl", hash = "sha256:2363c69b61c4a97c838da3b130dcd6468f4848992b21a82f2a63ec34377137d9", size = 1250147, upload-time = "2026-08-17T08:02:44.912Z" }, +] + +[[package]] +name = "pytest" +version = "9.2.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "colorama", marker = "sys_platform == 'win32'" }, + { name = "iniconfig" }, + { name = "packaging" }, + { name = "pluggy" }, + { name = "pygments" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/79/42/bb4641652e58dedeac2ec51abc1f8cae4fee4ec63899a0999016229a0f2a/pytest-9.2.0.tar.gz", hash = "sha256:97c4f3b1f3c7414aa36465e09b8220f1d03627993bd51b1282e193753c80557b", size = 1797555, upload-time = "2026-10-27T21:30:20.728Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/51/39/1f5d8c8877a0fa327db959c19341d4be61660de1ab6b7391f9eb805bcd67/pytest-9.2.0-py3-none-any.whl", hash = "sha256:07acdcf88ec174f907dc01af70bf52d49b014bbab03faeeade31c96b18c2e588", size = 411776, upload-time = "2026-10-27T21:30:19.131Z" }, +] + +[[package]] +name = "python-dateutil" +version = "2.9.0.post0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "six" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/66/c0/0c8b6ad9f17a802ee498c46e004a0eb49bc148f2fd230864601a86dcf6db/python-dateutil-2.9.0.post0.tar.gz", hash = "sha256:37dd54208da7e1cd875388217d5e00ebd4179249f90fb72437e91a35459a0ad3", size = 342432, upload-time = "2024-03-01T18:36:20.211Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/ec/57/56b9bcc3c9c6a792fcbaf139543cee77261f3651ca9da0c93f5c1221264b/python_dateutil-2.9.0.post0-py2.py3-none-any.whl", hash = "sha256:a8b2bc7bffae282281c8140a97d3aa9c14da0b136dfe83f850eea9a5f7470427", size = 229892, upload-time = "2024-03-01T18:36:18.57Z" }, +] + +[[package]] +name = "python-dotenv" +version = "1.2.4" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/74/26/2fbeedb218a787a5eea551c7532cac4e009f83d689dd2faa0d0353473f86/python_dotenv-1.2.4.tar.gz", hash = "sha256:f0d53e69935a851c0dcc78f3ab7aaccd8cabef0b92382b576b824212902873c0", size = 60824, upload-time = "2026-10-01T05:36:10Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/60/d1/38f3a3405989a89ac18390803e70c6ad7c7760da4f9b83cbeca0c44a0c72/python_dotenv-1.2.4-py3-none-any.whl", hash = "sha256:42269a8a5b3fd54ffa6f3d84b18abed50064717576b4ecf03dc4a55d8aa04fdc", size = 23266, upload-time = "2026-10-01T05:36:08.633Z" }, +] + +[[package]] +name = "pyyaml" +version = "6.0.3" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/05/8e/961c0007c59b8dd7729d542c61a4d537767a59645b82a0b521206e1e25c2/pyyaml-6.0.3.tar.gz", hash = "sha256:d76623373421df22fb4cf8817020cbb7ef15c725b9d5e45f17e189bfc384190f", size = 130960, upload-time = "2025-09-25T21:33:16.546Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/d1/33/422b98d2195232ca1826284a76852ad5a86fe23e31b009c9886b2d0fb8b2/pyyaml-6.0.3-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:7f047e29dcae44602496db43be01ad42fc6f1cc0d8cd6c83d342306c32270196", size = 182063, upload-time = "2025-09-25T21:32:11.445Z" }, + { url = "https://files.pythonhosted.org/packages/89/a0/6cf41a19a1f2f3feab0e9c0b74134aa2ce6849093d5517a0c550fe37a648/pyyaml-6.0.3-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:fc09d0aa354569bc501d4e787133afc08552722d3ab34836a80547331bb5d4a0", size = 173973, upload-time = "2025-09-25T21:32:12.492Z" }, + { url = "https://files.pythonhosted.org/packages/ed/23/7a778b6bd0b9a8039df8b1b1d80e2e2ad78aa04171592c8a5c43a56a6af4/pyyaml-6.0.3-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:9149cad251584d5fb4981be1ecde53a1ca46c891a79788c0df828d2f166bda28", size = 775116, upload-time = "2025-09-25T21:32:13.652Z" }, + { url = "https://files.pythonhosted.org/packages/65/30/d7353c338e12baef4ecc1b09e877c1970bd3382789c159b4f89d6a70dc09/pyyaml-6.0.3-cp312-cp312-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:5fdec68f91a0c6739b380c83b951e2c72ac0197ace422360e6d5a959d8d97b2c", size = 844011, upload-time = "2025-09-25T21:32:15.21Z" }, + { url = "https://files.pythonhosted.org/packages/8b/9d/b3589d3877982d4f2329302ef98a8026e7f4443c765c46cfecc8858c6b4b/pyyaml-6.0.3-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:ba1cc08a7ccde2d2ec775841541641e4548226580ab850948cbfda66a1befcdc", size = 807870, upload-time = "2025-09-25T21:32:16.431Z" }, + { url = "https://files.pythonhosted.org/packages/05/c0/b3be26a015601b822b97d9149ff8cb5ead58c66f981e04fedf4e762f4bd4/pyyaml-6.0.3-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:8dc52c23056b9ddd46818a57b78404882310fb473d63f17b07d5c40421e47f8e", size = 761089, upload-time = "2025-09-25T21:32:17.56Z" }, + { url = "https://files.pythonhosted.org/packages/be/8e/98435a21d1d4b46590d5459a22d88128103f8da4c2d4cb8f14f2a96504e1/pyyaml-6.0.3-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:41715c910c881bc081f1e8872880d3c650acf13dfa8214bad49ed4cede7c34ea", size = 790181, upload-time = "2025-09-25T21:32:18.834Z" }, + { url = "https://files.pythonhosted.org/packages/74/93/7baea19427dcfbe1e5a372d81473250b379f04b1bd3c4c5ff825e2327202/pyyaml-6.0.3-cp312-cp312-win32.whl", hash = "sha256:96b533f0e99f6579b3d4d4995707cf36df9100d67e0c8303a0c55b27b5f99bc5", size = 137658, upload-time = "2025-09-25T21:32:20.209Z" }, + { url = "https://files.pythonhosted.org/packages/86/bf/899e81e4cce32febab4fb42bb97dcdf66bc135272882d1987881a4b519e9/pyyaml-6.0.3-cp312-cp312-win_amd64.whl", hash = "sha256:5fcd34e47f6e0b794d17de1b4ff496c00986e1c83f7ab2fb8fcfe9616ff7477b", size = 154003, upload-time = "2025-09-25T21:32:21.167Z" }, + { url = "https://files.pythonhosted.org/packages/1a/08/67bd04656199bbb51dbed1439b7f27601dfb576fb864099c7ef0c3e55531/pyyaml-6.0.3-cp312-cp312-win_arm64.whl", hash = "sha256:64386e5e707d03a7e172c0701abfb7e10f0fb753ee1d773128192742712a98fd", size = 140344, upload-time = "2025-09-25T21:32:22.617Z" }, +] + +[[package]] +name = "redis" +version = "8.1.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/a8/99/604f0b666d4c616d891cf77ebb9db6bb21601344c051aebf1b72b9ff915f/redis-8.1.0.tar.gz", hash = "sha256:6e1a19beef9225c83efd689c7e6b7da2d5215b1f42cd13b7fc3714d0a09c7b25", size = 5254356, upload-time = "2026-07-30T08:51:00.269Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/66/9d/c5731f6e3608663d4d3656fd8d3aecee8b509c3082818f5a13eae925baea/redis-8.1.0-py3-none-any.whl", hash = "sha256:a4fe1aac3d3b3cc791d4b3d5931c5a956045dc951ee74d1c913ee3ac4d2ee9fb", size = 560618, upload-time = "2026-07-30T08:50:58.497Z" }, +] + +[[package]] +name = "referencing" +version = "0.37.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "attrs" }, + { name = "rpds-py" }, + { name = "typing-extensions" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/22/f5/df4e9027acead3ecc63e50fe1e36aca1523e1719559c499951bb4b53188f/referencing-0.37.0.tar.gz", hash = "sha256:44aefc3142c5b842538163acb373e24cce6632bd54bdb01b21ad5863489f50d8", size = 78036, upload-time = "2025-10-13T15:30:48.871Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/2c/58/ca301544e1fa93ed4f80d724bf5b194f6e4b945841c5bfd555878eea9fcb/referencing-0.37.0-py3-none-any.whl", hash = "sha256:381329a9f99628c9069361716891d34ad94af76e461dcb0335825aecc7692231", size = 26766, upload-time = "2025-10-13T15:30:47.625Z" }, +] + +[[package]] +name = "requests" +version = "2.34.2" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "certifi" }, + { name = "charset-normalizer" }, + { name = "idna" }, + { name = "urllib3" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/ac/c3/e2a2b89f2d3e2179abd6d00ebd70bff6273f37fb3e0cc209f48b39d00cbf/requests-2.34.2.tar.gz", hash = "sha256:f288924cae4e29463698d6d60bc6a4da69c89185ad1e0bcc4104f584e960b9ed", size = 142856, upload-time = "2026-05-14T19:25:27.735Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/a0/f4/c67b0b3f1b9245e8d266f0f112c500d50e5b4e83cb6f3b71b6528104182a/requests-2.34.2-py3-none-any.whl", hash = "sha256:2a0d60c172f83ac6ab31e4554906c0f3b3588d37b5cb939b1c061f4907e278e0", size = 73075, upload-time = "2026-05-14T19:25:26.443Z" }, +] + +[[package]] +name = "rfc3339-validator" +version = "0.1.4" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "six" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/28/ea/a9387748e2d111c3c2b275ba970b735e04e15cdb1eb30693b6b5708c4dbd/rfc3339_validator-0.1.4.tar.gz", hash = "sha256:138a2abdf93304ad60530167e51d2dfb9549521a836871b88d7f4695d0022f6b", size = 5513, upload-time = "2021-05-12T16:37:54.178Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/7b/44/4e421b96b67b2daff264473f7465db72fbdf36a07e05494f50300cc7b0c6/rfc3339_validator-0.1.4-py2.py3-none-any.whl", hash = "sha256:24f6ec1eda14ef823da9e36ec7113124b39c04d50a4d3d3a3c2859577e7791fa", size = 3490, upload-time = "2021-05-12T16:37:52.536Z" }, +] + +[[package]] +name = "rpds-py" +version = "2026.9.1" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/42/68/3bd46b8a5e01d3c2ebdf9c5e9497912e3fe0cde02bac21a7130ca866e403/rpds_py-2026.9.1.tar.gz", hash = "sha256:4793ef7f78268b124b73fa933440f01d258bbae01de9fa53e9080c9ab0425a12", size = 63948, upload-time = "2026-10-04T16:32:36.469Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/5d/34/a828586ea3329fbb50895b50e9cf98ca3d924a9f41a0b26d443bff1b3794/rpds_py-2026.9.1-cp312-cp312-macosx_10_12_x86_64.whl", hash = "sha256:50906f5aea24b5a865cbd0a589698288631d9f3a54c3a937c83aefa95a0d14af", size = 346822, upload-time = "2026-10-04T16:29:16.258Z" }, + { url = "https://files.pythonhosted.org/packages/90/81/ac6a0d064982251856ce009c9e1dd51a34110b3c055aa7d1aad18b4899a3/rpds_py-2026.9.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:e21c1429e205828ea886a2293a4a2c8e01f4c25d9893ca330e97a6cf73f52e7b", size = 341380, upload-time = "2026-10-04T16:29:17.706Z" }, + { url = "https://files.pythonhosted.org/packages/42/ff/bf7d54f362748fd6a49277b9d6531c394074110fedf50ad791ec59133fbb/rpds_py-2026.9.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:2693b2728bbcc48d09a981a356954b0c47c53ff25b545856f28a889ea619f69a", size = 373053, upload-time = "2026-10-04T16:29:19.063Z" }, + { url = "https://files.pythonhosted.org/packages/60/de/74b0ccdbbd28687b9b5fdb34c1cabed88352182facaced9d6f5486b8b9ed/rpds_py-2026.9.1-cp312-cp312-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:8601470267d938bcb7f3ab1a336100af51a4fd5b6ed030ef52461bb3ef5e7e07", size = 377742, upload-time = "2026-10-04T16:29:20.543Z" }, + { url = "https://files.pythonhosted.org/packages/c2/6d/b979775a3057b2a5c26d75ecbff60a20a24ef081db6dd76836fca3f20247/rpds_py-2026.9.1-cp312-cp312-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:3890a6aa36e6baa53d5258a2a25d3ef8b37ad165a6ab27a892d7c3e3a432cd69", size = 487289, upload-time = "2026-10-04T16:29:21.958Z" }, + { url = "https://files.pythonhosted.org/packages/1d/5d/7c34734ce3ece943d9d6ee0122a74a21bbc75b47acb5b7053c83f6efb1ed/rpds_py-2026.9.1-cp312-cp312-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:6b5b393eda5ea42cca1c1a6665f2a4882b4fd5d1777e41ce0545a107fb008c9d", size = 390710, upload-time = "2026-10-04T16:29:23.378Z" }, + { url = "https://files.pythonhosted.org/packages/1d/6d/b26eb1e75395925b3a142ed351cbed2ec8212f5c9d937aee3df32c701baa/rpds_py-2026.9.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:addeda51556dac7c1a2f14cda62db8b621cd12afba3091d03a96c72932387eab", size = 371261, upload-time = "2026-10-04T16:29:25.1Z" }, + { url = "https://files.pythonhosted.org/packages/7c/98/b2fdfe10301a9e27af21e634337fbba7baac0bc17fe44619a17c26bba2cb/rpds_py-2026.9.1-cp312-cp312-manylinux_2_31_riscv64.whl", hash = "sha256:d9edf30457d74eebfd76b045535e36f1cd89062566a128a0db2145ca042d787e", size = 376075, upload-time = "2026-10-04T16:29:26.748Z" }, + { url = "https://files.pythonhosted.org/packages/c5/b1/c4b8d954e49c3c69cf8063c0c9e0919c99f3d2cecc46311606a1cbe835dc/rpds_py-2026.9.1-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:815d26356930846a40c7bc1366e7b1b0320ab8a063e66c11298a208bed0fd237", size = 399358, upload-time = "2026-10-04T16:29:28.282Z" }, + { url = "https://files.pythonhosted.org/packages/b3/59/9559a7293c97dff0cbb293efffbd36644103883ecc27741af8ef90c84ca8/rpds_py-2026.9.1-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:3b5a6f40f0a1486b4b36c888123afc67acdbd9f33235927acf5ff295429a0ba3", size = 550267, upload-time = "2026-10-04T16:29:29.851Z" }, + { url = "https://files.pythonhosted.org/packages/6c/9d/6dc60e49511de4c8b00e74f9c1d43aed4d27f712cdb1ade92f2c199cbf64/rpds_py-2026.9.1-cp312-cp312-musllinux_1_2_i686.whl", hash = "sha256:b5b8b0753718d258fd454283fbd57e14545d3b40583fa672e27cb4f987626bcc", size = 614018, upload-time = "2026-10-04T16:29:31.54Z" }, + { url = "https://files.pythonhosted.org/packages/fb/bc/92a4ecf27301b886232a413360f6b348a81d55ffef654f2ebda5970ebc3d/rpds_py-2026.9.1-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:46d80bc76b51a6c24f9944368c28d38b8bcbcea1da4f2f8d3ebc31a67e8c6ec6", size = 578509, upload-time = "2026-10-04T16:29:33.01Z" }, + { url = "https://files.pythonhosted.org/packages/08/53/efb97f2e6589b7ab8394385a73870e0b2ab2a195281c117b21fd6d7d4855/rpds_py-2026.9.1-cp312-cp312-win32.whl", hash = "sha256:befc2d6a953e563f8a7bfd87a42c22ebf8a3e980dcb7b6a4d17b70b0e914e8a3", size = 205401, upload-time = "2026-10-04T16:29:34.451Z" }, + { url = "https://files.pythonhosted.org/packages/1c/84/1700cc748d0eaa747486e4e82882d2575224e6e9a3148df583058850c629/rpds_py-2026.9.1-cp312-cp312-win_amd64.whl", hash = "sha256:5ce8943f79c2210f7abcc28e86367b03b28d95027fd01c46d2472373ae70c86f", size = 222923, upload-time = "2026-10-04T16:29:35.709Z" }, + { url = "https://files.pythonhosted.org/packages/c3/89/0302215373c2f8b4408b0fdfee955368cc378a98ff59508d47a7e0dc2dbf/rpds_py-2026.9.1-cp312-cp312-win_arm64.whl", hash = "sha256:501909f2e4a1e2dee528ef766fe3c469060ebc17e54a8383d404ba07a81a6f02", size = 218415, upload-time = "2026-10-04T16:29:37.263Z" }, + { url = "https://files.pythonhosted.org/packages/a3/90/a9ba81408369d34c1aca73319c15adc91ed45c1d21e9e8ee4832ffb7fe0b/rpds_py-2026.9.1-pp312-pypy312_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:6cdc537c8633d7fd92a82e2e0d2ab74320a3f63d5e59fb9cf08711e08fe151c4", size = 381109, upload-time = "2026-10-04T16:32:08.994Z" }, + { url = "https://files.pythonhosted.org/packages/b3/44/5192a0bed94cec86bd2a5e1cc5a1bb8f7eec3aec907eacd2deb13e87e326/rpds_py-2026.9.1-pp312-pypy312_pp73-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:10e208f2425d973938afcd56e28a7c4be32e27b6a60b5d381f49fb9d8acf9759", size = 388222, upload-time = "2026-10-04T16:32:11.321Z" }, + { url = "https://files.pythonhosted.org/packages/92/cd/5356549711448f18b52f7a11ffbe90f1228774996fbf3c6cd1b18d22abaf/rpds_py-2026.9.1-pp312-pypy312_pp73-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:6c0dbbcc19735fe5f8b0a54c07659d154a9e69f47e15d0a6ab7299215daf62cb", size = 500384, upload-time = "2026-10-04T16:32:13.478Z" }, + { url = "https://files.pythonhosted.org/packages/7a/88/ddda9d28adfe33119c75b2e733d4ba7e326f41d7e1b1093951771768ca48/rpds_py-2026.9.1-pp312-pypy312_pp73-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:684fd492fff4fead00587544e059be2bbcb6f93454f21fa2a91b66fc7508be82", size = 401661, upload-time = "2026-10-04T16:32:15.653Z" }, + { url = "https://files.pythonhosted.org/packages/32/c3/bb59ba16a6b4a57995d15b8c04c00f28df3b938c4dcdde48fbe0f73edb0c/rpds_py-2026.9.1-pp312-pypy312_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d1028417bb44037eb3069c1009bd7b7277212876cda22fbe565b0bca9fab6d2c", size = 380748, upload-time = "2026-10-04T16:32:17.727Z" }, + { url = "https://files.pythonhosted.org/packages/f5/b8/0580faa1c5a32ddc160130dd7ae54d2d007272a89a40a6b5db3e50f9f585/rpds_py-2026.9.1-pp312-pypy312_pp73-manylinux_2_31_riscv64.whl", hash = "sha256:492e5e428cbe126221611f47e068f01660352feec4ad18bc0f5ea9b2ae88fb14", size = 385731, upload-time = "2026-10-04T16:32:19.855Z" }, + { url = "https://files.pythonhosted.org/packages/bf/70/f73564642bbe3322c7eeef2c2f258cf040b71c41a430b532e59d04a1b838/rpds_py-2026.9.1-pp312-pypy312_pp73-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:88b5268892fde430d5531f95bc560b6efbbd67c929662c586afd729a96e7461c", size = 412131, upload-time = "2026-10-04T16:32:22.285Z" }, + { url = "https://files.pythonhosted.org/packages/8c/5d/17fff2e1f8f68721a2afb5cb48f7e442c751bb6b4883157c5abaf618cd08/rpds_py-2026.9.1-pp312-pypy312_pp73-musllinux_1_2_aarch64.whl", hash = "sha256:01445c8d194aa032a08e944f16567672da1c62dbdbefd8b6d0693032e290cf68", size = 558193, upload-time = "2026-10-04T16:32:24.4Z" }, + { url = "https://files.pythonhosted.org/packages/2a/d0/869ab6fb08531f97aae4a780b4d61b4190d8aef48fe054ee28bcf7114466/rpds_py-2026.9.1-pp312-pypy312_pp73-musllinux_1_2_i686.whl", hash = "sha256:eef6a03b0b6d08d0835ccfa8ec8d1bc70525e3801387567137b50c557695e6da", size = 622448, upload-time = "2026-10-04T16:32:26.844Z" }, + { url = "https://files.pythonhosted.org/packages/ba/a5/9672e532fe02cd3b92c78cfd8743abca939d96853006c63835009a1ecb6f/rpds_py-2026.9.1-pp312-pypy312_pp73-musllinux_1_2_x86_64.whl", hash = "sha256:6b9bf3135b4ad5981df9a73d71a35272d650a2985ae9c2746357b24d59de2448", size = 591126, upload-time = "2026-10-04T16:32:29.274Z" }, + { url = "https://files.pythonhosted.org/packages/80/ef/3a9f8e4279c7920af561deed4cb7ebebed2794a8f608cf404d5eef14a105/rpds_py-2026.9.1-pp312-pypy312_pp80-macosx_10_12_x86_64.whl", hash = "sha256:56c6952a9b15047466d0c2347c446a761d4527f89976156341e68f0ce5cc08b0", size = 357108, upload-time = "2026-10-04T16:32:31.641Z" }, + { url = "https://files.pythonhosted.org/packages/b7/55/4b2fa381a583760aea5c92841e4e928a358e1c6511b129219e9c2826a226/rpds_py-2026.9.1-pp312-pypy312_pp80-macosx_11_0_arm64.whl", hash = "sha256:b242c27c8f836305a4a72df9cdd564386ac57b807bd252a063223331c9316b37", size = 346877, upload-time = "2026-10-04T16:32:34.061Z" }, +] + +[[package]] +name = "ruff" +version = "0.17.3" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/59/73/81f140c4edd9cc323de5478e6bbd3bbcfae9a82692df1a258de8cec6a6d2/ruff-0.17.3.tar.gz", hash = "sha256:a57049c8addb3662073859bb55a7ad35aa54f8a7c9ed268911d1333c5aadaaa9", size = 5339444, upload-time = "2026-10-27T00:34:05.914Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/9e/8c/083365310c4e79c842f25bf5a842facbd9b0c0ec336f96dffa5074fe723d/ruff-0.17.3-py3-none-linux_armv6l.whl", hash = "sha256:ab86b84cd9d05e56d329742c0cabdcbe2d1d56c98f4a04aab9b5b66196febfb4", size = 10216522, upload-time = "2026-10-27T00:33:29.822Z" }, + { url = "https://files.pythonhosted.org/packages/72/26/4b2edf31cfebe9605d8f6ed8f1d6f376d3a53d4c9a123e62661c64c440f0/ruff-0.17.3-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:e407b4a6852853a9a2cdce96963e94ad9775578bb44e7561a0f2829f3cc04b11", size = 10217786, upload-time = "2026-10-27T00:33:33.949Z" }, + { url = "https://files.pythonhosted.org/packages/a2/7e/537aba4b7f54397a374d2f6a6fc93e9c8015e18553f31a4a7b7dbced48b5/ruff-0.17.3-py3-none-macosx_11_0_arm64.whl", hash = "sha256:b75cc113b3aca388933d8296b667b1ac401a80317ea3074c9b0a66541199da29", size = 9440362, upload-time = "2026-10-27T00:33:35.784Z" }, + { url = "https://files.pythonhosted.org/packages/3d/66/283e39734f66c8a5ebaa93c22eb7b7515779a0b1d5a5c0ad20e05c0edb41/ruff-0.17.3-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:ab5fa7ed5ce18554ea69d850ad162cbaa0c85fc47c08d83a569f806681c9a6ad", size = 10094281, upload-time = "2026-10-27T00:33:38.216Z" }, + { url = "https://files.pythonhosted.org/packages/21/4c/1ffc768497bd025a32c72152771e40c0b99bddc5cc6e4f50c7949a395346/ruff-0.17.3-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:c673c170e27834d1262e3a9c1e97bdc9b9c3b180c63d89173ce69747232474c1", size = 10022543, upload-time = "2026-10-27T00:33:40.181Z" }, + { url = "https://files.pythonhosted.org/packages/73/c3/f90db547301080fcb82c92abf914c8bd57b89911d9b65a6c4cc6b52d0635/ruff-0.17.3-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:6a754c0341bc9ca151b7b335988b3263921c08859f84ca219b70cee825571b6f", size = 10683921, upload-time = "2026-10-27T00:33:42.182Z" }, + { url = "https://files.pythonhosted.org/packages/e5/98/92d4a8a26c6c96cf1a5b34dd59036d8a71e52d650aab065c58867e964e63/ruff-0.17.3-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:4590b9d86c0b1543ebb09094254e191cd43fe8edaf330baa035aab03da251532", size = 11373408, upload-time = "2026-10-27T00:33:44.19Z" }, + { url = "https://files.pythonhosted.org/packages/43/02/1f24d2e3064c9753926deeb901afa57777b37ee46799b09ddd7aee6e5145/ruff-0.17.3-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:bbde18beccd98c29a227c63c99022e3443b99258e08326df6425dfe0443705ef", size = 10977469, upload-time = "2026-10-27T00:33:46.179Z" }, + { url = "https://files.pythonhosted.org/packages/f0/20/fecedea2209f574ab92033b344e01a7f0c2dc76c6d6d19a14c9f8141173f/ruff-0.17.3-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:7fa4b0f931cdbcb8a52044f370a3eb429fb42eb88807b0e800fcaa98dd42b24e", size = 10577491, upload-time = "2026-10-27T00:33:48.233Z" }, + { url = "https://files.pythonhosted.org/packages/33/36/b93fdf0bc6f84f0cd487aadfb0354deb40013669ea35ac3d26855de1e959/ruff-0.17.3-py3-none-manylinux_2_31_riscv64.whl", hash = "sha256:39405f341deec934b4289634324ad695f72df2970f9121582872eaf5b722f0f5", size = 10608748, upload-time = "2026-10-27T00:33:50.284Z" }, + { url = "https://files.pythonhosted.org/packages/5d/b7/7d3f5f14145daead1efb0b9a8289ed1daa100f419d60774375951723ce00/ruff-0.17.3-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:68074094f55ca3d29ab19491f640282f7a84061c4c7977aa5094b968ca457e9a", size = 10075057, upload-time = "2026-10-27T00:33:52.074Z" }, + { url = "https://files.pythonhosted.org/packages/b0/ed/93ff7a5909ee56e2bd4b982deae9e0efb2724417874a90c9e41ad66c6dd7/ruff-0.17.3-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:27bb571ac78fef178fe5118d2827df95c2aae74a48fff2b15f6acd03af5ff5bb", size = 10022431, upload-time = "2026-10-27T00:33:54.061Z" }, + { url = "https://files.pythonhosted.org/packages/9b/07/a83b9eeec8c1c3c0e4eda15f06c3a91001bfd2687ea2f07b750719bf9712/ruff-0.17.3-py3-none-musllinux_1_2_i686.whl", hash = "sha256:029c37cbd3de48ca37aa12117bead2d065f15da17d66bf84e0d4274013705db2", size = 10394903, upload-time = "2026-10-27T00:33:56.158Z" }, + { url = "https://files.pythonhosted.org/packages/af/b2/05c39857c2526fcbebe46ad93a8dc97424656dfef14d3ef933abe1ffd331/ruff-0.17.3-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:692fdb46d0fd9c71e380947dc5fc72f2c3f881073bc1f739e4579376231affbe", size = 10799780, upload-time = "2026-10-27T00:33:58.204Z" }, + { url = "https://files.pythonhosted.org/packages/ec/d9/47171a16739eb7a353936b31c20cf54340531e68c9af7d72fd7a784e235d/ruff-0.17.3-py3-none-win32.whl", hash = "sha256:46539cb031b01fd29ae0a02142483c46640b233ee12bb1c1b690bffa1555d5ca", size = 9908481, upload-time = "2026-10-27T00:34:00.087Z" }, + { url = "https://files.pythonhosted.org/packages/d0/a0/f08c1631bfd81faa6a90eaf70c37c786c11bed2046302b56bb506c25e1a0/ruff-0.17.3-py3-none-win_amd64.whl", hash = "sha256:56b8ffb3f3b3cbccb8b76b71b38261b7ed982ef5d20f5b447b1b61a7f4949b24", size = 10341333, upload-time = "2026-10-27T00:34:02.099Z" }, + { url = "https://files.pythonhosted.org/packages/99/d5/4ad4ed31413c301430918e70d3d38ae6f097af0766cb9ab8c9d502b2a4d6/ruff-0.17.3-py3-none-win_arm64.whl", hash = "sha256:81fce74bcd6be0e9da7c67c7553fd0f1f12964a2052cd728ef917b937a5ca1d9", size = 9854332, upload-time = "2026-10-27T00:34:03.847Z" }, +] + +[[package]] +name = "s3transfer" +version = "0.19.3" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "botocore" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/49/c5/0a5ce655109cb96b8dfad36908a4e108d15f5dc2eff8fbc3146c4312e704/s3transfer-0.19.3.tar.gz", hash = "sha256:8326acc3d056d7f7b8a37110c7d2aea41f67e83f6ae79cd3b5fbcca34c726406", size = 166087, upload-time = "2026-10-19T19:19:49.751Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/e2/a4/88f9e10498759121060b8050a1554753dfc04df39bbbcc7aad9ecc8d9440/s3transfer-0.19.3-py3-none-any.whl", hash = "sha256:24eb7535804306355e31c952a90022bf5b2f9d760f9a11062c7493a217c08553", size = 90252, upload-time = "2026-10-19T19:19:48.309Z" }, +] + +[[package]] +name = "six" +version = "1.17.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/94/e7/b2c673351809dca68a0e064b6af791aa332cf192da575fd474ed7d6f16a2/six-1.17.0.tar.gz", hash = "sha256:ff70335d468e7eb6ec65b95b99d3a2836546063f63acc5171de367e834932a81", size = 34031, upload-time = "2024-12-04T17:35:28.174Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/b7/ce/149a00dd41f10bc29e5921b496af8b574d8413afcd5e30dfa0ed46c2cc5e/six-1.17.0-py2.py3-none-any.whl", hash = "sha256:4721f391ed90541fddacab5acf947aa0d3dc7d27b2e1e8eda2be8970586c3274", size = 11050, upload-time = "2024-12-04T17:35:26.475Z" }, +] + +[[package]] +name = "starlette" +version = "1.10.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "anyio" }, + { name = "typing-extensions" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/48/bb/3d8757f21e9a53d9035c9eb039a777047139a16bfdbedfc7a58241c3d914/starlette-1.10.0.tar.gz", hash = "sha256:b8399098d4c1e3522734f7235dc79b1fc967f96cf139c81e0fa30479e0685f9b", size = 2734356, upload-time = "2026-10-24T15:04:12.342Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/88/2e/947cfe02def9371c07cd5bf5b6b61c829e9aecb9904db02a66cfafbc1eec/starlette-1.10.0-py3-none-any.whl", hash = "sha256:478c0ab3b4ced6e82719849c118fa406f0278a3499c1a898cd15cd31bdc38ce4", size = 80571, upload-time = "2026-10-24T15:04:10.371Z" }, +] + +[[package]] +name = "typing-extensions" +version = "4.16.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/f6/cc/6253133b5bb138fc3306cebfbda2c520f545d36b5be2c7255cc528bb45d6/typing_extensions-4.16.0.tar.gz", hash = "sha256:dc983d19a509c94dba722ee6abd33940f7c05a89e243c47e907eb4db6f1a43e5", size = 113555, upload-time = "2026-07-02T08:40:05.92Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/49/d3/b8441a820a491ddfc024b0b0cf0393375b75ea13866d9c66727e54c2fc80/typing_extensions-4.16.0-py3-none-any.whl", hash = "sha256:481caa481374e813c1b176ada14e97f1f67a4539ce9cfeb3f350d78d6370c2e8", size = 45571, upload-time = "2026-07-02T08:40:04.659Z" }, +] + +[[package]] +name = "typing-inspection" +version = "0.4.4" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "typing-extensions" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/a3/26/b09b8010994eccc3c09092e6b34058f36a460eea2d4c3e8b910c695975a0/typing_inspection-0.4.4.tar.gz", hash = "sha256:547274fa6b0a561ccf549cc9524b999a578e737d015d8709d021f9d0d13bea47", size = 76928, upload-time = "2026-08-12T12:37:25.997Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/67/81/4add07e5172b7ac40d8ed5ff580409a7801a4fe26d529bdd915401dabfbe/typing_inspection-0.4.4-py3-none-any.whl", hash = "sha256:65b8397ba37ccbce054456aaccddfc91e6e3083c92824df348d96ca832f3f147", size = 14750, upload-time = "2026-08-12T12:37:24.648Z" }, +] + +[[package]] +name = "tzdata" +version = "2026.6" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/7a/29/6a1391d31cd00ff9e927215a224a880e1e84e826b64ba80a499e51c074d8/tzdata-2026.6.tar.gz", hash = "sha256:85d2cd9c09f81f0bb29db27759fc83af4f1e620efb814f8c5bf8b4cc4feece6d", size = 201017, upload-time = "2026-10-28T09:57:09.137Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/0a/66/9a06c2227fedfd4919f0eaaa8b94377d9730882a7e4f95823c9a331ab5e1/tzdata-2026.6-py2.py3-none-any.whl", hash = "sha256:0a10eec6e13ef16b627fabed9a5f2ba61a62b1c67f327305f4e7e412a70b4aec", size = 348210, upload-time = "2026-10-28T09:57:07.276Z" }, +] + +[[package]] +name = "urllib3" +version = "2.8.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/e3/05/b17359e1cefb4f909b5e40b1b90a496d987258916dbbf88e842c729f510e/urllib3-2.8.0.tar.gz", hash = "sha256:63bf2ead4c879426ebf22ef2a781eeb4aa3b4ae798a0435506f8687fd5bb9b63", size = 458972, upload-time = "2026-09-15T19:29:36.253Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/92/9d/c4e665119135114480843e7ab388fa94d8480650450e6f8e26b70d323a4c/urllib3-2.8.0-py3-none-any.whl", hash = "sha256:0cf3cae568d36aa9576b28dfb35f11328f1cb974ca7647d9475ebb86c75ac6e3", size = 135717, upload-time = "2026-09-15T19:29:34.577Z" }, +] + +[[package]] +name = "uvicorn" +version = "0.54.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "click" }, + { name = "h11" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/da/34/30e9280707135d2cfc589dfff3cb796bd07a3aeb1a3e415ba09dd89d7bb4/uvicorn-0.54.0.tar.gz", hash = "sha256:a2e33cbfaa0306f8e6b0c13e0cb89d7d7a2da3e62b90c66e18c33d9807b28620", size = 112283, upload-time = "2026-09-25T06:52:37.601Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/38/0c/b54a4fdd7f90a3af8b02ebc9ce6712c2c208b7926a2f7bad95c33ebbe943/uvicorn-0.54.0-py3-none-any.whl", hash = "sha256:505bdb0f318731d45f1f712071fc781a8981f6847a31c902c9f5e652d4f67faf", size = 87427, upload-time = "2026-09-25T06:52:35.829Z" }, +]