Google Cloud Functions 数据存储连接问题

问题和答案

几个小时前,我们的应用程序开始失败

Error: Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.
at (/user_code/node_modules/@google-cloud/datastore/node_modules/grpc/src/node/src/client.js:442)

据我所知,客户端库使用应用程序默认凭据方法,以防万一没有权限文件传递到数据库连接实例,或者没有 env。指定的变量。我们没有在远程 Google Cloud Functions 执行环境中使用任何这些文件。

const db = new require("@google-cloud/datastore")();

并且知道我没有看到任何其他方式并生成凭据文件并在数据库初始化期间显式传递它。

const db = new require("@google-cloud/datastore")({
    keyFilename: "./configs/db_key.json" 
});

如果有人知道这种行为的原因 - 请分享。

问题和答案

在与 Google 支持人员对话后,我们发现了几件事。

  1. 几周后,我再次检查,应用程序默认凭据开始在 GCF 中再次工作。
  2. 支持建议像我一样使用额外的服务帐户。此外,文档包含此警告。

注意:创建默认服务帐户的确切行为以及它们在您的项目中的显示方式将来可能会发生变化,因为它们旨在供 Google Compute Engine 和 Google App Engine 使用,因此建议您不要t 依赖这些默认帐户的存在供您使用。建议您使用 IAM API、Cloud Platform Console 或 gcloud 工具明确创建其他服务帐号以供长期使用。来源

因此,看起来最好为应用程序中使用的每个模块和服务使用显式密钥。此外,这里是服务帐户最佳实践的链接

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何从Cloud Functions连接Google Cloud SQL?

如何从Google Cloud Functions NodeJS连接到Google Cloud Storage

将Google Cloud CDN与Google Cloud Functions连接

Google Cloud Functions API在哪里存储和检索数据?

从 Firebase 获取数据 - Google Cloud Functions

Google Cloud Functions - 重试

从同一存储库部署多个Google Cloud Functions

Google Cloud Functions(Python)中的随机连接错误

使用私有IP从Google Functions连接到Cloud SQL

Google Cloud Functions和AWS Lambda的超时问题

如何通过Google Cloud Functions部署与PostgreSQL(梁块)连接的Google Cloud Dataflow

等待Google Cloud Functions(Node-JS)中的数据存储回调

从 Google Cloud Functions 原子更新实时数据库

Google Cloud Functions中的Python

Google Cloud Functions的开发环境

Google Cloud Functions预热时间

Google Cloud Functions通知iOS

Google Cloud Functions-Cloud Storage存储桶触发器延迟触发

使用Cloud Functions for Firebase和@ google-cloud / storage删除图像时出现问题

将大文件从Google云端存储加载到Google Cloud Functions?

Google Cloud 和 Google.Cloud.Functions.Framework

Google Cloud SQL 存储扩展问题

Google Cloud Fedora ssh 连接问题

Google Cloud Functions:Github发布的项目布局

如何从 Google Cloud Functions 中删除文件

使用Google Cloud Functions加速GAE应用

在本地测试Python Google Cloud Functions

Google Cloud Functions是否可以启用CORS?

Google Cloud Functions(Golang)和Terraform