Missing necessary permission resourcemanager.projects.getIamPolicy - firebase

The deployment of your Cloud Function failed:
Missing necessary permission resourcemanager.projects.getIamPolicy for service-1044193269753#gcf-admin-robot.iam.gserviceaccount.com on resource projects/ourcafe-mucqxq. Please grant service-1044193269753#gcf-admin-robot.iam.gserviceaccount.com the Cloud Functions Service Agent role. You can do that by running 'gcloud iam service-accounts add-iam-policy-binding projects/ourcafe-mucqxq --member=service-1044193269753#gcf-admin-robot.iam.gserviceaccount.com --role=Cloud Functions Service Agent'
I bumped into this problem in Dialogflow Fulfillment. However, I didn't know how to figure it out, did someone know how to do that?
This picture is IAM
This picture is Service Account

I stumbled over the same message. It appears there's a typo in the gcloud command they give you: the role argument is missing the "roles/" prefix. This version worked for me:
gcloud projects add-iam-policy-binding ourcafe-mucqxq \
--member=serviceAccount:service-1044193269753#gcf-admin-robot.iam.gserviceaccount.com \
--role=roles/cloudfunctions.serviceAgent

Maybe you need to log out and back in.
Check all the small boxes in the login interface.

I feel like the answer is given to you. But I'm not sure. Have you tried running the command provided from the google cloud shell.
From your images the service account that is actually mentioned (service-1044193269753)does not have the role needed.
Read more on the Cloud functions service account here

Related

Firebase functions deploy problem (Failed to create/update function)

I would like to ask for the help of people familiar with Firebase functions. I am struggling with the problem that uploading the code via firebase cli fails. It was working a few days ago, I didn't change anything in the world, I mean through the configuration. And it gets stuck at a part where not even a code change was made. I have had this problem ever since the client set the editor role to the owner role. But in theory this shouldn't be a problem.
firebase deploy --debug returns this:
{"error":{"code":403,"message":"Unable to retrieve the repository metadata for projects/{projectname}/locations/us-central1/repositories/gcf-artifacts. Ensure that the Cloud Functions service account has 'artifactregistry.repositories.list' and 'artifactregistry.repositories.get' permissions. You can add the permissions by granting the role 'roles/artifactregistry.reader'.","status":"PERMISSION_DENIED"}}
I set it up but it still doesn't work. Maybe in the wrong place or I don't know. I only encountered similar problems on the net, but none of them helped. I do not know what to do. Artifactregistry api is also enabled.
firebase functions:log :
2022-11-09T22:15:55.891760Z E friendRequestNotification: {"#type":"type.googleapis.com/google.cloud.audit.AuditLog","status":{"code":7,"message":"Unable to retrieve the repository metadata for projects/{projectname}/locations/us-central1/repositories/gcf-artifacts. Ensure that the Cloud Functions service account has 'artifactregistry.repositories.list' and 'artifactregistry.repositories.get' permissions. You can add the permissions by granting the role 'roles/artifactregistry.reader'."},"authenticationInfo":{"principalEmail":"{email}"},"requestMetadata":{"callerIp":"{ip}","callerSuppliedUserAgent":"FirebaseCLI/11.16.0,gzip(gfe),gzip(gfe)","requestAttributes":{"time":"2022-11-09T22:15:56.055987Z","auth":{}},"destinationAttributes":{}},"serviceName":"cloudfunctions.googleapis.com","methodName":"google.cloud.functions.v1.CloudFunctionsService.CreateFunction","authorizationInfo":[{"resource":"projects/{projectname}/locations/us-central1/functions/friendRequestNotification","permission":"cloudfunctions.functions.create","granted":true,"authorizationLoggingOptions":{"permissionType":"ADMIN_WRITE"},"resourceAttributes":{}}],"resourceName":"projects/{projectname}/locations/us-central1/functions/friendRequestNotification","request":{"function":{"sourceUploadUrl":"https://storage.googleapis.com/uploads-760418412171.us-central1.cloudfunctions.appspot.com/6d1f7217-7899-484f-911c-1dbcb4512d8d.zip?GoogleAccessId=service-{}#gcf-admin-robot.iam.gserviceaccount.com&Expires={}","labels":{"deployment-tool":"cli-firebase","firebase-functions-hash":"{hash}"},"runtime":"nodejs16","dockerRegistry":"ARTIFACT_REGISTRY","entryPoint":"friendRequestNotification","name":"projects/{projectname}/locations/us-central1/functions/friendRequestNotification","eventTrigger":{"eventType":"providers/cloud.firestore/eventTypes/document.create","resource":"projects/{projectname}/databases/(default)/documents/users/{userId}/friends/{friendId}"}},"location":"projects/{projectname}/locations/us-central1","#type":"type.googleapis.com/google.cloud.functions.v1.CreateFunctionRequest"},"resourceLocation":{"currentLocations":["us-central1"]}}
I have already tried all options within the Google cloud iam&admin settings, but nothing.
Well, I solved the issue by updating my credit card. Basically, billing was disabled because my credit card was expired and all the permissions were disabled.
Try to enable the created artifacts for your project on Google Cloud Console
https://console.cloud.google.com/artifacts

gcp giving it roles iam roles to configure the policiy

so what every i am doing in the gcp giving it roles iam roles to configure the policies , i am not able to do to my firebase project. i am able to log into it using my terminal with firebase login and then then firebare init is there and i put the function initilaize but it says i don't have permission to do that i need to give it permission so i open the file
/iam-admin/iam?folder=&organizationId=&project=clone-6de06 because this is my firebase project but i dont' have access to it in the gcp so i am not able to change the permission to change the policy or
need to run the role command
gcloud projects add-iam-policy-binding ourcafe-mucqxq
--member=serviceAccount:service-1044193269753#gcf-admin-robot.iam.gserviceaccount.com
--role=roles/cloudfunctions.serviceAgent as that says it will take care of following error: Deployment of your Cloud Function failed:
Missing necessary permission resourcemanager.projects.getIamPolicy for
service-1044193269753#gcf-admin-robot.iam.gserviceaccount.com on
resource projects/ourcafe-mucqxq. Please grant
service-1044193269753#gcf-admin-robot.iam.gserviceaccount.com the
Cloud Functions Service Agent
any help will be appreciated thank for the help.
Did you try to log in to firebase with a proper account?
If you're not sure that your account with proper permission, you can go to Firebase project >> Project settings >> Users and permission to check that your account is on the list with the right permission.
Also, you can see all of the accounts on the IAM of GCP console.

Error: Failed to get Firebase project project-name. Please make sure the project exists and your account has permission to access it

I tried running firebase deploy like I have always done but came across this Error:
Error: Failed to get Firebase project project-name. Please make sure the project exists and your account has permission to access it.
I have run firebase login and I get 'Already logged in as email#example.com'
The firebase-debug.log file shows a few 401 http responses and some of them have the following text:
'Request had invalid authentication credentials' and also 'invalid token'
How can this be solved?
For me this worked,
firebase logout
firebase login
This worked for me:
Run
firebase use --add
And re-select the project
Simply
use firebase login --reauth
For me, I was setting up a new machine with an existing firebase project. This is what I did:
First successfully login to firebase from your command console
firebase login
Get a list of your projects
firebase projects:list
Tell firebase which project you are using
firebase use <Project ID>
Then, I was able to deploy and use other commands for this project. Hope this helps someone.
sometimes there is a token error you can check debug.log
Error Message in debug.log : [debug] [2020-10-13T23:01:28.050Z] <<< HTTP RESPONSE BODY {"error":{"code":401,"message":"Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.","status":"UNAUTHENTICATED"}}
Solution of error use
firebase login --reauth
and again firebase init for reinitializing the project
select project and
firebase deploy
Run
firebase use --add
And re-select the project
This works 100%
Try logging out of firebase CLI and then log back in with the account that has the project that you are trying to run.
This was the case with me. I was logged in to another firebase account.
Steps:
`firebase logout`
`firebase login`
Any typo inside the .firebaserc would show this error. For me I had an extra comma, removing it solved the error.
Disconnecting the company's VPN and trying it again worked for me.
If none of the other answers worked for you, I had the same problem and received this solution from Firebase Support. (ty Sergei)
My system will occasionally create and Environment Variable named FIREBASE_TOKEN. The token will expire, but the variable does not. Restarts and logout/login cycles did nothing. Deleting the variable works every time though.
Remove-Item Env:\FIREBASE_TOKEN
It's really awesome and confusing------>
just did these command ->
> firebase logout
>
> firebase login
if you use Mac or Linux, you can write this command export http_proxy=http://127.0.0.1:1087 to make sure your terminal uses the proxy, which is useful for me.
None of the above solutions worked for me but removing/editing the stored value of the default project in $HOME/.config/configstore/firebase-tools.json did work.
If you have this issue in a CI pipeline, you can regenerate a token on your local machine with
firebase login:ci
Put the generated token as an environment variable, e.g. FIREBASE_TOKEN and run like this:
firebase deploy --token "$FIREBASE_TOKEN"
1.run this
firebase logout
firebase login
2.if u can not login successfully , like this ?
[https://i.stack.imgur.com/4MJM5.png][1]
run this , export http_proxy=http://localhost:your proxy port
4.successfully!!!
[https://i.stack.imgur.com/sRcvG.png][1]
It is possible you are trying to deploy without internet connection. The first thing to look for is if your internet is okay.
Make sure that you don't have this file .firebaserc already existing in your project directory if you already do!
Delete it and try firebase init in console again.
I got this error in Linux when I was out of disk space, freeing some space resolved it.

can't update firebase functions using cli because Default service account doesn't exist

I realized that my service account credentials were posted to github so I decommissioned them and now I am no longer able to update my firebase functions.
This is the error I get:
functions: failed to create function functionName
HTTP Error: 400, Default service account '<APP_ID>#appspot.gserviceaccount.com' doesn't exist. Please recreate this account (for example by disabling and enabling the Cloud Functions API), or specify a different account.
I've tried numerous solutions to no avail.
disabling and enabling the Cloud Functions API
re initializing the sdk - using a newly generated service account. The firebase cli seems to still be using the old account which no longer exists.
I've contacted firebase support who suggested the second solution above and have been entirely unresponsive for days.
In case anyone has a similar issue I figured out how to fix it:
The key that was leaked was created here:
I assumed that I had to delete the entire account once that key was leaked, and didn't realize I could just delete that key from the same page:
Because I deleted the service account less than 30 days ago I was able to Restore the default service account
If you are outside of the 30-day window I don't think anyone can help you.

How to retrieve list of Firebase authenticated users and download them in JSON format?

I am new to firebase, I wanted to retrieve list of my authenticated users in JSON Format
I have searched for the solution but couldn't have found, some say it isn't possible !!!
Please, someone, tell me whether it is possible or any other alternative ways to
get my users username/displayName/emailId or any other description based on their SignUp method.
I found a way to do it but I got an error , using Nodejs with this command :
**firebase auth:export users.json --format=json --project projectname**
This is a rather indirect answer, but, when they sign up, you could add the info you need about the user to the Firebase live database. Then, when you retrieve that information from the database, it's in JSON. I guess this probably isn't the answer you were looking for, but I hope it helps.
Ensure that you have firebase-cli installed on your computer. If so, just use firebase auth:export <name.format> --project <project-id> from the command line.
You can read more about the exported file from their tutorials here.

Resources