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

file sandbox: check but don't alter paths passed to 'file' #1254

Merged
merged 1 commit into from
Aug 12, 2019

Conversation

tgross
Copy link
Member

@tgross tgross commented Aug 9, 2019

During a discussion with @notnoop about hashicorp/nomad#6075, we discovered that altering the path being passed into the file function was going to cut off a lot of existing uses of consul-template in Nomad, particularly around the use of the NOMAD_TASK_DIR variable.

This PR provides a check but doesn't prefix the path parameter.

cc @schmichael @eikenb

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]
// pathInSandbox determines whether a provided path falls within the sandbox.
// returns an error only if the file can't be evaluated (missing, invalid
// symlink, etc.)
func pathInSandbox(sandbox, path string) (bool, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Returning both a bool and an error is redundant here as you always return false with an error and true when there is no error. So when you check !ok above, you would always use that error and ignore the returned one whenever this returned false.

I'd say skip the bool and just use the standard if err != nil {return err} on the result.

Copy link
Member Author

Choose a reason for hiding this comment

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

It was feeling semantically weird to return an error on a yes/no question. But I think you're right, let's do that.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done!

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks. And yeah, I get the semantic itch for having it return a bool to a yes/no question-y function. Maybe with a different name or something it wouldn't feel wrong or if it could be reworked such that the error could be handled internally (just changing the bool result). But as is, I think simplifying it is better.

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
Copy link
Member Author

tgross commented Aug 12, 2019

@eikenb https://circleci.com/gh/hashicorp/consul-template/126 is showing what looks like a flaky test but I don't have permissions to re-run on CircleCI. I pushed a no-op commit message change to get CI run again.

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
Copy link
Contributor

eikenb commented Aug 12, 2019

@tgross Yeah.. that TestRunner_quiescence/snooze test has a race in it somewhere. It hasn't been a priority as it is infrequent enough and I'm planning on reworking that runner code anyways.

@tgross
Copy link
Member Author

tgross commented Aug 12, 2019

Are we ok to merge then?

@eikenb
Copy link
Contributor

eikenb commented Aug 12, 2019

Yep. Going to take care of that in a few.

@eikenb eikenb added enhancement nomad Related to ingetration in Nomad labels Aug 12, 2019
@eikenb eikenb added this to the 0.21.1 milestone Aug 12, 2019
@eikenb eikenb merged commit 9e45d49 into hashicorp:master 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

3 participants