forked from mtusi2026/mtusi2026lab7
fix(telemetry): use the operator identity for protected readiness probes
This commit is contained in:
File diff suppressed because one or more lines are too long
+3
-2
@@ -16,7 +16,8 @@ ENDPOINTS = {
|
|||||||
|
|
||||||
|
|
||||||
def fetch(service, path, *, params=None, json_result=True):
|
def fetch(service, path, *, params=None, json_result=True):
|
||||||
if service == "otel":
|
operator_probe = service == "otel" or path in {"/-/ready", "/ready"}
|
||||||
|
if operator_probe:
|
||||||
from scripts.bootstrap_security import OPERATOR, SECRET, write_private
|
from scripts.bootstrap_security import OPERATOR, SECRET, write_private
|
||||||
|
|
||||||
# Operator credentials can change during CA rollover; never keep a
|
# Operator credentials can change during CA rollover; never keep a
|
||||||
@@ -32,7 +33,7 @@ def fetch(service, path, *, params=None, json_result=True):
|
|||||||
url += "?" + urlencode(params, doseq=True)
|
url += "?" + urlencode(params, doseq=True)
|
||||||
code = (
|
code = (
|
||||||
f"import urllib.request; from src.security_probe import context; service={service!r}; "
|
f"import urllib.request; from src.security_probe import context; service={service!r}; "
|
||||||
f"r=urllib.request.urlopen(urllib.request.Request({url!r},headers={{'Accept':'application/json'}}),timeout=8,context=context('operator' if 'otel' == service else 'grafana')); "
|
f"r=urllib.request.urlopen(urllib.request.Request({url!r},headers={{'Accept':'application/json'}}),timeout=8,context=context({'operator' if operator_probe else 'grafana'!r})); "
|
||||||
"print(r.read().decode())"
|
"print(r.read().decode())"
|
||||||
)
|
)
|
||||||
text = compose(
|
text = compose(
|
||||||
|
|||||||
+55
-6
@@ -2,9 +2,11 @@ import argparse
|
|||||||
import atexit
|
import atexit
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
import shutil
|
||||||
import socket
|
import socket
|
||||||
import subprocess
|
import subprocess
|
||||||
import tempfile
|
import tempfile
|
||||||
|
from contextlib import contextmanager
|
||||||
from datetime import UTC, datetime
|
from datetime import UTC, datetime
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
@@ -13,6 +15,21 @@ ROOT = Path(__file__).resolve().parents[1]
|
|||||||
PROGRESS = {}
|
PROGRESS = {}
|
||||||
|
|
||||||
|
|
||||||
|
@contextmanager
|
||||||
|
def workspace(keep_failed):
|
||||||
|
temporary = tempfile.mkdtemp(prefix="mtusi-lab7-clean-")
|
||||||
|
try:
|
||||||
|
yield temporary
|
||||||
|
finally:
|
||||||
|
if keep_failed and not PROGRESS["receipt"].get("checks_completed"):
|
||||||
|
print(
|
||||||
|
"Retained failed diagnostic workspace: " + temporary,
|
||||||
|
flush=True,
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
shutil.rmtree(temporary)
|
||||||
|
|
||||||
|
|
||||||
def save_incomplete():
|
def save_incomplete():
|
||||||
receipt = PROGRESS.get("receipt")
|
receipt = PROGRESS.get("receipt")
|
||||||
if receipt and receipt.get("result") != "PASS":
|
if receipt and receipt.get("result") != "PASS":
|
||||||
@@ -93,6 +110,7 @@ def free_port():
|
|||||||
def main():
|
def main():
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument("--output", default="evidence/clean-clone.json")
|
parser.add_argument("--output", default="evidence/clean-clone.json")
|
||||||
|
parser.add_argument("--keep-failed", action="store_true")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
output = ROOT / args.output
|
output = ROOT / args.output
|
||||||
if output.exists():
|
if output.exists():
|
||||||
@@ -138,7 +156,7 @@ def main():
|
|||||||
"fixed_host_port_for_restart": int(public_port),
|
"fixed_host_port_for_restart": int(public_port),
|
||||||
}
|
}
|
||||||
PROGRESS.update(receipt=receipt, output=output)
|
PROGRESS.update(receipt=receipt, output=output)
|
||||||
with tempfile.TemporaryDirectory(prefix="mtusi-lab7-clean-") as temporary:
|
with workspace(args.keep_failed) as temporary:
|
||||||
clone = Path(temporary) / "lab7"
|
clone = Path(temporary) / "lab7"
|
||||||
run(
|
run(
|
||||||
[
|
[
|
||||||
@@ -422,11 +440,42 @@ def main():
|
|||||||
raise
|
raise
|
||||||
finally:
|
finally:
|
||||||
assert project.startswith("mtusi-lab7-clean-")
|
assert project.startswith("mtusi-lab7-clean-")
|
||||||
run(
|
if args.keep_failed and not receipt.get("checks_completed"):
|
||||||
["docker", "compose", "down", "--volumes", "--remove-orphans"],
|
diagnostic_env = {
|
||||||
cwd=clone,
|
key: value
|
||||||
env=env,
|
for key, value in env.items()
|
||||||
)
|
if key
|
||||||
|
in {
|
||||||
|
"COMPOSE_PROJECT_NAME",
|
||||||
|
"API_IMAGE",
|
||||||
|
"PUBLIC_PORT",
|
||||||
|
"GRAFANA_PORT",
|
||||||
|
"BASE_URL",
|
||||||
|
"BAO_PORT",
|
||||||
|
"S3_ADMIN_PORT",
|
||||||
|
"VCS_REF",
|
||||||
|
"COMPOSE_FILE",
|
||||||
|
"NO_PROXY",
|
||||||
|
"no_proxy",
|
||||||
|
"CA_FILE",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
(clone / ".work-debug-environment.json").write_text(
|
||||||
|
json.dumps(diagnostic_env)
|
||||||
|
)
|
||||||
|
print("Diagnostic containers retained: " + project, flush=True)
|
||||||
|
else:
|
||||||
|
run(
|
||||||
|
[
|
||||||
|
"docker",
|
||||||
|
"compose",
|
||||||
|
"down",
|
||||||
|
"--volumes",
|
||||||
|
"--remove-orphans",
|
||||||
|
],
|
||||||
|
cwd=clone,
|
||||||
|
env=env,
|
||||||
|
)
|
||||||
receipt["result"] = "PASS"
|
receipt["result"] = "PASS"
|
||||||
output.parent.mkdir(parents=True, exist_ok=True)
|
output.parent.mkdir(parents=True, exist_ok=True)
|
||||||
output.write_text(json.dumps(receipt, ensure_ascii=False, indent=2) + "\n")
|
output.write_text(json.dumps(receipt, ensure_ascii=False, indent=2) + "\n")
|
||||||
|
|||||||
Reference in New Issue
Block a user