Azure Graph queries for Azure Policy non compliance

Admin User 1 Reputation point
2022-05-21T16:47:20.743+00:00

I am trying to use Azure Graph queries to query Key Vault compliance, but I cannot figure out where the non-compliance data is stored.

I can query all the resources that are non compliant, but cannot query why.

There seems to be a method Microsoft.PolicyInsights/policyEvents that can be called under REST APIs, but that doesn't seem to appear in Azure Resource Graph

According to this article it is not possible:

Note
Currently "reason for non-compliance" cannot be retrieved from Command line. We are working on mapping the reason code to the "reason for non-compliance" and at this point there is no ETA on this.

How can I report on this other than via REST APIs? Where else is it exposed?

Azure Key Vault
Azure Key Vault
An Azure service that is used to manage and protect cryptographic keys and other secrets used by cloud apps and services.
1,126 questions
Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,647 questions
Azure Policy
Azure Policy
An Azure service that is used to implement corporate governance and standards at scale for Azure resources.
799 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Udaiappa Ramachandran 726 Reputation points MVP
    2022-05-22T21:29:59.423+00:00

    The easiest way to run the non-compliances key vault query is to use the Microsoft Defender for cloud blade. Navigate to

    Home > Microsoft Defender for Cloud > Security Posture > View Recommendations > Expand the Key Vault then open in Resource Explorer

    Or you can use the query like this (copied from the same section), you can include an additional where clause

    securityresources
    | where type == "microsoft.security/assessments"
    | extend source = trim(' ', tolower(tostring(properties.resourceDetails.Source)))
    | extend resourceId = trim(' ', tolower(tostring(case(
    source =~ "azure", properties.resourceDetails.Id,
    extract('^(.+)/providers/Microsoft.Security/assessments/.+$',1,id)
    ))))
    | extend status = trim(" ", tostring(properties.status.code))
    | extend cause = trim(" ", tostring(properties.status.cause))
    | extend assessmentKey = tostring(name)

    204417-image.png

    1 person found this answer helpful.
    0 comments No comments