Container Image Built Inside a Container
This rule detects a container image being built from inside a running container using a container build utility such as "docker build", "buildah", "buildctl", "img", or "nerdctl build". Building an image on the host (or inside a pod) bypasses defenses that monitor for the retrieval of malicious images from a public registry, allowing an adversary to assemble and run tooling without pulling a flagged image. Nested image builds inside a Kubernetes pod are rarely legitimate outside of dedicated CI/build namespaces.
Elastic rule (View on GitHub)
1[metadata]
2creation_date = "2026/11/13"
3integration = ["cloud_defend"]
4maturity = "production"
5min_stack_comments = "Defend for Containers integration was re-introduced in 9.3.0"
6min_stack_version = "9.3.0"
7updated_date = "2026/11/13"
8
9[rule]
10author = ["Elastic"]
11description = """
12This rule detects a container image being built from inside a running container using a container build utility such as
13"docker build", "buildah", "buildctl", "img", or "nerdctl build". Building an image on the host (or inside a pod)
14bypasses defenses that monitor for the retrieval of malicious images from a public registry, allowing an adversary to
15assemble and run tooling without pulling a flagged image. Nested image builds inside a Kubernetes pod are rarely
16legitimate outside of dedicated CI/build namespaces.
17"""
18false_positives = [
19 """
20 CI/CD and image-build pipelines (for example Tekton, Argo Workflows, Jenkins, or Kaniko builders) legitimately build
21 images inside pods. Baseline the build namespaces and service accounts used for those pipelines and add exceptions
22 by "orchestrator.namespace".
23 """,
24]
25from = "now-6m"
26interval = "5m"
27language = "esql"
28license = "Elastic License v2"
29name = "Container Image Built Inside a Container"
30note = """## Setup
31
32This rule requires the Elastic Defend for Containers integration to be configured to collect container process events.
33
34## Triage and analysis
35
36### Investigating Container Image Built Inside a Container
37
38Adversaries build a container image directly inside a running container or pod to bypass defenses that inspect images pulled from a registry. Using "docker build" (or buildah/buildctl/img/nerdctl) they assemble an image locally from a Dockerfile and then run it, avoiding registry scanning and admission controls. Outside of dedicated CI/build workloads this is a strong indicator of hands-on-keyboard activity.
39
40### Possible investigation steps
41
42- Identify the container (`container.id`, `container.name`) and namespace (`orchestrator.namespace`) and determine whether it is a sanctioned build/CI workload.
43- Review the full command line (`process.args`) for the build context, Dockerfile path, and resulting image tag.
44- Examine the parent process (`process.parent.name`, `process.parent.executable`) to determine whether the build was launched interactively.
45- Correlate with follow-on activity such as the newly built image being run, pushed, or used to deploy a privileged or host-namespaced pod.
46
47### False positive analysis
48
49- Dedicated CI/build namespaces (Tekton, Argo, Jenkins, Kaniko) build images routinely. Baseline those namespaces and service accounts and add exceptions by `orchestrator.namespace`.
50
51### Response and remediation
52
53- If unexpected, isolate the container, capture the build context and Dockerfile, and identify what the resulting image was used for.
54- Remove the built image, redeploy affected workloads from trusted images, and tighten RBAC/admission controls to prevent in-cluster image builds outside approved pipelines.
55"""
56references = [
57 "https://attack.mitre.org/techniques/T1612/",
58 "https://github.com/redcanaryco/atomic-red-team/blob/master/atomics/T1612/T1612.md",
59]
60risk_score = 47
61rule_id = "daa0d56b-9149-475c-8bf7-bce8a337eed8"
62severity = "medium"
63tags = [
64 "Data Source: Elastic Defend for Containers",
65 "Domain: Containers",
66 "OS: Linux",
67 "Use Case: Threat Detection",
68 "Tactic: Defense Evasion",
69 "Resources: Investigation Guide",
70 "Rule Type: ES|QL",
71 "Platform: Linux",
72 "Platform: Kubernetes",
73]
74timestamp_override = "event.ingested"
75type = "esql"
76
77query = '''
78from logs-cloud_defend.process* metadata _id, _index, _version
79| where host.os.type == "linux" and event.type == "start" and event.action == "exec" and
80 container.id like "*" and
81 process.name in ("docker", "docker-buildx", "buildah", "buildctl", "img", "nerdctl") and
82 kql("""process.args: ("build" or "bud")""")
83| keep @timestamp, host.id, container.id, process.name, process.args, process.parent.name, process.parent.executable, user.id, _id, _index, _version
84'''
85
86
87[[rule.threat]]
88framework = "MITRE ATT&CK"
89[[rule.threat.technique]]
90id = "T1612"
91name = "Build Image on Host"
92reference = "https://attack.mitre.org/techniques/T1612/"
93
94
95[rule.threat.tactic]
96id = "TA0005"
97name = "Defense Evasion"
98reference = "https://attack.mitre.org/tactics/TA0005/"
Setup
This rule requires the Elastic Defend for Containers integration to be configured to collect container process events.
Triage and analysis
Investigating Container Image Built Inside a Container
Adversaries build a container image directly inside a running container or pod to bypass defenses that inspect images pulled from a registry. Using "docker build" (or buildah/buildctl/img/nerdctl) they assemble an image locally from a Dockerfile and then run it, avoiding registry scanning and admission controls. Outside of dedicated CI/build workloads this is a strong indicator of hands-on-keyboard activity.
Possible investigation steps
- Identify the container (
container.id,container.name) and namespace (orchestrator.namespace) and determine whether it is a sanctioned build/CI workload. - Review the full command line (
process.args) for the build context, Dockerfile path, and resulting image tag. - Examine the parent process (
process.parent.name,process.parent.executable) to determine whether the build was launched interactively. - Correlate with follow-on activity such as the newly built image being run, pushed, or used to deploy a privileged or host-namespaced pod.
False positive analysis
- Dedicated CI/build namespaces (Tekton, Argo, Jenkins, Kaniko) build images routinely. Baseline those namespaces and service accounts and add exceptions by
orchestrator.namespace.
Response and remediation
- If unexpected, isolate the container, capture the build context and Dockerfile, and identify what the resulting image was used for.
- Remove the built image, redeploy affected workloads from trusted images, and tighten RBAC/admission controls to prevent in-cluster image builds outside approved pipelines.
References
Related rules
- Scheduled Job Creation via At Utility Inside a Container
- Kubeconfig File Creation or Modification
- Potential Impersonation Attempt via Kubectl
- Potential Kubectl Masquerading via Unexpected Process
- Container Management Utility Execution Detected via Defend for Containers