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

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

始める前に

  1. Google Cloud アカウントにログインします。 Google Cloudを初めて使用する場合は、 アカウントを作成して、実際のシナリオでの Google プロダクトのパフォーマンスを評価してください。新規のお客様には、ワークロードの実行、テスト、デプロイができる無料クレジット $300 分を差し上げます。
  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

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

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

    Cloud Shell を開く

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

  2. docker を使用してコンテナ イメージを pull します。

    docker pull golang:1.17.6-alpine
    
  3. スキャンを実行します。

    gcloud artifacts docker images scan golang:1.17.6-alpine --additional-package-types=GO
    

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

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

    gcloud artifacts docker images list-vulnerabilities \
    projects/my-project/locations/us/scans/a54f12b0-ca2d-4d93-8da5-5cf48e9e20ef
    

    出力には、Go、Go 標準ライブラリ、Linux パッケージの脆弱性の一覧が含まれます。次のラベルは、Go の脆弱性のタイプを示します。

    • packageType:GO_STDLIB。Go 標準ライブラリの脆弱性。これは、バイナリのビルドに使用された Go ツールチェーン、またはツールチェーンにバンドルされた標準ライブラリで脆弱性が発見されたことを示します。考えられる解決策は、ビルド ツールチェーンをアップグレードすることです。

    • packageType:GO。Go パッケージの脆弱性。これは、サードパーティ パッケージで脆弱性が見つかったことを示します。依存モジュールをアップグレードすることが解決策になる可能性があります。

クリーンアップ

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

  1. Google Cloud コンソールで [リソースの管理] ページに移動します。

    [リソースの管理] に移動

  2. プロジェクト リストで、削除するプロジェクトを選択し、[削除] をクリックします。
  3. ダイアログでプロジェクト ID を入力し、[シャットダウン] をクリックしてプロジェクトを削除します。

次のステップ