Repository navigation
Conversation
### Description Related to firebase#11330. Explore an opt-in runtimeUpdatePolicy setting in firebase.json for Gen 2 functions. Accept automatic and on-deploy per functions configuration and map the selected policy to the Cloud Functions v2 build configuration. Read deployed policies so policy-only changes are not skipped when source and environment hashes match. Omission preserves existing deployment behavior and leaves new functions to use the API default. This is an initial implementation proposal for design discussion. The option name, its placement in firebase.json, and whether Firebase CLI should manage this setting remain open to maintainer feedback. ### Scenarios Tested - 262 related unit tests passed, including both policy values, omission, invalid configuration, mixed platforms, request bodies and masks, deployed policy conversion, and policy-only deployment changes. - Lint and TypeScript compilation passed. - Full unit suite passed with TZ=UTC: 5,912 passing, 11 pending. UTC avoids an existing datetimeString failure under Asia/Tokyo. - Live Cloud Functions deployment has not been tested. ### Sample Commands Set functions.runtimeUpdatePolicy to automatic or on-deploy in firebase.json, then run: firebase deploy --only functions:hello
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
There was a problem hiding this comment.
Code Review
This pull request introduces the functions.runtimeUpdatePolicy configuration setting for 2nd generation Cloud Functions, allowing users to choose between automatic and on-deploy runtime security updates. The changes include updates to the configuration schema, validation logic, deployment planner, and the Cloud Functions v2 API integration, along with corresponding unit tests. The review feedback recommends extracting the inlined policy strings in the validation function into a top-level constant to comply with the repository's style guide against magic values.
| if ( | ||
| config.runtimeUpdatePolicy !== undefined && | ||
| config.runtimeUpdatePolicy !== "automatic" && | ||
| config.runtimeUpdatePolicy !== "on-deploy" | ||
| ) { | ||
| throw new FirebaseError( | ||
| 'functions.runtimeUpdatePolicy must be either "automatic" or "on-deploy".', | ||
| ); | ||
| } |
There was a problem hiding this comment.
To adhere to the repository style guide (Rule 34: Extract magic numbers and static constants), we should avoid inlining the repeated magic strings "automatic" and "on-deploy". We can extract them into a local allowedPolicies constant array, which also simplifies the validation logic and makes it more maintainable.
| if ( | |
| config.runtimeUpdatePolicy !== undefined && | |
| config.runtimeUpdatePolicy !== "automatic" && | |
| config.runtimeUpdatePolicy !== "on-deploy" | |
| ) { | |
| throw new FirebaseError( | |
| 'functions.runtimeUpdatePolicy must be either "automatic" or "on-deploy".', | |
| ); | |
| } | |
| const allowedPolicies: readonly string[] = ["automatic", "on-deploy"]; | |
| if ( | |
| config.runtimeUpdatePolicy !== undefined && | |
| !allowedPolicies.includes(config.runtimeUpdatePolicy) | |
| ) { | |
| throw new FirebaseError( | |
| 'functions.runtimeUpdatePolicy must be either "automatic" or "on-deploy".', | |
| ); | |
| } |
References
- Extract magic numbers and static constants: Define static IDs, default timeouts, millisecond offsets, and repeated strings as top-level constants (UPPER_SNAKE_CASE) instead of inlining magic values inside functions. Mark static configuration arrays and lookup tables as readonly or as const. (link)
Description
Related to #11330.
This draft explores an opt-in way to configure runtime security updates for
existing 2nd gen functions through Firebase deployments. For example, setting
functions.runtimeUpdatePolicytoautomaticwould switch a function currentlyusing
on-deployto automatic updates on the next deployment.I opened the issue to clarify the intended ownership of this setting. This is an
initial implementation proposal to make that discussion more concrete; the option
name, its placement in
firebase.json, and the behavior when omitted are open tofeedback. Would managing this through Firebase CLI fit the intended configuration
model, or would it be better exposed through the Functions SDK?
The implementation accepts
automaticandon-deployper functionsconfiguration and applies the setting only to 2nd gen functions. It maps the
selected value to the corresponding Cloud Functions v2 build configuration field
and update mask. Policy changes trigger an update even when the source and
environment hashes match. When omitted, no policy field or policy update mask is
sent, preserving existing update behavior and API defaults for new functions.
API reference:
https://cloud.google.com/functions/docs/reference/rest/v2/projects.locations.functions#BuildConfig
Scenarios Tested
preparation, Cloud Functions v2 conversion and requests, and deployment planning.
codebases, and policy-only changes with matching source hashes are covered.
update tests also check the mask. Output-only
runtimeVersionis not sent back.TZ=UTC npm run mocha -- --forbid-only --reporter dotpassed (5,912 passing, 11 pending). UTC avoids an existing
datetimeStringtest failure under Asia/Tokyo.
Sample Commands
With the following
firebase.jsonconfiguration:{ "functions": { "source": "functions", "runtimeUpdatePolicy": "automatic" } }Use
on-deployto apply runtime security patches only on deployment. Omittingthe option leaves the policy unmanaged by Firebase CLI.