Scan Java 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 Maven 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.

    Go to project selector

  3. Make sure that billing is enabled for your Google Cloud project.

  4. Enable the On-Demand Scanning API.

    Enable the API

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

    Go to project selector

  6. Make sure that billing is enabled for your Google Cloud project.

  7. Enable the On-Demand Scanning API.

    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:

    docker pull jenkins:2.60.3-alpine
    
  3. Run the scan:

    gcloud artifacts docker images scan jenkins:2.60.3-alpine --additional-package-types=MAVEN
    

    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/1a6fd941-b997-4e5f-ba4f-6351f30e7dad]
    Done.
    
    done: true
    metadata:
      '@type': type.googleapis.com/google.cloud.ondemandscanning.v1.AnalyzePackagesMetadata
      createTime: '2021-01-26T13:43:53.112123Z'
      resourceUri: jenkins:2.60.3-alpine
    name: projects/my-project/locations/us/operations/1a6fd941-b99f-4eaf-ba4f-6e5af30e7dad
    response:
      '@type': type.googleapis.com/google.cloud.ondemandscanning.v1.AnalyzePackagesResponse
      scan: projects/my-project/locations/us/scans/893c91ce-7fe6-4f1a-a69a-d6ca1b465160
    
  4. Use the scan name, the value of scan from the output, to fetch the scan results:

    gcloud artifacts docker images list-vulnerabilities \
    projects/my-project/locations/us/scans/893c91ce-7fe6-4f1a-a69a-d6ca1b465160
    

    The output contains a list of Maven and Linux package vulnerabilities. Maven package vulnerabilities can be identified by the field packageType:MAVEN.

Clean up

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

If you created a new project for this guide, you can now delete the project.

  • Open the Settings page (found under IAM & Admin) in the Google Cloud console.

    Open the Settings page

  • Click Select a project.

  • Select a project you want to delete, and click Open.

  • Click Shut down.

  • Enter the Project ID, then click Shut down.

What's next