Scansione dei secret

Le scansioni delle vulnerabilità di Artifact Analysis possono identificare i secret, come le chiavi account di servizio e le chiavi API, archiviati nelle immagini scansionate. Puoi visualizzare informazioni su questi secret nel report sull'occorrenza della scansione delle vulnerabilità e passare all'azione per evitare l'esposizione di informazioni sensibili.

Panoramica

Quando una scansione delle vulnerabilità rileva un secret, Artifact Analysis crea un'occorrenza di tipo secret con i dettagli del secret. L'Artifact Analysis può rilevare i seguenti secret:

Secret

  • Chiavi di amministrazione Anthropic
  • Chiavi API Anthropic
  • Token di accesso Azure
  • Token ID Azure
  • Token di accesso personale Docker Hub
  • Token di aggiornamento dell'app GitHub
  • Token server-to-server dell'app GitHub
  • Token user-to-server dell'app GitHub
  • Token di accesso personale classici di GitHub
  • Token di accesso personale granulare di GitHub
  • Token OAuth GitHub
  • Google Cloud Coppie OAuth2 (ID client e secret)
  • Google Cloud Token di accesso OAuth2
  • Chiavi service accountGoogle Cloud
  • Google Cloud Chiavi API
  • Chiavi API Hugging Face
  • Chiavi API OpenAI
  • Chiavi API Perplexity
  • Chiavi con limitazioni di Stripe
  • Chiavi segrete Stripe
  • Secret webhook di Stripe

Per informazioni dettagliate sui diversi tipi di secret nei report sulle occorrenze, consulta SecretKind nella documentazione dell'API Artifact Analysis.

L'Artifact Analysis può rilevare solo i secret archiviati come file di testo. Sono supportate le seguenti estensioni di file:

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

Prima di iniziare

  1. Accedi al tuo account Google Cloud . 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 carichi di lavoro.
  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, if any are not already enabled.

    Roles required to enable APIs

    To enable APIs, you need the serviceusage.services.enable permission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.

    Enable the APIs

  6. Install the Google Cloud CLI.

  7. If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

  8. To initialize the gcloud CLI, run the following command:

    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, if any are not already enabled.

    Roles required to enable APIs

    To enable APIs, you need the serviceusage.services.enable permission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.

    Enable the APIs

  13. Install the Google Cloud CLI.

  14. If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

  15. To initialize the gcloud CLI, run the following command:

    gcloud init

Se abiliti questa API, viene abilitata anche l'analisi dei pacchetti di lingua in Artifact Registry. Consulta i tipi di pacchetti supportati.

Ruoli obbligatori

Per ottenere le autorizzazioni necessarie per analizzare le immagini alla ricerca di secret durante le analisi delle vulnerabilità, chiedi all'amministratore di concederti i seguenti ruoli IAM nel progetto:

Per saperne di più sulla concessione dei ruoli, consulta Gestisci l'accesso a progetti, cartelle e organizzazioni.

Potresti anche riuscire a ottenere le autorizzazioni richieste tramite i ruoli personalizzati o altri ruoli predefiniti.

Visualizzare i secret

Per visualizzare i segreti dopo una scansione delle vulnerabilità:

  1. Esegui il push di un'immagine Docker in Artifact Registry.

  2. Attendi il completamento dell'analisi delle vulnerabilità.

  3. Esegui questo comando per elencare le occorrenze di secret per l'immagine analizzata:

    $ 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
    

    Dove:

    • PROJECT_ID è l'ID progetto della console Google Cloud .
    • LOCATION è la località regionale o multiregionale del tuo repository.
    • RESOURCE_URL è l'URL dell'immagine scansionata, nel formato https://LOCATION-docker.pkg.dev/PROJECT_ID/REPOSITORY/IMAGE_ID.

    La seguente risposta di esempio mostra un possibile risultato. In questo caso, è stata identificata una chiave APIGoogle Cloud denominata my_api_key.yaml nella directory documents di un'immagine. L'attributo secret mostra informazioni sul secret scoperto.

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

Limitazioni

  • Mentre l'analisi dei secret è in anteprima pubblica, le occorrenze di tipo secret sono visualizzabili solo nell'API Container Analysis.
  • L'analisi dei segreti di Artifact Analysis segnala al massimo un'occorrenza per segreto per immagine. Vengono restituite al massimo 1000 posizioni dei file per occorrenza.
  • Potrebbero verificarsi falsi positivi con i segreti identificati. Verifica sempre ogni segreto identificato prima di intraprendere qualsiasi azione sulle tue immagini.