在 Compute Engine 实例上使用服务帐号
Using service accounts on Compute Engine instances
我正在尝试使用我在 Developers Console 中创建的服务帐户在我的新 GCE 实例上执行 gcloud init
。在 Developers Console 中,我在 Permissions 下看到一些服务帐户,我无法为其生成私钥文件;我还看到了我在 服务帐户 下创建的服务帐户,我 可以 获取其私钥。
当我在 GCE 实例上执行 gcloud init
时,在 "Pick credentials to use" 下,我只能在“权限”选项卡中看到服务帐户(我没有私钥)。我想使用我拥有私钥的服务帐户。
我现在可以使用我的个人帐户登录,但这不可扩展。有什么建议吗?
您可以使用 gcloud auth activate-service-account command to get credentials via the private key for a service account. For more information and example please visit this link.
在进一步讨论后详细说明@Kamaran 的回答。
基本解决方案是在 GCE 实例上启用服务帐户。
首先使用gcloud compute copy-files <private json key file> <instance name>:remote/path/to/key
将文件复制到远程实例。然后在遥控器上执行 运行 gcloud auth activate-service-account <service account address> --key-file remote/path/to/key
命令。然后,新服务帐户将在 gcloud init
菜单中可用。
我正在尝试使用我在 Developers Console 中创建的服务帐户在我的新 GCE 实例上执行 gcloud init
。在 Developers Console 中,我在 Permissions 下看到一些服务帐户,我无法为其生成私钥文件;我还看到了我在 服务帐户 下创建的服务帐户,我 可以 获取其私钥。
当我在 GCE 实例上执行 gcloud init
时,在 "Pick credentials to use" 下,我只能在“权限”选项卡中看到服务帐户(我没有私钥)。我想使用我拥有私钥的服务帐户。
我现在可以使用我的个人帐户登录,但这不可扩展。有什么建议吗?
您可以使用 gcloud auth activate-service-account command to get credentials via the private key for a service account. For more information and example please visit this link.
在进一步讨论后详细说明@Kamaran 的回答。
基本解决方案是在 GCE 实例上启用服务帐户。
首先使用gcloud compute copy-files <private json key file> <instance name>:remote/path/to/key
将文件复制到远程实例。然后在遥控器上执行 运行 gcloud auth activate-service-account <service account address> --key-file remote/path/to/key
命令。然后,新服务帐户将在 gcloud init
菜单中可用。