Skip to content

Commit 0b09e3a

Browse files
committed
Add support for --insecure-skip-tls-verify option
Some users are stuck behind corporate HTTP proxies that MITM all traffic and are forced to sacrifice TLS security. This allows those users to use the tool despite the proxy messing with the certificates. Signed-off-by: Geoff Baskwill <[email protected]>
1 parent c8b9314 commit 0b09e3a

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

kubeval/config.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ type Config struct {
5757
// Quiet indicates whether non-results output should be emitted to the applications
5858
// log.
5959
Quiet bool
60+
61+
// InsecureSkipTLSVerify controls whether to skip TLS certificate validation
62+
// when retrieving schema content over HTTPS
63+
InsecureSkipTLSVerify bool
6064
}
6165

6266
// NewDefaultConfig creates a Config with default values
@@ -80,6 +84,7 @@ func AddKubevalFlags(cmd *cobra.Command, config *Config) *cobra.Command {
8084
cmd.Flags().StringVarP(&config.KubernetesVersion, "kubernetes-version", "v", "master", "Version of Kubernetes to validate against")
8185
cmd.Flags().StringVarP(&config.OutputFormat, "output", "o", "", fmt.Sprintf("The format of the output of this script. Options are: %v", validOutputs()))
8286
cmd.Flags().BoolVar(&config.Quiet, "quiet", false, "Silences any output aside from the direct results")
87+
cmd.Flags().BoolVar(&config.InsecureSkipTLSVerify, "insecure-skip-tls-verify", false, "If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure")
8388

8489
return cmd
8590
}

main.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ package main
33
import (
44
"bufio"
55
"bytes"
6+
"crypto/tls"
67
"errors"
78
"fmt"
89
"io/ioutil"
10+
"net/http"
911
"os"
1012
"path/filepath"
1113
"runtime"
@@ -43,6 +45,17 @@ var RootCmd = &cobra.Command{
4345
if config.IgnoreMissingSchemas && !config.Quiet {
4446
log.Warn("Set to ignore missing schemas")
4547
}
48+
49+
// This is not particularly secure but we highlight that with the name of
50+
// the config item. It would be good to also support a configurable set of
51+
// trusted certificate authorities as in the `--certificate-authority`
52+
// kubectl option.
53+
if config.InsecureSkipTLSVerify {
54+
http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{
55+
InsecureSkipVerify: true,
56+
}
57+
}
58+
4659
success := true
4760
windowsStdinIssue := false
4861
outputManager := kubeval.GetOutputManager(config.OutputFormat)

0 commit comments

Comments
 (0)