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(s3): cannot deploy multiple replication source buckets (under feature flag) #33360

Merged
merged 11 commits into from
Mar 3, 2025

Conversation

badmintoncryer
Copy link
Contributor

@badmintoncryer badmintoncryer commented Feb 10, 2025

Issue # (if applicable)

Closes #33355.

Reason for this change

We cannot deploy multiple source buckets for object replication due to the explicitly set replication role name.

Description of changes

Set replication role name by PhysicalName.GENERATE_IF_NEEDED.

Describe any new or updated permissions being added

None

Description of how you validated changes

Update both unit and integ test.

Checklist


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

@aws-cdk-automation aws-cdk-automation requested a review from a team February 10, 2025 06:05
@github-actions github-actions bot added bug This issue is a bug. p2 distinguished-contributor [Pilot] contributed 50+ PRs to the CDK labels Feb 10, 2025
@badmintoncryer badmintoncryer marked this pull request as ready for review February 10, 2025 06:08
Copy link

codecov bot commented Feb 10, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.21%. Comparing base (dd0d62f) to head (a564674).

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #33360   +/-   ##
=======================================
  Coverage   82.21%   82.21%           
=======================================
  Files         119      119           
  Lines        6876     6876           
  Branches     1162     1162           
=======================================
  Hits         5653     5653           
  Misses       1120     1120           
  Partials      103      103           
Flag Coverage Δ
suite.unit 82.21% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
packages/aws-cdk ∅ <ø> (∅)
packages/aws-cdk-lib/core 82.21% <ø> (ø)

@badmintoncryer badmintoncryer changed the title fix(s3): cannot deploy multiple source S3 replication source bucket (under feature flag) fix(s3): cannot deploy multiple replication source buckets (under feature flag) Feb 10, 2025
@aws-cdk-automation aws-cdk-automation added the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Feb 10, 2025
@jochemd
Copy link

jochemd commented Feb 10, 2025

How does this work in a scenario where multiple stages are deployed to 1 account? So we have 2 buckets from the TEST stage being replicated and 2 buckets from the PRD stage being replicated? Will they use the same role? And what if the replication is cross-account?

I was more thinking along the lines of adding an optional replicationRole: Role property to the ReplicationRule interface and use that role if it is passed in. That gives the control to the user on when to use the same and when to use different roles. The destination bucket already allows the user to specify the role (ARN) in the addReplicationPolicy method. Or possibly refactor renderReplicationConfiguration so that the part that creates the policy for the source bucket becomes a public method to allow people to set up permissions easily when they cutomize their stack (similar to how the addReplicationPolicy method is public for the destination bucket).

BTW, https://github.com/aws/aws-cdk/blob/main/packages/aws-cdk-lib/aws-s3/lib/bucket.ts#L2853 appears to be confusing the buckets: addReplicationPolicy() can be used to set permissions on the destination bucket.

@badmintoncryer
Copy link
Contributor Author

@jochemd
I'm sorry for my late reply. Thank you for your feedback!

How does this work in a scenario where multiple stages are deployed to 1 account? So we have 2 buckets from the TEST stage being replicated and 2 buckets from the PRD stage being replicated? Will they use the same role? And what if the replication is cross-account?

One replication role is generated for each source bucket, regardless of stage differences or whether cross-account access is involved.
In the case of cross-account access, an explicit role name is specified, but there are no other differences.

I was more thinking along the lines of adding an optional replicationRole: Role property to the ReplicationRule interface and use that role if it is passed in.

Since one replication role executes replication according to multiple replication rules, it seems difficult to simply add a role property to the ReplicationRule interface. However, since I think the idea itself is excellent, how about posting it as a separate issue?
For this PR, I think it's better to focus on fixing the bug where multiple source buckets cannot be defined in the first place.

BTW, https://github.com/aws/aws-cdk/blob/main/packages/aws-cdk-lib/aws-s3/lib/bucket.ts#L2853 appears to be confusing the buckets: addReplicationPolicy() can be used to set permissions on the destination bucket.

Oh! I've not realized this. I'll resolve this problem in another PR.

@badmintoncryer
Copy link
Contributor Author

@jochemd
I noticed that in the original issue you suggested making the role receivable as an argument.

From my perspective, since the current implementation is problematic, I think it would be best to first merge this PR to remove the hardcoded role name, and then create a new PR as a new feature to accept an optional replication role.

@jochemd
Copy link

jochemd commented Feb 15, 2025

Sounds good to me. Unfortunately I am not able to give an actual review or serious testing of this PR as when I try to go through the steps in the contributing guide I get errors on the linking step.

mergify bot pushed a commit that referenced this pull request Feb 18, 2025
### Issue # (if applicable)

None

### Reason for this change

As mentioned in [this comment](#33360 (comment)), the annotation phrase is incorrect and may confuse users.
The `addReplicationPolicy()` function works to add a resource policy for the destination bucket, but the annotation phrase says source bucket.

### Description of changes

```diff
- For Cross-account S3 replication, ensure to set up permissions on source bucket using method addReplicationPolicy() 
+ For Cross-account S3 replication, ensure to set up permissions on destination bucket using method addReplicationPolicy() 
```

### Describe any new or updated permissions being added

None


### Description of how you validated changes

None

### Checklist
- [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
yashkh-amzn pushed a commit to yashkh-amzn/aws-cdk that referenced this pull request Feb 21, 2025
)

### Issue # (if applicable)

None

### Reason for this change

As mentioned in [this comment](aws#33360 (comment)), the annotation phrase is incorrect and may confuse users.
The `addReplicationPolicy()` function works to add a resource policy for the destination bucket, but the annotation phrase says source bucket.

### Description of changes

```diff
- For Cross-account S3 replication, ensure to set up permissions on source bucket using method addReplicationPolicy() 
+ For Cross-account S3 replication, ensure to set up permissions on destination bucket using method addReplicationPolicy() 
```

### Describe any new or updated permissions being added

None


### Description of how you validated changes

None

### Checklist
- [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
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.

Just a nit comment. The changes look good to me.

GavinZZ
GavinZZ previously approved these changes Feb 28, 2025
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.

Thank you as always for contributing!

Copy link
Contributor

mergify bot commented Feb 28, 2025

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).

@aws-cdk-automation aws-cdk-automation removed the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Feb 28, 2025
Copy link
Contributor

mergify bot commented Feb 28, 2025

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).

@badmintoncryer
Copy link
Contributor Author

@GavinZZ Thank you always too!

@phuhung273
Copy link
Contributor

Guys is it weird the PR stuck too long while being the 1st in queue ?

@badmintoncryer
Copy link
Contributor Author

@mergify update

Copy link
Contributor

mergify bot commented Mar 1, 2025

update

☑️ Nothing to do

  • queue-position = -1 [📌 update requirement]
  • #commits-behind > 0 [📌 update requirement]
  • -closed [📌 update requirement]
  • -conflict [📌 update requirement]

@badmintoncryer
Copy link
Contributor Author

@mergify dequeue

Copy link
Contributor

mergify bot commented Mar 1, 2025

dequeue

❌ Command disallowed due to command restrictions in the Mergify configuration.

  • sender-permission >= write

@badmintoncryer
Copy link
Contributor Author

@GavinZZ Could you please resolve this mergify problem??

Copy link
Contributor

mergify bot commented Mar 2, 2025

This pull request has been removed from the queue for the following reason: pull request dequeued.

Pull request #33360 has been dequeued. Mergify failed to merge the pull request. GitHub can't merge the pull request after 15 retries.
Base branch was modified in the meantime

You should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it.

If you want to requeue this pull request, you need to post a comment with the text: @mergifyio requeue

@badmintoncryer
Copy link
Contributor Author

@mergify requeue

Copy link
Contributor

mergify bot commented Mar 2, 2025

requeue

❌ Command disallowed due to command restrictions in the Mergify configuration.

  • sender-permission >= write

@badmintoncryer
Copy link
Contributor Author

@mergify update

Copy link
Contributor

mergify bot commented Mar 2, 2025

update

❌ Base branch update has failed

expected head sha didn’t match current head ref.

@GavinZZ
Copy link
Contributor

GavinZZ commented Mar 3, 2025

@badmintoncryer somehow I can't update latest main branch to this PR.. The PR seems to stuck at Checking for the ability to merge automatically.... I'll keep an eye out for this but we may need to create a new PR instead.

@GavinZZ GavinZZ closed this Mar 3, 2025
@GavinZZ GavinZZ reopened this Mar 3, 2025
Copy link

github-actions bot commented Mar 3, 2025

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 3, 2025
@github-actions github-actions bot added the effort/medium Medium work item – several days of effort label Mar 3, 2025
@mergify mergify bot dismissed GavinZZ’s stale review March 3, 2025 19:27

Pull request has been modified.

@mergify mergify bot merged commit d580853 into aws:main Mar 3, 2025
15 of 16 checks passed
@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

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

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

@badmintoncryer badmintoncryer deleted the 33355-fix-replication branch March 4, 2025 03:36
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug This issue is a bug. distinguished-contributor [Pilot] contributed 50+ PRs to the CDK effort/medium Medium work item – several days of effort p2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

s3: replication only allows a single source bucket
5 participants