CKS · Question #51
Context You must fully integrate a container image scanner into the kubeadm provisioned cluster. Task Given an incomplete configuration located at /etc/kubernetes/bouncer and a functional container im
To integrate the image scanner, the candidate must modify the provided ValidatingWebhookConfiguration file to set the failurePolicy to Deny and the clientConfig.url to the scanner's endpoint, then apply this configuration, and finally test it by deploying a vulnerable resource.
Question
Explanation
To integrate the image scanner, the candidate must modify the provided ValidatingWebhookConfiguration file to set the failurePolicy to Deny and the clientConfig.url to the scanner's endpoint, then apply this configuration, and finally test it by deploying a vulnerable resource.
Approach. The core task is to implement a validating admission controller for image scanning. In modern Kubernetes, this is achieved using a ValidatingWebhookConfiguration resource. Although the question uses the term 'ImagePolicyWebhook configuration' and mentions 'AdmissionConfiguration', the requirements for failurePolicy: Deny and a specific URL for the backend align perfectly with the structure of a ValidatingWebhookConfiguration.
Here's the detailed approach:
- Connect to the Master Node: SSH into the master node:
ssh kssh00301-master. This is necessary for potentially modifying thekube-apiservermanifest and for havingkubectlaccess. - Ensure
kubectlcontext: Verify or set thekubectlcontext using the provided command:kubectl config use-context KSSH00301. - Verify/Enable
ValidatingAdmissionWebhookPlugin: Review thekube-apiserverstatic pod manifest located at/etc/kubernetes/manifests/kube-apiserver.yaml. Ensure thatValidatingAdmissionWebhookis included in the--enable-admission-pluginslist. Forkubeadmprovisioned clusters, this plugin is typically enabled by default. No modification to--admission-control-config-fileshould be made for aValidatingWebhookConfigurationresource, as these are applied dynamically viakubectl. - Edit the Webhook Configuration File: Open and edit the incomplete configuration file:
sudo vi /etc/kubernetes/bouncer. This file is expected to contain aValidatingWebhookConfigurationmanifest.- Locate the
webhooksarray within the configuration. - For the relevant webhook entry (usually the one designed for image policy), set the
failurePolicyfield toDeny.failurePolicy: Deny - Within the same webhook entry, locate or add the
clientConfigsection and set theurlto the image scanner's endpoint.clientConfig: url: https://smooth-yak.local/review # In a real-world scenario, a 'caBundle' (base64 encoded CA certificate) would also be required here # to establish trust for the HTTPS connection. Since it's not mentioned as incomplete, we focus on the explicit requirements. - Ensure other required fields like
rules,sideEffects, andadmissionReviewVersionsare correctly defined within the webhook entry.
- Locate the
- Apply the Webhook Configuration: Save the changes to
/etc/kubernetes/bouncer. Then, apply thisValidatingWebhookConfigurationresource to the cluster:kubectl apply -f /etc/kubernetes/bouncerThis registers the webhook with the Kubernetes API server. - Test the Configuration: Deploy the provided test resource:
kubectl apply -f /home/candidate/vulnerable.yaml. The expected outcome is that the pod creation will be denied by the admission controller. - Verify Scanner Logs (Optional but good practice): If possible, check the scanner's log file (
/var/log/nginx/access_logon thesmooth-yak.localhost) to confirm that the webhook request was received by the scanner.
Common mistakes.
- common_mistake. A common mistake is misinterpreting the phrasing 'AdmissionConfiguration' and 'ImagePolicyWebhook configuration' as referring to the legacy
ImagePolicyWebhookplugin and its associatedImagePolicyConfigurationobject, or trying to pass the/etc/kubernetes/bouncerfile via thekube-apiserver's--admission-control-config-fileflag. If/etc/kubernetes/bounceris indeed aValidatingWebhookConfigurationresource (which is implied by the explicit need forfailurePolicyandclientConfig.url), then applying it viakubectl applyis the correct method, not via a static API server flag. Attempting to forcefailurePolicyinto a legacyImagePolicyConfiguration(which usesallowUnauthenticatedfor similar behavior) or an incorrect file format will result in errors. Other mistakes include syntax errors in the YAML file, providing an incorrect URL for the scanner, settingfailurePolicytoIgnore(which would allow images even if the scanner backend fails), or forgetting to apply theValidatingWebhookConfigurationwithkubectl applyafter editing.
Concept tested. The core technical concept being tested is the implementation and configuration of Kubernetes Validating Admission Webhooks. This includes understanding the ValidatingWebhookConfiguration resource, its key fields (failurePolicy, clientConfig.url), how to modify and apply such configurations, and the role of the ValidatingAdmissionWebhook plugin in the Kubernetes API server. It also implicitly tests knowledge of kube-apiserver static pod manifests and kubectl commands.
Topics
Community Discussion
No community discussion yet for this question.