Skip to content

Commit 04c3053

Browse files
authored
Merge pull request from GHSA-q4w5-4gq2-98vm
Signed-off-by: Michael Crenshaw <[email protected]> fix tests/lint Signed-off-by: Michael Crenshaw <[email protected]>
1 parent 17f7f4f commit 04c3053

File tree

10 files changed

+63
-19
lines changed

10 files changed

+63
-19
lines changed

reposerver/repository/repository.go

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1461,19 +1461,23 @@ func populateHelmAppDetails(res *apiclient.RepoAppDetailsResponse, appPath strin
14611461
return err
14621462
}
14631463

1464-
if err := loadFileIntoIfExists(filepath.Join(appPath, "values.yaml"), &res.Helm.Values); err != nil {
1465-
return err
1464+
if resolvedValuesPath, _, err := pathutil.ResolveFilePath(appPath, repoRoot, "values.yaml", []string{}); err == nil {
1465+
if err := loadFileIntoIfExists(resolvedValuesPath, &res.Helm.Values); err != nil {
1466+
return err
1467+
}
1468+
} else {
1469+
log.Warnf("Values file %s is not allowed: %v", filepath.Join(appPath, "values.yaml"), err)
14661470
}
14671471
var resolvedSelectedValueFiles []pathutil.ResolvedFilePath
14681472
// drop not allowed values files
14691473
for _, file := range selectedValueFiles {
14701474
if resolvedFile, _, err := pathutil.ResolveFilePath(appPath, repoRoot, file, q.GetValuesFileSchemes()); err == nil {
14711475
resolvedSelectedValueFiles = append(resolvedSelectedValueFiles, resolvedFile)
14721476
} else {
1473-
log.Debugf("Values file %s is not allowed: %v", file, err)
1477+
log.Warnf("Values file %s is not allowed: %v", file, err)
14741478
}
14751479
}
1476-
params, err := h.GetParameters(resolvedSelectedValueFiles)
1480+
params, err := h.GetParameters(resolvedSelectedValueFiles, appPath, repoRoot)
14771481
if err != nil {
14781482
return err
14791483
}
@@ -1492,15 +1496,16 @@ func populateHelmAppDetails(res *apiclient.RepoAppDetailsResponse, appPath strin
14921496
return nil
14931497
}
14941498

1495-
func loadFileIntoIfExists(path string, destination *string) error {
1496-
info, err := os.Stat(path)
1499+
func loadFileIntoIfExists(path pathutil.ResolvedFilePath, destination *string) error {
1500+
stringPath := string(path)
1501+
info, err := os.Stat(stringPath)
14971502

14981503
if err == nil && !info.IsDir() {
1499-
if bytes, err := ioutil.ReadFile(path); err != nil {
1500-
*destination = string(bytes)
1501-
} else {
1504+
bytes, err := ioutil.ReadFile(stringPath);
1505+
if err != nil {
15021506
return err
15031507
}
1508+
*destination = string(bytes)
15041509
}
15051510

15061511
return nil

reposerver/repository/repository_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,11 +1125,13 @@ func TestListApps(t *testing.T) {
11251125
"app-parameters/single-app-only": "Kustomize",
11261126
"app-parameters/single-global": "Kustomize",
11271127
"invalid-helm": "Helm",
1128+
"in-bounds-values-file-link": "Helm",
11281129
"invalid-kustomize": "Kustomize",
11291130
"kustomization_yaml": "Kustomize",
11301131
"kustomization_yml": "Kustomize",
11311132
"my-chart": "Helm",
11321133
"my-chart-2": "Helm",
1134+
"out-of-bounds-values-file-link": "Helm",
11331135
"values-files": "Helm",
11341136
}
11351137
assert.Equal(t, expectedApps, res.Apps)
@@ -2027,3 +2029,23 @@ func Test_populateHelmAppDetails(t *testing.T) {
20272029
assert.Len(t, res.Helm.Parameters, 3)
20282030
assert.Len(t, res.Helm.ValueFiles, 4)
20292031
}
2032+
2033+
func Test_populateHelmAppDetails_values_symlinks(t *testing.T) {
2034+
t.Run("inbound", func(t *testing.T) {
2035+
res := apiclient.RepoAppDetailsResponse{}
2036+
q := apiclient.RepoServerAppDetailsQuery{Repo: &argoappv1.Repository{}, Source: &argoappv1.ApplicationSource{}}
2037+
err := populateHelmAppDetails(&res, "./testdata/in-bounds-values-file-link/", "./testdata/in-bounds-values-file-link/", &q)
2038+
require.NoError(t, err)
2039+
assert.NotEmpty(t, res.Helm.Values)
2040+
assert.NotEmpty(t, res.Helm.Parameters)
2041+
})
2042+
2043+
t.Run("out of bounds", func(t *testing.T) {
2044+
res := apiclient.RepoAppDetailsResponse{}
2045+
q := apiclient.RepoServerAppDetailsQuery{Repo: &argoappv1.Repository{}, Source: &argoappv1.ApplicationSource{}}
2046+
err := populateHelmAppDetails(&res, "./testdata/out-of-bounds-values-file-link/", "./testdata/out-of-bounds-values-file-link/", &q)
2047+
require.NoError(t, err)
2048+
assert.Empty(t, res.Helm.Values)
2049+
assert.Empty(t, res.Helm.Parameters)
2050+
})
2051+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
name: my-chart
2+
version: 1.1.0
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
some: yaml
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
values-2.yaml
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
name: my-chart
2+
version: 1.1.0
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../out-of-bounds.yaml
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
some: yaml

util/helm/helm.go

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ import (
66
"net/url"
77
"os"
88
"os/exec"
9+
"path/filepath"
910
"strings"
1011

1112
"github.com/ghodss/yaml"
13+
log "github.com/sirupsen/logrus"
1214

1315
"github.com/argoproj/argo-cd/v2/util/config"
1416
executil "github.com/argoproj/argo-cd/v2/util/exec"
@@ -27,7 +29,7 @@ type Helm interface {
2729
// Template returns a list of unstructured objects from a `helm template` command
2830
Template(opts *TemplateOpts) (string, error)
2931
// GetParameters returns a list of chart parameters taking into account values in provided YAML files.
30-
GetParameters(valuesFiles []pathutil.ResolvedFilePath) (map[string]string, error)
32+
GetParameters(valuesFiles []pathutil.ResolvedFilePath, appPath, repoRoot string) (map[string]string, error)
3133
// DependencyBuild runs `helm dependency build` to download a chart's dependencies
3234
DependencyBuild() error
3335
// Init runs `helm init --client-only`
@@ -129,12 +131,19 @@ func Version(shortForm bool) (string, error) {
129131
return strings.TrimSpace(version), nil
130132
}
131133

132-
func (h *helm) GetParameters(valuesFiles []pathutil.ResolvedFilePath) (map[string]string, error) {
133-
out, err := h.cmd.inspectValues(".")
134-
if err != nil {
135-
return nil, err
134+
func (h *helm) GetParameters(valuesFiles []pathutil.ResolvedFilePath, appPath, repoRoot string) (map[string]string, error) {
135+
var values []string
136+
// Don't load values.yaml if it's an out-of-bounds link.
137+
if resolved, _, err := pathutil.ResolveFilePath(appPath, repoRoot, "values.yaml", []string{}); err == nil {
138+
fmt.Println(resolved)
139+
out, err := h.cmd.inspectValues(".")
140+
if err != nil {
141+
return nil, err
142+
}
143+
values = append(values, out)
144+
} else {
145+
log.Warnf("Values file %s is not allowed: %v", filepath.Join(appPath, "values.yaml"), err)
136146
}
137-
values := []string{out}
138147
for i := range valuesFiles {
139148
file := string(valuesFiles[i])
140149
var fileValues []byte
@@ -156,7 +165,7 @@ func (h *helm) GetParameters(valuesFiles []pathutil.ResolvedFilePath) (map[strin
156165
output := map[string]string{}
157166
for _, file := range values {
158167
values := map[string]interface{}{}
159-
if err = yaml.Unmarshal([]byte(file), &values); err != nil {
168+
if err := yaml.Unmarshal([]byte(file), &values); err != nil {
160169
return nil, fmt.Errorf("failed to parse values: %s", err)
161170
}
162171
flatVals(values, output)

util/helm/helm_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func TestHelmGetParams(t *testing.T) {
8585
require.NoError(t, err)
8686
h, err := NewHelmApp(repoRootAbs, nil, false, "", "", false)
8787
assert.NoError(t, err)
88-
params, err := h.GetParameters(nil)
88+
params, err := h.GetParameters(nil, repoRootAbs, repoRootAbs)
8989
assert.Nil(t, err)
9090

9191
slaveCountParam := params["cluster.slaveCount"]
@@ -100,7 +100,7 @@ func TestHelmGetParamsValueFiles(t *testing.T) {
100100
assert.NoError(t, err)
101101
valuesPath, _, err := path.ResolveFilePath(repoRootAbs, repoRootAbs, "values-production.yaml", nil)
102102
require.NoError(t, err)
103-
params, err := h.GetParameters([]path.ResolvedFilePath{valuesPath})
103+
params, err := h.GetParameters([]path.ResolvedFilePath{valuesPath}, repoRootAbs, repoRootAbs)
104104
assert.Nil(t, err)
105105

106106
slaveCountParam := params["cluster.slaveCount"]
@@ -117,7 +117,7 @@ func TestHelmGetParamsValueFilesThatExist(t *testing.T) {
117117
require.NoError(t, err)
118118
valuesProductionPath, _, err := path.ResolveFilePath(repoRootAbs, repoRootAbs, "values-production.yaml", nil)
119119
require.NoError(t, err)
120-
params, err := h.GetParameters([]path.ResolvedFilePath{valuesMissingPath, valuesProductionPath})
120+
params, err := h.GetParameters([]path.ResolvedFilePath{valuesMissingPath, valuesProductionPath}, repoRootAbs, repoRootAbs)
121121
assert.Nil(t, err)
122122

123123
slaveCountParam := params["cluster.slaveCount"]

0 commit comments

Comments
 (0)