0
votes

I created a service account for a specific role by going through the steps mentioned here.

https://cloud.google.com/iam/docs/creating-managing-service-accounts

https://cloud.google.com/iam/docs/creating-managing-service-account-keys

after generating the keys in json file when i am trying to authenticate with credentials using gcloud using

gcloud auth activate-service-account ACCOUNT --key-file=KEY-FILE

ERROR: (gcloud.auth.activate-service-account) Unable to read file [#path of file#]: [Errno 2] No such file or directory: 'filename.json'

1
Can you show your folder structure? Seems that the file is not in the same directory where you execute the activation script. If possible, print the output of dir in the same directory where you execute the gcloud command.Daniel Stoyanoff

1 Answers

1
votes

As per your question the key file basically is the service account key file that we have downloaded and in the command gcloud auth activate-service-account ACCOUNT --key-file=KEY-FILE we need to give the path of the json keyfile .

I faced this same issue ,so I created the json keys through gcloud .

steps-

  1. create the keys through gcloud command in cloud shell

gcloud iam service-accounts keys create OUTPUT-FILE --iam-account=IAM_ACCOUNT [--key-file-type=KEY_FILE_TYPE; default="json"] [GCLOUD_WIDE_FLAG …]

example-
gcloud iam service-accounts keys create key.json [email protected]

  1. after generating the keys we need to give the command for the credential authentication

gcloud auth activate-service-account ACCOUNT --key-file=KEY-FILE

Give the service account email that you have created in Account and the key we generated using gcloud command

example-
gcloud auth activate-service-account [service-account-name-]@[projectID].iam.gserviceaccount.com --key-file=key.json

i am attaching public docs links for reference.

Authentication using Credentials

service account key generate using gcloud