Firebase functions deploy 403 Permission denied on 'locations/null' error - firebase

I am trying to deploy Firebase functions project, on two different target projects on Firebase. One is in region "us-cenral" and the other one is "europe-west".
I'm using only functions and RTDB from Firebase, I don't have a need for "hosting".
At the start, I was having only one Firebase project region:"us-central" and I was able to deploy functions without problem. I have created another project recently in region:"europe-west" on the same billing account. And also in the local project I have added that another project using command:
firebase use --add project2
Since I didn't deploy functions for a couple of months and there was no need to check if deployment is still working on "project1" I have not checked if this functionally is working.
After adding "project2" I have issued command to deploy for the first time on another region.
When using command: "firebase deploy --only functions"
command ended with the following error:
There was an issue deploying your functions. Verify that your project has a Google App Engine instance setup at https://console.cloud.google.com/appengine and try again. If this issue persists, please contact support.
! functions: Upload Error: HTTP Error: 403, Permission denied on 'locations/null' (or it may not exist).
Error: HTTP Error: 403, Permission denied on 'locations/null' (or it may not exist).
[2022-05-11T19:32:17.580Z] Error Context: {
"body": {
"error": {
"code": 403,
"message": "Permission denied on 'locations/null' (or it may not exist).",
"status": "PERMISSION_DENIED"
}
},
"response": {
"statusCode": 403
}
}
Switching back to project1 and trying to deploy the same thing, I got the same error.
So now I'm stuck. Does anyone have experience with this problem and how to overcome it.
Google support suggest to create "App Engine application", I cannot see how this can help as I didn't had that thing in the 1st place and everything was working. Now with the second project I have this error that suggest permissions problem. Since I have OWNER account on both of these projects what could be wrong?
What I have done so far:
installed the latest firebase tools (same problem)
defined default region on both projects (as stated above)
checked that I'm logged with the OWNER account (also switched between different owner account but the same issue)
checked permissions and din't find anything useful
default service accounts exist on both projects with rights
visited suggested link: https://console.cloud.google.com/appengine
on both projects (and still have the same error although not sure if I need to deploy?!? - I don't have anything there to deploy or do I?)
Config package.json:
{
"name": "functions",
"description": "Cloud Functions for Firebase",
"engines": {
"node": "10"
},
"dependencies": {
"canvas": "^2.6.1",
"firebase-admin": "^10.2.0",
"firebase-functions": "^3.21.0",
"jsbarcode": "^3.11.0",
"qrcode": "^1.4.4"
},
"devDependencies": {
"eslint": "^5.16.0",
"eslint-plugin-promise": "^4.0.1",
"firebase-functions-test": "^0.2.0"
},
"private": true
}
Configuration didn't changed from the 1st deploy to project1 when everything was working fine.

At the end I found out the reason for my problem, and posting just to help the others if they end up with the same error.
The problem was not deployment script "per se" but the function that was connected to fetch data from RTDB on the project. Method "region" was supposed to get configured "region(fnRegion)" value, but that variable value was "null" and resulted with the error posted above during deployment.
function selectDatabaseReference(path = '/') {
return functions
.region(fnRegion) // Sets function region
.database
.ref(path); // Sets database reference path
}
It would be nice if I could get more descriptive error to the real cause of the error (I'm not truly sure, what would be the content of that error message though).
Anyway it's good I was not able to deploy functions because of this.

Related

Google Cloud Function / Firebase Function deployment stops working: "unexpected end of file"

Deploying our Firebase Function suddenly stopped working recently. Running firebase functions:log provided an insight that was not very helpful:
2022-02-15T06:53:12.421579Z E XXX:
{"#type":"type.googleapis.com/google.cloud.audit.AuditLog","status":{"code":3,"message":"Build
failed: curl: (22) The requested URL returned error: 404 \n\ngzip:
stdin: unexpected end of file\ntar: Child returned status 1\ntar:
Error is not recoverable: exiting now; Error ID:
08522105"},"authenticationInfo":{"principalEmail":"XXXX"},"serviceName":"cloudfunctions.googleapis.com","methodName":"google.cloud.functions.v1.CloudFunctionsService.UpdateFunction","resourceName":"XXXX"}
The deployment works fine for other projects, but fails even for older versions of this project (ones that have been deployed successfully in the past).
I received a 404 error from gcloud.functions.deploy on deploy:
Deploying function (may take a while - up to 2 minutes)...
.
For Cloud Build Stackdriver Logs, visit: https://console.cloud.google.com/logs/viewer?project=x-xxx-dev&advancedFilter=resource.type%3Dbuild%0Aresource.labels.build_id%3D35aac420-xx-4cd1-b7be-blah%0AlogName%3Dprojects%2Fxxx-xxx-dev%2Flogs%2Fcloudbuild
................failed.
ERROR: (gcloud.functions.deploy) OperationError: code=3, message=Build failed: curl: (22) The requested URL returned error: 404
The root cause error is not visible here, but if you click on the Stackdriver logs link in the console output, there will be more details. In my case, the root error was that yarn 2.4.3 couldn't be downloaded # https://github.com/yarnpkg/yarn/releases/download/v2.4.3/yarn-v2.4.3.tar.gz
I did not expect to be using yarn 2 (berry) at this point, but in my package.json I was not explicit:
"engines": {
...
"yarn": ">=1.22.0"
},
By changing to accept only version 1, the problem was resolved:
"engines": {
...
"yarn": "^1.22.0"
},
I still don't understand why npm resolved this missing version.
The firebase log was not useful at all, but since Functions are built using "Google Cloud Build" I was able to get more insight into what's wrong by opening the Logs Explorer in Google Cloud Console. Select the resource type "Cloud Build" and there you will find logs of each build step and which one failed.
In this case, it fails to fetch the yarn-version specific in our package.json (1.22). Changing it to "1.22.17" (latest as of now) fixed the build.
"engines": {
"node": "14",
"npm": "8.1",
"yarn": "1.22.17"
},

HTTP Error: 403, Permission iam.serviceAccounts.create is required to perform this operation on project "X" FIREBASE

I created a project in firebase, then I made them commands:
firebase login
firebase init
I associated it with my Github and finally
firebase deploy
from project "X" and it worked normally, then, I deleted project y from Github and Firebase and when I try to deploy from a new or different project I get the following error:
HTTP Error: 403, Permission iam.serviceAccounts.create is required to perform this operation on project "X"
You can see the error here:
As you can see in the output, there is a default project in your .firebaserc file located in the directory you choose to initialize the project.
The first thing you need to do is delete the Secret in Github that you share with Firebase in your previous deploy.
For doing that go to your Github Project:
your-project > Settings > Secrets > FIREBASE_SERVICE_ACCOUNT_PROJECT_ID
And remove it.
Then open the file .firebaserc and be sure that the default project is pointing to your current project ID:
{
"projects": {
"default": "id_of_previous_project"
},
After editing property:
{
"projects": {
"default": "id_of_current_project"
},
Then run the script again to get the initial configuration. If the error persist when you deploying or during the initialization, you should run the following command in order to change de default project that Firebase Cli uses in a directory:
firebase use --add

'No matching client found' with Flavors in Flutter

I want to use Flavors for dev and prod, and connect each to a firebase project. I've done the proper setup, but keep getting this error:
Execution failed for task ':app:processDevDebugGoogleServices'. No matching client found for package name 'applicationid.dev'
my build.gradle:
flavorDimensions "app"
productFlavors {
dev {
dimension "app"
resValue "string", "app_name", "App Dev"
applicationIdSuffix ".dev"
}
prod {
dimension "app"
applicationId "applicationid"
The project exists in firebase, the names match, and I've added google-services.json to the proper folder (app/src/dev/google-services.json)
Any idea why this is happening? Thanks in advance!
EDIT
I also tried adding an app inside my main (prod) firebase project, and generating only one google-services.json to manage both. I ran the app as -dev and it ran, but still connected to prod database.
EDIT 2
For people running into the same problem, I got it working by deleting google-services.json from app/ root. Leave the google-services files only inside their proper folders in app/src/...

Deployment error. Build failed: src/index.js does not exist;

This drives me crazy - I'm getting the below error during firebase deploy (click the image to enlarge):
package.json
{
"engines": {
"node": "10"
},
"main": "src/index.js",
...
}
The index.js does exist under the src folder.
I tried to change the path in "main" to a fake path and then it fails before deployment which is expected.
However with the "main": "src/index.js" it actually starts to deploy and fails much later during the process as shown on the screenshot above.
What am I missing here?
I'm using firebase-tools v8.12.0
Please, check build steps and your functions configuration in firebase.json.

Firebase Serve Error

I am new to firebase and am trying to make a simple app that utilizes user authentication. At this point in the project I am trying to run firebase on a local server using CLI commands.
I have set up firebase init and firebase deploy. When I type firebase serve on my project folder i get the response,
"an unexpected error has occurred".
Below i am attaching the contents of my firebase-debug.log file. Any help would be appreciated. Thanks
command requires scopes:
["email","openid","https://www.googleapis.com/auth/cloudplatformprojects.readonly","https://www.googleapis.com/auth/firebase",...
[debug] [2017-06-11T17:09:09.607Z] > authorizing via signed-in user
TypeError: Cannot read property 'public' of undefined
Look in your firebase.json file, which you should have in the directory where you're running firebase serve. It should look something like this:
{
"hosting": {
"public": "app",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
]
}
}
If it doesn't have that "hosting" key, then you'll get that Cannot read property 'public' of undefined error because firebase serve tries to access .hosting.public.
I faced this issue today, I ran it with --debug and found out that I've installed npm/node as sudo user, running following:
firebase serve
was giving me this error:
Error: An unexpected error has occurred.
When I ran it with sudo, I was able to deploy hosting and functions locally:
sudo firebase serve --debug --only hosting,functions
1) create a folder called "public" and put your files inside.
2) edit the firebase.json and just write this:
{
"hosting": {
"public": "public"
}
}
This appears to be a bug - that ideally should be resolved with Firebase Init. I have logged a support ticket with Firebase, and would encourage others to do so as well.
I think you may have skipped an initialization step by accident (I did the same thing on my first run-through)
Try this (from your same project directory):
1) firebase init
2) When prompted for which services you'll need make sure that Database AND Hosting options have their markers highlighted green (tab to Hosting with the spacebar). It's easy to select just database and let it run its configuration and assume it configures all of the bulleted options below it if you do not watch closely because the stdout info isn't very clear. Now hit Enter
3) Accept the default database settings as you probably did before, and when asked "What do you want to use as your public directory? (public)", hit Enter.
At this point you should be good to go spin up a local firebase web server...
4) try 'firebase serve', hit Enter, and you should get a verification that hosting files are being served from /public
Hope this helps. Good luck.
As for me the error is (--debug attr)
Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/firebase-tools/node_modules/#google-cloud/functions-emulator/logs'
So the solution will be to run with sudo

Resources