Through API how to get AKS and ARO clusters with "Defender for Containers" enabled

DiptiRanjan Swain 176 Reputation points
2025-02-05T15:19:27.71+00:00

For automation purpose, my requirement is through API call fetch the AKS and ARO clusters from Azure on which "Defender for Containers" is enabled. Is there such API present or any alternative ?

Azure Kubernetes Service (AKS)
Azure Kubernetes Service (AKS)
An Azure service that provides serverless Kubernetes, an integrated continuous integration and continuous delivery experience, and enterprise-grade security and governance.
2,260 questions
{count} votes

Accepted answer
  1. Akshay kumar Mandha 2,510 Reputation points Microsoft Vendor
    2025-02-11T17:21:03.4333333+00:00

    Hi DiptiRanjan Swain,
    Good catch! Glad the issue is resolved for you finally. I will have this answer promoted by reposting it. As an Original Poster (You) will not be able to accept your own answer. This is in the attempt to help others looking for a solution for a similar issue.

    Thanks again for sharing the solution here. Have a good day!
    Issue:
    For automation purpose, my requirement is through API call fetch the AKS and ARO clusters from Azure on which "Defender for Containers" is enabled. Is there such API present or any alternative?
    Solution:
    securityresources

    | where name == "56a83a6e-c417-42ec-b567-1e6fcb3d09a9"

    | extend Status = tostring(properties["status"]["code"])

    | extend ResourceName = tostring(properties ["resourceDetails"]["ResourceName"])

    | where Status == "Healthy"

    | distinct ResourceName, Status, resourceGroup, subscriptionId

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Megha Dubey 1 Reputation point Microsoft Employee
    2025-02-07T00:52:48.7133333+00:00

    Hello @Diptiranjan Swain , another option that you can try is Resource Graph API query for AKS and ARO clusters with "Defender for Containers" enabled.

    Something like this-

    Resources

    | where type == "microsoft.containerservice/managedclusters"

    | where properties.addonProfiles.azureDefender.enabled == true

    | project name, resourceGraph, location

    Similarly, you can change the query accordingly for ARO clusters.

    Reference: https://learn.microsoft.com/en-us/azure/governance/resource-graph/first-query-portal

    You can use Azure CLI or Rest APIs too to run these queries instead of Azure portal. Hope this helps.

    Please feel free to reach out if you have questions on these.

    Thanks!


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.