{"id":1013,"slug":"minifier-cli","title":"Shrinking third-party containers without touching a Dockerfile","excerpt":"A Go tool born out of ProdSec vuln noise on third-party images we run on k8s but don't own.. observes runtime file access, rebuilds from scratch with only what's needed.","content":"\u003cp\u003eOur ProdSec team at work recently leaned hard into Wiz and Slack-ops. Vulnerabilities started piling up across our various namespaces, a lot of them flagged critical on paper.. typical enterprise scenario where dashboards are red and every alert demands a response.\u003c/p\u003e\n\u003cp\u003eThe catch: most of those images aren\u0026rsquo;t ours. We\u0026rsquo;re DevX, which sits inside CloudOps alongside Platform Engineering, SRE, and Cloud Cost.. a big part of what our org does is run the infrastructure that makes the clusters work. Wiz, Datadog agents, observability tooling, a bunch of GitOps stuff. Closed source, proprietary, not ours to rebuild. But they live in our namespaces, so we own the vuln count. Anything legacy or shared comes along for the ride too.\u003c/p\u003e\n\u003cp\u003eCoworker bud and I started talking about what you\u0026rsquo;d actually do about this. You can\u0026rsquo;t patch a binary you don\u0026rsquo;t ship. You can\u0026rsquo;t swap the base image. The vendor updates when they update. The realistic options are: accept the noise, get exceptions granted, or get creative.\u003c/p\u003e\n\u003cp\u003eMoment of clarity: what if we just\u0026hellip; axe the parts that aren\u0026rsquo;t running?\u003c/p\u003e\n\u003ch2 id=\"trace-whats-actually-used\"\u003eTrace What\u0026rsquo;s Actually Used\u003c/h2\u003e\n\u003cp\u003eA typical third-party agent image is built for maximum compatibility. Shells, package managers, debug utilities, man pages, and a pile of shared libraries for features nobody in your environment uses. Hundreds of megabytes, and every one of those binaries is something for the scanner to yell about.\u003c/p\u003e\n\u003cp\u003eRebuild the image from scratch with only the files the container actually touches at runtime, and the agent still pongs.. but the shell is gone. So is the package manager. So is most of what the scanner was complaining about.\u003c/p\u003e\n\u003ch2 id=\"so-i-built-something\"\u003eSo I Built Something\u003c/h2\u003e\n\u003cp\u003e\u003cstrong\u003e\u003ca href=\"https://github.com/swantron/minifier-cli\"\u003eminifier-cli\u003c/a\u003e\u003c/strong\u003e is a Go tool that does exactly this.\u003c/p\u003e\n\u003cp\u003e\u003cstrong\u003e1. Trace.\u003c/strong\u003e Run your container through the tool and it watches which files the process opens and maps into memory, polling \u003ccode\u003e/proc\u003c/code\u003e inside the container every second.\u003c/p\u003e\n\u003cdiv class=\"highlight\"\u003e\u003cpre tabindex=\"0\" style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;\"\u003e\u003ccode class=\"language-bash\" data-lang=\"bash\"\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003eminifier-cli trace start --image datadog/agent:latest --name dd-prod\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e\u003cspan style=\"color:#75715e\"\u003e# Let it run in a production-like environment\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e\u003cspan style=\"color:#75715e\"\u003e# Ctrl+C to stop tracing\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003c/div\u003e\u003cp\u003e\u003cstrong\u003e2. Repackage.\u003c/strong\u003e It walks every binary in the trace for the shared libraries it needs, adds the handful of files everything quietly relies on (passwd, hosts, resolv.conf), copies it all out, and builds a \u003ccode\u003eFROM scratch\u003c/code\u003e image with the original ENV, CMD, and ENTRYPOINT.\u003c/p\u003e\n\u003cdiv class=\"highlight\"\u003e\u003cpre tabindex=\"0\" style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;\"\u003e\u003ccode class=\"language-bash\" data-lang=\"bash\"\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003eminifier-cli repackage --name dd-prod --output datadog-minimal:prod\n\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003c/div\u003e\u003cp\u003enginx:alpine goes from 91.7MB to 14.1MB. A startup-only trace of \u003ccode\u003edatadog/agent:latest\u003c/code\u003e takes it from 1.17GB to 59MB. The vuln scanner suddenly has a lot less to say.\u003c/p\u003e\n\u003cp\u003e\u003cimg src=\"/uploads/2026/06/minifier-cli-terminal.png\" alt=\"minifier-cli terminal output: trace, repackage, and docker images before and after\"\n  loading=\"lazy\"\n  decoding=\"async\"\n/\u003e\n\u003c/p\u003e\n\u003ch2 id=\"how-it-ended-up\"\u003eHow It Ended Up\u003c/h2\u003e\n\u003cp\u003eWe eventually landed on a different solution for the actual hardening problem.. we are basically buying pre-hardened images that someone else has already performed surgery on. With vendor backing and security buy-off, we are somewhat less culpable.\u003c/p\u003e\n\u003cp\u003eStill, it\u0026rsquo;s a handy way to find out what a black-box container actually needs at runtime.. for hardening, audits, or poking at a legacy app before you migrate it. Open-sourcing it on the theory that someone else has the same problem.\u003c/p\u003e\n\u003cp\u003eFair warning: the image only has what got touched during the trace. Error paths, plugins, and config-flag-only drivers won\u0026rsquo;t be there unless you exercised them. Run your integration tests while tracing, trigger your error states, test it in staging, and keep the original around. Don\u0026rsquo;t ship it on the strength of a five-minute trace and a \u003ccode\u003ecurl localhost\u003c/code\u003e.\u003c/p\u003e\n\u003cp\u003eBinaries on the \u003ca href=\"https://github.com/swantron/minifier-cli/releases\"\u003ereleases page\u003c/a\u003e. The tracer needs Linux; the repackager runs fine on a Mac.\u003c/p\u003e\n\u003cp\u003eSource: \u003ca href=\"https://github.com/swantron/minifier-cli\"\u003egithub.com/swantron/minifier-cli\u003c/a\u003e\u003c/p\u003e\n","date":"2026-06-01T00:00:00Z","permalink":"https://swantron.com/2026/06/01/minifier-cli/","link":"https://swantron.com/2026/06/01/minifier-cli/","path":"/2026/06/01/minifier-cli/","featuredImage":"/uploads/2026/06/minifier-cli-terminal.png","categories":[],"tags":[]}