Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the active authenticated gcloud account?

Using gcloud auth ... you can add or remove accounts used during the gcloud commands.

Is there a way to get the active account without grep-ing and awk-ing?

gcloud auth list is good for humans but not good enough to a machine. I want a cleaner solution.

gcloud config list account also shows me to verbose output:

Your active configuration is: [default]  [core] account = service@<my_project>.iam.gserviceaccount.com 
like image 909
4 revs, 2 users 76% Avatar asked Feb 10 '16 09:02

4 revs, 2 users 76%


People also ask

Where is gcloud credential stored?

Configuring/Using Credentials Via Cloud Sdk Distribution Of Gsutil. When gsutil is installed/used via the Cloud SDK ("gcloud"), credentials are stored by Cloud SDK in a non-user-editable file located under ~/. config/gcloud (any manipulation of credentials should be done via the gcloud auth command).


2 Answers

I found the solution:

gcloud config list account --format "value(core.account)" 

This would tell you:

Your active configuration is: [default]  service@<my_project>.iam.gserviceaccount.com 

To also avoid the active configuration message, you can redirect the stderr to /dev/null:

$ gcloud config list account --format "value(core.account)" 2> /dev/null service@<my_project>.iam.gserviceaccount.com 

It would be nice if --verbosity would also work in this case to remove the info message. That would mean:

$ gcloud config list account --format "value(core.account)" --verbosity error 

Any Googlers out there that can post a comment if this is a reasonable feature/bug request/report?

like image 92
4 revs, 2 users 76% Avatar answered Oct 11 '22 15:10

4 revs, 2 users 76%


This also seems to work

gcloud config get-value account

like image 26
aclowkay Avatar answered Oct 11 '22 13:10

aclowkay