29 Containers Guardduty And Cloudtrail Container Context
Query
// REVIEW ONLY - AWS Security Operations Workbook Visual Query
// Tab: Containers | Panel: guardduty-and-cloudtrail-container-context | Visualization: table | Mode: All
// Security Question: Are GuardDuty EKS/ECS findings or EKS cluster access-policy changes occurring alongside Kubernetes API anomalies?
// Drill-Through: Correlate ClusterOrResource with P1-04b analytic rule.
// Empty/No-Data Contract: No GuardDuty EKS/ECS findings or EKS control-plane mutations observed in window.
let Start = {TimeRange:start};
let End = {TimeRange:end};
let OrgFilter = base64_decode_tostring("{Organization:base64}");
let AccountFilter = base64_decode_tostring("{AwsAccount:base64}");
let RegionFilter = base64_decode_tostring("{AwsRegion:base64}");
let EnvFilter = base64_decode_tostring("{Environment:base64}");
let WorkloadFilter = base64_decode_tostring("{Workload:base64}");
let SeverityFilter = base64_decode_tostring("{Severity:base64}");
let SourceFilter = base64_decode_tostring("{SourceTable:base64}");
let SummaryPref = base64_decode_tostring("{SummaryMode:base64}");
let SelectedPrincipalFilter = base64_decode_tostring("{SelectedPrincipal:base64}");
let SelectedIpFilter = base64_decode_tostring("{SelectedIp:base64}");
let GdContainers = union isfuzzy=true
(datatable(TimeGenerated:datetime, Id:string, AccountId:string, Region:string, ServiceDetails:dynamic, ResourceDetails:dynamic, ActivityType:string, Severity:real)[]),
(AWSGuardDuty | where TimeGenerated between (Start .. End)
| project TimeGenerated, Id, AccountId, Region, ServiceDetails=todynamic(ServiceDetails), ResourceDetails=todynamic(ResourceDetails), ActivityType, Severity=todouble(Severity))
| where (AccountFilter == "*" or AccountId == AccountFilter) and (RegionFilter == "*" or Region == RegionFilter)
| summarize arg_max(TimeGenerated, *) by Id
| where tobool(ServiceDetails.archived) != true
| where ActivityType has_any (":Kubernetes/", ":ECS/", ":Container/") or isnotempty(tostring(ResourceDetails.eksClusterDetails.name))
| project TimeGenerated, Source="AWSGuardDuty", AccountId, Region,
ClusterOrResource=coalesce(iff(isnotempty(tostring(ResourceDetails.eksClusterDetails.name)), tostring(ResourceDetails.eksClusterDetails.name), ""), Id),
Signal=ActivityType, ActorOrSeverity=strcat("Severity:", Severity);
let EksControl = union isfuzzy=true
(datatable(TimeGenerated:datetime, EventSource:string, ReadOnly:bool, RecipientAccountId:string, AWSRegion:string, RequestParameters:string, EventName:string, UserIdentityArn:string)[]),
(AWSCloudTrail | where TimeGenerated between (Start .. End)
| project TimeGenerated, EventSource, ReadOnly, RecipientAccountId, AWSRegion, RequestParameters, EventName, UserIdentityArn)
| where EventSource == "eks.amazonaws.com" and ReadOnly == false
| where (AccountFilter == "*" or RecipientAccountId == AccountFilter) and (RegionFilter == "*" or AWSRegion == RegionFilter)
| project TimeGenerated, Source="AWSCloudTrail:EKS", AccountId=RecipientAccountId, Region=AWSRegion,
ClusterOrResource=tostring(parse_json(RequestParameters).name), Signal=EventName, ActorOrSeverity=UserIdentityArn;
union GdContainers, EksControl
| order by TimeGenerated desc
| take 5000Explanation
This query is designed to analyze security events related to AWS container services, specifically focusing on Amazon EKS (Elastic Kubernetes Service) and ECS (Elastic Container Service). Here's a simplified breakdown of what the query does:
-
Time and Filters Setup: It sets up a time range and various filters (like organization, account, region, environment, workload, severity, source, principal, and IP) to narrow down the data to be analyzed.
-
GuardDuty Data Collection:
- It collects data from AWS GuardDuty, focusing on findings related to Kubernetes, ECS, or containers.
- It filters out archived events and selects relevant fields like time, account ID, region, and activity type.
- It identifies the cluster or resource involved and combines the severity level with the activity type.
-
CloudTrail Data Collection:
- It gathers data from AWS CloudTrail, specifically looking for changes in EKS cluster access policies (i.e., non-read-only events from the EKS service).
- It filters the data based on account and region, and extracts relevant fields like event name and user identity.
-
Data Union and Presentation:
- It combines the data from GuardDuty and CloudTrail.
- The results are ordered by the time of the event, with a limit of 5000 records displayed.
-
Purpose:
- The query aims to identify if there are any GuardDuty findings related to EKS/ECS or changes in EKS cluster access policies that occur alongside anomalies in Kubernetes API activities.
- If no relevant data is found within the specified time window, it implies that no such security events were observed.
Overall, this query helps in monitoring and correlating security events in AWS container environments to detect potential security issues or policy changes.