From 2e1a53464283e6fb469199cdb2a8ea2ee0fa7a9d Mon Sep 17 00:00:00 2001 From: JoshVanL Date: Thu, 3 Oct 2019 16:57:54 +0100 Subject: [PATCH] The ingress shim checks certificate common names and ensures they are empty Signed-off-by: JoshVanL --- pkg/controller/ingress-shim/sync.go | 5 ++ pkg/controller/ingress-shim/sync_test.go | 62 ++++++++++++++++++++++++ 2 files changed, 67 insertions(+) diff --git a/pkg/controller/ingress-shim/sync.go b/pkg/controller/ingress-shim/sync.go index 749df8525..c428afb17 100644 --- a/pkg/controller/ingress-shim/sync.go +++ b/pkg/controller/ingress-shim/sync.go @@ -184,6 +184,7 @@ func (c *controller) buildCertificates(ctx context.Context, ing *extv1beta1.Ingr updateCrt.Spec.IssuerRef.Name = issuerName updateCrt.Spec.IssuerRef.Kind = issuerKind updateCrt.Spec.IssuerRef.Group = issuerGroup + updateCrt.Spec.CommonName = "" updateCrt.Labels = ing.Labels err = c.setIssuerSpecificConfig(updateCrt, ing, tls) if err != nil { @@ -241,6 +242,10 @@ func certNeedsUpdate(a, b *cmapi.Certificate) bool { return true } + if a.Spec.CommonName != b.Spec.CommonName { + return true + } + if len(a.Spec.DNSNames) != len(b.Spec.DNSNames) { return true } diff --git a/pkg/controller/ingress-shim/sync_test.go b/pkg/controller/ingress-shim/sync_test.go index 350d89a15..bf6637d74 100644 --- a/pkg/controller/ingress-shim/sync_test.go +++ b/pkg/controller/ingress-shim/sync_test.go @@ -802,6 +802,68 @@ func TestSync(t *testing.T) { }, }, }, + { + Name: "should update a Certificate if is contains a Common Name that is not defined on the ingress annotations", + Issuer: acmeIssuer, + IssuerLister: []runtime.Object{acmeIssuer}, + Ingress: &extv1beta1.Ingress{ + ObjectMeta: metav1.ObjectMeta{ + Name: "ingress-name", + Namespace: gen.DefaultTestNamespace, + Annotations: map[string]string{ + cmapi.IngressIssuerNameAnnotationKey: "issuer-name", + cmapi.IssuerKindAnnotationKey: "Issuer", + cmapi.IssuerGroupAnnotationKey: "cert-manager.io", + }, + UID: types.UID("ingress-name"), + }, + Spec: extv1beta1.IngressSpec{ + TLS: []extv1beta1.IngressTLS{ + { + Hosts: []string{"example.com"}, + SecretName: "example-com-tls", + }, + }, + }, + }, + CertificateLister: []runtime.Object{ + &cmapi.Certificate{ + ObjectMeta: metav1.ObjectMeta{ + Name: "example-com-tls", + Namespace: gen.DefaultTestNamespace, + OwnerReferences: buildOwnerReferences("ingress-name", gen.DefaultTestNamespace), + }, + Spec: cmapi.CertificateSpec{ + DNSNames: []string{"example.com"}, + SecretName: "example-com-tls", + CommonName: "example-common-name", + IssuerRef: cmmeta.ObjectReference{ + Name: "issuer-name", + Kind: "Issuer", + Group: "cert-manager.io", + }, + }, + }, + }, + ExpectedUpdate: []*cmapi.Certificate{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "example-com-tls", + Namespace: gen.DefaultTestNamespace, + OwnerReferences: buildOwnerReferences("ingress-name", gen.DefaultTestNamespace), + }, + Spec: cmapi.CertificateSpec{ + DNSNames: []string{"example.com"}, + SecretName: "example-com-tls", + IssuerRef: cmmeta.ObjectReference{ + Name: "issuer-name", + Kind: "Issuer", + Group: "cert-manager.io", + }, + }, + }, + }, + }, } testFn := func(test testT) func(t *testing.T) { return func(t *testing.T) {