Eseguire la scansione manuale dei pacchetti Java

Questa guida rapida mostra come eseguire il pull di un'immagine container, eseguirne la scansione manuale con la scansione on demand e recuperare le vulnerabilità identificate per i pacchetti di sistema e Maven. Per seguire questa guida rapida, utilizzerai Cloud Shell e un'immagine Alpine di esempio.

Prima di iniziare

  1. Accedi al tuo Google Cloud account. Se non hai mai utilizzato Google Cloud, crea un account per valutare il rendimento dei nostri prodotti in scenari reali. I nuovi clienti ricevono anche 300 $di crediti senza costi per l'esecuzione, il test e il deployment dei workload.
  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

Scaricare ed eseguire la scansione di un'immagine

  1. Apri Cloud Shell nel tuo progetto.

    Apri Cloud Shell

    Si apre un terminale con tutti gli strumenti necessari per seguire questa guida.

  2. Utilizza docker per eseguire il pull dell'immagine container:

    docker pull jenkins:2.60.3-alpine
    
  3. Esegui la scansione:

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

    Viene attivato il processo di scansione e viene restituito il nome della scansione al termine:

    ✓ 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. Utilizza il nome della scansione, il valore di scan nell'output, per recuperare i risultati della scansione:

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

    L'output contiene un elenco di vulnerabilità dei pacchetti Maven e Linux. Le vulnerabilità dei pacchetti Maven possono essere identificate dal campo packageType:MAVEN.

Libera spazio

Per evitare che al tuo Google Cloud account vengano addebitati costi relativi alle risorse utilizzate in questa pagina, segui questi passaggi.

Se hai creato un nuovo progetto per questa guida, ora puoi eliminarlo.

  • Apri la pagina Impostazioni (che si trova in IAM e amministrazione) nella Google Cloud console.

    Apri la pagina Impostazioni

  • Fai clic su Seleziona un progetto.

  • Seleziona un progetto che vuoi eliminare e fai clic su Apri.

  • Fai clic su Arresto.

  • Inserisci l'ID progetto e fai clic su Chiudi.

Passaggi successivi