mirror of https://github.com/Icinga/icinga2.git
Add SSL support for the IdoMysqlConnection feature
fixes #9725 Signed-off-by: Michael Friedrich <michael.friedrich@netways.de>
This commit is contained in:
parent
79c1e883d1
commit
7050529976
|
@ -691,6 +691,12 @@ Configuration Attributes:
|
||||||
user |**Optional.** MySQL database user with read/write permission to the icinga database. Defaults to "icinga".
|
user |**Optional.** MySQL database user with read/write permission to the icinga database. Defaults to "icinga".
|
||||||
password |**Optional.** MySQL database user's password. Defaults to "icinga".
|
password |**Optional.** MySQL database user's password. Defaults to "icinga".
|
||||||
database |**Optional.** MySQL database name. Defaults to "icinga".
|
database |**Optional.** MySQL database name. Defaults to "icinga".
|
||||||
|
enable\_ssl |**Optional.** Use SSL. Defaults to false. Change to `true` in case you want to use any of the SSL options.
|
||||||
|
ssl\_key |**Optional.** MySQL SSL client key file path.
|
||||||
|
ssl\_cert |**Optional.** MySQL SSL certificate file path.
|
||||||
|
ssl\_ca |**Optional.** MySQL SSL certificate authority certificate file path.
|
||||||
|
ssl\_capath |**Optional.** MySQL SSL trusted SSL CA certificates in PEM format directory path.
|
||||||
|
ssl\_cipher |**Optional.** MySQL SSL list of allowed ciphers.
|
||||||
table\_prefix |**Optional.** MySQL database table prefix. Defaults to "icinga\_".
|
table\_prefix |**Optional.** MySQL database table prefix. Defaults to "icinga\_".
|
||||||
instance\_name |**Optional.** Unique identifier for the local Icinga 2 instance. Defaults to "default".
|
instance\_name |**Optional.** Unique identifier for the local Icinga 2 instance. Defaults to "default".
|
||||||
instance\_description|**Optional.** Description for the Icinga 2 instance.
|
instance\_description|**Optional.** Description for the Icinga 2 instance.
|
||||||
|
|
|
@ -187,7 +187,10 @@ void IdoMysqlConnection::Reconnect(void)
|
||||||
ClearIDCache();
|
ClearIDCache();
|
||||||
|
|
||||||
String ihost, isocket_path, iuser, ipasswd, idb;
|
String ihost, isocket_path, iuser, ipasswd, idb;
|
||||||
|
String isslKey, isslCert, isslCa, isslCaPath, isslCipher;
|
||||||
const char *host, *socket_path, *user , *passwd, *db;
|
const char *host, *socket_path, *user , *passwd, *db;
|
||||||
|
const char *sslKey, *sslCert, *sslCa, *sslCaPath, *sslCipher;
|
||||||
|
bool enableSsl;
|
||||||
long port;
|
long port;
|
||||||
|
|
||||||
ihost = GetHost();
|
ihost = GetHost();
|
||||||
|
@ -196,6 +199,13 @@ void IdoMysqlConnection::Reconnect(void)
|
||||||
ipasswd = GetPassword();
|
ipasswd = GetPassword();
|
||||||
idb = GetDatabase();
|
idb = GetDatabase();
|
||||||
|
|
||||||
|
enableSsl = GetEnableSsl();
|
||||||
|
isslKey = GetSslKey();
|
||||||
|
isslCert = GetSslCert();
|
||||||
|
isslCa = GetSslCa();
|
||||||
|
isslCaPath = GetSslCapath();
|
||||||
|
isslCipher = GetSslCipher();
|
||||||
|
|
||||||
host = (!ihost.IsEmpty()) ? ihost.CStr() : NULL;
|
host = (!ihost.IsEmpty()) ? ihost.CStr() : NULL;
|
||||||
port = GetPort();
|
port = GetPort();
|
||||||
socket_path = (!isocket_path.IsEmpty()) ? isocket_path.CStr() : NULL;
|
socket_path = (!isocket_path.IsEmpty()) ? isocket_path.CStr() : NULL;
|
||||||
|
@ -203,6 +213,12 @@ void IdoMysqlConnection::Reconnect(void)
|
||||||
passwd = (!ipasswd.IsEmpty()) ? ipasswd.CStr() : NULL;
|
passwd = (!ipasswd.IsEmpty()) ? ipasswd.CStr() : NULL;
|
||||||
db = (!idb.IsEmpty()) ? idb.CStr() : NULL;
|
db = (!idb.IsEmpty()) ? idb.CStr() : NULL;
|
||||||
|
|
||||||
|
sslKey = (!isslKey.IsEmpty()) ? isslKey.CStr() : NULL;
|
||||||
|
sslCert = (!isslCert.IsEmpty()) ? isslCert.CStr() : NULL;
|
||||||
|
sslCa = (!isslCa.IsEmpty()) ? isslCa.CStr() : NULL;
|
||||||
|
sslCaPath = (!isslCaPath.IsEmpty()) ? isslCaPath.CStr() : NULL;
|
||||||
|
sslCipher = (!isslCipher.IsEmpty()) ? isslCipher.CStr() : NULL;
|
||||||
|
|
||||||
/* connection */
|
/* connection */
|
||||||
if (!mysql_init(&m_Connection)) {
|
if (!mysql_init(&m_Connection)) {
|
||||||
Log(LogCritical, "IdoMysqlConnection")
|
Log(LogCritical, "IdoMysqlConnection")
|
||||||
|
@ -211,10 +227,13 @@ void IdoMysqlConnection::Reconnect(void)
|
||||||
BOOST_THROW_EXCEPTION(std::bad_alloc());
|
BOOST_THROW_EXCEPTION(std::bad_alloc());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (enableSsl)
|
||||||
|
mysql_ssl_set(&m_Connection, sslKey, sslCert, sslCa, sslCaPath, sslCipher);
|
||||||
|
|
||||||
if (!mysql_real_connect(&m_Connection, host, user, passwd, db, port, socket_path, CLIENT_FOUND_ROWS | CLIENT_MULTI_STATEMENTS)) {
|
if (!mysql_real_connect(&m_Connection, host, user, passwd, db, port, socket_path, CLIENT_FOUND_ROWS | CLIENT_MULTI_STATEMENTS)) {
|
||||||
Log(LogCritical, "IdoMysqlConnection")
|
Log(LogCritical, "IdoMysqlConnection")
|
||||||
<< "Connection to database '" << db << "' with user '" << user << "' on '" << host << ":" << port
|
<< "Connection to database '" << db << "' with user '" << user << "' on '" << host << ":" << port
|
||||||
<< "' failed: \"" << mysql_error(&m_Connection) << "\"";
|
<< "' " << (enableSsl ? "(SSL enabled) " : "") << "failed: \"" << mysql_error(&m_Connection) << "\"";
|
||||||
|
|
||||||
BOOST_THROW_EXCEPTION(std::runtime_error(mysql_error(&m_Connection)));
|
BOOST_THROW_EXCEPTION(std::runtime_error(mysql_error(&m_Connection)));
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,6 +42,12 @@ class IdoMysqlConnection : DbConnection
|
||||||
[config] String database {
|
[config] String database {
|
||||||
default {{{ return "icinga"; }}}
|
default {{{ return "icinga"; }}}
|
||||||
};
|
};
|
||||||
|
[config] bool enable_ssl;
|
||||||
|
[config] String ssl_key;
|
||||||
|
[config] String ssl_cert;
|
||||||
|
[config] String ssl_ca;
|
||||||
|
[config] String ssl_capath;
|
||||||
|
[config] String ssl_cipher;
|
||||||
[config] String instance_name {
|
[config] String instance_name {
|
||||||
default {{{ return "default"; }}}
|
default {{{ return "default"; }}}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue