GCP 服务帐号认证

时间:2021-05-12 06:40:39

标签: google-cloud-platform service-accounts google-cloud-iam

我按照此处提到的步骤为特定角色创建了一个服务帐户。

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

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

当我尝试使用 gcloud 使用凭据进行身份验证时,在 json 文件中生成密钥后

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

错误:(gcloud.auth.activate-service-account) 无法读取文件 [#path of file#]:[Errno 2] 没有这样的文件或目录:'filename.json'

1 个答案:

答案 0 :(得分:0)

根据您的问题,密钥文件基本上是我们下载的服务帐户密钥文件,在命令 gcloud auth activate-service-account ACCOUNT --key-file=KEY-FILE 中,我们需要提供json 密钥文件。

我遇到了同样的问题,所以我通过 gcloud 创建了 json 密钥。

步骤-

  1. 在 Cloud Shell 中通过 gcloud 命令创建密钥

gcloud iam service-accounts 密钥创建输出文件 --iam-account=IAM_ACCOUNT [--key-file-type=KEY_FILE_TYPE; default="json"] [GCLOUD_WIDE_FLAG ...]

示例-
gcloud iam service-accounts 密钥创建 key.json --iam-account=my-iam-account@my-project.iam.gserviceaccount.com

  1. 生成密钥后,我们需要给出凭据认证命令

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

提供您在帐户中创建的服务帐户电子邮件以及我们使用 gcloud 命令生成的密钥

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

我附上公共文档链接以供参考。

Authentication using Credentials

service account key generate using gcloud