Enable Microsoft Defender for Containers

Microsoft Defender for Containers is the cloud-native solution for securing your containers.

Defender for Containers protects your clusters whether they're running in:

  • Azure Kubernetes Service (AKS) - Microsoft's managed service for developing, deploying, and managing containerized applications.

  • Amazon Elastic Kubernetes Service (EKS) in a connected Amazon Web Services (AWS) account - Amazon's managed service for running Kubernetes on AWS without needing to install, operate, and maintain your own Kubernetes control plane or nodes.

  • Google Kubernetes Engine (GKE) in a connected Google Cloud Platform (GCP) project - Google’s managed environment for deploying, managing, and scaling applications using GCP infrastructure.

  • Other Kubernetes distributions (using Azure Arc-enabled Kubernetes) - Cloud Native Computing Foundation (CNCF) certified Kubernetes clusters hosted on-premises or on IaaS. For more information, see the On-prem/IaaS (Arc) section of Supported features by environment.

Learn about this plan in Overview of Microsoft Defender for Containers.

You can learn more by watching these videos from the Defender for Cloud in the Field video series:

Note

Defender for Containers' support for Arc-enabled Kubernetes clusters, AWS EKS, and GCP GKE. This is a preview feature.

The Azure Preview Supplemental Terms include additional legal terms that apply to Azure features that are in beta, preview, or otherwise not yet released into general availability.

Network requirements

Validate the following endpoints are configured for outbound access so that the Defender profile can connect to Microsoft Defender for Cloud to send security data and events:

See the required FQDN/application rules for Microsoft Defender for Containers.

By default, AKS clusters have unrestricted outbound (egress) internet access.

Network requirements

Validate the following endpoints are configured for outbound access so that the Defender extension can connect to Microsoft Defender for Cloud to send security data and events:

For Azure public cloud deployments:

Domain Port
*.ods.opinsights.azure.com 443
*.oms.opinsights.azure.com 443
login.microsoftonline.com 443

You will also need to validate the Azure Arc-enabled Kubernetes network requirements.

Enable the plan

To enable the plan:

  1. From Defender for Cloud's menu, open the Environment settings page and select the relevant subscription.

  2. In the Defender plans page, enable Defender for Containers

    Tip

    If the subscription already has Defender for Kubernetes and/or Defender for container registries enabled, an update notice is shown. Otherwise, the only option will be Defender for Containers.

    Defender for container registries and Defender for Kubernetes plans showing 'Deprecated' and upgrade information.

  3. By default, when enabling the plan through the Azure portal, Microsoft Defender for Containers is configured to auto provision (automatically install) required components to provide the protections offered by plan, including the assignment of a default workspace.

    If you want to disable auto provisioning during the onboarding process, select Edit configuration for the Containers plan. This opens the Advanced options, where you can disable auto provisioning for each component.

    In addition, you can modify this configuration from the Defender plans page or from the Auto provisioning page on the Microsoft Defender for Containers components row:

    Screenshot of the auto provisioning options for Microsoft Defender for Containers.

    Note

    If you choose to disable the plan at any time after enabling it through the portal as shown above, you'll need to manually remove Defender for Containers components deployed on your clusters.

    You can assign a custom workspace through Azure Policy.

  4. If you disable the auto provisioning of any component, you can easily deploy the component to one or more clusters using the appropriate recommendation:

    Note

    Microsoft Defender for Containers is configured to defend all of your clouds automatically. When you install all of the required prerequisites and enable all of the auto provisioning capabilities.

    If you choose to disable all of the auto provision configuration options, no agents, or components will be deployed to your clusters. Protection will be limited to the Agentless features only. Learn which features are Agentless in the availability section for Defender for Containers.

Deploy the Defender profile

You can enable the Defender for Containers plan and deploy all of the relevant components from the Azure portal, the REST API, or with a Resource Manager template. For detailed steps, select the relevant tab.

Once the Defender profile has been deployed, a default workspace will be automatically assigned. You can assign a custom workspace in place of the default workspace through Azure Policy.

Note

The Defender profile is deployed to each node to provide the runtime protections and collect signals from those nodes using eBPF technology.

Use the fix button from the Defender for Cloud recommendation

A streamlined, frictionless, process lets you use the Azure portal pages to enable the Defender for Cloud plan and setup auto provisioning of all the necessary components for defending your Kubernetes clusters at scale.

A dedicated Defender for Cloud recommendation provides:

  • Visibility about which of your clusters has the Defender profile deployed
  • Fix button to deploy it to those clusters without the extension
  1. From Microsoft Defender for Cloud's recommendations page, open the Enable enhanced security security control.

  2. Use the filter to find the recommendation named Azure Kubernetes Service clusters should have Defender profile enabled.

    Tip

    Notice the Fix icon in the actions column

  3. Select the clusters to see the details of the healthy and unhealthy resources - clusters with and without the profile.

  4. From the unhealthy resources list, select a cluster and select Remediate to open the pane with the remediation confirmation.

  5. Select Fix [x] resources.

Enable the plan

To enable the plan:

  1. From Defender for Cloud's menu, open the Environment settings page and select the relevant subscription.

  2. In the Defender plans page, enable Defender for Containers.

    Tip

    If the subscription already has Defender for Kubernetes and/or Defender for container registries enabled, an update notice is shown. Otherwise, the only option will be Defender for Containers.

    Defender for container registries and Defender for Kubernetes plans showing 'Deprecated' and upgrade information.

  3. By default, when enabling the plan through the Azure portal, Microsoft Defender for Containers is configured to auto provision (automatically install) required components to provide the protections offered by plan, including the assignment of a default workspace.

    If you want to disable auto provisioning during the onboarding process, select Edit configuration for the Containers plan. The Advanced options will appear, and you can disable auto provisioning for each component.

    In addition, you can modify this configuration from the Defender plans page or from the Auto provisioning page on the Microsoft Defender for Containers components row:

    Screenshot of the auto provisioning options for Microsoft Defender for Containers.

    Note

    If you choose to disable the plan at any time after enabling it through the portal as shown above, you'll need to manually remove Defender for Containers components deployed on your clusters.

    You can assign a custom workspace through Azure Policy.

  4. If you disable the auto provisioning of any component, you can easily deploy the component to one or more clusters using the appropriate recommendation:

Prerequisites

Before deploying the extension, ensure you:

Deploy the Defender extension

You can deploy the Defender extension using a range of methods. For detailed steps, select the relevant tab.

Use the fix button from the Defender for Cloud recommendation

A dedicated Defender for Cloud recommendation provides:

  • Visibility about which of your clusters has the Defender for Kubernetes extension deployed
  • Fix button to deploy it to those clusters without the extension
  1. From Microsoft Defender for Cloud's recommendations page, open the Enable enhanced security security control.

  2. Use the filter to find the recommendation named Azure Arc-enabled Kubernetes clusters should have Defender for Cloud's extension installed.

    Microsoft Defender for Cloud's recommendation for deploying the Defender extension for Azure Arc-enabled Kubernetes clusters.

    Tip

    Notice the Fix icon in the actions column

  3. Select the extension to see the details of the healthy and unhealthy resources - clusters with and without the extension.

  4. From the unhealthy resources list, select a cluster and select Remediate to open the pane with the remediation options.

  5. Select the relevant Log Analytics workspace and select Remediate x resource.

    Deploy Defender extension for Azure Arc with Defender for Cloud's 'fix' option.

Verify the deployment

To verify that your cluster has the Defender extension installed on it, follow the steps in one of the tabs below:

Use Defender for Cloud recommendation to verify the status of your extension

  1. From Microsoft Defender for Cloud's recommendations page, open the Enable Microsoft Defender for Cloud security control.

  2. Select the recommendation named Azure Arc-enabled Kubernetes clusters should have Microsoft Defender for Cloud's extension installed.

    Microsoft Defender for Cloud's recommendation for deploying the Defender extension for Azure Arc-enabled Kubernetes clusters.

  3. Check that the cluster on which you deployed the extension is listed as Healthy.

Protect Amazon Elastic Kubernetes Service clusters

Important

If you haven't already connected an AWS account, do so now using the instructions in Connect your AWS accounts to Microsoft Defender for Cloud.

To protect your EKS clusters, enable the Containers plan on the relevant account connector:

  1. From Defender for Cloud's menu, open Environment settings.

  2. Select the AWS connector.

    Screenshot of Defender for Cloud's environment settings page showing an AWS connector.

  3. Set the toggle for the Containers plan to On.

    Screenshot of enabling Defender for Containers for an AWS connector.

  4. (Optional) To change the retention period for your audit logs, select Configure, enter the required timeframe, and select Save.

    Screenshot of adjusting the retention period for EKS control pane logs.

    Note

    If you disable this configuration, then the Threat detection (control plane) feature will be disabled. Learn more about features availability.

  5. Continue through the remaining pages of the connector wizard.

  6. Azure Arc-enabled Kubernetes, the Defender extension, and the Azure Policy extension should be installed and running on your EKS clusters. There are 2 dedicated Defender for Cloud recommendations to install these extensions (and Azure Arc if necessary):

    • EKS clusters should have Microsoft Defender's extension for Azure Arc installed
    • EKS clusters should have the Azure Policy extension installed

    For each of the recommendations, follow follow the steps below to install the required extensions.

    To install the required extensions:

    1. From Defender for Cloud's Recommendations page, search for one of the recommendations by name.

    2. Select an unhealthy cluster.

      Important

      You must select the clusters one at a time.

      Don't select the clusters by their hyperlinked names: select anywhere else in the relevant row.

    3. Select Fix.

    4. Defender for Cloud generates a script in the language of your choice: select Bash (for Linux) or PowerShell (for Windows).

    5. Select Download remediation logic.

    6. Run the generated script on your cluster.

    7. Repeat steps "a" through "f" for the second recommendation.

    Video of how to use the Defender for Cloud recommendation to generate a script for your EKS clusters that enables the Azure Arc extension.

View recommendations and alerts for your EKS clusters

Tip

You can simulate container alerts by following the instructions in this blog post.

To view the alerts and recommendations for your EKS clusters, use the filters on the alerts, recommendations, and inventory pages to filter by resource type AWS EKS cluster.

Screenshot of how to use filters on Microsoft Defender for Cloud's alerts page to view alerts related to AWS EKS clusters.

Protect Google Kubernetes Engine (GKE) clusters

Important

If you haven't already connected a GCP project, do so now using the instructions in Connect your GCP projects to Microsoft Defender for Cloud.

To protect your GKE clusters, you will need to enable the Containers plan on the relevant GCP project.

To protect Google Kubernetes Engine (GKE) clusters:

  1. Sign in to the Azure portal.

  2. Navigate to Microsoft Defender for Cloud > Environment settings.

  3. Select the relevant GCP connector

    Screenshot showing an example GCP connector.

  4. Select the Next: Select plans > button.

  5. Ensure that the Containers plan is toggled to On.

    Screenshot that shows the containers plan is toggled to on.

  6. (Optional) Configure the containers plan.

  7. Select the Copy button.

    Screenshot showing the location of the copy button.

  8. Select the GCP Cloud Shell > button.

  9. Paste the script into the Cloud Shell terminal, and run it.

The connector will update after the script executes. This process can take up to 6-8 hours up to complete.

Deploy the solution to specific clusters

If you disabled any of the default auto provisioning configurations to Off, during the GCP connector onboarding process, or afterwards. You will need to manually install Azure Arc-enabled Kubernetes, the Defender extension, and the Azure Policy extensions to each of your your GKE clusters to get the full security value out of Defender for Containers.

There are 2 dedicated Defender for Cloud recommendations you can use to install the extensions (and Arc if necessary):

  • GKE clusters should have Microsoft Defender's extension for Azure Arc installed
  • GKE clusters should have the Azure Policy extension installed

To deploy the solution to specific clusters:

  1. Sign in to the Azure portal.

  2. Navigate to Microsoft Defender for Cloud > Recommendations.

  3. From Defender for Cloud's Recommendations page, search for one of the recommendations by name.

    Screenshot showing how to search for the recommendation.

  4. Select an unhealthy GKE cluster.

    Important

    You must select the clusters one at a time.

    Don't select the clusters by their hyperlinked names: select anywhere else in the relevant row.

  5. Select the name of the unhealthy resource.

  6. Select Fix.

    Screenshot showing the location of the fix button.

  7. Defender for Cloud will generate a script in the language of your choice:

    • For Linux, select Bash.
    • For Windows, select PowerShell.
  8. Select Download remediation logic.

  9. Run the generated script on your cluster.

  10. Repeat steps 3 through 8 for the second recommendation.

View your GKE cluster alerts

  1. Sign in to the Azure portal.

  2. Navigate to Microsoft Defender for Cloud > Security alerts.

  3. Select the button.

  4. In the Filter drop-down menu, select Resource type.

  5. In the Value drop-down menu, select GCP GKE Cluster.

  6. Select Ok.

Simulate security alerts from Microsoft Defender for Containers

A full list of supported alerts is available in the reference table of all Defender for Cloud security alerts.

  1. To simulate a security alert, run the following command from the cluster:

    kubectl get pods --namespace=asc-alerttest-662jfi039n
    

    The expected response is "No resource found".

    Within 30 minutes, Defender for Cloud will detect this activity and trigger a security alert.

  2. In the Azure portal, open Microsoft Defender for Cloud's security alerts page and look for the alert on the relevant resource:

    Sample alert from Microsoft Defender for Kubernetes.

Remove the Defender extension

To remove this - or any - Defender for Cloud extension, it's not enough to turn off auto provisioning:

  • Enabling auto provisioning, potentially impacts existing and future machines.
  • Disabling auto provisioning for an extension, only affects the future machines - nothing is uninstalled by disabling auto provisioning.

Nevertheless, to ensure the Defender for Containers components aren't automatically provisioned to your resources from now on, disable auto provisioning of the extensions as explained in Configure auto provisioning for agents and extensions from Microsoft Defender for Cloud.

You can remove the extension using Azure portal, Azure CLI, or REST API as explained in the tabs below.

Use Azure portal to remove the extension

  1. From the Azure portal, open Azure Arc.

  2. From the infrastructure list, select Kubernetes clusters and then select the specific cluster.

  3. Open the extensions page. The extensions on the cluster are listed.

  4. Select the cluster and select Uninstall.

    Removing an extension from your Arc-enabled Kubernetes cluster.

Default Log Analytics workspace for AKS

The Log Analytics workspace is used by the Defender profile as a data pipeline to send data from the cluster to Defender for Cloud without retaining any data in the Log Analytics workspace itself. As a result, users won't be billed in this use case.

The Defender profile uses a default Log Analytics workspace. If you don't already have a default Log Analytics workspace, Defender for Cloud will create a new resource group and default workspace when the Defender profile is installed. The default workspace is created based on your region.

The naming convention for the default Log Analytics workspace and resource group is:

  • Workspace: DefaultWorkspace-[subscription-ID]-[geo]
  • Resource Group: DefaultResourceGroup-[geo]

Assign a custom workspace

When you enable the auto-provision option, a default workspace will be automatically assigned. You can assign a custom workspace through Azure Policy.

To check if you have a workspace assigned:

  1. Sign in to the Azure portal.

  2. Search for, and select Policy.

    Screenshot that shows how to locate the policy page.

  3. Select Definitions.

  4. Search for policy ID 64def556-fbad-4622-930e-72d1d5589bf5.

    Screenshot that shows where to search for the policy by ID number.

  5. Select Configure Azure Kubernetes Service clusters to enable Defender profile.

  6. Select Assignment.

    Screenshot showing where to locate the assignments tab.

  7. Follow the Create a new assignment with custom workspace steps if the policy hasn't yet been assigned to the relevant scope. Or, follow the Update assignment with custom workspace steps if the policy is already assigned and you want to change it to use a custom workspace.

Create a new assignment with custom workspace

If the policy hasn't been assigned, you'll see Assignments (0).

Screenshot showing that no workspace has been assigned.

To assign custom workspace:

  1. Select Assign.

  2. In the Parameters tab, deselect the Only show parameters that need input or review option.

  3. Select a LogAnalyticsWorkspaceResource ID from the drop-down menu.

    Screenshot showing where the drop-down menu is located.

  4. Select Review + create.

  5. Select Create.

Update assignment with custom workspace

If the policy has already been assigned to a workspace, you'll see Assignments (1).

Screenshot that shows Assignment (1), meaning a workspace has already been assigned.

Note

If you have more than one subscription the number may be higher.

To assign custom workspace:

  1. Select the relevant assignment.

    Screenshot that shows where to select the relevant assignment from.

  2. Select Edit assignment.

  3. In the Parameters tab, deselect the Only show parameters that need input or review option.

  4. Select a LogAnalyticsWorkspaceResource ID from the drop-down menu.

    Screenshot showing where the drop-down menu is located.

  5. Select Review + create.

  6. Select Create.

Default Log Analytics workspace for Arc

The Log Analytics workspace is used by the Defender extension as a data pipeline to send data from the cluster to Defender for Cloud without retaining any data in the Log Analytics workspace itself. As a result, users won't be billed in this use case.

The Defender extension uses a default Log Analytics workspace. If you don't already have a default Log Analytics workspace, Defender for Cloud will create a new resource group and default workspace when the Defender extension is installed. The default workspace is created based on your region.

The naming convention for the default Log Analytics workspace and resource group is:

  • Workspace: DefaultWorkspace-[subscription-ID]-[geo]
  • Resource Group: DefaultResourceGroup-[geo]

Assign a custom workspace

When you enable the auto-provision option, a default workspace will be automatically assigned. You can assign a custom workspace through Azure Policy.

To check if you have a workspace assigned:

  1. Sign in to the Azure portal.

  2. Search for, and select Policy.

    Screenshot that shows how to locate the policy page for ARC.

  3. Select Definitions.

  4. Search for policy ID 708b60a6-d253-4fe0-9114-4be4c00f012c.

    Screenshot that shows where to search for the policy by ID number for ARC.

  5. Select Configure Azure Arc enabled Kubernetes clusters to install Microsoft Defender for Cloud extension..

  6. Select Assignments.

    Screenshot that shows where the assignments tab is for ARC.

  7. Follow the Create a new assignment with custom workspace steps if the policy hasn't yet been assigned to the relevant scope. Or, follow the Update assignment with custom workspace steps if the policy is already assigned and you want to change it to use a custom workspace.

Create a new assignment with custom workspace

If the policy hasn't been assigned, you'll see Assignments (0).

Screenshot showing that no workspace has been assigned for ARC.

To assign custom workspace:

  1. Select Assign.

  2. In the Parameters tab, deselect the Only show parameters that need input or review option.

  3. Select a LogAnalyticsWorkspaceResource ID from the drop-down menu.

    Screenshot showing where the drop-down menu is located for ARC.

  4. Select Review + create.

  5. Select Create.

Update assignment with custom workspace

If the policy has already been assigned to a workspace, you'll see Assignments (1).

Note

If you have more than one subscription the number may be higher. If you have a number 1 or higher, the assignment may still not be on the relevant scope. If this is the case, you will want to follow the Create a new assignment with custom workspace steps.

Screenshot that shows Assignment (1), meaning a workspace has already been assigned for ARC.

To assign custom workspace:

  1. Select the relevant assignment.

    Screenshot that shows where to select the relevant assignment from for ARC.

  2. Select Edit assignment.

  3. In the Parameters tab, deselect the Only show parameters that need input or review option.

  4. Select a LogAnalyticsWorkspaceResource ID from the drop-down menu.

    Screenshot showing where the drop-down menu is located for ARC.

  5. Select Review + create.

  6. Select Create.

Remove the Defender profile

To remove this - or any - Defender for Cloud extension, it's not enough to turn off auto provisioning:

  • Enabling auto provisioning, potentially impacts existing and future machines.
  • Disabling auto provisioning for an extension, only affects the future machines - nothing is uninstalled by disabling auto provisioning.

Nevertheless, to ensure the Defender for Containers components aren't automatically provisioned to your resources from now on, disable auto provisioning of the extensions as explained in Configure auto provisioning for agents and extensions from Microsoft Defender for Cloud.

You can remove the profile using the REST API or a Resource Manager template as explained in the tabs below.

Use REST API to remove the Defender profile from AKS

To remove the profile using the REST API, run the following PUT command:

https://management.azure.com/subscriptions/{{SubscriptionId}}/resourcegroups/{{ResourceGroup}}/providers/Microsoft.ContainerService/managedClusters/{{ClusterName}}?api-version={{ApiVersion}}
Name Description Mandatory
SubscriptionId Cluster's subscription ID Yes
ResourceGroup Cluster's resource group Yes
ClusterName Cluster's name Yes
ApiVersion API version, must be >= 2021-07-01 and <= 2022-04-01 Yes

Request body:

{
  "location": "{{Location}}",
  "properties": {
    "securityProfile": {
            "azureDefender": {
                "enabled": false
            }
        }
    }
}

Request body parameters:

Name Description Mandatory
location Cluster's location Yes
properties.securityProfile.azureDefender.enabled Determines whether to enable or disable Microsoft Defender for Containers on the cluster Yes

FAQ

How can I use my existing Log Analytics workspace?

You can use your existing Log Analytics workspace by following the steps in the Assign a custom workspace workspace section of this article.

Can I delete the default workspaces created by Defender for Cloud?

We don't recommend deleting the default workspace. Defender for Containers uses the default workspaces to collect security data from your clusters. Defender for Containers will be unable to collect data, and some security recommendations and alerts, will become unavailable if you delete the default workspace.

I deleted my default workspace, how can I get it back?

To recover your default workspace, you need to remove the Defender profile/extension, and reinstall the agent. Reinstalling the Defender profile/extension creates a new default workspace.

Where is the default Log Analytics workspace located?

Depending on your region, the default Log Analytics workspace located will be located in various locations. To check your region see Where is the default Log Analytics workspace created?

My organization requires me to tag my resources, and auto provision failed, what went wrong?

The Defender agent uses the Log analytics workspace to send data from your Kubernetes clusters to Defender for Cloud. The Defender for Cloud's auto provision feature via the built-in policy, adds the Log analytic workspace and the resource group as a parameter for the agent to use.

However, if your organization has a policy that requires a specific tag on your resources, it may cause auto provisioning to fail during the resource group or the default workspace creation stage. If it fails, you can either:

  • Assign a custom workspace and add any tag your organization requires.

    or

  • If your company requires you to tag your resource, you should navigate to that policy and exclude the following resources:

    1. The resource group DefaultResourceGroup-<RegionShortCode>
    2. The Workspace DefaultWorkspace-<sub-id>-<RegionShortCode>

    RegionShortCode is a 2-4 letters string.

Learn More

You can check out the following blogs:

Next steps

Use Defender for Containers to scan your ACR images for vulnerabilities.