Dit deel is nog niet vertaald. Je ziet de Engelse tekst.
$ als gewone gebruiker# als root (of met sudo)
Vaardigheden in dit hoofdstuk
- Minimale images, SBOM, scannen, ondertekenen en toegestane registries
Use minimal base images
Fewer packages = fewer vulnerabilities and fewer tools for an attacker.
Make and use an SBOM
A Software Bill of Materials lists every component of an image. With it, a new CVE is matched to your images in minutes.
Scan images
Scan in CI (block bad builds) and in the cluster (find old images with new CVEs).
trivy image --severity CRITICAL --exit-code 1 ghcr.io/s0sta/api:2.0
trivy k8s --report summary cluster
kubectl get pods -A -o jsonpath='{range .items[*]}{.spec.containers[*].image}{"\n"}{end}' | sort -uExamentip
A task like "find pods with images that have CRITICAL vulnerabilities and delete them": list the images, scan each with trivy image -s CRITICAL, delete the matching pods.
Sign and verify images
Sign images in CI with cosign; let an admission policy accept only signed images.
cosign sign --key cosign.key ghcr.io/s0sta/api@sha256:DIGEST
cosign verify --key cosign.pub ghcr.io/s0sta/api@sha256:DIGESTapiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata: { name: verify-signature }
spec:
validationFailureAction: Enforce
rules:
- name: check-signature
match: { any: [{ resources: { kinds: [Pod] } }] }
verifyImages:
- imageReferences: ["ghcr.io/s0sta/*"]
attestors:
- entries:
- keys:
publicKeys: |-
-----BEGIN PUBLIC KEY-----
...
-----END PUBLIC KEY-----Allow only trusted registries
Block images from unknown registries — with Gatekeeper (allowed repos), Kyverno, or the ImagePolicyWebhook admission plugin.
apiVersion: apiserver.config.k8s.io/v1
kind: AdmissionConfiguration
plugins:
- name: ImagePolicyWebhook
configuration:
imagePolicy:
kubeConfigFile: /etc/kubernetes/admission/kubeconfig.yaml
allowTTL: 50
denyTTL: 50
retryBackoff: 500
defaultAllow: falseIn the API server manifest: --enable-admission-plugins=NodeRestriction,ImagePolicyWebhook and --admission-control-config-file=/etc/kubernetes/admission/admission-config.yaml (plus the volume mount).
Onthoud
defaultAllow: false = when the webhook can not be reached, pods are denied (fail closed).
Analyse manifests statically
Find risky settings in YAML before it is applied.
kubesec scan deployment.yaml
kube-linter lint ./manifests
trivy config ./manifests
checkov -d ./manifests --framework kubernetesTypical findings: running as root, no resource limits, privileged: true, latest tags, writable root file system, host namespaces.