Provable software releases #

What is new: a release is attested as a reproducible build: the source it came from, every locked dependency by the hash of its file, and two independent builds that came out byte-identical. When a dependency is found bad, one revocation tells you exactly which releases contain it, and their attestations stop verifying as valid, while releases without it stay valid.

Why it matters: software supply-chain incidents start with "which of our releases ship this package?". A lock file answers it for one project at one moment; here the answer is a recorded, signed, re-checkable fact across every release you attested, and the revocation is a signed record of who decided it and why.

Build a release twice, byte for byte #

import gzip, hashlib, io, json, tarfile
from tensorchain import issuers, provenance
from tensorchain.checkers import software_build_v1 as sb
from tensorchain.workspace import Workspace

source = {"src/app.py": b"print('hello')\n", "src/util.py": b"def add(a, b):\n    return a + b\n"}

def build(files):
    """A deterministic release: sorted entries, fixed mtimes and owners, gzip without a timestamp."""
    raw = io.BytesIO()
    with tarfile.open(fileobj=raw, mode="w", format=tarfile.PAX_FORMAT) as t:
        for name in sorted(files):
            info = tarfile.TarInfo(name)
            info.size, info.mtime, info.uid, info.gid, info.mode = len(files[name]), 0, 0, 0, 0o644
            t.addfile(info, io.BytesIO(files[name]))
    out = io.BytesIO()
    with gzip.GzipFile(fileobj=out, mode="wb", mtime=0) as g:
        g.write(raw.getvalue())
    return out.getvalue()

b1, b2 = build(source), build(source)
release = hashlib.sha256(b1).hexdigest()
print("build 1", release[:16], "| build 2", hashlib.sha256(b2).hexdigest()[:16], "| identical:", b1 == b2)
assert b1 == b2
Output (captured at build)
build 1 e1437594d9b8a615 | build 2 e1437594d9b8a615 | identical: True

Attest it, with its locked dependencies #

h = lambda t: hashlib.sha256(t.encode()).hexdigest()
lock = ("fastapi==0.128.0 \\\n    --hash=sha256:%s\nhttpx==0.28.1 \\\n    --hash=sha256:%s\n"
        % (h("fastapi wheel"), h("httpx wheel"))).encode()
files = sorted(source)
ev = {"source": json.dumps({"commit": "a" * 40, "tree": "b" * 40, "files": files,
                            "files_sha256": hashlib.sha256("\n".join(files).encode()).hexdigest()}).encode(),
      "lock": lock, "builds": json.dumps({"builds": [release, hashlib.sha256(b2).hexdigest()]}).encode()}
reg = issuers.Registry("issuers")
reg.create("release:acme")
reg.create("security:acme")
ws = Workspace("releases.sqlite", actor="agent:docs")
a1 = provenance.attest(ws, reg, "release:acme", {"release": release}, "software.build.v1", ev)
c = provenance.verify_attestation(ws, reg, a1)["claims"]
print("release 1:", provenance.verify_attestation(ws, reg, a1)["status"], "|", c["packages"], "packages,",
      c["dependency_hashes"], "file hashes | rebuild identical:", c["rebuild_identical"])
assert c["rebuild_identical"] and c["packages"] == 2

# A second release that no longer ships httpx
lock2 = lock.split(b"httpx")[0]
b3 = build(dict(source, **{"src/app.py": b"print('hello, v2')\n"}))
r2 = hashlib.sha256(b3).hexdigest()
a2 = provenance.attest(ws, reg, "release:acme", {"release": r2}, "software.build.v1",
                       dict(ev, lock=lock2, builds=json.dumps({"builds": [r2, hashlib.sha256(build(dict(source, **{"src/app.py": b"print('hello, v2')\n"}))).hexdigest()]}).encode()))
try:                                                   # an attestation about something its builds did not produce
    provenance.attest(ws, reg, "release:acme", {"release": h("something else")}, "software.build.v1", ev)
except provenance.ProvenanceError as e:
    print("a mismatched subject is refused:", e.code)
    assert e.code == "subject_mismatch"
Output (captured at build)
release 1: valid | 2 packages, 2 file hashes | rebuild identical: True
a mismatched subject is refused: subject_mismatch

A dependency is found bad #

bad = h("httpx wheel")
provenance.register_asset(ws, reg, "security:acme", bad, "dependency/httpx==0.28.1")
provenance.revoke(ws, reg, "security:acme", bad, "asset", "advisory: a stand-in for a real CVE")
edges = sb.dependency_edges(lock, release) + sb.dependency_edges(lock2, r2)
imp = provenance.impact(ws, reg, bad, edges)
s1 = provenance.verify_attestation(ws, reg, a1, affected=imp["affected"])["status"]
s2 = provenance.verify_attestation(ws, reg, a2, affected=imp["affected"])["status"]
print("releases containing it:", len(imp["attestations"]), "(release 1:", imp["attestations"] == [a1], ") | release 1:", s1,
      "| release 2:", s2)
assert imp["attestations"] == [a1] and s1 == "revoked" and s2 == "valid"
assert ws.verify()["ok"]
Output (captured at build)
releases containing it: 1 (release 1: True ) | release 1: revoked | release 2: valid

A real run of this, on TensorChain's own cloud deployment bundle (the service source plus the server's 673-hash lock, built twice with git archive and gzip -n), is in docs/PROVENANCE-V1.md, T7. The attestation also exports as a standard in-toto Statement in a DSSE envelope (tensorchain.interop.export_intoto), which a 30-line jq + openssl script verifies without any TensorChain code.