firebase-tools: Version 11.2.2 and higher do not attach secrets to functions upon deploy when using Firebase Functions SDK
[REQUIRED] Environment info
firebase-tools: 11.2.2,11.3.0 or 11.4.0 (has bug)
firebase-tools: 10.9.2 and 11.1.0 succeeds (no bug)
Platform: macOS
[REQUIRED] Test case
Have a function with runWith secrets:
export const playground = functions
.runWith({
secrets: [
'TEST_SECRET',
],
})
.https.onRequest(app());
[REQUIRED] Steps to reproduce
Deploy the function:
firebase deploy --project projectId --config firebase.json --only functions:playground
[REQUIRED] Expected behavior
The secret should be attached to the function, as it is in 10.9.2 and 11.1.0.
[REQUIRED] Actual behavior
There is no log about attaching the TEST_SECRET in the buggy versions when deploying, whereas 10.9.2 and 11.1.0 do attach the secret. Inside the function, inspecting process.env.TEST_SECRET shows undefined in the buggy versions.
[REQUIRED] Environment info
firebase-tools: 11.2.2,11.3.0 or 11.4.0 (has bug)
firebase-tools: 10.9.2 and 11.1.0 succeeds (no bug)
Platform: macOS
[REQUIRED] Test case
Have a function with runWith secrets:
export const playground = functions
.runWith({
secrets: [
'TEST_SECRET',
],
})
.https.onRequest(app());
[REQUIRED] Steps to reproduce
Deploy the function:
firebase deploy --project projectId --config firebase.json --only functions:playground
[REQUIRED] Expected behavior
The secret should be attached to the function, as it is in 10.9.2 and 11.1.0.
[REQUIRED] Actual behavior
There is no log about attaching the TEST_SECRET in the buggy versions when deploying, whereas 10.9.2 and 11.1.0 do attach the secret. Inside the function, inspecting process.env.TEST_SECRET shows undefined in the buggy versions.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 3
- Comments: 26 (7 by maintainers)
Commits related to this issue
- Fix bug where secrets were not parsed when using old firebase functions sdk versions (#4926) Partially fixes https://github.com/firebase/firebase-tools/issues/4797 — committed to firebase/firebase-tools by taeold 2 years ago
- Fix bug where secrets were not parsed when using old firebase functions sdk versions (#4926) Partially fixes https://github.com/firebase/firebase-tools/issues/4797 — committed to firebase/firebase-tools by taeold 2 years ago
@taeold I did some digging between 11.1.0 and 11.8.0. The issue appears to be that there was a change from
discoverBackendtodiscoverBuild. Unfortunately,discoverBuildcallsaddResourcesToBuildwhich does not contain the block of code to copy the secrets tosecretEnvironmentVariablesthataddResourcesToBackenddoes at https://github.com/firebase/firebase-tools/blob/v11.8.0/src/deploy/functions/runtimes/node/parseTriggers.ts#L496-L507Looks like it was related to this change: https://github.com/firebase/firebase-tools/commit/39bf06e80b79c933a8a3fa5b471962e9d1b02b7c
@taeold I’ve got a debug log attached. But, I think I know why you weren’t able to reproduce it.
In my setup, my functions are part of a workspace so the
npm list firebase-functions --json=truedoesn’t return expected format. As a result, thesdkVersionends up empty and it falls back toparseTriggerswhich still returnssecretsinstead ofsecretEnvironmentVariables.If I break my package out as a standalone package it parses the
firebase-functionsversion successfully and goes intodiscovery.detectFromPortwhich returnssecretsEnvironmentVariablesand carries forward successfully.Here’s an example of the
npm listoutput that is tripping it up:broken.debug.log.gz
Not sure, I have not test this flow for such time
I still got this warning in 11.16.0 when run in firebase emulator
This is my code
Even I have set my secret properly
It also have weird behaviour that 1 in 10 times it might get the value for unknown reason
@protyze Are you also using something like yarn/npm workspaces the way @tpodom described?
@tpodom Thanks for following up. That gives me some closure on why things weren’t working as I’d expect.
Monorepo isn’t something we failed to consider when developing in the CLI, and this is yet another reason for us to pay more attention to it. Same story with yarn pnp support.
We have a 4 year old issue - https://github.com/firebase/firebase-tools/issues/653 - if anything you’ll hear us from this. Thanks you again for helping us understand the issue better.
I’m seeing this as well. Is there anything I can do to help get to the bottom of the issue? I’m using
firebase-functions3.22.0 andfirebase-tools11.7.0.I didn’t notice the issue at first because functions that were previously deployed with secrets still show secrets in Google Cloud. But, deploying new secrets is not working. If I manually add the secret to the function in Google Cloud it seems to stick around after redeploy.
This issue doesn’t seem to be a problem with the emulator, it’s just when it creates the function in Google Cloud from
firebase deploy.