Voir :
Containers !
Source : https://www.fairwinds.com/blog/kubernetes-basics-tutorial-ensure-containers-do-not-run-as-root
apiVersion: v1 kind: Pod metadata: name: security-context-demo spec: securityContext: runAsNonRoot: true runAsUser: 1000
apiVersion: v1 kind: Pod metadata: name: security-context-demo spec: containers: - name: busybox image: busybox securityContext: runAsNonRoot: true runAsUser: 1000 # allowPrivilegeEscalation: false # privileged: false
If there are no non-root users in the Docker image, you may also need to create one in the Dockerfile, with:
RUN useradd nonroot -u 1000 --user-group # useradd is a low level utility for adding users. On Debian, administrators should usually use adduser(8) instead.
Comment ?
spec: hostPID: true hostIPC: true hostNetwork: true volumes: - name: host-filesystem hostPath: path: /
runAsNonRoot: true : Ensures that the container does not run as root. If the image’s default user is root, Kubernetes will refuse to start the pod.runAsUser: 1000 & runAsGroup: 3000 Forces the container to use a specific non-root user (UID 1000) and group (GID 3000).fsGroup: 2000 Ensures that files created in shared volumes have the correct group ownership.Setting privileged: false, allowPrivilegeEscalation: false, and dropping all capabilities dramatically limits what processes within the container can do.spec! runAsUser: 0
securityContext: allowPrivilegeEscalation: true
Utiliser
Utiliser
Voir :
Step 1: Download the official job manifest
Clone the kube-bench repo or grab job.yaml from the GitHub releases page.
git clone https://github.com/aquasecurity/kube-bench.git cd kube-bench # ou kubectl apply -f https://raw.githubusercontent.com/aquasecurity/kube-bench/main/job.yaml
Step 2: Apply the job to your cluster
kubectl apply -f job.yaml
Step 3: Watch the pod until it shows as Completed
kubectl get pods -w
Step 4: Review the results
#kubectl logs -l job-name=kube-bench kubectl logs pod/kube-bench-6zgst
podman run --pid=host -v /etc:/etc:ro -v /var:/var:ro -v $(which kubectl):/usr/local/mount-from-host/bin/kubectl -v ~/.kube:/.kube -e KUBECONFIG=/.kube/config -t docker.io/aquasec/kube-bench:latest run
Voir :
Install
kubectl krew update
kubectl krew install kubescape
Scan
kubectl kubescape scan kubescape scan --format html --output results.html
Voir Trivy Scan de vulnérabilité pour les images de conteneurs