Skip to content

fix(functions): defer secret access granting to release phase to prevent SA 404 race condition - #10983

Merged
inlined merged 7 commits into
mainfrom
stellar_wave_sails_13h41
Aug 26, 2026
Merged

fix(functions): defer secret access granting to release phase to prevent SA 404 race condition#10983
inlined merged 7 commits into
mainfrom
stellar_wave_sails_13h41

Conversation

@inlined

@inlined inlined commented Aug 25, 2026

Copy link
Copy Markdown
Member

Description

Refactors secret access permission granting during Cloud Functions deployment:

  • Refactors ensure.secretAccess into ensure.secretsAccessDelta (to calculate secret-to-service-account mappings), ensure.checkSecretAccess (for dry-run output), and ensure.grantSecretAccess (to grant IAM permissions per secret).
  • Attaches secretAccessPlan to CodebasePlan in planner.ts.
  • In prepare.ts, computes secretsAccessDelta and runs checkSecretAccess only during --dry-run. Added explicit comments noting that actual grants take place in release.
  • In fabricator.ts, enqueues grantSecretAccess execution after grantNewRoles() runs (ensuring service accounts are created first) with retryPredicates: [isTransientError, isServiceAccount404] to gracefully handle GCP IAM propagation delays.

Scenarios Tested

  • Ran unit test suite covering executor.spec.ts, ensure.spec.ts, planner.spec.ts, fabricator.spec.ts, and lifecycle.spec.ts (182 passing).
  • Verified npm run lint:changed-files and npm run build.

Sample Commands

  • firebase deploy --only functions
  • firebase deploy --only functions --dry-run

Notes

This issue revealed that I didn't know about the --dry-run command and it might be worth revisiting this command. I left the existing code in prepare becasue dry-run skips release, but there is legitimate stuff happening in release. We should eventually do a tech debt pass where we maybe stop running parallel code in prepare and instead run --dry-run throughout the codebase. This can reveal things in deploy like "create X bucket" "upload to X artfiact registry" "Create X task queue" "create X service account with Y roles". There's simply too much right now to fix it all and I opted for preserving existing behavior rather than improving it.

…ent SA 404 race condition

### Description
Refactors secret access permission granting during Cloud Functions deployment:
- Refactors ensure.secretAccess into ensure.secretsAccessDelta (to calculate secret-to-service-account mappings), ensure.checkSecretAccess (for dry-run output), and ensure.grantSecretAccess (to grant IAM permissions per secret).
- Attaches secretAccessPlan to CodebasePlan in planner.ts.
- In prepare.ts, computes secretsAccessDelta and runs checkSecretAccess only during --dry-run. Added explicit comments noting that actual grants take place in release.
- In fabricator.ts, enqueues grantSecretAccess execution after grantNewRoles() runs (ensuring service accounts are created first) with retryPredicates: [isTransientError, isServiceAccount404] to gracefully handle GCP IAM propagation delays.

### Scenarios Tested
- Ran unit test suite covering executor.spec.ts, ensure.spec.ts, planner.spec.ts, fabricator.spec.ts, and lifecycle.spec.ts (182 passing).
- Verified npm run lint:changed-files and npm run build.

### Sample Commands
- firebase deploy --only functions
- firebase deploy --only functions --dry-run
@inlined
inlined requested review from Berlioz and ajperel and removed request for ajperel August 25, 2026 00:44

@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 resolves a secret access permission race condition during Cloud Functions deployment by deferring secret grants to the release phase after service accounts are created. It refactors the executor's retry mechanism to use predicates, enabling retries on service account 404 errors, and adds automatic cleanup of newly created service accounts upon complete deployment failure. Feedback on these changes highlights a performance regression in secretAccess where secret grants are processed serially instead of in parallel.

Comment thread src/deploy/functions/ensure.ts Outdated

@ajperel ajperel 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.

Nice. I realize dry-run could benefit from larger improvements but this seems a step in the right direction. Thanks for quickly fixing this!

Comment thread CHANGELOG.md Outdated
Comment thread src/deploy/functions/ensure.ts Outdated
Comment thread src/deploy/functions/ensure.ts Outdated
Comment thread CHANGELOG.md Outdated
@inlined
inlined force-pushed the stellar_wave_sails_13h41 branch from ba92705 to 6527959 Compare August 26, 2026 04:55
@inlined
inlined enabled auto-merge (squash) August 26, 2026 04:58
@inlined
inlined merged commit c5e739b into main Aug 26, 2026
53 checks passed
@inlined
inlined deleted the stellar_wave_sails_13h41 branch August 26, 2026 05:08
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