Skip to content

Commit

Permalink
Merge pull request #5456 from AndiDog/tls-case-insensitive-host-matching
Browse files Browse the repository at this point in the history
Case-insensitive TLS host matching
  • Loading branch information
k8s-ci-robot authored Apr 28, 2020
2 parents 7fbf497 + c775b43 commit eaf63d9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
7 changes: 5 additions & 2 deletions internal/ingress/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1351,9 +1351,12 @@ func extractTLSSecretName(host string, ing *ingress.Ingress,
}

// naively return Secret name from TLS spec if host name matches
lowercaseHost := toLowerCaseASCII(host)
for _, tls := range ing.Spec.TLS {
if sets.NewString(tls.Hosts...).Has(host) {
return tls.SecretName
for _, tlsHost := range tls.Hosts {
if toLowerCaseASCII(tlsHost) == lowercaseHost {
return tls.SecretName
}
}
}

Expand Down
27 changes: 27 additions & 0 deletions internal/ingress/controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,33 @@ func TestExtractTLSSecretName(t *testing.T) {
},
"demo",
},
"ingress tls, hosts, matching cert cn, uppercase host": {
"FOO.BAR",
&ingress.Ingress{
Ingress: networking.Ingress{
ObjectMeta: metav1.ObjectMeta{
Name: "test",
},
Spec: networking.IngressSpec{
TLS: []networking.IngressTLS{
{
Hosts: []string{"foo.bar", "example.com"},
SecretName: "demo",
},
},
Rules: []networking.IngressRule{
{
Host: "foo.bar",
},
},
},
},
},
func(string) (*ingress.SSLCert, error) {
return nil, nil
},
"demo",
},
}

for title, tc := range testCases {
Expand Down

0 comments on commit eaf63d9

Please sign in to comment.