Skip to content

Declarative security: first deploy with a fresh managed SA fails with 404 actAs (no propagation wait or retry) #10859

Description

@cabljac

Description

Deploying a codebase with requireRoles on a project with no existing managed service account creates the SA, grants roles, then immediately calls createFunction. IAM SA creation is eventually consistent, so GCF rejects the brand new SA:

i  functions: Creating managed service account firebase-fn-5873801311@<project>.iam.gserviceaccount.com...
i  functions: Granting IAM roles to firebase-fn-5873801311@<project>.iam.gserviceaccount.com...
⚠  functions: Request to .../functions?functionId=... had HTTP Error: 404, Service account
   projects/-/serviceAccounts/firebase-fn-5873801311@... was not found. ... verify that the caller
   has been granted the 'iam.serviceAccounts.actAs' permission.

The SA does exist (visible in console immediately after). There's currently no mitigation on either side:

  • grantNewRoles creates the SA and returns without polling for visibility (src/deploy/functions/release/fabricator.ts:98-118), and applyPlan goes straight into function creates (fabricator.ts:210-212)
  • the 404 is never retried: DEFAULT_RETRY_CODES = [429, 409, 503] (src/deploy/functions/release/executor.ts:22), and createV2Function's catch only special-cases Cloud Run RESOURCE_EXHAUSTED before rethrowing as DeploymentError (fabricator.ts:557-571)

Steps to reproduce

  1. Project with no firebase-fn-* SA, codebase using requireRoles
  2. firebase deploy --only functions
  3. SA is created and roles granted, then every function create fails with the 404 above

Failing tests reproducing both facets (createFunction 404 never retried, getServiceAccount never polled after create) are up as a draft PR: #10858.

Is the intended fix to poll the SA for visibility after creation, to retry this specific 404 on the create path, or both? Terraform and gcloud both sleep-retry here, and a visibility poll alone may not be enough since GCF's own actAs check can lag behind IAM reads.

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