【问题标题】:GCP service Account AuthenticationGCP 服务帐号身份验证
【发布时间】:2021-05-12 06:40:39
【问题描述】:

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

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'

【问题讨论】:

  • 你能显示你的文件夹结构吗?似乎该文件不在您执行激活脚本的同一目录中。如果可能,在执行 gcloud 命令的同一目录中打印 dir 的输出。

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


【解决方案1】:

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

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

步骤-

  1. 在 cloud shell 中通过 gcloud 命令创建密钥

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

示例-
gcloud iam service-accounts keys create key.json --iam-account=my-iam-account@my-project.iam.gserviceaccount.com

  1. 生成密钥后,我们需要为凭据身份验证提供命令

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

提供您在 Account 中创建的服务帐户电子邮件和我们使用 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

【讨论】:

  • 这对我有用,现在没有遇到错误。谢谢!!
猜你喜欢
  • 1970-01-01
  • 2021-04-27
  • 1970-01-01
  • 1970-01-01
  • 2022-09-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多