Here’s the command to authenticate as a service account.

gcloud auth activate-service-account --key-file=key.json

To log out.

gcloud auth revoke