Skip to content

Commit

Permalink
ELB for API Server to use separate security group
Browse files Browse the repository at this point in the history
  • Loading branch information
aaroniscode authored and randomvariable committed Jan 10, 2020
1 parent 45f191c commit 0bb9b79
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 1 deletion.
3 changes: 3 additions & 0 deletions api/v1alpha2/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,9 @@ var (
// SecurityGroupControlPlane defines a Kubernetes control plane node role
SecurityGroupControlPlane = SecurityGroupRole("controlplane")

// SecurityGroupAPIServerLB defines a Kubernetes API Server Load Balancer role
SecurityGroupAPIServerLB = SecurityGroupRole("apiserver-lb")

// SecurityGroupLB defines a container for the cloud provider to inject its load balancer ingress rules
SecurityGroupLB = SecurityGroupRole("lb")
)
Expand Down
11 changes: 11 additions & 0 deletions pkg/cloud/services/ec2/securitygroups.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ func (s *Service) reconcileSecurityGroups() error {
// Declare all security group roles that the reconcile loop takes care of.
roles := []infrav1.SecurityGroupRole{
infrav1.SecurityGroupBastion,
infrav1.SecurityGroupAPIServerLB,
infrav1.SecurityGroupLB,
infrav1.SecurityGroupControlPlane,
infrav1.SecurityGroupNode,
Expand Down Expand Up @@ -458,6 +459,16 @@ func (s *Service) getSecurityGroupIngressRules(role infrav1.SecurityGroupRole) (
},
},
}, nil
case infrav1.SecurityGroupAPIServerLB:
return infrav1.IngressRules{
{
Description: "Kubernetes API",
Protocol: infrav1.SecurityGroupProtocolTCP,
FromPort: s.scope.APIServerPort(),
ToPort: s.scope.APIServerPort(),
CidrBlocks: []string{anyIPv4CidrBlock},
},
}, nil
case infrav1.SecurityGroupLB:
// We hand this group off to the in-cluster cloud provider, so these rules aren't used
return infrav1.IngressRules{}, nil
Expand Down
35 changes: 35 additions & 0 deletions pkg/cloud/services/ec2/securitygroups_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,41 @@ func TestReconcileSecurityGroups(t *testing.T) {

////////////////////////

securityGroupAPIServerLb := m.CreateSecurityGroup(gomock.Eq(&ec2.CreateSecurityGroupInput{
VpcId: aws.String("vpc-securitygroups"),
GroupName: aws.String("test-cluster-apiserver-lb"),
Description: aws.String("Kubernetes cluster test-cluster: apiserver-lb"),
})).
Return(&ec2.CreateSecurityGroupOutput{GroupId: aws.String("sg-apiserver-lb")}, nil)

m.CreateTags(matchesTags(&ec2.CreateTagsInput{
Resources: []*string{aws.String("sg-apiserver-lb")},
Tags: []*ec2.Tag{
{
Key: aws.String("sigs.k8s.io/cluster-api-provider-aws/cluster/test-cluster"),
Value: aws.String("owned"),
},
{
Key: aws.String("sigs.k8s.io/cluster-api-provider-aws/role"),
Value: aws.String("apiserver-lb"),
},
{
Key: aws.String("Name"),
Value: aws.String("test-cluster-apiserver-lb"),
},
},
})).
Return(nil, nil).
After(securityGroupAPIServerLb)

m.AuthorizeSecurityGroupIngress(gomock.AssignableToTypeOf(&ec2.AuthorizeSecurityGroupIngressInput{
GroupId: aws.String("sg-apiserver-lb"),
})).
Return(&ec2.AuthorizeSecurityGroupIngressOutput{}, nil).
After(securityGroupAPIServerLb)

////////////////////////

securityGroupLb := m.CreateSecurityGroup(gomock.Eq(&ec2.CreateSecurityGroupInput{
VpcId: aws.String("vpc-securitygroups"),
GroupName: aws.String("test-cluster-lb"),
Expand Down
2 changes: 1 addition & 1 deletion pkg/cloud/services/elb/loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ func (s *Service) getAPIServerClassicELBSpec() (*infrav1.ClassicELB, error) {
HealthyThreshold: 5,
UnhealthyThreshold: 3,
},
SecurityGroupIDs: []string{s.scope.SecurityGroups()[infrav1.SecurityGroupControlPlane].ID},
SecurityGroupIDs: []string{s.scope.SecurityGroups()[infrav1.SecurityGroupAPIServerLB].ID},
Attributes: infrav1.ClassicELBAttributes{
IdleTimeout: 10 * time.Minute,
},
Expand Down

0 comments on commit 0bb9b79

Please sign in to comment.