Repository navigation
fix(functions): don't prune secret versions mounted as volumes or used by non-Firebase functions - #11623
Open
rarya618 wants to merge 3 commits into
Open
fix(functions): don't prune secret versions mounted as volumes or used by non-Firebase functions#11623rarya618 wants to merge 3 commits into
rarya618 wants to merge 3 commits into
Conversation
…irebase#11616) functions:secrets:prune counted a version as in use only if a function used it as a secret environment variable. Functions read from GCF v1 and v2 now carry their secretVolumes, and prune counts every version they mount, or the latest version when a volume lists none. The CLI still never deploys secret volumes.
functions:secrets:prune only looked at functions the Firebase CLI had deployed, so a function deployed another way (for example with gcloud) did not stop prune from destroying a secret version it used. functions:secrets:set already checks every function before pruning.
Contributor
There was a problem hiding this comment.
Code Review
This pull request updates the functions:secrets:prune command to ensure it does not destroy secret versions that are mounted as volumes or used by functions deployed outside of the Firebase CLI. It introduces a new SecretVolume interface, updates GCF v1 and v2 endpoint parsers to preserve secret volumes, and incorporates these volumes into the pruning logic. Comprehensive unit tests have been added to validate these scenarios. As there are no review comments to evaluate, I have no feedback to provide.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #11616 (secret volumes, and functions not deployed by the Firebase CLI; the cross-project case is left open, see below).
functions:secrets:prunedecides a Firebase-managed secret version is unused if no function in the project references it. Two gaps made it destroy versions that functions still need:endpointFromFunctioninsrc/gcp/cloudfunctions.tsandsrc/gcp/cloudfunctionsv2.tscopiedsecretEnvironmentVariablesbut notsecretVolumes, andbackend.Endpointhad no field for them. A version that a function only mounts as a file looked unused.functions-secrets-prune.tsfiltered the existing functions withisFirebaseManagedbefore checking usage. A function deployed another way, like thegcloud functions deployin the issue's repro, didn't protect a version even through an env var. So fixing (1) alone wouldn't fix the reported repro.Changes:
backend.Endpointgets an optionalsecretVolumesfield, filled in by bothendpointFromFunctionconversions. It's read-only:functionFromEndpointdoesn't send it, so the CLI still never deploys secret volumes and doesn't touch volumes set by other tools.pruneSecretscounts every version a volume mounts. A volume that lists no versions mounts the latest, so it counts aslatestand is resolved the same way as an env var pinned tolatest. Volumes referencing other projects are ignored, as env vars already are.functions:secrets:prunepasses every function topruneSecrets, asfunctions:secrets:setalready does. The filter dates back to the original secrets release (Release CF3's support for environment variables and secrets #4149) with no stated reason. Removing it can only make prune keep more versions, never destroy more. It's a separate commit in case you'd rather keep it.Not covered
projects/A/secrets/API_KEY/versions/1still doesn't stop prune in project A, because prune can't list another project's functions. That seems to need a product decision (for example, a warning in the confirmation prompt) rather than a code fix, so I left it out.runv2.endpointFromService): secret volumes there live in the service template'svolumes, which isn't read here.Scenarios Tested
pruneSecretstests:latestresolves to, including when the volume references the project by number.endpointFromFunctiontests for GCF v1 and v2:secretVolumesis copied onto the endpoint.npx mochaoversrc/deploy/functions,src/functions,src/gcpand the functions commands: 1931 passing, 0 failing.tscis clean and lint reports no errors.Sample Commands