Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

fix ingress-nginx panic when the certificate format is wrong. #7443

Merged
merged 3 commits into from
Aug 24, 2021
Merged
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
2 changes: 1 addition & 1 deletion internal/ingress/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1472,7 +1472,7 @@ func extractTLSSecretName(host string, ing *ingress.Ingress,
continue
}

if cert == nil { // for tests
if cert == nil || cert.Certificate == nil {
continue
}

Expand Down
50 changes: 50 additions & 0 deletions internal/ingress/controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"crypto/x509"
"crypto/x509/pkix"
"encoding/asn1"
"encoding/base64"
"fmt"
"io/ioutil"
"os"
Expand Down Expand Up @@ -1295,6 +1296,55 @@ func TestExtractTLSSecretName(t *testing.T) {
},
"demo",
},
"ingress tls, hosts, bad format cert, host not in tls Hosts": {
"foo1.bar",
&ingress.Ingress{
Ingress: networking.Ingress{
ObjectMeta: metav1.ObjectMeta{
Name: "test",
},
Spec: networking.IngressSpec{
TLS: []networking.IngressTLS{
{
Hosts: []string{"foo.bar"},
SecretName: "demo",
},
},
Rules: []networking.IngressRule{
{
Host: "foo.bar",
},
{
Host: "foo1.bar",
},
},
},
},
},
func(string) (*ingress.SSLCert, error) {
secretData := map[string]string{
"ca.crt": "LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUN5RENDQWJDZ0F3SUJBZ0lCQURBTkJna3Foa2lHOXcwQkFRc0ZBREFWTVJNd0VRWURWUVFERXdwcmRXSmwKY201bGRHVnpNQjRYRFRJd01EVXhOVEEzTXpJMU5sb1hEVE13TURVeE16QTNN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NRX05RNFRlQnZxWEMyUHR4REFwM19QM3QyZnRKN0w2Z1kzTkcyZUsyQTVFZG82azQtR2wzN0Zaam51NmRzc0FocVZaeld0NE9ZS3hTWWtpN003dnh5ZWtJQ091UmJ6SW5DNmhldEhtbHhyaF9ObWplMHhfY2M4V3ZkUnJYbFlpRWxnYXZCY1FtMTJ2YkxBQWlzWkFrT2Y1T3VvaEhLUmpEOGlMS1pRMXdKRHNnRmYzd1BFWGxTWkg2QkVZdS1TU0laSDNKYWVWU3llWjExdw==",
}
ca, err := base64.StdEncoding.DecodeString(secretData["ca.crt"])
if err != nil {
t.Fatalf("unexpected error decoding ca.crt: %v", err)
}
cert, err := ssl.CreateCACert(ca)
if err != nil {
t.Fatalf("unexpected error creating SSL Cert: %v", err)
}
err = ssl.ConfigureCACert("demo", ca, cert)
if err != nil {
t.Fatalf("error configuring CA certificate: %v", err)
}
cert.Name = "default-token-dn6xb"
cert.Namespace = "demo"
return cert, nil
},
"",
},
}

for title, tc := range testCases {
Expand Down