lab7: тесты безопасности и перевод своих тестов на HTTPS, документы (trust-matrix, THREAT_MODEL, OPERATOR, DEFENSE, WINDOWS, PR), сборщик доказательств, чистка legacy bench
This commit is contained in:
@@ -1,13 +1,14 @@
|
||||
"""Database-level guarantees, checked over HTTP and verified directly in PostgreSQL / Valkey."""
|
||||
from __future__ import annotations
|
||||
|
||||
import subprocess
|
||||
import threading
|
||||
import time
|
||||
import uuid
|
||||
|
||||
import pytest
|
||||
|
||||
from conftest import PASSWORD, Api, compose, psql
|
||||
from conftest import PASSWORD, ROOT, Api, compose, psql
|
||||
|
||||
pytestmark = pytest.mark.stack
|
||||
|
||||
@@ -81,7 +82,8 @@ def test_migrations_rerun_is_a_noop():
|
||||
assert "0004_attachments: already applied, skipped" in result.stdout
|
||||
assert "0005_pipeline: already applied, skipped" in result.stdout
|
||||
assert "0006_observability: already applied, skipped" in result.stdout
|
||||
assert psql("SELECT count(*) FROM schema_migrations") == "6"
|
||||
assert "0007_least_privilege: already applied, skipped" in result.stdout
|
||||
assert psql("SELECT count(*) FROM schema_migrations") == "7"
|
||||
assert psql("SELECT count(*) FROM users") == users_before
|
||||
|
||||
|
||||
@@ -112,8 +114,14 @@ def test_secrets_are_not_stored_in_plain_text(api):
|
||||
actor = api.user("store")
|
||||
stored = psql(f"SELECT password_hash FROM users WHERE id = '{actor['id']}'")
|
||||
assert stored.startswith("$argon2id$v=19$m=19456,t=2,p=1$") and PASSWORD not in stored
|
||||
token_hex = actor["token"].encode().hex()
|
||||
keys = compose("exec", "-T", "valkey", "sh", "-c",
|
||||
'REDISCLI_AUTH="$(cat /run/secrets/valkey_password)" valkey-cli --scan --pattern "session:*"').stdout.split()
|
||||
assert keys and all(len(k) == len("session:") + 64 for k in keys)
|
||||
assert not any(actor["token"] in k or token_hex in k for k in keys)
|
||||
# Lab 7: Valkey has no all-powerful user any more (default off; `api` may not SCAN/KEYS), so the
|
||||
# check asks with the API's own ACL user: the session exists ONLY under SHA-256(token).
|
||||
import hashlib
|
||||
hashed = "session:" + hashlib.sha256(actor["token"].encode()).hexdigest()
|
||||
script = ('read -r REDISCLI_AUTH; export REDISCLI_AUTH; read -r k1; read -r k2; '
|
||||
'c="valkey-cli --tls --cacert /run/secrets/internal-ca.crt -h localhost --user api --no-auth-warning"; '
|
||||
'$c exists "$k1"; $c exists "$k2"')
|
||||
pw = (ROOT / "secrets" / "valkey_api_password").read_text(encoding="utf-8").strip()
|
||||
out = subprocess.run(["docker", "compose", "exec", "-T", "valkey", "sh", "-c", script], cwd=ROOT, capture_output=True,
|
||||
input=f"{pw}\n{hashed}\nsession:{actor['token']}\n".encode()).stdout.decode().split()
|
||||
assert out == ["1", "0"], out # hashed key present, raw-token key absent
|
||||
|
||||
Reference in New Issue
Block a user