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 supporting secret-based and pre-shared certs at the same time #687

Merged
merged 1 commit into from
Mar 15, 2019
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
22 changes: 9 additions & 13 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -556,19 +556,15 @@ func (lbc *LoadBalancerController) toRuntimeInfo(ing *extensions.Ingress, urlMap
var tls []*loadbalancers.TLSCerts

annotations := annotations.FromIngress(ing)
// Load the TLS cert from the API Spec if it is not specified in the annotation.
// TODO: enforce this with validation.
if annotations.UseNamedTLS() == "" {
tls, err = lbc.tlsLoader.Load(ing)
if err != nil {
if apierrors.IsNotFound(err) {
// TODO: this path should be removed when external certificate managers migrate to a better solution.
const msg = "Could not find TLS certificates. Continuing setup for the load balancer to serve HTTP. Note: this behavior is deprecated and will be removed in a future version of ingress-gce"
lbc.ctx.Recorder(ing.Namespace).Eventf(ing, apiv1.EventTypeWarning, "Sync", msg)
} else {
glog.Errorf("Could not get certificates for ingress %s/%s: %v", ing.Namespace, ing.Name, err)
return nil, err
}
tls, err = lbc.tlsLoader.Load(ing)
if err != nil {
if apierrors.IsNotFound(err) {
// TODO: this path should be removed when external certificate managers migrate to a better solution.
const msg = "Could not find TLS certificates. Continuing setup for the load balancer to serve HTTP. Note: this behavior is deprecated and will be removed in a future version of ingress-gce"
lbc.ctx.Recorder(ing.Namespace).Eventf(ing, apiv1.EventTypeWarning, "Sync", msg)
} else {
glog.Errorf("Could not get certificates for ingress %s/%s: %v", ing.Namespace, ing.Name, err)
return nil, err
}
}

Expand Down
35 changes: 35 additions & 0 deletions pkg/controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ import (
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/client-go/kubernetes/fake"
"k8s.io/ingress-gce/pkg/annotations"
backendconfigclient "k8s.io/ingress-gce/pkg/backendconfig/client/clientset/versioned/fake"
"k8s.io/ingress-gce/pkg/events"
"k8s.io/ingress-gce/pkg/instances"
"k8s.io/ingress-gce/pkg/loadbalancers"
"k8s.io/ingress-gce/pkg/test"
"k8s.io/ingress-gce/pkg/tls"
"k8s.io/ingress-gce/pkg/utils"
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce"

Expand Down Expand Up @@ -350,3 +352,36 @@ func TestEnsureMCIngress(t *testing.T) {
t.Errorf("Ingress.Annotation %q = %q, want %q", igAnnotationKey, val, wantVal)
}
}

// TestToRuntimeInfoCerts asserts that both pre-shared and secret-based certs
// are included in the RuntimeInfo.
func TestToRuntimeInfoCerts(t *testing.T) {
lbc := newLoadBalancerController()
tlsCerts := []*loadbalancers.TLSCerts{&loadbalancers.TLSCerts{Key: "key", Cert: "cert", Name: "tlsCert"}}
fakeLoader := &tls.FakeTLSSecretLoader{FakeCerts: map[string]*loadbalancers.TLSCerts{"tlsCert": tlsCerts[0]}}
lbc.tlsLoader = fakeLoader
presharedCertName := "preSharedCert"
ing := &extensions.Ingress{
ObjectMeta: meta_v1.ObjectMeta{
Annotations: map[string]string{annotations.PreSharedCertKey: presharedCertName},
},
Spec: extensions.IngressSpec{
TLS: []extensions.IngressTLS{
extensions.IngressTLS{
SecretName: tlsCerts[0].Name,
},
},
},
}
urlMap := &utils.GCEURLMap{}
lbInfo, err := lbc.toRuntimeInfo(ing, urlMap)
if err != nil {
t.Fatalf("lbc.toRuntimeInfo() = err %v", err)
}
if lbInfo.TLSName != presharedCertName {
t.Errorf("lbInfo.TLSName = %v, want %v", lbInfo.TLSName, presharedCertName)
}
if len(lbInfo.TLS) != 1 || lbInfo.TLS[0] != tlsCerts[0] {
t.Errorf("lbInfo.TLS = %v, want %v", lbInfo.TLS, tlsCerts)
}
}
1 change: 1 addition & 0 deletions pkg/loadbalancers/certificates.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ func (l *L7) checkSSLCert() error {
errs = append(errs, err)
}
l.sslCerts = append(l.sslCerts, secretsSslCerts...)
glog.V(2).Infof("Using %v pre-shared certificates and %v certificates from secrets", len(preSharedSslCerts), len(secretsSslCerts))
if len(errs) > 0 {
return utils.JoinErrs(errs)
}
Expand Down