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 6 Question 87 Discussion

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.
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 6 Question 87 Discussion

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

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
Francene
1 month ago
I’d start with creating the PodSecurityPolicy first.
upvoted 0 times
...
Leanora
1 month ago
Yeah, preventing privileged pods is key for security.
upvoted 0 times
...
Aliza
2 months ago
I think the PSP part is crucial.
upvoted 0 times
...
Timothy
2 months ago
Agreed, lots of steps involved.
upvoted 0 times
...
Francene
2 months ago
This question is tricky.
upvoted 0 times
...
Van
2 months ago
This is a solid approach, love the attention to security!
upvoted 0 times
...
Malinda
2 months ago
Nice, but what if we need a privileged pod for a specific task?
upvoted 0 times
...
Nan
3 months ago
Wait, can we really block all privileged pods like this?
upvoted 0 times
...
Vilma
3 months ago
Totally agree, this is a must for security!
upvoted 0 times
...
Quentin
3 months ago
Just created a PodSecurityPolicy to block privileged pods!
upvoted 0 times
...
Goldie
3 months ago
Alright, let's do this! I'm ready to put my Kubernetes skills to the test.
upvoted 0 times
...
Felicitas
3 months ago
Haha, "prevent-privileged-policy" - I wonder if that's a subtle hint that we shouldn't be creating privileged pods in the first place!
upvoted 0 times
...
Rossana
4 months ago
Wait, we need to create a ClusterRole and a ClusterRoleBinding too? This is getting a bit complicated.
upvoted 0 times
...
Doug
4 months ago
Hmm, creating a PodSecurityPolicy and then binding it to a ServiceAccount seems like a lot of work. Is there an easier way to do this?
upvoted 0 times
...
Bronwyn
4 months ago
This looks like a pretty straightforward task. I think I can handle it.
upvoted 0 times
...
Carin
4 months ago
I think the validation step is crucial. If we try to create a privileged pod and it fails, that should confirm our policy is working, right?
upvoted 0 times
...
Candra
5 months ago
I feel a bit confused about the role of the ServiceAccount in this setup. Does it really need to be created in the default namespace, or can it be in any namespace?
upvoted 0 times
...
Pa
5 months ago
I practiced something similar last week, but I can't recall the exact syntax for creating the ClusterRoleBinding. I hope I can remember it during the exam.
upvoted 0 times
...
Mindy
5 months ago
I think I remember that we need to set the `privileged` field to `false` in the PodSecurityPolicy to prevent privileged pods, but I'm not entirely sure about the other required fields.
upvoted 0 times
...
Ernie
5 months ago
I'm feeling pretty confident about this one. I've worked with PodSecurityPolicies before, so I know the general approach. As long as I follow the instructions closely, I think I can get this done without too much trouble.
upvoted 0 times
...
Jesus
5 months ago
This seems like a good opportunity to practice my Kubernetes manifests. I'll try to write out the YAML for each resource ahead of time, then apply them in the correct order. Hopefully that will help me avoid any silly mistakes.
upvoted 0 times
...
Lindsey
5 months ago
Okay, I think I've got a handle on this. The key is to create the PodSecurityPolicy first, then the other resources that reference it. I'll make sure to double-check my work before submitting, just to be safe.
upvoted 0 times
...
Pete
6 months ago
Hmm, I'm a bit confused about the order of the steps here. Do I need to create the PodSecurityPolicy first, or can I start with the ServiceAccount? I'll have to read through the instructions carefully to make sure I don't miss anything.
upvoted 0 times
...
Bulah
6 months ago
This looks like a pretty straightforward task, but I'll need to be careful to follow all the steps precisely. I'll start by creating the PodSecurityPolicy, then the ServiceAccount, ClusterRole, and ClusterRoleBinding.
upvoted 0 times
...

Save Cancel