Database access (etcd for Kubernetes)
TLS for Kubernetes Ingress
Container runtime isolation
Users can present a valid certificate signed by the cluster’s CA (Certificate Authority) are considered authenticated.
k8s-helm of the csc603ngo CloudLab profile
1
$ cat ~/.kube/config
certificate-authority-dataserverclient-certificate-dataclient-key-datastudent:
1
2
$ sudo useradd -s /bin/bash -d /home/student -m -G docker student
$ sudo su - student
kubectl commands now:
1
2
$ kubectl get nodes
$ kubectl get svc
student, run the following command:
1
$ mkdir .kube
config inside .kube with the following contents: COPY_FROM_ABOVE with the corresponding values of the corresponding fields above.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
apiVersion: v1
clusters:
- cluster:
certificate-authority-data: COPY_FROM_ABOVE
server: COPY_FROM_ABOVE
name: kubernetes
contexts:
- context:
cluster: kubernetes
user: student
name: student@kubernetes
current-context: student@kubernetes
kind: Config
preferences: {}
users:
- name: student
user:
client-certificate-data: COPY_FROM_ABOVE
client-key-data: COPY_FROM_ABOVE
kubectl commands now:
1
2
$ kubectl get nodes
$ kubectl get svc
Challenge Adding at least another Kubernetes cluster from one of your classmates’ experiment to your student account. In other words, one account can have access to multiple K8S cluster.
Deployments and Services, but not for cluster-wide objects like StorageClass, Nodes, and PersistentVolumes.
1
2
3
4
5
# In a namespace
$ kubectl api-resources --namespaced=true
# Not in a namespace
$ kubectl api-resources --namespaced=false
rbac.authorization.k8s.io API group to drive RBAC-based authorization decisions,
1
$ kubectl describe pods kube-apiserver -n kube-system | grep authorization
1
2
$ kubectl get role --all-namespaces
$ kubectl describe role system::leader-locking-kube-controller-manager -n kube-system
1
2
$ kubectl get clusterrole --all-namespaces
$ kubectl describe clusterrole cluster-admin
1
2
3
4
5
$ kubectl get RoleBinding --all-namespaces
$ kubectl get ClusterRoleBinding
- What `resources` are available and what `verbs` are applicable?
$ kubectl api-resources –sort-by name -o wide
1
2
3
4
5
6
7
- Run the following to deploy jenkins
~~~bash
$ bash /local/repository/jenkins/deploy_jenkins.sh
Setup a single build pipeline
hello_kube with contents copied from the instructor’s hello repo’s hello_kube branch Jenkins, create a New Item of type Pipeline and name it hello_kube, click OK.Pipeline select Pipeline script from SCM.SCM appears, select Git and provide the Repository URL for your hello_kube repo.Branch to build, change */master to */main.Script Path, enter Jenkinsfile. Jenkinsfile in the hello_kube branch.Apply.Save.hello_kube, select Build Now.:::{image} ../fig/csc603/08-cloud-security/rbac-01.png :alt: Missing service account :class: bg-primary mb-1 :height: 800px :align: center :::
Build Now.
1
$ kubectl create serviceaccount jenkins
1
2
3
$ kubectl delete serviceaccount jenkins
$ kubectl create namespace jenkins
$ kubectl create serviceaccount jenkins -n jenkins
Try Build Now again, does it still work?
There are many diffferent Ingress Controllers
nginx ingress controller using NodePort
1
2
$ kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.4.0/deploy/static/provider/baremetal/deploy.yaml
$ kubectl get svc -n ingress-nginx -o wide
hostname -f and use the port that is mapped to port 80 of ingress-nginx-controller to view::::{image} ../fig/csc603/08-cloud-security/ingress-01.png :alt: Ingress controller with no back-end services :class: bg-primary mb-1 :height: 200px :align: center :::
1
2
3
$ kubectl create deployment demo --image=httpd --port=80
$ kubectl expose deployment demo
$ kubectl get svc
hostname -f and see if you can view the default webpage.
1
kubectl create ingress demo-localhost --class=nginx --rule="$(hostname -f)/*=demo:80"
:::{image} ../fig/csc603/08-cloud-security/ingress-02.png :alt: Ingress controller with back-end services :class: bg-primary mb-1 :height: 200px :align: center :::
1
2
3
4
5
kubectl run template-frontend --image=hashicorp/http-echo --labels=app=template,type=frontend -- -listen=:80 -text="Frontend"
kubectl run template-api --image=hashicorp/http-echo --labels=app=template,type=api -- -listen=:80 -text="API"
kubectl expose pod template-api --port=80
kubectl expose pod template-frontend --port=80
kubectl get svc
annotation to the rule to provide alternative path options to different service end-points.
1
2
3
kubectl delete ingress demo-localhost
kubectl create ingress demo-localhost --class=nginx --rule="$(hostname -f)/demo/=demo:80" --rule="$(hostname -f)/api/=template-api:80" --rule="$(hostname -f)/frontend/=template-frontend:80"
kubectl annotate ingress demo-localhost nginx.ingress.kubernetes.io/rewrite-target="/"
/demo/, /api/, and /frontend/.
1
$ bash /local/repository/cert-manager/deploy_cert_manager.sh
HTTPS) of the nginx-controller
1
$ kubectl get svc -n ingress-nginx
demo-local ingress with updated TLS rules
1
2
3
kubectl delete ingress demo-localhost
kubectl create ingress demo-localhost --class=nginx --rule="$(hostname -f)/demo/=demo:80,tls=clemson.cloudlab.us-cert-secret" --rule="$(hostname -f)/api/=template-api:80" --rule="$(hostname -f)/frontend/=template-frontend:80"
kubectl annotate ingress demo-localhost nginx.ingress.kubernetes.io/rewrite-target="/"
/api/ and /frontend/ still work with the HTTP NodePort, but /demo/ requires HTTPS NodePort:::{image} ../fig/csc603/08-cloud-security/ingress-03.png :alt: Ingress controller with secured back-end services :class: bg-primary mb-1 :height: 200px :align: center :::
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
## Container Security
- Pod security will influence container security.
- Three policies:
- Privileged
- Baseline
- Restricted
- Cummulative and range from highly permissive to highly restrictive
- Purposely open, entirely unrestricted
- Enable system- and infrastructure-level workloads
- Implied understanding that these workloads are run as privileged/trusted users.
- Absence of restrictions and allow-by-default mechanism
- Streamline adoption for common containerized workloads
- Prevent known privilege escalations
- Example capabilities (Linux capabilities) enabled in baseline
- AUDIT_WRITE
- CHOWN
- DAC_OVERRIDE
- FOWNER
- FSETID
- KILL
- MKNOD
- NET_BIND_SERVICE
- SETFCAP
- SETGID
- SETPCAP
- SETUID
- SYS_CHROOT
- [Linux full capability list](https://man7.org/linux/man-pages/man7/capabilities.7.html)
- Enforce Pod hardening best practices at the expense of compatibility
- Target security-critical applications and lower-trust users
- Example policy:
- Disable privilege escalation
- Containers must run as non-root
- Drop **ALL** capabilities and only allow `NET_BIND_SERVICE`.