Google Cloud功能数据存储连接问题

时间:2017-06-08 10:42:53

标签: google-cloud-datastore 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,则客户端库使用Applications Default Credentials方法。变量指定。我们未在远程Google Cloud Functions执行环境中使用任何此类文件。

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

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

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

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

1 个答案:

答案 0 :(得分:0)

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

  1. 几周后我再次检查,并且Application Default Credentials在GCF中再次开始工作。
  2. 支持建议像我一样使用其他服务帐户。此外,文档还包含此注意事项。
  3.   

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

    因此,看起来最好对应用程序中使用的每个模块和服务使用显式键。此外,还有指向service account best practices

    的链接