0Pricing
Cloud & IT Cert Prep · Lesson

Kubernetes Security: RBAC, Network Policies, and Pod Security

Configure Kubernetes RBAC roles, enforce network policies that restrict pod-to-pod traffic, and apply pod security standards to limit privilege escalation.

Kubernetes Security: RBAC, Network Policies, and Pod Security is a free Cloud & IT Cert Prep lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Cloud & IT Cert Prep learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Kubernetes Attack Surface Overview

Kubernetes orchestrates containerized workloads at scale, but its complexity creates a rich attack surface. Key components that must be secured include: the API Server (the central control plane — compromise here gives control of the entire cluster), etcd (the cluster state database — stores secrets in base64, must be encrypted at rest), kubelet (node agent — unauthenticated kubelet API allows arbitrary pod execution), container runtime (Docker/containerd), and the network fabric connecting all pods. Security+ candidates should understand that Kubernetes misconfigurations are among the most common cloud security findings.

RBAC: Role-Based Access Control in Kubernetes

Kubernetes RBAC (Role-Based Access Control) controls which users, service accounts, and processes can perform which actions on which API resources. The model has four objects: Role (namespaced permissions), ClusterRole (cluster-wide permissions), RoleBinding (grants a Role to a subject within a namespace), and ClusterRoleBinding (grants a ClusterRole to a subject cluster-wide). Every kubectl command translates to an API call checked against RBAC rules. If RBAC is not configured, any authenticated user (or service account) may have administrative access.

# Create a role allowing only pod reads in 'default' namespace
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  name: pod-reader
  namespace: default
rules:
- apiGroups: [''] 
  resources: ['pods']
  verbs: ['get', 'list', 'watch']

Service Accounts and Least Privilege

Every pod in Kubernetes runs under a service account — an identity used for API authentication. By default, pods use the default service account in their namespace, which may have broad permissions. The principle of least privilege requires creating dedicated service accounts for each application with only the permissions it needs. Additionally, setting automountServiceAccountToken: false on pods that do not need API access prevents the service account token from being mounted into the pod filesystem, where a compromised application could use it to make API calls.

# Pod spec: disable service account token auto-mount
apiVersion: v1
kind: Pod
metadata:
  name: myapp
spec:
  serviceAccountName: myapp-sa
  automountServiceAccountToken: false
  containers:
  - name: myapp
    image: myapp:v1.0

Network Policies: Default Deny

By default in Kubernetes, all pods can communicate with all other pods in any namespace. A compromised pod can immediately attempt to reach databases, internal APIs, and other microservices. Kubernetes NetworkPolicy resources define rules that restrict pod-to-pod traffic based on labels, namespaces, and ports. The recommended approach is a 'default deny all' network policy in each namespace, followed by explicit allow rules for required communication paths. Note that NetworkPolicy requires a CNI plugin that supports it (Calico, Cilium, Weave) — vanilla Kubernetes ignores NetworkPolicy without a compatible CNI.

# Default deny all ingress and egress in a namespace
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: default-deny-all
  namespace: production
spec:
  podSelector: {}
  policyTypes:
  - Ingress
  - Egress

Pod Security Standards: Replacing PSP

Pod Security Standards (PSS), introduced in Kubernetes 1.23 and stable in 1.25, replace the deprecated Pod Security Policy (PSP) with three built-in profiles enforced at the namespace level: Privileged (unrestricted, for system components), Baseline (prevents known privilege escalations like privileged containers and host network access), and Restricted (hardened, requires non-root users, drops all capabilities, enforces read-only root filesystems). Namespaces are labeled to enforce a policy level, and pods that violate it are rejected at admission.

# Label namespace to enforce 'restricted' pod security
kubectl label namespace production \
  pod-security.kubernetes.io/enforce=restricted \
  pod-security.kubernetes.io/audit=restricted \
  pod-security.kubernetes.io/warn=restricted

Secrets Management in Kubernetes

Kubernetes Secrets store sensitive data like passwords, tokens, and TLS certificates. By default, Secrets are stored in etcd as base64-encoded values — not encrypted. Anyone who can read etcd or has sufficient RBAC permissions can decode them trivially. Best practices include: enabling encryption at rest for etcd using AES-GCM with a key stored in a KMS (AWS KMS, GCP KMS), integrating with an external secrets manager like HashiCorp Vault or AWS Secrets Manager via the Secrets Store CSI Driver, and restricting Secret access via RBAC so only the service accounts that need them can read them.

# Enable etcd encryption at rest (encryption configuration)
apiVersion: apiserver.config.k8s.io/v1
kind: EncryptionConfiguration
resources:
- resources:
  - secrets
  providers:
  - aescbc:
      keys:
      - name: key1
        secret: <base64-encoded-32-byte-key>

Admission Controllers: Security Gates

Admission controllers are plugins in the Kubernetes API server that intercept API requests after authentication and authorization but before object persistence, allowing them to validate, mutate, or reject requests. Security-relevant admission controllers include: PodSecurity (enforces Pod Security Standards), ImagePolicyWebhook (allows external image signing verification), AlwaysPullImages (forces fresh image pulls to prevent using locally cached malicious images), and OPA/Gatekeeper (Open Policy Agent — the most flexible, allows custom policies expressed in Rego language to enforce any organizational security rule).

Cluster Component Hardening

Hardening the Kubernetes control plane components is critical: the API server should have --anonymous-auth=false to disable unauthenticated access, --audit-log-path configured to capture all API activity, and TLS for all connections. The kubelet should have --authorization-mode=Webhook (not AlwaysAllow) and anonymous authentication disabled. etcd should have TLS peer and client encryption, restricted network access (only reachable by the API server), and encrypted data at rest. The CIS Kubernetes Benchmark provides a comprehensive checklist for all component settings.

# Check kubelet configuration for security issues
kubectl get --raw /api/v1/nodes/nodename/proxy/configz | jq '.kubeletconfig | {anonymousAuth: .authentication.anonymous.enabled, authorization: .authorization.mode}'

Namespace Isolation and Multi-Tenancy

Kubernetes namespaces provide logical separation of resources but are not a strong security boundary by themselves — they primarily provide organizational isolation. For true multi-tenant isolation (e.g., different customers' workloads), additional controls are required: network policies to block cross-namespace traffic, resource quotas to prevent noisy-neighbor DoS, separate node pools for strongly isolated tenants, or dedicated clusters per tenant. Many organizations use Hierarchical Namespaces or commercial solutions like vCluster for stronger multi-tenancy within a single cluster.

Audit Logging and Runtime Monitoring

Kubernetes audit logging records every API request: who made it, from where, what action was requested, and what resource was targeted. Audit logs are essential for forensic investigation after a security incident and for detecting anomalous behavior like unusual role bindings, access to secrets, or exec commands into production pods. Audit logs should be streamed to a centralized SIEM. Falco provides runtime monitoring of container behavior, while cloud-managed Kubernetes services (EKS, GKE, AKS) provide native audit log integration with their respective logging platforms.

# Check recent kubectl exec events in audit log
grep '"verb":"create".*"resource":"pods".*"subresource":"exec"' /var/log/kubernetes/audit.log | tail -20

Supply Chain Security: Image Provenance

Supply chain security for Kubernetes ensures that only trusted, verified images reach production. The CNCF Supply Chain Security recommendations include: verifying image signatures with Cosign before deployment (enforced via admission controllers), generating and verifying SBOMs (Software Bills of Materials) for all container images to track component provenance, pinning images to digests (myimage@sha256:abc123) rather than mutable tags, and scanning all third-party Helm charts for misconfigurations and vulnerabilities before deployment.

# Pin image to digest for immutability
# Instead of:
image: nginx:latest
# Use:
image: nginx@sha256:a3e2a7a3d7f94e...  # immutable digest

Quick Check

Test your understanding of CompTIA Security+ (SY0-701) concepts from this lesson.

Lesson Recap

In this lesson you learned: Kubernetes RBAC controls API access through Roles, ClusterRoles, and Bindings — always apply least privilege to service accounts, NetworkPolicy default-deny configurations prevent lateral movement between pods and namespaces, and Pod Security Standards enforce container hardening at the namespace level, blocking privileged containers, host network access, and root execution. Next up we explore serverless security and function-level attack surfaces.

Frequently asked questions

Is the “Kubernetes Security: RBAC, Network Policies, and Pod Security” lesson free?

Yes — the full text of “Kubernetes Security: RBAC, Network Policies, and Pod Security” is free to read here on the web, and the Cloud & IT Cert Prep course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Cloud & IT Cert Prep course, upgrade to CoddyKit PRO.

What will I learn in “Kubernetes Security: RBAC, Network Policies, and Pod Security”?

Configure Kubernetes RBAC roles, enforce network policies that restrict pod-to-pod traffic, and apply pod security standards to limit privilege escalation. You practise Cloud & IT Cert Prep with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Cloud & IT Cert Prep?

No prior experience is required. Cloud & IT Cert Prep on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Kubernetes Security: RBAC, Network Policies, and Pod Security” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Cloud & IT Cert Prep lesson?

Yes. Every Cloud & IT Cert Prep lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Container Security: Image Hardening and Runtime Protection
  2. Kubernetes Security: RBAC, Network Policies, and Pod Security
  3. Serverless and Function Security
  4. Infrastructure as Code Security Scanning
← Back to Cloud & IT Cert Prep