tech:notes_kubernetes_k8s_-_securite
Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentesRévision précédente | |||
| tech:notes_kubernetes_k8s_-_securite [2025/11/06 11:33] – Jean-Baptiste | tech:notes_kubernetes_k8s_-_securite [2026/02/24 14:44] (Version actuelle) – Jean-Baptiste | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| + | < | ||
| + | {{tag> | ||
| + | |||
| + | # Notes Kubernetes k8s - sécurite | ||
| + | |||
| + | Voir : | ||
| + | * [[Scan de vulnérabilité pour les images de conteneurs]] | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * Kube-bench | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | |||
| + | Containers ! | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | ## Ensure Containers Do Not Run As Root | ||
| + | |||
| + | Source : https:// | ||
| + | |||
| + | ~~~yaml | ||
| + | apiVersion: v1 | ||
| + | kind: Pod | ||
| + | metadata: | ||
| + | name: security-context-demo | ||
| + | spec: | ||
| + | | ||
| + | | ||
| + | | ||
| + | ~~~ | ||
| + | |||
| + | ~~~yaml | ||
| + | apiVersion: v1 | ||
| + | kind: Pod | ||
| + | metadata: | ||
| + | name: security-context-demo | ||
| + | spec: | ||
| + | | ||
| + | - name: busybox | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | # allowPrivilegeEscalation: | ||
| + | # privileged: false | ||
| + | ~~~ | ||
| + | |||
| + | If there are no non-root users in the Docker image, you may also need to create one in the Dockerfile, with: | ||
| + | |||
| + | ~~~bash | ||
| + | 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 ? | ||
| + | |||
| + | ~~~yaml | ||
| + | spec: | ||
| + | hostPID: true | ||
| + | hostIPC: true | ||
| + | hostNetwork: | ||
| + | volumes: | ||
| + | - name: host-filesystem | ||
| + | hostPath: | ||
| + | path: / | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | ### Autres | ||
| + | |||
| + | Source : https:// | ||
| + | |||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * Container Security Settings: '' | ||
| + | |||
| + | |||
| + | |||
| + | spec! | ||
| + | runAsUser: 0 | ||
| + | | ||
| + | securityContext: | ||
| + | allowPrivilegeEscalation: | ||
| + | |||
| + | |||
| + | 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) | ||
| + | |||
| + | |||
| + | ## Outils analyse sécu | ||
| + | |||
| + | Voir : | ||
| + | * m9sweeper | ||
| + | |||
| + | |||
| + | ### Kube bench | ||
| + | |||
| + | Step 1: Download the official job manifest | ||
| + | |||
| + | Clone the kube-bench repo or grab job.yaml from the GitHub releases page. | ||
| + | ~~~bash | ||
| + | git clone https:// | ||
| + | cd kube-bench | ||
| + | |||
| + | # ou | ||
| + | kubectl apply -f https:// | ||
| + | ~~~ | ||
| + | |||
| + | Step 2: Apply the job to your cluster | ||
| + | ~~~bash | ||
| + | kubectl apply -f job.yaml | ||
| + | ~~~ | ||
| + | |||
| + | Step 3: Watch the pod until it shows as Completed | ||
| + | ~~~bash | ||
| + | kubectl get pods -w | ||
| + | ~~~ | ||
| + | |||
| + | Step 4: Review the results | ||
| + | ~~~bash | ||
| + | #kubectl logs -l job-name=kube-bench | ||
| + | kubectl logs pod/ | ||
| + | ~~~ | ||
| + | |||
| + | ~~~bash | ||
| + | podman run --pid=host -v / | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | ### kubescape | ||
| + | |||
| + | Voir : | ||
| + | * https:// | ||
| + | |||
| + | Install | ||
| + | ~~~bash | ||
| + | kubectl krew update | ||
| + | kubectl krew install kubescape | ||
| + | ~~~ | ||
| + | |||
| + | Scan | ||
| + | ~~~bash | ||
| + | kubectl kubescape scan | ||
| + | kubescape scan --format html --output results.html | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | Voir Trivy [[Scan de vulnérabilité pour les images de conteneurs]] | ||
| + | |||
| + | |||
| + | |||
| + | |||
