Skip to content

Commit 78d2364

Browse files
committed
Don't verify TLS certs on support bundle requests
1 parent 1f9e478 commit 78d2364

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

cmd/troubleshoot/cli/root.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ from a server that can be used to assist when troubleshooting a server.`,
4444
cmd.Flags().String("pullpolicy", "", "the pull policy of the collector image")
4545
cmd.Flags().Bool("redact", true, "enable/disable default redactions")
4646
cmd.Flags().Bool("collect-without-permissions", false, "always run troubleshoot collectors even if some require permissions that troubleshoot does not have")
47+
cmd.Flags().Bool("allow-insecure-connections", false, "don't verify TLS certs when retrieving spec and reporting results")
4748

4849
cmd.Flags().String("serviceaccount", "", "name of the service account to use. if not provided, one will be created")
4950
viper.BindPFlags(cmd.Flags())

cmd/troubleshoot/cli/run.go

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cli
22

33
import (
4+
"crypto/tls"
45
"encoding/base64"
56
"encoding/json"
67
"fmt"
@@ -23,10 +24,22 @@ import (
2324
"github.com/replicatedhq/troubleshoot/pkg/collect"
2425
)
2526

27+
var (
28+
httpClient *http.Client
29+
)
30+
2631
func runTroubleshoot(v *viper.Viper, arg string) error {
2732
fmt.Print(cursor.Hide())
2833
defer fmt.Print(cursor.Show())
2934

35+
if v.GetBool("allow-insecure-connections") {
36+
httpClient = &http.Client{Transport: &http.Transport{
37+
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
38+
}}
39+
} else {
40+
httpClient = http.DefaultClient
41+
}
42+
3043
collectorContent := ""
3144
if !isURL(arg) {
3245
if _, err := os.Stat(arg); os.IsNotExist(err) {
@@ -45,7 +58,7 @@ func runTroubleshoot(v *viper.Viper, arg string) error {
4558
return errors.Wrap(err, "make request")
4659
}
4760
req.Header.Set("User-Agent", "Replicated_Troubleshoot/v1beta1")
48-
resp, err := http.DefaultClient.Do(req)
61+
resp, err := httpClient.Do(req)
4962
if err != nil {
5063
return errors.Wrap(err, "execute request")
5164
}
@@ -120,12 +133,15 @@ the %s Admin Console to begin analysis.`
120133
for _, ac := range collector.Spec.AfterCollection {
121134
if ac.UploadResultsTo != nil {
122135
if err := uploadSupportBundle(ac.UploadResultsTo, archivePath); err != nil {
123-
return errors.Wrap(err, "upload support bundle")
136+
c := color.New(color.FgHiRed)
137+
c.Printf("%s\r * Failed to upload support bundle: %v\n", cursor.ClearEntireLine(), err)
138+
} else {
139+
fileUploaded = true
124140
}
125-
fileUploaded = true
126141
} else if ac.Callback != nil {
127142
if err := callbackSupportBundleAPI(ac.Callback, archivePath); err != nil {
128-
return errors.Wrap(err, "execute callback")
143+
c := color.New(color.FgHiRed)
144+
c.Printf("%s\r * Failed to notify API that support bundle has been uploaded: %v\n", cursor.ClearEntireLine(), err)
129145
}
130146
}
131147
}
@@ -299,7 +315,7 @@ func uploadSupportBundle(r *troubleshootv1beta1.ResultRequest, archivePath strin
299315
req.Header.Set("Content-Type", contentType)
300316
}
301317

302-
resp, err := http.DefaultClient.Do(req)
318+
resp, err := httpClient.Do(req)
303319
if err != nil {
304320
return errors.Wrap(err, "execute request")
305321
}
@@ -325,7 +341,7 @@ func callbackSupportBundleAPI(r *troubleshootv1beta1.ResultRequest, archivePath
325341
return errors.Wrap(err, "create request")
326342
}
327343

328-
resp, err := http.DefaultClient.Do(req)
344+
resp, err := httpClient.Do(req)
329345
if err != nil {
330346
return errors.Wrap(err, "execute request")
331347
}

0 commit comments

Comments
 (0)