fix(codebuild): race condition between CfnProject and IAM Policy for CodeConnections - #38508
Open
ryutasato wants to merge 2 commits into
Open
Conversation
aws-cdk-automation
previously requested changes
Aug 7, 2026
…M policy race condition fix
aws-cdk-automation
dismissed
their stale review
August 7, 2026 03:21
✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.
aws-cdk-automation
temporarily deployed
to
automation
August 7, 2026 03:37 — with
GitHub Actions
Inactive
aws-cdk-automation
temporarily deployed
to
automation
August 7, 2026 03:37 — with
GitHub Actions
Inactive
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue # (if applicable)
Closes #38504.
Reason for this change
When creating a
codebuild.ProjectwithCODECONNECTIONS(orCODESTAR_CONNECTIONS) source authentication, CloudFormation attempts to createAWS::CodeBuild::Projectbefore theAWS::IAM::Policygrantingcodeconnections:UseConnectionis fully attached and propagated to the project's service role. The CodeBuildCreateProjectAPI validates the connection synchronously using the role's permissions, resulting in anOAuthProviderExceptiondeployment failure.Users must currently work around this by manually creating a dedicated
iam.Policyand callingcfnProject.addResourceDependency()— a pattern that should be handled automatically by the construct.Description of changes
packages/aws-cdk-lib/aws-codebuild/lib/project.tsto detect whenCODECONNECTIONSorCODESTAR_CONNECTIONSsource authentication is configuredDependsOndependency fromAWS::CodeBuild::Projectto theAWS::IAM::Policyresource(s) associated with the project's service roleCreateProjectis calledSynthesized template change:
BuildProject: Type: AWS::CodeBuild::Project + DependsOn: + - BuildProjectCodeConnectionsPolicy Properties: ServiceRole: !GetAtt BuildProjectRole.ArnDependsOnmetadata to the CloudFormation templateDescribe any new or updated permissions being added
N/A — No new IAM permissions are introduced. The change only affects CloudFormation resource dependency ordering to ensure existing permissions are propagated before they are needed.
Description of how you validated changes
packages/aws-cdk-lib/aws-codebuild/test/project.test.tsverifying thatProjectwithCODECONNECTIONSsource authentication synthesizes a template containingDependsOnreferencing the IAM policy resourceDependsOn:AWS::CodeBuild::Projectcreation fails withOAuthProviderExceptionDependsOn: Deployment succeeds deterministically —AWS::IAM::PolicyreachesCREATE_COMPLETEbeforeAWS::CodeBuild::Projectcreation beginsChecklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license