A06 Aws Secrets To Entra App Credentials
Query
// Standalone KQL for Analytic Rule: AWS cross-cloud - AWS secrets use precedes Entra application credential change
// Rule File: analytics/A06-aws-secrets-to-entra-app-credentials.yaml | Rule ID: 54f1f278-4d53-4f20-a2a1-0e357f02da06 | Severity: High
// Schedule: 15m / Lookback: 2h | REVIEW ONLY - Do not deploy/schedule without approval.
let IdentityMap = _GetWatchlist('AWS_EntraIdentityMap')
| where tolower(tostring(column_ifexists("Verified", ""))) == "true" and isnotempty(tostring(column_ifexists("MappingEvidence", "")))
| project AwsAccessKeyId=tostring(column_ifexists("AwsAccessKeyId", "")), AwsPrincipalArn=tostring(column_ifexists("AwsPrincipalArn", "")),
AWSAccountId=tostring(column_ifexists("AWSAccountId", "")), EntraTenantId=tolower(tostring(column_ifexists("EntraTenantId", ""))),
EntraObjectId=tolower(tostring(column_ifexists("EntraObjectId", ""))), IdentityType=tostring(column_ifexists("IdentityType", "")),
ValidFrom=todatetime(column_ifexists("ValidFromUtc", "")), ValidTo=todatetime(column_ifexists("ValidToUtc", ""))
| summarize MappingRows=count(), take_any(*) by AwsAccessKeyId, AwsPrincipalArn, AWSAccountId
| where MappingRows == 1 and IdentityType in ("User", "ServicePrincipal")
and isnotempty(EntraTenantId) and isnotempty(EntraObjectId);
let CredentialChanges = AuditLogs
| where TimeGenerated > ago(2h) and Result =~ "success"
| where OperationName in~ ("Add service principal credentials", "Update application - Certificates and secrets management")
| extend Actor=todynamic(InitiatedBy)
| extend EntraObjectId=tolower(coalesce(tostring(Actor.user.id), tostring(Actor.app.servicePrincipalId))),
IdentityType=iff(isnotempty(tostring(Actor.user.id)), "User", "ServicePrincipal")
| where isnotempty(EntraObjectId)
| mv-expand Target=TargetResources
| where tostring(Target.type) in~ ("Application", "ServicePrincipal") and isnotempty(tostring(Target.id))
| project AuditTime=TimeGenerated, AuditIngest=ingestion_time(), AuditId=Id,
AuditCorrelationId=CorrelationId, OperationName, EntraTenantId=tolower(AADTenantId),
EntraObjectId, IdentityType, TargetObjectId=tostring(Target.id), TargetType=tostring(Target.type);
AWSCloudTrail
| where TimeGenerated > ago(2h)
| where isempty(ErrorCode) and isempty(ErrorMessage) and isnotempty(AwsEventId)
| where EventSource == "secretsmanager.amazonaws.com" and EventName == "GetSecretValue"
| project AwsTime=TimeGenerated, AwsIngest=ingestion_time(), AwsEventId, EventName,
AwsAccessKeyId=UserIdentityAccessKeyId, AwsPrincipalArn=UserIdentityArn,
AWSAccountId=UserIdentityAccountId, RecipientAccountId, SourceIpAddress
| where isnotempty(AwsAccessKeyId) and isnotempty(AwsPrincipalArn) and isnotempty(AWSAccountId)
| join kind=inner IdentityMap on AwsAccessKeyId, AwsPrincipalArn, AWSAccountId
| where AwsTime between (ValidFrom .. ValidTo)
| join kind=inner CredentialChanges on EntraTenantId, EntraObjectId, IdentityType
| where AuditTime between (AwsTime .. (AwsTime + 1h))
| extend CorrelationIngest=max_of(AwsIngest, AuditIngest)
| where CorrelationIngest > ago(15m)
| summarize arg_max(CorrelationIngest, *) by AuditId, TargetObjectId, EntraTenantId, EntraObjectId
| extend UserObjectId=iff(IdentityType == "User", EntraObjectId, "")
| project TimeGenerated=AuditTime, AwsTime, AwsEventId, EventName, AwsAccessKeyId, AwsPrincipalArn,
AWSAccountId, RecipientAccountId, SourceIpAddress, EntraTenantId, EntraObjectId,
IdentityType, UserObjectId, AuditId, AuditCorrelationId, OperationName, TargetObjectId, TargetType,
CorrelationBasis="Verified same AWS/Entra actor + ordered secret-read/credential-change; causality unproven";Explanation
This query is designed to detect potential security incidents involving AWS and Entra (formerly Azure Active Directory) by identifying scenarios where AWS secrets are accessed shortly before changes are made to Entra application credentials. Here's a simplified breakdown of what the query does:
-
Identity Mapping:
- It retrieves a list of verified mappings between AWS and Entra identities from a watchlist.
- It ensures that each mapping is unique and valid, focusing on users and service principals.
-
Credential Changes:
- It examines audit logs for successful operations related to adding or updating service principal credentials in Entra within the last 2 hours.
- It extracts relevant details like the actor's identity and the target resource involved in the operation.
-
AWS Secrets Access:
- It looks at AWS CloudTrail logs for any successful access to secrets in AWS Secrets Manager within the last 2 hours.
- It filters for events without errors and gathers details about the AWS identity involved.
-
Correlation:
- It joins the AWS secrets access data with the identity mapping to ensure the same AWS identity is involved.
- It then joins this with the Entra credential changes to find cases where the credential change happened within an hour after the AWS secret was accessed.
- It checks that the correlation was ingested within the last 15 minutes to ensure the data is recent.
-
Output:
- The query outputs a summarized list of these correlated events, including details about the AWS and Entra identities, the operations performed, and the timing of these events.
- It flags these events as potentially suspicious, noting that while the same actor is involved in both AWS and Entra actions, causality is not proven.
This query is part of a high-severity analytic rule intended for review and should not be deployed or scheduled without approval.