首页 > 解决方案 > 如何在生产环境中配置 Google Storage 密钥文件名

问题描述

对于许多人来说,这可能是一个非常简单的问题,但让我发疯。

我一直在查看谷歌关于通过谷歌存储上传文件的几个文档,并且可以在本地进行 - 但我的问题是我无法让它在 GKE 环境中的生产中工作。

我的上传代码:


let KeyfilenamePath = ''

// if development 
keyFilenamePath = path.join(__dirname, '../my-path/keyfile.json');

// if production 
keyFilenamePath = ''

const gcBucket = gc.bucket({
  keyFilename: keyFilenamePath;
  projectId: 'my-project'
});

这在本地环境中运行良好,但我不确定如何通过阅读 Google 的文档使其在生产环境中运行。

我尝试在生产中一起省略 keyFilename,但没有运气。它总是同样的错误:

Error ApiError: Insufficient Permission at new ApiError (/app/node_modules/@google-cloud/common/build/src/util.js:59:15)

现在在我的 pod 上,keyfile.json 显然不存在,而且我还没有设置GOOGLE_APPLICATION_CREDENTIALS. 但从我收集的信息来看,它仍然可以工作,但我不确定如何让一切都与谷歌的 ADC 合作,如: https ://cloud.google.com/docs/authentication/production#auth-cloud-implicit-节点

它指出:

If the environment variable isn't set, ADC uses the default service account that Compute Engine, Google Kubernetes Engine, Cloud Run, App Engine, and Cloud Functions provide, for applications that run on those services.

我应该使用 kubernetes 机密设置 json 密钥文件吗? https://jamesdefabia.github.io/docs/user-guide/kubectl/kubectl_create_secret_generic/

我已经搜索了几个小时,不知道如何处理这个问题。

其他资源:

从 Google Cloud Storage 提供 Google 客户服务帐户的 keyFilename

谷歌云存储 - 权限不足

google plus api:“insufficientPermissions”错误

如何在本地使用 Google Cloud Platform 客户端库时确定身份验证方法

标签: kubernetesgoogle-cloud-storagegoogle-kubernetes-engine

解决方案


推荐阅读