Skip to content

fix(provisioning): retry KMS fresh-principal policy + bind EC2 IAM instance profile post-launch - #848

Merged
go-to-k merged 1 commit into
mainfrom
test/propagation-races-2
Jun 14, 2026
Merged

fix(provisioning): retry KMS fresh-principal policy + bind EC2 IAM instance profile post-launch#848
go-to-k merged 1 commit into
mainfrom
test/propagation-races-2

Conversation

@go-to-k

@go-to-k go-to-k commented Jun 14, 2026

Copy link
Copy Markdown
Owner

Summary

This branch fixes two real cdkd bugs that surface when a resource consumes a freshly-created IAM principal/profile, plus adds the propagation-races-2 integ fixture and unit tests.

Bug 1: KMS Key create fails on fresh-IAM-principal key policy (propagation race)

Creating a KMS Key whose key policy references a just-created IAM principal failed with Policy contains a statement with one or more invalid principals. The IAM principal exists but has not yet propagated to the region KMS validates against, so the first CreateKey is rejected.

Fix: added the fresh-principal propagation pattern to src/deployment/retryable-errors.ts so the create is retried until the principal is visible to KMS.

Bug 2: EC2 instance silently launches without its fresh IAM instance profile

IamInstanceProfile in the template is a NAME string, not a {Arn, Name} object. The prior code passed the raw value through in a shape the SDK ignored, so the instance launched with no instance profile bound and no error was raised.

Fix in src/provisioning/providers/ec2-provider.ts:

  • normalize the IamInstanceProfile shape (accept a name string),
  • after launch, describe-then-associate the profile and poll the association until it reports associated, so a fresh profile that has not yet propagated still binds deterministically.

Tests

  • propagation-races-2 integ fixture (4 fresh-principal/consumer race edges) with verify.sh.
  • Unit tests: tests/unit/deployment/retryable-errors.test.ts (KMS fresh-principal retry classification) and tests/unit/provisioning/providers/ec2-provider-instance-profile-bind.test.ts (shape normalization + post-launch associate/poll).

Verification

Validated green against real AWS (deploy + destroy clean) on the propagation-races-2 fixture.

…instance profile post-launch

Harden two propagation-race paths surfaced by the propagation-races-2 fixture:

- retryable-errors: classify KMS key-policy "fresh principal" failures as
  retryable so a just-created IAM principal referenced in a KMS key policy is
  retried until IAM propagation catches up.
- ec2-provider: after launching an EC2 instance, describe-then-associate the
  IAM instance profile and poll until the association is observed, so a freshly
  created instance profile binds reliably despite IAM propagation lag.

Adds the propagation-races-2 integration fixture plus unit coverage for the
KMS retry classifier and the EC2 instance-profile bind path.
@go-to-k
go-to-k force-pushed the test/propagation-races-2 branch from cc81631 to c7bddab Compare June 14, 2026 01:27
@go-to-k

go-to-k commented Jun 14, 2026

Copy link
Copy Markdown
Owner Author

Independent code review complete (pr-code-reviewer): both fixes clean, no blockers. KMS + IAM-instance-profile retry patterns well-anchored; normalizeIamInstanceProfile handles all 3 shapes; post-launch describe-associate-poll is bounded (10 attempts each), idempotent, and correctly treats 'associating' as not-yet-bound. 3 minor nits accepted as known cost: a dead defensive branch (ec2-provider.ts:2521), worst-case ~90s propagation wall-time (within the per-resource path), and a slightly-broad 'not authorized' substring (bounded by maxAttempts). Plus unit tests + real-AWS integ PASS. Setting pr-review bound to c7bddab.

@go-to-k
go-to-k merged commit afd5c63 into main Jun 14, 2026
5 checks passed
@go-to-k
go-to-k deleted the test/propagation-races-2 branch June 14, 2026 01:31
github-actions Bot pushed a commit that referenced this pull request Jun 14, 2026
## [0.221.8](v0.221.7...v0.221.8) (2026-06-14)

### Bug Fixes

* **provisioning:** retry KMS fresh-principal policy + bind EC2 IAM instance profile post-launch ([#848](#848)) ([afd5c63](afd5c63))
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 0.221.8 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant