【问题标题】:Google Cloud Authentication - getting the Key ID of my app谷歌云身份验证 - 获取我的应用程序的密钥 ID
【发布时间】:2021-05-10 13:23:56
【问题描述】:

我正在尝试将 docker 映像推送到 Container Registry,以便我的应用可以使用它。

为此,我必须设置身份验证。

这需要使用如下命令:

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

这里提到: https://cloud.google.com/container-registry/docs/advanced-authentication#gcloud-helper

但我首先必须设置服务帐户密钥,如下所述: https://cloud.google.com/iam/docs/creating-managing-service-account-keys#creating_service_account_keys

我做了链接所说的一切,我得到了 json 文件。

但是 KEY-FILE 参数究竟是什么?

没有提到 KEY-FILE 参数是什么。

【问题讨论】:

    标签: google-cloud-platform


    【解决方案1】:

    @user1584421 KEY-FILE 是你生成的 json 文件的物理位置。

    比方说 - C:\my-key.json

    【讨论】:

    • 我知道。我提供了整个路径,但它不起作用。
    • 您遇到了什么错误?您是否生成了 .json 或 .p12?您是否检查过 ACCOUNT 的值和 JSON 文件中的值是否相同?
    • 我刚刚检查了您之前命令中的错误“[ACCOUNT] 的值无效:给定的帐户名称与密钥文件中的帐户名称不匹配”,我认为您提供的帐户值in 命令与 JSON 文件中的不同。请打开 JSON 文件并匹配一次。
    • 我在 json 文件中找到的唯一相关字段是 client_id。这只是数字。虽然我在参数中输入的是字母。为什么我的 json 没有我的服务帐号名称?
    • 你看到client_email了吗?那是帐户名
    【解决方案2】:

    在密钥文件参数中,您基本上需要提供您在本地创建并下载到系统的服务帐户 Json 文件,其中包含一个私钥。

    所以基本上它看起来像

    gcloud auth activate-service-account Name-of-Your-Service_account --key-file name of the serviceaccount json file.
    

    例子-

    $gcloud auth activate-service-account test-account@temp123.iam.gserviceaccount.com --key-file myservice.json
    

    【讨论】:

    • 谢谢,但我该如何通过呢?我的意思是,当我生成密钥时,它会将一个 json 文件下载到我的机器上。但我在浏览器上使用 gcloud。那么我到底通过了什么?
    • 你可以参考这个公开文档-cloud.google.com/sdk/gcloud/reference/auth/…
    • 我参考了它,但没有显示任何新信息。我做了我的第二个链接所说的一切,并且文件在本地下载。但我有 Cloud Shell,那里没有文件(标准 README.txt 除外)。
    • @user1584421 - 您需要将服务帐号 JSON 文件上传到 Cloud Shell,然后在 Cloud Shell 中执行您的命令。注意:Cloud Shell 已有凭据(您的用户帐号),因此您不需要其他服务帐号。
    • @JohnHanley 我如何将 JSON 文件上传到 Cloud Shell? (顺便说一句,这是一个蹩脚的政策,因为我从他们那里下载了文件,现在我必须将它上传回他们)。我尝试通过从快照下载 gcloud 在本地使用它。即便如此,我还是收到了ERROR: (gcloud.auth.activate-service-account) Invalid value for [ACCOUNT]: The given account name does not match the account name in the key file. This argument can be omitted when using .json keys.
    猜你喜欢
    • 1970-01-01
    • 2013-02-11
    • 2017-10-25
    • 2019-11-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-14
    • 2023-03-05
    • 1970-01-01
    相关资源
    最近更新 更多