@@ -85,14 +85,14 @@ func getEndportNetworkPolicies(policiesByNamespace map[string][]*networkingv1.Ne
8585 for _ , policy := range policies {
8686 // Check the ingress field for endport
8787 for _ , ingress := range policy .Spec .Ingress {
88- foundEndPort := checkEndportInPolicyRules (& ingress .Ports )
88+ foundEndPort := checkEndportInPolicyRules (ingress .Ports )
8989 if foundEndPort {
9090 ingressPoliciesWithEndport = append (ingressPoliciesWithEndport , fmt .Sprintf ("%s/%s" , namespace , policy .Name ))
9191 break
9292 }
9393 }
9494 for _ , egress := range policy .Spec .Egress {
95- foundEndPort := checkEndportInPolicyRules (& egress .Ports )
95+ foundEndPort := checkEndportInPolicyRules (egress .Ports )
9696 if foundEndPort {
9797 egressPoliciesWithEndport = append (egressPoliciesWithEndport , fmt .Sprintf ("%s/%s" , namespace , policy .Name ))
9898 break
@@ -103,8 +103,8 @@ func getEndportNetworkPolicies(policiesByNamespace map[string][]*networkingv1.Ne
103103 return ingressPoliciesWithEndport , egressPoliciesWithEndport
104104}
105105
106- func checkEndportInPolicyRules (ports * []networkingv1.NetworkPolicyPort ) bool {
107- for _ , port := range * ports {
106+ func checkEndportInPolicyRules (ports []networkingv1.NetworkPolicyPort ) bool {
107+ for _ , port := range ports {
108108 if port .EndPort != nil {
109109 return true
110110 }
@@ -117,15 +117,15 @@ func getCIDRNetworkPolicies(policiesByNamespace map[string][]*networkingv1.Netwo
117117 for _ , policy := range policies {
118118 // Check the ingress field for cidr
119119 for _ , ingress := range policy .Spec .Ingress {
120- foundCIDRIngress := checkCIDRInPolicyRules (& ingress .From )
120+ foundCIDRIngress := checkCIDRInPolicyRules (ingress .From )
121121 if foundCIDRIngress {
122122 ingressPoliciesWithCIDR = append (ingressPoliciesWithCIDR , fmt .Sprintf ("%s/%s" , namespace , policy .Name ))
123123 break
124124 }
125125 }
126126 // Check the egress field for cidr
127127 for _ , egress := range policy .Spec .Egress {
128- foundCIDREgress := checkCIDRInPolicyRules (& egress .To )
128+ foundCIDREgress := checkCIDRInPolicyRules (egress .To )
129129 if foundCIDREgress {
130130 egressPoliciesWithCIDR = append (egressPoliciesWithCIDR , fmt .Sprintf ("%s/%s" , namespace , policy .Name ))
131131 break
@@ -137,8 +137,8 @@ func getCIDRNetworkPolicies(policiesByNamespace map[string][]*networkingv1.Netwo
137137}
138138
139139// Check for CIDR in ingress or egress rules
140- func checkCIDRInPolicyRules (rules * []networkingv1.NetworkPolicyPeer ) bool {
141- for _ , rule := range * rules {
140+ func checkCIDRInPolicyRules (rules []networkingv1.NetworkPolicyPeer ) bool {
141+ for _ , rule := range rules {
142142 if rule .IPBlock != nil && rule .IPBlock .CIDR != "" {
143143 return true
144144 }
@@ -232,15 +232,15 @@ func checkServiceRisk(service *corev1.Service, policiesListAtNamespace []*networ
232232 // Check if there is an allow all ingress policy that matches labels the service is safe
233233 if len (ingress .From ) == 0 && len (ingress .Ports ) == 0 {
234234 // Check if there is an allow all ingress policy with empty selectors or matching service labels as the policy allows all services in the namespace
235- if checkPolicySelectorsAreEmpty (& policy .Spec .PodSelector ) || checkPolicyMatchServiceLabels (service .Spec .Selector , policy .Spec .PodSelector .MatchLabels ) {
235+ if checkPolicySelectorsAreEmpty (policy .Spec .PodSelector ) || checkPolicyMatchServiceLabels (service .Spec .Selector , policy .Spec .PodSelector .MatchLabels ) {
236236 return true
237237 }
238238 }
239239 // If there are no ingress from but there are ports in the policy; check if the service is safe
240240 if len (ingress .From ) == 0 && len (ingress .Ports ) > 0 {
241241 // 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
242- if checkPolicySelectorsAreEmpty (& policy .Spec .PodSelector ) || checkPolicyMatchServiceLabels (service .Spec .Selector , policy .Spec .PodSelector .MatchLabels ) {
243- if checkServiceTargetPortMatchPolicyPorts (& service .Spec .Ports , & ingress .Ports ) {
242+ if checkPolicySelectorsAreEmpty (policy .Spec .PodSelector ) || checkPolicyMatchServiceLabels (service .Spec .Selector , policy .Spec .PodSelector .MatchLabels ) {
243+ if checkServiceTargetPortMatchPolicyPorts (service .Spec .Ports , ingress .Ports ) {
244244 return true
245245 }
246246 }
@@ -250,7 +250,7 @@ func checkServiceRisk(service *corev1.Service, policiesListAtNamespace []*networ
250250 return false
251251}
252252
253- func checkPolicySelectorsAreEmpty (podSelector * metav1.LabelSelector ) bool {
253+ func checkPolicySelectorsAreEmpty (podSelector metav1.LabelSelector ) bool {
254254 return len (podSelector .MatchLabels ) == 0 && len (podSelector .MatchExpressions ) == 0
255255}
256256
@@ -277,21 +277,21 @@ func checkPolicyMatchServiceLabels(serviceLabels, policyLabels map[string]string
277277 return true
278278}
279279
280- func checkServiceTargetPortMatchPolicyPorts (servicePorts * []corev1.ServicePort , policyPorts * []networkingv1.NetworkPolicyPort ) bool {
280+ func checkServiceTargetPortMatchPolicyPorts (servicePorts []corev1.ServicePort , policyPorts []networkingv1.NetworkPolicyPort ) bool {
281281 // If the service has no ports then it is at risk
282- if len (* servicePorts ) == 0 {
282+ if len (servicePorts ) == 0 {
283283 return false
284284 }
285285
286- for _ , servicePort := range * servicePorts {
286+ for _ , servicePort := range servicePorts {
287287 // If the target port is a string then it is a named port and service is at risk
288288 if servicePort .TargetPort .Type == intstr .String {
289289 return false
290290 }
291291
292292 // Check if all the services target ports are in the policies ingress ports
293293 matchedserviceTargetPortToPolicyPort := false
294- for _ , policyPort := range * policyPorts {
294+ for _ , policyPort := range policyPorts {
295295 // Check if the policys port and protocol exists
296296 if policyPort .Port == nil && policyPort .Protocol == nil {
297297 return false
0 commit comments