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 28 Discussion

You can switch the cluster/configuration context using the following command:[desk@cli] $kubectl config use-context test-accountTask:Enable audit logs in the cluster.To do so, enable the log backend, and ensure that:1. logs are stored at/var/log/Kubernetes/logs.txt2. log files are retained for5days3. at maximum, a number of10old audit log files are retainedA basic policy is provided at/etc/Kubernetes/logpolicy/audit-policy.yaml. It only specifies what not to log.Note: The base policy is located on the cluster's master node.Edit and extend the basic policy to log:1.Nodeschanges atRequestResponselevel2. The request body ofpersistentvolumeschanges in the namespacefrontend3.ConfigMapandSecretchanges in all namespaces at theMetadatalevelAlso, add a catch-all rule to log all other requests at theMetadatalevelNote:Don't forget to apply the modified policy.
A) Explanation: $vim /etc/kubernetes/log-policy/audit-policy.yaml - level: RequestResponse userGroups: ['system:nodes'] - level: Request resources: - group: '' # core API group resources: ['persistentvolumes'] namespaces: ['frontend'] - level: Metadata resources: - group: '' resources: ['configmaps', 'secrets'] - level: Metadata $vim /etc/kubernetes/manifests/kube-apiserver.yaml Add these - --audit-policy-file=/etc/kubernetes/log-policy/audit-policy.yaml - --audit-log-path=/var/log/kubernetes/logs.txt - --audit-log-maxage=5 - --audit-log-maxbackup=10 Explanation [desk@cli] $ssh master1 [master1@cli] $vim /etc/kubernetes/log-policy/audit-policy.yaml apiVersion: audit.k8s.io/v1 # This is required. kind: Policy # Don't generate audit events for all requests in RequestReceived stage. omitStages: - 'RequestReceived' rules: # Don't log watch requests by the 'system:kube-proxy' on endpoints or services - level: None users: ['system:kube-proxy'] verbs: ['watch'] resources: - group: '' # core API group resources: ['endpoints', 'services'] # Don't log authenticated requests to certain non-resource URL paths. - level: None userGroups: ['system:authenticated'] nonResourceURLs: - '/api*' # Wildcard matching. - '/version' # Add your changes below - level: RequestResponse userGroups: ['system:nodes'] # Block for nodes - level: Request resources: - group: '' # core API group resources: ['persistentvolumes'] # Block for persistentvolumes namespaces: ['frontend'] # Block for persistentvolumes of frontend ns - level: Metadata resources: - group: '' # core API group resources: ['configmaps', 'secrets'] # Block for configmaps & secrets - level: Metadata # Block for everything else [master1@cli] $vim /etc/kubernetes/manifests/kube-apiserver.yaml apiVersion: v1 kind: Pod metadata: annotations: kubeadm.kubernetes.io/kube-apiserver.advertise-address.endpoint: 10.0.0.5:6443 labels: component: kube-apiserver tier: control-plane name: kube-apiserver namespace: kube-system spec: containers: - command: - kube-apiserver - --advertise-address=10.0.0.5 - --allow-privileged=true - --authorization-mode=Node,RBAC - --audit-policy-file=/etc/kubernetes/log-policy/audit-policy.yaml #Add this - --audit-log-path=/var/log/kubernetes/logs.txt #Add this - --audit-log-maxage=5 #Add this - --audit-log-maxbackup=10 #Add this ... output truncated Note: log volume & policy volume is already mounted invim /etc/kubernetes/manifests/kube-apiserver.yamlso no need to mount it. Reference:https://kubernetes.io/docs/tasks/debug-application-cluster/audit/ Note: log volume & policy volume is already mounted invim /etc/kubernetes/manifests/kube-apiserver.yamlso no need to mount it. Reference:https://kubernetes.io/docs/tasks/debug-application-cluster/audit/

Linux Foundation CKS Exam - Topic 1 Question 28 Discussion

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

You can switch the cluster/configuration context using the following command:

[desk@cli] $kubectl config use-context test-account

Task:Enable audit logs in the cluster.

To do so, enable the log backend, and ensure that:

1. logs are stored at/var/log/Kubernetes/logs.txt

2. log files are retained for5days

3. at maximum, a number of10old audit log files are retained

A basic policy is provided at/etc/Kubernetes/logpolicy/audit-policy.yaml. It only specifies what not to log.

Note: The base policy is located on the cluster's master node.

Edit and extend the basic policy to log:

1.Nodeschanges atRequestResponselevel

2. The request body ofpersistentvolumeschanges in the namespacefrontend

3.ConfigMapandSecretchanges in all namespaces at theMetadatalevel

Also, add a catch-all rule to log all other requests at theMetadatalevel

Note:Don't forget to apply the modified policy.

Show Suggested Answer Hide Answer
Suggested Answer: A

Contribute your Thoughts:

0/2000 characters
Ammie
7 months ago
Is it really necessary to log the request body for persistent volumes?
upvoted 0 times
...
Noel
8 months ago
I disagree, 10 old log files is way too few for audit purposes.
upvoted 0 times
...
Charisse
8 months ago
The command to switch context is super handy!
upvoted 0 times
...
James
8 months ago
Wait, are we really keeping logs for 5 days? Seems a bit short.
upvoted 0 times
...
Mitsue
8 months ago
Don't forget to apply the modified policy after editing!
upvoted 0 times
...
Leslee
8 months ago
I feel a bit confused about where to place the audit policy file path in the kube-apiserver configuration. Was it in the command section or somewhere else?
upvoted 0 times
...
Sheridan
8 months ago
I think we had a similar question in our last mock exam about logging changes to resources. I hope I can recall the right levels for each resource.
upvoted 0 times
...
Sylvie
8 months ago
I remember we practiced enabling audit logs, but I'm not entirely sure about the exact syntax for the audit policy rules.
upvoted 0 times
...
Lavonna
9 months ago
I definitely remember that we need to ensure the logs are stored in the correct path, but I can't quite recall the retention settings. Was it 5 days and 10 backups?
upvoted 0 times
...
Lakeesha
9 months ago
I'm a bit confused by the multi-tenant database container (MDO) mode. I'll need to make sure I understand how that affects the backup process before I can confidently select an answer.
upvoted 0 times
...
Jillian
9 months ago
Hmm, I'm a bit confused. Do I need to create a dynamic distribution list or a regular one? And do I share the dashboard from the Power BI service or from Desktop?
upvoted 0 times
...

Save Cancel