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(@aws-cdk/aws-elasticloadbalancingv2)/logAccessLogs provides open permissions on log bucket for alb #2929

Merged
merged 4 commits into from
Jun 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class ApplicationLoadBalancer extends BaseLoadBalancer implements IApplic
* Import an existing Application Load Balancer
*/
public static fromApplicationLoadBalancerAttributes(
scope: Construct, id: string, attrs: ApplicationLoadBalancerAttributes): IApplicationLoadBalancer {
scope: Construct, id: string, attrs: ApplicationLoadBalancerAttributes): IApplicationLoadBalancer {

return new ImportedApplicationLoadBalancer(scope, id, attrs);
}
Expand Down Expand Up @@ -97,7 +97,7 @@ export class ApplicationLoadBalancer extends BaseLoadBalancer implements IApplic
}

prefix = prefix || '';
bucket.grantPut(new iam.AccountPrincipal(account), prefix + '*');
bucket.grantPut(new iam.AccountPrincipal(account), `${(prefix ? prefix + "/" : "")}AWSLogs/${Stack.of(this).account}/*`);

// make sure the bucket's policy is created before the ALB (see https://github.com/awslabs/aws-cdk/issues/1633)
this.node.addDependency(bucket);
Expand Down Expand Up @@ -519,7 +519,7 @@ export interface ApplicationLoadBalancerAttributes {
}

// https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-access-logs.html#access-logging-bucket-permissions
const ELBV2_ACCOUNTS: {[region: string]: string } = {
const ELBV2_ACCOUNTS: { [region: string]: string } = {
'us-east-1': '127311923021',
'us-east-2': '033677994240',
'us-west-1': '027434742980',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export = {

'Access logging'(test: Test) {
// GIVEN
const stack = new cdk.Stack(undefined, undefined, { env: { region: 'us-east-1' }});
const stack = new cdk.Stack(undefined, undefined, { env: { region: 'us-east-1' } });
const vpc = new ec2.Vpc(stack, 'Stack');
const bucket = new s3.Bucket(stack, 'AccessLoggingBucket');
const lb = new elbv2.ApplicationLoadBalancer(stack, 'LB', { vpc });
Expand Down Expand Up @@ -140,26 +140,29 @@ export = {
Version: '2012-10-17',
Statement: [
{
Action: [ "s3:PutObject*", "s3:Abort*" ],
Action: ["s3:PutObject*", "s3:Abort*"],
Effect: 'Allow',
Principal: { AWS: { "Fn::Join": [ "", [ "arn:", { Ref: "AWS::Partition" }, ":iam::127311923021:root" ] ] } },
Resource: { "Fn::Join": [ "", [ { "Fn::GetAtt": [ "AccessLoggingBucketA6D88F29", "Arn" ] }, "/*" ] ] }
Principal: { AWS: { "Fn::Join": ["", ["arn:", { Ref: "AWS::Partition" }, ":iam::127311923021:root"]] } },
Resource: {
"Fn::Join": ["", [{ "Fn::GetAtt": ["AccessLoggingBucketA6D88F29", "Arn"] }, "/AWSLogs/",
{ Ref: "AWS::AccountId" }, "/*"]]
}
}
]
}
}));

// verify the ALB depends on the bucket *and* the bucket policy
expect(stack).to(haveResource('AWS::ElasticLoadBalancingV2::LoadBalancer', {
DependsOn: [ 'AccessLoggingBucketPolicy700D7CC6', 'AccessLoggingBucketA6D88F29' ]
DependsOn: ['AccessLoggingBucketPolicy700D7CC6', 'AccessLoggingBucketA6D88F29']
}, ResourcePart.CompleteDefinition));

test.done();
},

'access logging with prefix'(test: Test) {
// GIVEN
const stack = new cdk.Stack(undefined, undefined, { env: { region: 'us-east-1' }});
const stack = new cdk.Stack(undefined, undefined, { env: { region: 'us-east-1' } });
const vpc = new ec2.Vpc(stack, 'Stack');
const bucket = new s3.Bucket(stack, 'AccessLoggingBucket');
const lb = new elbv2.ApplicationLoadBalancer(stack, 'LB', { vpc });
Expand Down Expand Up @@ -192,10 +195,13 @@ export = {
Version: '2012-10-17',
Statement: [
{
Action: [ "s3:PutObject*", "s3:Abort*" ],
Action: ["s3:PutObject*", "s3:Abort*"],
Effect: 'Allow',
Principal: { AWS: { "Fn::Join": [ "", [ "arn:", { Ref: "AWS::Partition" }, ":iam::127311923021:root" ] ] } },
Resource: { "Fn::Join": [ "", [ { "Fn::GetAtt": [ "AccessLoggingBucketA6D88F29", "Arn" ] }, "/prefix-of-access-logs*" ] ] }
Principal: { AWS: { "Fn::Join": ["", ["arn:", { Ref: "AWS::Partition" }, ":iam::127311923021:root"]] } },
Resource: {
"Fn::Join": ["", [{ "Fn::GetAtt": ["AccessLoggingBucketA6D88F29", "Arn"] }, "/prefix-of-access-logs/AWSLogs/",
{ Ref: "AWS::AccountId" }, "/*"]]
}
}
]
}
Expand Down