cks 试题

考试信息 2小时 15-20题目 预约时间同CKA,32小时出成绩 满分不到100分,87分或93分,但67分及格 模拟环境 4套环境 1个控制台 NAT网段192.168.26.0 模拟考题

1.镜像扫描ImagePolicyWebhook

切换集群 kubectl config use-context k8s context A container image scanner is set up on the cluster,but It’s not yet fully integrated into the cluster’s configuration When complete,the container image scanner shall scall scan for and reject the use of vulnerable images. task: You have to complete the entire task on the cluster’s master node,where all services and files have been prepared and placed Glven an incomplete configuration in directory /etc/kubernetes/aa and a functional container image scanner with HTTPS sendpitont http://192.168.26.60:1323/image_policy

  • 1.enable the necessary plugins to create an image policy

  • 2.validate the control configuration and chage it to an implicit deny

  • 3.Edit the configuration to point the provied HTTPS endpoint correctiy

Finally,test if the configurateion is working by trying to deploy the valnerable resource /csk/1/web1.yaml 解题思路 ImagePolicyWebhook

关键字:image_policy,deny
1. 切换集群,查看master,sshmaster
2. ls /etc/kubernetes/xxx
3. vi /etc/kubernetes/xxx/xxx.yaml 更改 true 为 false
vi /etc/kubernetes/xxx/xxx.yaml 中 https的地址
volume需要挂载进去
4. 启用ImagePolicyWebhook和- --admission-control-config-file=
5. systemctl restart kubelet
6.kubectl run pod1 --image=nginx

案例:

  • 修改kubeconf文件的server

  • 修改admission_config.yaml 的defaultAllow为false

  • 配置/etc/kubernetes/manifests/kube-apiserver.yaml 添加ImagePolicyWebhook相关策略

  • 重启api-server,systemctl restart kubelet

  • 验证镜像创建pod失败

  • 修改/etc/kubernetes/admission/admission_config.yaml 策略defaultAllow: true

  • 重新验证镜像创建pod

2. sysdig检测pod

切换集群 kubectl config use-context k8s you may user you brower to open one additonal tab to access sysdig’s documentation ro Falco’s documentaion Task: user runtime detection tools to detect anomalous processes spawning and executing frequently in the sigle container belorging to Pod redis. Tow tools are avaliable to use:

  • sysdig

  • falico

the tools are pre-installed on the cluster’s worker node only;the are not avaliable on the base system or the master node. using the tool of you choice(including any non pre-install tool) analyse the container’s behaviour for at lest 30 seconds,using filers that detect newly spawing and executing processes store an incident file at /opt/2/report,containing the detected incidents one per line in the follwing format:

解题思路 Sysdig User Guide

案例

3. clusterrole

切换集群 kubectl config use-context k8s context A Role bound to a pod’s serviceAccount grants overly permissive permission Complete the following tasks to reduce the set of permissions. task Glven an existing Pod name web-pod running in the namespace monitoring Edit the Roleebound to the Pod’s serviceAccount sa-dev-1 to only allow performing list operations,only on resources of type Endpoints create a new Role named role-2 in the namespaces monitoring which only allows performing update operations,only on resources of type persistentvoumeclaims. create a new Rolebind name role role-2-bindding binding the newly created Roleto the Pod’s serviceAccount

解题思路 RBAC

4. AppArmor

切换集群 kubectl config use-context k8s Context AppArmor is enabled on the cluster’s worker node. An AppArmor profile is prepared, but not enforced yet. You may use your browser to open one additional tab to access theAppArmor documentation. Task On the cluster’s worker node, enforce the prepared AppArmor profile located at /etc/apparmor.d/nginx_apparmor . Edit the prepared manifest file located at /cks/4/pod1.yaml to apply the AppArmor profile. Finally, apply the manifest file and create the pod specified in it

解题思路 apparmor

5. PodSecurityPolicy

切换集群 kubectl config use-context k8s63 context A PodsecurityPolicy shall prevent the create on of privileged Pods in a specific namespace. Task

  • Create a new PodSecurityPolicy named prevent-psp-policy , which prevents the creation of privileged Pods.

  • Create a new ClusterRole named restrict-access-role , which uses the newly created PodSecurityPolicy prevent-psp-policy .

  • Create a new serviceAccount named pspdenial-sa in the existing namespace development .

  • Finally, create a new clusterRoleBinding named dany-access-bind ,which binds the newly created ClusterRole restrict-access-role to the newly created serviceAccount

解题思路 PodSecurityPolicy

6. 网络策略

切换集群 kubectl config use-context k8s create a NetworkPolicy named pod-access to restrict access to Pod products-service running in namespace development . only allow the following Pods to connect to Pod productsservice :

  • Pods in the namespace testing

  • Pods with label environment: staging , in any namespace Make sure to apply the NetworkPolicy. You can find a skelet on manifest file at/cks/6/p1.yaml

解题思路 NetworkPolicy

7. dockerfile检测及yaml文件问题

切换集群 kubectl config use-context k8s Task Analyze and edit the given Dockerfile (based on the ubuntu:16.04 image) /cks/7/Dockerfile fixing two instructions present in the file being prominent security/best-practice issues.

Analyze and edit the given manifest file /cks/7/deployment.yaml fixing two fields present in the file being prominent security/best-practiceissues.

解题思路

案例: Dockerfile

8. pod安全

切换集群 kubectl config use-context k8s context lt is best-practice to design containers to best teless and immutable. Task lnspect Pods running in namespace testing and delete any Pod that is either not stateless or not immutable. use the following strict interpretation of stateless and immutable: Pods being able to store data inside containers must be treated as not stateless. You don’t have to worry whether data is actually stored inside containers or not already. Pods being configured to be privileged in any way must be treated as potentially not stateless and not immutable.

解题思路

9. 创建SA

切换集群 kubectl config use-context k8s context A Pod fails to run because of an incorrectly specified ServiceAcccount. Task create a new ServiceAccount named frontend-sa in the existing namespace qa ,which must not have access to any secrets.lnspect the Pod named frontend running inthe namespace qa . Edit the Pod to use the newly created serviceAccount

解题思路 Configure Service Accounts for Pods

10. trivy检测镜像安全

切换集群 kubectl config use-context k8s Task Use the Trivy open-source container scanner to detect images with severe vulnerabilities used by Pods in the namespace yavin . Look for images with High or Critical severity vulnerabilities,and delete the Pods that use those images. Trivy is pre-installed on the cluster’s master node only; it is not available on the base system or the worker nodes. You’ll have to connect to the cluster’s master node to use Trivy

解题思路

kubectl

11. 创建secret

切换集群 kubectl config use-context k8s Task Retrieve the content of the existing secret named db1-test in the istio-system namespace. store the username field in a file named /cks/11/old-username.txt ,and the password field in a file named /cks/11/old-pass.txt. You must create both files; they don’t existyet. Do not use/modify the created files in!the following steps, create new temporaryfiles if needed. Create a new secret named test-workflow in the istio-system namespace, with the followingcontent:

  • username : thanos

  • password : hahahaha

Finally, create a new Pod that has access to the secret test-workflow via avolume:

  • pod name dev-pod

  • namespace istio-system

  • container name dev-container

  • image nginx:1.9

  • volume name dev-volume

  • mount path /etc/test-secret

解题思路 Secret

12. kube-bench

切换集群 kubectl config use-context k8s65 context ACIS Benchmark tool was run against the kubeadm-created cluster and found multiple issues that must be addressed immediately. Task Fix all issues via configuration and restart theaffected components to ensure the new settings take effect. Fix all of the following violations that were found against the API server:

  • Ensure that the 1.2.7 --authorization-mode FAIL argument is not set to AlwaysAllow

  • Ensure that the 1.2.8 --authorization-mode FAIL argument includes Node

  • Ensure that the 1.2.9 --authorization-mode FAIL argument includes RBAC

  • Ensure that the 1.2.18 --insecure-bind-address FAIL argument is not set

  • Ensure that the 1.2.19 --insecure-port FAIL argument is set to 0

Fix all of the following violations that were found against the kubelet:

  • Ensure that the 4.2.1 anonymous-auth FAIL argument is set to false

  • Ensure that the 4.2.2 --authorization-mode FAIL argument is not set to AlwaysAllow

Use webhook authn/authz

解题思路

4.2.14.2.2修改配置kubelet也可以在/var/lib/kubelet/config.yaml

案例1

案例2

13. gVsior

换集群 kubectl config use-context k8s67 context This cluster uses containerd as CRl runtime. Containerd’s default runtime handler is runc . Containerd has been prepared to support an additional runtime handler ,runsc (gVisor). Task:

Create a RuntimeClass named untrusted using the prepared runtime handler named runsc . Update all Pods in the namespace client to run on gvisor, unless they are already running on anon-default runtime handler. You can find a skeleton manifest file at /cks/13/rc.yaml

解题思路 RuntimeClass

14. 审计

切换集群 kubectl config use-context k8s Task Enable audit logs in the cluster. To do so, enable the log backend, and ensure that:

  • logs are stored at /var/log/kubernetes/audit-logs.txt

  • log files are retained for 5 days at maximum, a number of 10 auditlog files are retained

A basic policy is provided at /etc/kubernetes/logpolicy/sample-policy.yaml . it only specifies what not to log. The base policy is located on the cluster’s master node. Edit and extend the basic policy to log:

  • namespaces changes at RequestResponse level

  • the request body of pods changes in the namespace front-apps

  • configMap and secret changes in all namespaces at the Metadata level

  • Also, add a catch-all rule to log all other requests at the Metadata level. Don’t forget to apply

解题思路 audit

15. 默认网络策略

切换集群 kubectl config use-context k8s context A default-deny NetworkPolicy avoids to accident all y expose a Pod in a namespace that doesn’t have any other NetworkPolicy defined. Task Create a new default-deny NetworkPolicy named denynetwork in the namespace development for all traffic of type Ingress . The new NetworkPolicy must deny all lngress traffic in the namespace development . Apply the newly created default-deny NetworkPolicy to all Pods running in namespace development . You can find a skeleton manifest file

解题思路 NetworkPolicy

16. falco 检测输出日志格式

在这里插入图片描述

最后更新于