> [!CAUTION]
> **Caution:** Starting on July 23, 2024, container OS vulnerability scanning is deprecated and is scheduled for shutdown on July 31, 2025. Starting on June 16, 2025, Advanced Vulnerability Insights is deprecated and is scheduled for shutdown on June 16, 2026. For more information about deprecation and shutdown dates, see [Vulnerability scanning removal from GKE](https://docs.cloud.google.com/kubernetes-engine/docs/deprecations/vulnerability-scanning-gkee.md.txt).

This page helps you get started and guides you in using the
security posture dashboard to detect vulnerabilities.
Check requirements, select from the available tiers, and learn how to enable
vulnerability scanning, deploy a test workload, view results and recommendations,
and disable the scanning.

This page is for Security specialists who monitor clusters for security
issues. To learn more about common roles and example tasks that we reference in
Google Cloud content, see
[Common GKE user roles and tasks](https://docs.cloud.google.com/kubernetes-engine/enterprise/docs/concepts/roles-tasks.md.txt).

Before reading this page, ensure that you're familiar with the general overview
of [workload vulnerability scanning](https://docs.cloud.google.com/kubernetes-engine/docs/concepts/about-workload-vulnerability-scanning.md.txt).

## Pricing

For pricing information, see
[GKE security posture dashboard pricing](https://docs.cloud.google.com/kubernetes-engine/docs/concepts/about-security-posture-dashboard.md.txt#pricing).

## Before you begin


Before you start, make sure that you have performed the following tasks:

- Enable the Google Kubernetes Engine API.
[Enable Google Kubernetes Engine API](https://console.cloud.google.com/apis/enableflow?apiid=container.googleapis.com)
- To use the Google Cloud CLI for this task, [install](https://docs.cloud.google.com/sdk/docs/install) and then [initialize](https://docs.cloud.google.com/sdk/docs/initialize.md.txt) the gcloud CLI. If you previously installed the gcloud CLI, get the latest version by running the `gcloud components update` command. Earlier gcloud CLI versions might not support running the commands in this document.

  > [!NOTE]
  > **Note:** For existing gcloud CLI installations, make sure to set the `compute/region` [property](https://docs.cloud.google.com/sdk/docs/properties.md.txt#setting_properties). If you use primarily zonal clusters, set the `compute/zone` instead. By setting a default location, you can avoid errors in the gcloud CLI like the following: `One of [--zone, --region] must be supplied: Please specify location`. You might need to specify the location in certain commands if the location of your cluster differs from the default that you set.

<!-- -->

- Enable the Container Security API.

  [Enable
  Container Security API](https://console.cloud.google.com/apis/enableflow?apiid=containersecurity.googleapis.com)
- To use advanced vulnerability insights, enable the
  Container Analysis API.

  [Enable
  Container Analysis API](https://console.cloud.google.com/apis/enableflow?apiid=containeranalysis.googleapis.com)

### Requirements

-

  To get the permissions that
  you need to use workload vulnerability scanning,

  ask your administrator to grant you the
  [Security Posture Viewer](https://docs.cloud.google.com/iam/docs/roles-permissions/containersecurity.md.txt#containersecurity.viewer) (`roles/containersecurity.viewer`) IAM role on your Google Cloud project.


  For more information about granting roles, see [Manage access to projects, folders, and organizations](https://docs.cloud.google.com/iam/docs/granting-changing-revoking-access.md.txt).


  This predefined role contains

  the permissions required to use workload vulnerability scanning. To see the exact permissions that are
  required, expand the **Required permissions** section:


  #### Required permissions

  The following permissions are required to use workload vulnerability scanning:
  - `resourcemanager.projects.get`
  - `resourcemanager.projects.list`
  - `containersecurity.locations.list`
  - `containersecurity.locations.get`
  - `containersecurity.clusterSummaries.list`
  - `containersecurity.findings.list`


  You might also be able to get
  these permissions
  with [custom roles](https://docs.cloud.google.com/iam/docs/creating-custom-roles.md.txt) or
  other [predefined roles](https://docs.cloud.google.com/iam/docs/roles-overview.md.txt#predefined).
- Advanced vulnerability insights requires GKE version 1.27 or later.

## Workload vulnerability scanning tiers

You enable vulnerability scanning in tiers, each of which adds scanning
capabilities as follows. If you use Google Kubernetes Engine (GKE) Enterprise edition to manage fleets of
clusters, you can also configure fleet-level vulnerability scanning settings
that apply to all member clusters. For instructions, see
[Configure GKE security posture dashboard features at fleet-level](https://docs.cloud.google.com/kubernetes-engine/docs/how-to/fleet-security-posture.md.txt).

| Tier | Enabled capabilities | GKE version requirement |
|---|---|---|
| [Standard](https://docs.cloud.google.com/kubernetes-engine/docs/how-to/security-posture-vulnerability-scanning.md.txt#enable-os-vuln-scanning) `standard` | Container OS vulnerability scanning | - **GKE Enterprise edition**: Enabled by default in all new clusters running version 1.27 and later |
| [Advanced vulnerability insights](https://docs.cloud.google.com/kubernetes-engine/docs/how-to/security-posture-vulnerability-scanning.md.txt#enable-advanced-insights) `enterprise` | - Container OS vulnerability scanning - Language package vulnerability scanning | - **GKE Enterprise edition**: Enabled by default in all new clusters running version 1.27 and later - **GKE Standard edition**: Disabled by default in all new clusters. |

For more information, about each capability, see
[About workload vulnerability scanning](https://docs.cloud.google.com/kubernetes-engine/docs/concepts/about-workload-vulnerability-scanning.md.txt).

## Enable container OS vulnerability scanning

Container OS vulnerability scanning is enabled by default in new Autopilot clusters
running version 1.27 and later. This section shows you how to enable this feature in new existing
Standard clusters and in Autopilot clusters running versions prior to 1.27.

### Enable container OS scanning on an existing cluster

### gcloud

Update the cluster:

```bash
gcloud container clusters update CLUSTER_NAME \
    --location=CONTROL_PLANE_LOCATION \
    --workload-vulnerability-scanning=standard
```

<br />

Replace the following:

- `CLUSTER_NAME`: the name of your cluster.
- `CONTROL_PLANE_LOCATION`: the [location](https://docs.cloud.google.com/compute/docs/regions-zones.md.txt#available) of the control plane of your cluster. Provide a region for regional Standard and Autopilot clusters, or a zone for zonal Standard clusters.

### Console

1. Go to the **Security Posture** page in the Google Cloud console.

   [Go to Security Posture](https://console.cloud.google.com/kubernetes/security/dashboard)
2. Click the **Settings** tab.
3. In the **Vulnerability scan enabled clusters** section, click **Select clusters**.
4. Select the checkboxes for the clusters that you want to add.
5. In the **Select action** drop-down menu, select **Set to Basic**.
6. Click **Apply**.

## Enable advanced vulnerability insights

Advanced vulnerability insights enables continuous scanning of your running applications for the
following vulnerability types:

- Container OS vulnerabilities
- Language package vulnerabilities

When you enable advanced vulnerability insights, the container OS vulnerability scanning
capability is automatically enabled and can't be separately disabled.

### Requirements

- Ensure that you enabled the Container Analysis API in your project.

  [Enable
  Container Analysis API](https://console.cloud.google.com/apis/enableflow?apiid=containeranalysis.googleapis.com)

### Enable advanced vulnerability insights on an existing cluster

### gcloud

Update the cluster:

```bash
gcloud container clusters update CLUSTER_NAME \
    --location=CONTROL_PLANE_LOCATION \
    --workload-vulnerability-scanning=enterprise
```

<br />

Replace the following:

- `CLUSTER_NAME`: the name of your cluster.
- `CONTROL_PLANE_LOCATION`: the [location](https://docs.cloud.google.com/compute/docs/regions-zones.md.txt#available) of the control plane of your cluster. Provide a region for regional Standard and Autopilot clusters, or a zone for zonal Standard clusters.

### Console

1. Go to the **Security Posture** page in the Google Cloud console.

   [Go to Security Posture](https://console.cloud.google.com/kubernetes/security/dashboard)
2. Click the **Settings** tab.
3. In the **Vulnerability scan enabled clusters** section, click **Select clusters**.
4. Select the checkboxes for the clusters that you want to add.
5. In the **Select action** drop-down menu, select **Set to Advanced**.
6. Click **Apply**.

## Deploy a test workload

In the following section, you use example Deployment manifests.
A *Deployment* is a Kubernetes API object that lets you run multiple replicas of Pods that are distributed among the nodes in a cluster..

The following manifests have known vulnerabilities
for demonstration purposes. In practice, if you know an application is
vulnerable, you probably shouldn't run it.

1. Save the following manifest as `os-vuln-sample.yaml`:

   ```yaml
   apiVersion: apps/v1
   kind: Deployment
   metadata:
     name: frontend
   spec:
     replicas: 1
     selector:
       matchLabels:
         app: guestbook
         tier: frontend
     template:
       metadata:
         labels:
           app: guestbook
           tier: frontend
       spec:
         containers:
         - name: php-redis
           image: us-docker.pkg.dev/google-samples/containers/gke/gb-frontend:v5
           env:
           - name: GET_HOSTS_FROM
             value: "dns"
           resources:
             requests:
               cpu: 100m
               memory: 100Mi
           ports:
           - containerPort: 80
   ```
2. Review the following manifest, which contains a known Maven vulnerability:

   ```yaml
   apiVersion: apps/v1
   kind: Deployment
   metadata:
     name: maven-vulns
   spec:
     replicas: 1
     selector:
       matchLabels:
         app: mavenvulns
     template:
       metadata:
         labels:
           app: mavenvulns
       spec:
         containers:
         - name: maven-vulns-app
           image: us-docker.pkg.dev/google-samples/containers/gke/security/maven-vulns
           # This app listens on port 8080 for web traffic by default.
           ports:
           - containerPort: 8080
           env:
             - name: PORT
               value: "8080"
           resources:
             requests:
               memory: "1Gi"
               cpu: "500m"
               ephemeral-storage: "1Gi"
             limits:
               memory: "1Gi"
               cpu: "500m"
               ephemeral-storage: "1Gi"
   ```
3. Optionally, get credentials for your cluster:

   ```bash
   gcloud container clusters get-credentials CLUSTER_NAME \
       --location=CONTROL_PLANE_LOCATION
   ```
4. Deploy the applications to your cluster:

   ```bash
   kubectl apply -f os-vuln-sample.yaml
   kubectl apply -f https://raw.githubusercontent.com/GoogleCloudPlatform/kubernetes-engine-samples/main/security/language-vulns/maven/deployment.yaml
   ```

To test other vulnerabilities, try deploying earlier versions of images such as
`nginx` in staging environments.

## View and action the results

The initial scan takes at least 15 minutes to return results, depending on how
many workloads are scanned. GKE displays the results on the
**security posture dashboard** and automatically adds entries to
Logging.

### View results

To see an overview of discovered concerns across your project's clusters and
workloads, do the following:

1. Go to the **Security Posture** page in the Google Cloud console.

   [Go to Security Posture](https://console.cloud.google.com/kubernetes/security/dashboard)
2. Click the **Concerns** tab.

3. In the **Filter concerns** pane, in the **Concern type** section, select the
   **Vulnerability** checkbox.

### View concern details and recommendations

To view detailed information about a specific vulnerability, click the row
containing that concern.

The **Vulnerability Concern** pane shows the following information:

- **Description:** a description of the concern including a CVE number if applicable and a detailed description of the vulnerability and its potential impact.
- **Recommended action:** actions that you can take to address the vulnerability, such as fixed package versions and where to apply the fix.

### View logs for discovered concerns

GKE adds entries to the `_Default` log bucket in Logging
for each discovered concern. These logs are only retained for a specific period. For details, see
[Logs retention periods](https://docs.cloud.google.com/logging/quotas.md.txt#logs_retention_periods).

1. In the Google Cloud console, go to the **Logs Explorer**:

   [Go
   to Logs Explorer](https://console.cloud.google.com/logs/query)
2. In the **Query** field, specify the following query:

   ```sql
   resource.type="k8s_cluster"
   jsonPayload.@type="type.googleapis.com/cloud.kubernetes.security.containersecurity_logging.Finding"
   jsonPayload.type="FINDING_TYPE_VULNERABILITY"
   ```
3. Click **Run query**.

To receive notifications when GKE adds new findings to
Logging, set up log-based alerts for this query. For more
information, see
[Configure log-based alerts](https://docs.cloud.google.com/logging/docs/alerting/log-based-alerts.md.txt#lba-definition).

## Clean up

1. Delete the sample workload that you deployed:

   ```bash
   kubectl delete deployment frontend
   ```
2. Optionally, delete the cluster that you used:

   ```bash
   gcloud container clusters delete CLUSTER_NAME \
       --location=CONTROL_PLANE_LOCATION
   ```

## Disable workload vulnerability scanning

You can disable workload vulnerability scanning using either the gcloud CLI
or the Google Cloud console.

### gcloud

Run the following command:


```bash
gcloud container clusters update CLUSTER_NAME \
    --location=CONTROL_PLANE_LOCATION \
    --workload-vulnerability-scanning=disabled
```

Replace the following:

- `CLUSTER_NAME`: the name of your cluster.
- `CONTROL_PLANE_LOCATION`: the [location](https://docs.cloud.google.com/compute/docs/regions-zones.md.txt#available) of the control plane of your cluster. Provide a region for regional Standard and Autopilot clusters, or a zone for zonal Standard clusters.

### Console

1. Go to the **Security Posture** page in the Google Cloud console.

   [Go to Security Posture](https://console.cloud.google.com/kubernetes/security/dashboard)
2. Click the **Settings** tab.
3. In the **Vulnerability scan enabled clusters** section, click **Select clusters**.
4. Select the checkboxes for the clusters that you want to remove.
5. In the **Select action** drop-down menu, select **Set to Disabled**.
6. Click **Apply**.

## What's next

- [Learn more about the security posture dashboard](https://docs.cloud.google.com/kubernetes-engine/docs/concepts/about-security-posture-dashboard.md.txt).
- [Learn how to scan your workloads for configuration concerns](https://docs.cloud.google.com/kubernetes-engine/docs/how-to/protect-workload-configuration.md.txt).