OS パッケージを手動でスキャンする

このクイックスタートでは、コンテナ イメージを pull し、オンデマンド スキャン API を使用してオペレーティング システムの脆弱性を手動でスキャンし、特定された脆弱性を取得する方法について説明します。このクイックスタートでは、Cloud Shell と Ubuntu イメージの例を使用します。

始める前に

  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 (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 (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

  8. 画像をダウンロードしてスキャンする

    1. プロジェクトで Cloud Shell を開きます。

      Cloud Shell を開く

      これにより、このガイドに沿って進めるために必要なツールがすべて含まれたターミナルが開きます。

    2. docker を使用して最新の Ubuntu イメージを pull します。

      docker pull ubuntu:latest
      
    3. スキャンを実行します。

      gcloud artifacts docker images scan ubuntu:latest
      

      これにより、スキャン プロセスがトリガーされ、完了するとスキャン名が返されます。

      ✓ 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. スキャン名(出力の scan の値)を使用して、スキャン結果を取得します。

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

    クリーンアップ

    このページで使用したリソースについて、 Google Cloud アカウントに課金されないようにするには、次の手順を実施します。

    このガイド用に新しいプロジェクトを作成した場合は、ここでプロジェクトを削除できます。

    次のステップ