Alcuni servizi Cloud de Confiance , come Compute Engine, App Engine e Cloud Run, supportano l'allegato di un service account gestito dall'utente ad alcuni tipi di risorse. In genere, il collegamento di un account di servizio è supportato quando le risorse del servizio possono eseguire o includere codice dell'applicazione. Quando colleghi un account di servizio a una risorsa, il codice in esecuzione sulla risorsa può utilizzare il account di servizio come identità.
Il collegamento di un account di servizio gestito dall'utente è il modo preferito per fornire le credenziali ad ADC per il codice di produzione in esecuzione su Cloud de Confiance.
Per assistenza nella determinazione dei ruoli da fornire al account di servizio, consulta Scegliere ruoli predefiniti.
Per informazioni sulle risorse a cui puoi collegare un account di servizio e assistenza per il collegamento del account di servizio alla risorsa, consulta la documentazione IAM sul collegamento di un service account.
Set up authentication:
-
Ensure that you have the Create Service Accounts IAM role
(
roles/iam.serviceAccountCreator). Learn how to grant roles. -
Create the service account:
gcloud iam service-accounts create SERVICE_ACCOUNT_NAME
Replace
SERVICE_ACCOUNT_NAMEwith a name for the service account. -
To provide access to your project and your resources, grant a role to the service account:
gcloud projects add-iam-policy-binding PROJECT_ID --member="serviceAccount:SERVICE_ACCOUNT_NAME@PROJECT_ID.s3ns.iam.gserviceaccount.com" --role=ROLE
Replace the following:
SERVICE_ACCOUNT_NAME: the name of the service accountPROJECT_ID: the project ID where you created the service accountROLE: the role to grant
- To grant another role to the service account, run the command as you did in the previous step.
-
Grant the required role to the principal that will attach the service account to other resources.
gcloud iam service-accounts add-iam-policy-binding SERVICE_ACCOUNT_NAME@PROJECT_ID.s3ns.iam.gserviceaccount.com --member="principal://iam.googleapis.com/locations/global/workforcePools/POOL_ID/subject/SUBJECT_ID" --role=roles/iam.serviceAccountUser
Replace the following:
SERVICE_ACCOUNT_NAME: the name of the service account.PROJECT_ID: the project ID where you created the service account.POOL_ID: a workforce identity pool ID.-
SUBJECT_ID: a subject ID; typically the identifier for a user in a workforce identity pool. For details, see Represent workforce pool users in IAM policies.
Passaggi successivi
- Comprendi le best practice per l'utilizzo dei service account e delle chiavi dei service account.
- Scopri di più su come ADC trova le credenziali.
- Autenticati per utilizzare le librerie client di Cloud.
- Esplora i metodi di autenticazione.