Skip to content

Commit f7d0b9e

Browse files
committed
feat: adding mTLS support on envoy upstream
1 parent 036f68f commit f7d0b9e

File tree

2 files changed

+36
-11
lines changed

2 files changed

+36
-11
lines changed

pkg/envoy/boilerplate.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,19 @@ func makeCluster(c cluster, ca string, healthCfg UpstreamHealthCheck, outlierPer
492492
},
493493
},
494494
}
495+
if c.authTLSVerifyClient == "true" {
496+
tls.Sni = c.VirtualHost
497+
tls.CommonTlsContext.TlsCertificates = []*auth.TlsCertificate{
498+
{
499+
CertificateChain: &core.DataSource{
500+
Specifier: &core.DataSource_InlineString{InlineString: c.authTLSEnvoyClientCert},
501+
},
502+
PrivateKey: &core.DataSource{
503+
Specifier: &core.DataSource_InlineString{InlineString: c.authTLSEnvoyClientKey},
504+
},
505+
},
506+
}
507+
}
495508
} else {
496509
tls = nil
497510
}

pkg/envoy/ingress_translator.go

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,17 @@ type LBHost struct {
110110
}
111111

112112
type cluster struct {
113-
Name string
114-
VirtualHost string
115-
HealthCheckPath string
116-
HealthCheckHost string // with Wildcard, the HealthCheck host can be different than the VirtualHost
117-
HttpVersion string
118-
Timeout time.Duration
119-
Hosts []LBHost
120-
authTLSSecret string // the secret name of the CA : could be "ca-secret"
121-
authTLSVerifyClient string // Verify or not the client cert (can be either true or false)
113+
Name string
114+
VirtualHost string
115+
HealthCheckPath string
116+
HealthCheckHost string // with Wildcard, the HealthCheck host can be different than the VirtualHost
117+
HttpVersion string
118+
Timeout time.Duration
119+
Hosts []LBHost
120+
authTLSSecret string // the secret name of the CA : could be "ca-secret"
121+
authTLSVerifyClient string // Verify or not the client cert (can be either true or false)
122+
authTLSEnvoyClientCert string // the envoy cert, if authTLSSecret is set, this will be used for mTLS between envoy and the backend
123+
authTLSEnvoyClientKey string // the envoy key, if authTLSSecret is set, this will be used for mTLS between envoy and the backend
122124
}
123125

124126
func (c *cluster) identity() string {
@@ -312,6 +314,13 @@ func (ing *envoyIngress) setAuthTlsSecret(version string) {
312314
func (ing *envoyIngress) setAuthTlsVerifyClient(verify string) {
313315
ing.cluster.authTLSVerifyClient = verify
314316
}
317+
func (ing *envoyIngress) setAuthTlsEnvoyClientCert(cert string) {
318+
ing.cluster.authTLSEnvoyClientCert = cert
319+
}
320+
321+
func (ing *envoyIngress) setAuthTlsEnvoyClientKey(key string) {
322+
ing.cluster.authTLSEnvoyClientKey = key
323+
}
315324

316325
// hostMatch returns true if tlsHost and ruleHost match, with wildcard support
317326
//
@@ -553,16 +562,19 @@ func translateIngresses(ingresses []*k8s.Ingress, syncSecrets bool, secrets []*v
553562
// envoyIngress.setUpstreamHttpVersion(val)
554563
// }
555564
}
556-
557565
if ingress.Annotations["yggdrasil.uswitch.com/auth-tls-secret"] != "" {
558566
val := ingress.Annotations["yggdrasil.uswitch.com/auth-tls-secret"]
559567
caSecret, err := getCaTlsSecret(ingress, secrets) // auth-tls-secret is only the name of the secret, it does not contain the namespace
560568
if err != nil {
561569
logrus.Warnf("Failed to retrive auth-tls-secret %s/%s: %s", ingress.Namespace, val, err.Error())
562570
} else {
563-
caCert := string(caSecret.Data["tls.crt"])
571+
caCert := string(caSecret.Data["ca.crt"])
572+
envoyClientCert := string(caSecret.Data["tls.crt"])
573+
envoyClientKey := string(caSecret.Data["tls.key"])
564574
envoyIngress.setAuthTlsSecret(fmt.Sprintf("%s/%s", ingress.Namespace, val))
565575
envoyIngress.vhost.TrustedCa = caCert
576+
envoyIngress.setAuthTlsEnvoyClientCert(envoyClientCert)
577+
envoyIngress.setAuthTlsEnvoyClientKey(envoyClientKey)
566578
}
567579
}
568580

0 commit comments

Comments
 (0)