Kubeconfig File Creation or Modification
The kubeconfig file is a critical component in Kubernetes environments, containing configuration details for accessing and managing Kubernetes clusters. Attackers may attempt to get access to, create or modify kubeconfig files to gain unauthorized initial access to Kubernetes clusters or move laterally within the cluster.
Elastic rule (View on GitHub)
1[metadata]
2creation_date = "2025/06/17"
3integration = ["endpoint"]
4maturity = "production"
5updated_date = "2025/07/07"
6
7[rule]
8author = ["Elastic"]
9description = """
10The kubeconfig file is a critical component in Kubernetes environments, containing configuration
11details for accessing and managing Kubernetes clusters. Attackers may attempt to get access to,
12create or modify kubeconfig files to gain unauthorized initial access to Kubernetes clusters or
13move laterally within the cluster.
14"""
15from = "now-9m"
16index = ["logs-endpoint.events.file*"]
17language = "eql"
18license = "Elastic License v2"
19name = "Kubeconfig File Creation or Modification"
20note = """ ## Triage and analysis
21
22> **Disclaimer**:
23> This investigation guide was created using generative AI technology and has been reviewed to improve its accuracy and relevance. While every effort has been made to ensure its quality, we recommend validating the content and adapting it to suit your specific environment and operational needs.
24
25### Investigating Kubeconfig File Creation or Modification
26Kubeconfig files are essential in Kubernetes environments, storing configurations for cluster access and management. Adversaries may target these files to gain unauthorized access or move laterally within clusters. The detection rule identifies suspicious creation or modification of kubeconfig files, excluding legitimate processes like kubeadm and minikube, to flag potential threats and mitigate risks associated with unauthorized access.
27
28### Possible investigation steps
29
30- Review the alert details to identify the specific file path involved in the creation or modification event, focusing on paths like "/root/.kube/config" or "/etc/kubernetes/admin.conf".
31- Examine the process responsible for the file creation or modification, ensuring it is not one of the excluded legitimate processes such as "kubeadm", "kubelet", "vcluster", or "minikube".
32- Check the user account associated with the process to determine if it has legitimate access to modify kubeconfig files and assess if the activity aligns with typical user behavior.
33- Investigate the timing of the event to see if it coincides with any scheduled maintenance or deployment activities that could explain the modification.
34- Look for any related alerts or logs that might indicate lateral movement or unauthorized access attempts within the Kubernetes cluster.
35- Assess the network activity from the host where the modification occurred to identify any suspicious connections or data transfers that could suggest unauthorized access or exfiltration.
36
37### False positive analysis
38
39- Legitimate administrative tools like kubeadm, kubelet, vcluster, and minikube may create or modify kubeconfig files as part of normal operations. Ensure these processes are excluded from triggering alerts by maintaining the exclusion list in the detection rule.
40- Automated scripts or configuration management tools that use sed to modify kubeconfig files might be flagged. Consider adding specific script names or paths to the exclusion list if they are verified as non-threatening.
41- User-initiated changes to kubeconfig files for legitimate access or configuration updates can trigger alerts. Implement a process to verify and document such changes, allowing for quick exclusion of known user actions.
42- Regular updates or maintenance activities that involve kubeconfig file modifications should be documented and excluded from detection. Coordinate with the operations team to identify and whitelist these activities.
43- Development environments where frequent kubeconfig changes occur, such as in testing or staging, may generate false positives. Establish a separate monitoring policy for these environments to reduce noise while maintaining security oversight.
44
45### Response and remediation
46
47- Immediately isolate the affected system to prevent further unauthorized access or lateral movement within the Kubernetes cluster.
48- Revoke any potentially compromised credentials associated with the kubeconfig files and issue new credentials to ensure secure access.
49- Conduct a thorough review of recent access logs and audit trails to identify any unauthorized access or suspicious activity related to the kubeconfig files.
50- Restore the kubeconfig files from a known good backup to ensure the integrity of the configuration and access settings.
51- Implement additional monitoring and alerting for any future modifications to kubeconfig files, focusing on processes not typically involved in legitimate changes.
52- Escalate the incident to the security operations team for further investigation and to assess the potential impact on the broader Kubernetes environment.
53- Review and update Kubernetes access policies to ensure they align with best practices for security and least privilege, reducing the risk of unauthorized access.
54"""
55references = [
56 "https://kubernetes-threat-matrix.redguard.ch/initial-access/kubeconfig-file/",
57 "https://kubenomicon.com/Initial_access/Kubeconfig_file.html",
58 ]
59risk_score = 47
60rule_id = "b11116fd-023c-4718-aeb8-fa9d283fc53b"
61setup = """## Setup
62
63This rule requires data coming in from Elastic Defend.
64
65### Elastic Defend Integration Setup
66Elastic Defend is integrated into the Elastic Agent using Fleet. Upon configuration, the integration allows the Elastic Agent to monitor events on your host and send data to the Elastic Security app.
67
68#### Prerequisite Requirements:
69- Fleet is required for Elastic Defend.
70- To configure Fleet Server refer to the [documentation](https://www.elastic.co/guide/en/fleet/current/fleet-server.html).
71
72#### The following steps should be executed in order to add the Elastic Defend integration on a Linux System:
73- Go to the Kibana home page and click "Add integrations".
74- In the query bar, search for "Elastic Defend" and select the integration to see more details about it.
75- Click "Add Elastic Defend".
76- Configure the integration name and optionally add a description.
77- Select the type of environment you want to protect, either "Traditional Endpoints" or "Cloud Workloads".
78- Select a configuration preset. Each preset comes with different default settings for Elastic Agent, you can further customize these later by configuring the Elastic Defend integration policy. [Helper guide](https://www.elastic.co/guide/en/security/current/configure-endpoint-integration-policy.html).
79- We suggest selecting "Complete EDR (Endpoint Detection and Response)" as a configuration setting, that provides "All events; all preventions"
80- Enter a name for the agent policy in "New agent policy name". If other agent policies already exist, you can click the "Existing hosts" tab and select an existing policy instead.
81
82For more details on Elastic Agent configuration settings, refer to the [helper guide](https://www.elastic.co/guide/en/fleet/8.10/agent-policy.html).
83- Click "Save and Continue".
84- To complete the integration, select "Add Elastic Agent to your hosts" and continue to the next section to install the Elastic Agent on your hosts.
85For more details on Elastic Defend refer to the [helper guide](https://www.elastic.co/guide/en/security/current/install-endpoint.html).
86"""
87severity = "medium"
88tags = [
89 "Domain: Endpoint",
90 "Domain: Container",
91 "Domain: Kubernetes",
92 "OS: Linux",
93 "Use Case: Threat Detection",
94 "Tactic: Lateral Movement",
95 "Tactic: Defense Evasion",
96 "Tactic: Initial Access",
97 "Data Source: Elastic Defend",
98 "Resources: Investigation Guide",
99]
100timestamp_override = "event.ingested"
101type = "eql"
102query = '''
103file where host.os.type == "linux" and event.type != "deletion" and file.path like (
104 "/root/.kube/config",
105 "/home/*/.kube/config",
106 "/etc/kubernetes/admin.conf",
107 "/etc/kubernetes/super-admin.conf",
108 "/etc/kubernetes/kubelet.conf",
109 "/etc/kubernetes/controller-manager.conf",
110 "/etc/kubernetes/scheduler.conf",
111 "/var/lib/*/kubeconfig"
112) and not (
113 process.name in ("kubeadm", "kubelet", "vcluster", "minikube") or
114 (process.name == "sed" and file.Ext.original.name like "sed*")
115)
116'''
117
118[[rule.threat]]
119framework = "MITRE ATT&CK"
120
121[[rule.threat.technique]]
122id = "T1550"
123name = "Use Alternate Authentication Material"
124reference = "https://attack.mitre.org/techniques/T1550/"
125
126[rule.threat.tactic]
127id = "TA0008"
128name = "Lateral Movement"
129reference = "https://attack.mitre.org/tactics/TA0008/"
130
131[[rule.threat]]
132framework = "MITRE ATT&CK"
133
134[[rule.threat.technique]]
135id = "T1550"
136name = "Use Alternate Authentication Material"
137reference = "https://attack.mitre.org/techniques/T1550/"
138
139[rule.threat.tactic]
140id = "TA0005"
141name = "Defense Evasion"
142reference = "https://attack.mitre.org/tactics/TA0005/"
143
144[[rule.threat]]
145framework = "MITRE ATT&CK"
146
147[rule.threat.tactic]
148id = "TA0001"
149name = "Initial Access"
150reference = "https://attack.mitre.org/tactics/TA0001/"
151
152[[rule.threat.technique]]
153id = "T1078"
154name = "Valid Accounts"
155reference = "https://attack.mitre.org/techniques/T1078/"
Triage and analysis
Disclaimer: This investigation guide was created using generative AI technology and has been reviewed to improve its accuracy and relevance. While every effort has been made to ensure its quality, we recommend validating the content and adapting it to suit your specific environment and operational needs.
Investigating Kubeconfig File Creation or Modification
Kubeconfig files are essential in Kubernetes environments, storing configurations for cluster access and management. Adversaries may target these files to gain unauthorized access or move laterally within clusters. The detection rule identifies suspicious creation or modification of kubeconfig files, excluding legitimate processes like kubeadm and minikube, to flag potential threats and mitigate risks associated with unauthorized access.
Possible investigation steps
- Review the alert details to identify the specific file path involved in the creation or modification event, focusing on paths like "/root/.kube/config" or "/etc/kubernetes/admin.conf".
- Examine the process responsible for the file creation or modification, ensuring it is not one of the excluded legitimate processes such as "kubeadm", "kubelet", "vcluster", or "minikube".
- Check the user account associated with the process to determine if it has legitimate access to modify kubeconfig files and assess if the activity aligns with typical user behavior.
- Investigate the timing of the event to see if it coincides with any scheduled maintenance or deployment activities that could explain the modification.
- Look for any related alerts or logs that might indicate lateral movement or unauthorized access attempts within the Kubernetes cluster.
- Assess the network activity from the host where the modification occurred to identify any suspicious connections or data transfers that could suggest unauthorized access or exfiltration.
False positive analysis
- Legitimate administrative tools like kubeadm, kubelet, vcluster, and minikube may create or modify kubeconfig files as part of normal operations. Ensure these processes are excluded from triggering alerts by maintaining the exclusion list in the detection rule.
- Automated scripts or configuration management tools that use sed to modify kubeconfig files might be flagged. Consider adding specific script names or paths to the exclusion list if they are verified as non-threatening.
- User-initiated changes to kubeconfig files for legitimate access or configuration updates can trigger alerts. Implement a process to verify and document such changes, allowing for quick exclusion of known user actions.
- Regular updates or maintenance activities that involve kubeconfig file modifications should be documented and excluded from detection. Coordinate with the operations team to identify and whitelist these activities.
- Development environments where frequent kubeconfig changes occur, such as in testing or staging, may generate false positives. Establish a separate monitoring policy for these environments to reduce noise while maintaining security oversight.
Response and remediation
- Immediately isolate the affected system to prevent further unauthorized access or lateral movement within the Kubernetes cluster.
- Revoke any potentially compromised credentials associated with the kubeconfig files and issue new credentials to ensure secure access.
- Conduct a thorough review of recent access logs and audit trails to identify any unauthorized access or suspicious activity related to the kubeconfig files.
- Restore the kubeconfig files from a known good backup to ensure the integrity of the configuration and access settings.
- Implement additional monitoring and alerting for any future modifications to kubeconfig files, focusing on processes not typically involved in legitimate changes.
- Escalate the incident to the security operations team for further investigation and to assess the potential impact on the broader Kubernetes environment.
- Review and update Kubernetes access policies to ensure they align with best practices for security and least privilege, reducing the risk of unauthorized access.
References
Related rules
- Potential Kubectl Masquerading via Unexpected Process
- Kubeconfig File Discovery
- Kubectl Network Configuration Modification
- Kubectl Permission Discovery
- Kubernetes Direct API Request via Curl or Wget