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:
2026-11-17 17:52:48 +03:00
co-authored by Claude Opus 5.5
parent 5573973670
commit 13fdd187c6
57 changed files with 4184 additions and 175 deletions
+15 -5
View File
@@ -142,10 +142,15 @@ def assert_accepted(resp: httpx.Response) -> dict[str, Any]:
return attachment
def assert_error(resp: httpx.Response, status: int) -> dict[str, Any]:
def assert_error(
resp: httpx.Response,
status: int,
*,
instance_id: bool = True,
) -> dict[str, Any]:
"""Ошибка в формате контракта; `code` соответствует статусу."""
assert resp.status_code == status, describe(resp, f"expected {status}")
body = json_body(resp)
body = json_body(resp, instance_id=instance_id)
check_body(body, "Error")
error = body["error"]
assert error["code"] == ERROR_CODES[status], describe(
@@ -314,11 +319,16 @@ def assert_replicas(values: Iterable[str], expected: int) -> set[str]:
return seen
def json_body(resp: httpx.Response) -> Any:
"""JSON-тело в UTF-8, непустые `X-Request-Id` и `X-Instance-Id`."""
def json_body(resp: httpx.Response, *, instance_id: bool = True) -> Any:
"""JSON-тело в UTF-8, непустые `X-Request-Id` и `X-Instance-Id`.
`instance_id=False` — ответ мог построить сам LB (предел тела, change
auth-hardening): у его ответов `X-Instance-Id` нет, контракт допускает.
"""
request_id = resp.headers.get("X-Request-Id", "")
assert request_id.strip(), describe(resp, "no X-Request-Id")
assert_instance_id(resp)
if instance_id:
assert_instance_id(resp)
media_type, _, params = resp.headers.get("Content-Type", "").partition(
";",
)