feat: harden authentication (Argon2id by measurement, login limits, body limit)
Apply auth-hardening up to the bench_login label: Argon2id parameters from [auth] chosen by driver.py argon2-params (m=64 MiB, t=2, p=1), rehash on login, per-process KDF budget with 429, shared login failure limit in Valkey with a local fallback, X-Forwarded-For from HAProxy, 64 KiB body limit (400) in LB and middleware, bench login profile, tests, threat model and trust matrix rows. Hypotheses H1-H4 are committed here before the baseline label. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+27
-1
@@ -8,7 +8,10 @@ from fastapi import FastAPI
|
||||
from src.api import errors
|
||||
from src.api.dependencies import database_ready
|
||||
from src.api.health_listener import HealthListener
|
||||
from src.api.middlewares import RequestContextMiddleware
|
||||
from src.api.middlewares import (
|
||||
BodySizeLimitMiddleware,
|
||||
RequestContextMiddleware,
|
||||
)
|
||||
from src.api.routers import health_router, v1_router
|
||||
from src.config import settings
|
||||
from src.infra import early_stop, telemetry
|
||||
@@ -74,6 +77,7 @@ async def lifespan(_: FastAPI) -> AsyncIterator[None]:
|
||||
)
|
||||
await health_listener.start()
|
||||
tls = settings.api_tls
|
||||
auth = settings.auth
|
||||
logger.info(
|
||||
"Started API",
|
||||
host=settings.app.host,
|
||||
@@ -92,6 +96,21 @@ async def lifespan(_: FastAPI) -> AsyncIterator[None]:
|
||||
uploads_wait_timeout_seconds=settings.uploads.wait_timeout_seconds,
|
||||
uploads_body_timeout_seconds=settings.uploads.body_timeout_seconds,
|
||||
uploads_max_unfinished_jobs=settings.uploads.max_unfinished_jobs,
|
||||
# параметры Argon2id, бюджет хэшей и предел входа (change
|
||||
# auth-hardening): профиль login сверяет по ним вариант
|
||||
auth_argon2_time_cost=auth.argon2_time_cost,
|
||||
auth_argon2_memory_kib=auth.argon2_memory_kib,
|
||||
auth_argon2_parallelism=auth.argon2_parallelism,
|
||||
auth_kdf_concurrency=auth.kdf_concurrency,
|
||||
auth_kdf_max_waiting=auth.kdf_max_waiting,
|
||||
auth_kdf_wait_timeout_seconds=auth.kdf_wait_timeout_seconds,
|
||||
auth_login_window_seconds=auth.login_window_seconds,
|
||||
auth_login_max_failures_per_account=(
|
||||
auth.login_max_failures_per_account
|
||||
),
|
||||
auth_login_max_failures_per_address=(
|
||||
auth.login_max_failures_per_address
|
||||
),
|
||||
# режим TLS без путей к файлам
|
||||
tls_client_auth=tls.client_auth,
|
||||
tls_allowed_clients=len(tls.allowed_clients) if tls.client_auth else 0,
|
||||
@@ -120,6 +139,9 @@ def create_app() -> FastAPI:
|
||||
version=SERVICE_VERSION,
|
||||
lifespan=lifespan,
|
||||
)
|
||||
# последний добавленный — внешний: предел тела внутри контекста запроса,
|
||||
# у его 400 есть X-Request-Id, X-Instance-Id и итоговая запись
|
||||
app.add_middleware(BodySizeLimitMiddleware)
|
||||
app.add_middleware(RequestContextMiddleware)
|
||||
errors.register(app)
|
||||
app.include_router(health_router)
|
||||
@@ -164,4 +186,8 @@ def main() -> None:
|
||||
# логи uvicorn идут через наш JSON-форматтер (src/infra/logger.py)
|
||||
log_config=None,
|
||||
access_log=False,
|
||||
# адрес клиента — только зависимость get_client_address: прокси-
|
||||
# middleware uvicorn верил бы X-Forwarded-For от 127.0.0.1 (change
|
||||
# auth-hardening, design, решение 6)
|
||||
proxy_headers=False,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user