firebase-tools icon indicating copy to clipboard operation
firebase-tools copied to clipboard

Functions cannot access Firebase Secrets, when i debug (inspect) mode

Open if-fi opened this issue 3 years ago • 2 comments

[REQUIRED] Environment info

firebase-tools:11.0.1

Platform:MacOS

[REQUIRED] Test case

export const testSecretAccess = functions
  .region("europe-west3")
  .runWith({
    secrets: ["TEST_API_USER"],
  })
  .https.onRequest(async (request, response) => {

    functions.logger.info(`SECRET: ${process.env.TEST_API_USER}`);

    response.send({
      status: process.env.TEST_API_USER ? "success" : "failed",
    });
  });

[REQUIRED] Steps to reproduce

  1. Add a secret: firebase functions:secrets:set TEST_API_USER
  2. Run functions emulator in debug mode: firebase emulators:start --inspect-functions --only functions
  3. Trugger the function http://localhost:5001/<PROJECT_NAME>/europe-west3/testSecretAccess

[REQUIRED] Expected behavior

The value of the secret is logged, and "success" is returned as a response.

Log:

>  {"severity":"INFO","message":"SECRET: test"}

Response:

{"status":"success"}

[REQUIRED] Actual behavior

Log:

>  {"severity":"INFO","message":"SECRET: undefined"}

Response:

{"status":"failed"}

NB: The expected result is achieved, when we run the emulator without debug mode: firebase emulators:start --only functions. The probelm appears only in debug mode.

if-fi avatar Jun 01 '22 12:06 if-fi

Running into the same issue:

[email protected]

Platform: Windows 10

Adam-Beno avatar Aug 27 '22 14:08 Adam-Beno

I'm also running into this issue.

[email protected]

Platform: macOS

@taeold is this a known limitation of the --inspect-functions flag?

justinkrol avatar Oct 03 '22 09:10 justinkrol

I still got this warning in 11.16.0 when run in firebase emulator with --inspect-functions

{"severity":"WARNING","message":"No value found for secret parameter "DIALOGFLOW_KEYFILE". A function can only access a secret if you include the secret in the function's dependency array."}

{"severity":"WARNING","message":"No value found for secret parameter "FACEBOOK_TOKENS". A function can only access a secret if you include the secret in the function's dependency array."}

image

This is my code


const functionsParams = require('firebase-functions/params');
var FACEBOOK_TOKENS = functionsParams.defineSecret("FACEBOOK_TOKENS");
var DIALOGFLOW_KEYFILE = functionsParams.defineSecret("DIALOGFLOW_KEYFILE");

exports.WebHook = functions.region("asia-east1").runWith({ secrets: [FACEBOOK_TOKENS,DIALOGFLOW_KEYFILE] }).https.onRequest(async (request,response) => {
	console.log(DIALOGFLOW_KEYFILE.value());
	console.log(FACEBOOK_TOKENS.value());

It also have weird behaviour that 1 in 10 times it might get the value for unknown reason

Thaina avatar Nov 15 '22 08:11 Thaina