Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose tls.InsecureSkipVerify to es.tls.* CLI flags #1473

Merged
merged 3 commits into from
Apr 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions pkg/es/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,11 @@ type Configuration struct {

// TLSConfig describes the configuration properties to connect tls enabled ElasticSearch cluster
type TLSConfig struct {
Enabled bool
CertPath string
KeyPath string
CaPath string
Enabled bool
SkipHostVerify bool
CertPath string
KeyPath string
CaPath string
}

// ClientBuilder creates new es.Client
Expand Down Expand Up @@ -297,9 +298,11 @@ func (tlsConfig *TLSConfig) createTLSConfig() (*tls.Config, error) {
if err != nil {
return nil, err
}
// #nosec
return &tls.Config{
RootCAs: rootCerts,
Certificates: []tls.Certificate{*clientPrivateKey},
RootCAs: rootCerts,
Certificates: []tls.Certificate{*clientPrivateKey},
InsecureSkipVerify: tlsConfig.SkipHostVerify,
}, nil

}
Expand Down
6 changes: 6 additions & 0 deletions plugin/storage/es/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const (
suffixCert = ".tls.cert"
suffixKey = ".tls.key"
suffixCA = ".tls.ca"
suffixSkipHostVerify = ".tls.skip-host-verify"
suffixIndexPrefix = ".index-prefix"
suffixTagsAsFields = ".tags-as-fields"
suffixTagsAsFieldsAll = suffixTagsAsFields + ".all"
Expand Down Expand Up @@ -174,6 +175,10 @@ func addFlags(flagSet *flag.FlagSet, nsConfig *namespaceConfig) {
nsConfig.namespace+suffixTLS,
nsConfig.TLS.Enabled,
"Enable TLS with client certificates.")
flagSet.Bool(
nsConfig.namespace+suffixSkipHostVerify,
nsConfig.TLS.SkipHostVerify,
"(insecure) Skip server's certificate chain and host name verification")
flagSet.String(
nsConfig.namespace+suffixCert,
nsConfig.TLS.CertPath,
Expand Down Expand Up @@ -240,6 +245,7 @@ func initFromViper(cfg *namespaceConfig, v *viper.Viper) {
cfg.BulkFlushInterval = v.GetDuration(cfg.namespace + suffixBulkFlushInterval)
cfg.Timeout = v.GetDuration(cfg.namespace + suffixTimeout)
cfg.TLS.Enabled = v.GetBool(cfg.namespace + suffixTLS)
cfg.TLS.SkipHostVerify = v.GetBool(cfg.namespace + suffixSkipHostVerify)
cfg.TLS.CertPath = v.GetString(cfg.namespace + suffixCert)
cfg.TLS.KeyPath = v.GetString(cfg.namespace + suffixKey)
cfg.TLS.CaPath = v.GetString(cfg.namespace + suffixCA)
Expand Down
4 changes: 4 additions & 0 deletions plugin/storage/es/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ func TestOptionsWithFlags(t *testing.T) {
"--es.aux.server-urls=3.3.3.3, 4.4.4.4",
"--es.aux.max-span-age=24h",
"--es.aux.num-replicas=10",
"--es.tls=true",
"--es.tls.skip-host-verify=true",
})
opts.InitFromViper(v)

Expand All @@ -65,6 +67,8 @@ func TestOptionsWithFlags(t *testing.T) {
assert.Equal(t, []string{"1.1.1.1", "2.2.2.2"}, primary.Servers)
assert.Equal(t, 48*time.Hour, primary.MaxSpanAge)
assert.True(t, primary.Sniffer)
assert.Equal(t, true, primary.TLS.Enabled)
assert.Equal(t, true, primary.TLS.SkipHostVerify)

aux := opts.Get("es.aux")
assert.Equal(t, []string{"3.3.3.3", "4.4.4.4"}, aux.Servers)
Expand Down