Skip to content

Commit 7c4f423

Browse files
authored
feat(elasticloadbalancingv2): connection logs for ALB (#30599)
### Reason for this change ALB can output connection logs as well as access logs to the S3 bucket, but this is not yet supported by L2 Construct. https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-connection-logs.html ### Description of changes The implementation is almost the same as for access logs. However, since connection logs are not supported by NLB, but only by ALB, the `logConnectionLogs` method is added to the `ApplicationLoadBalancer` instead of the `BaseLoadBalancer`. The needed BucketPolicy is described in the documentation only as follows, but to support buckets that still use the ACL, it is necessary to set the same policy that is currently set in the access logs. ```json { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::elb-account-id:root" }, "Action": "s3:PutObject", "Resource": "arn:aws:s3:::bucket-name/prefix/AWSLogs/aws-account-id/*" } ] } ``` https://docs.aws.amazon.com/elasticloadbalancing/latest/application/enable-connection-logging.html#attach-bucket-policy-connection ### Description of how you validated changes add unit tests and integ tests. ### 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*
1 parent 1e7c690 commit 7c4f423

24 files changed

+1234
-148
lines changed

packages/@aws-cdk-testing/framework-integ/test/aws-elasticloadbalancingv2/test/integ.alb.extended.log.js.snapshot/aws-cdk-elbv2-integ.assets.json

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-elasticloadbalancingv2/test/integ.alb.extended.log.js.snapshot/aws-cdk-elbv2-integ.template.json

+195-1
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,20 @@
412412
{
413413
"Key": "access_logs.s3.prefix",
414414
"Value": ""
415+
},
416+
{
417+
"Key": "connection_logs.s3.enabled",
418+
"Value": "true"
419+
},
420+
{
421+
"Key": "connection_logs.s3.bucket",
422+
"Value": {
423+
"Ref": "LBALBConnectionLogsBucket4BFA48DB"
424+
}
425+
},
426+
{
427+
"Key": "connection_logs.s3.prefix",
428+
"Value": ""
415429
}
416430
],
417431
"Scheme": "internet-facing",
@@ -434,7 +448,8 @@
434448
"Type": "application"
435449
},
436450
"DependsOn": [
437-
"LBALBAccessLogsBucket6AE92937",
451+
"LBALBAccessLogsBucketPolicy1E4EBAFE",
452+
"LBALBConnectionLogsBucketPolicy62509153",
438453
"VPCPublicSubnet1DefaultRoute91CEF279",
439454
"VPCPublicSubnet1RouteTableAssociation0B0896DC",
440455
"VPCPublicSubnet2DefaultRouteB7481BBA",
@@ -647,6 +662,185 @@
647662
}
648663
}
649664
},
665+
"LBALBConnectionLogsBucket4BFA48DB": {
666+
"Type": "AWS::S3::Bucket",
667+
"Properties": {
668+
"BucketEncryption": {
669+
"ServerSideEncryptionConfiguration": [
670+
{
671+
"ServerSideEncryptionByDefault": {
672+
"SSEAlgorithm": "AES256"
673+
}
674+
}
675+
]
676+
},
677+
"LoggingConfiguration": {
678+
"LogFilePrefix": "selflog/"
679+
},
680+
"PublicAccessBlockConfiguration": {
681+
"BlockPublicAcls": true,
682+
"BlockPublicPolicy": true,
683+
"IgnorePublicAcls": true,
684+
"RestrictPublicBuckets": true
685+
},
686+
"VersioningConfiguration": {
687+
"Status": "Enabled"
688+
}
689+
},
690+
"UpdateReplacePolicy": "Retain",
691+
"DeletionPolicy": "Retain"
692+
},
693+
"LBALBConnectionLogsBucketPolicy62509153": {
694+
"Type": "AWS::S3::BucketPolicy",
695+
"Properties": {
696+
"Bucket": {
697+
"Ref": "LBALBConnectionLogsBucket4BFA48DB"
698+
},
699+
"PolicyDocument": {
700+
"Statement": [
701+
{
702+
"Action": "s3:*",
703+
"Condition": {
704+
"Bool": {
705+
"aws:SecureTransport": "false"
706+
}
707+
},
708+
"Effect": "Deny",
709+
"Principal": {
710+
"AWS": "*"
711+
},
712+
"Resource": [
713+
{
714+
"Fn::GetAtt": [
715+
"LBALBConnectionLogsBucket4BFA48DB",
716+
"Arn"
717+
]
718+
},
719+
{
720+
"Fn::Join": [
721+
"",
722+
[
723+
{
724+
"Fn::GetAtt": [
725+
"LBALBConnectionLogsBucket4BFA48DB",
726+
"Arn"
727+
]
728+
},
729+
"/*"
730+
]
731+
]
732+
}
733+
]
734+
},
735+
{
736+
"Action": "s3:PutObject",
737+
"Condition": {
738+
"ArnLike": {
739+
"aws:SourceArn": {
740+
"Fn::GetAtt": [
741+
"LBALBConnectionLogsBucket4BFA48DB",
742+
"Arn"
743+
]
744+
}
745+
},
746+
"StringEquals": {
747+
"aws:SourceAccount": {
748+
"Ref": "AWS::AccountId"
749+
}
750+
}
751+
},
752+
"Effect": "Allow",
753+
"Principal": {
754+
"Service": "logging.s3.amazonaws.com"
755+
},
756+
"Resource": {
757+
"Fn::Join": [
758+
"",
759+
[
760+
{
761+
"Fn::GetAtt": [
762+
"LBALBConnectionLogsBucket4BFA48DB",
763+
"Arn"
764+
]
765+
},
766+
"/selflog/*"
767+
]
768+
]
769+
}
770+
},
771+
{
772+
"Action": "s3:PutObject",
773+
"Effect": "Allow",
774+
"Principal": {
775+
"AWS": "arn:aws:iam::797873946194:root"
776+
},
777+
"Resource": {
778+
"Fn::Join": [
779+
"",
780+
[
781+
{
782+
"Fn::GetAtt": [
783+
"LBALBConnectionLogsBucket4BFA48DB",
784+
"Arn"
785+
]
786+
},
787+
"/AWSLogs/",
788+
{
789+
"Ref": "AWS::AccountId"
790+
},
791+
"/*"
792+
]
793+
]
794+
}
795+
},
796+
{
797+
"Action": "s3:PutObject",
798+
"Condition": {
799+
"StringEquals": {
800+
"s3:x-amz-acl": "bucket-owner-full-control"
801+
}
802+
},
803+
"Effect": "Allow",
804+
"Principal": {
805+
"Service": "delivery.logs.amazonaws.com"
806+
},
807+
"Resource": {
808+
"Fn::Join": [
809+
"",
810+
[
811+
{
812+
"Fn::GetAtt": [
813+
"LBALBConnectionLogsBucket4BFA48DB",
814+
"Arn"
815+
]
816+
},
817+
"/AWSLogs/",
818+
{
819+
"Ref": "AWS::AccountId"
820+
},
821+
"/*"
822+
]
823+
]
824+
}
825+
},
826+
{
827+
"Action": "s3:GetBucketAcl",
828+
"Effect": "Allow",
829+
"Principal": {
830+
"Service": "delivery.logs.amazonaws.com"
831+
},
832+
"Resource": {
833+
"Fn::GetAtt": [
834+
"LBALBConnectionLogsBucket4BFA48DB",
835+
"Arn"
836+
]
837+
}
838+
}
839+
],
840+
"Version": "2012-10-17"
841+
}
842+
}
843+
},
650844
"LBListener49E825B4": {
651845
"Type": "AWS::ElasticLoadBalancingV2::Listener",
652846
"Properties": {

packages/@aws-cdk-testing/framework-integ/test/aws-elasticloadbalancingv2/test/integ.alb.extended.log.js.snapshot/cdk.out

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-elasticloadbalancingv2/test/integ.alb.extended.log.js.snapshot/cdkintegalbextendedlogDefaultTestDeployAssertAEFAB19B.assets.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-elasticloadbalancingv2/test/integ.alb.extended.log.js.snapshot/integ.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-elasticloadbalancingv2/test/integ.alb.extended.log.js.snapshot/manifest.json

+14-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)