Esegui la scansione manuale dei pacchetti del sistema operativo

Questa guida rapida mostra come eseguire il pull di un'immagine container, analizzarla manualmente per individuare le vulnerabilità del sistema operativo con l'API On-Demand Scanning e recuperare le vulnerabilità identificate. Per seguire questa guida rapida, utilizzerai Cloud Shell e un'immagine di esempio di Ubuntu.

Prima di iniziare

  1. Accedi al tuo Google Cloud account. Se non conosci Google Cloud, crea un account per valutare le prestazioni 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

Scarica ed esegui 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'ultima immagine di Ubuntu.

    docker pull ubuntu:latest
    
  3. Esegui la scansione.

    gcloud artifacts docker images scan ubuntu:latest
    

    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: ubuntu:latest
    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
    

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.

Passaggi successivi