Skip to content

Commit

Permalink
fix: ensure ingress HTTP rule exists to prevent panic (#726)
Browse files Browse the repository at this point in the history
Signed-off-by: Ali Harris <aliharriss1995@gmail.com>
Co-authored-by: Aris Boutselis <aris.boutselis@senseon.io>
  • Loading branch information
testA113 and Aris Boutselis committed Nov 3, 2023
1 parent 16b229d commit 37721b5
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions pkg/analyzer/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,26 +98,28 @@ func (IngressAnalyzer) Analyze(a common.Analyzer) ([]common.Result, error) {

// loop over rules
for _, rule := range ing.Spec.Rules {
// loop over paths
for _, path := range rule.HTTP.Paths {
_, err := a.Client.GetClient().CoreV1().Services(ing.Namespace).Get(a.Context, path.Backend.Service.Name, metav1.GetOptions{})
if err != nil {
doc := apiDoc.GetApiDocV2("spec.rules.http.paths.backend.service")

failures = append(failures, common.Failure{
Text: fmt.Sprintf("Ingress uses the service %s/%s which does not exist.", ing.Namespace, path.Backend.Service.Name),
KubernetesDoc: doc,
Sensitive: []common.Sensitive{
{
Unmasked: ing.Namespace,
Masked: util.MaskString(ing.Namespace),
// loop over HTTP paths
if rule.HTTP != nil {
for _, path := range rule.HTTP.Paths {
_, err := a.Client.GetClient().CoreV1().Services(ing.Namespace).Get(a.Context, path.Backend.Service.Name, metav1.GetOptions{})
if err != nil {
doc := apiDoc.GetApiDocV2("spec.rules.http.paths.backend.service")

failures = append(failures, common.Failure{
Text: fmt.Sprintf("Ingress uses the service %s/%s which does not exist.", ing.Namespace, path.Backend.Service.Name),
KubernetesDoc: doc,
Sensitive: []common.Sensitive{
{
Unmasked: ing.Namespace,
Masked: util.MaskString(ing.Namespace),
},
{
Unmasked: path.Backend.Service.Name,
Masked: util.MaskString(path.Backend.Service.Name),
},
},
{
Unmasked: path.Backend.Service.Name,
Masked: util.MaskString(path.Backend.Service.Name),
},
},
})
})
}
}
}
}
Expand Down

0 comments on commit 37721b5

Please sign in to comment.