Questa pagina mostra come creare, disattivare ed eliminare un messaggio basato su hash Chiavi HMAC (Authentication Code) associate agli account di servizio nel tuo progetto.
Prima di iniziare
Prima di utilizzare questa funzionalità in Cloud Storage, devi soddisfare i seguenti requisiti requisiti:
Disporre di autorizzazioni sufficienti per utilizzare le chiavi HMAC nel progetto selezionato:
Se sei il proprietario del progetto, molto probabilmente disponi delle autorizzazioni necessarie.
Per il progetto devi disporre delle autorizzazioni IAM con prefisso
storage.hmacKeys
. Consulta Utilizzo delle autorizzazioni IAM per istruzioni su come ottenere un ruolo, ad esempio Amministratore chiavi HMAC Storage, che dispone di queste autorizzazioni.
Avere un account di servizio nel progetto con cui intendi creare chiavi HMAC . Consulta Creazione di un account di servizio se al momento non ne hai uno.
Il vincolo
restrictAuthTypes
deve essere disattivato per l'autenticazione della chiave HMAC. Per istruzioni su come controllare e disattivare il vincolo, consulta la sezione Creare e gestire i criteri dell'organizzazione.
Creare una chiave HMAC
Per creare una chiave HMAC per un account di servizio:
Console
- Nella console Google Cloud, vai alla pagina Impostazioni di Cloud Storage.
Seleziona la scheda Interoperabilità.
Fai clic su add_box Crea una chiave per un account di servizio.
Seleziona l'account di servizio a cui vuoi associare la chiave HMAC.
Fai clic su Crea chiave.
Per scoprire come ottenere informazioni dettagliate sugli errori relativi alle operazioni di Cloud Storage non riuscite nella console Google Cloud, consulta la sezione Risoluzione dei problemi.
Riga di comando
Utilizza il comando hmac create
:
gcloud storage hmac create SERVICE_ACCOUNT_EMAIL
Dove è l'indirizzo email SERVICE_ACCOUNT_EMAIL
associati al tuo account di servizio. Ad esempio:
service-7550275089395@my-pet-project.iam.gserviceaccount.com
.
In caso di esito positivo, la risposta contiene una risorsa chiave HMAC, inclusi i valori per accessId
e secret
.
Librerie client
C++
Per ulteriori informazioni, consulta la documentazione di riferimento dell'API Cloud Storage C++.
Per autenticarti a Cloud Storage, configura le credenziali predefinite dell'applicazione. Per ulteriori informazioni, vedi Configura l'autenticazione per un ambiente di sviluppo locale.
C#
Per ulteriori informazioni, consulta API Cloud Storage C# documentazione di riferimento.
Per autenticarti a Cloud Storage, configura le credenziali predefinite dell'applicazione. Per ulteriori informazioni, vedi Configura l'autenticazione per un ambiente di sviluppo locale.
Go
Per ulteriori informazioni, consulta API Cloud Storage Go documentazione di riferimento.
Per eseguire l'autenticazione su Cloud Storage, configura Credenziali predefinite dell'applicazione. Per ulteriori informazioni, vedi Configura l'autenticazione per un ambiente di sviluppo locale.
Java
Per ulteriori informazioni, consulta API Cloud Storage Java documentazione di riferimento.
Per eseguire l'autenticazione su Cloud Storage, configura Credenziali predefinite dell'applicazione. Per ulteriori informazioni, vedi Configura l'autenticazione per un ambiente di sviluppo locale.
Node.js
Per ulteriori informazioni, consulta la documentazione di riferimento dell'API Cloud Storage Node.js.
Per eseguire l'autenticazione su Cloud Storage, configura Credenziali predefinite dell'applicazione. Per maggiori informazioni, consulta Configurare l'autenticazione per un ambiente di sviluppo locale.
PHP
Per ulteriori informazioni, consulta API Cloud Storage PHP documentazione di riferimento.
Per autenticarti a Cloud Storage, configura le credenziali predefinite dell'applicazione. Per ulteriori informazioni, vedi Configura l'autenticazione per un ambiente di sviluppo locale.
Python
Per ulteriori informazioni, consulta la documentazione di riferimento dell'API Cloud Storage Python.
Per autenticarti a Cloud Storage, configura le credenziali predefinite dell'applicazione. Per ulteriori informazioni, vedi Configura l'autenticazione per un ambiente di sviluppo locale.
Ruby
Per ulteriori informazioni, consulta la documentazione di riferimento dell'API Cloud Storage Ruby.
Per autenticarti a Cloud Storage, configura le credenziali predefinite dell'applicazione. Per ulteriori informazioni, vedi Configura l'autenticazione per un ambiente di sviluppo locale.
Terraform
Puoi utilizzare una risorsa Terraform per creare una chiave HMAC. Questo esempio include anche una risorsa per creare un servizio Google Cloud.
API REST
API JSON
Avere installato e inizializzato gcloud CLI per generare un token di accesso per l'intestazione
Authorization
.In alternativa, puoi creare un token di accesso utilizzando il metodo OAuth 2.0 Playground e includilo nell'intestazione
Authorization
.Utilizza
cURL
per chiamare l'API JSON con una chiamata RichiestaPOST
hmacKeys,:curl -X POST \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "https://storage.googleapis.com/storage/v1/projects/PROJECT_IDENTIFIER/hmacKeys?serviceAccountEmail=SERVICE_ACCOUNT_EMAIL"
Dove:
PROJECT_IDENTIFIER
è l'ID o il numero del progetto associato alla chiave che vuoi creare. Ad esempio,my-pet-project
.SERVICE_ACCOUNT_EMAIL
è l'indirizzo email associato al tuo account di servizio. Ad esempio:service-7550275089395@my-pet-project.iam.gserviceaccount.com
.
API XML
Avere gcloud CLI installato e inizializzato, per generare un token di accesso per l'intestazione
Authorization
.In alternativa, puoi creare un token di accesso utilizzando il metodo OAuth 2.0 Playground e includilo nell'intestazione
Authorization
.Utilizza
cURL
per chiamare l'API XML con una richiesta di chiave HMACPOST
:curl -X POST \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "https://storage.googleapis.com/?Action=CreateAccessKey&UserName=SERVICE_ACCOUNT_EMAIL"
Dove si trova l'email
SERVICE_ACCOUNT_EMAIL
associato al tuo account di servizio. Ad esempio,service-7550275089395@my-pet-project.iam.gserviceaccount.com
.
Recupera informazioni chiave HMAC
Per elencare le chiavi HMAC di un progetto e ottenere informazioni sulle chiavi:
Console
- Nella console Google Cloud, vai alla pagina Impostazioni di Cloud Storage.
Seleziona la scheda Interoperabilità.
Gli account di servizio a cui sono associate chiavi HMAC vengono visualizzati nel Sottosezione Chiavi di accesso per gli account di servizio della Sezione HMAC account di servizio.
Fai clic sul nome di un account di servizio specifico per visualizzare le chiavi HMAC associate e il relativo stato.
Riga di comando
Utilizza il comando
hmac list
per elencare le chiavi HMAC nel tuo progetto:gcloud storage hmac list
Se l'operazione va a buon fine, il comando restituisce un elenco di ID di accesso alle chiavi HMAC, insieme allo stato di ogni chiave e all'account di servizio associato a ogni chiave.
Utilizza il comando
hmac describe
per recuperare i metadati per un chiave specifica:gcloud storage hmac describe KEY_ACCESS_ID
Dove
KEY_ACCESS_ID
è l'ID di accesso per la chiave preferita.
Librerie client
C++
Per ulteriori informazioni, consulta API Cloud Storage C++ documentazione di riferimento.
Per eseguire l'autenticazione su Cloud Storage, configura Credenziali predefinite dell'applicazione. Per ulteriori informazioni, vedi Configura l'autenticazione per un ambiente di sviluppo locale.
L'esempio seguente recupera un elenco di chiavi HMAC associate a un progetto:
Il seguente esempio recupera le informazioni per una chiave HMAC specifica:
C#
Per ulteriori informazioni, consulta API Cloud Storage C# documentazione di riferimento.
Per eseguire l'autenticazione su Cloud Storage, configura Credenziali predefinite dell'applicazione. Per ulteriori informazioni, vedi Configura l'autenticazione per un ambiente di sviluppo locale.
L'esempio seguente recupera un elenco di chiavi HMAC associate a un progetto:
Il seguente esempio recupera le informazioni per una chiave HMAC specifica:
Go
Per ulteriori informazioni, consulta API Cloud Storage Go documentazione di riferimento.
Per eseguire l'autenticazione su Cloud Storage, configura Credenziali predefinite dell'applicazione. Per maggiori informazioni, consulta Configurare l'autenticazione per un ambiente di sviluppo locale.
Il seguente esempio recupera un elenco di chiavi HMAC associate a un progetto:
Il seguente esempio recupera le informazioni per una chiave HMAC specifica:
Java
Per ulteriori informazioni, consulta API Cloud Storage Java documentazione di riferimento.
Per autenticarti a Cloud Storage, configura le credenziali predefinite dell'applicazione. Per ulteriori informazioni, vedi Configura l'autenticazione per un ambiente di sviluppo locale.
L'esempio seguente recupera un elenco di chiavi HMAC associate a un progetto:
Il seguente esempio recupera le informazioni per una chiave HMAC specifica:
Node.js
Per ulteriori informazioni, consulta API Cloud Storage Node.js documentazione di riferimento.
Per eseguire l'autenticazione su Cloud Storage, configura Credenziali predefinite dell'applicazione. Per ulteriori informazioni, vedi Configura l'autenticazione per un ambiente di sviluppo locale.
L'esempio seguente recupera un elenco di chiavi HMAC associate a un progetto:
Il seguente esempio recupera le informazioni per una chiave HMAC specifica:
PHP
Per ulteriori informazioni, consulta API Cloud Storage PHP documentazione di riferimento.
Per eseguire l'autenticazione su Cloud Storage, configura Credenziali predefinite dell'applicazione. Per ulteriori informazioni, vedi Configura l'autenticazione per un ambiente di sviluppo locale.
Il seguente esempio recupera un elenco di chiavi HMAC associate a un progetto:
Il seguente esempio recupera le informazioni per una chiave HMAC specifica:
Python
Per ulteriori informazioni, consulta la documentazione di riferimento dell'API Cloud Storage Python.
Per eseguire l'autenticazione su Cloud Storage, configura Credenziali predefinite dell'applicazione. Per maggiori informazioni, consulta Configurare l'autenticazione per un ambiente di sviluppo locale.
Il seguente esempio recupera un elenco di chiavi HMAC associate a un progetto:
Il seguente esempio recupera le informazioni per una chiave HMAC specifica:
Ruby
Per ulteriori informazioni, consulta la documentazione di riferimento dell'API Cloud Storage Ruby.
Per autenticarti a Cloud Storage, configura le credenziali predefinite dell'applicazione. Per maggiori informazioni, consulta Configurare l'autenticazione per un ambiente di sviluppo locale.
L'esempio seguente recupera un elenco di chiavi HMAC associate a un progetto:
Il seguente esempio recupera le informazioni per una chiave HMAC specifica:
API REST
API JSON
Avere gcloud CLI installato e inizializzato, per generare un token di accesso per l'intestazione
Authorization
.In alternativa, puoi creare un token di accesso utilizzando OAuth 2.0 Playground e includerlo nell'intestazione
Authorization
.Utilizza
cURL
per chiamare l'API JSON con una chiamata RichiestaLIST
hmacKeys:curl -X GET \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json" \ "https://storage.googleapis.com/storage/v1/projects/PROJECT_IDENTIFIER/hmacKeys"
Dove
PROJECT_IDENTIFIER
è l'ID o il numero per il progetto associato alle chiavi che vuoi elencare. Ad esempio,my-pet-project
.
API XML
Avere gcloud CLI installato e inizializzato, per generare un token di accesso per l'intestazione
Authorization
.In alternativa, puoi creare un token di accesso utilizzando il metodo OAuth 2.0 Playground e includilo nell'intestazione
Authorization
.Utilizza
cURL
per chiamare l'API XML con una richiesta di chiave HMACGET
:curl -X GET \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "https://storage.googleapis.com/?Action=ListAccessKeys&UserName=SERVICE_ACCOUNT_EMAIL"
dove
SERVICE_ACCOUNT_EMAIL
è l'indirizzo email associato al tuo account di servizio. Ad esempio,service-7550275089395@my-pet-project.iam.gserviceaccount.com
.
Aggiorna lo stato di una chiave HMAC
Per attivare o disattivare una chiave HMAC:
Console
- Nella console Google Cloud, vai alla pagina Impostazioni di Cloud Storage.
Seleziona la scheda Interoperabilità.
Nella sottosezione Chiavi di accesso per gli account di servizio, fai clic sul nome all'account di servizio associato alla chiave HMAC di cui desideri lo stato da aggiornare.
Fai clic sullo stato della chiave che vuoi aggiornare.
Se modifichi lo stato della chiave da Inattiva ad Attivo, fai clic su Disattiva nella finestra visualizzata.
Se modifichi lo stato della chiave da Attiva a Inattiva, sono necessari altri passaggi.
Riga di comando
Utilizza il comando hmac update
:
gcloud storage hmac update ACCESS_KEY_ID STATE
Dove:
ACCESS_KEY_ID
è l'ID di accesso associato alla chiave che stai aggiornando.STATE
è--activate
o--deactivate
.
In caso di esito positivo, il comando restituisce i metadati aggiornati della chiave HMAC.
Librerie client
C++
Per ulteriori informazioni, consulta la documentazione di riferimento dell'API Cloud Storage C++.
Per eseguire l'autenticazione su Cloud Storage, configura Credenziali predefinite dell'applicazione. Per ulteriori informazioni, vedi Configura l'autenticazione per un ambiente di sviluppo locale.
L'esempio seguente disattiva una chiave HMAC:
Il seguente esempio attiva una chiave HMAC:
C#
Per ulteriori informazioni, consulta API Cloud Storage C# documentazione di riferimento.
Per eseguire l'autenticazione su Cloud Storage, configura Credenziali predefinite dell'applicazione. Per ulteriori informazioni, vedi Configura l'autenticazione per un ambiente di sviluppo locale.
Il seguente esempio disattiva una chiave HMAC:
Il seguente esempio attiva una chiave HMAC:
Go
Per ulteriori informazioni, consulta la documentazione di riferimento dell'API Cloud Storage Go.
Per eseguire l'autenticazione su Cloud Storage, configura Credenziali predefinite dell'applicazione. Per maggiori informazioni, consulta Configurare l'autenticazione per un ambiente di sviluppo locale.
L'esempio seguente disattiva una chiave HMAC:
Il seguente esempio attiva una chiave HMAC:
Java
Per ulteriori informazioni, consulta API Cloud Storage Java documentazione di riferimento.
Per eseguire l'autenticazione su Cloud Storage, configura Credenziali predefinite dell'applicazione. Per maggiori informazioni, consulta Configurare l'autenticazione per un ambiente di sviluppo locale.
L'esempio seguente disattiva una chiave HMAC:
Il seguente esempio attiva una chiave HMAC:
Node.js
Per ulteriori informazioni, consulta API Cloud Storage Node.js documentazione di riferimento.
Per autenticarti a Cloud Storage, configura le credenziali predefinite dell'applicazione. Per ulteriori informazioni, vedi Configura l'autenticazione per un ambiente di sviluppo locale.
L'esempio seguente disattiva una chiave HMAC:
Il seguente esempio attiva una chiave HMAC:
PHP
Per ulteriori informazioni, consulta la documentazione di riferimento dell'API Cloud Storage PHP.
Per autenticarti a Cloud Storage, configura le credenziali predefinite dell'applicazione. Per maggiori informazioni, consulta Configurare l'autenticazione per un ambiente di sviluppo locale.
L'esempio seguente disattiva una chiave HMAC:
Il seguente esempio attiva una chiave HMAC:
Python
Per ulteriori informazioni, consulta API Cloud Storage Python documentazione di riferimento.
Per autenticarti a Cloud Storage, configura le credenziali predefinite dell'applicazione. Per maggiori informazioni, consulta Configurare l'autenticazione per un ambiente di sviluppo locale.
Il seguente esempio disattiva una chiave HMAC:
Il seguente esempio attiva una chiave HMAC:
Ruby
Per ulteriori informazioni, consulta API Cloud Storage Ruby documentazione di riferimento.
Per autenticarti a Cloud Storage, configura le credenziali predefinite dell'applicazione. Per maggiori informazioni, consulta Configurare l'autenticazione per un ambiente di sviluppo locale.
L'esempio seguente disattiva una chiave HMAC:
Il seguente esempio attiva una chiave HMAC:
API REST
API JSON
Avere gcloud CLI installato e inizializzato, per generare un token di accesso per l'intestazione
Authorization
.In alternativa, puoi creare un token di accesso utilizzando il metodo OAuth 2.0 Playground e includilo nell'intestazione
Authorization
.Crea un file JSON contenente le seguenti informazioni:
{"state": "STATE"}
Dove
STATE
è lo stato desiderato per la chiave. Ad esempio:INACTIVE
.Utilizza
cURL
per chiamare l'API JSON con una chiamata RichiestaPUT
hmacKeys:curl -X PUT --data-binary @JSON_FILE_NAME \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json" \ "https://storage.googleapis.com/storage/v1/projects/PROJECT_IDENTIFIER/hmacKeys/ACCESS_KEY_ID"
Dove:
JSON_FILE_NAME
è il percorso del file creato nel passaggio 2.PROJECT_IDENTIFIER
è l'ID o il numero per il progetto associato alla chiave che vuoi aggiornare. Ad esempio,my-pet-project
.ACCESS_KEY_ID
è l'ID di accesso associato alla chiave che stai aggiornando.
API XML
Avere gcloud CLI installato e inizializzato, per generare un token di accesso per l'intestazione
Authorization
.In alternativa, puoi creare un token di accesso utilizzando OAuth 2.0 Playground e includerlo nell'intestazione
Authorization
.Utilizza
cURL
per chiamare l'API XML con una chiave HMACPOST
richiesta:curl -X POST \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "https://storage.googleapis.com/?Action=UpdateAccessKey&AccessKeyId=ACCESS_KEY_ID&Status=STATUS"
Dove:
ACCESS_KEY_ID
è l'ID di accesso associato alla chiave che stai aggiornando.STATUS
è lo stato desiderato per chiave. Ad esempio:Inactive
.
Quando modifichi lo stato di una chiave HMAC, sono necessari fino a 3 minuti modifica di stato per propagarsi nel sistema Cloud Storage. Per questo motivo, devi attendere almeno 3 minuti tra il momento in cui una chiave HMAC viene disattivata e quello in cui viene eliminata.
Eliminare una chiave HMAC
Una chiave HMAC deve essere in stato inattivo per poter essere eliminata. Per eliminare una chiave HMAC inattiva:
Console
- Nella console Google Cloud, vai alla pagina Impostazioni di Cloud Storage.
Seleziona la scheda Interoperabilità.
Nella sottosezione Chiavi di accesso per gli account di servizio, fai clic sul nome dell'account di servizio associato alla chiave HMAC che vuoi eliminare.
Fai clic sull'icona del cestino associata alla chiave che vuoi eliminare.
Nella finestra di dialogo visualizzata, inserisci i primi 10 caratteri dell'ID chiave di accesso come indicato nella finestra.
Fai clic su Elimina.
Riga di comando
Utilizza il comando hmac delete
:
gcloud storage hmac delete ACCESS_KEY_ID
Dove ACCESS_KEY_ID
è l'ID accesso associato
con la chiave che stai eliminando.
In caso di esito positivo, il comando non restituisce una risposta.
Librerie client
C++
Per ulteriori informazioni, consulta API Cloud Storage C++ documentazione di riferimento.
Per autenticarti a Cloud Storage, configura le credenziali predefinite dell'applicazione. Per maggiori informazioni, consulta Configurare l'autenticazione per un ambiente di sviluppo locale.
C#
Per ulteriori informazioni, consulta API Cloud Storage C# documentazione di riferimento.
Per eseguire l'autenticazione su Cloud Storage, configura Credenziali predefinite dell'applicazione. Per maggiori informazioni, consulta Configurare l'autenticazione per un ambiente di sviluppo locale.
Go
Per ulteriori informazioni, consulta API Cloud Storage Go documentazione di riferimento.
Per eseguire l'autenticazione su Cloud Storage, configura Credenziali predefinite dell'applicazione. Per ulteriori informazioni, vedi Configura l'autenticazione per un ambiente di sviluppo locale.
Java
Per ulteriori informazioni, consulta API Cloud Storage Java documentazione di riferimento.
Per eseguire l'autenticazione su Cloud Storage, configura Credenziali predefinite dell'applicazione. Per maggiori informazioni, consulta Configurare l'autenticazione per un ambiente di sviluppo locale.
Node.js
Per ulteriori informazioni, consulta API Cloud Storage Node.js documentazione di riferimento.
Per autenticarti a Cloud Storage, configura le credenziali predefinite dell'applicazione. Per maggiori informazioni, consulta Configurare l'autenticazione per un ambiente di sviluppo locale.
PHP
Per ulteriori informazioni, consulta API Cloud Storage PHP documentazione di riferimento.
Per autenticarti a Cloud Storage, configura le credenziali predefinite dell'applicazione. Per ulteriori informazioni, vedi Configura l'autenticazione per un ambiente di sviluppo locale.
Python
Per ulteriori informazioni, consulta la documentazione di riferimento dell'API Cloud Storage Python.
Per autenticarti a Cloud Storage, configura le credenziali predefinite dell'applicazione. Per maggiori informazioni, consulta Configurare l'autenticazione per un ambiente di sviluppo locale.
Ruby
Per ulteriori informazioni, consulta API Cloud Storage Ruby documentazione di riferimento.
Per eseguire l'autenticazione su Cloud Storage, configura Credenziali predefinite dell'applicazione. Per maggiori informazioni, consulta Configurare l'autenticazione per un ambiente di sviluppo locale.
API REST
API JSON
Avere gcloud CLI installato e inizializzato, per generare un token di accesso per l'intestazione
Authorization
.In alternativa, puoi creare un token di accesso utilizzando il metodo OAuth 2.0 Playground e includilo nell'intestazione
Authorization
.Utilizza
cURL
per chiamare l'API JSON con una richiestaDELETE
hmacKeys:curl -X DELETE \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "https://storage.googleapis.com/storage/v1/projects/PROJECT_IDENTIFIER/hmacKeys/ACCESS_KEY_ID"
Dove:
PROJECT_IDENTIFIER
è l'ID o il numero del progetto associato alla chiave che vuoi eliminare. Ad esempio,my-pet-project
.ACCESS_KEY_ID
è l'ID di accesso associato alla chiave che stai eliminando.
API XML
Avere gcloud CLI installato e inizializzato, per generare un token di accesso per l'intestazione
Authorization
.In alternativa, puoi creare un token di accesso utilizzando il metodo OAuth 2.0 Playground e includilo nell'intestazione
Authorization
.Utilizza
cURL
per chiamare l'API XML con una chiave HMACPOST
richiesta:curl -X POST \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "https://storage.googleapis.com/?Action=DeleteAccessKey&AccessKeyId=ACCESS_KEY_ID"
Dove
ACCESS_KEY_ID
è l'ID accesso associato alla chiave che stai eliminando.
Passaggi successivi
- Segui le linee guida per la migrazione dalle chiavi HMAC degli account utente a e le chiavi HMAC dell'account di servizio.
- Utilizza una chiave HMAC in una richiesta autenticata.