| name | cloud-container-defense |
| description | Guide complet de sécurité des conteneurs cloud — EKS, GKE, AKS, image scanning, admission controllers, runtime security, CIS benchmarks, Pod Security Standards, network policies, secrets management |
| category | cybersecurite |
Cloud Container Security — EKS / GKE / AKS
1. Principes Fondamentaux
Container Security Stack
┌──────────────────────────────────────┐
│ Container Image │
│ Scanning (Trivy, Grype, Snyk) │
├──────────────────────────────────────┤
│ Image Registry │
│ Auth, Signing (Cosign, Notary) │
├──────────────────────────────────────┤
│ Admission Control │
│ OPA/Gatekeeper, Kyverno, PSA │
├──────────────────────────────────────┤
│ Runtime Security │
│ Falco, Tracee, Aqua, Sysdig │
├──────────────────────────────────────┤
│ Network Security │
│ Network Policies, Cilium, Calico │
├──────────────────────────────────────┤
│ Cluster Security │
│ RBAC, Secrets, Audit, CIS │
└──────────────────────────────────────┘
2. Image Security
Image Scanning
trivy image --severity CRITICAL,HIGH <image>
trivy image --severity MEDIUM --ignore-unfixed --exit-code 1 <image>
trivy image --format sarif --output report.sarif <image>
grype <image> --only-fixed --fail-on high
clairctl analyze <image>
docker scout quickview <image>
docker scout cves <image> --only-severity critical
snyk container test <image> --severity-threshold=high
Image Hardening
# Multi-stage build
FROM python:3.11-slim AS builder
# build dependencies
FROM python:3.11-slim AS runtime
# Minimal runtime
COPY --from=builder /app /app
RUN groupadd -r appuser && useradd -r -g appuser appuser
USER appuser
ENTRYPOINT ["python", "/app/main.py"]
# Pas de root
# USER 10001:10001 (non-root)
# readOnly: true
# capabilities: drop all, add only needed
Image Signing (Cosign)
cosign generate-key-pair
cosign sign --key cosign.key <registry>/image:tag
cosign verify --key cosign.pub <registry>/image:tag
cosign sign <registry>/image:tag
cosign verify <registry>/image:tag
cosign attest --predicate slsa.json --type slsa.dev/v1 <registry>/image:tag
Registry Security
aws ecr put-image-scanning-configuration --repository <name> --image-scanning-configuration scanOnPush=true
gcloud artifacts repositories list
gcloud artifacts docker images list <location>/<repo>
az acr show --name <registry> --query "policies.quarantinePolicy"
az acr update --name <registry> --anonymous-pull-enabled false
3. Amazon EKS Security
Cluster Creation Hardened
eksctl create cluster --name prod --region us-east-1 --nodegroup-name workers --node-type t3.medium --nodes 3 --node-private-networking
aws eks update-cluster-config --name prod --logging '{"clusterLogging":[{"types":["api","audit","authenticator","controllerManager","scheduler"],"enabled":true}]}'
aws eks create-cluster ... --encryption-config '{"resources":["secrets"],"provider":{"keyArn":"arn:aws:kms:...:key/..."}}'
eksctl create iamserviceaccount --name app-sa --namespace prod --cluster prod --attach-policy-arn arn:aws:iam::...:policy/app-policy
EKS Security Best Practices
aws eks create-pod-identity-association --cluster-name prod --namespace prod --service-account app-sa --role-arn arn:aws:iam::...:role/pod-role
aws elbv2 create-target-group ...
kubectl apply -f https://raw.githubusercontent.com/aws/amazon-vpc-cni-k8s/master/config/master/calico-operator.yaml
eksctl create fargateprofile --cluster prod --namespace prod --name prod-fargate
eksctl create nodegroup --cluster prod --node-type t3.medium --node-ami-family Bottlerocket
4. GKE Security
GKE Cluster Hardening
gcloud container clusters create prod-cluster \
--enable-private-nodes \
--enable-private-endpoint \
--master-ipv4-cidr 172.16.0.0/28 \
--enable-master-authorized-networks \
--master-authorized-networks <ip-range>
gcloud container clusters update prod-cluster --workload-pool=<project>.svc.id.goog
kubectl annotate serviceaccount app-sa --namespace prod iam.gke.io/gcp-service-account=<sa>@<project>.iam.gserviceaccount.com
gcloud container node-pools create shielded-nodes --cluster prod-cluster --shielded-secure-boot --shielded-integrity-monitoring
gcloud container node-pools create confidential --cluster prod-cluster --confidential-nodes
gcloud container clusters create prod-cluster --enable-dataplane-v2
GKE Security Features
gcloud container binauthz policy create --default-admission-rule deny
gcloud container binauthz attestations create --artifact-url <image> --public-key-id <key>
kubectl apply -f iam-policy.yaml
gcloud container node-pools create sandbox --cluster prod-cluster --sandbox type=gvisor
gcloud container clusters create auto --autopilot --region us-central1
5. AKS Security
AKS Cluster Hardening
az aks create --name prod-aks --resource-group <RG> --enable-private-cluster --enable-managed-identity
az aks create --name prod-aks --resource-group <RG> --enable-aad --aad-admin-group-object-ids <admin-group-id>
az aks enable-addons --name prod-aks --resource-group <RG> --addons azure-policy
az aks create --name prod-aks --resource-group <RG> --enable-pod-identity
az aks pod-identity add --name app-identity --namespace prod --cluster prod-aks --identity-resource-id <identity>
AKS Security Features
az aks create --name prod-aks --resource-group <RG> --network-plugin azure --network-policy calico
az aks enable-addons --name prod-aks --resource-group <RG> --addons monitoring
az aks create --name prod-aks --resource-group <RG> --enable-encryption-at-host --enable-keyvault
az aks update --name prod-aks --resource-group <RG> --enable-defender
6. Admission Controllers
OPA/Gatekeeper
kubectl apply -f https://raw.githubusercontent.com/open-policy-agent/gatekeeper/master/deploy/gatekeeper.yaml
cat > deny-privileged-template.yaml << 'EOF'
apiVersion: templates.gatekeeper.sh/v1beta1
kind: ConstraintTemplate
metadata:
name: k8spspprivilegedcontainer
spec:
crd:
spec:
names:
kind: K8sPSPPrivilegedContainer
targets:
- target: admission.k8s.gatekeeper.sh
rego: |
package k8spspprivilegedcontainer
violation[{"msg": msg}] {
container := input.review.object.spec.containers[_]
container.securityContext.privileged
msg := sprintf("Container %v is privileged, not allowed", [container.name])
}
EOF
kubectl apply -f deny-privileged-template.yaml
cat > deny-privileged-constraint.yaml << 'EOF'
apiVersion: constraints.gatekeeper.sh/v1beta1
kind: K8sPSPPrivilegedContainer
metadata:
name: deny-privileged
spec:
match:
kinds:
- apiGroups: [""]
kinds: ["Pod"]
EOF
kubectl apply -f deny-privileged-constraint.yaml
Kyverno
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: deny-latest-tag
spec:
validationFailureAction: enforce
rules:
- name: require-image-tag
match:
resources:
kinds:
- Pod
validate:
message: "Using 'latest' tag is not allowed"
pattern:
spec:
containers:
- image: "!*:latest"
---
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: add-resource-limits
spec:
validationFailureAction: audit
rules:
- name: add-limits
match:
resources:
kinds:
- Pod
mutate:
patchStrategicMerge:
spec:
containers:
Pod Security Standards (PSS)
kubectl label --overwrite ns prod pod-security.kubernetes.io/enforce=baseline
kubectl label --overwrite ns prod pod-security.kubernetes.io/audit=restricted
kubectl label --overwrite ns prod pod-security.kubernetes.io/warn=restricted
7. Runtime Security
Falco
helm install falco falcosecurity/falco --set driver.kind=ebpf
curl -s http://localhost:8765/metrics
falco
Tracee
docker run --name tracee --rm --privileged -v /lib/modules:/lib/modules:ro -v /tmp/tracee:/tmp/tracee aquasec/tracee
Network Security Policies
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: deny-all
namespace: prod
spec:
podSelector: {}
policyTypes:
- Ingress
---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: allow-web-to-app
namespace: prod
spec:
podSelector:
matchLabels:
app: app
ingress:
- from:
- podSelector:
matchLabels:
app: web
ports:
- protocol: TCP
port: 8080
---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: allow-app-to-db
namespace: prod
Cilium — eBPF Networking
helm install cilium cilium/cilium --namespace kube-system \
--set hubble.enabled=true \
--set hubble.relay.enabled=true \
--set hubble.ui.enabled=true
hubble observe --since 5m
hubble observe --pod prod/web-xxxx
cat > cilium-policy.yaml << 'EOF'
apiVersion: cilium.io/v2
kind: CiliumNetworkPolicy
metadata:
name: allow-http-get
namespace: prod
spec:
endpointSelector:
matchLabels:
app: app
ingress:
- fromEndpoints:
- matchLabels:
app: web
toPorts:
- ports:
- port: "8080"
protocol: TCP
rules:
http:
- method: "GET"
path: "/api/v1/.*"
EOF
8. CIS Benchmarks
kube-bench
kubectl apply -f https://raw.githubusercontent.com/aquasecurity/kube-bench/main/job.yaml
kubectl logs job.batch/kube-bench
kubescape
kubescape scan --enable-host-scan --format sarif --output kubescape-report.sarif
kubescape scan framework nsa
kubescape scan framework mitre
9. Secrets Management dans K8s
apiVersion: external-secrets.io/v1beta1
kind: SecretStore
metadata:
name: aws-secret-store
namespace: prod
spec:
provider:
aws:
service: SecretsManager
region: us-east-1
---
apiVersion: external-secrets.io/v1beta1
kind: ExternalSecret
metadata:
name: db-password
namespace: prod
spec:
refreshInterval: "1h"
secretStoreRef:
name: aws-secret-store
kind: SecretStore
target:
name: db-password-secret
data:
- secretKey: password
remoteRef:
key: prod/db/password
10. Container Security Checklist
IMAGES
☐ Images minimales (slim, distroless)
☐ Multi-stage builds
☐ Non-root user
☐ Image scanning (Trivy/Grype) CI intégré
☐ Image signing (Cosign)
☐ Registry avec scanning on push
☐ Aucune image :latest en production
CLUSTER
☐ RBAC — cluster-admin restreint
☐ Service accounts sans automount par défaut
☐ Secrets chiffrés (KMS)
☐ Audit logging activé
☐ CIS benchmark < 50 failures
☐ Network policies appliquées
☐ Pod Security Standards (restricted)
☐ OPA/Kyverno admission policies
RUNTIME
☐ Falco installé et actif
☐ LectureSeccomp profil appliqué
☐ AppArmor/SELinux
☐ Read-only root filesystem
☐ SecurityContext: drop ALL capabilities
☐ Seccomp: RuntimeDefault
RÉSEAU
☐ Network policies — deny-all par défaut
☐ mTLS (service mesh ou Cilium)
☐ Aucun hostNetwork
☐ Aucun hostPort
☐ Egress filtré
☐ NodePort évité (Ingress + LB)
OBSERVABILITÉ
☐ kubescape scan régulier
☐ kube-bench run périodique
☐ Container Insights / Managed Prometheus
☐ Runtime anomaly detection
☐ Audit logs analysés (SIEM)
Ressources