【问题标题】:Exception accessing Google Cloud Storage from newly created Compute Engine从新创建的 Compute Engine 访问 Google Cloud Storage 的异常
【发布时间】:2021-10-19 09:59:09
【问题描述】:

我在旧的谷歌计算引擎上有一个工作的 nodejs 应用程序。将应用程序迁移到新的计算引擎后,我进入了这一行:

const [files] = await storage.bucket(GOOGLE_CLOUD_PROJECT_ID_PUBLIC).getFiles();

以下异常:

Error: Could not refresh access token: A Not Found error was returned while attempting to retrieve an accesstoken for the Compute Engine built-in service account. This may be because the Compute Engine instance does not have any permission scopes specified: Could not refresh access token: 
at Gaxios._request (/smar/backend.smar.shop/node_modules/gaxios/build/src/gaxios.js:129:23)                                                                                                                                                                                       
at processTicksAndRejections (internal/process/task_queues.js:93:5)                                                                                                                                                                                                                           
at async metadataAccessor (/smar/backend.smar.shop/node_modules/gcp-metadata/build/src/index.js:68:21)                                                                                                                                                                            
at async Compute.refreshTokenNoCache (/smar/backend.smar.shop/node_modules/google-auth-library/build/src/auth/computeclient.js:53:20)                                                                                                                                             
at async Compute.getRequestMetadataAsync (/smar/backend.smar.shop/node_modules/google-auth-library/build/src/auth/oauth2client.js:261:17)                                                                                                                                         
at async Compute.getRequestHeaders (/smar/backend.smar.shop/node_modules/google-auth-library/build/src/auth/oauth2client.js:238:26)                                                                                                                                               
at async GoogleAuth.authorizeRequest (/smar/backend.smar.shop/node_modules/google-auth-library/build/src/auth/googleauth.js:600:25)                                                                                                                                               
at async Promise.all (index 1) 

我想这里的重要部分是:因为 Compute Engine 实例没有指定任何权限范围

谁能解释一下这是什么意思,或者我可以在哪里找到这些权限范围?我是否必须修改 Compute Engine 的配置?

【问题讨论】:

  • 编辑范围,菜单>计算引擎>VM实例>名称>停止实例>编辑>云API范围。
  • @danyL 我觉得有点傻。我已经停止了实例。但是在编辑模式下,我看不到任何有作用域的东西:screencast.com/t/pmUqCJ6b 我错过了权限吗?
  • 编辑后转到 SAVE 按钮上方的访问范围 > 为每个 API 设置访问权限
  • @danyL 我爱你!

标签: google-cloud-platform google-cloud-storage google-compute-engine


【解决方案1】:

范围 https://www.googleapis.com/auth/cloud-platform 别名 cloud-platform 是 VM 的最低要求。可能另一个实例可能使用具有不同角色和/或不同 API 访问范围的不同服务帐户?

见“Register your application for Google Cloud Storage JSON API in Google Cloud Platform”;这至少是 NodeJS 客户端 documentation 所建议的。另见:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-11-14
    • 2014-05-18
    • 2015-11-05
    • 1970-01-01
    • 2014-07-10
    • 1970-01-01
    • 1970-01-01
    • 2017-06-03
    相关资源
    最近更新 更多