12 Identity Control Plane Analyst Error Principals And Raw Trail
Query
// REVIEW ONLY - AWS Security Operations Workbook Visual Query
// Tab: IdentityControlPlane | Panel: analyst-error-principals-and-raw-trail | Visualization: table | Mode: Analyst
// Security Question: Which principals are hitting AccessDenied walls (automated/AI recon), or what APIs did SelectedPrincipal/SelectedIp invoke?
// Drill-Through: Click a principal or IP in earlier panels (or type into SelectedPrincipal / SelectedIp above) to drill down.
// Empty/No-Data Contract: No principals hit >=10 AccessDenied errors, and no events matched SelectedPrincipal/SelectedIp.
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}");
union isfuzzy=true
(datatable(TimeGenerated:datetime, RecipientAccountId:string, AWSRegion:string, UserIdentityArn:string, UserIdentityAccessKeyId:string, SourceIpAddress:string, UserAgent:string, EventName:string, ErrorCode:string)[]),
(AWSCloudTrail | where TimeGenerated between (Start .. End)
| project TimeGenerated, RecipientAccountId, AWSRegion, UserIdentityArn, UserIdentityAccessKeyId, SourceIpAddress, UserAgent, EventName, ErrorCode)
| where (AccountFilter == "*" or RecipientAccountId == AccountFilter) and (RegionFilter == "*" or AWSRegion == RegionFilter)
| where (SelectedPrincipalFilter != "*" and UserIdentityArn has SelectedPrincipalFilter)
or (SelectedIpFilter != "*" and SourceIpAddress == SelectedIpFilter)
or isnotempty(ErrorCode)
| summarize Events=count(), DeniedCount=countif(isnotempty(ErrorCode)), DistinctApis=dcount(EventName),
SampleEvents=make_set(EventName, 20), ErrorCodes=make_set(ErrorCode, 10), LastSeen=max(TimeGenerated)
by RecipientAccountId, AWSRegion, UserIdentityArn, UserIdentityAccessKeyId, SourceIpAddress, UserAgent
| where SelectedPrincipalFilter != "*" or SelectedIpFilter != "*" or DeniedCount >= 10
| order by DeniedCount desc, LastSeen desc
| take 5000Explanation
This query is designed to help security analysts identify which AWS principals (users or roles) are encountering access denial errors, potentially due to automated or AI reconnaissance activities, or to see what APIs a specific principal or IP address has invoked. Here's a simplified breakdown of what the query does:
-
Time Range and Filters: It starts by setting a time range and various filters for organization, account, region, environment, workload, severity, source, selected principal, and selected IP. These filters are decoded from base64 strings.
-
Data Union: It combines data from a datatable (which is empty in this case) and AWS CloudTrail logs, focusing on specific fields like time, account ID, region, user identity, source IP, user agent, event name, and error code.
-
Filtering: The query filters the data based on the specified account, region, selected principal, selected IP, and whether there is an error code present.
-
Summarization: It summarizes the data by counting the total number of events, the number of denied access events, and the distinct APIs called. It also creates a sample set of event names and error codes, and notes the last time an event was seen, grouped by account ID, region, user identity, access key ID, source IP, and user agent.
-
Condition for Display: It only includes results where a specific principal or IP is selected, or where there are 10 or more access denied errors.
-
Ordering and Limiting Results: The results are ordered by the number of denied access events and the last seen time, and the query returns up to 5000 results.
In essence, this query helps analysts quickly identify potential security issues related to access denials in AWS by focusing on specific principals or IPs, or by highlighting those with a significant number of access denials.