From 4e2e4084edc0fa1e21d6a9a83b3ffdc8c1ec5e01 Mon Sep 17 00:00:00 2001 From: Matt Farina Date: Fri, 25 Jun 2021 20:08:06 -0400 Subject: [PATCH 1/2] Fix the url being set by WithURL on the getters The URL passed to the getter for WithURL needs to be a full URL rather than a chart reference used at the CLI. For example, bitnami/wordpress can point to the wordpress chart in the bitnami repo where the bitnami repo is at https://charts.bitnami.com. WithURL needs the full URL to the repo and not bitnami/wordpress. This is important because getters use the full URL information. In this case the http getter uses the host name for SNI handling. Before this change WithURL was being set to the chart reference instead of the URL. This was a silent bug. This change sets WithURL using a URL after for the repo is available when a reference is used instead of a full url. Signed-off-by: Matt Farina --- pkg/downloader/chart_downloader.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pkg/downloader/chart_downloader.go b/pkg/downloader/chart_downloader.go index 2c0d55a55..575c94151 100644 --- a/pkg/downloader/chart_downloader.go +++ b/pkg/downloader/chart_downloader.go @@ -158,7 +158,6 @@ func (c *ChartDownloader) ResolveChartVersion(ref, version string) (*url.URL, er if err != nil { return nil, errors.Errorf("invalid chart URL format: %s", ref) } - c.Options = append(c.Options, getter.WithURL(ref)) rf, err := loadRepoConfig(c.RepositoryConfig) if err != nil { @@ -177,6 +176,8 @@ func (c *ChartDownloader) ResolveChartVersion(ref, version string) (*url.URL, er // If there is no special config, return the default HTTP client and // swallow the error. if err == ErrNoOwnerRepo { + // Make sure to add the ref URL as the URL for the getter + c.Options = append(c.Options, getter.WithURL(ref)) return u, nil } return u, err @@ -215,6 +216,10 @@ func (c *ChartDownloader) ResolveChartVersion(ref, version string) (*url.URL, er return u, err } + // Now that we have the chart repository information we can use that URL + // to set the URL for the getter. + c.Options = append(c.Options, getter.WithURL(rc.URL)) + r, err := repo.NewChartRepository(rc, c.Getters) if err != nil { return u, err From 385fcae1ba0c8450bd89795cade5fafa99f4d771 Mon Sep 17 00:00:00 2001 From: Matt Farina Date: Mon, 28 Jun 2021 11:36:37 -0400 Subject: [PATCH 2/2] Adding test for user/pass without repo on Helm install Signed-off-by: Matt Farina --- cmd/helm/install_test.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cmd/helm/install_test.go b/cmd/helm/install_test.go index 13c994b92..b7349e3d5 100644 --- a/cmd/helm/install_test.go +++ b/cmd/helm/install_test.go @@ -20,6 +20,7 @@ import ( "fmt" "net/http" "net/http/httptest" + "path/filepath" "testing" "helm.sh/helm/v3/pkg/repo/repotest" @@ -48,6 +49,8 @@ func TestInstall(t *testing.T) { t.Fatal(err) } + repoFile := filepath.Join(srv.Root(), "repositories.yaml") + tests := []cmdTestCase{ // Install, base case { @@ -244,6 +247,11 @@ func TestInstall(t *testing.T) { cmd: "install aeneas reqtest --namespace default --repo " + srv2.URL + " --username username --password password --pass-credentials", golden: "output/install.txt", }, + { + name: "basic install with credentials and no repo", + cmd: fmt.Sprintf("install aeneas test/reqtest --username username --password password --repository-config %s --repository-cache %s", repoFile, srv.Root()), + golden: "output/install.txt", + }, } runTestActionCmd(t, tests)