Firebase HTTP 云函数 HTTP 错误代码 403

Pao*_*olo 2 http-status-code-403 firebase google-cloud-functions

自 2020 年 3 月 28 日起,我的所有 HTTP 云函数都出现错误。在我上次更新之前,它们运行良好。我只更改了一些内容,在上次部署后我收到了此错误:

<html>

<head>
    <meta http-equiv="content-type" content="text/html;charset=utf-8">
    <title>403 Forbidden</title>
</head>

<body text=#000000 bgcolor=#ffffff>
    <h1>Error: Forbidden</h1>
    <h2>Your client does not have permission to get URL <code>/api/v0/.../</code> from this server. 
</h2>
    <h2></h2>
</body>

</html>
Run Code Online (Sandbox Code Playgroud)

我所做的所有更改不仅仅涉及 BI 中的 HTTP 函数实现。还有其他人有同样的错误吗?从 Firebase 状态控制台来看,firebase 似乎没有遇到任何错误https://status.firebase.google.com/

编辑:添加了有关如何初始化 HTTP 云函数的摘录。

'use strict';

// node import
const cors = require('cors')({ origin: true });
const functions = require('firebase-functions');
const admin = require('firebase-admin');

// Setting timeout and memory for the deploy
const runtimeOpts = {
  timeoutSeconds: 540,
  memory: '2GB'
}


admin.initializeApp(); 

exports.exportMultipleDataToCSV = functions
  .runWith(runtimeOpts)
  .https.onRequest((request, response) => {

    cors(request, response, () => {

      if (request.method === 'PUT')   response.status(403).send('Forbidden!');
      if (request.method === 'DELETE') response.status(403).send('Forbidden!');
      if (request.method === 'POST') response.status(403).send('Forbidden!');

      // BI
      let data = MY-BI;


      response.status(200).set('Access-Control-Allow-Origin', '*').send(data);
    });
});
Run Code Online (Sandbox Code Playgroud)

我正在使用我刚刚看到的库“请求”,该库已在两个月前被弃用。这可能是问题所在?https://www.npmjs.com/package/request

Mic*_*igh 7

Cloud Functions 最近更改了其默认 IAM 策略,将新功能限制为项目所有者(以前是allUsers,允许公共访问)。

为了准备此更改,firebase-tools@7.7.0在创建函数时添加了 IAM 策略更新以添加allUsers权限。如果您使用旧版本的 CLI,新功能可能会以受限模式部署。

但重要的是,此更改应仅适用于新函数的创建 - 如果函数已存在且仅更新,则不应发生 IAM 更改。如果您在更新功能时遇到其他问题,请提交详细的问题,包括调试日志firebase-tools