Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(pipelines): pipeline asset role trust policy has account root principal #30084

Merged
merged 12 commits into from
May 8, 2024

Conversation

xazhao
Copy link
Contributor

@xazhao xazhao commented May 7, 2024

Note

This may be a breaking change for some users. If the AssetFileRole is being assumed by other service/Users/Roles, they will not be able to assume the role after this change by default.

To revert back to the old behavior, setting the following feature flag to false in the context section of cdk.json

"@aws-cdk/pipelines:reduceAssetRoleTrustScope": true

The is enabled by default to address the overly broad trust policy of AssetFileRole

Reason for this change

CDK Pipeline will create a AssetFileRole which has trust policy including the root account principal. The root account principal is not needed in this use case and should be removed to scope down trust policy.

Description of changes

Adding a new feature flag PIPELINE_REDUCE_ASSET_ROLE_TRUST_SCOPE with default value true.
When the feature flag is enabled, remove the root account principal from the trust policy.
When the feature flag is disabled, keep the old behavior.

Using the feature flag here in case of customers are using the root account principal and it will allow them to turn off this change.

Description of how you validated changes

Unit test/Integration Test
Manually tested in cross-account pipeline

Checklist


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@github-actions github-actions bot added the p2 label May 7, 2024
@aws-cdk-automation aws-cdk-automation requested a review from a team May 7, 2024 07:46
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label May 7, 2024
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.

A comment requesting an exemption should contain the text Exemption Request. Additionally, if clarification is needed add Clarification Request to a comment.

@xazhao xazhao added the pr-linter/exempt-integ-test The PR linter will not require integ test changes label May 7, 2024
@aws-cdk-automation aws-cdk-automation dismissed their stale review May 7, 2024 08:03

✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.

@xazhao xazhao added p1 and removed p2 pr-linter/exempt-integ-test The PR linter will not require integ test changes labels May 7, 2024
@xazhao xazhao marked this pull request as ready for review May 7, 2024 23:10
@aws-cdk-automation aws-cdk-automation added the pr/needs-maintainer-review This PR needs a review from a Core Team Member label May 7, 2024
Copy link
Contributor

@GavinZZ GavinZZ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some doc changes comment.

packages/aws-cdk-lib/cx-api/lib/features.ts Outdated Show resolved Hide resolved
packages/aws-cdk-lib/cx-api/FEATURE_FLAGS.md Outdated Show resolved Hide resolved
Comment on lines 1307 to 1310
Remove the root account principal from the generated PipelineAssetsFileRole trust policy,
because it's only assumed by the codebuild.
Use a feature flag to make sure existing customers who might be relying
on the overly-broad trust policy are not broken.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of explaining why we add a feature flag here, can we explain the behaviour of the flag when it's true vs false, i.e. When this feature flag is enabled, the it will not add root account principal ...

Comment on lines -400 to -409
Action: 'sts:AssumeRole',
Effect: 'Allow',
Principal: {
AWS: {
'Fn::Join': ['', [
'arn:', { Ref: 'AWS::Partition' }, `:iam::${PIPELINE_ENV.account}:root`,
]],
},
},
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this test change when no feature flag is set?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the behavior has been tested with feature flag in the other test, we can use this to test default value.

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 2ee638f
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

Copy link
Contributor

@GavinZZ GavinZZ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM as long as we update the description with more explanation of the security issue and the solution with the feature flag (how and why it defaults to true)

Copy link
Contributor

mergify bot commented May 8, 2024

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify mergify bot merged commit 3928eae into aws:main May 8, 2024
10 checks passed
@aws-cdk-automation aws-cdk-automation removed the pr/needs-maintainer-review This PR needs a review from a Core Team Member label May 8, 2024
@aws-cdk-automation
Copy link
Collaborator

Comments on closed issues and PRs are hard for our team to see. If you need help, please open a new issue that references this one.

@aws aws locked as resolved and limited conversation to collaborators Jul 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
contribution/core This is a PR that came from AWS. p1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants