U.S. Independence Day Deal! Unlock 25% OFF Today – Limited-Time Offer - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

Linux Foundation CKS Exam - Topic 1 Question 7 Discussion

SIMULATIONCreate a PSP that will prevent the creation of privileged pods in the namespace.Create a new PodSecurityPolicy named prevent-privileged-policy which prevents the creation of privileged pods.Create a new ServiceAccount named psp-sa in the namespace default.Create a new ClusterRole named prevent-role, which uses the newly created Pod Security Policy prevent-privileged-policy.Create a new ClusterRoleBinding named prevent-role-binding, which binds the created ClusterRole prevent-role to the created SA psp-sa.Also, Check the Configuration is working or not by trying to Create a Privileged pod, it should get failed.
A) Explanation: Create a PSP that will prevent the creation of privileged pods in the namespace. $ cat clusterrole-use-privileged.yaml --- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: name: use-privileged-psp rules: - apiGroups: ['policy'] resources: ['podsecuritypolicies'] verbs: ['use'] resourceNames: - default-psp --- apiVersion: rbac.authorization.k8s.io/v1 kind: RoleBinding metadata: name: privileged-role-bind namespace: psp-test roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: use-privileged-psp subjects: - kind: ServiceAccount name: privileged-sa $ kubectl -n psp-test apply -f clusterrole-use-privileged.yaml After a few moments, the privileged Pod should be created. Create a new PodSecurityPolicy named prevent-privileged-policy which prevents the creation of privileged pods. apiVersion: policy/v1beta1 kind: PodSecurityPolicy metadata: name: example spec: privileged: false # Don't allow privileged pods! # The rest fills in some required fields. seLinux: rule: RunAsAny supplementalGroups: rule: RunAsAny runAsUser: rule: RunAsAny fsGroup: rule: RunAsAny volumes: - '*' And create it with kubectl: kubectl-admin create -f example-psp.yaml Now, as the unprivileged user, try to create a simple pod: kubectl-user create -f- <<EOF apiVersion: v1 kind: Pod metadata: name: pause spec: containers: - name: pause image: k8s.gcr.io/pause EOF The output is similar to this: Error from server (Forbidden): error when creating 'STDIN': pods 'pause' is forbidden: unable to validate against any pod security policy: [] Create a new ServiceAccount named psp-sa in the namespace default. $ cat clusterrole-use-privileged.yaml --- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: name: use-privileged-psp rules: - apiGroups: ['policy'] resources: ['podsecuritypolicies'] verbs: ['use'] resourceNames: - default-psp --- apiVersion: rbac.authorization.k8s.io/v1 kind: RoleBinding metadata: name: privileged-role-bind namespace: psp-test roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: use-privileged-psp subjects: - kind: ServiceAccount name: privileged-sa $ kubectl -n psp-test apply -f clusterrole-use-privileged.yaml After a few moments, the privileged Pod should be created. Create a new ClusterRole named prevent-role, which uses the newly created Pod Security Policy prevent-privileged-policy. apiVersion: policy/v1beta1 kind: PodSecurityPolicy metadata: name: example spec: privileged: false # Don't allow privileged pods! # The rest fills in some required fields. seLinux: rule: RunAsAny supplementalGroups: rule: RunAsAny runAsUser: rule: RunAsAny fsGroup: rule: RunAsAny volumes: - '*' And create it with kubectl: kubectl-admin create -f example-psp.yaml Now, as the unprivileged user, try to create a simple pod: kubectl-user create -f- <<EOF apiVersion: v1 kind: Pod metadata: name: pause spec: containers: - name: pause image: k8s.gcr.io/pause EOF The output is similar to this: Error from server (Forbidden): error when creating 'STDIN': pods 'pause' is forbidden: unable to validate against any pod security policy: [] Create a new ClusterRoleBinding named prevent-role-binding, which binds the created ClusterRole prevent-role to the created SA psp-sa. apiVersion: rbac.authorization.k8s.io/v1 # This role binding allows 'jane' to read pods in the 'default' namespace. # You need to already have a Role named 'pod-reader' in that namespace. kind: RoleBinding metadata: name: read-pods namespace: default subjects: # You can specify more than one 'subject' - kind: User name: jane # 'name' is case sensitive apiGroup: rbac.authorization.k8s.io roleRef: # 'roleRef' specifies the binding to a Role / ClusterRole kind: Role #this must be Role or ClusterRole name: pod-reader # this must match the name of the Role or ClusterRole you wish to bind to apiGroup: rbac.authorization.k8s.io apiVersion: rbac.authorization.k8s.io/v1 kind: Role metadata: namespace: default name: pod-reader rules: - apiGroups: [''] # '' indicates the core API group resources: ['pods'] verbs: ['get', 'watch', 'list']

Linux Foundation CKS Exam - Topic 1 Question 7 Discussion

Actual exam question for Linux Foundation's CKS exam
Question #: 7
Topic #: 1
[All CKS Questions]

SIMULATION

Create a PSP that will prevent the creation of privileged pods in the namespace.

Create a new PodSecurityPolicy named prevent-privileged-policy which prevents the creation of privileged pods.

Create a new ServiceAccount named psp-sa in the namespace default.

Create a new ClusterRole named prevent-role, which uses the newly created Pod Security Policy prevent-privileged-policy.

Create a new ClusterRoleBinding named prevent-role-binding, which binds the created ClusterRole prevent-role to the created SA psp-sa.

Also, Check the Configuration is working or not by trying to Create a Privileged pod, it should get failed.

Show Suggested Answer Hide Answer
Suggested Answer: A

Contribute your Thoughts:

0/2000 characters
Iluminada
8 months ago
I’m surprised this is even possible!
upvoted 0 times
...
Bobbie
8 months ago
Wait, does this actually work? I thought there were ways around it.
upvoted 0 times
...
Cyndy
8 months ago
Agreed, this is a solid approach for security!
upvoted 0 times
...
Verona
8 months ago
Sounds good, but can it really stop all privileged pods?
upvoted 0 times
...
Merilyn
8 months ago
Just created a PodSecurityPolicy to block privileged pods!
upvoted 0 times
...
Laila
8 months ago
I feel like I’ve seen a question like this before, but I’m not sure if I remember the steps in the right order. I hope I can piece it together during the exam.
upvoted 0 times
...
Yaeko
8 months ago
I’m a bit confused about how to check if the configuration is working. Do we just try to create a privileged pod and see if it fails?
upvoted 0 times
...
Annita
8 months ago
I think we did a similar question where we had to bind a ClusterRole to a ServiceAccount. I hope I can recall the correct commands during the exam.
upvoted 0 times
...
Remedios
8 months ago
I remember we practiced creating a PodSecurityPolicy, but I’m not entirely sure about the exact syntax for the YAML file.
upvoted 0 times
...
Barbra
9 months ago
Hmm, this is a tricky one. I'm not sure if Knowledge Catalog or Watson Explorer might also be able to do this. I'll have to think it through carefully.
upvoted 0 times
...
Alishia
9 months ago
Hmm, I'm a bit unsure about the differences between Fibre Channel and Gigabit Ethernet cables. I'll need to review that part carefully.
upvoted 0 times
...
Anisha
9 months ago
Okay, I'm pretty sure the correct answers are Initiation and Continuous Monitoring. Those seem to be the key phases based on what I've learned.
upvoted 0 times
...
Simona
9 months ago
Overstating the production plan seems risky; I don't think that's how we should solve this issue based on what we studied.
upvoted 0 times
...

Save Cancel