Kubernetes CKAD Hands-On Challenge #11 Security Contexts
Kubernetes CKAD Hands-On Challenge #11 Security Contexts
Kubernetes CKAD Hands-On Challenge #11 Security Contexts
https://codeburst.io/kubernetes-ckad-hands-on-challenge-11-security-contexts-bbe1289a422d 1/11
19/05/2020 Kubernetes CKAD hands-on challenge #11 Security Contexts
It has been a while! But I wanted to create some more challenges, so let’s
begin!
Rules!
1. be fast, avoid creating yaml manually from scratch
3. check my solution after you did yours. You probably have a better one!
Scenario Setup
apiVersion: v1
kind: Pod
metadata:
creationTimestamp: null
labels:
run: bash
https://codeburst.io/kubernetes-ckad-hands-on-challenge-11-security-contexts-bbe1289a422d 2/11
19/05/2020 Kubernetes CKAD hands-on challenge #11 Security Contexts
name: bash
spec:
volumes:
- name: share
emptyDir: {}
containers:
- command:
- /bin/sh
- -c
- sleep 1d
image: bash
name: bash1
volumeMounts:
- name: share
mountPath: /tmp/share
- command:
- /bin/sh
- -c
- sleep 1d
image: bash
name: bash2
volumeMounts:
- name: share
mountPath: /tmp/share
restartPolicy: Never
We have one pod with two containers of image bash which share an
emptyDir volume. Go get that pod running!
https://codeburst.io/kubernetes-ckad-hands-on-challenge-11-security-contexts-bbe1289a422d 3/11
19/05/2020 Kubernetes CKAD hands-on challenge #11 Security Contexts
1. Log into container bash1 and create a file in the shared volume. View
that file and its permissions via container bash2.
Solution
# 1 Create file in shared volume
alias k=kubectl
https://codeburst.io/kubernetes-ckad-hands-on-challenge-11-security-contexts-bbe1289a422d 4/11
19/05/2020 Kubernetes CKAD hands-on challenge #11 Security Contexts
...
spec:
securityContext:
runAsUser: 21
volumes:
- name: share
emptyDir: {}
containers:
...
Then run:
k delete -f deployment.yaml
https://codeburst.io/kubernetes-ckad-hands-on-challenge-11-security-contexts-bbe1289a422d 5/11
19/05/2020 Kubernetes CKAD hands-on challenge #11 Security Contexts
k create -f deployment.yaml
...
containers:
- command:
- /bin/sh
- -c
- sleep 1d
https://codeburst.io/kubernetes-ckad-hands-on-challenge-11-security-contexts-bbe1289a422d 6/11
19/05/2020 Kubernetes CKAD hands-on challenge #11 Security Contexts
image: bash
name: bash1
volumeMounts:
- name: share
mountPath: /tmp/share
securityContext:
runAsUser: 0
...
k delete -f deployment.yaml
k create -f deployment.yaml
https://codeburst.io/kubernetes-ckad-hands-on-challenge-11-security-contexts-bbe1289a422d 7/11
19/05/2020 Kubernetes CKAD hands-on challenge #11 Security Contexts
...
containers:
- command:
https://codeburst.io/kubernetes-ckad-hands-on-challenge-11-security-contexts-bbe1289a422d 8/11
19/05/2020 Kubernetes CKAD hands-on challenge #11 Security Contexts
- /bin/sh
- -c
- chmod og-w -R /tmp/share && sleep 1d
image: bash
name: bash1
...
Recap
We played around a little with Security Contexts and filesystem permissions
of volumes. There is more though!
https://codeburst.io/kubernetes-ckad-hands-on-challenge-11-security-contexts-bbe1289a422d 9/11
19/05/2020 Kubernetes CKAD hands-on challenge #11 Security Contexts
More challenges on
https://killer.sh
https://codeburst.io/kubernetes-ckad-hands-on-challenge-11-security-contexts-bbe1289a422d 11/11