使用 .NET 库在 GCE 上使用 GCS 进行身份验证

Authentication with GCS on GCE with .NET library

我有一个 ASP.NET 示例,它使用新的 Google Cloud .NET 库在 GCS 上存储一些文件。我 "gcloud auth login" 在 运行 本地示例之前进行身份验证。当我将此示例部署到 Compute Engine 时,我认为我还必须为 Compute Engine 实例进行设置身份验证,但它看起来很有效。从 Compute Engine 到 Cloud Storage 的请求默认经过身份验证?

很可能您的示例正在使用 Google Application Default Credentials which tries to take a lot of the work out of writing client authentication code by using ambient information where possible. For local testing, gcloud can provide the credentials. On Google App Engine or Google Compute Engine, it uses the associated service account. See also Creating and Enabling Service Accounts for [Google Compute Engine] Instances

当您创建 GCE 实例并选择 "Allow full access to all Cloud APIs" 时,您的凭据会预加载到该 GCE 实例上。无需复制 .json 文件或 运行 gcloud auth。使用应用程序默认凭据查找并使用预加载的凭据。