tech:notes_kubernetes_k8s_-_securite
Ceci est une ancienne révision du document !
Table des matières
Notes Kubernetes k8s - sécurite
Voir :
- Kube-bench
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
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: 3000Forces the container to use a specific non-root user (UID 1000) and group (GID 3000).fsGroup: 2000Ensures that files created in shared volumes have the correct group ownership.- Container Security Settings:
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
- ServiceAccount
- les RBAC
- mTLS pour les services
- EncryptionConfiguration resource pour les servrets (HashiCorp Vault)
- Sécuriser etcd
- Don't allow pods that run containers with root
- SecurtyPolicy (Open Policy Agent / Kyverno)
Utiliser
- Les NetworkPolicy (par défault tous les noeuds peuvent communiquer avec tous les noeuds Oou ServiceMesh (Side car)
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
Trivy
asdf plugin add trivy asdf install trivy latest asdf set --home trivy latest
tech/notes_kubernetes_k8s_-_securite.1759674273.txt.gz · Dernière modification : de Jean-Baptiste
