Skip to content

Commit

Permalink
feat(elasticloadbalancingv2): connection logs for ALB (aws#30599)
Browse files Browse the repository at this point in the history
### 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*
  • Loading branch information
sakurai-ryo authored Aug 9, 2024
1 parent 1e7c690 commit 7c4f423
Show file tree
Hide file tree
Showing 24 changed files with 1,234 additions and 148 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,20 @@
{
"Key": "access_logs.s3.prefix",
"Value": ""
},
{
"Key": "connection_logs.s3.enabled",
"Value": "true"
},
{
"Key": "connection_logs.s3.bucket",
"Value": {
"Ref": "LBALBConnectionLogsBucket4BFA48DB"
}
},
{
"Key": "connection_logs.s3.prefix",
"Value": ""
}
],
"Scheme": "internet-facing",
Expand All @@ -434,7 +448,8 @@
"Type": "application"
},
"DependsOn": [
"LBALBAccessLogsBucket6AE92937",
"LBALBAccessLogsBucketPolicy1E4EBAFE",
"LBALBConnectionLogsBucketPolicy62509153",
"VPCPublicSubnet1DefaultRoute91CEF279",
"VPCPublicSubnet1RouteTableAssociation0B0896DC",
"VPCPublicSubnet2DefaultRouteB7481BBA",
Expand Down Expand Up @@ -647,6 +662,185 @@
}
}
},
"LBALBConnectionLogsBucket4BFA48DB": {
"Type": "AWS::S3::Bucket",
"Properties": {
"BucketEncryption": {
"ServerSideEncryptionConfiguration": [
{
"ServerSideEncryptionByDefault": {
"SSEAlgorithm": "AES256"
}
}
]
},
"LoggingConfiguration": {
"LogFilePrefix": "selflog/"
},
"PublicAccessBlockConfiguration": {
"BlockPublicAcls": true,
"BlockPublicPolicy": true,
"IgnorePublicAcls": true,
"RestrictPublicBuckets": true
},
"VersioningConfiguration": {
"Status": "Enabled"
}
},
"UpdateReplacePolicy": "Retain",
"DeletionPolicy": "Retain"
},
"LBALBConnectionLogsBucketPolicy62509153": {
"Type": "AWS::S3::BucketPolicy",
"Properties": {
"Bucket": {
"Ref": "LBALBConnectionLogsBucket4BFA48DB"
},
"PolicyDocument": {
"Statement": [
{
"Action": "s3:*",
"Condition": {
"Bool": {
"aws:SecureTransport": "false"
}
},
"Effect": "Deny",
"Principal": {
"AWS": "*"
},
"Resource": [
{
"Fn::GetAtt": [
"LBALBConnectionLogsBucket4BFA48DB",
"Arn"
]
},
{
"Fn::Join": [
"",
[
{
"Fn::GetAtt": [
"LBALBConnectionLogsBucket4BFA48DB",
"Arn"
]
},
"/*"
]
]
}
]
},
{
"Action": "s3:PutObject",
"Condition": {
"ArnLike": {
"aws:SourceArn": {
"Fn::GetAtt": [
"LBALBConnectionLogsBucket4BFA48DB",
"Arn"
]
}
},
"StringEquals": {
"aws:SourceAccount": {
"Ref": "AWS::AccountId"
}
}
},
"Effect": "Allow",
"Principal": {
"Service": "logging.s3.amazonaws.com"
},
"Resource": {
"Fn::Join": [
"",
[
{
"Fn::GetAtt": [
"LBALBConnectionLogsBucket4BFA48DB",
"Arn"
]
},
"/selflog/*"
]
]
}
},
{
"Action": "s3:PutObject",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::797873946194:root"
},
"Resource": {
"Fn::Join": [
"",
[
{
"Fn::GetAtt": [
"LBALBConnectionLogsBucket4BFA48DB",
"Arn"
]
},
"/AWSLogs/",
{
"Ref": "AWS::AccountId"
},
"/*"
]
]
}
},
{
"Action": "s3:PutObject",
"Condition": {
"StringEquals": {
"s3:x-amz-acl": "bucket-owner-full-control"
}
},
"Effect": "Allow",
"Principal": {
"Service": "delivery.logs.amazonaws.com"
},
"Resource": {
"Fn::Join": [
"",
[
{
"Fn::GetAtt": [
"LBALBConnectionLogsBucket4BFA48DB",
"Arn"
]
},
"/AWSLogs/",
{
"Ref": "AWS::AccountId"
},
"/*"
]
]
}
},
{
"Action": "s3:GetBucketAcl",
"Effect": "Allow",
"Principal": {
"Service": "delivery.logs.amazonaws.com"
},
"Resource": {
"Fn::GetAtt": [
"LBALBConnectionLogsBucket4BFA48DB",
"Arn"
]
}
}
],
"Version": "2012-10-17"
}
}
},
"LBListener49E825B4": {
"Type": "AWS::ElasticLoadBalancingV2::Listener",
"Properties": {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7c4f423

Please sign in to comment.