MySQL 9.1.0
Source Code Documentation
|
#include <config_generator.h>
Classes | |
struct | ExistingConfigOptions |
struct | Options |
struct | TLS_filenames |
struct | UndoCreateAccountList |
Public Member Functions | |
ConfigGenerator (std::ostream &out_stream=std::cout, std::ostream &err_stream=std::cerr, SysUserOperationsBase *sys_user_operations=SysUserOperations::instance()) | |
virtual | ~ConfigGenerator () |
void | init (const std::string &server_url, const std::map< std::string, std::string > &bootstrap_options) |
first part of the bootstrap process More... | |
bool | warn_on_no_ssl (const std::map< std::string, std::string > &options) |
logs warning and returns false if SSL mode is set to PREFERRED and SSL is not being used, true otherwise More... | |
void | bootstrap_system_deployment (const std::string &program_name, const std::string &config_file_path, const std::string &state_file_path, const std::map< std::string, std::string > &options, const std::map< std::string, std::vector< std::string > > &multivalue_options, const std::map< std::string, std::string > &default_paths) |
void | bootstrap_directory_deployment (const std::string &program_name, const std::string &directory, const std::map< std::string, std::string > &options, const std::map< std::string, std::vector< std::string > > &multivalue_options, const std::map< std::string, std::string > &default_paths) |
Create a self-contained deployment of the Router in a directory. More... | |
void | set_keyring_info (const KeyringInfo &keyring_info) |
void | set_plugin_folder (const std::string &val) |
void | set_file_owner (const std::map< std::string, std::string > &options, const std::string &owner) const |
Private Member Functions | |
void | parse_bootstrap_options (const std::map< std::string, std::string > &bootstrap_options) |
init() calls this to read and validate several command-line options; results are stored in member fields. More... | |
URI | parse_server_uri (const std::string &server_uri, const std::string &bootstrap_socket) |
init() calls this to validate and extract metadata server info from server URI, including user credentials. More... | |
void | connect_to_metadata_server (const URI &u, const std::string &bootstrap_socket, const std::map< std::string, std::string > &bootstrap_options) |
init() calls this to connect to metadata server; sets mysql_ (connection) object. More... | |
void | init_gr_data (const URI &u, const std::string &bootstrap_socket) |
init() calls this to set GR-related member fields. More... | |
Options | fill_options (const std::map< std::string, std::string > &user_options, const std::map< std::string, std::string > &default_paths, const ExistingConfigOptions &existing_config_options) |
void | create_start_script (const std::string &program_name, const std::string &directory, bool interactive_master_key, const std::map< std::string, std::string > &options) |
void | create_stop_script (const std::string &directory, const std::map< std::string, std::string > &options) |
virtual void | set_script_permissions (const std::string &script_path, const std::map< std::string, std::string > &options) |
std::string | bootstrap_deployment (const std::string &program_name, std::ofstream &config_file, std::ofstream &state_file, const mysql_harness::Path &config_file_path, const mysql_harness::Path &state_file_path, const std::string &name, const std::map< std::string, std::string > &options, const std::map< std::string, std::vector< std::string > > &multivalue_options, const std::map< std::string, std::string > &default_paths, bool directory_deployment, AutoCleaner &auto_clean) |
std::tuple< std::string > | try_bootstrap_deployment (uint32_t &router_id, std::string &username, std::string &password, const std::string &router_name, const ClusterInfo &cluster_info, const std::map< std::string, std::string > &user_options, const std::map< std::string, std::vector< std::string > > &multivalue_options, const Options &options) |
void | create_config (std::ostream &config_file, std::ostream &state_file, uint32_t router_id, const std::string &router_name, const std::string &system_username, const ClusterInfo &cluster_info, const std::string &username, const Options &options, const std::map< std::string, std::string > &default_paths, const std::map< std::string, std::string > &config_overwrites, const std::string &state_file_name, const bool full) |
void | print_bootstrap_start_msg (uint32_t router_id, bool directory_deployment, const mysql_harness::Path &config_file_path) |
std::string | get_bootstrap_report_text (const std::string &program_name, const std::string &config_file_name, const std::string &router_name, const std::string &metadata_cluster, const std::string &cluster_type_name, const std::string &hostname, bool is_system_deployment, const Options &options) |
void | set_log_file_permissions (const std::map< std::string, std::string > &default_paths, const std::map< std::string, std::string > &user_options, const Options &options) |
void | undo_create_user_for_new_accounts () noexcept |
Deletes Router accounts just created. More... | |
std::string | create_router_accounts (const std::map< std::string, std::string > &user_options, const std::set< std::string > &hostnames, const std::string &username, const std::string &password, bool password_change_ok) |
Creates Router accounts. More... | |
std::string | create_accounts_with_compliant_password (const std::map< std::string, std::string > &user_options, const std::string &username, const std::set< std::string > &hostnames, const std::string &password, bool password_change_ok, bool if_not_exists) |
Creates Router account with compliant password. More... | |
void | create_accounts (const std::string &username, const std::set< std::string > &hostnames, const std::string &password, bool if_not_exists=false) |
Creates Router account (low-level function) More... | |
void | create_users (const std::string &username, const std::set< std::string > &hostnames, const std::string &password, bool if_not_exists) |
void | throw_account_exists (const MySQLSession::Error &e, const std::string &username) |
std::set< std::string > | get_hostnames_of_created_accounts (const std::string &username, const std::set< std::string > &hostnames, bool if_not_exists) |
void | give_grants_to_users (const std::string &new_accounts) |
std::string | make_account_list (const std::string username, const std::set< std::string > &hostnames) |
ExistingConfigOptions | get_options_from_config_if_it_exists (const std::string &config_file_path, const mysqlrouter::ClusterInfo &cluster_info, bool forcing_overwrite) |
Get selected configuration options from the existing Router configuration file. More... | |
void | update_router_info (uint32_t router_id, const Options &options) |
bool | backup_config_file_if_different (const mysql_harness::Path &config_path, const std::string &new_file_path, const std::map< std::string, std::string > &options, AutoCleaner *auto_cleaner=nullptr) |
void | set_keyring_info_real_paths (std::map< std::string, std::string > &options, const mysql_harness::Path &path) |
void | store_credentials_in_keyring (AutoCleaner &auto_clean, const std::map< std::string, std::string > &user_options, uint32_t router_id, const std::string &username, const std::string &password, Options &options) |
std::string | fetch_password_from_keyring (const std::string &username, uint32_t router_id) |
void | init_keyring_and_master_key (AutoCleaner &auto_clean, const std::map< std::string, std::string > &user_options, uint32_t router_id) |
void | init_keyring_file (uint32_t router_id, bool create_if_needed=true) |
void | ensure_router_id_is_ours (uint32_t &router_id, const std::string &hostname_override) |
uint32_t | register_router (const std::string &router_name, const std::string &hostname_override, bool force) |
void | verify_router_account (const std::string &username, const std::string &password, bool strict) |
void | prepare_ssl_certificate_files (const std::map< std::string, std::string > &user_options, const std::map< std::string, std::string > &default_paths, AutoCleaner *auto_cleaner) const |
Prepare X.509 certificates for the Router. More... | |
bool | datadir_contains_allowed_files (const mysql_harness::Directory &dir) const |
Check if datadir directory contains only files that are allowed before the bootstrap. More... | |
Static Private Member Functions | |
static std::set< std::string > | get_account_host_args (const std::map< std::string, std::vector< std::string > > &multivalue_options) noexcept |
Finds all hostnames given on command-line. More... | |
static void | set_ssl_options (MySQLSession *sess, const std::map< std::string, std::string > &options) |
Private Attributes | |
std::unique_ptr< MySQLSession > | mysql_ |
std::unique_ptr< ClusterMetadata > | metadata_ |
int | connect_timeout_ |
int | read_timeout_ |
std::string | cluster_specific_id_ |
std::string | cluster_initial_hostname_ |
unsigned int | cluster_initial_port_ |
std::string | cluster_initial_username_ |
std::string | cluster_initial_password_ |
std::string | cluster_initial_socket_ |
KeyringInfo | keyring_info_ |
bool | keyring_initialized_ = false |
std::ostream & | out_stream_ |
std::ostream & | err_stream_ |
struct mysqlrouter::ConfigGenerator::UndoCreateAccountList | undo_create_account_list_ |
const struct mysqlrouter::ConfigGenerator::TLS_filenames | tls_filenames_ |
SysUserOperationsBase * | sys_user_operations_ |
mysqlrouter::MetadataSchemaVersion | schema_version_ |
std::string | plugin_folder_ |
ConfigGenerator::ConfigGenerator | ( | std::ostream & | out_stream = std::cout , |
std::ostream & | err_stream = std::cerr , |
||
SysUserOperationsBase * | sys_user_operations = SysUserOperations::instance() |
||
) |
|
virtualdefault |
|
private |
|
private |
void ConfigGenerator::bootstrap_directory_deployment | ( | const std::string & | program_name, |
const std::string & | directory, | ||
const std::map< std::string, std::string > & | options, | ||
const std::map< std::string, std::vector< std::string > > & | multivalue_options, | ||
const std::map< std::string, std::string > & | default_paths | ||
) |
Create a self-contained deployment of the Router in a directory.
void ConfigGenerator::bootstrap_system_deployment | ( | const std::string & | program_name, |
const std::string & | config_file_path, | ||
const std::string & | state_file_path, | ||
const std::map< std::string, std::string > & | options, | ||
const std::map< std::string, std::vector< std::string > > & | multivalue_options, | ||
const std::map< std::string, std::string > & | default_paths | ||
) |
|
private |
init() calls this to connect to metadata server; sets mysql_ (connection) object.
u | parsed server URL (–bootstrap|-B argument) |
bootstrap_socket | bootstrap (unix) socket (–bootstrap-socket argumenent) |
bootstrap_options | bootstrap command-line options |
std::runtime_error | |
std::logic_error |
|
private |
Creates Router account (low-level function)
Creates Router account using CREATE USER [IF NOT EXISTS] and gives it GRANTs.
username | Router account to be created - the username part |
hostnames | Router accounts to be created - the hostnames part |
password | Password for the account |
if_not_exists | if true, CREATE USER IF NOT EXISTS will be used instead of CREATE USER |
std::logic_error | on not connected password_too_weak on Server not liking the password account_exists if running without IF NOT EXISTS and account exists already MySQLSession::Error on other (unexpected) SQL error |
|
private |
Creates Router account with compliant password.
Creates Router account with a (self-generated) password that will pass Server's password policy. It first tries creating a hashed password using mysql_native_password plugin. If that fails, it falls back to using plaintext password, which the Server may reject for not being strong enough. If that's the case, it will generate another password and try again 2 more times (for a total of 3 password-generation attempts), after which it will give up.
user_options | key/value map of bootstrap config options |
username | Router account to be created - the username part |
hostnames | Router accounts to be created - the hostname part |
password | Password for the account |
password_change_ok | password is allowed to be changed if needed |
if_not_exists | if true, CREATE USER IF NOT EXISTS will be used instead of CREATE USER |
std::logic_error | on not connected std::runtime_error on bad password MySQLSession::Error on other (unexpected) SQL error |
|
private |
|
private |
Creates Router accounts.
create account to be used by Router.
Creates Router accounts for all hostnames (ie. someuser@host1
, someuser@host2
, someuser@%
, etc). It will create such accounts for all hosts that appear in hostnames_cmdline, but not in hostnames_db.
user_options | key/value map of bootstrap config options |
hostnames | hostnames provided as –account-host arguments |
username | Router account to be created (without the hostname part) |
password_change_ok | password is allowed to be changed if needed |
password | Router account password, will be overwritten if empty |
std::logic_error | on not connected std::runtime_error on bad password or Server's password policy changing during bootstrap MySQLSession::Error on other (unexpected) SQL error |
<host>
part of <user>@<host>
will be %, unless user specified otherwise using –account-host switch. Multiple –account-host switches are allowed.
|
private |
|
private |
|
private |
|
private |
Check if datadir directory contains only files that are allowed before the bootstrap.
[in] | dir | Data directory representation. |
false | - datadir contains files that are not allowed before the bootstrap. |
true | - datadir does not contain files that are not allowed before the bootstrap. |
|
private |
|
private |
|
private |
|
staticprivatenoexcept |
Finds all hostnames given on command-line.
MySQL accounts are of form <username>@<hostname>
. This function returns all <hostname>
parts that were provided via –account-host switches
multivalue_options | key/list-of-values map of bootstrap config; carries –account-host inside |
|
private |
|
private |
|
private |
Get selected configuration options from the existing Router configuration file.
This function returns Router's id and SQL user for cluster cluster_name
, if it finds them in config file and they seem valid. If they're missing or incomplete, function will return empty values for them (0 or ""), giving a green light to generate new ones. Finally, if it detects that the cluster name is off or missing, it will throw or return {0, ""}, depending on forcing_overwrite
.
config_file_path | /path/to/config/file |
cluster_info | Information about the Cluster for which Router id and user should be returned |
forcing_overwrite | Action to take on unexpected cluster in config, see function description |
std::runtime_error | on invalid router_id or metadata_cluster |
|
private |
void ConfigGenerator::init | ( | const std::string & | server_url, |
const std::map< std::string, std::string > & | bootstrap_options | ||
) |
first part of the bootstrap process
This function does a lot of initialisation before bootstrap starts making changes.
server_url | server to bootstrap from |
bootstrap_options | bootstrap options |
std::runtime_error |
|
private |
init() calls this to set GR-related member fields.
u | parsed server URL (–bootstrap|-B argument) |
bootstrap_socket | bootstrap (unix) socket (–bootstrap-socket argumenent) |
TODO |
|
private |
|
private |
|
private |
|
private |
init() calls this to read and validate several command-line options; results are stored in member fields.
bootstrap_options | options map to process |
std::runtime_error | on an invalid option |
|
private |
init() calls this to validate and extract metadata server info from server URI, including user credentials.
It will also:
server_uri | server URI (–bootstrap|-B argument) |
bootstrap_socket | bootstrap (unix) socket (–bootstrap-socket argumenent) |
std::runtime_error | on an invalid data |
|
private |
Prepare X.509 certificates for the Router.
If user provides Router certificate and key files they are used in the first place so no action is taken in this method. If there are no existing certificate files then CA certificate and key along with Router certificate and key will be created.
[in] | user_options | Key/value map of bootstrap config options. |
[in] | default_paths | Map of predefined default paths. |
[in,out] | auto_cleaner | Automatic file cleanup object that guarantees file cleanup if bootstrap fails at any point. |
std::runtime_error | Data directory contains some certificate files but Router certificate and/or key is missing. |
|
private |
|
private |
void ConfigGenerator::set_file_owner | ( | const std::map< std::string, std::string > & | options, |
const std::string & | owner | ||
) | const |
|
inline |
|
private |
|
private |
|
inline |
|
privatevirtual |
|
staticprivate |
|
private |
|
private |
|
private |
|
privatenoexcept |
Deletes Router accounts just created.
This method runs as a cleanup after something goes wrong. Its purpose is to undo CREATE USER [IF NOT EXISTS] for accounts that got created during bootstrap. Note that it will drop only those accounts which did not exist prior to bootstrap (it may be a subset of account names passed to CREATE USER [IF NOT EXISTS]). If it is not able to determine what this (sub)set is, it will not drop anything - instead it will advise user on how to clean those up manually.
|
private |
|
private |
bool ConfigGenerator::warn_on_no_ssl | ( | const std::map< std::string, std::string > & | options | ) |
logs warning and returns false if SSL mode is set to PREFERRED and SSL is not being used, true otherwise
options | map of commandline options |
std::runtime_error |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |