Skip to content

Commit

Permalink
cloudformation: Further tighten IAM permissions.
Browse files Browse the repository at this point in the history
EC2 and ELB instances are tagged upon creation. Therefore,
ensuring that only EC2/ELB instances are deleted when they match
the Cluster API Provider AWS tag minimises privileges.

This approach cannot be used for other resources as they are tagged
after creation.

Signed-off-by: Naadir Jeewa <[email protected]>
  • Loading branch information
randomvariable committed Feb 26, 2019
1 parent 9971d8b commit 0b27511
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
1 change: 1 addition & 0 deletions pkg/cloud/aws/services/cloudformation/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ go_library(
deps = [
"//pkg/cloud/aws/services/awserrors:go_default_library",
"//pkg/cloud/aws/services/iam:go_default_library",
"//pkg/cloud/aws/tags:go_default_library",
"//vendor/github.com/aws/aws-sdk-go/aws:go_default_library",
"//vendor/github.com/aws/aws-sdk-go/service/cloudformation:go_default_library",
"//vendor/github.com/aws/aws-sdk-go/service/cloudformation/cloudformationiface:go_default_library",
Expand Down
23 changes: 21 additions & 2 deletions pkg/cloud/aws/services/cloudformation/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (

"sigs.k8s.io/cluster-api-provider-aws/pkg/cloud/aws/services/awserrors"
"sigs.k8s.io/cluster-api-provider-aws/pkg/cloud/aws/services/iam"
"sigs.k8s.io/cluster-api-provider-aws/pkg/cloud/aws/tags"
)

const (
Expand Down Expand Up @@ -180,10 +181,8 @@ func controllersPolicy(accountID string) *iam.PolicyDocument {
"ec2:ReleaseAddress",
"ec2:RevokeSecurityGroupIngress",
"ec2:RunInstances",
"ec2:TerminateInstances",
"elasticloadbalancing:CreateLoadBalancer",
"elasticloadbalancing:ConfigureHealthCheck",
"elasticloadbalancing:DeleteLoadBalancer",
"elasticloadbalancing:DescribeLoadBalancers",
"elasticloadbalancing:DescribeLoadBalancerAttributes",
"elasticloadbalancing:ModifyLoadBalancerAttributes",
Expand All @@ -203,6 +202,26 @@ func controllersPolicy(accountID string) *iam.PolicyDocument {
"StringLike": map[string]string{"iam:AWSServiceName": "elasticloadbalancing.amazonaws.com"},
},
},
{
Effect: iam.EffectAllow,
Resource: iam.Resources{"*"},
Action: iam.Actions{
"ec2:TerminateInstances",
},
Condition: iam.Conditions{
"StringEquals": map[string]string{fmt.Sprintf("ec2:ResourceTag/%s", tags.NameAWSProviderManaged): "true"},
},
},
{
Effect: iam.EffectAllow,
Resource: iam.Resources{"*"},
Action: iam.Actions{
"elasticloadbalancing:DeleteLoadBalancer",
},
Condition: iam.Conditions{
"StringEquals": map[string]string{fmt.Sprintf("elasticloadbalancing:ResourceTag/%s", tags.NameAWSProviderManaged): "true"},
},
},
{
Effect: iam.EffectAllow,
Resource: iam.Resources{fmt.Sprintf(
Expand Down

0 comments on commit 0b27511

Please sign in to comment.