Skip to content

proto(images): a runtime base built with apko from Wolfi, checked in CI (#397) - #404

Closed
ndreno wants to merge 10 commits into
mainfrom
proto/static-images
Closed

ndreno wants to merge 10 commits into
mainfrom
proto/static-images

Conversation

@ndreno

@ndreno ndreno commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Prototype for #397: our own runtime base, built with apko from Wolfi packages, under both images. Draft: it exists to produce the numbers the decision needs, not to merge as is.

Two earlier versions are recorded in the comments: static musl binaries on scratch ran about 4x slower (results, #409), and Debian's glibc on scratch ran up to 10% slower on proxied routes with 31 to 33 CVEs in a default scan (results). Results for this version: comment.

What changes

  • docker/runtime.apko.yaml: the base. wolfi-baselayout, ca-certificates-bundle, glibc-2.44, ld-linux-2.44 and libgcc from packages.wolfi.dev, the nonroot user (65532) and its home. No shell, no package manager.
  • Dockerfile, Dockerfile.control: built on rust:1.95-slim-bookworm (the builder the release uses today) with cargo auditable, which embeds the crate list scanners read; the final stage is FROM ${BASE} plus the binary. Without BASE, Chainguard's glibc-dynamic, so CI's own image job builds them as they are.
  • barbacane-control moves from Debian slim to the same base, runs as 65532 and has no HEALTHCHECK (no shell).
  • barbacane-standalone is unchanged: it keeps a shell (Align the container images on Wolfi #397).

What CI checks (static-images.yml)

Job What it shows
Image (barbacane, barbacane-control) apko v1.4.15 locks the packages and builds the base from the lock; the image runs the binary (--version) and holds no shell or package manager; home (65532), /tmp (1777), CA bundle, nsswitch.conf, os-release and the apk database are there; Syft sees Wolfi, the five packages and the Rust crates; Grype's release scan passes, and a second scan lists every match
Integration Tests, image binary (4 shards) CI's integration suite with BARBACANE_TEST_BINARY set to the image's gateway
Security Suite, image binaries the security suite, the control CLI and connected mode, with both binaries and PostgreSQL
Load comparison today's gateway image (main's Dockerfile) against the apko one, both with the gateway from this commit and both run as containers; 3 alternating rounds of 20 s under wrk on a mock route and a proxied route, with the cors and correlation-id middlewares. Before each round, a route to localhost and one to https://example.com must answer 200. Also every Grype match in today's image

Not in the prototype

Publishing the base (multi-arch, under ghcr.io/barbacane-dev) and pinning it by digest in the Dockerfiles; the committed lock and a scheduled job that refreshes it; the release workflow; the nightly scans; a health-check subcommand for barbacane-control; BARBACANE_TRUSTED_PUBKEY_FILE; docs and CHANGELOG. They come with the real change.

Refs #397.

A prototype for #397's alternative: the data plane and the control plane
as static musl binaries on `scratch`, with no distro and no vendor base.

- Dockerfile, Dockerfile.control: built on rust:1.95-alpine3.23 (pinned)
  with `cargo auditable`, refused if the binary links a shared library.
  The runtime image holds the binary, the CA bundle from the builder,
  /etc/passwd and /etc/group with nonroot (65532), its home and /tmp.
  barbacane-control runs as 65532 (it ran as a system user) and loses its
  bash HEALTHCHECK.
- Musl builds use mimalloc as the global allocator.
- static-images.yml: checks each image's contents, Syft's inventory and
  Grype's scan; runs the integration suite and the security suite against
  the static binaries; compares the static gateway with the glibc one,
  built from this commit by the current builder, under wrk.
init_template, artifact_capabilities and security/artifact_signing looked
for target/debug/barbacane themselves, process_lifecycle fell back to it,
and control_cli and connected_mode looked in the target directory only.
None honoured BARBACANE_TEST_BINARY, and under a redirected
CARGO_TARGET_DIR (the coverage job) they ran target/debug/barbacane rather
than the build under test whenever the cache had left one there.

They now call find_barbacane_binary(): BARBACANE_TEST_BINARY first, then
the active target directory, then the fixed candidates.

Found by the static-image prototype (#404), which points
BARBACANE_TEST_BINARY at a static gateway and has no
target/debug/barbacane: init_template and artifact_capabilities failed
there (run 44317540356, shards 1 and 3).
Without a `config` block the plugin's init fails and the upstream answered
500 to every request, so the comparison never started.
The proxied routes reach a loopback upstream, which the SSRF guard
refused with a 502.
The glibc gateway failed 1,549 of 48,621 proxied requests in round 1
(upstream calls: "error sending request"), which stopped the run. Failed
requests are now a metric of each run, compared like the others.
ndreno added a commit that referenced this pull request Nov 18, 2026
init_template, artifact_capabilities and security/artifact_signing looked
for target/debug/barbacane themselves, process_lifecycle fell back to it,
and control_cli and connected_mode looked in the target directory only.
None honoured BARBACANE_TEST_BINARY, and under a redirected
CARGO_TARGET_DIR (the coverage job) they ran target/debug/barbacane rather
than the build under test whenever the cache had left one there.

They now call find_barbacane_binary(): BARBACANE_TEST_BINARY first, then
the active target directory, then the fixed candidates.

Found by the static-image prototype (#404), which points
BARBACANE_TEST_BINARY at a static gateway and has no
target/debug/barbacane: init_template and artifact_capabilities failed
there (run 44317540356, shards 1 and 3).

(cherry picked from commit 049cd8a)
@ndreno

ndreno commented Nov 18, 2026

Copy link
Copy Markdown
Contributor Author

Results of run 44334532132, all jobs green.

Function: the static binaries work

  • Both binaries are static-pie, contain mimalloc and run on scratch. Images: 15.0 MB (barbacane), 5.1 MB (barbacane-control).
  • The full integration suite (4 shards), the security suite, the control CLI and connected mode pass with the static binaries, the control plane on PostgreSQL.
  • Through the static gateway, a route to localhost (musl's resolver) and one to https://example.com (DNS, TLS roots) answer 200.

Performance: the static gateway is about 4x slower and 4x larger

Median of 3 alternating rounds, 20 s each, wrk with 64 connections on the same runner; both built by Rust 1.95 from the same commit.

glibc (today's build) static (musl, mimalloc) static / glibc
mock route, req/s 1,893 442 0.23
mock route, p50 / p99 (ms) 34 / 87 141 / 320 4.1 / 3.7
proxied route, req/s 1,243 404 0.33
proxied route, p50 / p99 (ms) 49 / 131 153 / 352 3.1 / 2.7
peak RSS (MiB) 97 428 4.4
proxied requests failed per round 532, 548, 503 1, 1, 3

The cause is not identified: mimalloc is linked, so musl's own allocator is not the whole story. Candidates are mimalloc on static musl, musl's memory routines, or something in wasmtime under musl. As it stands, scratch with a musl binary is not acceptable for the data plane.

Also found

  • Crate advisories cargo-deny cannot see. With cargo auditable, Grype lists 398 crates in the gateway and 294 in the control plane, and finds tar 0.4.45 (GHSA-3pv8-6f4r-ffg2, medium, fixed in 0.4.46) and rand 0.8.5 (GHSA-cq8v-f236-94qc, low, fixed in 0.8.6). Neither advisory has a RUSTSEC id, so cargo-deny, which reads the RustSec database, does not report them. Embedding the crate list is worth keeping whatever the base image.
  • Proxied requests fail under load on the glibc build: about 2% of requests, "error sending request" to a healthy loopback upstream, and only at glibc's throughput. The upstream client keeps at most 10 idle connections per host (pool_max_idle_per_host), so at 64 concurrent requests most upstream connections are opened and closed per request. That is a hypothesis, not yet measured.
  • The release's musl tarballs (x86_64/aarch64-unknown-linux-musl) are built without mimalloc today, so whatever slows this build likely applies to them, possibly more.

The static musl gateway ran about 4x slower with 4.4x the memory
(results on #404, follow-up in #409), so the prototype moves to the
glibc build on scratch:

- the build stage is the bookworm Rust image the release uses today,
  with `cargo auditable`;
- a bookworm-slim stage installs the archive's current libc6, libgcc-s1
  and ca-certificates, and docker/scratch-rootfs.sh copies the files of
  libc6 and libgcc-s1 with their dpkg status records and os-release, so
  Grype matches them against Debian's tracker, plus the CA bundle, the
  users, nsswitch.conf and /tmp; it fails if the binary does not start
  in a chroot of those files;
- mimalloc goes with musl.

The workflow checks Syft sees Debian 12 with libc6 and libgcc-s1, lists
every Grype match besides the release scan, and runs the load
comparison with both images as containers: today's (main's Dockerfile)
against the scratch one.
@ndreno ndreno changed the title proto(images): static binaries on scratch, checked in CI (#397) proto(images): the binaries on scratch with Debian's glibc, checked in CI (#397) Nov 18, 2026
With Debian 12's glibc 2.36 (run 44361456851) the scratch gateway
matched today's image on the mock route but proxied 6% fewer requests
and peaked 11% higher in memory, and a default Grype scan listed 33
matches on libc6 and libgcc-s1, 1 critical and 7 high among them,
most marked won't fix: Debian 12 is oldstable, on LTS since June 2026.

Debian 13 is stable and carries glibc 2.41. The build stage stays on
Debian 12, whose glibc the runtime's exceeds. The load job also lists
every Grype match in today's image, to compare.
With Debian 13's runtime files (run 44366600617) the scratch gateway
again proxied 6% fewer requests than today's image and peaked 12%
higher in memory, as with Debian 12, so the glibc version is not the
cause. The load job now also runs today's runtime with the scratch
image's binary (`cargo auditable build`) and the scratch runtime with
today's binary (`cargo build`), to tell which of the two the gap
follows.
@ndreno

ndreno commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor Author

Results: glibc on scratch

The prototype moved from musl to glibc: the binary built as today (Debian 12 builder) plus cargo auditable, on scratch with the files of Debian's libc6 and libgcc-s1, their dpkg records and os-release, the CA bundle, the users and nsswitch.conf. Three runs, all green: the image checks, the integration suite, the security suite, the control CLI, connected mode, and from inside the container a route to localhost and one to https://example.com.

Size. Compressed, the gateway image is 19.7 MB against 19.3 MB today; the control plane 10.0 MB. Of the 13 MB of runtime files uncompressed, 8 MB are glibc's gconv modules, which only iconv loads.

Scanners. A default Grype scan (no only-fixed) of today's image finds 0 matches across its 7 Wolfi packages. Of the scratch image, it finds Debian's records:

runtime files CVEs on libc6 and libgcc-s1 critical high marked won't fix
Debian 12 (libc6 2.36-9+deb12u14) 33 1 6 17
Debian 13 (libc6 2.41-12+deb13u4) 31 (38 rows: Grype lists gcc-14 and libgcc-s1 apart) 0 5 (3 libc6, 2 libgcc) 23

The release scan (only-fixed, high and above) passes on both; a user's default scan does not look clean.

Performance. Run 44371738254 crosses the two builds with the two runtimes, all as containers, medians of 3 rounds, ratio to today:

metric today (Chainguard, cargo build) Chainguard, cargo auditable Debian 13, cargo build Debian 13, cargo auditable
mock req/s 3,818 1.00 0.96 0.99
proxy req/s 1,817 0.98 0.90 0.93
proxy p50 33.6 ms 1.01 1.10 1.08
peak RSS 79.6 MiB 1.03 1.11 1.13

The gap follows the runtime: cargo auditable costs nothing measurable, Debian's glibc build costs 7 to 10% on the proxied route and about 10 MiB. The run before it, with Debian 13 against today only, measured the same 0.94 and 1.12; with Debian 12, 0.94 and 1.11.

So far. musl: about 4x slower (#409). Debian's glibc on scratch: works, same size, slower on the proxied route, and a default scan lists 33 to 38 matches where today's image lists none. What today's image brings is Wolfi's glibc build and its security feed, not the Chainguard image as such.

Debian's glibc on scratch cost 7 to 10% on the proxied route and about
10 MiB (run 44371738254: the gap follows the runtime files, not
`cargo auditable`), and a default Grype scan listed 31 to 33 CVEs on
Debian's records where today's image lists none.

docker/runtime.apko.yaml defines the base: wolfi-baselayout,
ca-certificates-bundle, glibc-2.44, ld-linux-2.44 and libgcc from
packages.wolfi.dev, and the nonroot user with its home. CI installs
apko v1.4.15 with `go install`, locks the packages and builds the base
from the lock; both Dockerfiles take it as BASE (default: Chainguard's
glibc-dynamic, which today's data plane uses) and add the binary. The
Debian runtime stage and docker/scratch-rootfs.sh go.

The image job checks Syft sees Wolfi and the five packages; the load
job compares today's image with the apko one.
ndreno added a commit that referenced this pull request Nov 18, 2026
GHSA-3pv8-6f4r-ffg2 (tar, medium) and GHSA-cq8v-f236-94qc (rand, low).
Neither has a RustSec id, so cargo deny never reported them; Grype found
them in the static-image prototype (#404) through the crate list that
`cargo auditable` embeds.

Only the two packages change in Cargo.lock: a plain `cargo update -p`
also re-resolved Windows-only windows-sys entries, which are left as
they are on main.
@ndreno

ndreno commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor Author

Results: a runtime base built with apko from Wolfi

docker/runtime.apko.yaml lists five packages from packages.wolfi.dev: wolfi-baselayout, ca-certificates-bundle, glibc-2.44, ld-linux-2.44 and libgcc (glibc pulls in glibc-2.44-locale-posix), and the nonroot user (65532) with its home. CI installs apko v1.4.15 (go install), pins the packages with apko lock and builds the base from the lock; both Dockerfiles take it as BASE and add the binary. Run 44381449035: every job green.

today (Chainguard glibc-dynamic) Debian 13 on scratch apko base
gateway image, compressed 19.3 MB 19.7 MB 18.0 MB
control plane image not measured (on debian:bookworm-slim today) 10.0 MB 8.4 MB
base alone 3.6 MB
packages a scanner sees 7 apk 2 deb 6 apk
default Grype scan, OS matches 0 31 CVEs, 5 high 0
programs besides the binary none ldconfig, ld.so (glibc's)

The release scan on the apko images finds only tar and rand, which #410 bumps.

Load, both images as containers, medians of 3 rounds (the job's second attempt; the first had a round disturbed for both images):

metric today apko ratio
mock req/s 2,891 2,870 0.99
mock p99 39.7 ms 40.2 ms 1.01
proxy req/s 1,365 1,361 1.00
proxy p99 108.0 ms 108.0 ms 1.00
peak RSS 78.6 MiB 79.5 MiB 1.01

Same performance and the same clean scan as today, from packages and a tool that are open source, under versions we pin and tags we publish. Wolfi keeps old builds in its index (24 builds of glibc 2.44 back to August, ca-certificates-bundle back to January 2025), so an older lock still resolves for a while; a published image does not depend on it.

Today's image comes from Chainguard's own repository (apk.cgr.dev/chainguard) and adds libstdc++, which neither binary links.

@ndreno ndreno changed the title proto(images): the binaries on scratch with Debian's glibc, checked in CI (#397) proto(images): a runtime base built with apko from Wolfi, checked in CI (#397) Nov 18, 2026
ndreno added a commit that referenced this pull request Nov 18, 2026
* feat(images): a runtime base of Wolfi packages built with apko

The data plane image ran on cgr.dev/chainguard/glibc-dynamic, whose
free tier publishes `latest` only, and the control plane on Debian 12
slim. Both now run on a base the repository defines:

- docker/runtime.apko.yaml lists wolfi-baselayout,
  ca-certificates-bundle, glibc-2.44, ld-linux-2.44 and libgcc from
  packages.wolfi.dev, and the nonroot user (65532) with its home;
  docker/runtime.apko.lock.json pins every package by version and
  checksum.
- Both Dockerfiles build the base from the lock in a stage of their
  own (apko v1.4.15, on the build platform, for the target
  architecture) and copy its files under the binary on scratch. The
  release, CI's image job and `make docker-build` build them as before.
- The binaries are built with `cargo auditable`, so scanners read their
  crates.
- `barbacane-control health` calls /health and exits 0 on 200: the
  control-plane image has no shell, and its HEALTHCHECK runs it.
- The Runtime base workflow scans the base and the latest release's
  images every night, and pushes a newer lock to deps/runtime-base;
  Actions may not open pull requests here, so a person opens it.
- CI's image job checks the two images hold no shell or package
  manager, the home belongs to 65532, /tmp is 1777 and the apk database
  is there.

The prototype in #404 measured the gateway on this base against
today's image: same throughput and latency on a mock and a proxied
route (0.99 and 1.00), same peak memory (1.01), 18.0 MB against
19.3 MB, and a default Grype scan finds no OS matches on either.
Debian's glibc on scratch had cost up to 10% on proxied routes and
listed 31 to 33 CVEs; static musl ran 4x slower (#409).

The lock comes from the Runtime base workflow's first run on this
branch.

Refs #397.

* feat(images): lock the runtime base's packages

glibc-2.44 and its loader and POSIX locale at 2.44-r23, libgcc
16.2.0-r5, ca-certificates-bundle 20261020-r0 and wolfi-baselayout
20230201-r31, for amd64 and arm64, as the Runtime base workflow
locked them (run 44397561698).
@ndreno

ndreno commented Nov 18, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by #411, which shipped the third variant (a runtime base of Wolfi packages built with apko). The comments above keep the measurements of all three.

@ndreno ndreno closed this Nov 18, 2026
@ndreno
ndreno deleted the proto/static-images branch November 18, 2026 21:28
ndreno added a commit that referenced this pull request Nov 19, 2026
ndreno added a commit that referenced this pull request Nov 19, 2026
#409 reported the static musl gateway about 4x slower than the glibc
one, from a single run of the #404 prototype. It does not reproduce:
the same source built for musl with its own allocator, mimalloc and
jemalloc, on the commit #404 measured, on the one after the Wasmtime
bump and on current main, and once exactly as #404 built it (cargo
auditable, symbols stripped, mimalloc), stays within 0.80 to 0.97x the
glibc build's throughput with about a quarter less memory with musl's
own allocator. The profile puts the gap in musl's allocator lock,
malloc and free, and memcpy.

The release keeps musl's own allocator: jemalloc would close the gap
on the mock route but adds a C dependency to cross-compile for two
targets, and mimalloc holds 4x the memory. The installation guide says
what the musl builds trade.

Closes #409.
ndreno added a commit that referenced this pull request Nov 23, 2026
* ci(deny): ignore RUSTSEC-2026-0543 (chrono unmaintained)

The advisory, published 2026-11-17, marks every chrono version as
unmaintained; it reports no vulnerability. rskafka 0.6 requires chrono
whatever the workspace uses, so no change here removes it. The audit job
failed on every pull request. #400 moves the workspace's own uses to
`time`.

(cherry picked from commit 8fe1641)

* fix(deps): Wasmtime 48.0.9 (RUSTSEC-2026-0566 to -0573)

Eight Wasmtime advisories published on 2026-11-18, fixed in 48.0.9,
fail cargo deny on every pull request. None reaches the gateway; the
CHANGELOG says why for each.

Only the 28 Wasmtime, Cranelift and Pulley packages change in both
locks: `cargo update -p wasmtime` also re-resolved Windows-only
windows-sys entries, which stay as they are on main. cargo deny's
advisories check passes and barbacane-wasm's 283 unit tests pass.

(cherry picked from commit 695cce3)

* chore(deps): tar 0.4.46 and rand 0.8.6 (#410)

GHSA-3pv8-6f4r-ffg2 (tar, medium) and GHSA-cq8v-f236-94qc (rand, low).
Neither has a RustSec id, so cargo deny never reported them; Grype found
them in the static-image prototype (#404) through the crate list that
`cargo auditable` embeds.

Only the two packages change in Cargo.lock: a plain `cargo update -p`
also re-resolved Windows-only windows-sys entries, which are left as
they are on main.

(cherry picked from commit 998fac2)

* fix(deps): url 2.5.9 for RUSTSEC-2026-0592

RUSTSEC-2026-0592: `Url::origin()` recurses into a `blob:` URL's inner
URL without a bound, so a deeply nested `blob:blob:...` URL overflows the
stack. Fixed in url 2.5.9; form_urlencoded moves to 1.2.3 with it.

Barbacane does not reach it: neither its code nor any crate that depends
on url in its tree (reqwest, sqlx, async-nats, ldap3, wiremock) calls
`Url::origin()`. The bump clears the advisory gate (cargo deny), which
fails every build from today. The plugins do not depend on url.

Workspace and fuzz lockfiles; both resolve with --locked, and
`cargo deny check advisories` passes.

(cherry picked from commit 31a933c)

* chore(release): 0.12.5

Versions 0.12.5, and the 0.12.5 CHANGELOG section for the dependency
updates backported from main: Wasmtime 48.0.9 (RUSTSEC-2026-0566 to
-0573), tar 0.4.46 and rand 0.8.6 (GHSA-3pv8-6f4r-ffg2,
GHSA-cq8v-f236-94qc) and url 2.5.9 (RUSTSEC-2026-0592).

Each "does not reach" statement in the CHANGELOG was checked on 0.12's
code and tree, not taken from main's: no wasmtime-wasi in the lockfile,
no component loading, `get_module_export` or GC reference in a host
function, default Wasmtime features (gc, threads), rand 0.8 without
`log`, `.bca` read with tar-rs only, and no `Url::origin()` call in the
code or in the seven crates that depend on url.

* ci: run the 0.12 integration tests on Rust 1.99.1

On Rust 1.100 (stable since 2026-11-09) the integration tests on
release/0.12 fail before running anything: `assert_cmd` cannot find
`CARGO_BIN_EXE_barbacane`, and the lifecycle tests look for the gateway
binary under target/debug/build/barbacane-test/<hash>/. Cargo 1.100
puts build output elsewhere; 0.12.4's integration tests ran on 1.99.1.

The integration-tests job pins 1.99.1. The other jobs stay on stable,
which builds, lints and unit-tests 0.12 on 1.100, the compiler the
release workflow builds with. main rewrote the harness's binary lookup
during 1.0.0-rc.1 and pins its toolchain.

* ci: UI end-to-end tests on Ubuntu 24.04; release builds pin cross

ubuntu-latest is Ubuntu 26.04, for which Playwright 1.58.2 (0.12's UI)
has no Chromium build: the UI E2E job failed with "Playwright does not
support chromium on ubuntu26.04-x64". It runs on ubuntu-24.04.

The release workflow installed cross from the head of its repository.
It now installs a9301e91, the commit v0.12.4's release used (and the
head today), so 0.12.5 builds its aarch64 and musl binaries with the
same cross as 0.12.4. The release jobs already ran on Ubuntu 26.04 for
v0.12.4.
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.

1 participant