From 460416e78743626016a549566f1b10aa754def8b Mon Sep 17 00:00:00 2001 From: Derek Strickland <1111455+DerekStrickland@users.noreply.github.com> Date: Wed, 26 Jan 2022 11:31:37 -0500 Subject: [PATCH] Update IsEmpty to check for pre-1.2.4 fields (#11930) --- .changelog/11902.txt | 4 +++ client/config/config.go | 5 ++- command/agent/config_test.go | 35 +++++++++++++++++++ .../client_with_basic_template.hcl | 9 +++++ .../client_with_basic_template.json | 9 +++++ 5 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 .changelog/11902.txt create mode 100644 command/agent/test-resources/client_with_basic_template.hcl create mode 100644 command/agent/test-resources/client_with_basic_template.json diff --git a/.changelog/11902.txt b/.changelog/11902.txt new file mode 100644 index 000000000..5ab055281 --- /dev/null +++ b/.changelog/11902.txt @@ -0,0 +1,4 @@ +```release-note:bug +template: Fixed a bug where client template configuration that did not include any +of the new 1.2.4 configuration options could result in none of the configuration getting set. +``` diff --git a/client/config/config.go b/client/config/config.go index 45400fcaa..9ec256eab 100644 --- a/client/config/config.go +++ b/client/config/config.go @@ -450,7 +450,10 @@ func (c *ClientTemplateConfig) IsEmpty() bool { return true } - return c.BlockQueryWaitTime == nil && + return !c.DisableSandbox && + len(c.FunctionDenylist) == 0 && + len(c.FunctionBlacklist) == 0 && + c.BlockQueryWaitTime == nil && c.BlockQueryWaitTimeHCL == "" && c.MaxStale == nil && c.MaxStaleHCL == "" && diff --git a/command/agent/config_test.go b/command/agent/config_test.go index 72aa864b3..b795f8fad 100644 --- a/command/agent/config_test.go +++ b/command/agent/config_test.go @@ -1413,6 +1413,41 @@ func TestConfig_LoadConsulTemplateConfig(t *testing.T) { require.Equal(t, 20*time.Second, *templateConfig.VaultRetry.MaxBackoff) } +func TestConfig_LoadConsulTemplateBasic(t *testing.T) { + defaultConfig := DefaultConfig() + + // hcl + agentConfig, err := LoadConfig("test-resources/client_with_basic_template.hcl") + require.NoError(t, err) + require.NotNil(t, agentConfig.Client.TemplateConfig) + + agentConfig = defaultConfig.Merge(agentConfig) + + clientAgent := Agent{config: agentConfig} + clientConfig, err := clientAgent.clientConfig() + require.NoError(t, err) + + templateConfig := clientConfig.TemplateConfig + require.NotNil(t, templateConfig) + require.True(t, templateConfig.DisableSandbox) + require.Len(t, templateConfig.FunctionDenylist, 1) + + // json + agentConfig, err = LoadConfig("test-resources/client_with_basic_template.json") + require.NoError(t, err) + + agentConfig = defaultConfig.Merge(agentConfig) + + clientAgent = Agent{config: agentConfig} + clientConfig, err = clientAgent.clientConfig() + require.NoError(t, err) + + templateConfig = clientConfig.TemplateConfig + require.NotNil(t, templateConfig) + require.True(t, templateConfig.DisableSandbox) + require.Len(t, templateConfig.FunctionDenylist, 1) +} + func TestParseMultipleIPTemplates(t *testing.T) { testCases := []struct { name string diff --git a/command/agent/test-resources/client_with_basic_template.hcl b/command/agent/test-resources/client_with_basic_template.hcl new file mode 100644 index 000000000..fc1fcb493 --- /dev/null +++ b/command/agent/test-resources/client_with_basic_template.hcl @@ -0,0 +1,9 @@ + +client { + enabled = true + + template { + disable_file_sandbox = true + function_denylist = [] + } +} diff --git a/command/agent/test-resources/client_with_basic_template.json b/command/agent/test-resources/client_with_basic_template.json new file mode 100644 index 000000000..d468d357b --- /dev/null +++ b/command/agent/test-resources/client_with_basic_template.json @@ -0,0 +1,9 @@ +{ + "client": { + "enabled": true, + "template": { + "disable_file_sandbox": true, + "function_denylist": [] + } + } +}