Kubernetes security hardening using CIS Benchmarks: the industry standard for securing Kubernetes clusters. This guide covers control plane hardening, worker node security, network policies, RBAC, and audit logging with practical kubectl commands and configurations.
Why CIS Benchmarks for Kubernetes
The Center for Internet Security (CIS) Kubernetes Benchmark is the de facto standard for Kubernetes security. It provides specific, actionable recommendations for securing cluster components across major distributions (EKS, GKE, AKS, self-managed).
CIS Benchmarks are organized by Kubernetes version and cover:
- Control Plane Components: API Server, Controller Manager, Scheduler, etcd
- Worker Nodes: Kubelet, Kube Proxy, Container Runtime
- Policies: RBAC, Network Policies, Pod Security Standards
- Managed Services: EKS, GKE, AKS specific controls
Prerequisites
- Kubernetes cluster (v1.28+ recommended)
- kubectl access with cluster-admin or sufficient RBAC
kube-benchtool installed for automated checks
Step 1: Run kube-bench for Baseline Assessment
Install and run kube-bench to see your current compliance:
# On a worker node or as a DaemonSet
curl -L https://github.com/aquasecurity/kube-bench/releases/download/v0.6.15/kube-bench_0.6.15_linux_amd64.tar.gz | tar xz
sudo ./kube-bench --version 1.28
# Or run as a Job in the cluster
kubectl apply -f https://raw.githubusercontent.com/aquasecurity/kube-bench/main/job.yaml
kubectl logs job/kube-bench
Review the output for FAIL and WARN items. Target: 100% PASS for Level 1 controls.
Step 2: Control Plane Hardening (Master Nodes)
API Server (Most Critical)
| CIS ID | Control | Configuration |
|---|---|---|
| 1.1.1 | API Server: –anonymous-auth=false | Disable anonymous access |
| 1.1.2 | API Server: –basic-auth-file not set | Do not use basic auth |
| 1.1.3 | API Server: –token-auth-file not set | Do not use static token file |
| 1.1.4 | API Server: –kubelet-https=true | Use HTTPS to kubelet |
| 1.1.5 | API Server: –kubelet-client-certificate/key set | Client cert for kubelet |
| 1.1.6 | API Server: –kubelet-certificate-authority set | Verify kubelet certs |
| 1.1.7 | API Server: –authorization-mode=Node,RBAC | Enable RBAC + Node authorizer |
| 1.1.8 | API Server: –audit-log-path set | Enable audit logging |
| 1.1.9 | API Server: –audit-log-maxage=30 | Retain audit logs 30 days |
| 1.1.10 | API Server: –audit-log-maxbackup=10 | Keep 10 audit log files |
| 1.1.11 | API Server: –audit-log-maxsize=100 | Max 100MB per audit log |
| 1.1.12 | API Server: –request-timeout=300s | Timeout long requests |
| 1.1.13 | API Server: –service-account-lookup=true | Validate service account tokens |
| 1.1.14 | API Server: –service-account-key-file set | Separate key for service accounts |
| 1.1.15 | API Server: –etcd-certfile/key set | Mutual TLS with etcd |
| 1.1.16 | API Server: –etcd-cafile set | Verify etcd certificates |
| 1.1.17 | API Server: –encryption-provider-config set | Encrypt secrets at rest |
| 1.1.18 | API Server: –enable-admission-plugins=NodeRestriction,PodSecurityPolicy | Enable critical admission plugins |
| 1.1.19 | API Server: –disable-admission-plugins not set to include NodeRestriction | Do not disable NodeRestriction |
| 1.1.20 | API Server: –secure-port=6443 | Use secure port |
| 1.1.21 | API Server: –profiling=false | Disable profiling |
| 1.1.22 | API Server: –repair-malformed-updates=false | Reject malformed updates |
Controller Manager
| CIS ID | Control | Configuration |
|---|---|---|
| 1.2.1 | –profiling=false | Disable profiling |
| 1.2.2 | –use-service-account-credentials=true | Use individual SA credentials |
| 1.2.3 | –root-ca-file set | Verify kubelet certs |
| 1.2.4 | –rotate-kubelet-server-certificate=true | Auto-rotate kubelet certs |
| 1.2.5 | –bind-address=127.0.0.1 | Bind to localhost only |
Scheduler
| CIS ID | Control | Configuration |
|---|---|---|
| 1.3.1 | –profiling=false | Disable profiling |
| 1.3.2 | –bind-address=127.0.0.1 | Bind to localhost only |
etcd
| CIS ID | Control | Configuration |
|---|---|---|
| 1.4.1 | –cert-file/–key-file set | TLS certificates |
| 1.4.2 | –client-cert-auth=true | Require client certs |
| 1.4.3 | –auto-tls=false | Do not use auto TLS |
| 1.4.4 | –peer-cert-file/–peer-key-file set | Peer TLS certificates |
| 1.4.5 | –peer-client-cert-auth=true | Peer client cert auth |
| 1.4.6 | –peer-auto-tls=false | Do not use peer auto TLS |
Step 3: Worker Node Hardening
Kubelet
| CIS ID | Control | Configuration |
|---|---|---|
| 2.1.1 | –anonymous-auth=false | Disable anonymous access |
| 2.1.2 | –authorization-mode=Webhook | Use webhook auth |
| 2.1.3 | –client-ca-file set | Verify client certs |
| 2.1.4 | –read-only-port=0 | Disable read-only port |
| 2.1.5 | –streaming-connection-idle-timeout=5m | Timeout idle streams |
| 2.1.6 | –protect-kernel-defaults=true | Protect kernel defaults |
| 2.1.7 | –make-iptables-util-chains=true | Use iptables utility chains |
| 2.1.8 | –hostname-override not set | Do not override hostname |
| 2.1.9 | –event-qps=0 or appropriate | Limit event rate |
| 2.1.10 | –tls-cert-file/–tls-private-key-file set | TLS for kubelet |
| 2.1.11 | –rotate-certificates=true | Auto-rotate certs |
| 2.1.12 | –rotate-kubelet-server-certificate=true | Rotate server cert |
Container Runtime (containerd/CRI-O)
Ensure runtime is configured securely:
# /etc/containerd/config.toml
[plugins."io.containerd.grpc.v1.cri".containerd]
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc]
runtime_type = "io.containerd.runc.v2"
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc.options]
SystemdCgroup = true
Step 4: RBAC and Pod Security
RBAC Best Practices
# Restrict cluster-admin bindings
# Audit existing cluster-admin bindings
kubectl get clusterrolebindings -o custom-columns=NAME:.metadata.name,ROLE:.roleRef.name,SUBJECTS:.subjects[*].name
# Create least-privilege roles for teams
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
namespace: production
name: developer
rules:
- apiGroups: [""]
resources: ["pods", "services", "configmaps"]
verbs: ["get", "list", "watch"]
- apiGroups: ["apps"]
resources: ["deployments"]
verbs: ["get", "list", "watch"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: developer-binding
namespace: production
subjects:
- kind: User
name: jane
apiGroup: rbac.authorization.k8s.io
roleRef:
kind: Role
name: developer
apiGroup: rbac.authorization.k8s.io
Pod Security Standards (Replaces PSP)
# Apply Restricted profile to namespaces
apiVersion: v1
kind: Namespace
metadata:
name: production
labels:
pod-security.kubernetes.io/enforce: restricted
pod-security.kubernetes.io/audit: restricted
pod-security.kubernetes.io/warn: restricted
Restricted profile enforces:
- No privilege escalation
- No host namespace access
- Run as non-root
- Drop ALL capabilities
- Read-only root filesystem
- seccomp profile
Step 5: Network Policies
Default deny all, then allow specific traffic:
# Default deny ingress
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: default-deny-ingress
namespace: production
spec:
podSelector: {}
policyTypes:
- Ingress
---
# Allow ingress from specific namespace
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: allow-frontend-to-backend
namespace: production
spec:
podSelector:
matchLabels:
app: backend
policyTypes:
- Ingress
ingress:
- from:
- namespaceSelector:
matchLabels:
name: frontend
ports:
- protocol: TCP
port: 8080
Step 6: Audit Logging
Configure audit policy for the API Server:
# audit-policy.yaml
apiVersion: audit.k8s.io/v1
kind: Policy
rules:
- level: Metadata
namespaces: ["kube-system"]
- level: RequestResponse
resources:
- group: ""
resources: ["secrets"]
- group: "rbac.authorization.k8s.io"
resources: ["*"]
- level: Request
resources:
- group: ""
resources: ["pods"]
verbs: ["create", "update", "delete"]
- level: Metadata
omitStages:
- RequestReceived
Mount and configure in API Server:
# API Server args
--audit-policy-file=/etc/kubernetes/audit-policy.yaml
--audit-log-path=/var/log/kubernetes/audit.log
--audit-log-maxage=30
--audit-log-maxbackup=10
--audit-log-maxsize=100
Step 7: Secrets Encryption at Rest
Create encryption configuration:
# encryption-config.yaml
apiVersion: apiserver.config.k8s.io/v1
kind: EncryptionConfiguration
resources:
- resources:
- secrets
providers:
- aescbc:
keys:
- name: key1
secret:
- identity: {}
Add to API Server:
--encryption-provider-config=/etc/kubernetes/encryption-config.yaml
Step 8: Automated Compliance with kube-bench
Schedule regular kube-bench runs:
# kube-bench-cronjob.yaml
apiVersion: batch/v1
kind: CronJob
metadata:
name: kube-bench
namespace: kube-system
spec:
schedule: "0 2 * * *" # Daily at 2 AM
jobTemplate:
spec:
template:
spec:
serviceAccountName: kube-bench
containers:
- name: kube-bench
image: aquasec/kube-bench:latest
command: ["kube-bench", "--version", "1.28", "--json"]
volumeMounts:
- name: etc-kubernetes
mountPath: /etc/kubernetes
readOnly: true
volumes:
- name: etc-kubernetes
hostPath:
path: /etc/kubernetes
restartPolicy: Never
Managed Kubernetes (EKS/GKE/AKS) Specifics
| Platform | CIS Benchmark | Notes |
|---|---|---|
| EKS | EKS-specific controls in CIS | Control plane managed; focus on worker nodes, IAM, VPC |
| GKE | GKE-specific controls | Autopilot handles most controls; Standard needs node pool config |
| AKS | AKS-specific controls | Control plane managed; focus on node pools, Azure Policy |
Verification Checklist
- [ ] Run
kube-bench– all Level 1 controls PASS - [ ] Verify audit logs in
/var/log/kubernetes/audit.log - [ ] Test RBAC with
kubectl auth can-ias different users - [ ] Verify Network Policies block unauthorized traffic
- [ ] Confirm secrets encryption with
kubectl get secrets -o jsonpath=... | jq - [ ] Scan container images with
trivyorgrype
Related Reading
For Linux host hardening that complements Kubernetes security, see systemd Service Hardening: A Directive Reference. For container isolation fundamentals, see Linux Namespace & Cgroup Internals: Container Isolation Deep Dive.