mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-02 08:17:26 +00:00
Fix AWS NLB security group updates
This corrects a problem where valid security group ports were removed unintentionally when updating a service or when node changes occur. Fixes #60825, #64148
This commit is contained in:
parent
a3ccea9d87
commit
f052146a96
@ -569,12 +569,17 @@ func filterForIPRangeDescription(securityGroups []*ec2.SecurityGroup, lbName str
|
|||||||
response := []*ec2.SecurityGroup{}
|
response := []*ec2.SecurityGroup{}
|
||||||
clientRule := fmt.Sprintf("%s=%s", NLBClientRuleDescription, lbName)
|
clientRule := fmt.Sprintf("%s=%s", NLBClientRuleDescription, lbName)
|
||||||
healthRule := fmt.Sprintf("%s=%s", NLBHealthCheckRuleDescription, lbName)
|
healthRule := fmt.Sprintf("%s=%s", NLBHealthCheckRuleDescription, lbName)
|
||||||
|
alreadyAdded := sets.NewString()
|
||||||
for i := range securityGroups {
|
for i := range securityGroups {
|
||||||
for j := range securityGroups[i].IpPermissions {
|
for j := range securityGroups[i].IpPermissions {
|
||||||
for k := range securityGroups[i].IpPermissions[j].IpRanges {
|
for k := range securityGroups[i].IpPermissions[j].IpRanges {
|
||||||
description := aws.StringValue(securityGroups[i].IpPermissions[j].IpRanges[k].Description)
|
description := aws.StringValue(securityGroups[i].IpPermissions[j].IpRanges[k].Description)
|
||||||
if description == clientRule || description == healthRule {
|
if description == clientRule || description == healthRule {
|
||||||
|
sgIDString := aws.StringValue(securityGroups[i].GroupId)
|
||||||
|
if !alreadyAdded.Has(sgIDString) {
|
||||||
response = append(response, securityGroups[i])
|
response = append(response, securityGroups[i])
|
||||||
|
alreadyAdded.Insert(sgIDString)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -599,6 +604,7 @@ func (c *Cloud) getVpcCidrBlock() (*string, error) {
|
|||||||
// if clientTraffic is false, then only update HealthCheck rules
|
// if clientTraffic is false, then only update HealthCheck rules
|
||||||
func (c *Cloud) updateInstanceSecurityGroupsForNLBTraffic(actualGroups []*ec2.SecurityGroup, desiredSgIds []string, ports []int64, lbName string, clientCidrs []string, clientTraffic bool) error {
|
func (c *Cloud) updateInstanceSecurityGroupsForNLBTraffic(actualGroups []*ec2.SecurityGroup, desiredSgIds []string, ports []int64, lbName string, clientCidrs []string, clientTraffic bool) error {
|
||||||
|
|
||||||
|
klog.V(8).Infof("updateInstanceSecurityGroupsForNLBTraffic: actualGroups=%v, desiredSgIds=%v, ports=%v, clientTraffic=%v", actualGroups, desiredSgIds, ports, clientTraffic)
|
||||||
// Map containing the groups we want to make changes on; the ports to make
|
// Map containing the groups we want to make changes on; the ports to make
|
||||||
// changes on; and whether to add or remove it. true to add, false to remove
|
// changes on; and whether to add or remove it. true to add, false to remove
|
||||||
portChanges := map[string]map[int64]bool{}
|
portChanges := map[string]map[int64]bool{}
|
||||||
@ -653,16 +659,16 @@ func (c *Cloud) updateInstanceSecurityGroupsForNLBTraffic(actualGroups []*ec2.Se
|
|||||||
if add {
|
if add {
|
||||||
if clientTraffic {
|
if clientTraffic {
|
||||||
klog.V(2).Infof("Adding rule for client MTU discovery from the network load balancer (%s) to instances (%s)", clientCidrs, instanceSecurityGroupID)
|
klog.V(2).Infof("Adding rule for client MTU discovery from the network load balancer (%s) to instances (%s)", clientCidrs, instanceSecurityGroupID)
|
||||||
klog.V(2).Infof("Adding rule for client traffic from the network load balancer (%s) to instances (%s)", clientCidrs, instanceSecurityGroupID)
|
klog.V(2).Infof("Adding rule for client traffic from the network load balancer (%s) to instances (%s), port (%v)", clientCidrs, instanceSecurityGroupID, port)
|
||||||
} else {
|
} else {
|
||||||
klog.V(2).Infof("Adding rule for health check traffic from the network load balancer (%s) to instances (%s)", clientCidrs, instanceSecurityGroupID)
|
klog.V(2).Infof("Adding rule for health check traffic from the network load balancer (%s) to instances (%s), port (%v)", clientCidrs, instanceSecurityGroupID, port)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if clientTraffic {
|
if clientTraffic {
|
||||||
klog.V(2).Infof("Removing rule for client MTU discovery from the network load balancer (%s) to instances (%s)", clientCidrs, instanceSecurityGroupID)
|
klog.V(2).Infof("Removing rule for client MTU discovery from the network load balancer (%s) to instances (%s)", clientCidrs, instanceSecurityGroupID)
|
||||||
klog.V(2).Infof("Removing rule for client traffic from the network load balancer (%s) to instance (%s)", clientCidrs, instanceSecurityGroupID)
|
klog.V(2).Infof("Removing rule for client traffic from the network load balancer (%s) to instance (%s), port (%v)", clientCidrs, instanceSecurityGroupID, port)
|
||||||
}
|
}
|
||||||
klog.V(2).Infof("Removing rule for health check traffic from the network load balancer (%s) to instance (%s)", clientCidrs, instanceSecurityGroupID)
|
klog.V(2).Infof("Removing rule for health check traffic from the network load balancer (%s) to instance (%s), port (%v)", clientCidrs, instanceSecurityGroupID, port)
|
||||||
}
|
}
|
||||||
|
|
||||||
if clientTraffic {
|
if clientTraffic {
|
||||||
|
Loading…
Reference in New Issue
Block a user