From 50f392dc7cddec895a8296d541bee2960e84bf4f Mon Sep 17 00:00:00 2001 From: Christoph Dyllick-Brenzinger Date: Wed, 4 Nov 2026 17:01:45 +0100 Subject: [PATCH] Keep the apk package list so scanners see OS packages Removing /lib/apk also removed /lib/apk/db/installed, the list scanners read. Trivy found 0 OS packages and reported 0 OS CVEs, which said nothing about the image. /sbin/apk and /etc/apk stay removed, so apk remains unavailable. Co-Authored-By: Claude Opus 5.5 --- Dockerfile | 5 +++-- README.md | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 1a38eb1..a22b596 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,12 +13,13 @@ FROM ${NODE_IMAGE} # Remove everything the server never uses but an attacker inside the # container would: package managers (npm, yarn, corepack, apk) and the # busybox network/privilege tools (wget, nc, su). The health check uses -# node instead of wget. +# node instead of wget. /lib/apk/db stays: without that list of installed +# packages, scanners see 0 OS packages and report 0 CVEs however many there are. RUN apk upgrade --no-cache \ && rm -rf /usr/local/lib/node_modules/npm /usr/local/lib/node_modules/corepack /opt/yarn-* \ /usr/local/bin/npm /usr/local/bin/npx /usr/local/bin/corepack /usr/local/bin/yarn /usr/local/bin/yarnpkg \ /usr/bin/wget /usr/bin/nc /bin/su \ - /sbin/apk /etc/apk /lib/apk /usr/share/apk /var/cache/apk + /sbin/apk /etc/apk /lib/apk/exec /usr/share/apk /var/cache/apk WORKDIR /app # Copied as root and left root-owned: the node user can read the code but # never change it. diff --git a/README.md b/README.md index 94fa4e9..6a8ea73 100644 --- a/README.md +++ b/README.md @@ -186,7 +186,7 @@ The image is built so that code running inside the server process — for exampl - **Non-root:** the server runs as `node` (uid 1000). The code in `/app` is owned by root and read-only for that user. - **Node permission model:** the default `CMD` starts `node --permission --allow-fs-read=/app`. The process may read its own code and nothing else; writing files, child processes (no shell), worker threads and native addons are denied. Outbound network access is not affected. The server needs none of the denied operations, including `download_file`, which extracts PDF text in memory. -- **No tools for an attacker:** npm, npx, yarn, corepack and apk are removed, and so are busybox `wget`, `nc` and `su`. The health check uses `node`. There are no setuid binaries. +- **No tools for an attacker:** npm, npx, yarn, corepack and apk are removed, and so are busybox `wget`, `nc` and `su`. The health check uses `node`. There are no setuid binaries. Only apk's package list in `/lib/apk/db` stays, so that vulnerability scanners can see the OS packages. Without `/sbin/apk` it can't install anything, and the permission model denies the server read access to it. - **Pinned base image:** `node:22.23.4-alpine3.24` (build argument `NODE_IMAGE`), with `apk upgrade` at build time. At runtime, add the restrictions the image can't set itself. `docker-compose.yml` contains all of them: