Table des matières

, ,

Notes Kubernetes k8s - sécurite

Voir :

Containers !

Ensure Containers Do Not Run As Root

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.

Interdire le host namespace

Comment ?

spec:
  hostPID: true
  hostIPC: true
  hostNetwork: true
  volumes:
    - name: host-filesystem
      hostPath:
        path: /

Autres

Source : https://medium.com/@mughal.asim/kubernetes-security-contexts-series-part-3-running-containers-as-non-root-0b7ebd54636c

spec! runAsUser: 0

securityContext: allowPrivilegeEscalation: true

Utiliser

Utiliser

Outils analyse sécu

Voir :

Kube bench

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 

kubescape

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