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

allow multiple certificates #1029

Closed
wants to merge 1 commit into from
Closed
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
36 changes: 28 additions & 8 deletions pkg/converters/gateway/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ package gateway

import (
"fmt"
"regexp"
"sort"
"strconv"
"strings"

api "k8s.io/api/core/v1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -451,12 +453,32 @@ func (c *converter) applyCertRef(source *Source, listener *gatewayv1alpha2.Liste
source, listener.Name)
return
}
// TODO Support more certificates
if len(certRefs) > 1 {
err := fmt.Errorf("listener currently supports only the first referenced certificate")
c.logger.Warn("skipping one or more certificate references on %s listener '%s': %s",
source, listener.Name, err)
// iterate over all certRefs
for _, certRef := range certRefs {
crtFile, err := c.readCertRef(source.namespace, certRef)
if err != nil {
c.logger.Warn("skipping certificate reference on %s listener '%s': %s",
source, listener.Name, err)
return
}
// in crtFile.CommonName replace wildcards * with common regex wildcard .*
crtFilePattern := strings.ReplaceAll(crtFile.CommonName, "*", ".*")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd use HasPrefix("*.") and, if true, use the resulting of a TrimPrefix("*.") into a HasSuffix() instead of parse and match a regex on every iteration. This is the hot path of a cluster with dozens of thousands of httproutes, so we want all the processing to be as fast as possible.

for _, host := range hosts {

// if host.TLS.TLSCommonName matches regex patter crtFilePattern
if ok, _ := regexp.MatchString(crtFilePattern, host.Hostname); ok {
if host.TLS.TLSHash != "" && host.TLS.TLSHash != crtFile.SHA1Hash {
c.logger.Warn("skipping certificate reference on %s listener '%s' for hostname '%s': a TLS certificate was already assigned",
source, listener.Name, host.Hostname)
continue
}
host.TLS.TLSCommonName = crtFile.CommonName
host.TLS.TLSFilename = crtFile.Filename
host.TLS.TLSHash = crtFile.SHA1Hash
}
}
}
// Use first certificate to fix all missing hosts (legacy behavior)
certRef := certRefs[0]
crtFile, err := c.readCertRef(source.namespace, certRef)
if err != nil {
Expand All @@ -465,9 +487,7 @@ func (c *converter) applyCertRef(source *Source, listener *gatewayv1alpha2.Liste
return
}
for _, host := range hosts {
if host.TLS.TLSHash != "" && host.TLS.TLSHash != crtFile.SHA1Hash {
c.logger.Warn("skipping certificate reference on %s listener '%s' for hostname '%s': a TLS certificate was already assigned",
source, listener.Name, host.Hostname)
if host.TLS.TLSHash != "" {
continue
}
host.TLS.TLSCommonName = crtFile.CommonName
Expand Down
Loading