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(elasticloadbalancingv2): access logging fails on imported bucket #27948

Merged
merged 3 commits into from
Nov 14, 2023

Conversation

lpizzinidev
Copy link
Contributor

@lpizzinidev lpizzinidev commented Nov 11, 2023

#27558 fixed a circular dependency issue between the bucket and the ELB when using logAccessLogs by adding the dependency at the L1 level.
The dependency was added on both the bucket and the bucket policy (which already refers to the bucket).

This introduced a new bug when adding a dependency for imported buckets (as bucket.node.defaultChild is undefined).

This PR fixes the issue by adding the dependency at the L1 level on the bucket policy directly.

Closes #27928.


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 bug This issue is a bug. effort/medium Medium work item – several days of effort p1 distinguished-contributor [Pilot] contributed 50+ PRs to the CDK labels Nov 11, 2023
@aws-cdk-automation aws-cdk-automation requested a review from a team November 11, 2023 16:11
@aws-cdk-automation aws-cdk-automation added the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Nov 11, 2023
Copy link
Contributor

@tmokmss tmokmss 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 for the speedy fix! One comment for concern 🙏

bucket.addToResourcePolicy(putObjectStatement);
if (!bucket.policy) {
// Imported buckets have `autoCreatePolicy` disabled
bucket.policy = new s3.BucketPolicy(bucket, 'Policy', { bucket });
Copy link
Contributor

@tmokmss tmokmss Nov 13, 2023

Choose a reason for hiding this comment

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

Afaik this may fail if the imported bucket already has its bucket policy configured outside of cfn, because there can only be one bucket policy for each bucket. IMO we'd better leave the bucket policy as it is, at least for this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the review.
Should we provide users some feedback about it or assume they know how to manage bucket policies?

Copy link
Contributor

@tmokmss tmokmss Nov 14, 2023

Choose a reason for hiding this comment

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

Given that there's been no issue related to that, I think we can assume they know it. Additional documents may help, but I found that this behavior is explicitly stated here, which may be already sufficient. I'll leave it to you after all 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, just wanted feedback on this.
I think that the current documentation is clear enough.

Copy link
Contributor

@tmokmss tmokmss left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

Copy link
Contributor

@kaizencc kaizencc left a comment

Choose a reason for hiding this comment

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

Hi @lpizzinidev thanks for the quick fix for this issue! Just one comment, and also a general one: I would love if you described the issue you are solving in more detail in the pr description. It is quite hard to have to figure out what the actual problem is before looking into the code changes.

const bucketPolicy = bucket.policy?.node.defaultChild;
if (lb && bucketPolicy && CfnResource.isCfnResource(lb) && CfnResource.isCfnResource(bucketPolicy)) {
lb.addDependency(bucketPolicy);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

we started off with this (before #27558)

    this.node.addDependency(bucket);

Now, we are (among other changes) only adding the dependency if the policy exists. So I am concerned about the situation where the bucket does not have a policy. In this situation, it seems we used to add this.node.addDependency(bucket), but now skip adding the dependency altogether.

@lpizzinidev is that something you've considered?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the feedback.

If the bucket does not have a policy, then adding a dependency on it would not create a circular dependency.
Are there cases where we want a dependency on the bucket without the policy?
I assume that, if the bucket does not have a policy attached by CDK, the policy must already exist, otherwise logs would not be delivered to S3.

Copy link
Contributor

Choose a reason for hiding this comment

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

Gotcha. We were depending on the bucket before but really only cared about depending on the policy. Thats the nuance I was missing.

Copy link
Contributor

mergify bot commented Nov 14, 2023

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-maintainer-review This PR needs a review from a Core Team Member label Nov 14, 2023
@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

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

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

@mergify mergify bot merged commit ba11f36 into aws:main Nov 14, 2023
12 checks passed
Copy link
Contributor

mergify bot commented Nov 14, 2023

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

kaizencc pushed a commit that referenced this pull request Nov 14, 2023
…27948)

#27558 fixed a circular dependency issue between the bucket and the ELB when using `logAccessLogs` by adding the dependency at the L1 level.
The dependency was added on both the bucket and the bucket policy (which already refers to the bucket).

This introduced a new bug when adding a dependency for imported buckets (as `bucket.node.defaultChild` is `undefined`).

This PR fixes the issue by adding the dependency at the L1 level on the bucket policy directly.

Closes #27928.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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 p1
Projects
None yet
4 participants