Skip to content

Commit

Permalink
fix: add permisson to task execution role policy
Browse files Browse the repository at this point in the history
  • Loading branch information
marnixdessing committed Jun 14, 2023
1 parent f28bfb4 commit fb69d45
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/ContainerCluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@ export class ContainerClusterStack extends Stack {
environment: {
IRMA_GW_URL: this.hostedzone.zoneName, // protocol prefix is added in the container
},
secretsKmsKeyArn: ssm.StringParameter.valueForStringParameter(this, Statics.ssmProtectionKeyArn),
});

// Allow role to use the protection key for accessing the secrets on startup
Expand Down
1 change: 0 additions & 1 deletion src/ParameterStack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export class SecretsStack extends Stack {
}



createYiviProtectionKey() {
const key = new kms.Key(this, 'protection-key', {
description: 'Key for protecting access to secrets for Yivi',
Expand Down
15 changes: 15 additions & 0 deletions src/constructs/EcsFargateService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
aws_secretsmanager as secrets,
aws_cloudwatch as cloudwatch,
aws_elasticloadbalancingv2 as loadbalancing,
aws_iam as iam,
} from 'aws-cdk-lib';
import { SecurityGroup, SubnetType } from 'aws-cdk-lib/aws-ec2';
import { Construct } from 'constructs';
Expand Down Expand Up @@ -78,6 +79,12 @@ export interface EcsFargateServiceProps {
*/
environment?: { [key: string]: string };

/**
* The ARN of the key used to encrypt the secrets
* (execution role is given permissions to access the key)
*/
secretsKmsKeyArn?: string;

}

/**
Expand Down Expand Up @@ -165,6 +172,14 @@ export class EcsFargateService extends Construct {
secrets: props.secrets,
environment: props.environment,
});

if (props.secretsKmsKeyArn) {
taskDef.addToExecutionRolePolicy(new iam.PolicyStatement({
effect: iam.Effect.ALLOW,
actions: ['kms:Decrypt'],
resources: [props.secretsKmsKeyArn],
}));
}
return taskDef;
}

Expand Down

0 comments on commit fb69d45

Please sign in to comment.