Skip to content

Error in secrets #141

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

Closed
ekalosak opened this issue Sep 28, 2023 · 3 comments
Closed

Error in secrets #141

ekalosak opened this issue Sep 28, 2023 · 3 comments

Comments

@ekalosak
Copy link
Contributor

There appear to be two redundant methods for accessing secrets in firebase functions, according to https://firebase.google.com/docs/functions/config-env?gen=2nd

From the docs:

@https_fn.on_request(secrets=["SECRET_NAME"])
def process_payment(req):
    myBillingService = initialize_billing(key=os.environ.get('SECRET_NAME'))

and that SECRET_NAME is available once you do firebase functions:secrets:set SECRET_NAME.

I've set a secret and confirmed it exists (tagged with "firebase-managed" in the console, available via firebase functions:secrets:access).

Yet, when I use os.getenv('SECRET_NAME') from within a firestore_fn that has the keyword argument secrets=['SECRET_NAME', the environment variable remains unset (i.e. the getenv returns None).

Beyond the confusion of having two apparently redundant methods for providing secret access in functions, the second of the two does not appear to work. Please let me know if I'm missing something.

Finally, the first method (using params.SecretParam) hasn't worked yet for me either. I wonder if the Firebase team or a more advanced user can advise?

@ekalosak
Copy link
Contributor Author

Yeah, so the method using params.SecretParam is just a thin wrapper around os.getenv.
https://github.com/firebase/firebase-functions-python/blob/main/src/firebase_functions/params.py#L290

Is it just missing from the docs that only e.g. https_fn secrets are supported?

@ekalosak
Copy link
Contributor Author

Searching through the codebase I can't find anywhere where env vars are set. Only got. So it appears that this feature is silently completely unsupported, though the docs claim it is. Is that the case?

I searched for the following:

  • rg "_os\.environ" src
  • rg "environ" src
  • rg "setenv" src

If it's supported, it's implemented elsewhere - I wonder if someone might point me to the other codebase where the environment variables are shown to be injected?

@ekremcet
Copy link

I faced a similar issue, and I think it's caused by the outdated documentation here.

https://firebase.google.com/docs/functions/config-env?gen=2nd#secret_parameters

Just removing the parentheses in the end solves the issue

from firebase_functions import https_fn
from firebase_functions.params import SecretParam

DISCORD_API_KEY = SecretParam('DISCORD_API_KEY');

@https_fn.on_request(secrets=[DISCORD_API_KEY])
def post_to_discord(req):
    api_key = DISCORD_API_KEY.value() --> remove this parentheses

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants