【问题标题】:How can a service account authenticate in gcloud without changing the default gcloud account in the environment?服务帐户如何在 gcloud 中进行身份验证而不更改环境中的默认 gcloud 帐户?
【发布时间】:2020-06-14 11:47:44
【问题描述】:

我在脚本中使用gcloud auth activate-service-account ... 将服务帐户登录到gcloud。脚本完成后,gcloud 仍然登录到该服务帐户。

我更喜欢gcloud 使用我的普通用户帐户保持登录状态,这样我就可以交互地使用它。

我如何临时使用服务帐户进行身份验证 - 仅在单个脚本执行中?

【问题讨论】:

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


    【解决方案1】:

    Service Account Token Creator role 授予“普通用户帐户”并利用--impersonate-service-account = SERVICE_ACCOUNT_EMAIL flag 来执行您需要在脚本中运行的gcloud 命令,以避免在脚本中使用gcloud auth activate-service-account ...,或者只需添加gcloud config set account ACCOUNT command 在脚本末尾,以确保在脚本完成后设置普通用户帐户。

    【讨论】:

    • 谢谢。你的第二种方法对我有用
    猜你喜欢
    • 1970-01-01
    • 2020-08-29
    • 2020-04-07
    • 2017-03-15
    • 2022-08-04
    • 1970-01-01
    • 2019-06-09
    • 1970-01-01
    • 2018-04-14
    相关资源
    最近更新 更多