firebase / firebase/firebase-tools

Secrets not bound to a function have a value when using the emulator

Open
#6,905 3 comments 1 reaction 0 assignees View on GitHub
emulators: functions reproducible type: feature request
Dominant language
TypeScript
Stars
4.5k
Forks
1.3k
Avg merge
1d 12h
Merged PRs (30d)
84

Description

### [REQUIRED] Environment info

**firebase-tools:** 13.5.2

**Platform:** macOS

### [REQUIRED] Test case

```
import * as logger from "firebase-functions/logger";
import { defineSecret } from 'firebase-functions/params';
import { onRequest } from "firebase-functions/v2/https";

const secret = defineSecret('SECRET');

export const test = onRequest(
// Do not bind the secrets!
// {
// secrets: [secret],
// },
(req, res) => {
logger.info(`The secret is ${secret.value()}`);
});
```

### [REQUIRED] Steps to reproduce

Run the above function in both production and in an environment using the emulator. I used `.secret.local` and `.env.local` to give the secret a value for the emulated environment and used Cloud Secret Manager to provide a value for the production environment.

### [REQUIRED] Expected behavior

Without `secrets` being bound to the function, `secret.value()` should be `undefined` at runtime. See [documentation](https://firebase.google.com/docs/functions/config-env?gen=2nd#secret_parameters).

### [REQUIRED] Actual behavior

In production, `secret.value()` is undefined. In the emulated environment, the value from `.secret.local` is returned.

### Additional observations

There were some additional issues observed during testing of this. It may be expected behaviour, but if not I'm happy to raise additional bugs.

1. When the value of the secret is updated in production (by adding a new version in Cloud Secret Manager) the new value is not returned by `secret.value()` immediately. I had to redeploy the function to start seeing the new value.
2. If I properly bind the `secrets` to the function, run the function, then change the code to no longer bind the `secrets` (as in the test case) then `secret.value()` continues to return the value instead of `undefined`.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.