Skip to content

Opting out of declarative security deletes the managed service account but leaves its IAM bindings #11550

Open

Description

@IzaakGough

[REQUIRED] Environment info

firebase-tools: 15.36.0, firebase-functions 7.4.0

Platform: macOS

[REQUIRED] Test case

firebase.json:

{ "functions": [ { "source": "fn", "codebase": "repro-dsec", "runtime": "nodejs22" } ] }

fn/index.js:

const { onRequest } = require("firebase-functions/v2/https");
const { requiresRole } = require("firebase-functions/v2");

requiresRole("roles/datastore.viewer");

exports.reproDsecFn = onRequest((req, res) => res.send("ok"));

[REQUIRED] Steps to reproduce

  1. Run firebase deploy --only functions:repro-dsec and confirm the prompt. This creates a managed service account named firebase-fn-<id>, where <id> is random, and grants it roles/datastore.viewer.
  2. Remove the requiresRole line, deploy again, and confirm the prompt.
  3. Run gcloud projects get-iam-policy <project> --flatten=bindings --filter="bindings.members:firebase-fn-<id>".

[REQUIRED] Expected behavior

The service account and its project role bindings are both removed.

[REQUIRED] Actual behavior

The deploy deletes the service account:

i  functions: Deleting managed service account firebase-fn-<id>@<project>.iam.gserviceaccount.com...
✔  Deploy complete!

The project policy still has its binding:

roles/datastore.viewer  ['deleted:serviceAccount:firebase-fn-<id>@<project>.iam.gserviceaccount.com?uid=<uid>']

Each opt-out leaves one entry per declared role.

According to the IAM documentation, these entries count toward the project policy's limit of 1,500 principals, and an account undeleted within 30 days gets these roles back. Neither was tested here.

Cause: In src/deploy/functions/release/fabricator.ts, removeOldRoles deletes the account and returns without removing its roles:

if (plan.serviceAccountToDelete) {
  ...
  await iam.deleteServiceAccount(this.projectId, plan.serviceAccountToDelete);
  ...
  return;
}

Workaround: Remove the entries yourself:

gcloud projects remove-iam-policy-binding <project> --role=<role> --member='deleted:serviceAccount:<email>?uid=<uid>'

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