Retain redacted runtime drift evidence before Device Core rollback

This commit is contained in:
Codex
2026-09-29 22:14:48 +03:00
parent f7416bc59a
commit d1c5401f52
6 changed files with 335 additions and 12 deletions
+64 -2
View File
@@ -32870,6 +32870,66 @@ def device_release_runtime_snapshot_v2():
return result
def device_release_field_digests(fields):
"""Diagnostic hashes only. Never retain environment/inspect values here."""
result = {}
for section in ("HostConfig", "Config"):
values = fields.get(section)
if not isinstance(values, dict) or len(values) > 256:
die("Device Core runtime diagnostic section is invalid")
for key, value in values.items():
if not isinstance(key, str) or not re.fullmatch(r"[A-Za-z][A-Za-z0-9_]{0,100}", key):
die("Device Core runtime diagnostic field name is invalid")
result[section + "." + key] = device_release_drift_digest(value)
for key in ("Mounts", "networks"):
result[key] = device_release_drift_digest(fields.get(key))
return result
def device_release_capture_field_digests(expected_runtime):
"""Bind diagnostics to the already checked container generation and digest."""
observations = device_release_drift_sample()
if set(observations) != set(expected_runtime):
die("Device Core runtime diagnostic inventory changed")
result = {}
for service, sample in observations.items():
expected = expected_runtime[service]
fields = device_release_mounts_v2(sample["fields"])
if (sample["runtime"]["containerId"] != expected["containerId"]
or sample["runtime"]["imageId"] != expected["imageId"]
or device_release_drift_digest(fields) != expected["runtimeConfigSha256"]):
die("Device Core runtime changed while capturing diagnostic evidence: " + service)
result[service] = device_release_field_digests(fields)
return result
def device_release_runtime_drift_message(before, current, service):
message = "Device Core release runtime configuration drift: " + service
expected = before.get("runtimeFieldDigests", {}).get(service)
if expected is None:
return message # Legacy snapshots retain their exact acceptance semantics.
report = {"schema": "nodedc.device-core.runtime-drift-fields.v1",
"service": service,
"expectedSha256": before["runtime"][service]["runtimeConfigSha256"],
"actualSha256": current[service]["runtimeConfigSha256"]}
try:
if not isinstance(expected, dict) or any(
not isinstance(key, str) or not re.fullmatch(r"(?:HostConfig|Config)\.[A-Za-z][A-Za-z0-9_]{0,100}|Mounts|networks", key)
or not isinstance(value, str) or not re.fullmatch(r"[a-f0-9]{64}", value)
for key, value in expected.items()):
die("Device Core saved runtime field digests are invalid")
actual = device_release_capture_field_digests(current)[service]
changed = sorted(key for key in set(expected) | set(actual) if expected.get(key) != actual.get(key))
report["changedFields"] = [{"path": key, "expectedSha256": expected.get(key),
"actualSha256": actual.get(key)} for key in changed[:64]]
report["truncated"] = len(changed) > 64
report["evidence"] = "captured" if changed else "inconsistent"
except Exception:
# Do not copy raw external exception text into a public failed receipt.
report["evidence"] = "unavailable"
return message + "; field_evidence=" + json.dumps(report, sort_keys=True, separators=(",", ":"))
def device_release_mount_order_proof(fields, expected):
# Unlike the diagnostic probe, this CANNOT change Binds or NetworkMode.
# The legacy backup contains only a digest, so prove an exact old preimage.
@@ -32931,9 +32991,11 @@ def preflight_device_release(payload, entries, patch_id):
validate_device_manager_control_plane_runtime(require_edge_channel=True, core_network_mode="private-egress", require_persistent_data=True, read_only=True)
run_healthchecks("device-core-release", entries, DEVICE_RELEASE_SERVICES)
before = device_release_runtime_snapshot_v2()
field_digests = device_release_capture_field_digests(before)
compose = {str(p): sha256_file(p) for p in component_compose_files("device-plane")}
return {"runtimeFingerprintVersion": 2, "descriptor": d, "predecessor": predecessor["releaseId"] if predecessor else "manager-v13/core-v4/edge-v4",
"runtime": before, "compose": compose, "otherComposeServices": device_release_other_compose_services(),
"runtime": before, "runtimeFieldDigests": field_digests,
"compose": compose, "otherComposeServices": device_release_other_compose_services(),
"installedFiles": collect_exact_files(DEVICE_PLANE_ROOT, DEVICE_RELEASE_ENTRIES if predecessor else DEVICE_RELEASE_ENTRIES[:-1], "Device Core rollback baseline")}
@@ -32949,7 +33011,7 @@ def accept_device_release(before, *, rollback=False):
die("Device Core release changed a preserved service: " + service)
continue
if new["runtimeConfigSha256"] != old["runtimeConfigSha256"]:
die("Device Core release runtime configuration drift: " + service)
die(device_release_runtime_drift_message(before, current, service))
if rollback:
expected_image = old["imageId"]
else: