Memindai rahasia

Pemindaian kerentanan Artifact Analysis dapat mengidentifikasi secret, seperti kunci akun layanan dan kunci API, yang disimpan dalam image yang dipindai. Anda dapat melihat informasi tentang secret ini dalam laporan kemunculan pemindaian kerentanan dan mengambil tindakan untuk mencegah informasi sensitif terekspos.

Ringkasan

Saat pemindaian kerentanan mendeteksi secret, Artifact Analysis akan membuat kemunculan jenis secret dengan detail tentang secret tersebut. Artifact Analysis dapat mendeteksi secret berikut:

Rahasia

  • Kunci admin Anthropic
  • Kunci API Anthropic
  • Token akses Azure
  • Token ID Azure
  • Token akses pribadi Docker Hub
  • Token refresh aplikasi GitHub
  • Token server-ke-server aplikasi GitHub
  • Token pengguna-ke-server aplikasi GitHub
  • Token akses pribadi klasik GitHub
  • Token akses pribadi terperinci GitHub
  • Token OAuth GitHub
  • Google Cloud Pasangan OAuth2 (ID klien &secret)
  • Google Cloud Token akses OAuth2
  • Google Cloud Kunci akun layanan
  • Google Cloud Kunci API
  • Kunci API Huggingface
  • Kunci API OpenAI
  • Kunci API Perplexity
  • Kunci terbatas Stripe
  • Kunci rahasia Stripe
  • Secret webhook Stripe

Untuk mengetahui informasi mendetail tentang berbagai jenis secret dalam laporan kemunculan, lihat SecretKind dalam dokumentasi Artifact Analysis API.

Artifact Analysis hanya dapat mendeteksi secret yang disimpan sebagai file teks. Ekstensi file berikut didukung:

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

Sebelum memulai

  1. Login keakun Anda. Google Cloud Jika Anda baru menggunakan Google Cloud, buat akun untuk mengevaluasi performa produk kami dalam skenario dunia nyata. Pelanggan baru juga mendapatkan kredit gratis senilai $300 untuk menjalankan, menguji, dan men-deploy 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. If you're using an existing project for this guide, verify that you have the permissions required to complete this guide. If you created a new project, then you already have the required permissions.

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

  5. Enable the Artifact Registry and Container Scanning APIs.

    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 APIs

  6. Instal Google Cloud CLI.

  7. Jika Anda menggunakan penyedia identitas (IdP) eksternal, Anda harus login ke gcloud CLI dengan identitas gabungan Anda terlebih dahulu.

  8. Untuk melakukan inisialisasi gcloud CLI, jalankan perintah berikut:

    gcloud init
  9. 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

  10. If you're using an existing project for this guide, verify that you have the permissions required to complete this guide. If you created a new project, then you already have the required permissions.

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

  12. Enable the Artifact Registry and Container Scanning APIs.

    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 APIs

  13. Instal Google Cloud CLI.

  14. Jika Anda menggunakan penyedia identitas (IdP) eksternal, Anda harus login ke gcloud CLI dengan identitas gabungan Anda terlebih dahulu.

  15. Untuk melakukan inisialisasi gcloud CLI, jalankan perintah berikut:

    gcloud init

Mengaktifkan API ini juga akan mengaktifkan pemindaian paket bahasa di Artifact Registry. Lihat jenis paket yang didukung.

Peran yang diperlukan

Untuk mendapatkan izin yang Anda perlukan untuk memindai image guna mencari secret selama pemindaian kerentanan, minta administrator Anda untuk memberi Anda peran IAM berikut di project Anda:

Untuk mengetahui informasi selengkapnya tentang pemberian peran, lihat Mengelola akses ke project, folder, dan organisasi.

Anda mungkin juga bisa mendapatkan izin yang diperlukan melalui peran khusus atau peran bawaan lainnya.

Melihat secret

Untuk melihat secret setelah pemindaian kerentanan, lakukan hal berikut:

  1. Kirim image Docker ke Artifact Registry.

  2. Tunggu hingga pemindaian kerentanan selesai.

  3. Jalankan perintah berikut untuk mencantumkan kemunculan secret untuk image yang dipindai:

    $ 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
    

    Dengan:

    • PROJECT_ID adalah ID project konsol Google Cloud Anda.
    • LOCATION adalah lokasi regional atau multi-regional repositori Anda.
    • RESOURCE_URL adalah URL image yang dipindai, dalam format https://LOCATION-docker.pkg.dev/PROJECT_ID/REPOSITORY/IMAGE_ID.

    Contoh respons berikut menunjukkan kemungkinan hasil. Dalam hal ini, kunci Google Cloud API bernama my_api_key.yaml diidentifikasi di documents direktori image. Atribut secret menampilkan informasi tentang secret yang ditemukan.

    {
      "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"
                  }
                }
              }
            ]
          }
        }
      ]
    }
    

Batasan

  • Saat pemindaian secret berada dalam pratinjau publik, kemunculan jenis secret hanya dapat dilihat di Container Analysis API.
  • Laporan pemindaian secret Artifact Analysis menampilkan maksimal satu kemunculan per secret per image. Maksimal 1.000 lokasi file per kemunculan yang ditampilkan.
  • Positif palsu dapat terjadi dengan secret yang diidentifikasi. Selalu verifikasi setiap secret yang diidentifikasi sebelum mengambil tindakan apa pun pada image Anda.