-
Notifications
You must be signed in to change notification settings - Fork 2k
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
override consul-template blacklist configuration #6075
Conversation
(I seemed to have screwed something up in the vendoring of the updated consul-template here so it's failing CI. Let me fix that 😊 ) |
55fe5b7
to
6b07846
Compare
// By default we pass a blacklist of functions to prevent | ||
// task operators from bypassing client-task isolation. | ||
// This protection can be disabled by the client config. | ||
if !config.ClientConfig.EnableInsecureTemplateFunctions { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this line and the change to the documentation suggest that this is supposed to be in the client config, but the change to the parsing show it in the top-level config. as such, right now it's not possible to change this to a non-default value of true
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes, thanks for catching that.
command/agent/config.go
Outdated
@@ -108,6 +108,10 @@ type Config struct { | |||
// for security bulletins | |||
DisableAnonymousSignature bool `hcl:"disable_anonymous_signature"` | |||
|
|||
// EnableInsecureTemplateFunctions enables templates to include functions | |||
// that are unsafe because they expose information from the client host. | |||
EnableInsecureTemplateFunctions bool `hcl:"enable_insecure_template_functions"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this needs to move below into ClientConfig
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
verified that this is working in the protective sense... the error message returned by consul-template in the allocation status is somewhat unpleasant, although it gets the point across:
2019-08-05T21:01:46Z Killing Template failed: (dynamic): execute: template: :1:3: executing "" at <file "/tmp/foo">: error calling file: function is disabled
config parsing means that this protection cannot currently be disabled. otherwise, looks good to me.
Can we make this a feature flag? Especially for template {
destination = "pki.json"
data = <<<EOF
{{ with secret "pki/issue/my-domain-dot-com" "common_name=foo.example.com" }}
{{ .Data | toJSON }}{{ end }}
EOF;
}
template {
destination = "certificate.tls"
data = <<<EOF
{{ file "pki.json" | parseJSON | .certificate }}
EOF;
}
template {
destination = "stuff.tls"
data = <<<EOF
{{ file "pki.json" | parseJSON | .other_field }}
EOF;
} I wonder if a better long term fix would be to provide a list of folders where For example, I would like to disable |
// By default we pass a blacklist of functions to prevent | ||
// task operators from bypassing client-task isolation. | ||
// This protection can be disabled by the client config. | ||
if !config.ClientConfig.EnableInsecureTemplateFunctions { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would like to be able to disable plugin
but keep file
around - maybe expose a []string for the functions I want to blacklist manually as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i still can't reproduce the previous behavior with enable_insecure_template_functions = true
, it looks like there is some conversion needed in:
Line 424 in fc55f65
func convertClientConfig(agentConfig *Config) (*clientconfig.Config, error) { |
3729c72
to
8608e30
Compare
@cgbaker I'm still working on this but in the meantime I believe I've fixed the configuration problem at this point. If I build the current PR as
I can confirm the correct behavior when I toggle our boolean value. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Hello @jippi, thanks for your feedback on this! When I worked on this I had the same concern you do here that some operators would want to be able to be more selective about what functions they disallow. There’s a bit of a trade-off to make between configuration complexity and secure defaults. That being said, after seeing your example and having some other discussions I think I'm leaning towards having a more fine-grained control.
I would definitely like to see this myself! If we could sandbox consul-template to the same context as the task we wouldn’t really need to worry about the |
Just pushed a set of commits leveraging the work done in this draft PR hashicorp/consul-template#1249 for discussion. Demo of what this looks like: default.hcl bind_addr = "0.0.0.0"
data_dir = "/tmp/nomad"
log_level = "DEBUG"
server {
enabled = true
bootstrap_expect = 1
}
client {
enabled = true
template {
function_blacklist = ["plugin"]
disable_sandbox = false
}
} file-leak.nomad job "example" {
datacenters = ["dc1"]
type = "service"
group "cache" {
count = 1
task "redis" {
driver = "docker"
config {
image = "redis:3.2"
port_map {
db = 6379
}
}
resources {
cpu = 500 # 500 MHz
memory = 256 # 256MB
network {
mbits = 10
port "db" {}
}
}
template {
data = "{{ file \"/etc/passwd\" }}"
destination = "local/file.yml"
}
}
}
} output:
|
e3ef88b
to
c4dfc5b
Compare
We're getting a lot of timeouts on Travis builds here. I've opened #6094 to help mitigate some of that. |
c4dfc5b
to
613f7ef
Compare
@cgbaker @jippi I think I'm happy with where this has landed at this point. The configuration values and their defaults are: client {
template {
function_blacklist = ["plugin"]
disable_file_sandbox = false
}
} Although I know @jippi mentioned wanting to sandbox tasks to specific directories outside the task directory, we're going to punt on that for now and have a flag to disable the sandbox. We can return to this in later work and see if it makes sense to include, but we need the all-or-nothing flag for backwards compatibility. For now, this new configuration gives folks a bunch of different options depending on the level of protection they need:
What do we think? |
17e841d
to
e4b29e6
Compare
Rebased this on master to pick up #6095 and hopefully bring test run times down. |
|
||
- `function_blacklist` `([]string: ["plugin"])` - Specifies a list of template | ||
rendering functions that should be disallowed in job specs because they can | ||
leak information from the client host to templates. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"leak information" is too weak to describe plugin
, so maybe we should expand with:
By default the
plugin
function is disallowed as it allows running arbitrary commands on the host as root (unless Nomad is configured to run as a non-root user).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
e4b29e6
to
bdafd59
Compare
Looks like we can avoid breaking existing uses of |
bdafd59
to
9aa45a0
Compare
cf5b484
to
b932883
Compare
b932883
to
b61ced1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm - but would be good to remove burstsushi casing.
pulls in configuration option for blacklisting template functions from: hashicorp/consul-template#1243 hashicorp/consul-template#1246 pulls in configuration option for file sandboxing from: hashicorp/consul-template#1249 hashicorp/consul-template#1254 pulls in vault KVv2 read fixes from: hashicorp/consul-template#1253
b61ced1
to
c48f2f7
Compare
When rendering a task template, the `plugin` function is no longer permitted by default and will raise an error. An operator can opt-in to permitting this function with the new `template.function_blacklist` field in the client configuration. When rendering a task template, path parameters for the `file` function will be treated as relative to the task directory by default. Relative paths or symlinks that point outside the task directory will raise an error. An operator can opt-out of this protection with the new `template.disable_file_sandbox` field in the client configuration.
c48f2f7
to
af389da
Compare
This work has been cherry-picked into the |
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. |
By default consul-template allows any template rendering function it supports to be used. This PR drops the
plugin
andfile
functions by default for Nomad templates. Includes: