11 Identity Control Plane Assumerole Lineage And Entra Bridge
Query
// REVIEW ONLY - AWS Security Operations Workbook Visual Query
// Tab: IdentityControlPlane | Panel: assumerole-lineage-and-entra-bridge | Visualization: table | Mode: All
// Security Question: Which principals assumed roles across AWS accounts or chained temporary STS keys, and which map to verified Entra identities?
// Drill-Through: Use IssuedKeys in Cross-Cloud Workbook H06 or Tab 10 Cross-Cloud Pivot.
// Empty/No-Data Contract: No STS AssumeRole events matched the selected filters.
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 IdentityMap = union isfuzzy=true
(datatable(SearchKey:string)[]),
(_GetWatchlist('AWS_EntraIdentityMap'))
| where isnotempty(tostring(column_ifexists("SearchKey", "")))
| where tolower(tostring(column_ifexists("Verified", ""))) == "true"
| project AwsAccessKeyId=tostring(column_ifexists("AwsAccessKeyId", "")),
AWSAccountId=tostring(column_ifexists("AWSAccountId", "")),
EntraUPN=tostring(column_ifexists("EntraUPN", "")),
EntraObjectId=tostring(column_ifexists("EntraObjectId", ""));
union isfuzzy=true
(datatable(TimeGenerated:datetime, EventSource:string, EventName:string, ErrorCode:string, RecipientAccountId:string, UserIdentityAccountId:string, AWSRegion:string, UserIdentityArn:string, UserIdentityAccessKeyId:string, RequestParameters:string, ResponseElements:string, SourceIpAddress:string)[]),
(AWSCloudTrail | where TimeGenerated between (Start .. End)
| project TimeGenerated, EventSource, EventName, ErrorCode, RecipientAccountId, UserIdentityAccountId, AWSRegion, UserIdentityArn, UserIdentityAccessKeyId, RequestParameters, ResponseElements, SourceIpAddress)
| where EventSource == "sts.amazonaws.com" and EventName == "AssumeRole" and isempty(ErrorCode)
| where (AccountFilter == "*" or RecipientAccountId == AccountFilter or UserIdentityAccountId == AccountFilter)
and (RegionFilter == "*" or AWSRegion == RegionFilter)
and (SelectedPrincipalFilter == "*" or UserIdentityArn has SelectedPrincipalFilter)
| extend Req = parse_json(RequestParameters), Resp = parse_json(ResponseElements)
| extend TargetRoleArn = tostring(Req.roleArn),
IssuedKeyId = tostring(Resp.credentials.accessKeyId),
CrossAccount = (UserIdentityAccountId != RecipientAccountId)
| join kind=leftouter IdentityMap on $left.UserIdentityAccountId == $right.AWSAccountId and $left.UserIdentityAccessKeyId == $right.AwsAccessKeyId
| extend ResolvedEntra = coalesce(iff(isnotempty(EntraUPN), EntraUPN, ""), iff(isnotempty(EntraObjectId), EntraObjectId, ""), "UNMAPPED")
| summarize FirstAssumed=min(TimeGenerated), LastAssumed=max(TimeGenerated), Assumptions=count(),
IssuedKeys=make_set(IssuedKeyId, 10), SourceIps=make_set(SourceIpAddress, 10)
by CallerAccount=UserIdentityAccountId, TargetAccount=RecipientAccountId, CrossAccount,
CallerArn=UserIdentityArn, TargetRoleArn, EntraBridge=ResolvedEntra
| order by CrossAccount desc, Assumptions desc
| take 5000Explanation
This query is designed to analyze AWS security operations, specifically focusing on role assumptions across AWS accounts and their connection to verified Entra identities. Here's a simplified breakdown of what the query does:
-
Time Frame and Filters: It starts by setting a time range and various filters (like organization, account, region, environment, workload, severity, source, principal, and IP) to narrow down the data.
-
Identity Mapping: It creates a map of AWS access keys to Entra identities, ensuring only verified identities are considered.
-
Data Collection: The query collects data from AWS CloudTrail logs, specifically looking for "AssumeRole" events from the AWS Security Token Service (STS) that occurred within the specified time frame and meet the filter criteria.
-
Event Filtering: It filters out events with errors and applies additional filters based on account, region, and principal.
-
Data Parsing and Extension: The query parses request and response parameters to extract details like the target role ARN and issued key ID. It also determines if the role assumption was cross-account.
-
Joining Identity Data: It joins the CloudTrail data with the identity map to resolve Entra identities associated with the AWS access keys.
-
Summarization: The query summarizes the data by counting the number of role assumptions, listing issued keys and source IPs, and noting the first and last assumption times. It groups this information by caller and target accounts, role ARNs, and resolved Entra identities.
-
Ordering and Limiting Results: Finally, it orders the results by whether the assumption was cross-account and by the number of assumptions, limiting the output to 5000 records.
In essence, this query helps identify which AWS principals are assuming roles across accounts, whether these actions are linked to verified Entra identities, and provides a summary of these activities.