Skip to content

fix(build): derive the GNU build-ID from binary content so every released binary is unique (#653) - #654

Merged
bpalermo merged 2 commits into
mainfrom
fix/653-content-build-id
Sep 1, 2026
Merged

bpalermo merged 2 commits into
mainfrom
fix/653-content-build-id

Conversation

@bpalermo

@bpalermo bpalermo commented Sep 1, 2026

Copy link
Copy Markdown
Owner

Fixes #653. Amends the mechanism #652 shipped.

The collision

#651/#652 fixed build-to-build build-ID constancy by stamping the note with the
release commit SHA. But a GNU build-ID identifies a linked object, not a source
revision, and one aether commit produces seven released ELFs — so all seven ended
up with one ID. Verified on the artifacts published from 4aabff2:

binary image GNU build-ID
agent (multi-call) agent@sha256:47fa37d8… 4aabff27ace47e82c0df2e637e99e253442dc5a8
mesh-dns mesh-dns@sha256:2e186f02… same
registrar registrar@sha256:b3fc0d97… same
controller controller@sha256:47a3383b… same
cni-install cni-install@sha256:bee97fb5… same
aether-cni (plugin) same image, /opt/cni/bin/ same
envoy (custom proxy) aether-proxy:4aabff27… same

Pyroscope keys symbol lookup solely by build-ID, so uploading debuginfo for
any one of these would make the symbolizer resolve all seven against it — six of
them wrong, silently, with plausible-looking frames. Symbol upload has been
blocked on this.

Why a content hash, not a per-target-namespaced stamp

The issue's option 2 (sha1(commit || target_label)) would also give
distinctness, but the content hash (option 1) wins on three counts:

  • Canonical. It is what ld --build-id=sha1 computes natively and what
    debuginfod conventions assume. Both toolchains in this repo can produce it: the
    proxy gets it straight from lld, the Go binaries from a 20-byte note rewrite
    that hashes the same thing.
  • Self-verifying. Given only a shipped ELF you can recompute its build-ID and
    confirm the note belongs to that binary. A namespaced stamp is an assertion you
    have to trust; a content hash is a proof. The CI guard exploits this directly.
  • Correct by construction. Distinctness is not a rule someone has to remember
    to apply to a new target — it falls out of hashing different bytes.

Release traceability does not need the ELF note and does not live there: it lives
in the --stamp x_defs version information baked into the binaries and in the
image tags. The note is the symbolizer's key and nothing else.

Mechanism

Go binaries — //tools/buildid. rules_go links with -buildid=redacted and
Go ≥1.24 derives .note.gnu.build-id from that constant, so the plain
go_binary still carries 498919aff001d8366249403a2544fba2d833084f. The
post-link note rewrite from #652 stays; only the value changes:

build_id = SHA-1( image bytes, with the 20-byte build-ID descriptor
                  field replaced by 20 zero bytes )

Zeroing the descriptor is what makes the value well defined — it is the one field
the hash is about to overwrite, so excluding it removes the circular dependency
and makes writing the ID idempotent. The descriptor is exactly a SHA-1 wide,
so it is patched in place and no other byte of the image moves. All of that is
documented in the tool's package comment and covered by unit tests
(TestContentBuildIDIsSHA1OfTheZeroedImage, …IsDeterministic,
…IsIdempotent, …IsPairwiseDistinct, …ReplacesOnlyTheDescriptor).

The stable-status dependency is dropped. A content hash needs no workspace
status, so ctx.info_file, the --stamp config_setting, stamp_select() and
the STABLE_GIT_COMMIT variable #652 added are all gone, and the rewrite is
unconditional. That is the cleaner end state, and strictly better than gating it:

  • dev and PR-CI builds now get correct, unique IDs instead of the rules_go
    constant, so what CI validates is what releases ship;
  • the action's cache key is just (input binary, tool). Under fix(build): stamp the GNU build-ID with the release commit SHA (#651) #652 every new
    commit invalidated all seven stamping actions; now nothing invalidates unless
    the binary itself changes.

--stamp still does what it always did for charts and x_defs; it simply no
longer has anything to do with build-IDs.

Proxy — proxy/. envoy_cc_binary(stamped = True) is dropped (that is
Envoy's commit-SHA ldscript, i.e. exactly the #653 shape) in favour of
--build-id=sha1, lld's own content hash of the linked output.

It is passed as build --linkopt=-Wl,--build-id=sha1 in proxy/.bazelrc, not
as linkopts on //:envoy: envoy_cc_binary does
if not linkopts: linkopts = _envoy_linkopts(), so passing any target linkopts
would silently replace Envoy's defaults (-pthread -lrt -ldl -Wl,-z,relro,-z,now --hash-style=gnu -pie -Wl,-E). A --linkopt composes instead of replacing —
which is how envoy.bazelrc itself passes -fuse-ld=lld. The hermetic toolchain
already supplies -Wl,--build-id=md5 earlier on the link line; lld honours the
last --build-id, so ours wins and widens the note from 16 to the conventional
20 bytes.

The four properties

  1. Pairwise distinct — the headline fix. Two ELFs that differ anywhere
    outside the descriptor hash differently. Asserted directly by
    //tools/buildid:release_build_ids over the six released Go ELFs, and by a
    unit test.
  2. Different commits → different IDs (does not regress agent binary GNU build-ID is constant across different builds — breaks profile symbolization by build-ID #651): whenever a
    commit changes a binary's bytes, its ID moves. Honestly: a commit that leaves a
    given binary byte-identical keeps that binary's ID — and that is correct and
    desirable, not a regression. The previously uploaded symbols are still exactly
    the right ones for those bytes, and re-uploading dedupes.
  3. Same inputs → same ID. The ID is a pure function of the input bytes: no
    timestamps, no status files, no per-invocation state. Reproducible and
    remote-cache friendly.
  4. Dev/unstamped builds keep working — better than before, since they now get
    real IDs rather than a byte-identical copy of the constant-ID binary.

CI guards

  • //tools/buildid:release_build_ids (inverted from fix(build): stamp the GNU build-ID with the release commit SHA (#651) #652, which asserted each
    ID equals the stamp — precisely the condition that guaranteed the collision).
    It now asserts, over the six released Go ELFs (agent, mesh-dns, cni-install, the
    aether-cni plugin, controller, registrar): every note present and 20 bytes;
    every note equal to the SHA-1 recomputed from that binary's own content
    (self-verification); and all notes pairwise distinct. It needs no --stamp, so
    it holds in every configuration, is part of bazel build //... (hence
    bazel-diff on PRs), and is re-stated by publish.yaml.
  • //integration:build_id_test (proxy) — was "equals the ldscript"; now
    asserts the shipped Envoy carries a .note.gnu.build-id, that its descriptor is
    exactly 20 bytes (the SHA-1 shape: the toolchain's md5 is 16, fast is 8), and
    that it is not all-zero. It deliberately does not recompute the digest: lld's
    --build-id=sha1 is a tree hash over its output buffer — an internal linker
    detail, not a published function of the file — so recomputing it in a shell test
    would pin an lld implementation detail. (I confirmed that empirically against
    the hermetic lld 18.1.8 before deciding.)
  • proxy-release.yml — the ldscript grep is replaced by an analysis-only
    bazel aquery 'mnemonic("CppLink", //:envoy)' assertion that the last
    --build-id on the link command line is --build-id=sha1. Composed with the
    test above, that pins the published binary's note to lld's content hash. No
    extra compile; the ~150 MB binary never leaves the executor.
  • make check-build-id for the same report locally.

Validation

Go side — fully validated locally. Six released ELFs, one build, readelf -n:

agent_image_buildid_binary              e33c395749ca00cf140a8d0f09a5a66755c8b9a8
mesh-dns_image_buildid_binary           c7ea4d0cf85deb4cf50322c98785b9d5ec531aa6
cni-install_image_buildid_binary        629c246b1109e4d3281e5a5ccf545597383f89cc
cni-install_image_buildid_extra_0       3c8197e6cbd646b923e6ffa0f9ba07a9d83f8c62   (aether-cni)
controller_image_buildid_binary         f9a4af2f1cc6b584ae1fadda98d6901ce33a6989
registrar_image_buildid_binary          3c10db027c918d27177267eea95a112851cde984

Six binaries, six distinct IDs (the plain go_binary alongside them still reads
498919af…). Self-verification recomputed independently of the tool (a
throwaway Python script re-deriving sha1(image with the descriptor zeroed) from
each shipped file): all six match their note.

  • Property 2: changing one live string in cni/internal/cmd/root.go moved
    cni-install from 629c246b… to e37d2e04…; reverting restored 629c246b…
    exactly (which is also property 3).
  • Property 3: --stamp and --nostamp builds both self-verify and are both
    pairwise distinct. Interesting and correct: under --stamp the four binaries
    that embed x_defs version data get different IDs (their bytes differ), while
    cni-install and aether-cni, which embed none, keep the identical ID. That is
    property 2's honest caveat, visible in miniature.
  • Idempotence on a real 25 MB binary: buildid set run twice more over an
    already-written ELF produced byte-identical files and the same ID all three
    times.
  • The guard's collision detection was exercised for real: buildid verify on two
    copies of the same binary fails with
    build-ID 629c246b… is shared by 2 binaries: ….

bazel test //... green (89 tests). --config=ci lint green. make gazelle and
make format clean.

Proxy side — validated structurally; no full Envoy compile (multi-hour;
deliberately not run):

  • bazel aquery 'mnemonic("CppLink", //:envoy)' shows '-Wl,--build-id=sha1' on
    the link command line, after the toolchain's '-Wl,--build-id=md5', with
    Envoy's own defaults intact (-Wl,-z,relro,-z,now, '-Wl,--hash-style=gnu',
    -pie) and the gnu_build_id.ldscript gone. This is what proves both that the
    flag reaches the link and that dropping stamped = True did not disturb the
    rest of the link.
  • lld semantics confirmed independently against the hermetic clang/lld 18.1.8 from
    this workspace: --build-id=sha1 yields a 20-byte note; a later --build-id=sha1
    overrides an earlier --build-id=md5 and produces the identical id; relinking
    identical input reproduces the id; a different program gets a different id.
  • check_build_id.sh was exercised against real lld output for every branch:
    sha1 (pass), md5 (fails, "16-byte descriptor"), fast (fails, "8-byte"),
    no --build-id (fails, "carries no .note.gnu.build-id"), an all-zero hexstring
    id (fails), a missing file, and a non-ELF.
  • The --build-id ordering assertion the release workflow runs was verified
    against the real aquery output.

Awaits the proxy CI leg: the end-to-end assertion on a compiled Envoy —
//integration:build_id_test plus the aquery check — which runs on the first
proxy PR/release build. It is gated, not assumed.

Operational note (Pyroscope)

After this lands, all seven binaries are individually uploadable — each one's
debuginfo resolves only its own samples.

  • No stale 4aabff2-era upload exists and none must ever be made. We
    deliberately withheld the 4aabff2 artifacts precisely because of this
    collision; the earlier poisoned 498919af… upload was already deleted. Uploading
    a 4aabff2-era binary now would install one symbol table for all seven ELFs.
  • The still-valid 15e3b073… proxy upload predates the stamp and is unaffected;
    the proxy's ID changes on its next publish, so it will need re-uploading then.
  • Per the standing procedure, re-upload a binary only when its image digest
    moves, keying off the chart's pinned digest rather than the tag. Because the ID
    is now content-derived, an unchanged binary keeps its ID and the upload dedupes.
  • The agent, mesh-dns, cni-install, aether-cni, controller and registrar are six
    separate ELFs with six separate IDs; upload each one whose native frames matter.

Not touched

No charts/ changes, so no chart version bump. The cluster was not touched.

🤖 Generated with Claude Code

https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

bpalermo and others added 2 commits August 31, 2026 21:53
…#653)

#652 stamped the note with the release commit SHA, which made every binary
produced by a commit share one build-ID — seven released ELFs, one ID. Pyroscope
keys symbol lookup solely by build-ID, so uploading debuginfo for one of them
would silently resolve all seven against it. Symbol upload has been blocked on
this.

A GNU build-ID identifies a linked object, not a source revision. The note now
holds the binary's own content hash:

  build_id = sha1(image bytes, with the 20-byte descriptor field zeroed)

Zeroing the descriptor before hashing is what makes the value well defined — it
is the field the hash is about to overwrite — and it makes writing the ID
idempotent, which is in turn what lets the guard recompute and check it. The
descriptor is exactly a sha1 wide, so it is patched in place.

The stable-status dependency is gone: a content hash needs no workspace status,
so ctx.info_file, the --stamp config_setting, stamp_select() and the
STABLE_GIT_COMMIT variable are all removed and the rewrite is unconditional. Dev
and PR-CI builds now get correct, unique IDs instead of the rules_go constant,
and the action's cache key is just (input binary, tool) — a new commit no longer
invalidates all seven rewrites. --stamp keeps doing what it does for charts and
x_defs; it just has nothing to do with build-IDs any more.

//tools/buildid:release_build_ids is inverted accordingly. It asserted that each
ID equals the stamp — precisely the condition that guaranteed the collision. It
now asserts, over the six released Go ELFs, that every note is present, equals
the sha1 recomputed from that binary's own bytes (self-verification), and is
shared with no other binary.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
envoy_cc_binary(stamped = True) links with --build-id=0x<BUILD_SCM_REVISION>,
i.e. the source commit — the same shape that made all seven released aether
binaries share one GNU build-ID (#653). Upstream gets away with it because they
ship one binary per commit.

Replace it with --build-id=sha1, lld's own content hash of the linked output:
unique by construction, reproducible for identical inputs, and impossible to
collide with the six Go binaries.

It goes on the command line via --linkopt in proxy/.bazelrc rather than as
`linkopts` on //:envoy, because envoy_cc_binary does
`if not linkopts: linkopts = _envoy_linkopts()` — passing target linkopts would
silently drop Envoy's own defaults (-pthread, -lrt, -ldl, -z relro/now,
--hash-style=gnu, -pie, -Wl,-E). envoy.bazelrc passes -fuse-ld=lld the same way.
The hermetic toolchain already supplies -Wl,--build-id=md5 earlier on the link
line; lld honours the last --build-id, so ours wins and widens the note from 16
to the conventional 20 bytes.

- //integration:build_id_test no longer compares against the ldscript (gone). It
  asserts the shipped Envoy has a .note.gnu.build-id, that the descriptor is
  exactly 20 bytes — the sha1 shape, which the toolchain's md5 (16) and `fast`
  (8) cannot produce — and that it is not all-zero. It deliberately does not
  recompute the digest: lld's sha1 build-ID is a tree hash over its output
  buffer, an internal linker detail rather than a published function of the file.
- proxy-release.yml replaces the ldscript grep with an analysis-only
  `bazel aquery 'mnemonic("CppLink", //:envoy)'` assertion that the LAST
  --build-id on the link command line is --build-id=sha1. Composed with the test
  above that pins the published binary's note to lld's content hash, at no extra
  compile cost.

Validated structurally (no full Envoy compile): aquery shows
'-Wl,--build-id=sha1' after the toolchain's md5, with Envoy's own link defaults
intact and gnu_build_id.ldscript gone. lld 18.1.8 semantics — 20-byte note, last
flag wins, reproducible, distinct per program — confirmed against the hermetic
toolchain, and check_build_id.sh was exercised against real sha1/md5/fast/no-id
/zero-id/non-ELF inputs.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

stamped build-ID is per-commit, so all 7 released binaries share one ID — symbol upload still unsafe (follow-up to #651)

1 participant