HTTP: Add TLS version configurability for Grafana server (#67482)
Co-authored-by: Rao B V Chalapathi <b_v_chalapathi.rao@nokia.com> Co-authored-by: Christopher Moyer <35463610+chri2547@users.noreply.github.com>
This commit is contained in:
co-authored by
Rao B V Chalapathi
Christopher Moyer
parent
5155455c55
commit
b9e53f628f
@@ -166,6 +166,7 @@ type Cfg struct {
|
||||
ReadTimeout time.Duration
|
||||
EnableGzip bool
|
||||
EnforceDomain bool
|
||||
MinTLSVersion string
|
||||
|
||||
// Security settings
|
||||
SecretKey string
|
||||
@@ -1796,6 +1797,11 @@ func (cfg *Cfg) readServerSettings(iniFile *ini.File) error {
|
||||
cfg.SocketPath = server.Key("socket").String()
|
||||
}
|
||||
|
||||
cfg.MinTLSVersion = valueAsString(server, "min_tls_version", "TLS1.2")
|
||||
if cfg.MinTLSVersion == "TLS1.0" || cfg.MinTLSVersion == "TLS1.1" {
|
||||
return fmt.Errorf("TLS version not configured correctly:%v, allowed values are TLS1.2 and TLS1.3", cfg.MinTLSVersion)
|
||||
}
|
||||
|
||||
cfg.Domain = valueAsString(server, "domain", "localhost")
|
||||
cfg.HTTPAddr = valueAsString(server, "http_addr", DefaultHTTPAddr)
|
||||
cfg.HTTPPort = valueAsString(server, "http_port", "3000")
|
||||
|
||||
@@ -31,6 +31,7 @@ func TestLoadingSettings(t *testing.T) {
|
||||
|
||||
require.Equal(t, "admin", cfg.AdminUser)
|
||||
require.Equal(t, "http://localhost:3000/", cfg.RendererCallbackUrl)
|
||||
require.Equal(t, "TLS1.2", cfg.MinTLSVersion)
|
||||
})
|
||||
|
||||
t.Run("default.ini should have no semi-colon commented entries", func(t *testing.T) {
|
||||
@@ -143,6 +144,20 @@ func TestLoadingSettings(t *testing.T) {
|
||||
require.Equal(t, "test2", cfg.Domain)
|
||||
})
|
||||
|
||||
t.Run("Should be able to override TLS version via command line", func(t *testing.T) {
|
||||
cfg := NewCfg()
|
||||
err := cfg.Load(CommandLineArgs{
|
||||
HomePath: "../../",
|
||||
Args: []string{
|
||||
"cfg:default.server.min_tls_version=TLS1.3",
|
||||
},
|
||||
Config: filepath.Join(HomePath, "pkg/setting/testdata/override.ini"),
|
||||
})
|
||||
require.Nil(t, err)
|
||||
|
||||
require.Equal(t, "TLS1.3", cfg.MinTLSVersion)
|
||||
})
|
||||
|
||||
t.Run("Defaults can be overridden in specified config file", func(t *testing.T) {
|
||||
if runtime.GOOS == windows {
|
||||
cfg := NewCfg()
|
||||
|
||||
Reference in New Issue
Block a user