简体   繁体   English

firestore 备份 function 错误,“PERMISSION_DENIED:调用者没有权限”

[英]firestore backup function errors with "PERMISSION_DENIED: The caller does not have permission"

I'm trying to set up a scheduled firebase function that will export all collections in Firestore every 24 hours.我正在尝试设置一个预定的 firebase function,它将每 24 小时导出一次 Firestore 中的所有 collections。 I'm using this script for that:我为此使用了这个脚本:

import {fs} from '../services/firestore';

import * as functions from 'firebase-functions';
import * as firestore from '@google-cloud/firestore';

const client = new firestore.v1.FirestoreAdminClient();

const bucket = 'gs://my-cool-backup';

export const scheduledFirestoreExport = functions
    .region('europe-west1')
    .pubsub
    .schedule('every 24 hours')
    .onRun(async (context) => {
        const collections = await fs.listCollections();

        const projectId = process.env.GCP_PROJECT || process.env.GCLOUD_PROJECT;
        const databaseName =
            client.databasePath(projectId, '(default)');

        const responses = await client.exportDocuments({
            name: databaseName,
            outputUriPrefix: bucket,
            collectionIds: collections.map(x => x.id)
        });

        const response = responses[0];
        console.log(`Operation Name: ${response['name']}`);
        return response;
    });

../services/firestore looks like this: ../services/firestore看起来像这样:

import * as settings from '../settings.json';
import * as serviceAccount from '../firebase-admin.json';
import * as admin from 'firebase-admin';

export const fs = admin.initializeApp({
    credential: admin.credential.cert(serviceAccount as any),
    ...settings.firebase
}).firestore();

When I trigger the function using the Google Cloud Platform, this is the output:当我使用谷歌云平台触发 function 时,这是 output:

Error: function execution failed. Details:
7 PERMISSION_DENIED: The caller does not have permission

The service account I'm using has the following permissions我正在使用的服务帐户具有以下权限

在此处输入图像描述

I have many functions running without any problems, just this one is failing.我有很多功能运行没有任何问题,只有这个失败了。 I suspect it's because of @google-cloud/firestore , whereas the other ones only use firebase-admin我怀疑这是因为@google-cloud/firestore ,而其他的只使用firebase-admin

The error message gives me very little to go with.报错信息给我的很少 go 带。 What am I missing here?我在这里错过了什么?

This is most certainly an issue with permission on the service account you are using.这肯定是您正在使用的服务帐户的权限问题。

You can follow this link for settings Role (roles/datastore.user) [1], [2] for firestore on service account您可以点击此链接设置 Role (roles/datastore.user) [1], [2] for firestore on service account

[1] https://cloud.google.com/firestore/docs/quickstart-servers#set_up_authentication [1] https://cloud.google.com/firestore/docs/quickstart-servers#set_up_authentication

[2] https://cloud.google.com/firestore/docs/security/iam#roles [2] https://cloud.google.com/firestore/docs/security/iam#roles

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Firestore PERMISSION_DENIED - Firestore PERMISSION_DENIED Google Cloud Source Repository:远程:PERMISSION_DENIED:调用者没有远程权限 - Google Cloud Source Repository: remote: PERMISSION_DENIED: The caller does not have permission remote PERMISSION_DENIED Firestore 模拟器 - PERMISSION_DENIED Firestore Emulator cloud_firestore/permission-denied 调用者无权执行指定操作 - cloud_firestore/permission-denied The caller does not have permission to execute the specified operation FirebaseException([cloud_firestore/permission-denied] 调用者没有执行指定操作的权限 - FirebaseException ([cloud_firestore/permission-denied] The caller does not have permission to execute the specified operation firestore:PERMISSION_DENIED:权限缺失或不足 - firestore: PERMISSION_DENIED: Missing or insufficient permissions gcloud Firestore 导入:PERMISSION_DENIED - gcloud Firestore import: PERMISSION_DENIED 运行良好但 FirebaseException([cloud_firestore/permission-denied] 调用者没有执行指定操作的权限。) - was working well but FirebaseException ([cloud_firestore/permission-denied] The caller does not have permission to execute the specified operation.) Firebase iOS 上的 AppCheck:403 权限错误 - PERMISSION_DENIED - Firebase AppCheck on iOS: 403 permission errors - PERMISSION_DENIED 获取错误:Firestore:调用者没有执行指定操作的权限。 但是我已经登录了 - Get Error : Firestore: The caller does not have permission to execute the specified operation. But I have already signed in
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM