Skip to content

Fix admission webhook host/path overlap detection not working for multiple rules #13162

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions internal/ingress/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1821,16 +1821,14 @@ func checkOverlap(ing *networking.Ingress, servers []*ingress.Server) error {
continue
}

// same ingress
// path overlap. Check if one of the ingresses has a canary annotation
isCanaryEnabled, annotationErr := parser.GetBoolAnnotation("canary", ing, canary.CanaryAnnotations.Annotations)
for _, existing := range existingIngresses {
if existing.ObjectMeta.Namespace == ing.ObjectMeta.Namespace && existing.ObjectMeta.Name == ing.ObjectMeta.Name {
return nil
// same ingress
continue
}
}

// path overlap. Check if one of the ingresses has a canary annotation
isCanaryEnabled, annotationErr := parser.GetBoolAnnotation("canary", ing, canary.CanaryAnnotations.Annotations)
for _, existing := range existingIngresses {
isExistingCanaryEnabled, existingAnnotationErr := parser.GetBoolAnnotation("canary", existing, canary.CanaryAnnotations.Annotations)

if isCanaryEnabled && isExistingCanaryEnabled {
Expand All @@ -1843,7 +1841,6 @@ func checkOverlap(ing *networking.Ingress, servers []*ingress.Server) error {
}

// no overlap
return nil
}
}

Expand Down
31 changes: 31 additions & 0 deletions test/e2e/admission/admission.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,37 @@ var _ = framework.IngressNginxDescribeSerial("[Admission] admission controller",
assert.NotNil(ginkgo.GinkgoT(), err, "creating an ingress with the same host and path should return an error")
})

ginkgo.It("should not allow overlaps of host and paths without canary annotations in any rule", func() {
host := admissionTestHost

firstIngress := framework.NewSingleIngressWithMultiplePaths(
"first-ingress",
[]string{"/safe-path-1", "/conflict-path"},
host,
f.Namespace,
framework.EchoService,
80,
nil)
_, err := f.KubeClientSet.NetworkingV1().Ingresses(f.Namespace).Create(context.TODO(), firstIngress, metav1.CreateOptions{})
assert.Nil(ginkgo.GinkgoT(), err, "creating ingress")

f.WaitForNginxServer(host,
func(server string) bool {
return strings.Contains(server, fmt.Sprintf("server_name %v", host))
})

secondIngress := framework.NewSingleIngressWithMultiplePaths(
"second-ingress",
[]string{"/safe-path-2", "/conflict-path"},
host,
f.Namespace,
framework.EchoService,
80,
nil)
_, err = f.KubeClientSet.NetworkingV1().Ingresses(f.Namespace).Create(context.TODO(), secondIngress, metav1.CreateOptions{})
assert.NotNil(ginkgo.GinkgoT(), err, "creating an ingress with the same host and path should return an error")
})

ginkgo.It("should allow overlaps of host and paths with canary annotation", func() {
host := admissionTestHost

Expand Down