Courseiva
CKSChapter 1 of 15Objective 1.1

Kubernetes Security Fundamentals

Kubernetes security is the set of rules and tools that control who can access your applications and what they are allowed to do once inside. Without these controls, anyone with a network connection could tamper with your software, steal customer data, or crash your entire system. For the CKS exam, you must understand how this security model works because the exam tests whether you can lock down a real cluster, not just memorise definitions.

12 min read
Beginner
Updated Jul 23, 2026
Editorial oversight: Johnson Ajibi· Security Systems Architect · MSc IT Security · IEEE Senior Member

A simple way to picture Kubernetes Security Fundamentals

The Warehouse Security Model Analogy

A warehouse runs a busy shipping operation. The warehouse itself is a cluster. Each shipping container is a pod, and each box inside is a container. The warehouse has a security guard at the gate who checks every delivery driver's ID against a list before they can enter the yard. This is authentication. Once inside, a driver can only go to the loading bay assigned to them on their permit. They cannot wander into the freezer section or the office. This is authorisation. The permit lists exactly what actions the driver can perform: drop off pallets, pick up returns, but never open sealed containers. This is role-based access control, or RBAC. The warehouse manager did not want to hire a new guard every time a new supplier arrived, so they use a central pass system—Microsoft Entra ID—that lets any driver with a valid company badge and a pre-approved purpose enter. They do not need to memorise a new password for every warehouse. The guard does not need to know every driver's face. The system trusts the badge, and the permit controls the behaviour. The whole operation depends on the guard never skipping the check, and the manager regularly reviewing which permits are active.

The warehouse owner also secures each container with a tamper-proof seal. If a seal is broken, the container is quarantined. This mirrors how Kubernetes uses secrets and network policies to protect data inside pods. The manager knows that a single unlocked door could let a thief steal expensive stock, so they enforce that every container—every pod—has a purpose and a limit. The warehouse has cameras watching every aisle, logging every movement. That is the audit log. The manager reviews the logs weekly to spot suspicious patterns, like a driver visiting the same bay three times in one day without a valid reason. The entire security model is built on three pillars: who you are (authentication), what you are allowed to do (authorisation), and what is happening right now (auditing). If any pillar fails, the warehouse is vulnerable.

How It Actually Works

Kubernetes is an open-source system for running and managing containerised applications. A container is a lightweight, standalone package that contains everything needed to run a piece of software: code, runtime, system tools, and libraries. Think of a container as a single shipping container on a cargo ship. Kubernetes is the port that organises thousands of those containers so they can be loaded, unloaded, and moved efficiently.

Before containers, companies ran applications directly on servers. If one application crashed, it could take down the whole server. Containers isolate each application so that a crash in one does not affect the others. But with many containers spread across many servers, you need a way to control who and what interacts with each container. That control is the Kubernetes security model.

The security model has three main layers: authentication, authorisation, and admission control. Authentication means verifying who a user or machine is. The user might be a human administrator logging in with a password or a robot process running inside another application. Kubernetes does not store passwords itself. Instead, it trusts an external identity provider, such as Microsoft Entra ID or a certificate file. When you type a command like 'kubectl get pods', your tool sends a certificate or token to the Kubernetes API server. The API server checks that certificate against a trusted certificate authority. If it matches, you are authenticated.

Authorisation happens next. Even if the system knows who you are, you cannot do everything. Authorisation decides what actions you are allowed to perform. Kubernetes uses a system called RBAC, role-based access control. An RBAC policy is a set of rules that link a user (or a group of users) to a role. The role defines which API operations they can perform, such as 'create pods', 'delete services', or 'list secrets'. For example, a developer might have a role that allows them to view logs but not delete nodes. An administrator might have a role that allows them to create namespaces. RBAC is the most common authorisation method, and the CKS exam expects you to write and debug RBAC configuration files.

Admission control is the third layer. An admission controller is a piece of software that intercepts requests to the API server after authentication and authorisation have succeeded, but before the request is saved to the database. It can modify or reject the request. For instance, a built-in admission controller called 'NamespaceLifecycle' ensures that you cannot create a pod in a namespace that does not exist. Another called 'AlwaysPullImages' forces every pod to pull its container image from a registry, preventing a pod from using a stale local copy that might contain malware. The CKS exam frequently tests your ability to configure and enable admission controllers.

Beyond these three layers, there is network security. Kubernetes runs in a flat network by default, meaning any pod can talk to any other pod unless you restrict traffic. A network policy is a firewall rule that controls which pods can communicate. For example, you can create a network policy that allows only a frontend pod to talk to a database pod, blocking all other traffic. The CKS exam tests your ability to write network policies that enforce zero-trust principles: never trust, always verify.

Finally, there is secrets management. A secret in Kubernetes is an object that stores sensitive data such as passwords, OAuth tokens, and SSH keys. By default, secrets are stored unencrypted in the etcd database. Etcd is the key-value store that holds all cluster data. If an attacker gains access to etcd, they can read every secret. The CKS exam expects you to enable encryption at rest for secrets, rotate encryption keys regularly, and avoid storing secrets in environment variables whenever possible.

All of these components form the Kubernetes security model. The model is not a single product. It is a collection of integrated features that you must configure deliberately. If you leave defaults in place, your cluster is insecure. The CKS exam is designed to test whether you know how to harden each component.

For context, here is how the model replaces older approaches. Before Kubernetes, companies used virtual machines (VMs) and manual firewall rules. A VM is a pretend computer that runs on a physical server. Each VM had its own operating system, and administrators connected to it using a tool called SSH. To control access, you had to edit firewall rules on each VM individually. That was slow and error-prone. Kubernetes centralises all of that work in one API server, one RBAC system, and one set of admission controllers. You define security once and the system enforces it everywhere.

Understanding these fundamentals is critical because the CKS exam is a hands-on performance test. You will not answer multiple-choice questions. You will sit at a terminal and configure a live cluster. If you do not grasp authentication, authorisation, admission control, network policies, and secrets encryption, you will fail the exam tasks.

This flowchart shows the sequential stages of request processing in Kubernetes, from authentication through audit logging, with emphasis on the security checkpoints.

Walk-Through

1

Authenticate to the API Server

You must prove your identity to the Kubernetes API server before it processes any request. This is done using a client certificate, a bearer token (often from Microsoft Entra ID), or a basic username and password. The API server checks the credential against a trusted certificate authority or external identity provider. Without authentication, the request is rejected immediately.

2

Authorise the Request via RBAC

Once authenticated, the API server checks whether the user (or service account) is allowed to perform the requested action on the requested resource. It compares the user's identity against RBAC rules. The rules define verbs (get, list, create, delete) and resources (pods, secrets, nodes). If no RBAC rule matches, the request is denied with a '403 Forbidden' error.

3

Run Admission Controllers

After authorisation succeeds, the request passes through admission controllers. These are plugins that can modify the request (mutating) or reject it (validating). For example, the 'NamespaceLifecycle' controller rejects pods in a namespace that is being deleted. The 'AlwaysPullImages' controller forces every pod to pull its image fresh from the registry, preventing cached malware. If any admission controller rejects the request, it fails.

4

Store and Retrieve Secrets Securely

When a pod needs sensitive data like a database password, it references a Secret object. The Secret is stored in etcd. For security, you must configure encryption at rest in the EncryptionConfiguration so that the secret value is encrypted before it is written to disk. When the pod requests the secret, the API server decrypts it and delivers it to the pod's volume or environment variable.

5

Enforce Network Policies

After the pod is running, network policies control which pods can send traffic to each other. A network policy uses labels to select a group of pods (the target) and then defines ingress and egress rules. For instance, you can create a policy that allows only pods with the label 'role: frontend' to send traffic to pods with the label 'role: backend' on port 3306. All other traffic is dropped by the container network interface (CNI) plugin.

6

Audit and Monitor

The final step is to enable audit logging on the API server. An audit policy specifies which events to log (e.g., all requests to 'secrets' by non-admin users). The logs are sent to a file or an external log aggregator. Administrators review these logs to detect suspicious activity, such as repeated failed login attempts or unauthorised access to sensitive resources.

What This Looks Like on the Job

Imagine you work as a junior IT administrator for a company called QuickCart, an online grocery delivery service. QuickCart runs its entire platform on Kubernetes. They have a development cluster used by engineers to test new features, and a production cluster that serves real customers. You are tasked with securing the production cluster after a security audit revealed several vulnerabilities.

Your first task is to review and fix the RBAC configuration. An audit log shows that a former intern still has a role that can delete pods. You open the RBAC configuration file. You see a Role named 'pod-modifier' that is bound to multiple users via a RoleBinding. You need to remove the intern from that RoleBinding and create a new Role with restricted permissions for new employees. In the CKS exam, you would edit YAML files directly. In real life, you might use a command like:

'kubectl delete rolebinding intern-binding -n production'

Then you would create a new Role that only allows reading logs and restarting pods, not deleting them:

'kubectl create role readonly-logs --verb=get,list --resource=pods,logs'

'kubectl create rolebinding new-hire-binding --role=readonly-logs --user=alice@quickcart.com'

Your second task is to implement a network policy that isolates the payment processing pods. The audit found that a database pod in the same namespace is being accessed by a monitoring tool that should not have direct database access. You write a network policy that allows only the payment frontend pods to communicate with the backend payment database on TCP port 5432. All other traffic is denied. The policy uses podSelector to target the correct pods and ingress rules to whitelist specific sources.

Third, you discover that secrets are stored unencrypted in etcd. The company policy requires encryption at rest. You generate a new encryption key, create a YAML configuration file for the EncryptionConfiguration resource, and restart the kube-apiserver components. The CKS exam will simulate this exact scenario. You must know the structure of the EncryptionConfiguration file, including the providers block and the order of keys.

Fourth, you enable audit logging. You create an audit policy that logs all requests to the 'secrets' resource by any user who is not an admin. The logs are sent to a central logging system. In a real environment, this helps the security team detect data exfiltration attempts.

Finally, you run a kube-bench scan. Kube-bench is an open-source tool that checks your cluster against the CIS Kubernetes Benchmark, which is a set of security best practices published by the Center for Internet Security. The scan flags that the kubelet (the agent running on each worker node) is using a default port and has anonymous authentication enabled. You correct both issues by editing the kubelet configuration file and restarting the service.

Every one of these tasks appears on the CKS exam. The exam environment provides a cluster that is intentionally insecure. Your job is to identify and fix the vulnerabilities. You do not need to memorise every command. You need to understand the security concepts so well that you can apply them under time pressure.

How CKS Actually Tests This

The CKS exam is a two-hour practical test where you complete a series of tasks on a live Kubernetes cluster. There are between 15 and 20 tasks. Each task describes a security weakness and asks you to fix it. You must be able to perform actions from the command line without looking up syntax in your notes. The exam does not test theory. It tests your ability to implement security controls.

The exam focuses heavily on RBAC. Expect at least two tasks that require you to create or modify Roles, ClusterRoles, RoleBindings, and ClusterRoleBindings. The traps include:

Confusing a Role (namespace-scoped) with a ClusterRole (cluster-scoped). If a task says 'restrict access to pods in the namespace 'production'', you need a Role, not a ClusterRole.

Forgetting that a RoleBinding binds users to Roles only within a specific namespace, while a ClusterRoleBinding binds across all namespaces.

Using incorrect verb names. Kubernetes uses verbs like 'get', 'list', 'watch', 'create', 'update', 'patch', 'delete'. 'Read' is not a valid verb. 'Write' is not a valid verb.

The exam includes at least one task on network policies. You must know how to define a NetworkPolicy YAML that uses podSelector, ingress, and egress rules. Common traps:

Allowing all traffic by omitting the 'spec' field. If you do not specify ingress rules, the policy defaults to denying all ingress traffic. If you omit the entire policy, all traffic is allowed. You must explicitly define what you want to allow.

Using 'ipBlock' when the task requires podSelector. The exam prefers podSelector for workloads within the cluster.

Secrets encryption is another frequent topic. You must know:

The location and format of the EncryptionConfiguration file (it is passed to the kube-apiserver via the '--encryption-provider-config' flag).

The order of providers: aescbc, secretbox, identity. Identity means no encryption. The first provider in the list is used for encryption. All providers are tried for decryption.

How to rotate the encryption key without downtime. You add the new key to the configuration, restart the API server, then update all secrets so they are re-encrypted with the new key.

Admission controllers are tested in at least one task. The exam expects you to know:

How to enable a built-in admission controller (e.g., '--enable-admission-plugins=NodeRestriction,AlwaysPullImages').

How to write a custom admission webhook configuration (ValidatingWebhookConfiguration or MutatingWebhookConfiguration). The exam rarely asks you to write the webhook code, but you must configure the YAML that calls the webhook.

The difference between a mutating webhook (modifies the request) and a validating webhook (rejects or accepts the request without modification).

Kube-bench and CIS benchmarks are tested as a single task. You must run kube-bench on a control plane node, interpret the results, and fix one or two high-risk issues. The most common issue is unauthenticated access to the kubelet API. You fix it by setting 'authentication.anonymous.enabled' to 'false' and 'authorization.mode' to 'Webhook' in the kubelet configuration.

Finally, the exam tests your ability to secure cluster components. You might be asked to:

Disable the external etcd client port.

Ensure kube-apiserver uses TLS certificates from a specific certificate authority.

Restrict the use of hostNetwork or hostPath volumes in pods using a PodSecurityPolicy or PodSecurity admission controller.

The biggest trap is time management. Each task has a point value. Some tasks are worth 2 points and are quick (RBAC changes). Others are worth 8 points and require multiple steps (enabling encryption and rotating keys). Do not get stuck on a complex task early. Complete the easier tasks first to accumulate points, then return to the harder ones.

Key Takeaways

Kubernetes has four main security layers: authentication, authorisation, admission control, and network policies, and you must configure each one manually.

RBAC uses Roles (namespace-scoped) and ClusterRoles (cluster-scoped) to define permissions, and RoleBindings and ClusterRoleBindings to assign them to users or groups.

Secrets are stored unencrypted in etcd by default; always enable encryption at rest using the EncryptionConfiguration resource with the aescbc provider.

A NetworkPolicy without any rules denies all traffic to the selected pods by default; you must explicitly define allowed ingress and egress rules.

The kubelet API is a common attack vector; disable anonymous authentication and set the authorisation mode to Webhook in the kubelet configuration.

Admission controllers like AlwaysPullImages and NodeRestriction prevent insecure configurations from being applied, and you can write custom webhooks for organisation-specific policies.

Easy to Mix Up

These come up on the exam all the time. Here's how to tell them apart.

Role (RBAC)

Scoped to a single namespace; permissions only apply within that namespace.

Cannot grant access to cluster-scoped resources like nodes or namespaces.

Bound to users using a RoleBinding (namespace-scoped binding).

ClusterRole (RBAC)

Scoped to the entire cluster; permissions apply across all namespaces.

Can grant access to both cluster-scoped and namespace-scoped resources.

Bound to users using a ClusterRoleBinding (cluster-wide binding) or reused inside RoleBindings.

MutatingAdmissionWebhook

Can modify the incoming request before it is persisted.

Runs before validating webhooks in the admission chain.

Used for injecting default values, sidecars, or labels automatically.

ValidatingAdmissionWebhook

Cannot modify the request; only accepts or rejects it.

Runs after mutating webhooks in the admission chain.

Used for enforcing policies like 'container images must come from a trusted registry'.

Secrets (unencrypted in etcd)

Stored as base64-encoded plaintext in etcd; base64 is not encryption.

Vulnerable to data breach if etcd is compromised or backed up.

Default behaviour in Kubernetes; requires manual configuration to change.

Secrets (encrypted at rest)

Encrypted using a provider (e.g., aescbc) before writing to etcd.

Protected even if etcd is stolen; attacker needs the encryption key.

Requires EncryptionConfiguration resource and API server restart to enable.

Pod Security Policy (deprecated)

Deprecated since Kubernetes 1.21 and removed in 1.25.

Was a separate API resource (PodSecurityPolicy) with complex YAML.

Required manual management of PSP resources and RBAC for each policy.

Pod Security Admission (current)

Implemented as a built-in admission controller in Kubernetes 1.23+.

Uses three standardised policies: privileged, baseline, restricted.

Enabled per namespace via labels (e.g., 'pod-security.kubernetes.io/enforce: restricted').

Watch Out for These

Mistake

Kubernetes is secure by default because it uses containers, and containers are isolated from each other.

Correct

Kubernetes is not secure by default. It runs with a flat network, secrets are stored unencrypted in etcd, and anonymous authentication is often enabled out of the box. You must configure security manually.

Container isolation is not the same as network security or access control. Beginners assume containerisation magically solves security, forgetting that containers share a kernel and do not enforce authorisation rules.

Mistake

If I deploy my application in a Kubernetes namespace, it is automatically isolated from other namespaces.

Correct

Kubernetes namespaces provide logical separation for resource names, but they do not enforce network isolation. By default, any pod in any namespace can talk to any other pod unless you create a NetworkPolicy.

The word 'namespace' sounds like a security boundary, like a virtual private cloud. In reality, it is just a prefix for resource names. The security boundary is created by network policies, which are optional.

Mistake

I do not need to worry about etcd security because Kubernetes relies on the API server, and the API server has its own authentication.

Correct

The API server stores all cluster state, including secrets, in etcd. If an attacker gains direct access to the etcd database or the etcd daemon, they can read all secrets, create new users, and destroy the cluster. Etcd must be encrypted at rest and protected with TLS.

Beginners focus only on the API server because that is the component they interact with. They forget that the API server is just a front-end for etcd. The database behind it is equally critical.

Mistake

RBAC is optional because I can just use SSH keys to secure the nodes.

Correct

RBAC is not optional for a secure cluster. SSH keys control access to individual virtual machines, but Kubernetes is an API-driven system. Every action—even a simple 'kubectl get pods'—goes through the API server. Without RBAC, any authenticated user has full cluster admin access.

People come from a traditional server world where you secure the machine. They do not realise that Kubernetes operations are all API calls, not shell commands on a server. You must secure the API, not the OS.

Mistake

Admission controllers are only needed in large enterprise clusters with complex compliance requirements.

Correct

Admission controllers are essential in any cluster that runs untrusted workloads or multi-tenant applications. They are the only way to enforce policies like 'no privileged containers' or 'no containers running as root' before the pod is created.

Admission controllers run in the background and are invisible to developers. Beginners assume they are advanced features, but they are the primary mechanism for preventing security mistakes early in the deployment pipeline.

Do You Actually Know This?

Reveal each answer, then mark whether you got it right. Score 60%+ to unlock the next chapter.

Frequently Asked Questions

What is the difference between a Role and a ClusterRole in Kubernetes?

A Role defines permissions within a single namespace, such as 'can read pods in the production namespace'. A ClusterRole defines permissions across the entire cluster, such as 'can view all nodes' or 'can create namespaces'. You use RoleBindings to attach Roles to users, and ClusterRoleBindings to attach ClusterRoles.

Do I need to encrypt secrets if my cluster is only used internally and not exposed to the internet?

Yes. Internal threats are the most common vector for data breaches. An attacker who gains access to your corporate network, or a disgruntled employee with access to etcd, can read all secrets if they are stored in plaintext. Encryption at rest is a basic hygiene practice, even for internal clusters.

What is a PodSecurityPolicy and is it still used in the CKS exam?

A PodSecurityPolicy (PSP) was a cluster-level resource that controlled security settings for pods, such as preventing privileged containers. PSP has been deprecated in Kubernetes 1.21 and removed in 1.25. The CKS exam now tests Pod Security Admission (PSA), which is a built-in admission controller that enforces predefined security standards (privileged, baseline, restricted). You will not be tested on PSP.

How do I test my RBAC rules without accidentally giving too much access?

Use the 'kubectl auth can-i' command to simulate a request. For example, 'kubectl auth can-i create pods --as=developer' tells you whether the user 'developer' is allowed to create pods based on current RBAC rules. You can also use the '--as-group' flag to test group permissions. This lets you verify policies before applying them to real users.

What is the difference between a ValidatingWebhookConfiguration and a MutatingWebhookConfiguration?

A ValidatingWebhookConfiguration calls an external webhook that only inspects the request and returns an allow or deny decision. It cannot modify the request. A MutatingWebhookConfiguration can modify the request, for example, adding default labels or injecting a sidecar container, before returning the modified request to the API server. Both are types of admission webhooks.

Can I use a NetworkPolicy to block traffic from a specific IP address?

Yes. A NetworkPolicy can include an 'ipBlock' rule in its ingress or egress section. ipBlock allows you to specify a CIDR range (e.g., '10.0.0.0/24') and optionally an 'except' list to exclude certain IPs. However, the CKS exam emphasises podSelector-based rules because those are more portable and easier to maintain in dynamic cloud environments where pod IPs change.

Terms Worth Knowing

Keep going

You've finished Kubernetes Security Fundamentals. Continue through the CKS study guide to build a complete picture of the exam.

Done with this chapter?