Skip to content

Commit 37ce4ee

Browse files
r4f4k8s-infra-cherrypick-robot
authored andcommitted
🐛 fix: create ingress rules for all load balancers
Ingress rules from both primary and secondary load balancers must be taken into account.
1 parent 4e23e8c commit 37ce4ee

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

pkg/cloud/services/securitygroup/securitygroups.go

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -660,10 +660,15 @@ func (s *Service) getSecurityGroupIngressRules(role infrav1.SecurityGroupRole) (
660660
rulesToApply := customIngressRules.Difference(kubeletRules)
661661
return append(kubeletRules, rulesToApply...), nil
662662
case infrav1.SecurityGroupLB:
663+
rules := infrav1.IngressRules{}
664+
allowedNLBTraffic := false
663665
// We hand this group off to the in-cluster cloud provider, so these rules aren't used
664666
// Except if the load balancer type is NLB, and we have an AWS Cluster in which case we
665667
// need to open port 6443 to the NLB traffic and health check inside the VPC.
666-
if s.scope.ControlPlaneLoadBalancer() != nil && s.scope.ControlPlaneLoadBalancer().LoadBalancerType == infrav1.LoadBalancerTypeNLB {
668+
for _, lb := range s.scope.ControlPlaneLoadBalancers() {
669+
if lb == nil || lb.LoadBalancerType != infrav1.LoadBalancerTypeNLB {
670+
continue
671+
}
667672
var (
668673
ipv4CidrBlocks []string
669674
ipv6CidrBlocks []string
@@ -673,25 +678,26 @@ func (s *Service) getSecurityGroupIngressRules(role infrav1.SecurityGroupRole) (
673678
if s.scope.VPC().IsIPv6Enabled() {
674679
ipv6CidrBlocks = []string{s.scope.VPC().IPv6.CidrBlock}
675680
}
676-
if s.scope.ControlPlaneLoadBalancer().PreserveClientIP {
681+
if lb.PreserveClientIP {
677682
ipv4CidrBlocks = []string{services.AnyIPv4CidrBlock}
678683
if s.scope.VPC().IsIPv6Enabled() {
679684
ipv6CidrBlocks = []string{services.AnyIPv6CidrBlock}
680685
}
681686
}
682687

683-
rules := infrav1.IngressRules{
684-
{
688+
if !allowedNLBTraffic {
689+
rules = append(rules, infrav1.IngressRule{
685690
Description: "Allow NLB traffic to the control plane instances.",
686691
Protocol: infrav1.SecurityGroupProtocolTCP,
687692
FromPort: int64(s.scope.APIServerPort()),
688693
ToPort: int64(s.scope.APIServerPort()),
689694
CidrBlocks: ipv4CidrBlocks,
690695
IPv6CidrBlocks: ipv6CidrBlocks,
691-
},
696+
})
697+
allowedNLBTraffic = true
692698
}
693699

694-
for _, ln := range s.scope.ControlPlaneLoadBalancer().AdditionalListeners {
700+
for _, ln := range lb.AdditionalListeners {
695701
rules = append(rules, infrav1.IngressRule{
696702
Description: fmt.Sprintf("Allow NLB traffic to the control plane instances on port %d.", ln.Port),
697703
Protocol: infrav1.SecurityGroupProtocolTCP,
@@ -701,10 +707,8 @@ func (s *Service) getSecurityGroupIngressRules(role infrav1.SecurityGroupRole) (
701707
IPv6CidrBlocks: ipv6CidrBlocks,
702708
})
703709
}
704-
705-
return rules, nil
706710
}
707-
return infrav1.IngressRules{}, nil
711+
return rules, nil
708712
}
709713

710714
return nil, errors.Errorf("Cannot determine ingress rules for unknown security group role %q", role)
@@ -915,8 +919,14 @@ func (s *Service) getIngressRulesToAllowKubeletToAccessTheControlPlaneLB() infra
915919
// getControlPlaneLBIngressRules returns the ingress rules for the control plane LB.
916920
// We allow all traffic when no other rules are defined.
917921
func (s *Service) getControlPlaneLBIngressRules() infrav1.IngressRules {
918-
if s.scope.ControlPlaneLoadBalancer() != nil && len(s.scope.ControlPlaneLoadBalancer().IngressRules) > 0 {
919-
return s.scope.ControlPlaneLoadBalancer().IngressRules
922+
ingressRules := infrav1.IngressRules{}
923+
for _, lb := range s.scope.ControlPlaneLoadBalancers() {
924+
if lb != nil && len(lb.IngressRules) > 0 {
925+
ingressRules = append(ingressRules, lb.IngressRules...)
926+
}
927+
}
928+
if len(ingressRules) > 0 {
929+
return ingressRules
920930
}
921931

922932
// If no custom ingress rules have been defined we allow all traffic so that the MC can access the WC API

0 commit comments

Comments
 (0)