-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Perform log.fatal if TLS flags are used when tls.enabled=false #2893 #3030
Changes from 2 commits
f92ac6a
f8f1cdf
3969321
d4584f5
a79f23a
ca1dfac
5fbd179
552cf86
fad9357
2834752
8ef54be
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -16,6 +16,7 @@ package tlscfg | |||||
|
||||||
import ( | ||||||
"flag" | ||||||
"fmt" | ||||||
|
||||||
"github.com/spf13/viper" | ||||||
) | ||||||
|
@@ -60,23 +61,31 @@ func (c ServerFlagsConfig) AddFlags(flags *flag.FlagSet) { | |||||
} | ||||||
|
||||||
// InitFromViper creates tls.Config populated with values retrieved from Viper. | ||||||
func (c ClientFlagsConfig) InitFromViper(v *viper.Viper) Options { | ||||||
func (c ClientFlagsConfig) InitFromViper(v *viper.Viper) (Options, error) { | ||||||
var p Options | ||||||
p.Enabled = v.GetBool(c.Prefix + tlsEnabled) | ||||||
p.CAPath = v.GetString(c.Prefix + tlsCA) | ||||||
p.CertPath = v.GetString(c.Prefix + tlsCert) | ||||||
p.KeyPath = v.GetString(c.Prefix + tlsKey) | ||||||
p.ServerName = v.GetString(c.Prefix + tlsServerName) | ||||||
p.SkipHostVerify = v.GetBool(c.Prefix + tlsSkipHostVerify) | ||||||
return p | ||||||
areTLSFlagsUsed := v.IsSet(c.Prefix+tlsCA) || v.IsSet(c.Prefix+tlsCert) || v.IsSet(c.Prefix+tlsKey) || v.IsSet(c.Prefix+tlsServerName) | ||||||
if (!p.Enabled) && (p.SkipHostVerify && areTLSFlagsUsed) { | ||||||
return p, fmt.Errorf("%s has been disable", c.Prefix+tlsEnabled) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
return p, nil | ||||||
} | ||||||
|
||||||
// InitFromViper creates tls.Config populated with values retrieved from Viper. | ||||||
func (c ServerFlagsConfig) InitFromViper(v *viper.Viper) Options { | ||||||
func (c ServerFlagsConfig) InitFromViper(v *viper.Viper) (Options, error) { | ||||||
var p Options | ||||||
p.Enabled = v.GetBool(c.Prefix + tlsEnabled) | ||||||
p.CertPath = v.GetString(c.Prefix + tlsCert) | ||||||
p.KeyPath = v.GetString(c.Prefix + tlsKey) | ||||||
p.ClientCAPath = v.GetString(c.Prefix + tlsClientCA) | ||||||
return p | ||||||
areTLSFlagsUsed := v.IsSet(c.Prefix+tlsCA) || v.IsSet(c.Prefix+tlsCert) || v.IsSet(c.Prefix+tlsKey) | ||||||
if !p.Enabled && areTLSFlagsUsed { | ||||||
return p, fmt.Errorf("%s has been disable", c.Prefix+tlsEnabled) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: I would extract Also, consider rewording this to be clearer on what is causing the error, a suggestion:
|
||||||
} | ||||||
return p, nil | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not test for the type of error, only that it is not nil (the last argument is only used when logging a failure).
If you want to test for the actual error, I would suggest this: