forked from mtusi2026/mtusi2026lab7
lab7: Argon2id из env (замер bench/argon2_bench.py), лимит неудачных входов в Valkey (429 + Retry-After), cap_drop ALL и no-new-privileges, X-Instance-Id = случайный alias
This commit is contained in:
+11
-1
@@ -13,6 +13,7 @@ from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import json
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
@@ -33,6 +34,13 @@ def run(*args: str, timeout: float = 60) -> str:
|
||||
return result.stdout
|
||||
|
||||
|
||||
def instance_alias(container_id: str) -> str | None:
|
||||
"""X-Instance-Id of the process running in the container (lab 7: random alias, not the hostname)."""
|
||||
result = subprocess.run(["docker", "exec", container_id, "cat", "/tmp/instance_id"], capture_output=True,
|
||||
text=True, timeout=30, env={**os.environ, "MSYS_NO_PATHCONV": "1"})
|
||||
return (result.stdout.strip() or None) if result.returncode == 0 else None
|
||||
|
||||
|
||||
def replicas(all_states: bool = True) -> list[dict]:
|
||||
"""API containers of this compose project (running and stopped)."""
|
||||
ids = run("docker", "compose", "ps", "-q", *(["-a"] if all_states else []), "api").split()
|
||||
@@ -46,6 +54,8 @@ def replicas(all_states: bool = True) -> list[dict]:
|
||||
"id": item["Id"][:12],
|
||||
"name": item["Name"].lstrip("/"),
|
||||
"hostname": item["Config"]["Hostname"],
|
||||
# Lab 7: X-Instance-Id is a random alias the process writes to /tmp/instance_id.
|
||||
"instance": instance_alias(item["Id"][:12]) if item["State"]["Status"] == "running" else None,
|
||||
"state": item["State"]["Status"],
|
||||
"health": (item["State"].get("Health") or {}).get("Status", "-"),
|
||||
"exit_code": item["State"]["ExitCode"],
|
||||
@@ -75,7 +85,7 @@ def lb_servers() -> list[dict]:
|
||||
container = by_ip.get(addr)
|
||||
servers.append({"slot": name, "addr": addr, "state": state,
|
||||
"container": container["name"] if container else None,
|
||||
"instance_id": container["hostname"] if container else None})
|
||||
"instance_id": container["instance"] if container else None})
|
||||
return servers
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user