Gcloud - 如何在同一台机器上使用服务帐户和用户帐户?

问题描述 投票:0回答:1

我为同事创建了一个服务帐户,用于将文件上传到我的 GCP 存储桶中。我共享了服务帐户凭据,同事使用

gcloud auth
命令激活了它们。

$ gcloud auth activate-service-account --key-file bucket-creds.json
Activated service account credentials for: [[email protected]]

该帐户已使用 gcloud 身份验证列表进行验证:

$ gcloud auth list

ACTIVE ACCOUNT   Credentialed Accounts
        [email protected]
*       [email protected]

现在,当我的同事使用

gsutil cp
将一些东西上传到我的存储桶中时,他们收到有关具有多种凭证类型的错误消息。

$ gsutil cp example.file  gs://my-bucket/
Copying file://example.file [Content-Type=application/x-tar]...

CommandException: You have multiple types of configured credentials (['Oauth 2.0 User Account', 'OAuth 2.0 Service Account']), which is not supported. One common way this happens is if you run gsutil config to create credentials and later run gcloud auth, and create a second set of credentials. Your boto config path is: ['/data/home/user/.boto', '/data/home/user/.config/gcloud/legacy_credentials/[email protected]/.boto']. For more help, see "gsutil help creds".

我很困惑为什么 gsutil 无法处理多种类型的凭据。如果服务帐户已使用 gcloud auth 激活,为什么

gsutil cp
命令无法使用凭据只是因为还有其他凭据可用?是否期望我们应该删除原始用户凭据并仅使用服务帐户凭据?

我已经阅读了有关该主题的其他问题,但发现它们没有帮助。我知道可能需要更改一些环境变量,但我不确定我们应该如何做,以及我们是否能够在上传完成后保留原始用户帐户的功能。有谁能解释为什么这不起作用?我过去在同一会话期间使用用户帐户和服务帐户时没有遇到任何问题,只要

gcloud auth
命令在其他命令之前执行即可。 .

我的同事尝试重新登录到他们的用户帐户并开始上传,不出所料,这没有用,因为他们的用户帐户没有所需的权限,而服务帐户有。

$ gcloud config set account [email protected]
Updated property [core/account].

$ gsutil cp example.file  gs://my-bucket/

Copying file://example.file [Content-Type=application/x-tar]...

ResumableUploadAbortException: 403 [email protected] does not have storage.objects.create access to the Google Cloud Storage object. Permission 'storage.objects.create' denied on resource (or it may not exist).

google-cloud-platform google-cloud-storage gcloud gsutil
1个回答
0
投票

您的系统配置有误。我建议运行

gcloud auth revoke
,直到没有更多的凭据被授权。运行
gsutil ls
并验证
gsutil
未被授权。运行
gcloud init
。然后运行
gcloud auth activate-service-account
.

如果要配置

gsutil
使用服务帐户而不是
gcloud
配置的凭据,请运行以下两个命令:

gcloud config set pass_credentials_to_gsutil false
gsutil config -e

系统将提示您输入服务帐户 JSON 密钥文件的完整路径。

© www.soinside.com 2019 - 2024. All rights reserved.