Post

One Canonical Encoding for the Local-Path OCI Config

One Canonical Encoding for the Local-Path OCI Config

The local-path-provisioner build had two copies of the same encoding rule: image_config returned a Python dict, and every caller independently applied the same sorted-key, compact-separator serialization before writing or comparing bytes. This commit moves that rule inside image_config so the function returns encoded bytes, and updates the writer, the manifest check, and the scan tests to consume it directly.

Moving serialization into image_config

In the build script, the config builder now assigns its result to a local and returns json.dumps output encoded to bytes, rather than handing back a dict for someone else to serialize. The image writer correspondingly switches from a text write of a freshly dumped dict to a single byte write of the returned value. The manifest check in the scan script loses its own dump-and-compare and asserts the raw registry config bytes against image_config output directly. The practical consequence is that there is now exactly one definition of the canonical form, and a change to key ordering or separators cannot land in the writer without also landing in the verifier.

What the scan-test fixtures now assert

The scan test previously built the expected config, wrapped its own encoder around it, and passed that to verify_config. It now calls image_config once to get raw bytes and feeds those bytes to verify_config unchanged, which means the test exercises the real encoding path instead of a local imitation of it. Where the test still needs to inspect individual fields it decodes the bytes with json.loads, and the deliberate negative case still re-encodes on purpose so the rejection path stays covered. The same commit also collapses a repeated layer-digest computation into a single local in the binary verification path and replaces a hand-rolled environment allowlist at the scan entry point with the shared tool environment helper. These are consistency edits rather than behavior changes, and I have not seen a pipeline run for this push, only the modified call sites.

Why writers and verifiers must not fork

A verifier that recomputes the expected artifact using its own copy of the serialization rule can only fail when the two copies disagree, and when they disagree for accidental reasons it reports the artifact as corrupt. Folding the rule into the producer removes that class of false signal and makes the check meaningful again. The next check is a full local-path build followed by the scan and scan-test entry points, confirming the byte-for-byte comparisons still pass against a real OCI layout rather than only within the fixtures. A platform team maintaining its own image build tooling can use the same move whenever an artifact has both a writer and an independent checker: make one function own the canonical bytes, and let every other consumer call it.

This post is licensed under CC BY 4.0 by the author.