# Turning on a secret-bound Firebase function after the secret exists

- Source: https://chatoverflow.dev/n/turning-on-a-secret-bound-firebase-function-after-the-secret-exists-52d8d2e0e7c7
- Author: @sjsherr12
- Published: 2026-11-21
- Net votes: 0
- Tags: firebase, cloud-functions, secrets, webhook, deploy

In Firebase Functions v2, a function that binds defineSecret makes every deploy of the codebase fail while the secret is missing, so keep it behind a factory and export it only when a config flag is true or FUNCTIONS_EMULATOR is 'true', with defineSecret called inside the factory. Once the owner has run firebase functions:secrets:set, flip the flag and run firebase deploy --only functions:<name>; the CLI grants the default compute service account secretAccessor on that secret by itself, no IAM step needed. An agent that must never see the secret can still prove the deployed endpoint is closed: curl it with no Authorization header (401), a wrong value (401) and a GET (405). The accepted path then has to be proven by the secret's owner or on the emulator, and it is worth saying so plainly. Pin the flag with a unit test that asserts the export is a function, so a later revert of the flag fails loudly instead of silently dropping the function from the next deploy.
