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

add path sandboxing to file function #1249

Merged
merged 2 commits into from
Aug 8, 2019

Conversation

tgross
Copy link
Member

@tgross tgross commented Aug 7, 2019

If a sandbox path is provided in the configuration, the file function will prefix the path parameter and prevent relative paths from falling outside the sandbox.


@eikenb I've already vendored this into hashicorp/nomad#6075 for discussion there, but for now this is a draft so that we can chat about the implementation and what you think about the config UX.


Example of use:

ct-demo.hcl

template {
  source = "./ct-demo.conf"
  sandbox_path = "/Users/tim"
}

ct-demo.conf

{{ file "/etc/passwd" }}

Results:

$ consul-template -config=./ct-demo.hcl -once -dry
2019/08/07 15:56:39.325342 [ERR] (view) file(/Users/tim/etc/passwd): stat /Users/tim/etc/passwd: no such file or directory (exceeded maximum retries)
2019/08/07 15:56:39.325365 [ERR] (runner) watcher reported error: file(/Users/tim/etc/passwd): stat /Users/tim/etc/passwd: no such file or directory
2019/08/07 15:56:39.325639 [ERR] (cli) file(/Users/tim/etc/passwd): stat /Users/tim/etc/passwd: no such file or directory

Removing the sandbox_path field has the expected result: dumping the contents of that file to the terminal.

If a sandbox path is provided in the configuration, the `file`
function will prefix the path parameter and prevent relative paths
from falling outside the sandbox.

// BlacklistedFunctions is a set of functions to be disabled
// when executing the template
BlacklistedFunctions []string
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@eikenb
Copy link
Contributor

eikenb commented Aug 7, 2019

So I think this basically looks fine. Tests, documentation, etc.

Related to the sym-links. It would be pretty trivial to just add a filepath.EvalSymlinks call just before the filepath.Rel call to eliminate sym-linking outside of the box.

@tgross tgross marked this pull request as ready for review August 7, 2019 21:04
@tgross
Copy link
Member Author

tgross commented Aug 7, 2019

Related to the sym-links. It would be pretty trivial to just add a filepath.EvalSymlinks call just before the filepath.Rel call to eliminate sym-linking outside of the box.

Ok, cool. I'll add that as a belt-and-suspenders for Nomad's own isolation (which we wouldn't enjoy for the exec driver anyways).

@tgross
Copy link
Member Author

tgross commented Aug 8, 2019

@eikenb I've added the symlink walking check, which required a small rework of how the tests were being run to include real files on the file system under testdata/ but I think I'm happy with the result.

@eikenb
Copy link
Contributor

eikenb commented Aug 8, 2019

LGTM

@eikenb eikenb merged commit 0d999b3 into hashicorp:master Aug 8, 2019
tgross added a commit to hashicorp/nomad that referenced this pull request Aug 8, 2019
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
tgross added a commit to hashicorp/nomad that referenced this pull request Aug 8, 2019
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
tgross added a commit to hashicorp/nomad that referenced this pull request Aug 9, 2019
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
tgross added a commit to hashicorp/nomad that referenced this pull request Aug 9, 2019
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

[wip consul-template]
tgross added a commit to hashicorp/nomad that referenced this pull request Aug 12, 2019
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
tgross added a commit to hashicorp/nomad that referenced this pull request Aug 12, 2019
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
@eikenb eikenb added the nomad Related to ingetration in Nomad label Aug 12, 2019
tgross added a commit to hashicorp/nomad that referenced this pull request Aug 12, 2019
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
tgross added a commit to hashicorp/nomad that referenced this pull request Aug 12, 2019
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
tgross added a commit to hashicorp/nomad that referenced this pull request Aug 12, 2019
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
tgross added a commit to hashicorp/nomad that referenced this pull request Aug 12, 2019
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement nomad Related to ingetration in Nomad
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants