Skip to content

Commit 29a6c2b

Browse files
feat(interceptor): Add possibility to skip tls verification for upstreams (#1307)
* Feat(interceptor): Add possibility to skip tls verification for upstreams Signed-off-by: Ilia Medvedev <ilia.medvedev@codefresh.io> * Update readme Signed-off-by: Ilia Medvedev <ilia.medvedev@codefresh.io> * Update CHANGELOG.md Signed-off-by: ilia-medvedev-codefresh <ilia.medvedev@codefresh.io> * run goimports Signed-off-by: Ilia Medvedev <ilia.medvedev@codefresh.io> --------- Signed-off-by: Ilia Medvedev <ilia.medvedev@codefresh.io> Signed-off-by: ilia-medvedev-codefresh <ilia.medvedev@codefresh.io>
1 parent dc863c6 commit 29a6c2b

File tree

5 files changed

+19
-11
lines changed

5 files changed

+19
-11
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ This changelog keeps track of work items that have been completed and are ready
2828
- **General**: Add configurable tracing support to the interceptor proxy ([#1021](https://github.com/kedacore/http-add-on/pull/1021))
2929
- **General**: Allow using HSO and SO with different names ([#1293](https://github.com/kedacore/http-add-on/issues/1293))
3030
- **General**: Support profiling for KEDA components ([#4789](https://github.com/kedacore/keda/issues/4789))
31-
31+
- **General**: Add possibility to skip TLS verification for upstreams in interceptor ([#1307](https://github.com/kedacore/http-add-on/pull/1307))
3232
### Improvements
3333

3434
- **General**: TODO ([#TODO](https://github.com/kedacore/http-add-on/issues/TODO))

docs/operate.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ For setting multiple TLS certs, set `KEDA_HTTP_PROXY_TLS_CERT_STORE_PATHS` with
2828
* `XYZ.crt` + `XYZ.key` - this is a convention when using Kubernetes Secrets of type tls
2929
* `XYZ.pem` + `XYZ-key.pem`
3030

31+
To disable certificate chain verification, set `KEDA_HTTP_PROXY_TLS_SKIP_VERIFY` to `false`
32+
3133
The matching between certs and requests is performed during the TLS ClientHelo message, where the SNI service name is compared to SANs provided in each cert and the first matching cert will be used for the rest of the TLS handshake.
3234
# Configuring tracing for the KEDA HTTP Add-on interceptor proxy
3335

interceptor/config/serving.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ type Serving struct {
4343
TLSKeyPath string `envconfig:"KEDA_HTTP_PROXY_TLS_KEY_PATH" default:"/certs/tls.key"`
4444
// TLSCertStorePaths is a comma separated list of paths to read the certificate/key pairs for the TLS server
4545
TLSCertStorePaths string `envconfig:"KEDA_HTTP_PROXY_TLS_CERT_STORE_PATHS" default:""`
46+
// TLSSkipVerify is a boolean flag to specify whether the interceptor should skip TLS verification for upstreams
47+
TLSSkipVerify bool `envconfig:"KEDA_HTTP_PROXY_TLS_SKIP_VERIFY" default:"false"`
4648
// TLSPort is the port that the server should serve on if TLS is enabled
4749
TLSPort int `envconfig:"KEDA_HTTP_PROXY_TLS_PORT" default:"8443"`
4850
// ProfilingAddr if not empty, pprof will be available on this address, assuming host:port here

interceptor/main.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ func main() {
192192
// start a proxy server with TLS
193193
if proxyTLSEnabled {
194194
eg.Go(func() error {
195-
proxyTLSConfig := map[string]string{"certificatePath": servingCfg.TLSCertPath, "keyPath": servingCfg.TLSKeyPath, "certstorePaths": servingCfg.TLSCertStorePaths}
195+
proxyTLSConfig := map[string]interface{}{"certificatePath": servingCfg.TLSCertPath, "keyPath": servingCfg.TLSKeyPath, "certstorePaths": servingCfg.TLSCertStorePaths, "skipVerify": servingCfg.TLSSkipVerify}
196196
proxyTLSPort := servingCfg.TLSPort
197197
k8sSharedInformerFactory.WaitForCacheSync(ctx.Done())
198198

@@ -308,12 +308,15 @@ func defaultCertPool(logger logr.Logger) *x509.CertPool {
308308

309309
// getTLSConfig creates a TLS config from KEDA_HTTP_PROXY_TLS_CERT_PATH, KEDA_HTTP_PROXY_TLS_KEY_PATH and KEDA_HTTP_PROXY_TLS_CERTSTORE_PATHS
310310
// The matching between request and certificate is performed by comparing TLS/SNI server name with x509 SANs
311-
func getTLSConfig(tlsConfig map[string]string, logger logr.Logger) (*tls.Config, error) {
312-
certPath := tlsConfig["certificatePath"]
313-
keyPath := tlsConfig["keyPath"]
314-
certStorePaths := tlsConfig["certstorePaths"]
311+
func getTLSConfig(tlsConfig map[string]interface{}, logger logr.Logger) (*tls.Config, error) {
312+
certPath, _ := tlsConfig["certificatePath"].(string)
313+
keyPath, _ := tlsConfig["keyPath"].(string)
314+
certStorePaths, _ := tlsConfig["certstorePaths"].(string)
315+
insecureSkipVerify, _ := tlsConfig["skipVerify"].(bool)
316+
315317
servingTLS := &tls.Config{
316-
RootCAs: defaultCertPool(logger),
318+
RootCAs: defaultCertPool(logger),
319+
InsecureSkipVerify: insecureSkipVerify,
317320
}
318321
var defaultCert *tls.Certificate
319322

@@ -404,7 +407,7 @@ func runProxyServer(
404407
timeouts *config.Timeouts,
405408
port int,
406409
tlsEnabled bool,
407-
tlsConfig map[string]string,
410+
tlsConfig map[string]interface{},
408411
tracingConfig *config.Tracing,
409412
) error {
410413
dialer := kedanet.NewNetDialer(timeouts.Connect, timeouts.KeepAlive)
@@ -430,6 +433,7 @@ func runProxyServer(
430433
if tlsCfg != nil {
431434
forwardingTLSCfg.RootCAs = tlsCfg.RootCAs
432435
forwardingTLSCfg.Certificates = tlsCfg.Certificates
436+
forwardingTLSCfg.InsecureSkipVerify = tlsCfg.InsecureSkipVerify
433437
}
434438

435439
upstreamHandler = newForwardingHandler(

interceptor/main_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func TestRunProxyServerCountMiddleware(t *testing.T) {
9292
timeouts,
9393
port,
9494
false,
95-
map[string]string{},
95+
map[string]interface{}{},
9696
&tracingCfg,
9797
)
9898
})
@@ -232,7 +232,7 @@ func TestRunProxyServerWithTLSCountMiddleware(t *testing.T) {
232232
timeouts,
233233
port,
234234
true,
235-
map[string]string{"certificatePath": "../certs/tls.crt", "keyPath": "../certs/tls.key"},
235+
map[string]interface{}{"certificatePath": "../certs/tls.crt", "keyPath": "../certs/tls.key", "skipVerify": true},
236236
&tracingCfg,
237237
)
238238
})
@@ -382,7 +382,7 @@ func TestRunProxyServerWithMultipleCertsTLSCountMiddleware(t *testing.T) {
382382
timeouts,
383383
port,
384384
true,
385-
map[string]string{"certstorePaths": "../certs"},
385+
map[string]interface{}{"certstorePaths": "../certs"},
386386
&tracingCfg,
387387
)
388388
})

0 commit comments

Comments
 (0)