3

I started to add Secret Manager with a SECRET_NAME contains a certain password inside Cloud Function using Node.js. I tried both ways. First, adding Secret Manager using Console and another, adding Secret Manager directly through Firebase CLI. Unfortunately, both ways give an empty Secret value in Cloud Function variable of Secret as shown in picture below.
Link to the picture

I used parameter runWith({secret: ["SECRET_NAME"]}) as shown in code below.

exports.Auth = functions.runWith(secret).https.onCall(async (data, context) => {
  const response = 129132;
  return Promise.resolve(response);
});

const secret = {
  timeoutSeconds: 120,
  memory: "1GB",
  secret: ["SECRET_NAME"],
  minInstances: 0,
};

I followed the documentation written in Firebase Cloud Function (https://firebase.google.com/docs/functions/config-env).

I had wasted almost a week to figure out where I got wrong and found nothing. I also added a role "Secret Manager Secret Accessor" to current SECRET_NAME in Google Cloud Console, and it gave result to nothing at all. As written in this stackoverflow post reference

My question is should I add SECRET_NAME manually in Cloud Function Console in Google Cloud Platform? If so, then what is the use of documentation written above? Is Firebase trying to lead us to nowhere?

Wege
  • 105
  • 9
  • 2
    In your code there you have "secret" instead of "secrets" - could that be the issue? – Michael Bleigh Mar 17 '22 at 04:07
  • 1
    As I tested it on my end, you must not include the secret with other configurations. You can do it like this: const secrets = ["SECRET_NAME"]; const config = { timeoutSeconds: 120, memory: "1GB", minInstances: 0, }; then use multiple `runWith()`. functions.runWith({ secrets }).runWith({ config }) – Marc Anthony B Mar 17 '22 at 04:25
  • @MichaelBleigh - You are correct. I really did mistake it for a reason. Okay, this problem is now solved. Thank you everyone. – Wege Mar 17 '22 at 04:35
  • @MarcAnthonyB - No, bro. We can combine all of runWith parameter into one variable const, and it works. I just made it happen. Anyway, thank you for answering. God blesses you all, good fellow. – Wege Mar 17 '22 at 04:50

1 Answers1

3

I am sorry guys.
Apparently, I was wrong in writing the code:

const secret = {
  timeoutSeconds: 120,
  memory: "1GB",
  secrets: ["SECRET_NAME"], //Must use secrets not secret
  minInstances: 0,
};
enter image description here

Thank you, @MichaelBleigh.
Problem is now solved.

Wege
  • 105
  • 9