如何消除 Firebase Cloud Functions 中非秘密和秘密环境变量的冲突?

问题描述 投票:0回答:1

我正在使用 Firebase Cloud Functions,它在底层使用 Google Cloud,并且我使用 Google Cloud 的 Secret Manager 为我的 Web 应用程序定义了一些机密。

我在 Firebase 函数的打字稿代码中访问这些秘密,如下所示:

import {onRequest} from 'firebase-functions/v2/https';
import {defineSecret} from 'firebase-functions/params';
import * as logger from 'firebase-functions/logger';
import axios from 'axios';
import * as cors from 'cors';
import * as admin from 'firebase-admin';

const var1= defineSecret('VAR1');
const var2 = defineSecret('VAR2');

当我运行

firebase deploy --only functions
时,我收到此错误:

i  functions: updating Node.js 18 (2nd Gen) function sendEmail(us-central1)...
!  functions: HTTP Error: 400, Could not update Cloud Run service projects/<myproject>/locations/us-central1/services/<myapi>. spec.template.spec.containers[0].env: Secret environment variable overlaps non secret environment variable: VAR1
!  functions:  failed to update function projects/<myproject>/locations/us-central1/functions/<myapi>
Failed to update function projects/<myproject>/locations/us-central1/functions/<myapi>

Functions deploy had errors with the following functions:
        myapi(us-central1)
i  functions: cleaning up build files...
!  functions: Unhandled error cleaning up build images. This could result in a small monthly bill if not corrected. You can attempt to delete these images by redeploying or you can delete them manually at https://console.cloud.google.com/gcr/images/<myproject>/us/gcf

Error: There was an error deploying functions

我尝试删除我的

.env
文件,我运行
firebase functions:config:unset VAR1 VAR2
并运行
gcloud run services describe <myapi> --format='value(spec.template.spec.containers[0].env)'
,它返回了 Google Cloud 中定义的机密。

我不知道如何识别重叠的“非秘密”和“秘密”环境变量。

firebase google-cloud-functions
1个回答
0
投票

我能够通过删除 Google Cloud Run 服务中定义的环境变量来解决此问题。我不确定这些是如何或为何在 Google Cloud Run Service 中定义的。

  1. 转到 Google Cloud Console 的 Cloud Run 部分。
  2. 选择项目并导航到相关服务。
  3. 点击该服务即可进入其详细信息页面。
  4. 单击“编辑并部署新修订版”。
  5. 向下滚动到“变量和秘密”部分。
  6. 在这里,您可以通过单击要删除的变量旁边的垃圾桶图标来删除环境变量。
  7. 进行更改后,单击“部署”以使用新配置更新服务。
© www.soinside.com 2019 - 2024. All rights reserved.