Skip to content
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
156 changes: 155 additions & 1 deletion pkg/cfn/builder/iam_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,8 @@ var _ = Describe("template builder for IAM", func() {
"Fn::Sub": "arn:${AWS::Partition}:iam::aws:policy/AmazonEC2ContainerRegistryPowerUser"
}
]`))

Expect(t).To(HaveOutputWithValue("Role1", `{ "Fn::GetAtt": "Role1.Arn" }`))
Expect(t).To(HaveResourceWithPropertyValue("PolicyEBSCSIController", "PolicyDocument", expectedEbsPolicyDocument))
})

It("can parse an iamserviceaccount addon template", func() {
Expand Down Expand Up @@ -465,3 +465,157 @@ const expectedAssumeRolePolicyDocument = `{
],
"Version": "2012-10-17"
}`

const expectedEbsPolicyDocument = `{
"Statement": [
{
"Action": [
"ec2:CreateSnapshot",
"ec2:AttachVolume",
"ec2:DetachVolume",
"ec2:ModifyVolume",
"ec2:DescribeAvailabilityZones",
"ec2:DescribeInstances",
"ec2:DescribeSnapshots",
"ec2:DescribeTags",
"ec2:DescribeVolumes",
"ec2:DescribeVolumesModifications"
],
"Effect": "Allow",
"Resource": "*"
},
{
"Action": [
"ec2:CreateTags"
],
"Condition": {
"StringEquals": {
"ec2:CreateAction": [
"CreateVolume",
"CreateSnapshot"
]
}
},
"Effect": "Allow",
"Resource": [
{
"Fn::Sub": "arn:${AWS::Partition}:ec2:*:*:volume/*"
},
{
"Fn::Sub": "arn:${AWS::Partition}:ec2:*:*:snapshot/*"
}
]
},
{
"Action": [
"ec2:DeleteTags"
],
"Effect": "Allow",
"Resource": [
{
"Fn::Sub": "arn:${AWS::Partition}:ec2:*:*:volume/*"
},
{
"Fn::Sub": "arn:${AWS::Partition}:ec2:*:*:snapshot/*"
}
]
},
{
"Action": [
"ec2:CreateVolume"
],
"Condition": {
"StringLike": {
"aws:RequestTag/ebs.csi.aws.com/cluster": "true"
}
},
"Effect": "Allow",
"Resource": "*"
},
{
"Action": [
"ec2:CreateVolume"
],
"Condition": {
"StringLike": {
"aws:RequestTag/CSIVolumeName": "*"
}
},
"Effect": "Allow",
"Resource": "*"
},
{
"Action": [
"ec2:CreateVolume"
],
"Condition": {
"StringLike": {
"aws:RequestTag/kubernetes.io/cluster/*": "owned"
}
},
"Effect": "Allow",
"Resource": "*"
},
{
"Action": [
"ec2:DeleteVolume"
],
"Condition": {
"StringLike": {
"ec2:ResourceTag/ebs.csi.aws.com/cluster": "true"
}
},
"Effect": "Allow",
"Resource": "*"
},
{
"Action": [
"ec2:DeleteVolume"
],
"Condition": {
"StringLike": {
"ec2:ResourceTag/CSIVolumeName": "*"
}
},
"Effect": "Allow",
"Resource": "*"
},
{
"Action": [
"ec2:DeleteVolume"
],
"Condition": {
"StringLike": {
"ec2:ResourceTag/kubernetes.io/cluster/*": "owned"
}
},
"Effect": "Allow",
"Resource": "*"
},
{
"Action": [
"ec2:DeleteSnapshot"
],
"Condition": {
"StringLike": {
"ec2:ResourceTag/CSIVolumeSnapshotName": "*"
}
},
"Effect": "Allow",
"Resource": "*"
},
{
"Action": [
"ec2:DeleteSnapshot"
],
"Condition": {
"StringLike": {
"ec2:ResourceTag/ebs.csi.aws.com/cluster": "true"
}
},
"Effect": "Allow",
"Resource": "*"
}
],
"Version": "2012-10-17"
}`
15 changes: 8 additions & 7 deletions pkg/cfn/builder/statement.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package builder

import (
cft "github.com/weaveworks/eksctl/pkg/cfn/template"
gfnt "github.com/weaveworks/goformation/v4/cloudformation/types"

cft "github.com/weaveworks/eksctl/pkg/cfn/template"
)

const (
Expand Down Expand Up @@ -319,9 +320,9 @@ func ebsStatements() []cft.MapOfInterfaces {
"Action": []string{
"ec2:CreateTags",
},
"Resource": []string{
"arn:aws:ec2:*:*:volume/*",
"arn:aws:ec2:*:*:snapshot/*",
"Resource": []*gfnt.Value{
addARNPartitionPrefix("ec2:*:*:volume/*"),
addARNPartitionPrefix("ec2:*:*:snapshot/*"),
},
"Condition": cft.MapOfInterfaces{
"StringEquals": cft.MapOfInterfaces{
Expand All @@ -337,9 +338,9 @@ func ebsStatements() []cft.MapOfInterfaces {
"Action": []string{
"ec2:DeleteTags",
},
"Resource": []string{
"arn:aws:ec2:*:*:volume/*",
"arn:aws:ec2:*:*:snapshot/*",
"Resource": []*gfnt.Value{
addARNPartitionPrefix("ec2:*:*:volume/*"),
addARNPartitionPrefix("ec2:*:*:snapshot/*"),
},
},
{
Expand Down