Skip to content

Commit d34dc7b

Browse files
authored
Add support for --insecure-skip-tls-verify flag on helm repo add command (#1990)
Parses a new field in repositories named `skipTLSVerify` and if set to `true`, it appends `--insecure-skip-tls-verify` in `helm repo add` command. This should be useful with internal self-signed repos, mitm proxies etc. Resolves #1871
1 parent 1986cb3 commit d34dc7b

File tree

9 files changed

+60
-24
lines changed

9 files changed

+60
-24
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ repositories:
6868
- name: insecure
6969
url: https://charts.my-insecure-domain.com
7070
caFile: optional_ca_crt
71+
# Advanced configuration: You can skip the verification of TLS for an https repo
72+
- name: skipTLS
73+
url: https://ss.my-insecure-domain.com
74+
skipTLSVerify: true
7175

7276
# context: kube-context # this directive is deprecated, please consider using helmDefaults.kubeContext
7377

pkg/app/app_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2554,7 +2554,7 @@ func (helm *mockHelmExec) SetExtraArgs(args ...string) {
25542554
func (helm *mockHelmExec) SetHelmBinary(bin string) {
25552555
return
25562556
}
2557-
func (helm *mockHelmExec) AddRepo(name, repository, cafile, certfile, keyfile, username, password string, managed string, passCredentials string) error {
2557+
func (helm *mockHelmExec) AddRepo(name, repository, cafile, certfile, keyfile, username, password string, managed string, passCredentials string, skipTLSVerify string) error {
25582558
helm.repos = append(helm.repos, mockRepo{Name: name})
25592559
return nil
25602560
}

pkg/app/mocks_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func (helm *noCallHelmExec) SetHelmBinary(bin string) {
4848
helm.doPanic()
4949
return
5050
}
51-
func (helm *noCallHelmExec) AddRepo(name, repository, cafile, certfile, keyfile, username, password string, managed string, passCredentials string) error {
51+
func (helm *noCallHelmExec) AddRepo(name, repository, cafile, certfile, keyfile, username, password string, managed string, passCredentials string, skipTLSVerify string) error {
5252
helm.doPanic()
5353
return nil
5454
}

pkg/exectest/helm.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ func (helm *Helm) SetExtraArgs(args ...string) {
8484
func (helm *Helm) SetHelmBinary(bin string) {
8585
return
8686
}
87-
func (helm *Helm) AddRepo(name, repository, cafile, certfile, keyfile, username, password string, managed string, passCredentials string) error {
88-
helm.Repo = []string{name, repository, cafile, certfile, keyfile, username, password, managed, passCredentials}
87+
func (helm *Helm) AddRepo(name, repository, cafile, certfile, keyfile, username, password string, managed string, passCredentials string, skipTLSVerify string) error {
88+
helm.Repo = []string{name, repository, cafile, certfile, keyfile, username, password, managed, passCredentials, skipTLSVerify}
8989
return nil
9090
}
9191
func (helm *Helm) UpdateRepo() error {

pkg/helmexec/exec.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ func (helm *execer) SetHelmBinary(bin string) {
108108
helm.helmBinary = bin
109109
}
110110

111-
func (helm *execer) AddRepo(name, repository, cafile, certfile, keyfile, username, password string, managed string, passCredentials string) error {
111+
func (helm *execer) AddRepo(name, repository, cafile, certfile, keyfile, username, password string, managed string, passCredentials string, skipTLSVerify string) error {
112112
var args []string
113113
var out []byte
114114
var err error
@@ -144,6 +144,9 @@ func (helm *execer) AddRepo(name, repository, cafile, certfile, keyfile, usernam
144144
if passCredentials == "true" {
145145
args = append(args, "--pass-credentials")
146146
}
147+
if skipTLSVerify == "true" {
148+
args = append(args, "--insecure-skip-tls-verify")
149+
}
147150
helm.logger.Infof("Adding repo %v %v", name, repository)
148151
out, err = helm.exec(args, map[string]string{})
149152
default:

pkg/helmexec/exec_test.go

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func Test_AddRepo_Helm_3_3_2(t *testing.T) {
8989
kubeContext: "dev",
9090
runner: &mockRunner{},
9191
}
92-
helm.AddRepo("myRepo", "https://repo.example.com/", "", "cert.pem", "key.pem", "", "", "", "")
92+
helm.AddRepo("myRepo", "https://repo.example.com/", "", "cert.pem", "key.pem", "", "", "", "", "")
9393
expected := `Adding repo myRepo https://repo.example.com/
9494
exec: helm --kube-context dev repo add myRepo https://repo.example.com/ --force-update --cert-file cert.pem --key-file key.pem
9595
`
@@ -102,7 +102,7 @@ func Test_AddRepo(t *testing.T) {
102102
var buffer bytes.Buffer
103103
logger := NewLogger(&buffer, "debug")
104104
helm := MockExecer(logger, "dev")
105-
helm.AddRepo("myRepo", "https://repo.example.com/", "", "cert.pem", "key.pem", "", "", "", "")
105+
helm.AddRepo("myRepo", "https://repo.example.com/", "", "cert.pem", "key.pem", "", "", "", "", "")
106106
expected := `Adding repo myRepo https://repo.example.com/
107107
exec: helm --kube-context dev repo add myRepo https://repo.example.com/ --cert-file cert.pem --key-file key.pem
108108
`
@@ -111,7 +111,7 @@ exec: helm --kube-context dev repo add myRepo https://repo.example.com/ --cert-f
111111
}
112112

113113
buffer.Reset()
114-
helm.AddRepo("myRepo", "https://repo.example.com/", "ca.crt", "", "", "", "", "", "")
114+
helm.AddRepo("myRepo", "https://repo.example.com/", "ca.crt", "", "", "", "", "", "", "")
115115
expected = `Adding repo myRepo https://repo.example.com/
116116
exec: helm --kube-context dev repo add myRepo https://repo.example.com/ --ca-file ca.crt
117117
`
@@ -120,7 +120,7 @@ exec: helm --kube-context dev repo add myRepo https://repo.example.com/ --ca-fil
120120
}
121121

122122
buffer.Reset()
123-
helm.AddRepo("myRepo", "https://repo.example.com/", "", "", "", "", "", "", "")
123+
helm.AddRepo("myRepo", "https://repo.example.com/", "", "", "", "", "", "", "", "")
124124
expected = `Adding repo myRepo https://repo.example.com/
125125
exec: helm --kube-context dev repo add myRepo https://repo.example.com/
126126
`
@@ -129,7 +129,7 @@ exec: helm --kube-context dev repo add myRepo https://repo.example.com/
129129
}
130130

131131
buffer.Reset()
132-
helm.AddRepo("acrRepo", "", "", "", "", "", "", "acr", "")
132+
helm.AddRepo("acrRepo", "", "", "", "", "", "", "acr", "", "")
133133
expected = `Adding repo acrRepo (acr)
134134
exec: az acr helm repo add --name acrRepo
135135
exec: az acr helm repo add --name acrRepo:
@@ -139,15 +139,15 @@ exec: az acr helm repo add --name acrRepo:
139139
}
140140

141141
buffer.Reset()
142-
helm.AddRepo("otherRepo", "", "", "", "", "", "", "unknown", "")
142+
helm.AddRepo("otherRepo", "", "", "", "", "", "", "unknown", "", "")
143143
expected = `ERROR: unknown type 'unknown' for repository otherRepo
144144
`
145145
if buffer.String() != expected {
146146
t.Errorf("helmexec.AddRepo()\nactual = %v\nexpect = %v", buffer.String(), expected)
147147
}
148148

149149
buffer.Reset()
150-
helm.AddRepo("myRepo", "https://repo.example.com/", "", "", "", "example_user", "example_password", "", "")
150+
helm.AddRepo("myRepo", "https://repo.example.com/", "", "", "", "example_user", "example_password", "", "", "")
151151
expected = `Adding repo myRepo https://repo.example.com/
152152
exec: helm --kube-context dev repo add myRepo https://repo.example.com/ --username example_user --password example_password
153153
`
@@ -156,7 +156,7 @@ exec: helm --kube-context dev repo add myRepo https://repo.example.com/ --userna
156156
}
157157

158158
buffer.Reset()
159-
helm.AddRepo("", "https://repo.example.com/", "", "", "", "", "", "", "")
159+
helm.AddRepo("", "https://repo.example.com/", "", "", "", "", "", "", "", "")
160160
expected = `empty field name
161161
162162
`
@@ -165,14 +165,20 @@ exec: helm --kube-context dev repo add myRepo https://repo.example.com/ --userna
165165
}
166166

167167
buffer.Reset()
168-
helm.AddRepo("myRepo", "https://repo.example.com/", "", "", "", "example_user", "example_password", "", "true")
168+
helm.AddRepo("myRepo", "https://repo.example.com/", "", "", "", "example_user", "example_password", "", "true", "")
169169
expected = `Adding repo myRepo https://repo.example.com/
170170
exec: helm --kube-context dev repo add myRepo https://repo.example.com/ --username example_user --password example_password --pass-credentials
171171
`
172172
if buffer.String() != expected {
173173
t.Errorf("helmexec.AddRepo()\nactual = %v\nexpect = %v", buffer.String(), expected)
174174
}
175175

176+
buffer.Reset()
177+
helm.AddRepo("myRepo", "https://repo.example.com/", "", "", "", "", "", "", "", "true")
178+
expected = `Adding repo myRepo https://repo.example.com/
179+
exec: helm --kube-context dev repo add myRepo https://repo.example.com/ --insecure-skip-tls-verify
180+
`
181+
176182
}
177183

178184
func Test_UpdateRepo(t *testing.T) {
@@ -516,7 +522,7 @@ func Test_LogLevels(t *testing.T) {
516522
buffer.Reset()
517523
logger := NewLogger(&buffer, logLevel)
518524
helm := MockExecer(logger, "")
519-
helm.AddRepo("myRepo", "https://repo.example.com/", "", "", "", "example_user", "example_password", "", "")
525+
helm.AddRepo("myRepo", "https://repo.example.com/", "", "", "", "example_user", "example_password", "", "", "")
520526
if buffer.String() != expected {
521527
t.Errorf("helmexec.AddRepo()\nactual = %v\nexpect = %v", buffer.String(), expected)
522528
}

pkg/helmexec/helmexec.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ type Interface interface {
1212
SetExtraArgs(args ...string)
1313
SetHelmBinary(bin string)
1414

15-
AddRepo(name, repository, cafile, certfile, keyfile, username, password string, managed string, passCredentials string) error
15+
AddRepo(name, repository, cafile, certfile, keyfile, username, password string, managed string, passCredentials string, skipTLSVerify string) error
1616
UpdateRepo() error
1717
RegistryLogin(name string, username string, password string) error
1818
BuildDeps(name, chart string) error

pkg/state/state.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ type RepositorySpec struct {
173173
Managed string `yaml:"managed,omitempty"`
174174
OCI bool `yaml:"oci,omitempty"`
175175
PassCredentials string `yaml:"passCredentials,omitempty"`
176+
SkipTLSVerify string `yaml:"skipTLSVerify,omitempty"`
176177
}
177178

178179
// ReleaseSpec defines the structure of a helm release
@@ -393,7 +394,7 @@ func (st *HelmState) ApplyOverrides(spec *ReleaseSpec) {
393394

394395
type RepoUpdater interface {
395396
IsHelm3() bool
396-
AddRepo(name, repository, cafile, certfile, keyfile, username, password string, managed string, passCredentials string) error
397+
AddRepo(name, repository, cafile, certfile, keyfile, username, password string, managed string, passCredentials string, skipTLSVerify string) error
397398
UpdateRepo() error
398399
RegistryLogin(name string, username string, password string) error
399400
}
@@ -412,7 +413,7 @@ func (st *HelmState) SyncRepos(helm RepoUpdater, shouldSkip map[string]bool) ([]
412413
err = helm.RegistryLogin(repo.URL, username, password)
413414
}
414415
} else {
415-
err = helm.AddRepo(repo.Name, repo.URL, repo.CaFile, repo.CertFile, repo.KeyFile, repo.Username, repo.Password, repo.Managed, repo.PassCredentials)
416+
err = helm.AddRepo(repo.Name, repo.URL, repo.CaFile, repo.CertFile, repo.KeyFile, repo.Username, repo.Password, repo.Managed, repo.PassCredentials, repo.SkipTLSVerify)
416417
}
417418

418419
if err != nil {

pkg/state/state_test.go

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -890,10 +890,11 @@ func TestHelmState_SyncRepos(t *testing.T) {
890890
Username: "",
891891
Password: "",
892892
PassCredentials: "",
893+
SkipTLSVerify: "",
893894
},
894895
},
895896
helm: &exectest.Helm{},
896-
want: []string{"name", "http://example.com/", "", "", "", "", "", "", ""},
897+
want: []string{"name", "http://example.com/", "", "", "", "", "", "", "", ""},
897898
},
898899
{
899900
name: "ACR hosted repository",
@@ -904,7 +905,7 @@ func TestHelmState_SyncRepos(t *testing.T) {
904905
},
905906
},
906907
helm: &exectest.Helm{},
907-
want: []string{"name", "", "", "", "", "", "", "acr", ""},
908+
want: []string{"name", "", "", "", "", "", "", "acr", "", ""},
908909
},
909910
{
910911
name: "repository with cert and key",
@@ -917,10 +918,11 @@ func TestHelmState_SyncRepos(t *testing.T) {
917918
Username: "",
918919
Password: "",
919920
PassCredentials: "",
921+
SkipTLSVerify: "",
920922
},
921923
},
922924
helm: &exectest.Helm{},
923-
want: []string{"name", "http://example.com/", "", "certfile", "keyfile", "", "", "", ""},
925+
want: []string{"name", "http://example.com/", "", "certfile", "keyfile", "", "", "", "", ""},
924926
},
925927
{
926928
name: "repository with ca file",
@@ -932,10 +934,11 @@ func TestHelmState_SyncRepos(t *testing.T) {
932934
Username: "",
933935
Password: "",
934936
PassCredentials: "",
937+
SkipTLSVerify: "",
935938
},
936939
},
937940
helm: &exectest.Helm{},
938-
want: []string{"name", "http://example.com/", "cafile", "", "", "", "", "", ""},
941+
want: []string{"name", "http://example.com/", "cafile", "", "", "", "", "", "", ""},
939942
},
940943
{
941944
name: "repository with username and password",
@@ -948,10 +951,11 @@ func TestHelmState_SyncRepos(t *testing.T) {
948951
Username: "example_user",
949952
Password: "example_password",
950953
PassCredentials: "",
954+
SkipTLSVerify: "",
951955
},
952956
},
953957
helm: &exectest.Helm{},
954-
want: []string{"name", "http://example.com/", "", "", "", "example_user", "example_password", "", ""},
958+
want: []string{"name", "http://example.com/", "", "", "", "example_user", "example_password", "", "", ""},
955959
},
956960
{
957961
name: "repository with username and password and pass-credentials",
@@ -964,10 +968,28 @@ func TestHelmState_SyncRepos(t *testing.T) {
964968
Username: "example_user",
965969
Password: "example_password",
966970
PassCredentials: "true",
971+
SkipTLSVerify: "",
967972
},
968973
},
969974
helm: &exectest.Helm{},
970-
want: []string{"name", "http://example.com/", "", "", "", "example_user", "example_password", "", "true"},
975+
want: []string{"name", "http://example.com/", "", "", "", "example_user", "example_password", "", "true", ""},
976+
},
977+
{
978+
name: "repository with skip-tls-verify",
979+
repos: []RepositorySpec{
980+
{
981+
Name: "name",
982+
URL: "http://example.com/",
983+
CertFile: "",
984+
KeyFile: "",
985+
Username: "",
986+
Password: "",
987+
PassCredentials: "",
988+
SkipTLSVerify: "true",
989+
},
990+
},
991+
helm: &exectest.Helm{},
992+
want: []string{"name", "http://example.com/", "", "", "", "", "", "", "", "true"},
971993
},
972994
}
973995
for i := range tests {

0 commit comments

Comments
 (0)