-
Notifications
You must be signed in to change notification settings - Fork 205
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
Deployment with gcloud utility fails without additional environment variables #772
Comments
I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight. |
Default credentials cannot be read synchronously in a Cloud Function but
the Admin SDK is initialized synchronously.
Therefore without an available environment variable, it is not possible to
implicitly initialize without waiting for a network call to resolve default
credentials.
To behave otherwise would require a different initialization pattern and
would be an issue to address in the firebase-admin-node repo.
…On Wed, Sep 2, 2020, 6:23 PM Google Open Source Bot < ***@***.***> wrote:
I couldn't figure out how to label this issue, so I've labeled it for a
human to triage. Hang tight.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#772 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAAH7RPCW6SY2XGFUVAOZDSD3VZHANCNFSM4QUCNR7A>
.
|
That's a very helpful response, thank you. I read more carefully and I see that firebase-admin can only get the project ID from a ServiceAccountCredential, and I'm guessing that functions run maybe with a ComputeEngineCredential that needs to fetch credentials from the metadata service. If that's the case, then it makes sense that there is a requirement for firebase-functions to have synchronous access to the project ID through an environment variable. Would a PR to support |
Unfortunately, I believe in more recent Node.js runtimes in Cloud Functions, not even |
It's not available by default. I was suggesting it only for consistency with other libraries like googleapis/google-auth-library-nodejs, which recognizes both. |
It also seems like it should maybe be possible, though perhaps uncommon or not advisable for some reason, to provide service account credentials as JSON in It also seems like If I tried to make a PR, I would look at either supporting these alternatives ways to get synchronous credentials, or remove some of the code in |
I'm closing this ticket, though. Thank you so much for the fast and clear explanation. |
Related issues
#669
#437
Version info
node: v12.18.3
firebase-functions: v3.3.0
firebase-admin: v8.9.2
I have looked in the source and this issue still exists. Read further for details.
Test case
This simple, quickstart example can be used to demonstrate the issue: https://github.com/firebase/functions-samples/tree/master/quickstarts/uppercase-firestore/functions
Steps to reproduce
gcloud functions deploy
, notfirebase deploy
Expected behavior
Since firebase-admin can read the project ID from the application default credentials, I expect not to require any explicit setting for the project ID.
Actual behavior
Code in firebase-functions throws an exception about
GCLOUD_PROJECT
not being defined.https://github.com/firebase/firebase-functions/blob/master/src/providers/firestore.ts#L112
Were you able to successfully deploy your functions?
I was lead to this discovery because the documentation around the environment variables is not very clear:
Source: https://firebase.google.com/docs/functions/config-env
This statement is only true if you deploy with
firebase deploy
, which populatesFIREBASE_CONFIG
.I think firebase-functions should support the project ID from the default credentials, or use
GOOGLE_CLOUD_PROJECT
. The warning during startup if neitherGCLOUD_PROJECT
norFIREBASE_CONFIG
is also erroneous, because initializingfirebase-admin
works just fine using the project ID from the default credentials. Only firebase-functions fails.The text was updated successfully, but these errors were encountered: