Skip to content

Commit

Permalink
fix(aws-ecs): set permissions for 'awslogs' log driver (aws#1291)
Browse files Browse the repository at this point in the history
Make sure that tasks using the 'awslogs' Log Driver have the correct IAM
permissions to actually write logs. Add grant() methods to IAM LogGroups
to make this nicer to write.

Fixes aws#1279.
  • Loading branch information
rix0rrr authored Dec 6, 2018
1 parent 0919bf4 commit f5bc59b
Show file tree
Hide file tree
Showing 10 changed files with 791 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/@aws-cdk/aws-ecs/lib/container-definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ export class ContainerDefinition extends cdk.Construct {
this.memoryLimitSpecified = props.memoryLimitMiB !== undefined || props.memoryReservationMiB !== undefined;

props.image.bind(this);
if (props.logging) { props.logging.bind(this); }
}

/**
Expand Down
8 changes: 8 additions & 0 deletions packages/@aws-cdk/aws-ecs/lib/log-drivers/aws-log-driver.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logs = require('@aws-cdk/aws-logs');
import cdk = require('@aws-cdk/cdk');
import { ContainerDefinition } from '../container-definition';
import { cloudformation } from '../ecs.generated';
import { LogDriver } from "./log-driver";

Expand Down Expand Up @@ -61,6 +62,13 @@ export class AwsLogDriver extends LogDriver {
});
}

/**
* Called when the log driver is configured on a container
*/
public bind(containerDefinition: ContainerDefinition): void {
this.logGroup.grantWrite(containerDefinition.taskDefinition.obtainExecutionRole());
}

/**
* Return the log driver CloudFormation JSON
*/
Expand Down
6 changes: 6 additions & 0 deletions packages/@aws-cdk/aws-ecs/lib/log-drivers/log-driver.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import cdk = require('@aws-cdk/cdk');
import { ContainerDefinition } from '../container-definition';
import { cloudformation } from '../ecs.generated';

/**
Expand All @@ -9,4 +10,9 @@ export abstract class LogDriver extends cdk.Construct {
* Return the log driver CloudFormation JSON
*/
public abstract renderLogDriver(): cloudformation.TaskDefinitionResource.LogConfigurationProperty;

/**
* Called when the log driver is configured on a container
*/
public abstract bind(containerDefinition: ContainerDefinition): void;
}
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,19 @@
],
"Effect": "Allow",
"Resource": "*"
},
{
"Action": [
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Effect": "Allow",
"Resource": {
"Fn::GetAtt": [
"FargateServiceLoggingLogGroup9B16742A",
"Arn"
]
}
}
],
"Version": "2012-10-17"
Expand Down
Loading

0 comments on commit f5bc59b

Please sign in to comment.