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

Fix possible path traversal attack when supporting Helm values.yaml #2452

Merged
merged 12 commits into from
Oct 16, 2019

Conversation

simster7
Copy link
Member

@simster7 simster7 commented Oct 9, 2019

Fixes #2447 by addressing #2020 (comment).

Currently looking for other possible path traversal attacks.

@@ -227,7 +227,7 @@ func helmTemplate(appPath string, q *apiclient.ManifestRequest) ([]*unstructured
}
templateOpts.Values = appHelm.ValueFiles
if appHelm.Values != "" {
file, err := ioutil.TempFile("", "values-*.yaml")
file, err := ioutil.TempFile(appPath, "values-*.yaml")
Copy link
Member Author

Choose a reason for hiding this comment

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

As part of this change, all values stemming from Helm.Values will now have to be saved in a temp file within the application path.

Copy link
Contributor

Choose a reason for hiding this comment

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

clever

@alexec alexec self-assigned this Oct 9, 2019
@alexec
Copy link
Contributor

alexec commented Oct 9, 2019

Looks good so far. Need to find out why e2e test failed

@codecov
Copy link

codecov bot commented Oct 9, 2019

Codecov Report

Merging #2452 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@          Coverage Diff           @@
##           master   #2452   +/-   ##
======================================
  Coverage    39.2%   39.2%           
======================================
  Files         108     108           
  Lines       15862   15862           
======================================
  Hits         6218    6218           
  Misses       8864    8864           
  Partials      780     780

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 87cb498...2622a64. Read the comment docs.

@alexec
Copy link
Contributor

alexec commented Oct 10, 2019

@simster7 you haven't removed the 'not ready for review' label, so I'll assume you don't want a review yet.

@simster7
Copy link
Member Author

@alexec I don't have permissions to add or remove labels haha, but this should be ready for review!

@alexec alexec added this to the v1.4 milestone Oct 10, 2019
util/security/path_traversal.go Show resolved Hide resolved
util/helm/cmd.go Show resolved Hide resolved
@simster7 simster7 requested a review from alexec October 12, 2019 20:12
@simster7
Copy link
Member Author

@alexec Added the extra tests!

util/helm/cmd_test.go Outdated Show resolved Hide resolved
util/security/path_traversal_test.go Outdated Show resolved Hide resolved
util/security/path_traversal_test.go Outdated Show resolved Hide resolved
util/security/path_traversal_test.go Outdated Show resolved Hide resolved
reposerver/repository/repository_test.go Outdated Show resolved Hide resolved
util/helm/cmd.go Outdated Show resolved Hide resolved
Copy link
Contributor

@alexec alexec left a comment

Choose a reason for hiding this comment

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

Conditional approval. You must fix the lint error!

@simster7 simster7 merged commit 656167f into argoproj:master Oct 16, 2019
@alexec alexec removed this from the v1.4 milestone Oct 16, 2019
@alexec alexec added this to the v1.3 milestone Oct 16, 2019
@jannfis
Copy link
Member

jannfis commented Nov 13, 2019

@alexec @simster7 Hm, I think this PR went a little over the goal. The behaviour of this change now forbids usage of values files outside the Chart folder, but should it not rather forbid usage of values files outside the repository root? It broke a few of our Helm applications that have a structure in repo like after we updated our integration environment to 1.3 today:

chart/Chart.yaml
env/env1/values.yaml
env/env2/values.yaml

Was this the intention?

@simster7
Copy link
Member Author

Correct, the directory used as "root" for Helm apps is the directory the Chart.yaml is located:

chartPath, closer, err := helmClient.ExtractChart(source.Chart, version)
if err != nil {
return err
}
defer util.Close(closer)
return operation(chartPath, revision)

I think it would be up to discussion to determine if we should support files/directories outside of the Chart.yaml directory, yet still under the repo.

One one hand, supporting the repo as a whole may allow an attacker to use a values.yaml file that is unintended for the current deployment – but still present in the repo – for malicious purposes. On the other hand, as a Kustomize user (which has a similar strict directory enforcer) I am not familiar with Helm repo's standard patterns of organization. If the set up that you described is standard or even popular enough, then one could argue that we would be forced to support it, while losing the benefits of stricter security. (I can't think of another simple way to enforce against the use of unintended files other than directory structure).

An easy and flexible solution to this could be to introduce a flag to allow the user to disable the directory enforcer.

@adamjohnson01
Copy link
Contributor

A lot of our deployments use shared values outside of the root but in the same repo. I think a flag to enable this would be good.

@jannfis
Copy link
Member

jannfis commented Nov 13, 2019

Yes, a switch would be fine. Regardless of its setting, it should prevent jumping out the repo root, tho.

@simster7
Copy link
Member Author

Will work on a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support values.yaml outside of chart folder allows directory traversal attack
5 participants