Search code examples
firebasegoogle-cloud-functionsgoogle-cloud-rungoogle-cloud-scheduler

Firebase Schedule Functions v2 NOT_FOUND Error


When you deploy a v2 firebase scheduled function, it doesn't work and ends up with a "NOT_FOUND" error. There is a way to make it work but clearly the intended behaviour is broken or I am missing something.

Deploying this function with firebase cli, creates two resources. One is a 2nd gen cloud function powered by the cloud run and the other is a cloud scheduler job. The issue is caused by the Auth header in the cloud scheduler job settings. The newly created cloud function requires authentication by default. (Security tab in the cloud run settings) This makes sense since this is not a public api and will be called internally by the cloud scheduler. The cloud scheduler job uses the default app engine service account in the auth header settings however doing so ends up with the NOT_FOUND error. When you set the auth header to none, you now get a PERMISSION_DENIED error as expected. So, if you change the authentication setting of the cloud run function to "Allow unauthenticated invocations", everything works. However, this makes the function publicly accessible. Although it would be difficult for someone to just guess the name, it would be nice to make this work by setting a auth header.

What I have tried is to try the other service accounts and also adding a cloud function invoker role to the default app engine service account but I have ended up getting the NOT_FOUND error again. I am out of ideas and if I am not missing something, this is way complicated for the expected smooth Firebase experience.

EDIT: My question is, how I can make the scheduled job to work with the my second gen cloud function that has "Require authentication" enabled.


Solution

  • I have disabled and enabled the Cloud Scheduler API and everything is working now.