A Dockerfile downloads a binary with `curl | sh`. How do you make it safe?
IntermediateScenarioSupply Chain Security
Answer
Situation read → You are executing whatever the server returns at build time. A compromised URL means a compromised image.
What I'd do →
- Pin an explicit version in the URL.
- Verify a SHA-256 checksum stored in the repo:
echo "<sha256> tool.tgz" | sha256sum -c -. - Prefer verifying a signature (
cosign verify-blob, GPG) from the publisher. - Better: use a package from your internal proxy, or copy from a pinned image with
COPY --from=.
Why → A checksum committed in the repo ties the build to a reviewed artifact.
Interview tip → curl | sh in a Dockerfile is a code review red flag.
More on Supply Chain Security
What is an SBOM, and at which point in the pipeline do you generate it?BeginnerA customer asks for an SBOM for your product. What do you give them?BeginnerHow do you sign container images in GitHub Actions without managing private keys?IntermediateYou signed images in CI. How do you make sure the cluster only runs signed images?IntermediateLeadership wants "SLSA compliance". What do you propose?IntermediateWhat is typosquatting and how do you protect developers from it?Beginner