Scan Go packages manually

This quickstart shows you how to pull a container image, manually scan it with On-Demand Scanning, and retrieve identified vulnerabilities for system and Go packages. To follow this quickstart you will use Cloud Shell and an example Alpine image.

Before you begin

  1. Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get 300ドル in free credits to run, test, and deploy workloads.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  3. Verify that billing is enabled for your Google Cloud project.

  4. Enable the On-Demand Scanning API.

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains the serviceusage.services.enable permission. Learn how to grant roles.

    Enable the API

  5. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  6. Verify that billing is enabled for your Google Cloud project.

  7. Enable the On-Demand Scanning API.

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains the serviceusage.services.enable permission. Learn how to grant roles.

    Enable the API

Download and scan an image

  1. Open a Cloud Shell in your project.

    Open Cloud Shell

    This opens a terminal with all the required tools to follow this guide.

  2. Use docker to pull the container image:

    dockerpullgolang:1.17.6-alpine
    
  3. Run the scan:

    gcloudartifactsdockerimagesscangolang:1.17.6-alpine--additional-package-types=GO
    

    This triggers that scanning process and returns the scan name when finished:

    ✓ Scanning container image
     ✓ Locally extracting packages and versions from local container image
     ✓ Remotely initiating analysis of packages and versions
     ✓ Waiting for analysis operation to complete [projects/my-project/locations/us/operations/849db1f8-2fb2-4559-9fe0-8720d8cd347c]
    Done.
    done: true
    metadata:
     '@type': type.googleapis.com/google.cloud.ondemandscanning.v1.AnalyzePackagesMetadata
     createTime: '2022-01-11T16:58:11.711487Z'
     resourceUri: golang:1.16.13-alpine
    name: projects/my-project/locations/us/operations/f4adb1f8-20b2-4579-9fe0-8720d8cd347c
    response:
     '@type': type.googleapis.com/google.cloud.ondemandscanning.v1.AnalyzePackagesResponse
     scan: projects/my-project/locations/us/scans/a54f12b0-ca2d-4d93-8da5-5cf48e9e20ef
    
  4. Use the scan name, the value of scan from the output, to fetch the scan results:

    gcloudartifactsdockerimageslist-vulnerabilities\
    projects/my-project/locations/us/scans/a54f12b0-ca2d-4d93-8da5-5cf48e9e20ef
    

    The output contains a list of Go, Go standard library, and Linux package vulnerabilities. The following labels indicate the type of Go vulnerabilities:

    • packageType:GO_STDLIB. Go standard library vulnerabilities. This indicates that the vulnerability was found either in the Go toolchain used to build the binary, or in the standard library bundled with the toolchain. A possible fix is to upgrade your build toolchain.

    • packageType:GO. Go package vulnerabilities. This indicates that the vulnerability was found in a third-party package. A possible fix is to upgrade your dependent modules.

Clean up

To avoid incurring charges to your Google Cloud account for the resources used on this page, follow these steps.

  1. In the Google Cloud console, go to the Manage resources page.

    Go to Manage resources

  2. In the project list, select the project that you want to delete, and then click Delete.
  3. In the dialog, type the project ID, and then click Shut down to delete the project.

What's next

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025年11月13日 UTC.