mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
postgres: tls: only use non-empty certificates (#82182)
This commit is contained in:
parent
dcc977005c
commit
7f77be8f85
@ -200,6 +200,19 @@ func (m *tlsManager) writeCertFiles(dsInfo sqleng.DataSourceInfo, tlsconfig *tls
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// we do not want to point to cert-files that do not exist
|
||||||
|
if tlsRootCert == "" {
|
||||||
|
tlsconfig.RootCertFile = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
if tlsClientCert == "" {
|
||||||
|
tlsconfig.CertFile = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
if tlsClientKey == "" {
|
||||||
|
tlsconfig.CertKeyFile = ""
|
||||||
|
}
|
||||||
|
|
||||||
// Update datasource cache
|
// Update datasource cache
|
||||||
m.dsCacheInstance.cache.Store(cacheKey, dsInfo.Updated)
|
m.dsCacheInstance.cache.Store(cacheKey, dsInfo.Updated)
|
||||||
return nil
|
return nil
|
||||||
|
@ -237,6 +237,45 @@ func TestGetTLSSettings(t *testing.T) {
|
|||||||
CertKeyFile: filepath.Join(cfg.DataPath, "tls", "xxxgeneratedTLSCerts", "client.key"),
|
CertKeyFile: filepath.Join(cfg.DataPath, "tls", "xxxgeneratedTLSCerts", "client.key"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
desc: "Custom TLS mode verify-ca with no client certificates with certificate files content",
|
||||||
|
updated: updatedTime.Add(3 * time.Minute),
|
||||||
|
uid: "xxx",
|
||||||
|
jsonData: sqleng.JsonData{
|
||||||
|
Mode: "verify-ca",
|
||||||
|
ConfigurationMethod: "file-content",
|
||||||
|
},
|
||||||
|
secureJSONData: map[string]string{
|
||||||
|
"tlsCACert": "I am CA certification",
|
||||||
|
},
|
||||||
|
tlsSettings: tlsSettings{
|
||||||
|
Mode: "verify-ca",
|
||||||
|
ConfigurationMethod: "file-content",
|
||||||
|
RootCertFile: filepath.Join(cfg.DataPath, "tls", "xxxgeneratedTLSCerts", "root.crt"),
|
||||||
|
CertFile: "",
|
||||||
|
CertKeyFile: "",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "Custom TLS mode require with client certificates and no root certificate with certificate files content",
|
||||||
|
updated: updatedTime.Add(4 * time.Minute),
|
||||||
|
uid: "xxx",
|
||||||
|
jsonData: sqleng.JsonData{
|
||||||
|
Mode: "require",
|
||||||
|
ConfigurationMethod: "file-content",
|
||||||
|
},
|
||||||
|
secureJSONData: map[string]string{
|
||||||
|
"tlsClientCert": "I am client certification",
|
||||||
|
"tlsClientKey": "I am client key",
|
||||||
|
},
|
||||||
|
tlsSettings: tlsSettings{
|
||||||
|
Mode: "require",
|
||||||
|
ConfigurationMethod: "file-content",
|
||||||
|
RootCertFile: "",
|
||||||
|
CertFile: filepath.Join(cfg.DataPath, "tls", "xxxgeneratedTLSCerts", "client.crt"),
|
||||||
|
CertKeyFile: filepath.Join(cfg.DataPath, "tls", "xxxgeneratedTLSCerts", "client.key"),
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for _, tt := range testCases {
|
for _, tt := range testCases {
|
||||||
t.Run(tt.desc, func(t *testing.T) {
|
t.Run(tt.desc, func(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user