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(eks): missing VPC permissions for fargate profiles #6074

Merged
merged 3 commits into from
Feb 3, 2020
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
5 changes: 5 additions & 0 deletions packages/@aws-cdk/aws-eks/lib/cluster-resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ export class ClusterResource extends Construct {
: '*'
});

this.creationRole.addToPolicy(new iam.PolicyStatement({
actions: [ 'ec2:DescribeSubnets' ],
resources: [ '*' ],
}));

this.creationRole.addToPolicy(new iam.PolicyStatement({
actions: [ 'eks:CreateCluster', 'eks:DescribeCluster', 'eks:DeleteCluster', 'eks:UpdateClusterVersion', 'eks:UpdateClusterConfig', 'eks:CreateFargateProfile' ],
resources: [ resourceArn ]
Expand Down
25 changes: 18 additions & 7 deletions packages/@aws-cdk/aws-eks/lib/fargate-cluster.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
import { Construct } from '@aws-cdk/core';
import { Cluster, ClusterOptions, CoreDnsComputeType } from './cluster';
import { FargateProfileOptions } from './fargate-profile';

/**
* Configuration props for EKS Fargate.
*/
export interface FargateClusterProps extends ClusterOptions {
/**
* Fargate Profile to create along with the cluster.
*
* @default - A profile called "default" with 'default' and 'kube-system'
* selectors will be created if this is left undefined.
*/
readonly defaultProfile?: FargateProfileOptions;
}

/**
Expand All @@ -23,11 +31,14 @@ export class FargateCluster extends Cluster {
coreDnsComputeType: props.coreDnsComputeType ?? CoreDnsComputeType.FARGATE
});

this.addFargateProfile('default', {
selectors: [
{ namespace: 'default' },
{ namespace: 'kube-system' },
]
});
this.addFargateProfile(
props.defaultProfile?.fargateProfileName ?? (props.defaultProfile ? 'custom' : 'default'),
props.defaultProfile ?? {
selectors: [
{namespace: 'default'},
{namespace: 'kube-system'},
]
}
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,11 @@
]
}
},
{
"Action": "ec2:DescribeSubnets",
"Effect": "Allow",
"Resource": "*"
},
{
"Action": [
"eks:CreateCluster",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,11 @@
]
}
},
{
"Action": "ec2:DescribeSubnets",
"Effect": "Allow",
"Resource": "*"
},
{
"Action": [
"eks:CreateCluster",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,11 @@
]
}
},
{
"Action": "ec2:DescribeSubnets",
"Effect": "Allow",
"Resource": "*"
},
{
"Action": [
"eks:CreateCluster",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,11 @@
]
}
},
{
"Action": "ec2:DescribeSubnets",
"Effect": "Allow",
"Resource": "*"
},
{
"Action": [
"eks:CreateCluster",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,11 @@
]
}
},
{
"Action": "ec2:DescribeSubnets",
"Effect": "Allow",
"Resource": "*"
},
{
"Action": [
"eks:CreateCluster",
Expand Down
5 changes: 5 additions & 0 deletions packages/@aws-cdk/aws-eks/test/integ.eks-spot.expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,11 @@
]
}
},
{
"Action": "ec2:DescribeSubnets",
"Effect": "Allow",
"Resource": "*"
},
{
"Action": [
"eks:CreateCluster",
Expand Down
10 changes: 10 additions & 0 deletions packages/@aws-cdk/aws-eks/test/test.cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,11 @@ export = {
]
}
},
{
Action: "ec2:DescribeSubnets",
Effect: "Allow",
Resource: "*",
},
{
Action: [
"eks:CreateCluster",
Expand Down Expand Up @@ -757,6 +762,11 @@ export = {
]
}
},
{
Action: "ec2:DescribeSubnets",
Effect: "Allow",
Resource: "*",
},
{
Action: [
"eks:CreateCluster",
Expand Down
69 changes: 67 additions & 2 deletions packages/@aws-cdk/aws-eks/test/test.fargate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export = {
test.done();
},

'fails if therer are no selectors or if there are more than 5'(test: Test) {
'fails if there are no selectors or if there are more than 5'(test: Test) {
// GIVEN
const stack = new Stack();
const cluster = new eks.Cluster(stack, 'MyCluster');
Expand Down Expand Up @@ -185,5 +185,70 @@ export = {
}
}));
test.done();
},

'can create FargateCluster with a custom profile'(test: Test) {
// GIVEN
const stack = new Stack();

// WHEN
new eks.FargateCluster(stack, 'FargateCluster', {
defaultProfile: {
fargateProfileName: 'my-app', selectors: [{namespace: 'foo'}, {namespace: 'bar'}]
}
});

// THEN
expect(stack).to(haveResource('Custom::AWSCDK-EKS-FargateProfile', {
Config: {
clusterName: {
Ref: "FargateCluster019F03E8"
},
fargateProfileName: "my-app",
podExecutionRoleArn: {
"Fn::GetAtt": [
"FargateClusterfargateprofilemyappPodExecutionRole875B4635",
"Arn"
]
},
selectors: [
{ namespace: "foo" },
{ namespace: "bar" }
]
}
}));
test.done();
},

'custom profile name is "custom" if no custom profile name is provided'(test: Test) {
// GIVEN
const stack = new Stack();

// WHEN
new eks.FargateCluster(stack, 'FargateCluster', {
defaultProfile: {
selectors: [{namespace: 'foo'}, {namespace: 'bar'}]
}
});

// THEN
expect(stack).to(haveResource('Custom::AWSCDK-EKS-FargateProfile', {
Config: {
clusterName: {
Ref: "FargateCluster019F03E8"
},
podExecutionRoleArn: {
"Fn::GetAtt": [
"FargateClusterfargateprofilecustomPodExecutionRoleDB415F19",
"Arn"
]
},
selectors: [
{ namespace: "foo" },
{ namespace: "bar" }
]
}
}));
test.done();
}
};
};