Skip to content

functions:secrets:prune destroys secret versions that are used outside the current project's secret env vars #11616

Backlog

Description

@IzaakGough

[REQUIRED] Environment info

firebase-tools: 15.37.0 for secrets labelled firebase-managed=true. With #11067 this also covers secrets labelled firebase-managed=functions, which is the label the CLI has used since v13.6.1.

Platform: macOS

[REQUIRED] Test case

A function that uses a Firebase-managed secret API_KEY in a way other than an env var in the same project, for example a 2nd gen function that mounts it as a volume:

gcloud functions deploy my-fn --gen2 --set-secrets=/etc/secrets/api_key=API_KEY:1 ...

[REQUIRED] Steps to reproduce

  1. Create a Firebase-managed secret API_KEY with firebase functions:secrets:set API_KEY.
  2. Deploy a function that mounts version 1 as a volume, as above. No function uses version 1 as an env var.
  3. Run firebase functions:secrets:prune.

[REQUIRED] Expected behavior

Version 1 is kept, because a function uses it.

[REQUIRED] Actual behavior

Prune lists API_KEY@1 as unused and offers to destroy it. Once it is destroyed, the function can no longer read /etc/secrets/api_key.

Cause: prune decides a version is in use only if a function in the current project references it as a secret environment variable (pruneSecrets in src/functions/secrets.ts). Other references are not read:

  • Secret volumes. endpointFromFunction in src/gcp/cloudfunctions.ts and src/gcp/cloudfunctionsv2.ts does not copy secretVolumes, and backend.Endpoint has no field for them.
  • Functions in other projects. Only the current project's functions are listed. A function in project B that references projects/A/secrets/API_KEY/versions/1 does not stop prune in project A from destroying version 1.
  • Cloud Run services under the functionsrunapionly or dartfunctions experiments. serviceFromEndpoint in src/gcp/runv2.ts writes secretKeyRef.secret as the short name, and endpointFromService splits it on /, which leaves projectId undefined, so the reference is skipped.

Workaround: run functions:secrets:prune interactively and decline. It prints a functions:secrets:destroy command for each version, so you can run only the ones you know are unused.

Activity

  1. rarya618 commented on Dec 2, 2026

    @rarya618
    Contributor

    I'm working on a fix for the secret volumes part. One addition to the diagnosis: functions:secrets:prune also drops every function not deployed by the Firebase CLI (isFirebaseManaged in src/commands/functions-secrets-prune.ts) before checking usage. So a function deployed with gcloud, like the one in the repro, protects nothing even through env vars. functions:secrets:set already passes all functions to pruneSecrets, so I plan to do the same in prune.

    I'm leaving the cross-project case out of the PR. Prune can't list another project's functions, so that probably needs a decision from the team (a warning, or not destroying versions by default) rather than a code fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions