如何将服务帐户附加到现有 GCP VM?

How to attach a service acount to an existing GCE VM?

需要从 google 云中的现有 GCE VM 提交数据流作业,了解到在创建 VM 时必须有一个具有适当范围的服务帐户附加到该 VM,如果 VM已经存在?如何将服务帐户附加到现有虚拟机?

根据 GCE 文档,您无法在创建实例后更改附加的服务帐户:

After you have created an instance with a service account and specified scopes, you cannot change or expand the list of scopes.

https://cloud.google.com/compute/docs/authentication#using 了解更多详情。

但是,如果您不想重新创建 VM,您应该能够创建一个服务帐户并使用私钥对其进行身份验证,如下所述: https://developers.google.com/identity/protocols/OAuth2ServiceAccount

这可能不如使用 VM 服务帐户方便,因为您需要自己管理私钥和身份验证。