apiVersion:extensions/v1beta1kind:PodSecurityPolicymetadata:name:restrictedannotations:# Seccomp v1.11 使用 'runtime/default',而 v1.10 及更早版本使用 'docker/default'seccomp.security.alpha.kubernetes.io/allowedProfileNames:'runtime/default'seccomp.security.alpha.kubernetes.io/defaultProfileName:'runtime/default'apparmor.security.beta.kubernetes.io/allowedProfileNames:'runtime/default'apparmor.security.beta.kubernetes.io/defaultProfileName:'runtime/default'spec:privileged:false# Required to prevent escalations to root.allowPrivilegeEscalation:false# This is redundant with non-root + disallow privilege escalation,# but we can provide it for defense in depth.requiredDropCapabilities: - ALL# Allow core volume types.volumes: - 'configMap' - 'emptyDir' - 'projected' - 'secret' - 'downwardAPI'# Assume that persistentVolumes set up by the cluster admin are safe to use. - 'persistentVolumeClaim'hostNetwork:falsehostIPC:falsehostPID:falserunAsUser:# Require the container to run without root privileges.rule:'MustRunAsNonRoot'seLinux:# This policy assumes the nodes are using AppArmor rather than SELinux.rule:'RunAsAny'supplementalGroups:rule:'MustRunAs'ranges:# Forbid adding the root group. - min:1max:65535fsGroup:rule:'MustRunAs'ranges:# Forbid adding the root group. - min:1max:65535readOnlyRootFilesystem:false
$kubectlapply-fhttps://github.com/feiskyer/kubernetes-handbook/raw/master/examples/job-master.yamljob.batch/kube-bench-mastercreated$kubectlapply-fhttps://github.com/feiskyer/kubernetes-handbook/raw/master/examples/job-node.yamljob.batch/kube-bench-nodecreated# Wait for a few seconds for the job to complete$kubectlgetpodsNAMEREADYSTATUSRESTARTSAGEkube-bench-master-k7jdd0/1Completed02m15skube-bench-node-p9sl90/1Completed02m15s# The results are held in the pod's logs$kubectllogskube-bench-master-k7jdd[INFO] 1 Master Node Security Configuration[INFO] 1.1 API Server...
# Install$gogetgithub.com/genuinetools/reg# Vulnerability Reports$regvulns--clairhttps://clair.j3ss.cor.j3ss.co/chrome# Generating Static Website for a Registry$ $ regserver--clairhttps://clair.j3ss.co
trivy
trivy 是 Aqua Security 开源的容器漏洞扫描工具。相对于 Clair 来说,使用起来更为简单,可以更方便集成到 CI 中。
# Installsudoapt-getinstallwgetapt-transport-httpsgnupglsb-releasewget-qO-https://aquasecurity.github.io/trivy-repo/deb/public.key|sudoapt-keyadd-echo deb https://aquasecurity.github.io/trivy-repo/deb $(lsb_release -sc) main | sudo tee -a /etc/apt/sources.list.d/trivy.list
sudoapt-getupdatesudoapt-getinstall-ytrivy# Image Scanningtrivypython:3.4-alpine