-
Notifications
You must be signed in to change notification settings - Fork 26
Can not request firebase function by using Cloud Task #157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hello @RTae. Could you tell me which libraries you're using? |
@exaby73 I'm using firebase function to create a cloud task to request another firebase function. Basically, I followed this example but it not working https://firebase.google.com/docs/functions/task-functions?gen=2nd#python tasks_v2 : https://pypi.org/project/google-cloud-tasks/ |
I also failed to get the auth token biz working similarily, so ended up removing access control from the task queue, to get forward. Our thing is low security anyway, and if needed, I guess I can add an API key to the workers. Would be nice to have proper auth working though ofc. |
I tried to follow this Python example too, with no success. |
Is it possible to give me an example I could test with? |
That basically is it, I also tried to follow it and got into the same trouble. https://firebase.google.com/docs/functions/task-functions?gen=2nd#python |
Any luck here? I also followed the docs but no luck. |
I am in the same boat. Anyone find a solution to this? |
Hello all, for those following the sample here there's a small issue, first change @kulaone @antont @spartonia @ShadowBearVR have you followed the instructions here? the error indicates that the service account used doesn't have the role @RTae you're trying to use a service account other than the ADC right? |
@pr-Mais I can confirm the required permissions (and extra) were added and I still got the same type of errors. |
@ShadowBearVR can you post the exact error message you're getting and if it's the same as the issue author? |
I'm also unable to get this to work. The example doesn't include an auth header or token:
This produces an error indicating that an authorization token is required in the function that consumes the queue:
The roles for my default compute service account include cloud run invoker and cloud function invoker: If you follow https://cloud.google.com/run/docs/authenticating/service-to-service#run-service-to-service-example-python, that suggests that you set the url from your service as the audience and create a bearer token you pass through:
This produces a different error in the queue consumer:
If you change the audience from the function to the firebase project (<project_id>), you get a different error:
That certainly looks like the service account doesn't have the required permission, but it does at least have functions invoker and cloud run invoker. It would be really helpful to have a working example. Based on the very first error, it seems like you must explicitly pass some kind of auth information to tasks_v2.Task, but the example doesn't do so. Edit: It looks like there are two different auth checks being performed with two different (and maybe incompatible) sets of requirements. The first looks like a standard firebase auth check. The second seems like it's the underlying cloud tasks. The error messages make it look like we're able to satisfy either Firebase or Cloud Tasks checks, but not both. |
And just for fun, I tried creating a task queue using typescript and calling it from python. That works perfectly if you follow the guidance in https://cloud.google.com/run/docs/authenticating/service-to-service#run-service-to-service-example-python:
If I instead define the queue in python and call it with exactly the same code, I get:
This seems problematic? https://github.com/firebase/firebase-functions-python/blob/7f83050dc44f7877a58a590a5aae1006a6f14358/src/firebase_functions/private/util.py#L218C28-L218C43. That's calling a firebase function to validate auth. The only other use of that method I see is for https functions where using Firebase's auth makes more sense because the caller is very likely to be external: https://github.com/search?q=repo%3Afirebase/firebase-functions-python%20_on_call_handler&type=code. It definitely seems like Firebase's auth requirements differ from the Cloud Run Service's auth requirements. Since they both use the same header it's not possible to satisfy both. A workaround seems to be to enable "Allow unauthenticated invocations" for the service. Firebase might still pass through and validate its own auth token if you do this (I haven't tried to validate that), but you can also pass through a secret or an auth token using the body and manually validate it. |
I have the same issue. Following the example "https://firebase.google.com/docs/functions/task-functions?gen=2nd", whatever configuration I use, I always get some kind of authentication / authorization error |
I'm having the same issue here. I tried adding an
If audience is set to the function url, then the function does seem to get invoked but the Firebase task wrapper fails with this error:
As a previous poster notes, it seems there are two layers of authentication that conflict with each other. Can Firebase team please follow up on this issue? Many people here need help. Thanks! |
Since the Cloud Run service is already doing the authentication, it seems we can patch the Firebase SDK inside the function to bypass auth: import firebase_functions.private.util as firebase_private_util
def _on_call_check_auth_token(*args, **kwargs):
return None
firebase_private_util._on_call_check_auth_token = _on_call_check_auth_token Then when enqueing a task, make sure to set the
I verified this works. |
Thanks, everyone for providing such detailed comments! we were able to reproduce. @jacobg This might be the issue, we are working on a fix ASAP. |
Thank you @pr-Mais 👍 |
This issue should be fixed and will go out in the next release |
Any update for when this will be released? |
^ Same question. Wonder if there're any temporary workarounds for this? |
Hi @exaby73, any updates on this? When will the next release happen?
@GoodluckH , the workaround is to define your function as |
We're planning a release soon. Keep a lookout in the next couple of days |
Any updates? I also have the same issue. |
I had the same issue here. Updating |
Hi, I have problem requesting a firebase function by using cloud task
this is my code
It will raise an error about authentication.
if I add audience in oidc_token with project ID, it will raise another error
From my understanding, both error are about authentication from firebase and cloud run
The text was updated successfully, but these errors were encountered: