feat(node): add confirmed board shutdown with expiring commands
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
"""Node112 over the installed, qualified Node111; retain all other payloads."""
|
||||
|
||||
import argparse
|
||||
import hashlib
|
||||
import io
|
||||
import json
|
||||
import sys
|
||||
import tarfile
|
||||
from pathlib import Path
|
||||
|
||||
REPO = Path(__file__).resolve().parents[3]
|
||||
NODE = REPO / "apps/node-agent"
|
||||
VERSION = "0.8.53-112"
|
||||
BASE_SHA = "ff0327f13b4c25cc00ef81048c2341e993cfcf2dbf322adfa64ea4e6322a998b"
|
||||
sys.path.insert(0, str(REPO / "scripts/packaging"))
|
||||
from debian import package # noqa: E402
|
||||
|
||||
|
||||
def build(binary, output):
|
||||
if output.exists():
|
||||
raise FileExistsError("Published releases are immutable")
|
||||
raw = (NODE / "build/bms-111/mission-core-node_0.8.53-111_amd64.deb").read_bytes()
|
||||
if hashlib.sha256(raw).hexdigest() != BASE_SHA:
|
||||
raise ValueError("Qualified baseline changed")
|
||||
stream = io.BytesIO(raw)
|
||||
assert stream.read(8) == b"!<arch>\n"
|
||||
archives = {}
|
||||
while header := stream.read(60):
|
||||
size = int(header[48:58])
|
||||
name = header[:16].decode().strip().rstrip("/")
|
||||
archives[name] = stream.read(size)
|
||||
if size % 2:
|
||||
stream.read(1)
|
||||
|
||||
def members(name):
|
||||
with tarfile.open(fileobj=io.BytesIO(archives[name]), mode="r:gz") as archive:
|
||||
return [(m.name, archive.extractfile(m).read(), m.mode) for m in archive if m.isfile()]
|
||||
|
||||
controls, files = members("control.tar.gz"), members("data.tar.gz")
|
||||
old = {n: d for n, d, _ in files}
|
||||
compiled = binary.read_bytes()
|
||||
assert compiled[:6] == b"\x7fELF\x02\x01" and compiled[18:20] == b"\x3e\x00"
|
||||
source_files = {
|
||||
str(p.relative_to(REPO)): hashlib.sha256(p.read_bytes()).hexdigest()
|
||||
for directory in (NODE / "internal", NODE / "cmd", NODE / "packaging", NODE / "web/dist")
|
||||
for p in sorted(directory.rglob("*"))
|
||||
if p.is_file() and "__pycache__" not in p.parts
|
||||
}
|
||||
provenance = dict(
|
||||
schema="missioncore.node.packaging-revision/v1",
|
||||
version=VERSION,
|
||||
qualified_base_sha256=BASE_SHA,
|
||||
qualified_base_provenance=json.loads(
|
||||
old["usr/share/doc/mission-core-node/provenance.json"]
|
||||
),
|
||||
scope="Confirmed graceful power-off via paired mTLS heartbeat and scoped logind policy",
|
||||
binary_sha256=hashlib.sha256(compiled).hexdigest(),
|
||||
source_files=source_files,
|
||||
)
|
||||
changes = {
|
||||
"usr/lib/mission-core-node/node-agent": compiled,
|
||||
"usr/share/doc/mission-core-node/provenance.json": (
|
||||
json.dumps(provenance, indent=2) + "\n"
|
||||
).encode(),
|
||||
}
|
||||
rule = "usr/share/polkit-1/rules.d/50-mission-core-node-power.rules"
|
||||
assert rule not in old
|
||||
replaced = []
|
||||
for name, data, mode in controls:
|
||||
if name == "control":
|
||||
assert b"Version: 0.8.53-111\n" in data
|
||||
data = data.replace(b"Version: 0.8.53-111\n", f"Version: {VERSION}\n".encode())
|
||||
replaced.append((name, data, mode))
|
||||
payload = [(n, changes.get(n, d), m) for n, d, m in files]
|
||||
payload.append(
|
||||
(rule, (NODE / "packaging/50-mission-core-node-power.rules").read_bytes(), 0o644)
|
||||
)
|
||||
output.parent.mkdir(parents=True, exist_ok=True)
|
||||
output.write_bytes(package(replaced, payload))
|
||||
report = dict(
|
||||
version=VERSION,
|
||||
base_sha256=BASE_SHA,
|
||||
sha256=hashlib.sha256(output.read_bytes()).hexdigest(),
|
||||
bytes=output.stat().st_size,
|
||||
changed_controls=["control"],
|
||||
changed_payloads=list(changes),
|
||||
added_payloads=[rule],
|
||||
retained_payload_count=len(files) - len(changes),
|
||||
)
|
||||
output.with_suffix(".json").write_text(json.dumps(report, indent=2) + "\n")
|
||||
print(json.dumps(report))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--binary", type=Path, required=True)
|
||||
parser.add_argument("--output", type=Path, required=True)
|
||||
args = parser.parse_args()
|
||||
build(args.binary, args.output)
|
||||
Reference in New Issue
Block a user