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

fix: add cmd line mysql ssl options, fixes RHOAIENG-3337 #4

Merged
merged 1 commit into from
Feb 20, 2024
Merged
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
56 changes: 56 additions & 0 deletions ml_metadata/metadata_store/metadata_store_server_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ bool ParseMetadataStoreServerConfigOrDie(
bool ParseMySQLFlagsBasedServerConfigOrDie(
const std::string& host, const int port, const std::string& database,
const std::string& user, const std::string& password,
const std::string& sslcert, const std::string& sslkey,
const std::string& sslrootcert, const std::string& sslcapath,
const std::string& sslcipher, const bool verify_server_cert,
const bool enable_database_upgrade,
const int64_t downgrade_db_schema_version,
ml_metadata::MetadataStoreServerConfig* server_config) {
Expand All @@ -128,6 +131,30 @@ bool ParseMySQLFlagsBasedServerConfigOrDie(
config->set_database(database);
config->set_user(user);
config->set_password(password);
bool has_ssl_config;
if (!sslcert.empty()) {
has_ssl_config = true;
config->mutable_ssl_options()->set_cert(sslcert);
}
if (!sslkey.empty()) {
has_ssl_config = true;
config->mutable_ssl_options()->set_key(sslkey);
}
if (!sslrootcert.empty()) {
has_ssl_config = true;
config->mutable_ssl_options()->set_ca(sslrootcert);
}
if (!sslcapath.empty()) {
has_ssl_config = true;
config->mutable_ssl_options()->set_capath(sslcapath);
}
if (!sslcipher.empty()) {
has_ssl_config = true;
config->mutable_ssl_options()->set_cipher(sslcipher);
}
if (has_ssl_config) {
config->mutable_ssl_options()->set_verify_server_cert(verify_server_cert);
}

CHECK(!enable_database_upgrade || downgrade_db_schema_version < 0)
<< "Both --enable_database_upgraded=true and downgrade_db_schema_version "
Expand Down Expand Up @@ -328,6 +355,23 @@ DEFINE_string(mysql_config_user, "",
"The mysql user name to use (Optional parameter)");
DEFINE_string(mysql_config_password, "",
"The mysql user password to use (Optional parameter)");
DEFINE_string(mysql_config_sslcert, "",
"This parameter specifies the file name of the client SSL certificate.");
DEFINE_string(mysql_config_sslkey, "",
"This parameter specifies the location for the secret key used for the "
"client certificate.");
DEFINE_string(mysql_config_sslrootcert, "",
"This parameter specifies the name of a file containing SSL "
"certificate authority (CA) certificate(s).");
DEFINE_string(mysql_config_sslcapath, "",
"This parameter specifies path name of the directory "
"that contains trusted SSL CA certificates.");
DEFINE_string(mysql_config_sslcipher, "",
"This parameter specifies the list of permissible ciphers for "
"SSL encryption.");
DEFINE_bool(mysql_config_verify_server_cert, false,
"This parameter enables verification of the server certificate "
" against the host name used when connecting to the server.");
Comment on lines +372 to +374
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
DEFINE_bool(mysql_config_verify_server_cert, false,
"This parameter enables verification of the server certificate "
" against the host name used when connecting to the server.");
DEFINE_bool(mysql_config_verify_server_cert, false,
"When certificates are provided, this parameter enables verification of the server certificate "
" against the host name used when connecting to the server.");

I know we discussed this, just re-reporting for archival purposes.


// PostgreSQL config command line options
DEFINE_string(postgres_config_host, "",
Expand Down Expand Up @@ -400,6 +444,12 @@ BuildDefaultConnectionConfig() {
(FLAGS_mysql_config_database),
(FLAGS_mysql_config_user),
(FLAGS_mysql_config_password),
(FLAGS_mysql_config_sslcert),
(FLAGS_mysql_config_sslkey),
(FLAGS_mysql_config_sslrootcert),
(FLAGS_mysql_config_sslcapath),
(FLAGS_mysql_config_sslcipher),
(FLAGS_mysql_config_verify_server_cert),
(FLAGS_enable_database_upgrade),
(FLAGS_downgrade_db_schema_version), &server_config)) {
LOG(WARNING) << "The connection_config is not given. Using in memory fake "
Expand Down Expand Up @@ -440,6 +490,12 @@ BuildMySQLConnectionConfig() {
(FLAGS_mysql_config_database),
(FLAGS_mysql_config_user),
(FLAGS_mysql_config_password),
(FLAGS_mysql_config_sslcert),
(FLAGS_mysql_config_sslkey),
(FLAGS_mysql_config_sslrootcert),
(FLAGS_mysql_config_sslcapath),
(FLAGS_mysql_config_sslcipher),
(FLAGS_mysql_config_verify_server_cert),
(FLAGS_enable_database_upgrade),
(FLAGS_downgrade_db_schema_version), &server_config)) {
return server_config;
Expand Down