Kubernetes single-node cluster installed on a Vagrant VM using the Vagrantfile below (variant of what's discussed (here)[https://medium.com/@lizrice/kubernetes-in-vagrant-with-kubeadm-21979ded6c63]), which runs kubeadm
to install Kubernetes.
I use v1.9.0 which doesn't include the patch for the critical Kubernetes CVE-2018-1002105.
kubeadm
sets up a number of files in /etc/kubernetes/manifests.
For the demo I change the API Server yaml file to set --anonymous-auth=true
(allows anonymous, unauthenticated access) or --anonymous-access=false
The kube-apiserver.yaml file is included in this gist, but it's only line 16 that needs to be modified for the demo. Don't copy this file
as-is because your IP addresses will probably be different.
With --anonymous-auth enabled, run kube-hunter from outside the cluster to show unauthenticated access to the API.
This is equivalent of curl -k https://<IP address>:6443
, curl -k https://<IP address>:6443/api/v1
Run kube-bench master
on the node to show API Server --anonymous-auth test.
Create a clusterrolebinding which allows all system serviceaccounts (including default) to view resources.
kubectl create clusterrolebinding serviceaccounts-view --clusterrole=view --group=system:serviceaccounts
Run a pod with curl enabled e.g.
kubectl run curl -it --image tutum/curl -- bash
Find the pod (kubectl get pods
) and attach to it:
k attach -it curl-74846499d6-gms9k
From inside the pod:
# Access the service account token
export TOKEN=`cat /var/run/secrets/kubernetes.io/serviceaccount/token`
# No info supplied
curl -k https://<IP address>:6443/api/v1/namespaces
# Use token to use service account's permissions
curl -k -H "Authorization: Bearer $TOKEN" https://<IP address>:6443/api/v1/namespaces
You can simply use https://kubernetes instead of the IP address and port