Skip to content

Commit 75c95b1

Browse files
authored
Remove inline ELB and CloudWatch policies from Cluster Role (#7603)
* remove inline elb and cloud watch policy #7139 * fixed unit tests for removing extra inline policies
1 parent f1fa4a1 commit 75c95b1

File tree

3 files changed

+1
-40
lines changed

3 files changed

+1
-40
lines changed

pkg/cfn/builder/cluster_test.go

-7
Original file line numberDiff line numberDiff line change
@@ -281,18 +281,11 @@ var _ = Describe("Cluster Template Builder", func() {
281281

282282
It("should add iam resources and policies", func() {
283283
Expect(clusterTemplate.Resources).To(HaveKey("ServiceRole"))
284-
Expect(clusterTemplate.Resources).To(HaveKey("PolicyELBPermissions"))
285-
Expect(clusterTemplate.Resources).To(HaveKey("PolicyCloudWatchMetrics"))
286284
})
287285

288286
It("should add the correct policies and references to the ServiceRole ARN", func() {
289287
Expect(clusterTemplate.Resources["ServiceRole"].Properties.ManagedPolicyArns).To(HaveLen(2))
290288
Expect(clusterTemplate.Resources["ServiceRole"].Properties.ManagedPolicyArns).To(ContainElements(makePolicyARNRef("AmazonEKSClusterPolicy"), makePolicyARNRef("AmazonEKSVPCResourceController")))
291-
292-
cwPolicy := clusterTemplate.Resources["PolicyCloudWatchMetrics"].Properties
293-
Expect(isRefTo(cwPolicy.Roles[0], "ServiceRole")).To(BeTrue())
294-
elbPolicy := clusterTemplate.Resources["PolicyELBPermissions"].Properties
295-
Expect(isRefTo(elbPolicy.Roles[0], "ServiceRole")).To(BeTrue())
296289
})
297290

298291
It("should add iam outputs", func() {

pkg/cfn/builder/iam.go

+1-7
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,7 @@ func (c *ClusterResourceSet) addResourcesForIAM() {
105105
if api.IsSetAndNonEmptyString(c.spec.IAM.ServiceRolePermissionsBoundary) {
106106
role.PermissionsBoundary = gfnt.NewString(*c.spec.IAM.ServiceRolePermissionsBoundary)
107107
}
108-
refSR := c.newResource("ServiceRole", role)
109-
c.rs.attachAllowPolicy("PolicyCloudWatchMetrics", refSR, cloudWatchMetricsStatements())
110-
// These are potentially required for creating load balancers but aren't included in the
111-
// AmazonEKSClusterPolicy
112-
// See https://docs.aws.amazon.com/elasticloadbalancing/latest/userguide/elb-api-permissions.html#required-permissions-v2
113-
// and weaveworks/eksctl#2488
114-
c.rs.attachAllowPolicy("PolicyELBPermissions", refSR, elbStatements())
108+
c.newResource("ServiceRole", role)
115109

116110
c.rs.defineOutputFromAtt(outputs.ClusterServiceRoleARN, "ServiceRole", "Arn", true, func(v string) error {
117111
c.spec.IAM.ServiceRoleARN = &v

pkg/cfn/builder/statement.go

-26
Original file line numberDiff line numberDiff line change
@@ -250,32 +250,6 @@ func loadBalancerControllerStatements() []cft.MapOfInterfaces {
250250
}
251251
}
252252

253-
func elbStatements() []cft.MapOfInterfaces {
254-
return []cft.MapOfInterfaces{
255-
{
256-
"Effect": effectAllow,
257-
"Resource": resourceAll,
258-
"Action": []string{
259-
"ec2:DescribeAccountAttributes",
260-
"ec2:DescribeAddresses",
261-
"ec2:DescribeInternetGateways",
262-
},
263-
},
264-
}
265-
}
266-
267-
func cloudWatchMetricsStatements() []cft.MapOfInterfaces {
268-
return []cft.MapOfInterfaces{
269-
{
270-
"Effect": effectAllow,
271-
"Resource": resourceAll,
272-
"Action": []string{
273-
"cloudwatch:PutMetricData",
274-
},
275-
},
276-
}
277-
}
278-
279253
func certManagerHostedZonesStatements() []cft.MapOfInterfaces {
280254
return []cft.MapOfInterfaces{
281255
{

0 commit comments

Comments
 (0)