Skip to content

Commit 1140a70

Browse files
committed
removed health probe ip check for loadbalancer services
1 parent 62df911 commit 1140a70

File tree

2 files changed

+105
-827
lines changed

2 files changed

+105
-827
lines changed

tools/azure-npm-to-cilium-validator/azure-npm-to-cilium-validator.go

Lines changed: 7 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"flag"
66
"fmt"
77
"log"
8-
"net"
98
"os"
109
"strings"
1110

@@ -232,20 +231,13 @@ func checkNoServiceRisk(service *corev1.Service, policiesListAtNamespace []*netw
232231
if len(ingress.From) == 0 && len(ingress.Ports) == 0 {
233232
return true
234233
}
235-
// If the policy targets all pods (allow all) or only pods that are in the service selector, check if traffic is allowed to all the service's target ports
236-
// Note: ingress.Ports.protocol will never be nil if len(ingress.Ports) is greater than 0. It defaults to "TCP" if not set
237-
if len(ingress.Ports) > 0 && checkServiceTargetPortMatchPolicyPorts(service.Spec.Ports, ingress.Ports) {
238-
switch service.Spec.Type {
239-
// If service the service is a node port check the policy does not have from rules that could disrupt traffic
240-
case corev1.ServiceTypeNodePort:
241-
if len(ingress.From) == 0 {
242-
return true
243-
}
244-
// If the service is a load balancer check if there exists a policy in the namespace that allows 168.63.129.16 (health probe IP)
245-
case corev1.ServiceTypeLoadBalancer:
246-
if checkAPolicyAllowsHealthProbeIP(service, policiesListAtNamespace) {
247-
return true
248-
}
234+
// If there are no ingress from but there are ports in the policy; check if the service is safe
235+
if len(ingress.From) == 0 {
236+
// If the policy targets all pods (allow all) or only pods that are in the service selector, check if traffic is allowed to all the service's target ports
237+
// Note: ingress.Ports.protocol will never be nil if len(ingress.Ports) is greater than 0. It defaults to "TCP" if not set
238+
// Note: for loadbalancer services the health probe always hits the service target ports
239+
if checkServiceTargetPortMatchPolicyPorts(service.Spec.Ports, ingress.Ports) {
240+
return true
249241
}
250242
}
251243
}
@@ -341,42 +333,6 @@ func checkServiceTargetPortMatchPolicyPorts(servicePorts []corev1.ServicePort, p
341333
return true
342334
}
343335

344-
func checkAPolicyAllowsHealthProbeIP(service *corev1.Service, policiesListAtNamespace []*networkingv1.NetworkPolicy) bool {
345-
healthProbeIP := net.ParseIP("168.63.129.16")
346-
for _, policy := range policiesListAtNamespace {
347-
if checkPolicyMatchServiceLabels(service.Spec.Selector, policy.Spec.PodSelector) {
348-
for _, ingress := range policy.Spec.Ingress {
349-
for _, from := range ingress.From {
350-
// Check if the policy allows traffic from the health probe IP and there is no except
351-
// Note: ipBlock is additive cannot be AND'd with namespaceSelector or podSelector
352-
if from.IPBlock != nil && from.IPBlock.CIDR != "" {
353-
// Check if the health probe IP is blocked in the CIDR except
354-
if from.IPBlock.Except != nil {
355-
for _, except := range from.IPBlock.Except {
356-
_, excecptCidr, err := net.ParseCIDR(except)
357-
if err != nil {
358-
continue
359-
}
360-
if excecptCidr.Contains(healthProbeIP) {
361-
return false
362-
}
363-
}
364-
}
365-
_, cidr, err := net.ParseCIDR(from.IPBlock.CIDR)
366-
if err != nil {
367-
continue
368-
}
369-
if cidr.Contains(healthProbeIP) {
370-
return true
371-
}
372-
}
373-
}
374-
}
375-
}
376-
}
377-
return false
378-
}
379-
380336
func difference(slice1, slice2 []string) []string {
381337
m := make(map[string]struct{})
382338
for _, s := range slice2 {

0 commit comments

Comments
 (0)