Secure a Deployment with Security Context and Capabilities
Scenario
The security team has identified that the joker-deployment in namespace joker needs hardening. The deployment is currently running with default security settings, which pose potential security risks.
The manifest file for the existing Deployment can be found at /home/laborant/joker-deployment.yaml.
Task
Modify the existing Deployment named joker-deployment running in namespace joker so that its containers:
- Run with user ID
3000 - Privilege escalation is forbidden
- Add the following Linux capabilities:
NET_BIND_SERVICENET_RAWNET_ADMIN
- Check the logs of the deployment to verify it shows user ID
3000.
Modify the YAML file at /home/laborant/joker-deployment.yaml and apply the changes.
Hint
- All security settings must be configured at the container level under
spec.template.spec.containers[0].securityContext - Use
runAsUserto set the user ID - Use
allowPrivilegeEscalationto control privilege escalation - Use
capabilities.addto add Linux capabilities as a list - After editing the YAML file, apply it with
kubectl apply -f - Check Kubernetes documentation for securityContext examples if needed