forked from mtusi2026/mtusi2026lab7
fix(pki): isolate concurrent atomic operator file writes
This commit is contained in:
@@ -64,18 +64,17 @@ ROLES = {
|
||||
def write_private(path, content, *, mode=0o600):
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
raw = content.encode() if isinstance(content, str) else content
|
||||
temporary = path.with_name(path.name + ".new")
|
||||
fd = os.open(temporary, os.O_WRONLY | os.O_CREAT | os.O_TRUNC, mode)
|
||||
temporary = path.with_name(path.name + "." + secrets.token_hex(8) + ".new")
|
||||
fd = os.open(temporary, os.O_WRONLY | os.O_CREAT | os.O_EXCL, mode)
|
||||
try:
|
||||
os.fchmod(fd, mode)
|
||||
with os.fdopen(fd, "wb") as stream:
|
||||
stream.write(raw)
|
||||
stream.flush()
|
||||
os.fsync(stream.fileno())
|
||||
except BaseException:
|
||||
temporary.replace(path)
|
||||
finally:
|
||||
temporary.unlink(missing_ok=True)
|
||||
raise
|
||||
temporary.replace(path)
|
||||
|
||||
|
||||
def key_bytes(key):
|
||||
|
||||
@@ -215,6 +215,9 @@ def main():
|
||||
cwd=clone,
|
||||
env=env,
|
||||
)
|
||||
receipt["login_budget_measurement"] = json.loads(
|
||||
(clone / "evidence/clean-login-budget.json").read_text()
|
||||
)
|
||||
for module, extra in [
|
||||
("verify_security", []),
|
||||
("verify_telemetry", []),
|
||||
@@ -470,6 +473,8 @@ def main():
|
||||
[
|
||||
"docker",
|
||||
"compose",
|
||||
"--profile",
|
||||
"*",
|
||||
"down",
|
||||
"--volumes",
|
||||
"--remove-orphans",
|
||||
|
||||
@@ -407,11 +407,15 @@ def main():
|
||||
marker,
|
||||
pending=phase == "after_commit",
|
||||
)
|
||||
wait(
|
||||
lambda j=j: inside(
|
||||
|
||||
def observer_ready(j=j, observer=observer):
|
||||
if observer.done():
|
||||
observer.result()
|
||||
return inside(
|
||||
f"with db.connection() as c: n=c.execute(\"SELECT count(*) n FROM pipeline_events WHERE job_id=%s AND event='crash_observer_ready'\",({j!r},)).fetchone()['n']\nprint(json.dumps(n>0))"
|
||||
)
|
||||
)
|
||||
|
||||
wait(observer_ready)
|
||||
start("worker")
|
||||
at_crash = observer.result(timeout=60)
|
||||
report["active_case"] = {
|
||||
|
||||
Reference in New Issue
Block a user