ADR-022: Distroless Runtime Image
Context
ADR-002 standardized the runtime on a `node:24-alpine` base — small, but still a full Linux userland: a shell, a package manager (apk), busybox, and the libraries they pull in. For an internet-facing service that is also a hiring showcase, every one of those is attack surface that the application never uses at runtime. Container scanners (Trivy) routinely flag CVEs in that base layer that have nothing to do with our code, and an Alpine/musl base also subtly mismatches the glibc world most native Node addons are compiled against.
Decision
Split the build cleanly in two and ship the runtime on Google's distroless image: `gcr.io/distroless/nodejs26-debian13:nonroot`.
* Stage 1 (Builder): `node:26-slim` (Debian 13 / trixie, glibc) installs only production dependencies with `npm ci --omit=dev` over a BuildKit cache mount. The builder shares the same libc as the runtime, so any package with a native binary is compiled against the C library the runtime actually provides — an Alpine/musl builder would produce binaries the distroless image cannot load.
* Stage 2 (Runtime): the distroless base has no shell, no package manager, and no busybox — only the Node.js runtime and its glibc dependencies. Its entrypoint is already `node` and the `:nonroot` tag runs as the unprivileged uid 65532, so the image starts as a non-root user by default; the `USER nonroot` instruction is declared explicitly so static scanners (Trivy DS-0002) can see it. The installed `node_modules`, the host-built `dist/` bundle, and `patches/` are copied in, all owned by 65532.
The `patches/` directory must ship to the runtime: the `node-domexception` `file:` override installs as a symlink into `patches/`, and without it at runtime the link dangles and Google auth's token refresh fails, breaking every Vertex AI call.
Amended 2026-10-16: a third stage, `debian:13-slim AS terraform`, downloads a pinned Terraform release and builds an offline mirror of a pinned google provider for the Terraform demo. The runtime ships that binary and mirror with `TERRAFORM_BIN`, `TF_CLI_CONFIG_FILE`, `TF_GOOGLE_PROVIDER_VERSION` and `HOME=/tmp` set, so `terraform init` needs no network. This widens the minimal runtime surface: the image now carries an executable the server spawns. There is still no shell or package manager, the container still runs as uid 65532, the demo only runs HCL generated from validated inputs, and the child process receives an allowlisted environment rather than the server's full one.
Consequences
Benefits:
* Near-zero base-layer CVEs: removing the shell, package manager, and busybox eliminates the most common source of scanner findings unrelated to our code.
* No interactive shell means nothing to `exec` into — a meaningful hardening win for an internet-facing container, removing the classic post-exploitation foothold.
* glibc builder/runtime parity makes native-addon behavior deterministic across build and run.
* Runs as a non-root user (uid 65532) out of the box, with the constraint declared explicitly for scanners.
Trade-offs:
* Debugging is harder: with no shell you cannot `docker exec` into a running container — diagnosis relies on logs, metrics, and reproducing locally instead.
* The split build is slightly more intricate: `patches/` must be copied to the runtime or Vertex auth breaks, and the builder libc must match the runtime libc.
Alternatives considered
1. Stay on node:24-alpine (ADR-002): Rejected — small, but still ships a shell, package manager, and busybox as standing attack surface, and its musl libc mismatches the glibc most native addons target.
2. node:26-slim as the runtime too: Rejected — smaller than full Debian but still a complete userland with a shell and apt; distroless removes that entire class of surface for the same glibc compatibility.
3. A "scratch" image with a statically linked Node: Rejected — fragile to build and maintain for a Node app with native dependencies; distroless delivers most of the benefit with an officially maintained, regularly patched base.