Skip to content

fix(functions): build with the custom service account when the default compute account is missing or disabled - #11618

Open
IzaakGough wants to merge 19 commits into
fix/skip-deleted-default-compute-safrom
fix/build-with-custom-sa
Open

IzaakGough wants to merge 19 commits into
fix/skip-deleted-default-compute-safrom
fix/build-with-custom-sa

Conversation

@IzaakGough

Copy link
Copy Markdown
Contributor

Fixes #8841. Supersedes #9598, keeping the original commits from @HassanBahati and @cabljac. Stacked on #11534, which it shares the default account lookup with.

2nd gen deploys failed when the default compute service account was deleted or disabled, even if every function set its own serviceAccount.

Now each function builds as its own account, and the deploy prints the gcloud command to grant it the Cloud Build builder role.

  • The CLI never grants roles to user-chosen accounts, as in fix(functions): skip Eventarc roles for a deleted default compute service account #11534. Declarative security accounts get a requiresRole suggestion instead, since the CLI creates them during the deploy.
  • Only a 404 or disabled account changes the build account. Other lookup errors keep current behaviour.
  • The deploy waits 2 minutes before building as a managed account that just got new roles. IAM has no way to tell when a grant takes effect, and without the wait the build failed on a first deploy and the CLI then deleted the account.

Tested with unit tests and live deploys with the default account healthy, disabled and deleted, including a first declarative security deploy. Event functions not tested live.

cabljac and others added 19 commits December 9, 2025 11:45
# Conflicts:
#	src/gcp/cloudfunctionsv2.spec.ts
…fault one is unusable

Setting buildConfig.serviceAccount on every deploy broke runtime service accounts without build permissions. The build service account is now only set when the default compute service account is missing or disabled, and uses projects/- so accounts from other projects resolve.
# Conflicts:
#	CHANGELOG.md
#	src/deploy/functions/release/fabricator.ts
Fail before deploying when a v2 function would build as a missing or disabled
default compute account, and print the commands to grant the build role to the
functions' own accounts instead of granting it.
…-sa' into @invertase/fns-custom-sa

# Conflicts:
#	src/deploy/functions/checkIam.spec.ts
#	src/deploy/functions/checkIam.ts
#	src/deploy/functions/prepare.ts
IAM grants take up to a few minutes to apply, and Cloud Build fails immediately when the managed account can't yet read the source bucket. Wait before creating or updating functions that build as a managed account that was just created or given roles.

@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 adds support for building v2 Cloud Functions using their runtime service accounts when the default compute service account is missing or disabled. Feedback on the changes suggests wrapping the default compute service account lookup in a try-catch block to prevent unexpected deployment failures if the API call itself fails. Additionally, it is recommended to explicitly set the build service account to null when not overridden to avoid configuration drift and ensure previous custom build service accounts are cleared.

Comment thread src/deploy/functions/checkIam.ts Resolved

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.

3 participants