03 Identity Map Rejections
Query
// REVIEW ONLY workbook query: 🪪 1.2 AWS-to-Entra Identity Mapping Health (`AWS_EntraIdentityMap`)
let AccountFilter = trim(" ", base64_decode_tostring("{AwsAccount:base64}"));
let UseAllAccounts = AccountFilter in ("", "*");
union isfuzzy=true
(datatable(SearchKey:string)[]),
(_GetWatchlist('AWS_EntraIdentityMap'))
| where isnotempty(tostring(column_ifexists("SearchKey", "")))
| extend AWSAccountId=tostring(column_ifexists("AWSAccountId", "")),
AwsAccessKeyId=tostring(column_ifexists("AwsAccessKeyId", "")),
AwsPrincipalArn=tostring(column_ifexists("AwsPrincipalArn", "")),
EntraTenantId=tostring(column_ifexists("EntraTenantId", "")),
EntraObjectId=tostring(column_ifexists("EntraObjectId", "")),
IdentityType=tostring(column_ifexists("IdentityType", "")),
AppClientId=tostring(column_ifexists("AppClientId", "")),
Verified=tostring(column_ifexists("Verified", "")),
MappingEvidence=tostring(column_ifexists("MappingEvidence", "")),
From=todatetime(column_ifexists("ValidFromUtc", "")),
To=todatetime(column_ifexists("ValidToUtc", ""))
| where UseAllAccounts or AWSAccountId == AccountFilter
| summarize Rows=count(), take_any(*) by AwsAccessKeyId, AwsPrincipalArn, AWSAccountId
| extend State=case(
Rows != 1, "🟠REVIEW: duplicate rows for same AWS key/principal; rejected by rules",
tolower(Verified) != "true" or isempty(MappingEvidence), "🔴 REJECT: Verified!=true or MappingEvidence empty",
isnull(toguid(EntraTenantId)) or isnull(toguid(EntraObjectId)), "🔴 REJECT: invalid EntraTenantId or EntraObjectId GUID",
IdentityType !in ("User", "ServicePrincipal"), "🔴 REJECT: IdentityType must be User or ServicePrincipal",
IdentityType == "ServicePrincipal" and isnull(toguid(AppClientId)), "🔴 REJECT: ServicePrincipal missing AppClientId GUID",
isnull(From) or isnull(To) or To < From, "🔴 REJECT: invalid ValidFromUtc/ValidToUtc interval",
isempty(AwsAccessKeyId) or isempty(AwsPrincipalArn) or isempty(AWSAccountId), "🔴 REJECT: incomplete AWS key/ARN/account",
To < now(), "🟡 EXPIRED: valid only for historical events inside [From .. To]",
From > now(), "🟡 FUTURE: validity window has not started yet",
"🟢 VALID: active & accepted by cross-cloud analytic rules")
| project State, AWSAccountId, AwsAccessKeyId, AwsPrincipalArn, IdentityType, EntraTenantId, EntraObjectId, AppClientId, From, To, Rows
| take 5000Explanation
This KQL (Kusto Query Language) query is designed to evaluate the health of mappings between AWS identities and Entra identities. Here's a simplified breakdown of what the query does:
-
Account Filtering: It starts by decoding a base64-encoded string to determine which AWS account to filter on. If the filter is empty or set to "*", it will consider all accounts.
-
Data Collection: It gathers data from a watchlist named
AWS_EntraIdentityMapand ensures that theSearchKeycolumn is not empty. -
Data Extension: The query extends the data with several columns, such as AWS account details, Entra identity details, and validity periods.
-
Filtering: It filters the data to include only entries that match the specified AWS account filter or all accounts if no specific filter is applied.
-
Summarization: It summarizes the data by counting the number of rows for each unique AWS access key and principal ARN, and takes any other columns for those keys.
-
State Evaluation: The query evaluates each entry's state based on several conditions:
- Duplicate rows for the same AWS key/principal are flagged for review.
- Entries with verification issues, invalid GUIDs, incorrect identity types, missing data, or invalid time intervals are rejected.
- Entries that are expired or not yet valid are flagged as such.
- Entries that pass all checks are marked as valid.
-
Projection: It selects specific columns to display, including the state, AWS account details, identity types, and validity periods.
-
Limitation: Finally, it limits the output to a maximum of 5000 entries.
In summary, this query checks the integrity and validity of AWS-to-Entra identity mappings, categorizing each entry into various states based on predefined rules and conditions.