Questo argomento descrive come recuperare un elenco di tutte le versioni del secret e visualizzare i metadati di una versione specifica del secret.
Ruoli obbligatori
Per elencare le versioni dei secret è necessario il ruolo Visualizzatore Secret Manager (
roles/secretmanager.viewer
) nel secret, nel progetto, nella cartella o nell'organizzazione.Per visualizzare i metadati di una versione del secret, è richiesto il ruolo Visualizzatore Secret Manager (
roles/secretmanager.viewer
) nel secret, nel progetto, nella cartella o nell'organizzazione.
Elenca le versioni di un secret
L'elenco delle versioni dei secret restituisce tutte le versioni associate al secret e lo stato di ciascuna versione (abilitata, disabilitata o eliminata).
Console
-
Vai alla pagina Secret Manager nella console Google Cloud.
-
Nella pagina Secret Manager, fai clic sul nome di un secret.
-
La pagina Dettagli secret mostra l'elenco delle versioni nella tabella Versioni.
gcloud
Per utilizzare Secret Manager nella riga di comando, devi prima installare Google Cloud CLI o eseguirne l'upgrade alla versione 378.0.0 o successiva. In Compute Engine o GKE, devi eseguire l'autenticazione con l'ambito cloud-platform.
$ gcloud secrets versions list secret-id
C#
Per eseguire questo codice, prima configura un ambiente di sviluppo C# e installa l'SDK C# di Secret Manager. In Compute Engine o GKE, devi eseguire l'autenticazione con l'ambito cloud-platform.
Go
Per eseguire questo codice, devi prima configurare un ambiente di sviluppo Go e installare l'SDK Secret Manager Go. In Compute Engine o GKE, devi eseguire l'autenticazione con l'ambito cloud-platform.
Java
Per eseguire questo codice, devi prima configurare un ambiente di sviluppo Java e installare l'SDK Java di Secret Manager. In Compute Engine o GKE, devi eseguire l'autenticazione con l'ambito cloud-platform.
Node.js
Per eseguire questo codice, prima configura un ambiente di sviluppo Node.js e installa l'SDK Node.js di Secret Manager. In Compute Engine o GKE, devi eseguire l'autenticazione con l'ambito cloud-platform.
PHP
Per eseguire questo codice, scopri prima di tutto come utilizzare PHP su Google Cloud e installare l'SDK PHP di Secret Manager. In Compute Engine o GKE, devi eseguire l'autenticazione con l'ambito cloud-platform.
Python
Per eseguire questo codice, prima configura un ambiente di sviluppo Python e installa l'SDK Python di Secret Manager. In Compute Engine o GKE, devi eseguire l'autenticazione con l'ambito cloud-platform.
Ruby
Per eseguire questo codice, devi prima configurare un ambiente di sviluppo Ruby e poi installare l'SDK Ruby di Secret Manager. In Compute Engine o GKE, devi eseguire l'autenticazione con l'ambito cloud-platform.
API
In questi esempi viene utilizzato curl per dimostrare l'utilizzo dell'API. Puoi generare token di accesso con gcloud auth print-access-token. In Compute Engine o GKE, devi eseguire l'autenticazione con l'ambito cloud-platform.
$ curl "https://secretmanager.googleapis.com/v1/projects/project-id/secrets/secret-id/versions" \
--request "GET" \
--header "authorization: Bearer $(gcloud auth print-access-token)" \
--header "content-type: application/json"
Ottieni dettagli su una versione del secret
Questi esempi mostrano come ottenere i dettagli di una versione del secret visualizzando i relativi metadati. Tuttavia, i dati sensibili della versione del secret non verranno restituiti.
Console
-
Vai alla pagina Secret Manager nella console Google Cloud.
-
Nella pagina Secret Manager, fai clic sul nome di un secret.
-
Nella tabella Versioni della pagina Dettagli secret, individua una versione del secret da recuperare.
-
Trova l'ID della versione nella tabella e leggi i relativi metadati.
gcloud
Per utilizzare Secret Manager nella riga di comando, devi prima installare Google Cloud CLI o eseguirne l'upgrade alla versione 378.0.0 o successiva. In Compute Engine o GKE, devi eseguire l'autenticazione con l'ambito cloud-platform.
$ gcloud secrets versions describe version-id --secret="secret-id"
C#
Per eseguire questo codice, prima configura un ambiente di sviluppo C# e installa l'SDK C# di Secret Manager. In Compute Engine o GKE, devi eseguire l'autenticazione con l'ambito cloud-platform.
Go
Per eseguire questo codice, devi prima configurare un ambiente di sviluppo Go e installare l'SDK Secret Manager Go. In Compute Engine o GKE, devi eseguire l'autenticazione con l'ambito cloud-platform.
Java
Per eseguire questo codice, devi prima configurare un ambiente di sviluppo Java e installare l'SDK Java di Secret Manager. In Compute Engine o GKE, devi eseguire l'autenticazione con l'ambito cloud-platform.
Node.js
Per eseguire questo codice, prima configura un ambiente di sviluppo Node.js e installa l'SDK Node.js di Secret Manager. In Compute Engine o GKE, devi eseguire l'autenticazione con l'ambito cloud-platform.
PHP
Per eseguire questo codice, scopri prima di tutto come utilizzare PHP su Google Cloud e installare l'SDK PHP di Secret Manager. In Compute Engine o GKE, devi eseguire l'autenticazione con l'ambito cloud-platform.
Python
Per eseguire questo codice, prima configura un ambiente di sviluppo Python e installa l'SDK Python di Secret Manager. In Compute Engine o GKE, devi eseguire l'autenticazione con l'ambito cloud-platform.
Ruby
Per eseguire questo codice, devi prima configurare un ambiente di sviluppo Ruby e poi installare l'SDK Ruby di Secret Manager. In Compute Engine o GKE, devi eseguire l'autenticazione con l'ambito cloud-platform.
API
In questi esempi viene utilizzato curl per dimostrare l'utilizzo dell'API. Puoi generare token di accesso con gcloud auth print-access-token. In Compute Engine o GKE, devi eseguire l'autenticazione con l'ambito cloud-platform.
$ curl "https://secretmanager.googleapis.com/v1/projects/project-id/secrets/secret-id/versions/version-id" \
--request "GET" \
--header "authorization: Bearer $(gcloud auth print-access-token)" \
--header "content-type: application/json"
Passaggi successivi
- Scopri come assegnare un alias a una versione del secret.