Kubernetes Security
December 7, 2017 | Docker Security KubernetesIn this post, we take a look at security on the PRP Kubernetes cluster. The Kubernetes cluster is experimental/alpha in its current incarnation, so security can be understandably quite lax.
CILOGON
All Kubernetes clusters have two categories of users: service accounts managed by Kubernetes, and normal users. The latter are assumed to be managed by an outside, independent service. For the PRP Kubernetes cluster, the outside service is CILogon. Currently there is no restriction: anyone with a valid CILogon credential can login at the PRP Kubernetes gateway. Then he/she can download a Kubeconfig file and launch containers on the cluster. Since CILogon bridges the identity credentials generated by over 200 universities and organizations (through the InCommon Federation) as well as Google identity credentials, virtually anyone in the world can freely use the cluster, including the four GPU nodes! Given the stratospherically (some may say bubbly) high prices for cryptocurrencies, I am constantly amazed that no one has used the GPU nodes to mine bitcoins and the likes for free yet!
Docker Security
To put it mildly, security is not Docker’s forte. root (id = 0) is the default user within a container, even though the container is launched by a normal user (a normal user must belong to the docker group in order to be able to run docker commands). For example, on the 4-GPU workstation Hydra:
If we mount a host volume / directory on the container, we’ll have unfettered, read and write, access to the files in the volume:
Furthermore, if we executes docker run with the --privileged
flag, Docker will enable access to all devices on the host as well as set some configuration in AppArmor or SELinux to allow the container nearly all the same access to the host as processes running outside containers on the host! For example, we can mount any host block device on the container, and do whatever tickles our fancy.
We can use the -u
(or --user
) to run the container as a non-root user. When passing a numeric ID, the user does not have to exist in the container, not in the host:
On the host, we can see that the sh process is running as uid 2000:
This scheme, however, won’t mitigate Docker’s security risks. It will at best protects the host from a malicious Docker image; but it won’t protect the host from a troublesome user!
Kubernetes Security
First switch to normal user shaw@ucsc.edu:
Next create a Kubernetes manifest alpine-volume.yaml
, which will mount the host’s /etc
directory at /etc2
on the alpine container:
Create a pod object from the YAML manifest:
Check whether the pod is running:
Start a shell in the running pod:
We can see that the host’s /etc
is indeed mounted at /etc2
on the container; and we have unfettered access to the files therein.
Clean up by deleting the pod:
For the last experiment, create a Kubernetes manifest alpine-privileged.yaml
, which will create a privileged container:
Create a pod object from the YAML manifest:
Check whether the pod is running:
Start a shell in the running pod:
We find that indeed the container has full access to all devices on the host!
Clean up by deleting the pod:
Discussion
These security risks are pretty serious! Perhaps we should look into Security Context and Pod Security Policy to mitigate these risks?