node.js - Firebase Cloud Functions missing permission on the build service account - Stack Overflow

To deploy NodeJS (2nd Gen) cloud functions to a Firebase project, I use the firebase deploy —-only func

To deploy NodeJS (2nd Gen) cloud functions to a Firebase project, I use the firebase deploy —-only functions command. following is the code base.

    import {onDocumentWritten} from "firebase-functions/v2/firestore";
import pkgNM from "nodemailer";
const {nodemailer} = pkgNM;

    // Firebase Cloud Function to send email on new document creation
    export const sendEmailOnNewDocument = onDocumentWritten(
        "subscriptions/{documentId}",
        async (event) => {
          const newData = event.data;
          const recipientEmail = "[email protected]";
          const subject = "New Subscription Created";
          const text1 = `A new Subscription was created: ${newData["shopName"]}`;
          const text2 = ` Subscription: ${newData["subscriptionType"]}`;
          // Check if the document was created or updated
          if (newData.after.exists()) {
            try {
            // Create a nodemailer transporter
              const transporter = nodemailer.createTransport({
              // Configure your email service
                host: "smtp.gmail",
                port: 465,
                auth: {
                  user: "[email protected]",
                  pass: "vtmi uzgz eiyw eooy",
                },
              });
    
              // Send email
              await transporter.sendMail({
                from: "[email protected]",
                to: recipientEmail,
                subject: subject,
                text: text1 + text2,
              });
    
              console.log("Email sent successfully");
            } catch (error) {
              console.error("Error sending email:", error);
            }
          } else {
          // Document was deleted
            console.log("Document deleted:", newData.before.data());
          }
        },
    );

but when i execute firebase deploy i get the following error.

PS C:\Users\Sameera\skypos-cloud-functions-repo> firebase deploy --only functions (node:21484) [DEP0040] DeprecationWarning: The punycode module is deprecated. Please use a userland alternative instead. (Use node --trace-deprecation ... to show where the warning was created)

=== Deploying to 'skypos360-bedb0'...

i deploying functions Running command: npm --prefix "$RESOURCE_DIR" run lint

lint eslint .

  • functions: Finished running predeploy script. i functions: preparing codebase default for deployment i functions: ensuring required API cloudfunctions.googleapis is enabled... i functions: ensuring required API cloudbuild.googleapis is enabled... i artifactregistry: ensuring required API artifactregistry.googleapis is enabled...
  • functions: required API cloudfunctions.googleapis is enabled
  • artifactregistry: required API artifactregistry.googleapis is enabled
  • functions: required API cloudbuild.googleapis is enabled i functions: Loading and analyzing source code for codebase default to determine what to deploy Serving at port 8869

i extensions: ensuring required API firebaseextensions.googleapis is enabled...

  • extensions: required API firebaseextensions.googleapis is enabled i functions: preparing functions directory for uploading... i functions: packaged C:\Users\Sameera\skypos-cloud-functions-repo\functions (69.22 KB) for uploading i functions: ensuring required API run.googleapis is enabled... i functions: ensuring required API eventarc.googleapis is enabled... i functions: ensuring required API pubsub.googleapis is enabled... i functions: ensuring required API storage.googleapis is enabled...
  • functions: required API pubsub.googleapis is enabled
  • functions: required API run.googleapis is enabled
  • functions: required API eventarc.googleapis is enabled
  • functions: required API storage.googleapis is enabled i functions: generating the service identity for pubsub.googleapis... i functions: generating the service identity for eventarc.googleapis...
  • functions: functions folder uploaded successfully i functions: creating Node.js 18 (2nd Gen) function sendEmailOnNewDocument(us-central1)... Build failed with status: FAILURE. Could not build the function due to a missing permission on the build service account. If you didn't revoke that permission explicitly, this could be caused by a change in the anization policies. Please refer to the following documentation for more details and resolution: You can also view the logs at ;region=us-central1/c26410df-de6d-4d37-b068-df028419e2b5?project=365124740735.

Functions deploy had errors with the following functions: sendEmailOnNewDocument(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

Error: There was an error deploying functions them manually at

how and where do I have to grant this access?

To deploy NodeJS (2nd Gen) cloud functions to a Firebase project, I use the firebase deploy —-only functions command. following is the code base.

    import {onDocumentWritten} from "firebase-functions/v2/firestore";
import pkgNM from "nodemailer";
const {nodemailer} = pkgNM;

    // Firebase Cloud Function to send email on new document creation
    export const sendEmailOnNewDocument = onDocumentWritten(
        "subscriptions/{documentId}",
        async (event) => {
          const newData = event.data;
          const recipientEmail = "[email protected]";
          const subject = "New Subscription Created";
          const text1 = `A new Subscription was created: ${newData["shopName"]}`;
          const text2 = ` Subscription: ${newData["subscriptionType"]}`;
          // Check if the document was created or updated
          if (newData.after.exists()) {
            try {
            // Create a nodemailer transporter
              const transporter = nodemailer.createTransport({
              // Configure your email service
                host: "smtp.gmail",
                port: 465,
                auth: {
                  user: "[email protected]",
                  pass: "vtmi uzgz eiyw eooy",
                },
              });
    
              // Send email
              await transporter.sendMail({
                from: "[email protected]",
                to: recipientEmail,
                subject: subject,
                text: text1 + text2,
              });
    
              console.log("Email sent successfully");
            } catch (error) {
              console.error("Error sending email:", error);
            }
          } else {
          // Document was deleted
            console.log("Document deleted:", newData.before.data());
          }
        },
    );

but when i execute firebase deploy i get the following error.

PS C:\Users\Sameera\skypos-cloud-functions-repo> firebase deploy --only functions (node:21484) [DEP0040] DeprecationWarning: The punycode module is deprecated. Please use a userland alternative instead. (Use node --trace-deprecation ... to show where the warning was created)

=== Deploying to 'skypos360-bedb0'...

i deploying functions Running command: npm --prefix "$RESOURCE_DIR" run lint

lint eslint .

  • functions: Finished running predeploy script. i functions: preparing codebase default for deployment i functions: ensuring required API cloudfunctions.googleapis is enabled... i functions: ensuring required API cloudbuild.googleapis is enabled... i artifactregistry: ensuring required API artifactregistry.googleapis is enabled...
  • functions: required API cloudfunctions.googleapis is enabled
  • artifactregistry: required API artifactregistry.googleapis is enabled
  • functions: required API cloudbuild.googleapis is enabled i functions: Loading and analyzing source code for codebase default to determine what to deploy Serving at port 8869

i extensions: ensuring required API firebaseextensions.googleapis is enabled...

  • extensions: required API firebaseextensions.googleapis is enabled i functions: preparing functions directory for uploading... i functions: packaged C:\Users\Sameera\skypos-cloud-functions-repo\functions (69.22 KB) for uploading i functions: ensuring required API run.googleapis is enabled... i functions: ensuring required API eventarc.googleapis is enabled... i functions: ensuring required API pubsub.googleapis is enabled... i functions: ensuring required API storage.googleapis is enabled...
  • functions: required API pubsub.googleapis is enabled
  • functions: required API run.googleapis is enabled
  • functions: required API eventarc.googleapis is enabled
  • functions: required API storage.googleapis is enabled i functions: generating the service identity for pubsub.googleapis... i functions: generating the service identity for eventarc.googleapis...
  • functions: functions folder uploaded successfully i functions: creating Node.js 18 (2nd Gen) function sendEmailOnNewDocument(us-central1)... Build failed with status: FAILURE. Could not build the function due to a missing permission on the build service account. If you didn't revoke that permission explicitly, this could be caused by a change in the anization policies. Please refer to the following documentation for more details and resolution: https://cloud.google/functions/docs/troubleshooting#build-service-account You can also view the logs at https://console.cloud.google/cloud-build/builds;region=us-central1/c26410df-de6d-4d37-b068-df028419e2b5?project=365124740735.

Functions deploy had errors with the following functions: sendEmailOnNewDocument(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/gcr/images/skypos360-bedb0/us/gcf

Error: There was an error deploying functions them manually at https://console.cloud.google/gcr/images/skypos360-bedb0/us/gcf

how and where do I have to grant this access?

Share Improve this question asked Nov 19, 2024 at 21:16 Sameera TennakoonSameera Tennakoon 551 silver badge16 bronze badges 1
  • Have you followed the troubleshooting documentation it links in the error message yet? What did/did not work as expected? What other things have you tried? – samthecodingman Commented Nov 19, 2024 at 22:40
Add a comment  | 

1 Answer 1

Reset to default 1

I had a similar issue for an anization that was created recently. It appears the level permissions are more restrictive than they used to be. I had to add the following permissions:

gcloud projects add-iam-policy-binding [project-id] --member="serviceAccount:[project-number][email protected]" --role="roles/logging.logWriter" --condition="None"

gcloud projects add-iam-policy-binding [project-id] --member="serviceAccount:[project-number][email protected]" --role="roles/cloudbuild.builds.builder" --condition="None"

gcloud projects add-iam-policy-binding [project-id] --member="serviceAccount:[project-number][email protected]" --role="roles/storage.objectViewer" --condition="None"

And then change the created cloud run functions so they could be called publicly by allUsers without authentication.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742398009a4436338.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信