Merge pull request #5456 from AndiDog/tls-case-insensitive-host-matching

Case-insensitive TLS host matching
This commit is contained in:
Kubernetes Prow Robot 2020-04-28 14:02:24 -07:00 committed by GitHub
commit eaf63d9da7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 2 deletions

View file

@ -1351,11 +1351,14 @@ func extractTLSSecretName(host string, ing *ingress.Ingress,
} }
// naively return Secret name from TLS spec if host name matches // naively return Secret name from TLS spec if host name matches
lowercaseHost := toLowerCaseASCII(host)
for _, tls := range ing.Spec.TLS { for _, tls := range ing.Spec.TLS {
if sets.NewString(tls.Hosts...).Has(host) { for _, tlsHost := range tls.Hosts {
if toLowerCaseASCII(tlsHost) == lowercaseHost {
return tls.SecretName return tls.SecretName
} }
} }
}
// no TLS host matching host name, try each TLS host for matching SAN or CN // no TLS host matching host name, try each TLS host for matching SAN or CN
for _, tls := range ing.Spec.TLS { for _, tls := range ing.Spec.TLS {

View file

@ -818,6 +818,33 @@ func TestExtractTLSSecretName(t *testing.T) {
}, },
"demo", "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 { for title, tc := range testCases {