firebase-tools icon indicating copy to clipboard operation
firebase-tools copied to clipboard

fix: set public invoker by default on httpsTrigger update

Open IzaakGough opened this issue 7 months ago • 0 comments

Summary

Fixes https://github.com/firebase/firebase-tools/issues/8984

This PR fixes an issue where HTTPS-triggered functions could become inaccessible after a failed deployment followed by a successful update.

From the original issue:

  • A function is initially deployed with a bug that causes the Cloud Run health check to fail
  • The deployment partially succeeds, but IAM (invoker) policies are never applied
  • After fixing the bug and re-deploying, the CLI performs an update instead of a create
  • During this update, IAM policies are not re-applied, leaving the function requiring authentication
  • As a result, invoking the function returns 403 Forbidden ("Require authentication")

The root cause is that:

  • The create flow sets invoker policies
  • The update flow assumes they already exist and skips setting them
  • If the initial deployment failed before setting IAM, the function is left without an invoker

Changes

  • Ensure updateV1Function and updateV2Function set a default invoker (["public"]) when none is specified
  • Align update behavior with create behavior so IAM policies are always applied
  • Prevent functions from remaining inaccessible after recovering from failed deployments

Manual Testing

Reproduced and verified locally:

  1. Created a new Firebase project and deployed a function with an httpsTrigger
  2. Introduced a bug causing the function to fail Cloud Run health checks
  3. Deployed → function entered a broken state (healthcheck failure)
  4. Fixed the bug
  5. Re-deployed the function (update flow)
  6. Observed:
    • Before fix:
      • Function endpoint returned 403 Forbidden
      • Cloud Run showed "Require authentication"
    • After fix:
      • Function is publicly accessible as expected
      • Invoker is correctly set during update

Tested for:

  • GCFv1
  • GCFv2

Automated Tests

Added/updated tests in fabricator.spec.ts to verify:

  • Default "public" invoker is applied on update when invoker is undefined
  • Explicit invokers are respected
  • Private invokers are not set
  • Non-HTTP triggers do not set invokers

These tests ensure:

  • Consistency between create and update flows
  • Protection against regressions in IAM handling

IzaakGough avatar Apr 16 '26 11:04 IzaakGough