Skip to content

Fail the deploy when deleting the managed service account fails - #11601

Open
Ultranmus wants to merge 1 commit into
firebase:mainfrom
Ultranmus:fix/delete-managed-sa-error
Open

Ultranmus wants to merge 1 commit into
firebase:mainfrom
Ultranmus:fix/delete-managed-sa-error

Conversation

@Ultranmus

@Ultranmus Ultranmus commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Description

Fixes #11551. Part of #11564.

When a codebase opts out of declarative security, removeOldRoles deletes the managed service account and has a catch that turns a failure into "Failed to delete managed service account ... Please ask an IAM administrator to delete it manually." That catch never ran, because deleteServiceAccount passed resolveOnHTTPError: true: a 403 was returned instead of thrown, and the deploy finished with "Deploy complete!" while the account and its roles stayed behind.

deleteServiceAccount now ignores a 404 (the account is already gone, same as before) and throws on any other error.

The other callers are fine with this:

  • The two cleanup paths in fabricator.ts (role grant failure, 100% deploy failure) already catch and log the error.
  • The Hosting GitHub setup deletes the account and then recreates it. A failed delete now stops with the IAM error, instead of the recreate failing because the account still exists.

Scenarios Tested

  • New iam.spec.ts test: a 403 from the delete is thrown. It fails without the fix. The existing "404 doesn't throw" test still passes.
  • New fabricator.spec.ts test: removeOldRoles fails with the "Failed to delete managed service account" error when the delete fails.
  • npm run mocha: 6142 passing. The "should output the date in the correct format" test also fails on main, and an auth emulator test that failed in the full run passes on its own.
  • tsc, prettier, and eslint (no new warnings).

Sample Commands

firebase deploy --only functions after removing requiresRole, as a deployer without iam.serviceAccounts.delete.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request fixes an issue where function deployments incorrectly reported success when the managed service account for declarative security could not be deleted. The deleteServiceAccount function in src/gcp/iam.ts was updated to only ignore 404 errors and propagate other errors, such as 403 Permission Denied. Relevant unit tests were added to verify this behavior, and the changelog was updated. There are no review comments to evaluate.

deleteServiceAccount passed resolveOnHTTPError, so a 403 was returned
instead of thrown and removeOldRoles reported a successful opt-out while
the managed service account was left behind. Ignore a 404 and throw on
any other error.

Fixes firebase#11551
@Ultranmus
Ultranmus force-pushed the fix/delete-managed-sa-error branch from 18bf39e to 37f6766 Compare December 3, 2026 13:30

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Opting out of declarative security reports success when deleting the managed service account fails

1 participant