Testing the Security of a Kubernetes Cluster
Ashwani Patel
Senior- Cloud Consultant @E2E Networks- NVIDIA Partners | AI hyperscaler | Migrate to E2E Cloud and save upto 50% Best performance to price ratio and zero unpredictable billing
Containers and Kubernetes are everywhere. The adoption of Kubernetes in production has increased to 83% to a survey by CNCF. Still, most security teams struggle to understand these modern technologies.
From an attacker's perspective, they can assess and attack Kubernetes Cluster environments to gain access to microservices, sensitive data, escaping containers, escalating to cluster privileges, and even its underlying cloud environments. Also, this article describes the offensive knowledge to build and design secured cluster environments.?
What are some of the most common concerns of people using Kubernetes?
Why are complex systems challenging to secure?
What gives an attacker a chance to attack?
Let’s take a look at some of the ways Kubernetes can be attacked and the ramifications of such attacks on data and the business in general.?
All attackers, irrespective of how unstructured they are, follow a set of tactics to reach their end goal. Each of these tactics (consider them as milestones) in an attack have various techniques by which the tactic is fulfilled. Depending on the technology being targeted, the tactic may differ but often align with: Initial discovery, code execution, privilege escalation, persistence (optional), evasion/evidence removal (optional), and Abuse/Impact.?
Mitre Attack & Threat Matrix:
Mitre-Attack is a globally accessible knowledge base of adversary tactics and techniques based on real-world observations. The threat matrix describes tactics, techniques and procedures (TTPs) for these technologies and can be used by both offensive security folks to plan test cases and defenders to identify attack paths that the bad guys will take. Microsoft created a similar threat matrix for kubernetes in 2020 and released an updated version in 2021.
The first vector, or category of attacker tactic, in the Kubernetes attack matrix is Initial Access. This tactic references the attacker’s objective of gaining access to Kubernetes clusters by either compromising a component within the Kubernetes control plane that handles cluster management or various resources within the cluster – for example, a running application component on a worker node.
Exposing a sensitive interface to the internet or within a cluster without strong authentication poses a security risk. Some popular cluster management services were not intended to be exposed to the internet, and therefore don’t require authentication by default. Thus, exposing such services to the internet allows unauthenticated access to a sensitive interface which might enable running code or deploying containers in the cluster by a malicious actor. Examples of such interfaces that were seen exploited include Apache NiFi, Kubeflow, Argo Workflows, Weave Scope, and the Kubernetes dashboard.
Once an exposed sensitive interface in Kubernetes has been identified, the first step is to take steps to secure the interface. This could include patching any vulnerabilities, implementing authentication and authorization controls, or disabling the interface if it is not needed. Additionally, it is important to monitor the exposed interface for any suspicious activity or unauthorized access attempts. By taking these steps, organizations can ensure that their Kubernetes infrastructure remains secure and protected from malicious actors.
Initial Access:
Multiple large companies have in the past exposed their kubernetes dashboard without authentication to the internet. Other sensitive interfaces that contain the ability to deploy containers or run code include Apache Nifi, Kubeflow, Argo Workflows, Weave Scope etc. can be exposed. App vulnerabilities that can be used to make network requests or read files like SSRF, XXEs, LFIs, Path Traversal, arbitrary file downloads, SQL injections or plain RCEs can be used to gain access to environment variables or files containing credentials. Stealing the config file while an ongoing attack and using cloud credentials are other popular techniques (dev machine compromise)?
Once the ability to interact with the cluster is obtained-either via an exposed dashboard, kubeconfig file taken off a developer laptop or secrets leaked via an application vulnerability, attackers will attempt to gain proper shell access or run custom code within the cluster. Attackers can also inject a sidecar container in an already running pod to hide their presence as an explicit container may be spotted by an admin.
Rarely, but not unheard of, cluster users may choose to run SSH servers within containers to provide for exec capabilities to devs without providing the kubeconfig. Attackers can target this to gain code exec capabilities.
Kubernetes Cronjob:
A CronJob runs within a Pod. By default, Kubernetes preserves the logs for terminated Pods representing the last three successful runs of a CronJob and the most recent failed Job. You can change or disable these defaults by changing the CronJob history limits.?
Why persistence?
Attackers can persist within the kubernetes infrastructure and maintain access in various different ways including but not limited to:
领英推荐
Some attackers like to persist in most networks for the thrill of seeing how long it takes owners to boot them out, to use the network as a means of further attack/abuse or as a symbolic trophy in their collection.
Privilege Escalation:
Escalation of privileges is a key step to gain additional access or to ensure the attacker remains hidden within the infrastructure.
Some ways by which an attacker can escalate privileges include:
Defense Evasion:
As privileges increase within the cluster, attackers find novel ways to remove their traces and remain undetected?
Credential Access:?
Most attackers will try to identify alternate regions, resources, and networks that they can gain access to from their vantage point.
To reach protected regions, they may require credentials that would unlock doors for them. Here are some techniques that attackers use to get their hands on credentials?
Lateral Movement:
Impact:
Impact Tactic is used to identify potential endgame goals of the attacker. Some documented techniques include:
Tips for cluster security:
We hope you are now able to get an in depth insight to secure your Kubernetes cluster and what can be practices followed by a hacker. Want a handbook on end-to-end Kubernetes deployment? Read this article to know more:?www.e2enetworks.com/blog/kubernetes-deployment-handbook-configurations-checklist-error-handling-and-best-practices .
Also, are you looking for Kubernetes as a service? EKS, E2E Kubernetes Service: With the E2E Cloud platform, You can quickly launch the Kubernetes master, worker nodes and get started working with your kubernetes cluster in a minute.?
Connect with us for any query you may have:[email protected]