Skip to content

Commit

Permalink
Skip https certificate verification (#920)
Browse files Browse the repository at this point in the history
Signed-off-by: fengshunli <1171313930@qq.com>
  • Loading branch information
fengshunli authored Feb 17, 2023
1 parent 9a678b4 commit 501744a
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions cmd/polaris/audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package cmd
import (
"bytes"
"context"
"crypto/tls"
"encoding/json"
"fmt"
"io"
Expand Down Expand Up @@ -45,6 +46,7 @@ var (
helmValues string
checks []string
auditNamespace string
skipSslValidation bool
)

func init() {
Expand All @@ -63,6 +65,7 @@ func init() {
auditCmd.PersistentFlags().StringVar(&helmValues, "helm-values", "", "Optional flag to add helm values")
auditCmd.PersistentFlags().StringSliceVar(&checks, "checks", []string{}, "Optional flag to specify specific checks to check")
auditCmd.PersistentFlags().StringVar(&auditNamespace, "namespace", "", "Namespace to audit. Only applies to in-cluster audits")
auditCmd.PersistentFlags().BoolVar(&skipSslValidation, "skip-ssl-validation", false, "Skip https certificate verification")
}

var auditCmd = &cobra.Command{
Expand Down Expand Up @@ -202,9 +205,13 @@ func outputAudit(auditData validator.AuditData, outputFile, outputURL, outputFor
} else {
req.Header.Set("Content-Type", "text/plain")
}

client := &http.Client{}
if skipSslValidation {
transport := &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}}
client = &http.Client{Transport: transport}
}
resp, err := client.Do(req)

if err != nil {
logrus.Errorf("Error making request for output: %v", err)
os.Exit(1)
Expand All @@ -223,7 +230,7 @@ func outputAudit(auditData validator.AuditData, outputFile, outputURL, outputFor
}

if outputFile != "" {
err := os.WriteFile(outputFile, []byte(outputBytes), 0644)
err := os.WriteFile(outputFile, outputBytes, 0644)
if err != nil {
logrus.Errorf("Error writing output to file: %v", err)
os.Exit(1)
Expand Down

0 comments on commit 501744a

Please sign in to comment.