Container Analysis provides vulnerability information and other types of metadata for the container images in Container Registry or Artifact Registry. The metadata is stored as notes. An occurrence is created for each instance of a note associated with an image. See Pricing for pricing information.
This page describes how to view and filter notes and occurrences.
Before you begin
- Connectez-vous à votre compte Google.
Si vous n'en possédez pas déjà un, vous devez en créer un.
-
Dans Google Cloud Console, sur la page de sélection du projet, sélectionnez ou créez un projet Google Cloud.
-
Assurez-vous que la facturation est activée pour votre projet Cloud. Découvrez comment vérifier que la facturation est activée pour votre projet.
- Activez l'API Container Scanning.
- Installez et initialisez le SDK Cloud.
Viewing vulnerabilities and other occurrences
You can view occurrences for your images in Container Registry or
Artifact Registry using Cloud Console, gcloud
command-line tool,
or the Container Analysis API. If an image has vulnerabilities,
you can then obtain the details.
Viewing occurrences in Google Cloud Console
To view occurrences for an image:
Go the list of images.
Artifact Registry
Open the Repositories page.
In the repository list, click the repository that contains the image.
Container Registry
Open the Repositories page.
Click on the image name.
Vulnerability totals for the images are displayed in the Vulnerabilities column.
To view the list of vulnerabilities for an image, click the link in the Vulnerabilities column.
The vulnerability list shows the severity, availability of a fix, and the name of the package that contains the vulnerability.
To learn more about a specific vulnerability from the vulnerability source, click the link in the Documentation column.
Viewing occurrences using gcloud
To view occurrences for an image, run the following command:
Artifact Registry
gcloud artifacts docker images list --show-occurrences \
LOCATION-docker.pkg.dev/PROJECT_ID/REPOSITORY/IMAGE_ID
where:
- LOCATION is the regional or multi-regional location of the repository.
- PROJECT_ID is your Google Cloud Console project ID.
- REPOSITORY is the name of the repository where the image is stored.
- IMAGE_ID is the name of the image in the repository. You cannot specify an image tag with this command.
By default, the command returns the 10 most recent images. To show a
different number of images, use the --show-occurrences-from
flag.
For example, this command returns the 25 most recent images.
gcloud artifacts docker images list --show-occurrences-from=25 \
us-central1-docker.pkg.dev/my-project/my-repo/my-image
Container Registry
gcloud container images list-tags \
HOSTNAME/PROJECT_ID/IMAGE_ID
where:
- HOSTNAME is the multi-regional hostname:
gcr.io
asia.gcr.io
eu.gcr.io
us.gcr.io
- PROJECT_ID is the ID of the project containing the images.
- IMAGE_ID is the ID of the image for which you want to view vulnerabilities. You cannot specify an image tag with this command.
By default, the command returns the 10 most recent images. To show a
different number of images, use the --show-occurrences-from
flag.
For example, this command returns the 25 most recent images.
gcloud container images list-tags --show-occurrences-from=25 \
gcr.io/my-project/my-image
To view information about a tag or a layer:
Artifact Registry
gcloud artifacts docker images describe \
LOCATION-docker.pkg.dev/PROJECT_ID/REPOSITORY/IMAGE_ID:TAG
or
gcloud artifacts docker images describe \
LOCATION-docker.pkg.dev/PROJECT_ID/REPOSITORY/IMAGE_ID@sha256:HASH
where:
- LOCATION is the regional or multi-regional location of the repository.
- PROJECT_ID is your Google Cloud Console project ID.
- REPOSITORY is the name of the repository where the image is stored.
- IMAGE_ID is the name of the image in the repository.
- TAG is the image tag about which you want to get information.
- HASH is the image digest.
Container Registry
gcloud container images describe HOSTNAME/PROJECT_ID/IMAGE_ID:TAG
or
gcloud container images describe HOSTNAME/PROJECT_ID/IMAGE_ID@sha256:HASH
where:
- HOSTNAME is the multi-regional hostname:
gcr.io
asia.gcr.io
eu.gcr.io
us.gcr.io
- PROJECT_ID is the ID of the project containing the images.
- IMAGE_ID is the ID of the image for which you want to view vulnerabilities.
- TAG is the image tag about which you want to get information.
- HASH is the image digest.
To view vulnerabilities for an image tag or a layer:
Artifact Registry
gcloud artifacts docker images describe \
LOCATION-docker.pkg.dev/PROJECT_ID/REPOSITORY/IMAGE_ID:TAG \
--show-package-vulnerability
or
gcloud artifacts docker images describe \
LOCATION-docker.pkg.dev/PROJECT_ID/REPOSITORY/IMAGE_ID@sha256:HASH \
--show-package-vulnerability
Container Registry
gcloud container images describe HOSTNAME/PROJECT_ID/IMAGE_ID:TAG \
--show-package-vulnerability
or
gcloud container images describe HOSTNAME/PROJECT_ID/IMAGE_ID@sha256:HASH \
--show-package-vulnerability
To filter the vulnerability occurrences:
Artifact Registry
gcloud artifacts docker images list --show-occurrences \
LOCATION-docker.pkg.dev/PROJECT_ID/REPOSITORY/IMAGE_ID --occurrence-filter=FILTER_EXPRESSION
where:
- LOCATION is the regional or multi-regional location of the repository.
- PROJECT_ID is your Google Cloud Console project ID.
- REPOSITORY is the name of the repository where the image is stored.
- IMAGE_ID is the name of the image in the repository.
- FILTER_EXPRESSION is a sample filter expression in the format explained in Filtering vulnerability occurrences.
Container Registry
gcloud container images list-tags \
HOSTNAME/PROJECT_ID/IMAGE_ID --occurrence-filter=FILTER_EXPRESSION
where:
- HOSTNAME is the multi-regional hostname:
gcr.io
asia.gcr.io
eu.gcr.io
us.gcr.io
- PROJECT_ID is the ID of the project containing the images.
- IMAGE_ID is the ID of the image for which you want to view vulnerability occurrences.
- FILTER_EXPRESSION is a sample filter expression in the format explained in Filtering vulnerability occurrences.
Viewing occurrences using the API or code
To view occurrences for an image, use the appropriate snippet. The code snippets specify URLs for images in Container Registry. If you are using Artifact Registry, specify images with a URL in the format:
LOCATION-docker.pkg.dev/PROJECT_ID/REPOSITORY/IMAGE_ID
API
Using cURL
To get a list of occurrences in your project:
curl -X GET -H "Content-Type: application/json" -H \
"Authorization: Bearer $(gcloud auth print-access-token)" \
https://containeranalysis.googleapis.com/v1/projects/PROJECT_ID/occurrences
To get a summary of vulnerabilities in your project:
curl -X GET -H "Content-Type: application/json" -H \
"Authorization: Bearer $(gcloud auth print-access-token)" \
https://containeranalysis.googleapis.com/v1/projects/PROJECT_ID/occurrences:vulnerabilitySummary
To get an occurrence:
curl -X GET -H "Content-Type: application/json" -H \
"Authorization: Bearer $(gcloud auth print-access-token)" \
https://containeranalysis.googleapis.com/v1/projects/PROJECT_ID/occurrences/OCCURRENCE_ID
Java
To learn how to install and use the client library for Container Analysis, see the Container Analysis Client Libraries. For more information, see the Container Analysis Java API reference documentation.
Go
To learn how to install and use the client library for Container Analysis, see the Container Analysis Client Libraries. For more information, see the Container Analysis Go API reference documentation.
Node.js
To learn how to install and use the client library for Container Analysis, see the Container Analysis Client Libraries. For more information, see the Container Analysis Node.js API reference documentation.
Ruby
To learn how to install and use the client library for Container Analysis, see the Container Analysis Client Libraries. For more information, see the Container Analysis Ruby API reference documentation.
Python
To learn how to install and use the client library for Container Analysis, see the Container Analysis Client Libraries. For more information, see the Container Analysis Python API reference documentation.
Filtering occurrences
You can use filter strings in the gcloud
commands and the
Container Analysis API to filter occurrences before viewing them. The
following sections describe the supported search filters.
Viewing discovery occurrences
When an image is initially pushed to the Container Registry, it creates a discovery occurrence, which contains information about the initial scan of the container image.
To retrieve the discovery occurrence for an image, use the following filter expression:
kind="DISCOVERY" AND resourceUrl="RESOURCE_URL"
The following snippet shows how to use the above filter expression to view discovery occurrences for an image. The code snippets specify URLs for images in Container Registry. If you are using Artifact Registry, specify images with a URL in the format:
LOCATION-docker.pkg.dev/PROJECT_ID/REPOSITORY/IMAGE_ID
gcloud
To view discovery occurrences for an image:
In this case the expression is not used directly in the command, but the same information is passed as arguments:
Artifact Registry:
gcloud artifacts docker images list --show-occurrences \
--occurrence-filter='kind="DISCOVERY"' --format=json \
LOCATION-docker.pkg.dev/PROJECT_ID/REPOSITORY/IMAGE_ID
Container Registry:
gcloud container images list-tags \
--occurrence-filter='kind="DISCOVERY"' --format=json HOSTNAME/PROJECT_ID/IMAGE_ID
API
To retrieve the discovery occurrence, the above filter expression should be URL
encoded and embedded in a GET
request as follows:
GET https://containeranalysis.googleapis.com/v1/projects/PROJECT_ID/occurrences?filter=kind%3D%22DISCOVERY%22%20AND%20resourceUrl%3D%22ENCODED_RESOURCE_URL%22
See
projects.occurrences.get
API endpoint for more details.
Java
To learn how to install and use the client library for Container Analysis, see the Container Analysis Client Libraries. For more information, see the Container Analysis Java API reference documentation.
Go
To learn how to install and use the client library for Container Analysis, see the Container Analysis Client Libraries. For more information, see the Container Analysis Go API reference documentation.
Node.js
To learn how to install and use the client library for Container Analysis, see the Container Analysis Client Libraries. For more information, see the Container Analysis Node.js API reference documentation.
Ruby
To learn how to install and use the client library for Container Analysis, see the Container Analysis Client Libraries. For more information, see the Container Analysis Ruby API reference documentation.
Python
To learn how to install and use the client library for Container Analysis, see the Container Analysis Client Libraries. For more information, see the Container Analysis Python API reference documentation.
Viewing vulnerability occurrences
To view vulnerability occurrences for a specific image, create a query with a filter expression:
kind="VULNERABILITY" AND resourceUrl="RESOURCE_URL"
The following snippet shows how to retrieve a list of vulnerability occurrences for an image. The code snippets specify URLs for images in Container Registry. If you are using Artifact Registry, specify images with a URL in the format:
LOCATION-docker.pkg.dev/PROJECT_ID/REPOSITORY/IMAGE_ID
gcloud
To view vulnerability occurrences for an image:
In this case the expression is not used directly in the command, but the same information is passed as arguments:
Artifact Registry
gcloud artifacts docker images list --show-occurrences \
--occurrence-filter='kind="VULNERABILITY"' --format=json \
LOCATION-docker.pkg.dev/PROJECT_ID/REPOSITORY/IMAGE_ID
Container Registry
gcloud container images list-tags \
--occurrence-filter='kind="VULNERABILITY"' --format=json HOSTNAME/PROJECT_ID/IMAGE_ID
API
The desired resource URL should be URL encoded, and embedded in a GET request as follows:
GET https://containeranalysis.googleapis.com/v1/projects/PROJECT_ID/occurrences?filter=kind%3D%22VULNERABILITY%22%20AND%20resourceUrl%3D%22ENCODED_RESOURCE_URL%22
See
projects.occurrences.get
API endpoint for more details.
Java
To learn how to install and use the client library for Container Analysis, see the Container Analysis Client Libraries. For more information, see the Container Analysis Java API reference documentation.
Go
To learn how to install and use the client library for Container Analysis, see the Container Analysis Client Libraries. For more information, see the Container Analysis Go API reference documentation.
Node.js
To learn how to install and use the client library for Container Analysis, see the Container Analysis Client Libraries. For more information, see the Container Analysis Node.js API reference documentation.
Ruby
To learn how to install and use the client library for Container Analysis, see the Container Analysis Client Libraries. For more information, see the Container Analysis Ruby API reference documentation.
Python
To learn how to install and use the client library for Container Analysis, see the Container Analysis Client Libraries. For more information, see the Container Analysis Python API reference documentation.
Viewing occurrences of a specific type
In the two previous examples the only difference between the filter expressions
is the value of kind
, which identifies the type of occurrence. Use
this field to limit the list of occurrences to a particular type, such as a
vulnerability or deployment.
To retrieve occurrences for a specific image, use this filter expression:
kind="NOTE_KIND" AND resourceUrl="RESOURCE_URL"
where:
- NOTE_KIND is the
kind of note.
- For example, use the kind
DISCOVERY
to list discovery occurrences. These are created for images when they are initially pushed to the Container Registry. - To list vulnerability occurrences, use the kind
VULNERABILITY
.
- For example, use the kind
-
RESOURCE_URL is the complete URL of the image
https://HOSTNAME/PROJECT_ID/IMAGE_ID@sha256:HASH
The filter expression to retrieve occurrences of a specific kind across many images is:
kind="NOTE_KIND" AND has_prefix(resourceUrl, "RESOURCE_URL_PREFIX")
where:
- RESOURCE_URL_PREFIX is the URL prefix for some images
- To list for all version of an image:
https://HOSTNAME/PROJECT_ID/IMAGE_ID@
- To list for all images in a project:
https://HOSTNAME/PROJECT_ID/
- To list for all version of an image:
Viewing images associated with a specific note
You can retrieve a list of resources that are associated with a specific note ID. For example, you can list images with a specific CVE vulnerability.
To list all images within a project that are associated with a particular note, use the following filter expression:
noteProjectId="PROVIDER_PROJECT_ID" AND noteId="NOTE_ID"
To check a specific image for a specific note, use the following filter expression:
resourceUrl="RESOURCE_URL" AND noteProjectId="PROVIDER_PROJECT_ID" \ AND noteId="NOTE_ID"
where:
- PROVIDER_PROJECT_ID is the ID of the provider project. For
example,
goog-vulnz
provides the default vulnerability analysis. - NOTE_ID is the ID of the note. Security related notes are often
formatted as
CVE-2019-12345
. -
RESOURCE_URL is the complete URL of the image
https://HOSTNAME/PROJECT_ID/IMAGE_ID@sha256:HASH
For example, to check for all images that have an occurrence of CVE-2017-16231 as analyzed by Google, use the following filter expression:
noteProjectId="goog-vulnz" AND noteId="CVE-2017-16231"
What's next
Use Pub/Sub notifications to get notifications about vulnerabilities and other metadata.
Kritis Signer and Voucher allow you create Binary Authorization attestations as part of your build pipeline. These tools can create Binary Authorization attestations based on vulnerability scanning results. For more information, see Creating attestations with Kritis Signer or Creating attestations with Voucher.