3 Ways to Ensure Kubernetes Pod Security

Mina Omobonike
Analytics Vidhya
Published in
4 min readFeb 25, 2022
Photo by Mohammad Rahmani on Unsplash

Lately, Kubernetes has become an essential part of the software development lifecycle, especially for continuous integration and continuous deployment. Once applications start gaining traction and more users register, there is a need for a load balancer that manages and optimizes the traffic. If you want a highly scalable application that automatically scales, accelerates, and secures every level of the build-and-deploy lifecycle, then Kubernetes is your answer.

Kubernetes is used for managing containerized applications and loosely coupled systems. With support for stateful, serverless, and software accelerators, you can create a wide range of apps. A Kubernetes pod represents a single instance of a running process in your cluster. This article discusses the Kubernetes pod’s best security measures that make your application invulnerable to cyber threats.

Pods are the simplest and most fundamental deployable objects in Kubernetes. One or more containers are contained in pods. When a pod has many containers running, they are treated as a single entity that shares the pod’s resources. For their containers, pods also feature integrated networking and storage infrastructures.

Why Do You Need Kubernetes Pod Security?

Pod security’s overall goal is to allow you to separate workloads. You can run a cluster with diverse workloads and build restrictions that require pods for each workload to limit their own rights to a specific bounding set without using third-party softwares. By rejecting resources that contravene the rules, pod security conforms to Kubernetes security best practices of declarative object management.

Prior to being deployed to Kubernetes, this necessitates updating resources in source repositories and tooling. A cluster administrator can configure the predefined pod security levels to fit the appropriate security posture.

Ways to Ensure Kubernetes Pod Security

Source

Pod security is a built-in admission controller, although it can also be used as a separate webhook. Admission controllers work by intercepting requests in the Kubernetes API server before they are saved to disk. They have the option of accepting or rejecting a request. Pod specs will be reviewed against a specified policy in the form of a pod security standard in the case of pod security. This means that in a pod definition, security-sensitive fields will only be allowed to have certain values. The following are ways to configure Kubernetes pod security:

1. Pod Security Standards:

The pod security standards specify three policies that cover a wide range of security concerns. These regulations are cumulative, ranging from the extremely permissive to the extremely stringent. Each policy’s requirements are outlined below.

The Privileged Policy is intentionally broad and uncontrolled. This type of regulation is often applied to workloads managed at the system and infrastructure levels by privileged, trusted users. The absence of constraints characterizes the Privileged Policy.

The Privileged Policy may be the absence of applied limitations rather than an instantiated profile for allow-by-default enforcement methods (such as gatekeeper). Privileged policy, on the other hand, should enable all controls for a deny-by-default method (such as pod security policy).

The Baseline Policy is designed to be simple to implement for common containerized workloads while avoiding known privilege escalations. Non-critical application operators and developers are the targets of this strategy.

The Restricted Policy is intended to enforce current pod protection best practices while sacrificing some compatibility. It is aimed at security-critical application operators and developers, as well as lower-trust users.

Each of these policy levels specifies which fields in a pod specification are restricted, as well as the values that can be used. The following are some of the fields that are limited by these policies:

spec.securityContext.sysctls

spec.hostNetwork

spec.volumes[*].hostPath

spec.containers[*].securityContext.privileged

Policy levels are applied to Namespace resources via labels, allowing for granular policy selection per-namespace. The API server’s AdmissionConfiguration can also be used to specify cluster-wide default levels and exemptions.

2. Pod Security Admission:

Kubernetes has a built-in pod security admission controller, which is the replacement of PodSecurityPolicies, as a beta feature. An admission controller is a piece of code that intercepts connections to the Kubernetes API server before the object is persistent but after the request is then authenticated and allowed. Requests to build, delete, alter, or connect to the proxy are limited by admission controllers. They don’t impose any restrictions on requests to read objects.

The admissions procedure is divided into two stages. Mutating admission controls are used in the initial phase. Validating entrance controllers are used in the second step.

3. Configure Pod Security Context:

For a pod or container, a security context defines the privilege and access control settings. Discretionary access control (DAC) grants permission to access an item, such as a file, is granted depending on the user ID and the group ID. SELinux (Security-Enhanced Linux) assigns security labels like the privileged or unprivileged users to objects. Additionally, you can filter the system calls made by a process using Seccomp or mount the root filesystem of the container as read-only. Finally, you can use allowPrivilegeEscalation which determines whether or not a process can earn higher privileges than its parent. This bool determines whether the container process’s no new privs flag is set. When the container is executed as privileged or with CAP SYS ADMIN, allowPrivilegeEscalation is always true.

Conclusion

Pod security is a great new feature that will allow you to strengthen the defense capabilities of your workloads right out of the box. Utilizing this feature in your Kubernetes pod is highly recommended. For specialized tutorials that address the cluster and namespace configuration requirements, refer to this Kubernetes documentation.

Thank you for reading.

--

--