Skip to content

Commit 1c8b2ff

Browse files
GergMerricdeLauney
authored andcommitted
Make Envoy ALPN configurable
- Allows disabling ALPN configuration for environments where envoy should not advertise h2 support [cloudfoundry/routing-release#200] Authored-by: Greg Cobb <[email protected]>
1 parent 26ea425 commit 1c8b2ff

File tree

3 files changed

+48
-4
lines changed

3 files changed

+48
-4
lines changed

depot/containerstore/proxy_config_handler.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ type ProxyConfigHandler struct {
8383
reloadClock clock.Clock
8484

8585
adsServers []string
86+
87+
http2Enabled bool
8688
}
8789

8890
type NoopProxyConfigHandler struct{}
@@ -126,6 +128,7 @@ func NewProxyConfigHandler(
126128
reloadDuration time.Duration,
127129
reloadClock clock.Clock,
128130
adsServers []string,
131+
http2Enabled bool,
129132
) *ProxyConfigHandler {
130133
return &ProxyConfigHandler{
131134
logger: logger.Session("proxy-manager"),
@@ -137,6 +140,7 @@ func NewProxyConfigHandler(
137140
reloadDuration: reloadDuration,
138141
reloadClock: reloadClock,
139142
adsServers: adsServers,
143+
http2Enabled: http2Enabled,
140144
}
141145
}
142146

@@ -254,6 +258,7 @@ func (p *ProxyConfigHandler) writeConfig(credentials Credential, container execu
254258
adminPort,
255259
p.containerProxyRequireClientCerts,
256260
p.adsServers,
261+
p.http2Enabled,
257262
)
258263
if err != nil {
259264
return err
@@ -305,6 +310,7 @@ func generateProxyConfig(
305310
adminPort uint16,
306311
requireClientCerts bool,
307312
adsServers []string,
313+
http2Enabled bool,
308314
) (*envoy_bootstrap.Bootstrap, error) {
309315
clusters := []*envoy_cluster.Cluster{}
310316
for index, portMap := range container.Ports {
@@ -332,7 +338,7 @@ func generateProxyConfig(
332338
})
333339
}
334340

335-
listeners, err := generateListeners(container, requireClientCerts)
341+
listeners, err := generateListeners(container, requireClientCerts, http2Enabled)
336342
if err != nil {
337343
return nil, fmt.Errorf("generating listeners: %s", err)
338344
}
@@ -443,7 +449,7 @@ func writeProxyConfig(proxyConfig *envoy_bootstrap.Bootstrap, path string) error
443449
return ioutil.WriteFile(path, yamlStr, 0666)
444450
}
445451

446-
func generateListeners(container executor.Container, requireClientCerts bool) ([]*envoy_listener.Listener, error) {
452+
func generateListeners(container executor.Container, requireClientCerts, http2Enabled bool) ([]*envoy_listener.Listener, error) {
447453
listeners := []*envoy_listener.Listener{}
448454

449455
for index, portMap := range container.Ports {
@@ -463,7 +469,6 @@ func generateListeners(container executor.Container, requireClientCerts bool) ([
463469
tlsContext := &envoy_tls.DownstreamTlsContext{
464470
RequireClientCertificate: &wrappers.BoolValue{Value: requireClientCerts},
465471
CommonTlsContext: &envoy_tls.CommonTlsContext{
466-
AlpnProtocols: AlpnProtocols,
467472
TlsCertificateSdsSecretConfigs: []*envoy_tls.SdsSecretConfig{
468473
{
469474
Name: "server-cert-and-key",
@@ -480,6 +485,10 @@ func generateListeners(container executor.Container, requireClientCerts bool) ([
480485
},
481486
}
482487

488+
if http2Enabled {
489+
tlsContext.CommonTlsContext.AlpnProtocols = AlpnProtocols
490+
}
491+
483492
if requireClientCerts {
484493
tlsContext.CommonTlsContext.ValidationContextType = &envoy_tls.CommonTlsContext_ValidationContextSdsSecretConfig{
485494
ValidationContextSdsSecretConfig: &envoy_tls.SdsSecretConfig{

depot/containerstore/proxy_config_handler_test.go

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ var _ = Describe("ProxyConfigHandler", func() {
6060
containerProxyVerifySubjectAltName []string
6161
containerProxyRequireClientCerts bool
6262
adsServers []string
63+
http2Enabled bool
6364
)
6465

6566
BeforeEach(func() {
@@ -101,6 +102,7 @@ var _ = Describe("ProxyConfigHandler", func() {
101102
"10.255.217.2:15010",
102103
"10.255.217.3:15010",
103104
}
105+
http2Enabled = true
104106
})
105107

106108
JustBeforeEach(func() {
@@ -114,6 +116,7 @@ var _ = Describe("ProxyConfigHandler", func() {
114116
reloadDuration,
115117
reloadClock,
116118
adsServers,
119+
http2Enabled,
117120
)
118121
Eventually(rotatingCredChan).Should(BeSent(containerstore.Credential{
119122
Cert: "some-cert",
@@ -394,6 +397,7 @@ var _ = Describe("ProxyConfigHandler", func() {
394397
statPrefix: "0-stats",
395398
clusterName: "0-service-cluster",
396399
requireClientCertificate: false,
400+
alpnProtocols: []string{"h2,http/1.1"},
397401
}.check(proxyConfig.StaticResources.Listeners[0])
398402
})
399403
})
@@ -548,6 +552,7 @@ var _ = Describe("ProxyConfigHandler", func() {
548552
statPrefix: "0-stats",
549553
clusterName: "0-service-cluster",
550554
requireClientCertificate: true,
555+
alpnProtocols: []string{"h2,http/1.1"},
551556
}.check(proxyConfig.StaticResources.Listeners[0])
552557

553558
adsConfigSource := &envoy_core.ConfigSource{
@@ -621,6 +626,31 @@ var _ = Describe("ProxyConfigHandler", func() {
621626
})
622627
})
623628

629+
Context("when HTTP/2 is disabled", func() {
630+
BeforeEach(func() {
631+
http2Enabled = false
632+
})
633+
634+
It("creates a proxy config without ALPN for listeners", func() {
635+
err := proxyConfigHandler.Update(containerstore.Credential{Cert: "cert", Key: "key"}, container)
636+
Expect(err).NotTo(HaveOccurred())
637+
Eventually(proxyConfigFile).Should(BeAnExistingFile())
638+
639+
var proxyConfig envoy_bootstrap.Bootstrap
640+
Expect(yamlFileToProto(proxyConfigFile, &proxyConfig)).To(Succeed())
641+
642+
Expect(proxyConfig.StaticResources.Listeners).To(HaveLen(1))
643+
expectedListener{
644+
name: "listener-8080",
645+
listenPort: 61001,
646+
statPrefix: "0-stats",
647+
clusterName: "0-service-cluster",
648+
requireClientCertificate: true,
649+
alpnProtocols: nil,
650+
}.check(proxyConfig.StaticResources.Listeners[0])
651+
})
652+
})
653+
624654
Context("with multiple port mappings", func() {
625655
BeforeEach(func() {
626656
container.Ports = []executor.PortMapping{
@@ -683,6 +713,7 @@ var _ = Describe("ProxyConfigHandler", func() {
683713
statPrefix: "0-stats",
684714
clusterName: "0-service-cluster",
685715
requireClientCertificate: true,
716+
alpnProtocols: []string{"h2,http/1.1"},
686717
}.check(proxyConfig.StaticResources.Listeners[0])
687718

688719
expectedListener{
@@ -691,6 +722,7 @@ var _ = Describe("ProxyConfigHandler", func() {
691722
statPrefix: "1-stats",
692723
clusterName: "1-service-cluster",
693724
requireClientCertificate: true,
725+
alpnProtocols: []string{"h2,http/1.1"},
694726
}.check(proxyConfig.StaticResources.Listeners[1])
695727
})
696728

@@ -846,6 +878,7 @@ type expectedListener struct {
846878
statPrefix string
847879
clusterName string
848880
requireClientCertificate bool
881+
alpnProtocols []string
849882
}
850883

851884
func (l expectedListener) check(listener *envoy_listener.Listener) {
@@ -869,7 +902,7 @@ func (l expectedListener) check(listener *envoy_listener.Listener) {
869902
Expect(filterChain.TransportSocket.Name).To(Equal(l.name))
870903

871904
Expect(downstreamTlsContext.RequireClientCertificate.Value).To(Equal(l.requireClientCertificate))
872-
Expect(downstreamTlsContext.CommonTlsContext.AlpnProtocols).To(Equal([]string{"h2,http/1.1"}))
905+
Expect(downstreamTlsContext.CommonTlsContext.AlpnProtocols).To(Equal(l.alpnProtocols))
873906
Expect(downstreamTlsContext.CommonTlsContext.TlsCertificateSdsSecretConfigs).To(ConsistOf(
874907
&envoy_tls.SdsSecretConfig{
875908
Name: "server-cert-and-key",

initializer/initializer.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ type ExecutorConfig struct {
139139
PathToTLSKey string `json:"path_to_tls_key"`
140140
PostSetupHook string `json:"post_setup_hook"`
141141
PostSetupUser string `json:"post_setup_user"`
142+
ProxyEnableHttp2 bool `json:"proxy_enable_http2"`
142143
ProxyMemoryAllocationMB int `json:"proxy_memory_allocation_mb,omitempty"`
143144
ReadWorkPoolSize int `json:"read_work_pool_size,omitempty"`
144145
ReservedExpirationTime durationjson.Duration `json:"reserved_expiration_time,omitempty"`
@@ -290,6 +291,7 @@ func Initialize(logger lager.Logger, config ExecutorConfig, cellID, zone string,
290291
time.Duration(config.EnvoyConfigReloadDuration),
291292
clock,
292293
config.ContainerProxyADSServers,
294+
config.ProxyEnableHttp2,
293295
)
294296
} else {
295297
proxyConfigHandler = containerstore.NewNoopProxyConfigHandler()

0 commit comments

Comments
 (0)