シークレットをスキャンする

Artifact Analysis の脆弱性スキャンでは、スキャンされたイメージに保存されているサービス アカウント キーや API キーなどのシークレットを特定できます。これらのシークレットに関する情報は、脆弱性スキャンの発生レポートで確認できます。また、機密情報が公開されないように対策を講じることもできます。

概要

脆弱性スキャンでシークレットが検出されると、Artifact Analysis はシークレットの詳細を含むシークレット タイプのオカレンスを作成します。Artifact Analysis では、次のシークレットを検出できます。

シークレット

  • Anthropic 管理者キー
  • Anthropic API キー
  • Azure アクセス トークン
  • Azure ID トークン
  • Docker Hub の個人用アクセス トークン
  • GitHub アプリの更新トークン
  • GitHub アプリのサーバー間トークン
  • GitHub アプリのユーザーからサーバーへのトークン
  • GitHub の従来の個人アクセス トークン
  • GitHub のきめ細かい個人アクセス トークン
  • GitHub OAuth トークン
  • Google Cloud OAuth2(クライアント ID とシークレット)のペア
  • Google Cloud OAuth2 アクセス トークン
  • Google Cloud サービス アカウント キー
  • Google Cloud API キー
  • Huggingface API キー
  • OpenAI API キー
  • Perplexity API キー
  • Stripe の制限付きキー
  • Stripe の秘密鍵
  • Stripe Webhook シークレット

発生レポートのさまざまな種類のシークレットの詳細については、Artifact Analysis API ドキュメントの SecretKind をご覧ください。

Artifact Analysis で検出できるのは、テキスト ファイルとして保存されたシークレットのみです。次のファイル拡張子がサポートされています。

  • .cer
  • .cfg
  • .crt
  • .der
  • .env
  • .html
  • .key
  • .ipynb
  • .json
  • .log
  • .md
  • .pem
  • .py
  • .pypirc
  • .textproto
  • .toml
  • .txt
  • .xml
  • .yaml

始める前に

  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 role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  3. このガイドで既存のプロジェクトを使用する場合は、このガイドを完了するために必要な権限があることを確認します。新しいプロジェクトを作成した場合は、必要な権限がすでに付与されています。

  4. Verify that billing is enabled for your Google Cloud project.

  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. このガイドで既存のプロジェクトを使用する場合は、このガイドを完了するために必要な権限があることを確認します。新しいプロジェクトを作成した場合は、必要な権限がすでに付与されています。

  7. Verify that billing is enabled for your Google Cloud project.

この API を有効にすると、Artifact Registry で言語パッケージ スキャンも有効になります。サポートされているパッケージ タイプをご覧ください。

必要なロール

脆弱性スキャン中にイメージでシークレットをスキャンするために必要な権限を取得するには、プロジェクトに対する次の IAM ロールを付与するよう管理者に依頼してください。

ロールの付与については、プロジェクト、フォルダ、組織へのアクセス権の管理をご覧ください。

必要な権限は、カスタムロールや他の事前定義ロールから取得することもできます。

Secret を表示する

脆弱性スキャン後にシークレットを表示する手順は次のとおりです。

  1. Docker イメージを Artifact Registry に push します

  2. 脆弱性スキャンが完了するまで待ちます。

  3. 次のコマンドを実行して、スキャンされたイメージのシークレットの検出結果を一覧表示します。

    $ curl -G -H "Content-Type: application/json"   -H "Authorization: Bearer $(gcloud auth print-access-token)" --data-urlencode "filter=(kind=\"SECRET\" AND resourceUrl=\"RESOURCE_URL\")" https://containeranalysis.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/occurrences
    

    ここで

    • PROJECT_ID は Google Cloud コンソールのプロジェクト ID です。
    • LOCATION は、リポジトリのリージョンまたはマルチリージョンのロケーションです。
    • RESOURCE_URL は、スキャンされた画像の URL です(https://LOCATION-docker.pkg.dev/PROJECT_ID/REPOSITORY/IMAGE_ID 形式)。

    次のレスポンス例は、考えられる結果を示しています。この場合、my_api_key.yaml という名前のGoogle Cloud API キーがイメージの documents ディレクトリで特定されました。secret 属性には、検出されたシークレットに関する情報が表示されます。

    {
      "occurrences": [
        {
          "name": "projects/my-project/locations/us-east1/occurrences/45619d23-66b1-4f5b-9b12-9060d7f97ff3",
          "resourceUri": "https://us-east1-docker.pkg.dev/my-project/my-images/test-image-0106@sha256:73cf5b9a788dc391c40e9cf1599144d03875b5d2dc935988ebfef8260bd2678e",
          "noteName": "projects/my-project/locations/us-east1/notes/secret_kind_gcp_api_key",
          "kind": "SECRET",
          "createTime": "2026-01-06T21:16:14.905851Z",
          "updateTime": "2026-01-06T21:16:14.905851Z",
          "secret": {
            "kind": "SECRET_KIND_GCP_API_KEY",
            "locations": [
              {
                "fileLocation": {
                  "filePath": "documents/my_api_key.yaml",
                  "layerDetails": {
                    "index": 2,
                    "diffId": "7b76df10d6d90391830392eac96b0ef2d2d43822c6ff4754aa6daea0fe14a8c5",
                    "command": "COPY . . # buildkit",
                    "chainId": "sha256:75df0c59982f47cc38e730e1a122b67fceaaf7797d91e1fa17ffffc5cfe7ff59"
                  }
                }
              }
            ]
          }
        }
      ]
    }
    

制限事項

  • シークレット スキャンが公開プレビュー版の期間中は、シークレット タイプのオカレンスは Container Analysis API でのみ表示できます。
  • Artifact Analysis のシークレット スキャンでは、イメージごとにシークレットごとに最大 1 つのオカレンスがレポートされます。1 回の発生につき最大 1,000 個のファイル ロケーションが返されます。
  • 特定されたシークレットで誤検出が発生する可能性があります。イメージに対してアクションを実行する前に、特定された各シークレットを必ず確認してください。