forked from mtusi2026/mtusi2026lab7
feat: confine a compromised worker and drill its compromise end to end
- narrow the worker S3 user to staging reads and attachments writes - add database rules the worker role cannot bypass: no return to pending, variant keys of its own attachment, known error codes only - let the cleaner remove a ready source only after its own SHA-256 check - add make jobs_audit [REPAIR=1] to name and requeue damaged jobs - add make worker_compromise: isolated before/after stands, one operation table, response windows, job safety, controls and committed hypotheses Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -15,6 +15,8 @@
|
||||
|
||||
import copy
|
||||
import importlib.util
|
||||
import io
|
||||
import json
|
||||
import os
|
||||
import signal
|
||||
import subprocess
|
||||
@@ -175,6 +177,56 @@ def test_secret_table_matches_seed() -> None:
|
||||
assert f"\n{variable}=" in template, variable
|
||||
|
||||
|
||||
def test_s3_value_checked_under_staging(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
capsys: pytest.CaptureFixture[str],
|
||||
) -> None:
|
||||
"""Ключ проверки S3 — под `staging` своей базы: пользователь worker читает
|
||||
только там (change track1-worker-compromise, решение 5), и принятый ключ
|
||||
вне его отвечал бы `AccessDenied` вместо «ok»."""
|
||||
keys: list[str] = []
|
||||
|
||||
class Missing(Exception):
|
||||
def __init__(self, code: str) -> None:
|
||||
super().__init__(code)
|
||||
self.response = {"Error": {"Code": code}}
|
||||
|
||||
class Client:
|
||||
def get_object(self, *, Bucket: str, Key: str) -> None: # noqa: N803
|
||||
keys.append(Key)
|
||||
raise Missing(
|
||||
"NoSuchKey"
|
||||
if Key.startswith("messenger/staging/")
|
||||
else "AccessDenied",
|
||||
)
|
||||
|
||||
class Session:
|
||||
def create_client(self, *_args: object, **_kwargs: object) -> Client:
|
||||
return Client()
|
||||
|
||||
stub = ModuleType("botocore.session")
|
||||
stub.get_session = Session # type: ignore[attr-defined]
|
||||
monkeypatch.setitem(sys.modules, "botocore.session", stub)
|
||||
monkeypatch.setattr("botocore.session", stub, raising=False)
|
||||
value = {"access_key_id": "a", "secret_access_key": "b"}
|
||||
monkeypatch.setattr(
|
||||
sys,
|
||||
"stdin",
|
||||
io.StringIO(json.dumps({"old": value, "new": value})),
|
||||
)
|
||||
for name, text in (
|
||||
("DATABASE__NAME", "messenger"),
|
||||
("S3__HOST", "s3"),
|
||||
("S3__PORT", "8333"),
|
||||
("S3__BUCKET", "messenger"),
|
||||
("CLIENT_TLS__CA_FILE", "/run/secrets/ca.crt"),
|
||||
):
|
||||
monkeypatch.setenv(name, text)
|
||||
exec(rotation.CHECK_PY["s3"], {}) # noqa: S102
|
||||
assert keys == ["messenger/staging/rotation-check"] * 2
|
||||
assert json.loads(capsys.readouterr().out) == {"old": "ok", "new": "ok"}
|
||||
|
||||
|
||||
def test_secret_readers() -> None:
|
||||
bao = rotation.load_bao()
|
||||
assert rotation.readers_of(bao, "postgres/api") == ["api"]
|
||||
|
||||
Reference in New Issue
Block a user