Understanding The Security Implications of Kubernetes Networking
Understanding The Security Implications of Kubernetes Networking
Understanding The Security Implications of Kubernetes Networking
Container-orchestration software such as Kubernetes make it easy to deploy and manage modern cloud
applications based on microservices. Yet, its network abstractions pave the way for "unexpected attacks"
if we approach cloud network security with the same mental model of traditional network security.
www.computer.org/security 47
KUBERNETES NETWORKING
command-and-control server and hijacks the whole cluster among a set of processes. Specifically, a network namespace
including services running on other containers. is a copy of the network stack, including network interfaces,
routing and firewall rules, which can be assigned to each
process or container. The longhorn, nfs server, dev, and
A Primer on Containers and Kubernetes prod namespaces shown in Figure 1 implement a similar
To explain why these attacks are feasible, some back- resources isolation at a K8s cluster level.
ground material on containers and key components of Deployment and management of containers is typi-
K8s is useful. cally automated with orchestration engines such as K8s,
A container emulates the operating system layers to Docker Swarm, and AWS ECS. In this article we focus only
offer a virtualized and self-contained environment with on K8s, the most widely used orchestration software.9
its own subprocesses and resources. Container isolation An application running on K8s is deployed within
in a typical Linux environment is implemented through a cluster, a set of machines (either virtual or physical)
namespaces, which allow a kernel to partition resources for running containerized applications. As shown in
www.computer.org/security 49
50
Controller- Scheduler kubelet Kube-Proxy kubelet Kube-Proxy
DevOps
Container Runtime Container Runtime
Pod-to-Pod Switch
Pod-to-Pod 172.16.0.0/16
(Different Nodes) Worker node Virtual Network
Master Node Pod netns Network
Pod-to-Service netns Interface Interface
Figure 2. K8s “real” network and possible interactions between different services in a single cluster. This figure shows a more accurate representation of the actual network architecture
of a single K8s-managed cluster from the top part of Figure 1. The key takeaway from a security standpoint is that all isolation boundaries (i.e., the namespace abstractions and
network-security policies) are implemented in software; these boundaries disappear as soon as one escapes to the right namespace. For example, if an attacker breaks out of the pod netns
of “Service 1” to the surrounding worker-node netns, the cluster is laid bare and, thus network-security policies no longer apply (see the “A Primer on Containers and Kubernetes” section).
Alternatively, a compromised service could ignore the CNI plug-in and “talk” directly to any reachable interface. Even in the presence of some physical boundaries, an attacker could rewire
the logical control flow (through kubelet on top) and provide backdoor access to workers that appear apparently separated.
September/October 2021
when nodes are in different datacenters or clouds), in A Summary of Network-Security
which case they, usually, use an overlay network. The Implications
CNI plug-in tracks which pods are on which subnets, In this section, we highlight a list of network-security
and on which nodes, and updates the routing rules in the issues that may arise within a K8s cluster and that every
network namespace of each node such that the pod-to- K8s user and developer should keep in mind.
pod traffic can be forwarded through the right node.
Connectivity between nodes is, however, not managed Pod netns by a Pause Container
by K8s, and we omit concerned scenarios, since they are The pod netns is held by a special container, called
beyond the scope of this article. Pod-to-pod communi- a pause container. Every container scheduled on a pod
cation on the same node is implemented via virtual Eth- will share the netns with the pause container. Thus,
ernet devices (veth pairs in Figure 2) and a bridge (cbr0 escaping from the pod netns means escaping from the
in the illustration). Therefore, multiple pods running on pause container netns, ending up in the host netns (the
the same worker node can exchange network packets pause container is not shown in Figure 2, but the same
via the virtual bridge. can be thought as
When a container is escaping from the pod
compromised, CNI square). An attacker
plug-ins using a bridge who is able to get on
become vulnerable the host netns can
to common L2 net- Therefore, multiple pods running on the potentially see network
work attacks [such as same worker node can exchange network interfaces, routing
Address Resolution packets via the virtual bridge. rules, other pods ne-
Protocol (ARP) and tns: if the attacker
Domain Name Sys- has privileged access,
tem (DNS) spoof- the worker-node netns
ing]. Other plug-ins, is fully compromised.
instead of the bridge,
use a virtual router in each node or IP in IP encapsulation CNI Plug-Ins Jeopardy
to avoid such problems. CNI plug-ins run as (privileged) programs on worker
nodes. Subverting these objects automatically results in
Pod-to-Service Networking privileged access to the worker nodes, compromising the
A K8s service is an abstract way to expose an application whole network. Also, an attacker can compromise the net-
running on a set of pods. All pods used by an applica- work interfaces or other components of the CNI plug-in
tion share a common label that K8s uses for grouping itself. Layer 2 plug-ins that use the Linux bridge may be
the pods. K8s also uses labels to automatically keep susceptible to man-in-the-middle (MITM) attacks (e.g.,
track of newly instantiated pods and maintains a list ARP spoofing and DNS spoofing); routing daemons of
of pod IP addresses associated with each service in an layer 3 plug-ins (e.g., CVE-2021-26928 affecting Border
EndpointSlice resource. K8s supports three different Gateway Protocol) and eBPF (e.g., CVE-2021—31440)
types of services: may also be vulnerable.
■ The ClusterIP service assigns the concerned applica- Software Isolation of Resources
tion a cluster-wide unique virtual IP address, only By default, the K8s network is flat. K8s isolates resources
reachable from within the cluster. in this flat architecture through network policies, while
■ The NodePort service assigns the service to a static port also introducing new security implications. Within a clus-
on every node in the cluster. It can be accessed from out- ter, network policies are enforced by the CNI plug-in and
side the cluster using the node’s IP address and the stati- not K8s itself. Subverting the plug-in may result in invali-
cally assigned port number. K8s also routes requests to dating all policies. The policies are also usually stored in
NodePort services to a clusterIP services (to load bal- the CNI-plug-in datastore (e.g., etcd): Compromising
ance traffic across the pods). this database will result in another point of failure.
■ In the Load Balancer case, K8s exposes the ser-
vice through a cloud-provider’s load balancer Network Policies Limitations
(red line in the Figure 2). Requests arriving at the K8s base network policies that do not depend on the par-
cloud-provider’s load balancer are subsequently ticular CNI plug-in do not support logs and drop/block
routed to a NodePort service, which in turn routes it to a options. There is no support for fully qualified domain
ClusterIP service. name filtering in network rules, limiting the security
www.computer.org/security 51
KUBERNETES NETWORKING
options available. Furthermore, network policies offer of these events, such as network traffic, system calls, and
protection for layer 3 network controls between pod IP CPU and memory usages is useful both to identify attacks
addresses, but attacks over trusted IP addresses can only and to improve the overall performance of the cluster.
be detected with layer 7 network filtering, which requires As an example, sophisticated attacks consist of several
additional components. Finally, to the best of our knowl- steps (e.g., malicious network traffic, CPU overload, and
edge, there is no methodology or tool yet to automatically mounting sensitive directories): resources tracing may
compare network policies with the business logic of appli- allow detecting these steps or identifying attack patterns.
cations, other than manually verifying them. As of today, correlation of data from different sources
remains complex and has to be done with external tools.
Multitenant K8s Clusters
CVE-2020-8554, affecting multitenant K8s clusters, is No Audit of the Level of Security of Policies
not fully patched in K8s yet. An attacker who has per- K8s does not automatically audit the security level of
mission to create or edit services and pods can intercept policies in a cluster and the potential risks and vulnerabil-
network traffic from other pods or nodes, by creating a ities that may result from them. In particular, authentica-
ClusterIP service with an arbitrary IP address to which tion and authorization such as role-based access control
traffic is forwarded. Some plug-ins offer few counter- (RBAC) and service accounts, secrets management, net-
measures, but an attacker might still be able to succeed. work policies, pod security policies, general policies han-
dling the use of namespaces, and security options should
Dynamic Nature of K8s Objects be analyzed before deploying the cluster and exposing
It is a common practice to segment a network by its services to the outside. As an example, sensitive files
assigning subnets and separating them with firewalls in to audit include configuration files (/etc/K8s) of both
between. This approach cannot cope with the ephem- the master and worker nodes and user-defined policies.
eral nature of K8s objects: network rules based on IP
addresses are not very effective, since IP addresses of Mapping Attacks and Defenses
resources may keep changing; a classic firewall should at The ATT&CK (adversarial tactics, techniques, and
least define rules based on classless interdomain routing common knowledge) framework, created by MITRE
(CIDR) ranges and not specific addresses. Referring to in 2013, describes common techniques used by attack-
Figure 2, a firewall has the same network visibility of the ers to gain access into a system as well as their behavior
switch: It can be used to monitor ingress traffic, but it has (e.g., lateral movement and privilege escalation) follow-
no internal visibility over intrazones traffic. ing the intrusion, based on real-world observations of
attacks.MITRE also recently published the D&FEND
Virtual Network Infrastructure framework for security defenses. The ATT&CK frame-
As we explained in §IV, the K8s network infrastructure work has also been specialized to address security
is all virtual (i.e., software-defined via veth pairs or the threats relevant to containers.11 Albeit MITRE has not
Linux bridge), with no physical interfaces or cables con- yet released a more specialized K8s-related matrix, most
necting the different components. The attack surface K8s attack techniques can be mapped to the MITRE
and security issues of SDN have been widely studied framework. Indeed, Microsoft published in April 2020
(e.g., Dabbagh et al.4 and Yoon et al.5), but, to the best a K8s threat matrix8 based on the structure of MITRE’s
of our knowledge, similar studies on the K8s network ATT&CK framework that has been widely adopted to
do not exist. As an example, the K8s master node, by study and secure K8s deployments. Given prior collab-
default, is not replicated, which makes it a single-point- orations between Microsoft and MITRE, and the over-
of-failure, affecting other components, like the API lap between the Microsoft and the MITRE ATT&CK
server, the controller-manager, the scheduler, and the matrices, we suppose that the Microsoft matrix will be
etcd database. The database is also not replicated, by included in the MITRE ATT&CK framework, in the
default: if it becomes unavailable, it may not be possible near future. We opted, hence, to choose the Microsoft
to retrieve network policies or other settings. An outage matrix to describe the attack scenarios, as shown in
or attack on a single master node cluster would not stop Figure 3. In Table 2, we also summarize the security issues,
the cluster from working, but the cluster itself would and propose solutions for hardening K8s deployments
become unmanageable (i.e., it would be impossible to and link them to the MITRE D&FEND framework.
change configurations or create new objects).
Using Cloud Exec Into Backdoor Privileged Clear Container List K8s Access the K8s Access Cloud Image From a Data
Credentials Container Container Container Logs Secrets API Server Resources Private Registry Destruction
Compromised Bash/cmd Writable Container
Cluster-Admin Delete K8s Mount Service Access Resource
Images in Inside HostPath Service
Binding Events Principal Kubelet API Hijacking
Registry Container Mount Account
Kubeconfig New Kubernetes HostPath Pod/Container Access Container Network Cluster Internal Denial of
File Container Cronjob Mount Name Similarity Service Account Mapping Networking Service
Applications
Malicious Access Applications Access
Application Application Connect From Credentials in
Admission Cloud Credentials in Kubernetes
Vulnerability Exploit (RCE) Proxy Server Configuration
Controller Resources config. files Dashboard Files
SSH Server Access Managed Writable Volume
Exposed Instance
Running Identity Mounts on the
Dashboard Metadata API Host
Inside Container Credential
Exposed Malicious Access
Sidecar
Sensitive Admission Kubernetes
Injection
Interfaces Controller Dashboard
Legend
Access
Tiller
Scenario 1 Endpoint
CoreDNS
Scenario 2 Poisoning
ARP Poisoning
Scenario 3
and IP Spoofing
Figure 3. Mapping the example attack scenarios from Table 1 to the Microsoft K8s threat matrix8 adapted from MITRE’s ATT&CK framework.
53
54
Table 2. Main security challenges and mapping possible solutions in K8s networking to MITRE’s D&FEND Framework.
mutual authentication and enforcement of such configuration of containers to access the K8s API server. • Message encryption
both at the control- and practices both at cluster • Built-in K8s Secrets—store encrypted confidential • Disk encryption (e.g., for the
data-planes. and service levels so as information within a nonpublic centralized repository. datastore cluster)
to reduce human errors • (Centralized) Secret management to store and grant access • Certificate analysis
and the time to deploy to secrets.
correct security policies. • Service mesh solutions—use mutual TLS for transport
authentication, simplifying the management of keys,
certificates and configurations.
Access control Enforce fine-grained user- Provide the ability of • Built-in K8s RBAC—regulate permissions to access K8s • Mandatory access control
and application- access administrators to define resources (from pods to namespaces). (at network level)
policies to clusters by roles and manage control • Service mesh solutions—include a decentralized • Authentication event
providing least-privilege with greater granularity authorization framework for communications among thresholding
principles. than what is allowed containers. • Authorization event
today. • Identity providers tools—allow centralized management of thresholding
roles and access policies, including reporting and auditing • Resource access pattern
features. analysis
• Explicit rules inside clusters—restrict access between
pods and allow communications only between permitted
services.
Traffic Achieve defense-in- Provide in a declarative • NetworkPolicy API—provide firewall-like declarative rules. • Broadcast domain isolation
segmentation depth, limiting the lateral way, the expected model It presents high complexity and a few limitations (such as • Inbound/Outbound traffic
movements of a malicious of interaction between the pod-level granularity of policies). filtering
actor. the deployed services • Namespaces—isolate the K8s API resources environments • DNS allowlisting/denylisting
and then enforce its from each other. They do not have any effect on the
configuration without isolation of network and cluster resources.
breaking complex but • Service mesh–work at the application layer and can help to
desired networks paths. segment traffic; though cannot inspect the traffic.
• Virtual networks rules inside clusters–explicit virtual
network rules useful to segment traffic between pods.
(continued)
September/October 2021
Table 2. Main security challenges and mapping possible solutions in K8s networking to MITRE’s D&FEND Framework. (continued)
www.computer.org/security
anomalous and suspicious fingerprinting at runtime itself • Connection attempt analysis
behaviors. represent promising yet • Built-in K8s metrics-server–fetch individual container usage • DNS traffic analysis
not fully investigated statistics • Network traffic community
approaches to identify • Open source monitoring and logging engines–aggregate deviation
drift behaviors and process logs and metrics from different sources • Protocol metadata anomaly
providing a centralized repository for correlating events and detection
detecting problems
• Runtime security engines–detects unexpected application
behavior and alerts on threats at runtime by monitoring
system calls and comparing against security rules
Automated Automated triage and Extend deployment • Open source monitoring and logging engines–providing • Administrative network
remediation handling security alerts, automation to respond alerts and warnings of runtime events activity analysis
incidents and policy to security alerts (e.g., • Complex event process–identify and analyze cause and • Resource access pattern
violations. intentionally and effect relationship in real-time, connect with the automated analysis
proactively stopping then actions to be performed • System call analysis
restarting containers) • Automation engines and modules–define the playbooks
managing how security events are handled and connecting
to K8s nodes
Compliance & Follow industry best Extract evidence to • Benchmarks and best practice recommendations and • Software update
audit practices, standards, and demonstrate compliance, certification schemes–a set of recommendations for • Disk encryption (e.g., for the
internal security policies. risks indicators, and the configuring K8s in a secure way, including the certification datastore cluster)
efficient automation of of the cybersecurity of deployed services • Administrative network
such checks and evidence • K8s Audit logs–provide timestamped evidence on the state activity analysis
collection process of the K8s cluster and related user interactions • Resource access pattern
• Open source monitoring and logging engines–provide analysis
indicators on runtime events • System call analysis
55
KUBERNETES NETWORKING
of these abstractions. Understanding the design choices in in Proc. ICAS 2019 Adv. Intell. Syst. Comput., vol. 1158,
implementing these abstractions7 as well as their ramifica pp. 99–109, 2021.
tions for security is a key first step toward securing a K8s 11. “Containers matrix,” MITRE. Accessed: June 28, 2021.
(or any container-based) platform. We present a number [Online]. Available: https://attack.mitre.org/matrices/
of open challenges for the security community and hope enterprise/containers/
that this article spurs the community to address them.
Francesco Minna is a Ph.D. candidate at Vrije Univer-
Acknowledgments siteit Amsterdam, 1081 HV, The Netherlands. His
We thank the reviewers and IEEE Security & Privacy’s research interests include cloud security and dynamic
Editor in Chief Sean Peisert for their comments that greatly risk analysis for free and open source software. Minna
helped to improve this article. Any remaining error is our received a double master’s in cybersecurity in from
fault. This work has received funding by the European the University of Trento and the University of Rennes.
Union under the H2020 grant 952647 (AssureMOSS). Contact him at f.minna@vu.nl.