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

Check for invalid L7-ILB HTTPS configuration #877

Merged
merged 1 commit into from
Oct 25, 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
9 changes: 8 additions & 1 deletion pkg/loadbalancers/l7.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package loadbalancers
import (
"encoding/json"
"fmt"
"k8s.io/ingress-gce/pkg/flags"
"strings"

"github.com/GoogleCloudPlatform/k8s-cloud-provider/pkg/cloud/meta"
Expand Down Expand Up @@ -154,6 +155,13 @@ func (l *L7) edgeHop() error {
// Keeps track if we will "try" to setup frontend resources based on user configuration.
// If user configuration dictates we do not, then we emit an event.
willConfigureFrontend := false
sslConfigured := l.runtimeInfo.TLS != nil || l.runtimeInfo.TLSName != ""

// Check for invalid L7-ILB HTTPS config before attempting sync
if flags.F.EnableL7Ilb && utils.IsGCEL7ILBIngress(l.runtimeInfo.Ingress) && sslConfigured && l.runtimeInfo.AllowHTTP {
l.recorder.Eventf(l.runtimeInfo.Ingress, corev1.EventTypeWarning, "WillNotConfigureFrontend", "gce-internal Ingress class does not currently support both HTTP and HTTPS served on the same IP (kubernetes.io/ingress.allow-http must be false when using HTTPS).")
return fmt.Errorf("error invalid internal ingress https config")
}

if err := l.ensureComputeURLMap(); err != nil {
return err
Expand All @@ -165,7 +173,6 @@ func (l *L7) edgeHop() error {
}
}
// Defer promoting an ephemeral to a static IP until it's really needed.
sslConfigured := l.runtimeInfo.TLS != nil || l.runtimeInfo.TLSName != ""
if l.runtimeInfo.AllowHTTP && sslConfigured {
klog.V(3).Infof("checking static ip for %v", l)
if err := l.checkStaticIP(); err != nil {
Expand Down
20 changes: 20 additions & 0 deletions pkg/loadbalancers/loadbalancers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,26 @@ func TestCreateHTTPSILBLoadBalancer(t *testing.T) {
verifyHTTPSForwardingRuleAndProxyLinks(t, j, l7)
}

// Test case with HTTPS ILB Load balancer and AllowHttp set to true (not currently supported)
// Ensure should throw an error
func TestCreateHTTPSILBLoadBalancerAllowHTTP(t *testing.T) {
j := newTestJig(t)

gceUrlMap := utils.NewGCEURLMap()
gceUrlMap.DefaultBackend = &utils.ServicePort{NodePort: 31234, BackendNamer: j.namer}
gceUrlMap.PutPathRulesForHost("bar.example.com", []utils.PathRule{{Path: "/bar", Backend: utils.ServicePort{NodePort: 30000, BackendNamer: j.namer}}})
lbInfo := &L7RuntimeInfo{
AllowHTTP: true,
TLS: []*TLSCerts{createCert("key", "cert", "name")},
UrlMap: gceUrlMap,
Ingress: newILBIngress(),
}

if _, err := j.pool.Ensure(lbInfo); err == nil {
t.Fatalf("j.pool.Ensure(%v) = nil, want err", lbInfo)
}
}

func TestCreateHTTPSLoadBalancer(t *testing.T) {
// This should NOT create the forwarding rule and target proxy
// associated with the HTTP branch of this loadbalancer.
Expand Down