Encryption Reading Time: 5 minutes

Is Your Organization Updated With The Best Practices of Kubernetes Security?

Read time: 5 minutes

Kubernetes is an open-source container-orchestration system used to automate deploy, scale, and manage containerized applications. Kubernetes manages all elements that make up a cluster, including each microservice in an application to entire clusters. Organizations using these containerized applications as microservices can provide them more flexibility and security benefits than monolithic software platforms and introduce other complexities.

Kubernetes security is essential for protecting the integrity, confidentiality, and availability of containerized applications orchestrated by Kubernetes. Organizations worldwide are choosing Kubernetes to manage their cloud-native environments, making it imperative to ensure robust security measures. The complexity of Kubernetes introduces various vulnerabilities and threats and requires that we adapt newer strategies to secure the dynamic environment of containerization. Yes, it does seem daunting, especially if you’re just getting started, but if you or your organization are using Kubernetes to deploy applications, it is important that you implement security practices that can shield against unauthorized access, data breaches, and misconfigurations. Effective Kubernetes security will help you maintain compliance with regulatory standards, protect sensitive data, and minimize the risk of costly security incidents.

Recommendations

We have compiled some Kubernetes security best practices to simplify securing your clusters. Let’s dive right in!

  1. Kubernetes Pod security
    1. Containers built to run applications should run as non-root users
    2. Run containers with immutable file systems whenever possible
    3. Regularly scan container images for potential vulnerabilities or misconfigurations
    4. Use Pod Security Policies to enforce a minimum level of security, including:
      1. Preventing privileged containers
      2. Denying container features that are frequently exploited to breakout, like hostPID, hostIPC, hostNetwork, allowedHostPath
      3. Rejecting containers that execute as root user or allow elevation to root
  2. Network separation and hardening
    1. Lockdown access to the control plane nodes using a firewall and RBAC (Role-Based Access Control)
    2. Limiting access to the Kubernetes, etcd server
    3. Configuring control plane components to use authenticated, encrypted communications using TLS/SSL certificates
    4. Set up network policies to isolate resources. Pods and services in different namespaces can communicate unless additional separation is applied, such as network policies.
    5. All credentials and sensitive information should be placed in Kubernetes Secrets rather than in configuration files. Encrypt Secrets using a robust encryption method
  3. Authentication and authorization
    1. Disable anonymous login
    2. Using strong user authentication
    3. Create RBAC policies that limit administrator, user, and service account activity
  4. Log auditing
    1. Enable audit logging
    2. Persist logs to ensure availability in case of pod, node, or container level failure
    3. Configuring a metrics logger
  5. Upgrading and application security practices
    1. Immediately apply security patches and updates
    2. Performing periodic vulnerability scans and penetration tests
    3. Removing components from the environment when they are no longer needed

Architectural overview

Kubernetes uses a cluster architecture. A Kubernetes cluster comprises many control planes and one or more physical or virtual machines called worker nodes which host Pods, which contain one or more containers. The container is an executable image that includes a software package and all its dependencies.

The control plane makes decisions about clusters. This includes scheduling the running of containers, detecting/responding to failures, and starting new Pods if the number of replicas listed in the deployment file is unsatisfactory.

Here is a brief overview of the key components of Kubernetes architecture:

Master Node: The control plane responsible for managing the cluster. It includes:

  • API Server: The central component that exposes the Kubernetes API. It enforces authentication and authorization, serving as the gateway for all interactions with the cluster.
  • etcd: A distributed key-value store that holds the cluster’s state and configuration data. Securing etcd is crucial, as it stores sensitive information, including secrets.
  • Controller Manager: Manages controllers that regulate the state of the cluster. It ensures that the desired state defined by the user matches the current state of the system.
  • Scheduler: Assigns pods to nodes based on resource availability and other constraints. Security policies can influence scheduling decisions.

Worker Nodes: These host the actual containers. Each worker node includes:

  • Kubelet: An agent that communicates with the API server and manages the lifecycle of containers on the node. It can enforce security contexts to define security settings for pods.
  • Kube-Proxy: Manages network routing to ensure that requests are directed to the appropriate pods. Network policies can be implemented to control traffic between pods.
  • Container Runtime: The software responsible for running containers (e.g., Docker, containerd). It should be secured to prevent container escapes.

Securing Pods in Kubernetes

Pods consist of one or more containers and are the smallest deployable Kubernetes unit. Pods can often be a cyber actor’s initial execution environment upon exploiting a container. Pods should be hardened to make exploitation much more complex and limit the impact on compromise.

“Non-root” and “rootless” container engines

Many container services run as privileged root users, and applications can execute inside the container as root despite not requiring privileged execution. Preventing root execution using non-root containers or a rootless container engine limits the impact of a container compromise. These methods affect the runtime environment significantly; thus, applications should be tested thoroughly to ensure compatibility.

Non-root containers

Container engines that allow containers to run applications as non-root users with non-root group membership. This non-default setting is configured while building the image.

Rootless container engines

Some container engines can run in an unprivileged context rather than using a daemon running as root. For this scenario, execution would appear to use the root user from the containerized application’s perspective, but the execution is remapped to the engine’s user context on the host.

Immutable container file systems

Containers are permitted mostly unrestricted execution within their context. A threat actor who has gained execution in a container can create files, download scripts, and modify applications within the container. Kubernetes can lockdown a container’s file system, thereby preventing many post-exploitation activities. These limitations can also affect legitimate container applications and can also potentially result in crashes or abnormal behavior. Kubernetes administrators can mount secondary read/write file systems for specific directories where applications require write access to prevent legitimate damaging applications.

Building secure container images

Container images are usually created by either building a container from scratch or building on top of an existing image pulled from a repository. Even after using trusted repositories to build containers, image scanning is key to ensuring deployed containers are secure. Images should be scanned throughout the container build workflow to identify outdated libraries, known vulnerabilities, or misconfigurations, such as insecure ports or permissions.

One approach for implementing image scanning is by using an admission controller. Admission controller is a Kubernetes-native feature that can intercept and process requests to the Kubernetes API before the persistence of the object but after a request is authenticated and authorized. A custom webhook can be implemented to scan any image before deploying it in the cluster. The admission controller could block deployments if the picture doesn’t comply with the security policies defined in the webhook configuration.

Conclusion

This was an introduction to properly managing and securing Kubernetes clusters and securely deploying them in your environment. In the current world of constant technological advancement and cyber threats, the security of an application cannot be assured without securing the Kubernetes environment within which it operates. Remember, a well-secured Kubernetes cluster not only safeguards your infrastructure but also builds trust with your users, allowing your organization to thrive in a competitive environment.

How can Encryption Consulting help?

Encryption Consulting offers encryption advisory services to help your organizations adhere to regulatory requirements and create a comprehensive encryption plan that fits your needs. We put encryption systems in place for databases, disk storage, and other special cases, making sure both data- and data-in-transit remain secure. Our experts develop policies, standards, and program structures to allow encryption throughout your organization. By analyzing your platforms and applications, we make a decision guide to help you choose the right encryption methods and solutions.

Free Downloads

Datasheet of Encryption Consulting Services

Encryption Consulting is a customer focused cybersecurity firm that provides a multitude of services in all aspects of encryption for our clients.

Download

About the Author

Anish Bhattacharya's profile picture

Anish Bhattacharya is a Consultant at Encryption Consulting, working with PKIs, HSMs, creating Google Cloud applications, and working as a consultant with high-profile clients.

Explore the full range of services offered by Encryption Consulting.

Feel free to schedule a demo to gain a comprehensive understanding of all the services Encryption Consulting provides.

Request a demo