Yet many developers may find themselves hating Kubernetes because it is, in a word, hard. The tradeoff for Kubernetes’s enormous power and flexibility is its complexity. Mastering that complexity is no mean feat.
Not only that, but navigating the security challenges posed by Kubernetes’s complexity is also enormously difficult. Small configuration mistakes or oversights within Kubernetes can have profoundly negative security consequences.
To illustrate the point, let’s walk you through a brief Kubernetes security overview, which addresses six common security mistakes in Kubernetes that are all too easy to make. We’ll focus in particular on the types of security issues that can become widespread within a cluster if you manage the cluster via infrastructure as code (IaC). This approach means that a security misconfiguration in a single IaC file can be quickly reproduced across an entire environment. Below are some of the common Kubernetes misconfigurations and security challenges when it comes to writing manifests and developing Kubernetes infrastructure.
Kubernetes containers running in privileged mode
Running containers in privileged mode—which gives them unfettered access to host-level resources—is like giving a redshirt the captain’s chair: it’s granting way too much power. And if you do, you may be unhappy with the consequences.
Unfortunately, running containers in privileged mode is a configuration mistake that you can easily make when configuring Kubernetes deployments. It just takes one variable/value: privileged:true
.
Ideally, you’ll avoid this mistake by not configuring containers to run in privileged mode in the first place. But you can also audit your Kubernetes configurations using a tool like Checkov to find containers that were deployed in privileged mode.
Allowing container privilege escalation
Along similar lines, there’s really no situation in which Kubernetes containers should be allowed to escalate into privileged mode. To preclude containers from running in privileged mode, make sure to set “allowPrivilegeEscalation:” to “false” when configuring security contexts. Note that “allowPrivilegeEscalation” is automatically set to true if the container is privileged (see previous) or given CAP_SYS_ADMIN capabilities. Avoid those as well.
Failing to encrypt internal traffic
Another small but critical setting is the --kubelet-https=...
flag. It should be set to “true.” If it’s not, traffic between your API server and kubelets won’t be encrypted.
Omitting the setting entirely also usually means that traffic will be encrypted by default. But because this behavior could vary depending on which Kubernetes version and distribution you use, it pays to be explicit about requiring Kubelet encryption, at least until the Kubernetes developers encrypt traffic universally by default.
Pulling containers using the “latest” tag
When specifying how to pull Kubernetes container images from a registry, avoid settings like this: