Fix CiStack IAM policy collision across environments - #694
Open
SaqlainR55 wants to merge 1 commit into
Open
Conversation
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.
Please check if the PR fulfills these requirements
What kind of change does this PR introduce?
Bug fix — CiStack IAM policy collision when deploying 3+ environments
What is the current behavior?
grantWrite()on an imported IAM user creates an inline policy with a deterministic name (EntrypointExternalCiUserPolicy1903AFEC) derived from the construct path. This name is identical across all environments. The first two environments deploy successfully (last-writer-wins silently overwrites the policy), but any additional environment fails with "Policy resource was already managed by another stack" due to AWS'sResourceExistenceCheckguardrail.What is the new behavior?
Replaced
grantWrite()with an explicitiam.Policyusing an environment-scoped policy name (${projectEnvName}-ci-artifacts-write). Each environment now creates its own uniquely named policy on the shared IAM user. The S3 actions match exactly whatgrantWrite()generates — no permission changes, only naming.Does this PR introduce a breaking change?
No. Existing environments will migrate from the shared policy to their own scoped policy on next CiStack redeploy. The old shared policy will be deleted once all environments have migrated.
Other information:
One file changed:
packages/infra/infra-shared/src/stacks/ci/ciEntrypoint.ts. Tested across three environments (staging, production, payments) — all CiStacks deployed successfully with no collisions and all pipelines verified working.