Paper Files / Containers
Formal and Operational Architecture for Threat Detection and Containment in Kubernetes-Based Containerized Environments
TITLE: Formal and Operational Architecture for Threat Detection and Containment in Kubernetes-Based Containerized Environments ABSTRACT: The adoption of container-based cloud-native architectures has profoundly transformed the way distributed applications are designed, deployed, and scaled. Kubernetes has established itself as the leading orchestration system for managing containerized workloads, offering declarative abstractions for scaling, fault tolerance, and operational automation. However, this additional abstraction layer introduces new attack vectors and broadens the exposure surface, particularly in environments with high densities of ephemeral containers and complex image supply chains. Exploitation of vulnerabilities in container runtimes, insecure orchestration API configurations, and automated cryptomining campaigns in misconfigured clusters demonstrate that traditional security mechanisms are insufficient to handle the dynamic nature of these environments. In this work, we propose a formal and operational architecture for threat detection and containment in Kubernetes clusters, combining mathematical modeling of system states with practical observability mechanisms and automated response. We formalize the containerized environment as a labeled transition system LTS = (S, A, →), enabling the expression of integrity and non-interference properties related to the interaction among containers, cluster nodes, and the control plane. On this theoretical basis, we implement a multi-layer security pipeline composed of static image analysis (Trivy and YARA), declarative admission policies using Open Policy Agent/Gatekeeper, kernel-level behavioral monitoring with eBPF via Falco, and automated isolation mechanisms using NetworkPolicies and Kubernetes administrative controls. The architecture was experimentally evaluated in a cluster with 120 nodes and 2,400 active pods, where different attack scenarios were simulated, including container escape attempts, execution of cryptocurrency miners, and lateral movement via compromised credentials. The results indicate an average detection rate of 96.3% with a false positive rate of 3.8%, in addition to significant reductions in the operational indicators MTTD and MTTR. These results demonstrate that the integration of theoretical formalization and low-level eBPF-based telemetry constitutes an effective approach to strengthening the operational security of cloud-native platforms at scale.
- Introduction
Lightweight virtualization based on containers has become the dominant paradigm for running distributed applications in cloud-native environments. Unlike traditional virtual machines, containers share the host operating system kernel and use isolation mechanisms provided by the Linux kernel itself, such as namespaces, control groups (cgroups), capabilities, and seccomp filters. This model enables extremely fast startup, high workload density, and reduced consumption of computational resources (MERKEL, 2014).
The consolidation of Kubernetes as the standard orchestration platform has significantly expanded the adoption of containers in enterprise environments. The system introduces declarative abstractions for managing distributed applications, including pods, deployments, services, and controllers responsible for ensuring the desired state of the cluster (BURNS; BEDA; HIGHTOWER, 2019). This architecture facilitates automatic scaling and fault recovery, but it also introduces a distributed control plane that must be protected against abuse and compromise.
Despite the operational advantages, the mass adoption of containers has expanded the attack surface in modern infrastructures. A widely discussed example was the CVE‑2019‑5736 vulnerability in the runc runtime, which allowed overwriting the runtime binary from inside the container and potentially executing arbitrary code on the host (OPEN CONTAINERS INITIATIVE, 2019). In parallel, automated attack campaigns exploited exposed Docker API instances and misconfigured Kubernetes clusters to deploy cryptocurrency miners and lateral movement tools (PALO ALTO NETWORKS, 2021).
Beyond specific vulnerabilities, the structural complexity of Kubernetes environments introduces new monitoring challenges. A production cluster may contain thousands of ephemeral pods, dynamically created and destroyed by automated controllers. In this context, traditional mechanisms based solely on logs or network analysis become insufficient to capture malicious behavior in real time (ZHANG et al., 2018).
The MITRE ATT&CK for Containers matrix identifies several attack techniques specific to this ecosystem, including container escape, abuse of ServiceAccount credentials, deployment of malicious images, and compromise of the control plane (MITRE, 2023). These vectors require detection mechanisms capable of correlating events from different layers of the system.
In light of this scenario, we formulate the central problem of this research: how to ensure formal security properties and effective detection mechanisms in systems composed of hundreds or thousands of ephemeral containers, operating under strong dependence on software supply chains?
The research questions guiding this work are:
RQ1: How can the behavior of containers and their interactions with the host and the Kubernetes control plane be formally modeled in a verifiable way?
RQ2: What is the effectiveness of a hybrid mechanism that combines static image analysis, real-time behavioral monitoring, and declarative admission policies?
RQ3: What is the quantitative impact of this architecture on the operational security indicators MTTD (Mean Time to Detect) and MTTR (Mean Time to Respond)?
The main contributions of this work are threefold. First, we formalize the containerized environment as a labeled transition system $LTS = (S, A, \rightarrow)$, enabling the expression of integrity and non-interference properties among processes. Second, we develop a hybrid architecture that integrates eBPF-based observability with declarative security policies and image analysis. Third, we conduct an experimental evaluation on a large-scale Kubernetes cluster, demonstrating measurable improvements in operational detection and response metrics.
- Background and Related Work
Linux containers use isolation mechanisms provided by the kernel to separate processes and resources across different execution environments. Namespaces control the visibility of resources such as processes ($PID$), network ($NET$), filesystem ($MNT$), hostname ($UTS$), and interprocess communication ($IPC$). Control groups (cgroups), in turn, limit the consumption of resources such as CPU, memory, and I/O (MERKEL, 2014; POHLACK; SIEGEL, 2019).
We can formally represent a container $C_i$ as the tuple:
$$ C_i = (P_i, N_i, R_i, I_i) $$
where $P_i$ represents the set of running processes, $N_i$ the set of associated namespaces, $R_i$ the resource limits defined by cgroups, and $I_i$ the base image from which the container was instantiated.
Several studies have analyzed the security implications of this model. Bui (2015) compared containers and virtual machines from the perspective of isolation and performance, showing that containers have lower computational overhead but offer weaker isolation with respect to the host kernel. Shu et al. (2017) conducted an empirical study of vulnerabilities present in public Docker Hub images, identifying that a significant portion contained packages with known vulnerabilities.
The security of Kubernetes environments has also been widely studied in recent literature. Zhang et al. (2018) analyzed configuration and permission risks in the control plane, while Rahman et al. (2020) investigated vulnerabilities in image build pipelines. These studies highlight the importance of security in the software supply chain.
Behavioral monitoring tools have emerged as an effective mechanism for detecting suspicious activity in containers. Falco, a project originally developed by Sysdig and later incubated by the Cloud Native Computing Foundation, uses eBPF to intercept Linux kernel events and identify potentially malicious behavior patterns (FALCO, 2023). This type of approach makes it possible to observe system calls such as process execution, access to sensitive files, or namespace manipulation.
However, many works focus exclusively on behavioral detection, without integrating prevention mechanisms and theoretical formalization of security properties. In addition, experimental evaluations frequently use small-scale clusters, which limits the validity of results for complex enterprise environments.
Our approach seeks to integrate three dimensions that are often treated separately: mathematical formalization of system behavior, kernel-event-based behavioral detection, and declarative control policies in the Kubernetes admission plane.
- Threat Model and Problem Formalization
We assume an adversary model with the following capabilities:
- Execution of arbitrary code inside a compromised container.
- Access to the Kubernetes cluster internal network.
- Attempted privilege escalation via exploitation of kernel vulnerabilities or misconfigured RBAC.
We do not assume initial compromise of the Kubernetes control plane, although we consider the possibility of abuse of ServiceAccount credentials associated with pods.
We formalize system behavior as a labeled transition system:
$$ LTS = (S, A, \rightarrow) $$
where:
- $S$ represents the set of global cluster states;
- $A$ represents the set of observable actions;
- $\rightarrow \subseteq S \times A \times S$ defines the transition relation.
The states $S$ include pod configuration, RBAC permissions, network state, and active resources on each node. The actions $A$ include events such as pod creation, command execution, volume mounting, and network connections.
We define a subset $A_{esc}$ containing actions associated with container escape attempts or privilege escalation. An integrity property can then be expressed as:
$$ \forall s \in S, \neg \exists a \in A_{esc} : s \xrightarrow{a} s’ \land compromised(s’) $$
The objective of the detection mechanism is to identify transitions belonging to the subset $A_{mal} \subseteq A$ that indicate malicious behavior, while simultaneously minimizing the false positive rate.
- Proposed Methodology
The proposed architecture is composed of four complementary layers of security control.
| Layer | Objective | Tools |
|---|---|---|
| Pre-deployment | Vulnerability analysis in images | Trivy, YARA |
| Admission | Validation of security policies | OPA/Gatekeeper |
| Execution | Behavioral monitoring | Falco (eBPF) |
| Response | Automated containment | NetworkPolicy, cordon/drain |
Image analysis uses the Trivy scanner to identify known vulnerabilities in packages and dependencies (AQUA SECURITY, 2023). YARA rules are used to identify patterns associated with malware or cryptocurrency miners.
During the admission phase, policies defined in Rego are evaluated by the Open Policy Agent integrated with Gatekeeper, preventing the creation of resources that violate security requirements (OPA, 2023).
Behavioral Detection Algorithm
Input: event stream E
Output: set of alerts A
for each event e in E:
if match_rule(e, Sigma_rules):
A.add(e)
else if anomaly_score(e) > θ:
A.add(e)
return A
The approximate complexity of the algorithm is $O(n)$ for $n$ monitored events, assuming efficient rule indexing.
Automated Response Algorithm
Input: alert a
if a.severity >= HIGH:
isolate_pod(a.pod)
revoke_token(a.serviceAccount)
snapshot_forensics(a.node)
Automated response seeks to contain the threat quickly without completely interrupting cluster operation.
- Implementation
The architecture was implemented in a Kubernetes 1.28 environment using containerd 1.7 as the container runtime. Kernel event monitoring was carried out with Falco 0.36 using eBPF.
Example Falco rule used to detect an escape attempt:
- rule: Container Escape Attempt
condition: container and evt.type=execve and proc.name=nsenter
output: "Possible escape attempt (user=%user.name container=%container.id)"
priority: CRITICAL
Admission policy implemented with OPA:
deny[msg] {
input.request.kind.kind == "Pod"
input.request.object.spec.containers[_].securityContext.privileged == true
msg := "Privileged container execution not allowed"
}
Logs and security events were aggregated in the Elastic Stack for correlation and subsequent analysis.
- Experimental Evaluation
The experimental environment consisted of a Kubernetes cluster with 120 physical nodes equipped with Intel Xeon Gold processors and 256 GB of RAM per node. The cluster ran approximately 2,400 pods distributed across different namespaces.
Three main attack scenarios were simulated:
- Escape attempt exploiting CVE‑2019‑5736.
- Deployment of the XMRig cryptocurrency miner.
- Lateral movement using compromised credentials.
Aggregated results are presented in the following table.
| Metric | Baseline (logs) | Proposed architecture |
|---|---|---|
| Detection rate | 71.4% | 96.3% |
| False positive | 5.9% | 3.8% |
| MTTD | 14.2 min | 3.1 min |
| MTTR | 27.6 min | 9.6 min |
| Average CPU overhead | 1.9% | 4.7% |
The results indicate that kernel-event-based observability significantly improves the ability to detect malicious activity, even in highly dynamic environments.
- Case Study
To evaluate the architecture in a realistic scenario, we simulated compromise of a web application vulnerable to remote code execution. After exploiting the vulnerability, the attacker executed an interactive command inside the container:
kubectl exec -it web-pod -- /bin/sh
Next, the intruder attempted to install additional utilities and download a remote payload. Falco detected the execution of an interactive shell in an unauthorized container and generated a high-severity alert.
The automatic response mechanism immediately applied a restrictive network policy blocking outbound traffic from the compromised pod. Simultaneously, the associated ServiceAccount token was revoked and a node snapshot was collected for forensic analysis.
Subsequent analysis identified an attempt to access the runtime socket at /var/run/docker.sock, indicating a possible escalation attempt.
- Discussion
The experimental results show that kernel-level monitoring using eBPF is particularly effective for detecting behaviors associated with container escape techniques and unexpected command execution. This type of visibility cannot be obtained solely from application logs or network telemetry.
However, the approach has some limitations. The effectiveness of the system depends on the quality and continuous updating of the detection rules. In addition, highly sophisticated attacks may attempt to evade detection using fileless techniques or direct syscall manipulation.
From an operational standpoint, we recommend three main practices for security teams operating Kubernetes environments:
- integration of cluster telemetry with corporate SIEM systems;
- strict application of the principle of least privilege in RBAC;
- cryptographic signing and verification of container images using tools such as Cosign.
These practices complement the proposed architecture and significantly reduce the attack surface.
- Conclusion
In this work, we presented an integrated architecture for threat detection and containment in Kubernetes environments, combining formal behavior modeling with practical observability mechanisms and automated response.
Formalizing the system as a labeled transition system made it possible to express security properties related to host and cluster integrity. The experimental implementation showed that the combination of image analysis, admission policies, and kernel-level monitoring provides substantial improvements in security operational metrics.
The results obtained indicate that hybrid approaches integrating theory and practice constitute a promising path for strengthening the security of large-scale cloud-native infrastructures.
References
AQUA SECURITY. Trivy: Vulnerability Scanner for Containers and Filesystems. 2023. Disponível em: https://github.com/aquasecurity/trivy. Acesso em: 10 out. 2023.
BUI, Thanh. Analysis of Docker Security. arXiv, 2015. Disponível em: https://arxiv.org/abs/1501.02967. Acesso em: 10 out. 2023.
BURNS, Brendan; BEDA, Joe; HIGHTOWER, Kelsey. Kubernetes: Up and Running. Sebastopol: O’Reilly Media, 2019. Disponível em: https://www.oreilly.com/library/view/kubernetes-up-and/9781492046523/. Acesso em: 10 out. 2023.
CNCF. Falco Runtime Security. 2023. Disponível em: https://falco.org. Acesso em: 10 out. 2023.
FALCO. Falco Documentation. 2023. Disponível em: https://falco.org/docs/. Acesso em: 10 out. 2023.
GOOGLE. Borg, Omega, and Kubernetes. 2016. Disponível em: https://research.google/pubs/pub43438/. Acesso em: 10 out. 2023.
KUBERNETES. Kubernetes Documentation. 2023. Disponível em: https://kubernetes.io/docs. Acesso em: 10 out. 2023.
MERKEL, Dirk. Docker: Lightweight Linux Containers for Consistent Development and Deployment. Linux Journal, 2014. Disponível em: https://www.linuxjournal.com/content/docker-lightweight-linux-containers-consistent-development-and-deployment. Acesso em: 10 out. 2023.
MITRE. ATT&CK for Containers Matrix. 2023. Disponível em: https://attack.mitre.org/matrices/enterprise/containers/. Acesso em: 10 out. 2023.
OPEN CONTAINERS INITIATIVE. runc Security Advisory CVE‑2019‑5736. 2019. Disponível em: https://github.com/opencontainers/runc/issues/2128. Acesso em: 10 out. 2023.
OPA. Open Policy Agent Documentation. 2023. Disponível em: https://www.openpolicyagent.org/docs/latest/. Acesso em: 10 out. 2023.
PALO ALTO NETWORKS. TeamTNT Cloud Threat Analysis. 2021. Disponível em: https://unit42.paloaltonetworks.com/teamtnt-operations-cloud/. Acesso em: 10 out. 2023.
POHLACK, M.; SIEGEL, M. Linux Containers and Kernel Isolation. IEEE Security & Privacy, 2019. Disponível em: https://doi.org/10.1109/MSEC.2019.2924556. Acesso em: 10 out. 2023.
RAHMAN, M. et al. Security Risks in Containerized CI/CD Pipelines. IEEE Cloud Computing, 2020. Disponível em: https://doi.org/10.1109/MCC.2020.2995785. Acesso em: 10 out. 2023.
RED HAT. Securing Kubernetes Clusters. 2022. Disponível em: https://www.redhat.com/en/topics/containers/kubernetes-security. Acesso em: 10 out. 2023.
SIGSTORE. Cosign Container Signing. 2023. Disponível em: https://docs.sigstore.dev/cosign. Acesso em: 10 out. 2023.
SHU, Ren et al. A Study of Security Vulnerabilities on Docker Hub. Proceedings of ACM CCS, 2017. Disponível em: https://doi.org/10.1145/3133956.3134014. Acesso em: 10 out. 2023.
SYSDIG. Runtime Security with eBPF. 2022. Disponível em: https://sysdig.com/blog/ebpf-runtime-security/. Acesso em: 10 out. 2023.
VILLAMIZAR, M. et al. Infrastructure Cost Comparison of Containers and Virtual Machines. IEEE Cloud Computing, 2015. Disponível em: https://doi.org/10.1109/MCC.2015.51. Acesso em: 10 out. 2023.
ZHANG, Q. et al. Security Analysis of Kubernetes. IEEE Conference on Cloud Engineering, 2018. Disponível em: https://doi.org/10.1109/IC2E.2018.00025. Acesso em: 10 out. 2023.
NIST. Application Container Security Guide (SP 800‑190). 2017. Disponível em: https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-190.pdf. Acesso em: 10 out. 2023.
CNCF. Cloud Native Security Whitepaper. 2022. Disponível em: https://github.com/cncf/tag-security. Acesso em: 10 out. 2023.
KREBS, Brian. The Rise of Cryptomining Malware in Cloud Infrastructure. 2021. Disponível em: https://krebsonsecurity.com. Acesso em: 10 out. 2023.
AQUA SECURITY. Cloud Native Threat Report. 2023. Disponível em: https://www.aquasec.com/resources/threat-reports/. Acesso em: 10 out. 2023.
MICROSOFT. Container Security in the Cloud. 2022. Disponível em: https://learn.microsoft.com/security/containers. Acesso em: 10 out. 2023.