OnCallReadyStart learning

Security and secrets Lesson 23.7 · Kubernetes Security (CKS) · 2 min read

Verify a Kubernetes binary before you trust it

In plain words

A binary you download is a sealed package from a stranger. The release team prints the package's fingerprint on their own website. Before you open the package, you compare its fingerprint with the printed one. If the two differ, someone swapped the contents on the way, and you throw the package away instead of opening it to see what happens.

A binary you did not build

kubelet, kubectl and kubeadm run as root on every node. A copy from a mirror, a cache or a colleague's USB stick may not be the one the Kubernetes release team built. Every release publishes a checksum next to each binary:

curl -LO "https://dl.k8s.io/release/v1.37.1/bin/linux/arm64/kubelet"
curl -LO "https://dl.k8s.io/release/v1.37.1/bin/linux/arm64/kubelet.sha256"
echo "$(cat kubelet.sha256)  kubelet" | sha256sum --check

The .sha256 file holds only the hash; the echo builds the "HASH FILE" line (two spaces) that sha256sum --check expects. It answers kubelet: OK - or kubelet: FAILED and "WARNING: 1 computed checksum did NOT match" with exit code 1. A FAILED binary is not installed, not "tried once": it is deleted and fetched again from the release URL.

In an interview: "a checksum from the same untrusted place as the binary proves nothing - take it from the release (dl.k8s.io) or, better, verify the release signature".

On the exam: domain "Cluster setup": verify platform binaries before deploying them.

Why it helps

kubelet, kubectl and kubeadm run as root on every node, so a tampered copy owns the whole cluster. Checking the release checksum takes one line, it is easy to forget when you copy a binary from a cache or a colleague, and it is a CKS cluster setup task. It is also the first step towards trusting your supply chain at all.

FAQ

Where does the checksum come from?

From the release itself: dl.k8s.io publishes a .sha256 file next to every binary for every version and platform. You download both from the release, not from the mirror or cache that gave you the binary.

Why the echo before sha256sum --check?

The .sha256 file holds only the hash. sha256sum --check expects lines of the form hash, two spaces, file name, so the echo builds that line from the file's content and the binary's name before it is piped in.

What does a mismatch look like?

sha256sum prints the file name followed by FAILED, warns that one computed checksum did NOT match, and exits with code 1. In a script that exit code is what stops the installation. Treat any non-zero exit as a stop, never as a warning.

What do I do with a FAILED binary?

Delete it and fetch it again from the release URL, then report where the bad copy came from. Never install it to see whether it works: a tampered binary usually works perfectly, which is the point.

Does a checksum from the same mirror help?

No. Whoever swapped the binary on the mirror can swap its checksum too. Take the checksum from the release itself, or better, verify the release signature, which an attacker on the mirror cannot forge. The checksum is only as trustworthy as the place it came from.

In an interview Mid

How do you make sure a Kubernetes binary you download is genuine?

Download it and its .sha256 from dl.k8s.io, build the hash-and-name line with echo "$(cat kubelet.sha256) kubelet" and pipe it to sha256sum --check: kubelet: OK means it matches the release build. FAILED means delete it and fetch it again from the release, and find out where the bad copy came from.

Also asked: Why is a checksum from the same mirror worthless? · What exit code does sha256sum --check give on a mismatch? · Which binaries matter most on a node?

Practise this lesson in the terminal Free, in your browser - a real Ubuntu terminal to try it in, with missions that check your work.