Skip to content

Commit 53aeeb5

Browse files
authored
Merge pull request #9727 from hashicorp/b-empty-ingress-proxy
consul/connect: avoid NPE from unset connect gateway proxy
2 parents 5b35556 + d57b390 commit 53aeeb5

File tree

4 files changed

+34
-17
lines changed

4 files changed

+34
-17
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ IMPROVEMENTS:
66

77
BUG FIXES:
88
* consul: Fixed a bug where updating a task to include services would not work [[GH-9707](https://github.com/hashicorp/nomad/issues/9707)]
9+
* consul/connect: Fixed a bug where absent ingress envoy proxy configuration could panic client [[GH-9669](https://github.com/hashicorp/nomad/issues/9669)]
910
* template: Fixed multiple issues in template src/dest and artifact dest interpolation [[GH-9671](https://github.com/hashicorp/nomad/issues/9671)]
1011
* template: Fixed a bug where dynamic secrets did not trigger the template `change_mode` after a client restart. [[GH-9636](https://github.com/hashicorp/nomad/issues/9636)]
1112
* server: Fixed a bug where new servers may bootstrap prematurely when configured with `bootstrap_expect = 0`.

command/agent/consul/connect.go

+21-17
Original file line numberDiff line numberDiff line change
@@ -45,29 +45,33 @@ func newConnectGateway(serviceName string, connect *structs.ConsulConnect) *api.
4545
return nil
4646
}
4747

48-
proxy := connect.Gateway.Proxy
48+
var envoyConfig map[string]interface{}
4949

50-
envoyConfig := make(map[string]interface{})
50+
// Populate the envoy configuration from the gateway.proxy stanza, if
51+
// such configuration is provided.
52+
if proxy := connect.Gateway.Proxy; proxy != nil {
53+
envoyConfig = make(map[string]interface{})
5154

52-
if len(proxy.EnvoyGatewayBindAddresses) > 0 {
53-
envoyConfig["envoy_gateway_bind_addresses"] = proxy.EnvoyGatewayBindAddresses
54-
}
55+
if len(proxy.EnvoyGatewayBindAddresses) > 0 {
56+
envoyConfig["envoy_gateway_bind_addresses"] = proxy.EnvoyGatewayBindAddresses
57+
}
5558

56-
if proxy.EnvoyGatewayNoDefaultBind {
57-
envoyConfig["envoy_gateway_no_default_bind"] = true
58-
}
59+
if proxy.EnvoyGatewayNoDefaultBind {
60+
envoyConfig["envoy_gateway_no_default_bind"] = true
61+
}
5962

60-
if proxy.EnvoyGatewayBindTaggedAddresses {
61-
envoyConfig["envoy_gateway_bind_tagged_addresses"] = true
62-
}
63+
if proxy.EnvoyGatewayBindTaggedAddresses {
64+
envoyConfig["envoy_gateway_bind_tagged_addresses"] = true
65+
}
6366

64-
if proxy.ConnectTimeout != nil {
65-
envoyConfig["connect_timeout_ms"] = proxy.ConnectTimeout.Milliseconds()
66-
}
67+
if proxy.ConnectTimeout != nil {
68+
envoyConfig["connect_timeout_ms"] = proxy.ConnectTimeout.Milliseconds()
69+
}
6770

68-
if len(proxy.Config) > 0 {
69-
for k, v := range proxy.Config {
70-
envoyConfig[k] = v
71+
if len(proxy.Config) > 0 {
72+
for k, v := range proxy.Config {
73+
envoyConfig[k] = v
74+
}
7175
}
7276
}
7377

command/agent/consul/connect_test.go

+11
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,17 @@ func TestConnect_newConnectGateway(t *testing.T) {
429429
}, result)
430430
})
431431

432+
t.Run("proxy undefined", func(t *testing.T) {
433+
result := newConnectGateway("s1", &structs.ConsulConnect{
434+
Gateway: &structs.ConsulGateway{
435+
Proxy: nil,
436+
},
437+
})
438+
require.Equal(t, &api.AgentServiceConnectProxyConfig{
439+
Config: nil,
440+
}, result)
441+
})
442+
432443
t.Run("full", func(t *testing.T) {
433444
result := newConnectGateway("s1", &structs.ConsulConnect{
434445
Gateway: &structs.ConsulGateway{

nomad/structs/services.go

+1
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,7 @@ func (c *ConsulConnect) IsNative() bool {
733733
return c != nil && c.Native
734734
}
735735

736+
// IsGateway checks if the service is a Connect gateway.
736737
func (c *ConsulConnect) IsGateway() bool {
737738
return c != nil && c.Gateway != nil
738739
}

0 commit comments

Comments
 (0)