forked from mtusi2026/mtusi2026lab7
64 lines
2.7 KiB
Python
64 lines
2.7 KiB
Python
import json
|
|
import time
|
|
from pathlib import Path
|
|
from client import check, run
|
|
from pipeline_support import broker, compose, wait_for
|
|
|
|
|
|
def snapshot():
|
|
groups = [
|
|
dict(zip(row[::2], row[1::2]))
|
|
for row in json.loads(broker("XINFO", "GROUPS", "attachment-jobs"))
|
|
]
|
|
return {
|
|
"entries": json.loads(broker("XRANGE", "attachment-jobs", "-", "+")),
|
|
"groups": [
|
|
{key: value for key, value in group.items() if key != "consumers"} for group in groups
|
|
],
|
|
"consumer_counts": [group["consumers"] for group in groups],
|
|
}
|
|
|
|
|
|
def main():
|
|
compose("stop", "worker", "dispatcher")
|
|
try:
|
|
before = snapshot()
|
|
started = time.monotonic()
|
|
compose("restart", "broker")
|
|
wait_for(lambda: broker("PING") == "PONG")
|
|
after = snapshot()
|
|
check(before["entries"] == after["entries"], "AOF restart changed stream entries")
|
|
check(
|
|
before["groups"] == after["groups"],
|
|
"AOF restart changed delivery cursor or pending state",
|
|
)
|
|
unauthenticated = compose("exec", "-T", "broker", "redis-cli", "-p", "16379", "PING")
|
|
check("NOAUTH" in unauthenticated, "Unauthenticated broker access accepted")
|
|
default = json.loads(broker("ACL", "GETUSER", "default"))
|
|
permissions = dict(zip(default[::2], default[1::2]))
|
|
check("off" in permissions["flags"], "Default broker user enabled")
|
|
check(not permissions["passwords"], "Default broker credentials configured")
|
|
logs = compose("logs", "--since", "30s", "broker")
|
|
check("CRITICAL" not in logs, "AOF loading reported errors")
|
|
report = dict(
|
|
status="PASS",
|
|
stream_and_consumer_groups_identical=True,
|
|
stream_entries=len(after["entries"]),
|
|
consumer_counts_before=before["consumer_counts"],
|
|
consumer_counts_after=after["consumer_counts"],
|
|
consumer_metadata="Idle consumers without any delivered message may disappear on restart; cursor, pending count, entries-read and lag are compared exactly.",
|
|
no_authentication_returns="NOAUTH",
|
|
default_user_disabled_without_password=True,
|
|
aof_replay_errors=0,
|
|
restart_seconds=round(time.monotonic() - started, 3),
|
|
explanation="Redis 7.4 AOF MULTI replay uses default ACL. Disabled passwordless-without-nopass default has internal permissions, but cannot authenticate. Runtime roles remain restricted.",
|
|
)
|
|
Path("evidence/broker-recovery.json").write_text(json.dumps(report, indent=2) + "\n")
|
|
print(json.dumps(report, indent=2))
|
|
finally:
|
|
compose("start", "worker", "dispatcher")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
run(main)
|