Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

consul-template: revert function_denylist logic #12071

Merged
merged 3 commits into from
Apr 18, 2022

Conversation

DerekStrickland
Copy link
Contributor

@DerekStrickland DerekStrickland commented Feb 15, 2022

Closes #11923

This PR fixes a regression that was introduced in 1.2.4 around the Consul Client Template configuration. The changes in that release erroneously merged user configuration with the default configuration for Consul Template. This resulted in a situation where the user could never override the default function deny list. The default FunctionDenylist values should only be applied if the user does not specify that field in their config.

@DerekStrickland DerekStrickland self-assigned this Feb 15, 2022
@vercel vercel bot temporarily deployed to Preview – nomad February 27, 2022 11:37 Inactive
@vercel vercel bot temporarily deployed to Preview – nomad February 27, 2022 11:43 Inactive
@vercel vercel bot temporarily deployed to Preview – nomad February 27, 2022 12:43 Inactive
@vercel vercel bot temporarily deployed to Preview – nomad February 28, 2022 22:10 Inactive
@vercel vercel bot temporarily deployed to Preview – nomad March 1, 2022 18:56 Inactive
@vercel vercel bot temporarily deployed to Preview – nomad March 1, 2022 21:26 Inactive
@DerekStrickland DerekStrickland changed the title [WIP] consul-template: maintain backwards compatibility during agent config parsing consul-template: replace function_denylist instead of append Mar 2, 2022
@DerekStrickland DerekStrickland changed the title consul-template: replace function_denylist instead of append consul-template: replace function_denylist instead of append during config parsing Mar 2, 2022
@DerekStrickland DerekStrickland marked this pull request as ready for review March 2, 2022 09:46
@DerekStrickland DerekStrickland added this to the 1.3.0 milestone Mar 2, 2022
"test-resources/client_with_function_denylist_empty_string.hcl",
&client.ClientTemplateConfig{
DisableSandbox: true,
FunctionDenylist: []string{""},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels like a bug to me: when would we ever want this to be the result after a merged configuration? Are we validating it elsewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it probably is, and I think you commented on the issue about that. Unfortunately, I pulled old code and confirmed that this currently does not fail validation. I added that comment to the issue thread as well.

My two thoughts other than continuing to allow this are either:

  • Remove this check and open an issue to validate empty strings (or remove them?)
  • Update this PR to validate empty strings (or remove them?)

Thoughts?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say let's fix this issue once and for all here instead of trying to do it in another issue and having to touch this code again. There are two issues in #11923, but we're really only discussing one of them.

This is the JSON client configuration block from #11923 (comment):

"template": {
  "function_denylist": [
    ""
  ]
}

This is an operator error: we should either correct it silently or return an error on startup. It's not clear to me at any point in the discussion in #11923 whether this configuration actually worked prior to 1.2.4. Generally speaking we don't silently correct things in the configuration, so my take is that this should blow up so the operator can fix their configuration. Especially because this is a security-related configuration.

The second issue is whether the configuration is being merged correctly with the defaults when we're done. It's not clear to me that the merging bug is a problem at all if the configuration were:

"template": {
  "function_denylist": []
}

Because in that scenario the configuration is an empty slice and there's nothing to iterate over during the merge.

Comment on lines -408 to -431
// Maintain backward compatibility for older clients
if len(b.FunctionBlacklist) > 0 {
for _, fn := range b.FunctionBlacklist {
if !helper.SliceStringContains(result.FunctionBlacklist, fn) {
result.FunctionBlacklist = append(result.FunctionBlacklist, fn)
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we only ever call Merge when merging onto the default configuration? If not, we're potentially dropping the merged-onto result by doing this, and it doesn't seem to be protecting us from the [""] case (see the test below).

.changelog/12071.txt Outdated Show resolved Hide resolved
@DerekStrickland DerekStrickland changed the title consul-template: replace function_denylist instead of append during config parsing consul-template: revert function_denylist logic Mar 18, 2022
@DerekStrickland DerekStrickland changed the title consul-template: revert function_denylist logic [WIP] consul-template: revert function_denylist logic Mar 28, 2022
@shoenig shoenig self-assigned this Apr 12, 2022
@vercel vercel bot temporarily deployed to Preview – nomad April 15, 2022 12:26 Inactive
@DerekStrickland DerekStrickland changed the title [WIP] consul-template: revert function_denylist logic consul-template: revert function_denylist logic Apr 15, 2022
@DerekStrickland DerekStrickland marked this pull request as ready for review April 15, 2022 12:32
@shoenig
Copy link
Member

shoenig commented Apr 15, 2022

@DerekStrickland just double checking I understand - are these all true?

  • this is just a reversion of trying to merge function_denylist
  • merging function_denylist only happened with the default denylist, which isn't the correct behavior
  • we're not trying to fix the [""] quirk here

@DerekStrickland
Copy link
Contributor Author

@DerekStrickland just double checking I understand - are these all true?

  • this is just a reversion of trying to merge function_denylist
  • merging function_denylist only happened with the default denylist, which isn't the correct behavior
  • we're not trying to fix the [""] quirk here

Exactly that!

Copy link
Member

@shoenig shoenig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

.changelog/12071.txt Outdated Show resolved Hide resolved
Co-authored-by: Seth Hoenig <seth.a.hoenig@gmail.com>
@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 120 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unable to get nomad config/get template function_denylist option
3 participants