Skip to content

fix: report malformed --chart-repos and --helm-repo-extra-args instead of panicking - #879

Open
vignesh2027 wants to merge 2 commits into
helm:mainfrom
vignesh2027:fix/chart-repos-missing-equals
Open

vignesh2027 wants to merge 2 commits into
helm:mainfrom
vignesh2027:fix/chart-repos-missing-equals

Conversation

@vignesh2027

Copy link
Copy Markdown
Contributor

What this PR does / why we need it:

ct lint, ct install and ct lint-and-install panic when a --chart-repos or --helm-repo-extra-args value has no name= prefix. processCharts splits each value on = and reads the second element without checking that there is one.

To reproduce, run either of these against any chart:

ct lint --charts charts/foo --chart-repos https://charts.bitnami.com/bitnami
ct lint --charts charts/foo --helm-repo-extra-args=--force-update

Both print the list of charts to be processed and then crash with panic: runtime error: index out of range [1] with length 1 and a goroutine trace. The same happens when the value comes from ct.yaml or from CT_CHART_REPOS.

With this change the values are split with strings.Cut, and a value without = returns a normal error that names it and shows the expected format:

Error: failed linting charts: invalid chart repo "https://charts.bitnami.com/bitnami": expected format 'name=url'
Error: failed linting charts: invalid helm repo extra args "--force-update": expected format 'name=args'

Valid values are parsed exactly as before. I added a table test to chart_test.go that panics on main and passes with the fix.

Which issue this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close that issue when PR gets merged):

Special notes for your reviewer:

This crash was reported in #248 for --chart-repos and again in a later comment there for --helm-repo-extra-args. That issue was closed once the first reporter found their config mistake, so I have not used "fixes" here.

…d of panicking

processCharts split every --chart-repos and --helm-repo-extra-args
value on "=" and read the second element without checking that it
exists. A value without a repo name, such as
--chart-repos https://charts.bitnami.com/bitnami or
--helm-repo-extra-args --force-update, made lint, install and
lint-and-install crash with "index out of range [1] with length 1".

Use strings.Cut and return an error that names the bad value and the
expected format.

Signed-off-by: vigneshwar <applemacbook6sep2004@gmail.com>

@cpanato cpanato left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This fixes a real panic, and the valid-input parsing preserves the previous behavior. Local go test ./... passes, and the regression test reproduces the panic against the original implementation. Please address the credential disclosure in the new error message before merging.

Comment thread pkg/chart/chart.go Outdated
repoArgs[name] = repoExtraArgs
name, extraArgs, found := strings.Cut(repo, "=")
if !found {
return nil, fmt.Errorf("invalid helm repo extra args %q: expected format 'name=args'", repo)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

[P2] Avoid echoing the full malformed repository arguments here. These arguments can contain credentials: for example, --helm-repo-extra-args='--username demo --password secret' (missing the required name= prefix) now prints the password in the normal CLI error, even with --debug and --print-config disabled. I reproduced this using a placeholder password. Previously this input panicked without printing the argument value. Please report the expected name=args format without including the raw value, and add a regression test that verifies a password is absent from the error.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch, thanks. In ad4c0ee the errors no longer include the value. They name the flag and the 1-based position of the entry, for example invalid --helm-repo-extra-args entry 1: expected format 'name=args'. I did the same for --chart-repos, since a URL like https://user:pass@host without a name= prefix has the same problem.

TestLintChartsInvalidRepoConfig now has two cases with a placeholder password, one in the extra args and one in a repo URL, and checks that it is absent from the error. Both fail on the previous commit.

The values of --chart-repos and --helm-repo-extra-args can carry
credentials, so name the malformed entry by its position instead.

Signed-off-by: vigneshwar <applemacbook6sep2004@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants