Get the Cloud Storage service agent Stay organized with collections Save and categorize content based on your preferences.
This page describes how to find the email address of a project'sCloud Storage service agent, which is a specialized service account createdand managed by Cloud Storage. For an overview of Cloud Storageservice agents, including when they're created and how they're used, seeService Accounts for Cloud Storage. For a general overview ofservice accounts in Google Cloud, seeService Accounts.
Before you begin
In order to get the required permissions for finding the email address of aproject's service agent, ask your administrator to grant you the View ServiceAccounts (roles/iam.serviceAccountViewer) role on the project.
This predefined role contains theresourcemanager.projects.get permission,which is required to access the service agent of a project. You can also getthis permission with otherpredefined roles. To see which roles areassociated with which permissions, refer toIAM roles forCloud Storage.
For instructions on using roles to control access to projects, seeManage access.
Get the email address of a project's Cloud Storage service agent
Console
- In the Google Cloud console, go to the Cloud StorageSettings page.
In theProject Access tab, the email address appears in theCloudStorage Service Account section.
Command line
Use thegcloud storage service-agent command:
gcloud storage service-agent --project=PROJECT_IDENTIFIER
wherePROJECT_IDENTIFIER is the ID or number ofthe relevant project. For example,my-project.
Client libraries
For more information, see theCloud StorageC++ API reference documentation. To authenticate to Cloud Storage, set up Application Default Credentials. For more information, seeSet up authentication for client libraries. For more information, see theCloud StorageC# API reference documentation. To authenticate to Cloud Storage, set up Application Default Credentials. For more information, seeSet up authentication for client libraries. For more information, see theCloud StorageGo API reference documentation. To authenticate to Cloud Storage, set up Application Default Credentials. For more information, seeSet up authentication for client libraries. For more information, see theCloud StorageJava API reference documentation. To authenticate to Cloud Storage, set up Application Default Credentials. For more information, seeSet up authentication for client libraries. For more information, see theCloud StorageNode.js API reference documentation. To authenticate to Cloud Storage, set up Application Default Credentials. For more information, seeSet up authentication for client libraries. For more information, see theCloud StoragePHP API reference documentation. To authenticate to Cloud Storage, set up Application Default Credentials. For more information, seeSet up authentication for client libraries. For more information, see theCloud StoragePython API reference documentation. To authenticate to Cloud Storage, set up Application Default Credentials. For more information, seeSet up authentication for client libraries. For more information, see theCloud StorageRuby API reference documentation. To authenticate to Cloud Storage, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.C++
namespacegcs=::google::cloud::storage;using::google::cloud::StatusOr;[](gcs::Clientclient){StatusOr<gcs::ServiceAccount>account=client.GetServiceAccount();if(!account)throwstd::move(account).status();std::cout <<"The service account details are " <<*account <<"\n";}C#
usingGoogle.Cloud.Storage.V1;usingSystem;publicclassGetStorageServiceAccountSample{publicstringGetStorageServiceAccount(stringprojectId="your-project-id"){varstorage=StorageClient.Create();varserviceAccountEmail=storage.GetStorageServiceAccountEmail(projectId);Console.WriteLine($"The GCS service account for project {projectId} is: {serviceAccountEmail}.");returnserviceAccountEmail;}}Go
import("context""fmt""io""time""cloud.google.com/go/storage")// getServiceAccount gets the default Cloud Storage service account email address.funcgetServiceAccount(wio.Writer,projectIDstring)error{// projectID := "my-project-id"ctx:=context.Background()client,err:=storage.NewClient(ctx)iferr!=nil{returnfmt.Errorf("storage.NewClient: %w",err)}deferclient.Close()ctx,cancel:=context.WithTimeout(ctx,time.Second*10)defercancel()serviceAccount,err:=client.ServiceAccount(ctx,projectID)iferr!=nil{returnfmt.Errorf("ServiceAccount: %w",err)}fmt.Fprintf(w,"The GCS service account for project %v is: %v\n",projectID,serviceAccount)returnnil}Java
importcom.google.cloud.storage.ServiceAccount;importcom.google.cloud.storage.Storage;importcom.google.cloud.storage.StorageOptions;publicclassGetServiceAccount{publicstaticvoidgetServiceAccount(StringprojectId){// The ID of your GCP project// String projectId = "your-project-id";Storagestorage=StorageOptions.newBuilder().setProjectId(projectId).build().getService();ServiceAccountserviceAccount=storage.getServiceAccount(projectId);System.out.println("The GCS service account for project "+projectId+" is: "+serviceAccount.getEmail());}}Node.js
/** * TODO(developer): Uncomment the following lines before running the sample. */// The ID of your GCP project// const projectId = 'your-project-id';// Imports the Google Cloud client libraryconst{Storage}=require('@google-cloud/storage');// Creates a clientconststorage=newStorage({projectId,});asyncfunctiongetServiceAccount(){const[serviceAccount]=awaitstorage.getServiceAccount();console.log(`The GCS service account for project${projectId} is:${serviceAccount.emailAddress}`);}getServiceAccount().catch(console.error);PHP
use Google\Cloud\Storage\StorageClient;/** * Get the current service account email. * * @param string $projectId The ID of your Google Cloud Platform project. * (e.g. 'my-project-id') */function get_service_account(string $projectId): void{ $storage = new StorageClient([ 'projectId' => $projectId, ]); $serviceAccountEmail = $storage->getServiceAccount(); printf('The GCS service account email for project %s is %s', $projectId, $serviceAccountEmail);}Python
fromgoogle.cloudimportstoragedefget_service_account():"""Get the service account email"""storage_client=storage.Client()email=storage_client.get_service_account_email()print(f"The GCS service account for project{storage_client.project} is:{email} ")Ruby
JSON API
Have gcloud CLIinstalled and initialized, which lets you generate an access token for the
Authorizationheader.Use
cURLto call the JSON API with aGETserviceAccountrequest:curl -X GET -H "Authorization: Bearer $(gcloud auth print-access-token)" \"https://storage.googleapis.com/storage/v1/projects/PROJECT_ID/serviceAccount"
Where
PROJECT_IDis the ID or number of therelevant project. For example,my-project.
What's next
- Learn aboutservice accounts and service agents in Cloud Storage.
- Assign a Cloud Key Management Service encryption key to a service agent.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2026-02-05 UTC.