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
+23
View File
@@ -21,6 +21,7 @@ from api_client import (
from contract import (
BASIC_CHALLENGE,
BEARER_CHALLENGE,
assert_error,
assert_ok,
assert_unauthorized,
)
@@ -117,6 +118,28 @@ def test_broken_basic(api: Api, alice: Actor) -> None:
assert_unauthorized(resp, BASIC_CHALLENGE)
@pytest.mark.spec("sessions", "Большое тело входа")
def test_login_large_body(api: Api, alice: Actor) -> None:
"""Предел размера тела (change auth-hardening, решение 8): верный Basic с
телом больше 64 KiB — 400 до проверки credentials; через LB отказывает
LB (без X-Instance-Id)."""
headers = {
"Authorization": basic_header(
f"{alice.username}:{alice.password}".encode(),
)["Authorization"],
"Content-Type": "application/json",
}
resp = api.request(
"POST",
SESSIONS,
headers=headers,
content=b" " * 65537,
)
error = assert_error(resp, 400, instance_id=False)
assert error["message"] == "Request body is too large"
assert "token" not in resp.text
@pytest.mark.spec("sessions", "Повторный выход")
def test_logout_twice(api: Api, alice: Actor) -> None:
assert api.logout(alice).status_code == 204