D07 Eks Audit Discovery
Query
// REVIEW ONLY - Mandatory Step 1: EKS Audit Destination Table & Kubernetes Audit Schema Discovery (P1-4 / 8.9)
// IMPORTANT: Microsoft Sentinel does NOT have a fixed built-in AWSEKSAudit table. EKS control-plane audit logs
// (/aws/eks/<cluster>/cluster) land either in AWSCloudWatch (JSON in Message) or a custom DCR table (*EKS*_CL).
// Run this discovery query FIRST to locate your EKS audit stream and inspect its exact JSON keys!
AWSCloudWatch
| where TimeGenerated > ago(24h)
| where Message has "\"kind\":\"Event\"" and Message has "audit.k8s.io/"
| extend ParsedAudit = parse_json(Message)
| extend TopKeys = bag_keys(ParsedAudit),
UserKeys = bag_keys(ParsedAudit.user),
ObjectRefKeys = bag_keys(ParsedAudit.objectRef),
AnnotationsKeys = bag_keys(ParsedAudit.annotations)
| project
TimeGenerated,
ApiVersion = tostring(ParsedAudit.apiVersion),
Stage = tostring(ParsedAudit.stage),
Verb = tostring(ParsedAudit.verb),
Username = tostring(ParsedAudit.user.username),
Resource = tostring(ParsedAudit.objectRef.resource),
Subresource = tostring(ParsedAudit.objectRef.subresource),
Namespace = tostring(ParsedAudit.objectRef.namespace),
SourceIPs = tostring(ParsedAudit.sourceIPs),
UserAgent = tostring(ParsedAudit.userAgent),
ResponseCode = toint(ParsedAudit.responseStatus.code),
TopKeys,
UserKeys,
ObjectRefKeys,
AnnotationsKeys
| take 50Explanation
This query is designed to help you discover and understand the structure of your Amazon EKS (Elastic Kubernetes Service) audit logs. Here's a simple breakdown of what it does:
-
Data Source: It starts by querying the
AWSCloudWatchlogs for the past 24 hours. -
Filter Criteria: It filters the logs to find messages that contain Kubernetes audit events, specifically looking for logs that include
"kind":"Event"and"audit.k8s.io/". -
Parse JSON: It parses the JSON-formatted log messages to extract detailed information.
-
Extract Keys: It identifies and extracts the keys from different parts of the parsed JSON, such as the main audit log, user information, object references, and annotations.
-
Select Fields: It selects and projects specific fields from the parsed data, including:
TimeGenerated: The time the log was generated.ApiVersion: The API version of the audit event.Stage: The stage of the request (e.g., "RequestReceived").Verb: The action taken (e.g., "create", "delete").Username: The user who initiated the action.Resource: The resource type affected (e.g., "pods").Subresource: Any subresource involved.Namespace: The Kubernetes namespace of the resource.SourceIPs: The source IP addresses involved.UserAgent: The user agent string of the client.ResponseCode: The HTTP response code of the action.- Various keys extracted earlier for further inspection.
-
Limit Results: It limits the output to the first 50 records to make the data more manageable.
Overall, this query helps you locate and understand the structure of your EKS audit logs by extracting key information and displaying it in a structured format.