mirror of https://github.com/Icinga/icinga2.git
parent
181b91b759
commit
e424017c15
|
@ -131,14 +131,14 @@ int NodeSetupCommand::SetupMaster(const boost::program_options::variables_map& v
|
||||||
cn = vm["cn"].as<std::string>();
|
cn = vm["cn"].as<std::string>();
|
||||||
|
|
||||||
/* check whether the user wants to generate a new certificate or not */
|
/* check whether the user wants to generate a new certificate or not */
|
||||||
String existing_path = ApiListener::GetCertsDir() + "/" + cn + ".crt";
|
String existingPath = ApiListener::GetCertsDir() + "/" + cn + ".crt";
|
||||||
|
|
||||||
Log(LogInformation, "cli")
|
Log(LogInformation, "cli")
|
||||||
<< "Checking for existing certificates for common name '" << cn << "'...";
|
<< "Checking in existing certificates for common name '" << cn << "'...";
|
||||||
|
|
||||||
if (Utility::PathExists(existing_path)) {
|
if (Utility::PathExists(existingPath)) {
|
||||||
Log(LogWarning, "cli")
|
Log(LogWarning, "cli")
|
||||||
<< "Certificate '" << existing_path << "' for CN '" << cn << "' already exists. Not generating new certificate.";
|
<< "Certificate '" << existingPath << "' for CN '" << cn << "' already exists. Not generating new certificate.";
|
||||||
} else {
|
} else {
|
||||||
Log(LogInformation, "cli")
|
Log(LogInformation, "cli")
|
||||||
<< "Certificates not yet generated. Running 'api setup' now.";
|
<< "Certificates not yet generated. Running 'api setup' now.";
|
||||||
|
@ -157,13 +157,11 @@ int NodeSetupCommand::SetupMaster(const boost::program_options::variables_map& v
|
||||||
}
|
}
|
||||||
|
|
||||||
/* write zones.conf and update with zone + endpoint information */
|
/* write zones.conf and update with zone + endpoint information */
|
||||||
|
|
||||||
Log(LogInformation, "cli", "Generating zone and object configuration.");
|
Log(LogInformation, "cli", "Generating zone and object configuration.");
|
||||||
|
|
||||||
NodeUtility::GenerateNodeMasterIcingaConfig();
|
NodeUtility::GenerateNodeMasterIcingaConfig();
|
||||||
|
|
||||||
/* update the ApiListener config - SetupMaster() will always enable it */
|
/* update the ApiListener config - SetupMaster() will always enable it */
|
||||||
|
|
||||||
Log(LogInformation, "cli", "Updating the APIListener feature.");
|
Log(LogInformation, "cli", "Updating the APIListener feature.");
|
||||||
|
|
||||||
String apipath = FeatureUtility::GetFeaturesAvailablePath() + "/api.conf";
|
String apipath = FeatureUtility::GetFeaturesAvailablePath() + "/api.conf";
|
||||||
|
@ -263,7 +261,8 @@ int NodeSetupCommand::SetupNode(const boost::program_options::variables_map& vm,
|
||||||
/* require master host information for auto-signing requests */
|
/* require master host information for auto-signing requests */
|
||||||
|
|
||||||
if (!vm.count("master_host")) {
|
if (!vm.count("master_host")) {
|
||||||
Log(LogCritical, "cli", "Please pass the master host connection information for auto-signing using '--master_host <host>'");
|
Log(LogCritical, "cli", "Please pass the master host connection information for auto-signing using '--master_host <host>'. This can also be a direct parent satellite since 2.8.");
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -279,13 +278,13 @@ int NodeSetupCommand::SetupNode(const boost::program_options::variables_map& vm,
|
||||||
master_port = tokens[1];
|
master_port = tokens[1];
|
||||||
|
|
||||||
Log(LogInformation, "cli")
|
Log(LogInformation, "cli")
|
||||||
<< "Verifying master host connection information: host '" << master_host << "', port '" << master_port << "'.";
|
<< "Verifying parent host connection information: host '" << master_host << "', port '" << master_port << "'.";
|
||||||
|
|
||||||
/* trusted cert must be passed (retrieved by the user with 'pki save-cert' before) */
|
/* trusted cert must be passed (retrieved by the user with 'pki save-cert' before) */
|
||||||
|
|
||||||
if (!vm.count("trustedcert")) {
|
if (!vm.count("trustedcert")) {
|
||||||
Log(LogCritical, "cli")
|
Log(LogCritical, "cli")
|
||||||
<< "Please pass the trusted cert retrieved from the master\n"
|
<< "Please pass the trusted cert retrieved from the parent node (master or satellite)\n"
|
||||||
<< "(Hint: 'icinga2 pki save-cert --host <masterhost> --port <5665> --key local.key --cert local.crt --trustedcert master.crt').";
|
<< "(Hint: 'icinga2 pki save-cert --host <masterhost> --port <5665> --key local.key --cert local.crt --trustedcert master.crt').";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -337,10 +336,10 @@ int NodeSetupCommand::SetupNode(const boost::program_options::variables_map& vm,
|
||||||
<< "Cannot set ownership for user '" << user << "' group '" << group << "' on file '" << key << "'. Verify it yourself!";
|
<< "Cannot set ownership for user '" << user << "' group '" << group << "' on file '" << key << "'. Verify it yourself!";
|
||||||
}
|
}
|
||||||
|
|
||||||
Log(LogInformation, "cli", "Requesting a signed certificate from the master.");
|
Log(LogInformation, "cli", "Requesting a signed certificate from the parent Icinga node.");
|
||||||
|
|
||||||
if (PkiUtility::RequestCertificate(master_host, master_port, key, cert, ca, trustedcert, ticket) != 0) {
|
if (PkiUtility::RequestCertificate(master_host, master_port, key, cert, ca, trustedcert, ticket) != 0) {
|
||||||
Log(LogCritical, "cli", "Failed to request certificate from Icinga 2 master.");
|
Log(LogCritical, "cli", "Failed to request certificate from parent Icinga node.");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -431,7 +430,7 @@ int NodeSetupCommand::SetupNode(const boost::program_options::variables_map& vm,
|
||||||
/* update constants.conf with NodeName = CN */
|
/* update constants.conf with NodeName = CN */
|
||||||
if (cn != Utility::GetFQDN()) {
|
if (cn != Utility::GetFQDN()) {
|
||||||
Log(LogWarning, "cli")
|
Log(LogWarning, "cli")
|
||||||
<< "CN '" << cn << "' does not match the default FQDN '" << Utility::GetFQDN() << "'. Requires update for NodeName constant in constants.conf!";
|
<< "CN '" << cn << "' does not match the default FQDN '" << Utility::GetFQDN() << "'. Requires an update for the NodeName constant in constants.conf!";
|
||||||
}
|
}
|
||||||
|
|
||||||
Log(LogInformation, "cli", "Updating constants.conf.");
|
Log(LogInformation, "cli", "Updating constants.conf.");
|
||||||
|
|
|
@ -78,12 +78,10 @@ int NodeWizardCommand::Run(const boost::program_options::variables_map& vm,
|
||||||
std::cout << ConsoleColorTag(Console_Bold | Console_ForegroundBlue)
|
std::cout << ConsoleColorTag(Console_Bold | Console_ForegroundBlue)
|
||||||
<< "Welcome to the Icinga 2 Setup Wizard!\n"
|
<< "Welcome to the Icinga 2 Setup Wizard!\n"
|
||||||
<< "\n"
|
<< "\n"
|
||||||
<< "We'll guide you through all required configuration details.\n"
|
<< "We will guide you through all required configuration details.\n"
|
||||||
<< "\n"
|
<< "\n"
|
||||||
<< ConsoleColorTag(Console_Normal);
|
<< ConsoleColorTag(Console_Normal);
|
||||||
|
|
||||||
//TODO: Add sort of bash completion to path input?
|
|
||||||
|
|
||||||
/* 0. master or node setup?
|
/* 0. master or node setup?
|
||||||
* 1. Ticket
|
* 1. Ticket
|
||||||
* 2. Master information for autosigning
|
* 2. Master information for autosigning
|
||||||
|
@ -100,11 +98,9 @@ int NodeWizardCommand::Run(const boost::program_options::variables_map& vm,
|
||||||
*/
|
*/
|
||||||
|
|
||||||
std::string answer;
|
std::string answer;
|
||||||
bool is_node_setup = true;
|
/* master or satellite/client setup */
|
||||||
|
|
||||||
/* master or node setup */
|
|
||||||
std::cout << ConsoleColorTag(Console_Bold)
|
std::cout << ConsoleColorTag(Console_Bold)
|
||||||
<< "Please specify if this is a satellite setup "
|
<< "Please specify if this is a satellite/client setup "
|
||||||
<< "('n' installs a master setup)" << ConsoleColorTag(Console_Normal)
|
<< "('n' installs a master setup)" << ConsoleColorTag(Console_Normal)
|
||||||
<< " [Y/n]: ";
|
<< " [Y/n]: ";
|
||||||
std::getline (std::cin, answer);
|
std::getline (std::cin, answer);
|
||||||
|
@ -113,12 +109,36 @@ int NodeWizardCommand::Run(const boost::program_options::variables_map& vm,
|
||||||
|
|
||||||
String choice = answer;
|
String choice = answer;
|
||||||
|
|
||||||
if (choice.Contains("n"))
|
std::cout << "\n";
|
||||||
is_node_setup = false;
|
|
||||||
|
|
||||||
if (is_node_setup) {
|
int res = 0;
|
||||||
/* node setup part */
|
|
||||||
std::cout << "Starting the Node setup routine...\n";
|
if (choice.Contains("n"))
|
||||||
|
res = MasterSetup();
|
||||||
|
else
|
||||||
|
res = ClientSetup();
|
||||||
|
|
||||||
|
if (res != 0)
|
||||||
|
return res;
|
||||||
|
|
||||||
|
std::cout << "\n";
|
||||||
|
std::cout << ConsoleColorTag(Console_Bold | Console_ForegroundGreen)
|
||||||
|
<< "Done.\n\n"
|
||||||
|
<< ConsoleColorTag(Console_Normal);
|
||||||
|
|
||||||
|
std::cout << ConsoleColorTag(Console_Bold | Console_ForegroundRed)
|
||||||
|
<< "Now restart your Icinga 2 daemon to finish the installation!\n\n"
|
||||||
|
<< ConsoleColorTag(Console_Normal);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int NodeWizardCommand::ClientSetup(void) const
|
||||||
|
{
|
||||||
|
std::string answer;
|
||||||
|
String choice;
|
||||||
|
|
||||||
|
std::cout << "Starting the Client/Satellite setup routine...\n";
|
||||||
|
|
||||||
/* CN */
|
/* CN */
|
||||||
std::cout << ConsoleColorTag(Console_Bold)
|
std::cout << ConsoleColorTag(Console_Bold)
|
||||||
|
@ -136,30 +156,30 @@ int NodeWizardCommand::Run(const boost::program_options::variables_map& vm,
|
||||||
|
|
||||||
std::vector<std::string> endpoints;
|
std::vector<std::string> endpoints;
|
||||||
|
|
||||||
String endpoint_buffer;
|
String endpointBuffer;
|
||||||
|
|
||||||
std::cout << ConsoleColorTag(Console_Bold)
|
std::cout << ConsoleColorTag(Console_Bold)
|
||||||
<< "Please specify the master endpoint(s) this node should connect to:"
|
<< "Please specify the parent endpoint(s) (master or satellite) where this node should connect to:"
|
||||||
<< ConsoleColorTag(Console_Normal) << "\n";
|
<< ConsoleColorTag(Console_Normal) << "\n";
|
||||||
String master_endpoint_name;
|
String parentEndpointName;
|
||||||
|
|
||||||
wizard_endpoint_loop_start:
|
wizard_endpoint_loop_start:
|
||||||
|
|
||||||
std::cout << ConsoleColorTag(Console_Bold)
|
std::cout << ConsoleColorTag(Console_Bold)
|
||||||
<< "Master Common Name" << ConsoleColorTag(Console_Normal)
|
<< "Master/Satellite Common Name" << ConsoleColorTag(Console_Normal)
|
||||||
<< " (CN from your master setup): ";
|
<< " (CN from your master/satellite node): ";
|
||||||
|
|
||||||
std::getline(std::cin, answer);
|
std::getline(std::cin, answer);
|
||||||
|
|
||||||
if (answer.empty()) {
|
if (answer.empty()) {
|
||||||
Log(LogWarning, "cli", "Master CN is required! Please retry.");
|
Log(LogWarning, "cli", "Master/Satellite CN is required! Please retry.");
|
||||||
goto wizard_endpoint_loop_start;
|
goto wizard_endpoint_loop_start;
|
||||||
}
|
}
|
||||||
|
|
||||||
endpoint_buffer = answer;
|
endpointBuffer = answer;
|
||||||
endpoint_buffer = endpoint_buffer.Trim();
|
endpointBuffer = endpointBuffer.Trim();
|
||||||
|
|
||||||
std::cout << "Do you want to establish a connection to the master "
|
std::cout << "Do you want to establish a connection to the parent node "
|
||||||
<< ConsoleColorTag(Console_Bold) << "from this node?"
|
<< ConsoleColorTag(Console_Bold) << "from this node?"
|
||||||
<< ConsoleColorTag(Console_Normal) << " [Y/n]: ";
|
<< ConsoleColorTag(Console_Normal) << " [Y/n]: ";
|
||||||
|
|
||||||
|
@ -167,91 +187,91 @@ wizard_endpoint_loop_start:
|
||||||
boost::algorithm::to_lower(answer);
|
boost::algorithm::to_lower(answer);
|
||||||
choice = answer;
|
choice = answer;
|
||||||
|
|
||||||
String tmpPort = "5665";
|
String parentEndpointPort = "5665";
|
||||||
|
|
||||||
if (choice.Contains("n")) {
|
if (choice.Contains("n")) {
|
||||||
Log(LogWarning, "cli", "Node to master connection setup skipped");
|
Log(LogWarning, "cli", "Node to master/satellite connection setup skipped");
|
||||||
std::cout << "Connection setup skipped. Please configure your master to connect to this node.\n";
|
std::cout << "Connection setup skipped. Please configure your parent node to connect to this node by setting the 'host' attribute for the node Endpoint object.\n";
|
||||||
} else {
|
} else {
|
||||||
std::cout << ConsoleColorTag(Console_Bold)
|
std::cout << ConsoleColorTag(Console_Bold)
|
||||||
<< "Please fill out the master connection information:"
|
<< "Please specify the master/satellite connection information:"
|
||||||
<< ConsoleColorTag(Console_Normal) << "\n"
|
<< ConsoleColorTag(Console_Normal) << "\n"
|
||||||
<< ConsoleColorTag(Console_Bold) << "Master endpoint host"
|
<< ConsoleColorTag(Console_Bold) << "Master/Satellite endpoint host"
|
||||||
<< ConsoleColorTag(Console_Normal) << " (Your master's IP address or FQDN): ";
|
<< ConsoleColorTag(Console_Normal) << " (IP address or FQDN): ";
|
||||||
|
|
||||||
std::getline(std::cin, answer);
|
std::getline(std::cin, answer);
|
||||||
|
|
||||||
if (answer.empty()) {
|
if (answer.empty()) {
|
||||||
Log(LogWarning, "cli", "Please enter the master's endpoint connection information.");
|
Log(LogWarning, "cli", "Please enter the parent endpoint (master/satellite) connection information.");
|
||||||
goto wizard_endpoint_loop_start;
|
goto wizard_endpoint_loop_start;
|
||||||
}
|
}
|
||||||
|
|
||||||
String tmp = answer;
|
String tmp = answer;
|
||||||
tmp = tmp.Trim();
|
tmp = tmp.Trim();
|
||||||
|
|
||||||
endpoint_buffer += "," + tmp;
|
endpointBuffer += "," + tmp;
|
||||||
master_endpoint_name = tmp; //store the endpoint name for later
|
parentEndpointName = tmp;
|
||||||
|
|
||||||
std::cout << ConsoleColorTag(Console_Bold)
|
std::cout << ConsoleColorTag(Console_Bold)
|
||||||
<< "Master endpoint port" << ConsoleColorTag(Console_Normal)
|
<< "Master/Satellite endpoint port" << ConsoleColorTag(Console_Normal)
|
||||||
<< " [" << tmpPort << "]: ";
|
<< " [" << parentEndpointPort << "]: ";
|
||||||
|
|
||||||
std::getline(std::cin, answer);
|
std::getline(std::cin, answer);
|
||||||
|
|
||||||
if (!answer.empty())
|
if (!answer.empty())
|
||||||
tmpPort = answer;
|
parentEndpointPort = answer;
|
||||||
|
|
||||||
endpoint_buffer += "," + tmpPort.Trim();
|
endpointBuffer += "," + parentEndpointPort.Trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
endpoints.push_back(endpoint_buffer);
|
endpoints.push_back(endpointBuffer);
|
||||||
|
|
||||||
std::cout << ConsoleColorTag(Console_Bold) << "Add more master endpoints?"
|
std::cout << ConsoleColorTag(Console_Bold) << "Add more master/satellite endpoints?"
|
||||||
<< ConsoleColorTag(Console_Normal) << " [y/N]: ";
|
<< ConsoleColorTag(Console_Normal) << " [y/N]: ";
|
||||||
std::getline (std::cin, answer);
|
std::getline (std::cin, answer);
|
||||||
|
|
||||||
boost::algorithm::to_lower(answer);
|
boost::algorithm::to_lower(answer);
|
||||||
|
|
||||||
String choice = answer;
|
choice = answer;
|
||||||
|
|
||||||
if (choice.Contains("y"))
|
if (choice.Contains("y"))
|
||||||
goto wizard_endpoint_loop_start;
|
goto wizard_endpoint_loop_start;
|
||||||
|
|
||||||
String master_host, master_port;
|
String parentHost, parentPort;
|
||||||
|
|
||||||
for (const String& endpoint : endpoints) {
|
for (const String& endpoint : endpoints) {
|
||||||
std::vector<String> tokens = endpoint.Split(",");
|
std::vector<String> tokens = endpoint.Split(",");
|
||||||
|
|
||||||
if (tokens.size() > 1)
|
if (tokens.size() > 1)
|
||||||
master_host = tokens[1];
|
parentHost = tokens[1];
|
||||||
|
|
||||||
if (tokens.size() > 2)
|
if (tokens.size() > 2)
|
||||||
master_port = tokens[2];
|
parentPort = tokens[2];
|
||||||
}
|
}
|
||||||
|
|
||||||
/* workaround for fetching the master cert */
|
/* workaround for fetching the master cert */
|
||||||
String pki_path = ApiListener::GetCertsDir();
|
String certsDir = ApiListener::GetCertsDir();
|
||||||
Utility::MkDirP(pki_path, 0700);
|
Utility::MkDirP(certsDir, 0700);
|
||||||
|
|
||||||
String user = ScriptGlobal::Get("RunAsUser");
|
String user = ScriptGlobal::Get("RunAsUser");
|
||||||
String group = ScriptGlobal::Get("RunAsGroup");
|
String group = ScriptGlobal::Get("RunAsGroup");
|
||||||
|
|
||||||
if (!Utility::SetFileOwnership(pki_path, user, group)) {
|
if (!Utility::SetFileOwnership(certsDir, user, group)) {
|
||||||
Log(LogWarning, "cli")
|
Log(LogWarning, "cli")
|
||||||
<< "Cannot set ownership for user '" << user
|
<< "Cannot set ownership for user '" << user
|
||||||
<< "' group '" << group
|
<< "' group '" << group
|
||||||
<< "' on file '" << pki_path << "'. Verify it yourself!";
|
<< "' on file '" << certsDir << "'. Verify it yourself!";
|
||||||
}
|
}
|
||||||
|
|
||||||
String node_cert = pki_path + "/" + cn + ".crt";
|
String nodeCert = certsDir + "/" + cn + ".crt";
|
||||||
String node_key = pki_path + "/" + cn + ".key";
|
String nodeKey = certsDir + "/" + cn + ".key";
|
||||||
|
|
||||||
if (Utility::PathExists(node_key))
|
if (Utility::PathExists(nodeKey))
|
||||||
NodeUtility::CreateBackupFile(node_key, true);
|
NodeUtility::CreateBackupFile(nodeKey, true);
|
||||||
if (Utility::PathExists(node_cert))
|
if (Utility::PathExists(nodeCert))
|
||||||
NodeUtility::CreateBackupFile(node_cert);
|
NodeUtility::CreateBackupFile(nodeCert);
|
||||||
|
|
||||||
if (PkiUtility::NewCert(cn, node_key, Empty, node_cert) > 0) {
|
if (PkiUtility::NewCert(cn, nodeKey, Empty, nodeCert) > 0) {
|
||||||
Log(LogCritical, "cli")
|
Log(LogCritical, "cli")
|
||||||
<< "Failed to create new self-signed certificate for CN '"
|
<< "Failed to create new self-signed certificate for CN '"
|
||||||
<< cn << "'. Please try again.";
|
<< cn << "'. Please try again.";
|
||||||
|
@ -259,29 +279,29 @@ wizard_endpoint_loop_start:
|
||||||
}
|
}
|
||||||
|
|
||||||
/* fix permissions: root -> icinga daemon user */
|
/* fix permissions: root -> icinga daemon user */
|
||||||
if (!Utility::SetFileOwnership(node_key, user, group)) {
|
if (!Utility::SetFileOwnership(nodeKey, user, group)) {
|
||||||
Log(LogWarning, "cli")
|
Log(LogWarning, "cli")
|
||||||
<< "Cannot set ownership for user '" << user
|
<< "Cannot set ownership for user '" << user
|
||||||
<< "' group '" << group
|
<< "' group '" << group
|
||||||
<< "' on file '" << node_key << "'. Verify it yourself!";
|
<< "' on file '" << nodeKey << "'. Verify it yourself!";
|
||||||
}
|
}
|
||||||
|
|
||||||
boost::shared_ptr<X509> trustedcert;
|
boost::shared_ptr<X509> trustedParentCert;
|
||||||
|
|
||||||
if (!master_host.IsEmpty()) {
|
if (!parentHost.IsEmpty()) {
|
||||||
//save-cert and store the master certificate somewhere
|
//save-cert and store the master certificate somewhere
|
||||||
Log(LogInformation, "cli")
|
Log(LogInformation, "cli")
|
||||||
<< "Fetching public certificate from master ("
|
<< "Fetching public certificate from master ("
|
||||||
<< master_host << ", " << master_port << "):\n";
|
<< parentHost << ", " << parentPort << "):\n";
|
||||||
|
|
||||||
trustedcert = PkiUtility::FetchCert(master_host, master_port);
|
trustedParentCert = PkiUtility::FetchCert(parentHost, parentPort);
|
||||||
if (!trustedcert) {
|
if (!trustedParentCert) {
|
||||||
Log(LogCritical, "cli", "Peer did not present a valid certificate.");
|
Log(LogCritical, "cli", "Peer did not present a valid certificate.");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << ConsoleColorTag(Console_Bold) << "Certificate information:\n"
|
std::cout << ConsoleColorTag(Console_Bold) << "Parent certificate information:\n"
|
||||||
<< ConsoleColorTag(Console_Normal) << PkiUtility::GetCertificateInformation(trustedcert)
|
<< ConsoleColorTag(Console_Normal) << PkiUtility::GetCertificateInformation(trustedParentCert)
|
||||||
<< ConsoleColorTag(Console_Bold) << "\nIs this information correct?"
|
<< ConsoleColorTag(Console_Bold) << "\nIs this information correct?"
|
||||||
<< ConsoleColorTag(Console_Normal) << " [y/N]: ";
|
<< ConsoleColorTag(Console_Normal) << " [y/N]: ";
|
||||||
|
|
||||||
|
@ -292,7 +312,7 @@ wizard_endpoint_loop_start:
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Log(LogInformation, "cli", "Received trusted master certificate.\n");
|
Log(LogInformation, "cli", "Received trusted parent certificate.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
wizard_ticket:
|
wizard_ticket:
|
||||||
|
@ -313,7 +333,7 @@ wizard_ticket:
|
||||||
String ticket = answer;
|
String ticket = answer;
|
||||||
ticket = ticket.Trim();
|
ticket = ticket.Trim();
|
||||||
|
|
||||||
if (!master_host.IsEmpty()) {
|
if (!parentHost.IsEmpty()) {
|
||||||
if (ticket.IsEmpty()) {
|
if (ticket.IsEmpty()) {
|
||||||
Log(LogInformation, "cli")
|
Log(LogInformation, "cli")
|
||||||
<< "Requesting certificate without a ticket.";
|
<< "Requesting certificate without a ticket.";
|
||||||
|
@ -322,31 +342,33 @@ wizard_ticket:
|
||||||
<< "Requesting certificate with ticket '" << ticket << "'.";
|
<< "Requesting certificate with ticket '" << ticket << "'.";
|
||||||
}
|
}
|
||||||
|
|
||||||
String target_ca = pki_path + "/ca.crt";
|
String nodeCA = certsDir + "/ca.crt";
|
||||||
|
|
||||||
if (Utility::PathExists(target_ca))
|
if (Utility::PathExists(nodeCA))
|
||||||
NodeUtility::CreateBackupFile(target_ca);
|
NodeUtility::CreateBackupFile(nodeCA);
|
||||||
if (Utility::PathExists(node_cert))
|
if (Utility::PathExists(nodeCert))
|
||||||
NodeUtility::CreateBackupFile(node_cert);
|
NodeUtility::CreateBackupFile(nodeCert);
|
||||||
|
|
||||||
if (PkiUtility::RequestCertificate(master_host, master_port, node_key,
|
if (PkiUtility::RequestCertificate(parentHost, parentPort, nodeKey,
|
||||||
node_cert, target_ca, trustedcert, ticket) > 0) {
|
nodeCert, nodeCA, trustedParentCert, ticket) > 0) {
|
||||||
Log(LogCritical, "cli")
|
Log(LogCritical, "cli")
|
||||||
<< "Failed to fetch signed certificate from master '"
|
<< "Failed to fetch signed certificate from master '"
|
||||||
<< master_host << ", "
|
<< parentHost << ", "
|
||||||
<< master_port <<"'. Please try again.";
|
<< parentPort <<"'. Please try again.";
|
||||||
goto wizard_ticket;
|
goto wizard_ticket;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* fix permissions (again) when updating the signed certificate */
|
/* fix permissions (again) when updating the signed certificate */
|
||||||
if (!Utility::SetFileOwnership(node_cert, user, group)) {
|
if (!Utility::SetFileOwnership(nodeCert, user, group)) {
|
||||||
Log(LogWarning, "cli")
|
Log(LogWarning, "cli")
|
||||||
<< "Cannot set ownership for user '" << user
|
<< "Cannot set ownership for user '" << user
|
||||||
<< "' group '" << group << "' on file '"
|
<< "' group '" << group << "' on file '"
|
||||||
<< node_cert << "'. Verify it yourself!";
|
<< nodeCert << "'. Verify it yourself!";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::cout << "\n";
|
||||||
|
|
||||||
/* apilistener config */
|
/* apilistener config */
|
||||||
std::cout << ConsoleColorTag(Console_Bold)
|
std::cout << ConsoleColorTag(Console_Bold)
|
||||||
<< "Please specify the API bind host/port"
|
<< "Please specify the API bind host/port"
|
||||||
|
@ -356,33 +378,35 @@ wizard_ticket:
|
||||||
|
|
||||||
std::getline(std::cin, answer);
|
std::getline(std::cin, answer);
|
||||||
|
|
||||||
String bind_host = answer;
|
String bindHost = answer;
|
||||||
bind_host = bind_host.Trim();
|
bindHost = bindHost.Trim();
|
||||||
|
|
||||||
std::cout << "Bind Port []: ";
|
std::cout << "Bind Port []: ";
|
||||||
|
|
||||||
std::getline(std::cin, answer);
|
std::getline(std::cin, answer);
|
||||||
|
|
||||||
String bind_port = answer;
|
String bindPort = answer;
|
||||||
bind_port = bind_port.Trim();
|
bindPort = bindPort.Trim();
|
||||||
|
|
||||||
std::cout << ConsoleColorTag(Console_Bold) << "\n"
|
std::cout << ConsoleColorTag(Console_Bold) << "\n"
|
||||||
<< "Accept config from master?" << ConsoleColorTag(Console_Normal)
|
<< "Accept config from parent node?" << ConsoleColorTag(Console_Normal)
|
||||||
<< " [y/N]: ";
|
<< " [y/N]: ";
|
||||||
std::getline(std::cin, answer);
|
std::getline(std::cin, answer);
|
||||||
boost::algorithm::to_lower(answer);
|
boost::algorithm::to_lower(answer);
|
||||||
choice = answer;
|
choice = answer;
|
||||||
|
|
||||||
String accept_config = choice.Contains("y") ? "true" : "false";
|
String acceptConfig = choice.Contains("y") ? "true" : "false";
|
||||||
|
|
||||||
std::cout << ConsoleColorTag(Console_Bold)
|
std::cout << ConsoleColorTag(Console_Bold)
|
||||||
<< "Accept commands from master?" << ConsoleColorTag(Console_Normal)
|
<< "Accept commands from parent node?" << ConsoleColorTag(Console_Normal)
|
||||||
<< " [y/N]: ";
|
<< " [y/N]: ";
|
||||||
std::getline(std::cin, answer);
|
std::getline(std::cin, answer);
|
||||||
boost::algorithm::to_lower(answer);
|
boost::algorithm::to_lower(answer);
|
||||||
choice = answer;
|
choice = answer;
|
||||||
|
|
||||||
String accept_commands = choice.Contains("y") ? "true" : "false";
|
String acceptCommands = choice.Contains("y") ? "true" : "false";
|
||||||
|
|
||||||
|
std::cout << "\n";
|
||||||
|
|
||||||
/* disable the notifications feature on client nodes */
|
/* disable the notifications feature on client nodes */
|
||||||
Log(LogInformation, "cli", "Disabling the Notification feature.");
|
Log(LogInformation, "cli", "Disabling the Notification feature.");
|
||||||
|
@ -397,11 +421,11 @@ wizard_ticket:
|
||||||
enable.push_back("api");
|
enable.push_back("api");
|
||||||
FeatureUtility::EnableFeatures(enable);
|
FeatureUtility::EnableFeatures(enable);
|
||||||
|
|
||||||
String apipath = FeatureUtility::GetFeaturesAvailablePath() + "/api.conf";
|
String apiConfPath = FeatureUtility::GetFeaturesAvailablePath() + "/api.conf";
|
||||||
NodeUtility::CreateBackupFile(apipath);
|
NodeUtility::CreateBackupFile(apiConfPath);
|
||||||
|
|
||||||
std::fstream fp;
|
std::fstream fp;
|
||||||
String tempApiPath = Utility::CreateTempFile(apipath + ".XXXXXX", 0644, fp);
|
String tempApiConfPath = Utility::CreateTempFile(apiConfPath + ".XXXXXX", 0644, fp);
|
||||||
|
|
||||||
fp << "/**\n"
|
fp << "/**\n"
|
||||||
<< " * The API listener is used for distributed monitoring setups.\n"
|
<< " * The API listener is used for distributed monitoring setups.\n"
|
||||||
|
@ -411,28 +435,27 @@ wizard_ticket:
|
||||||
<< " key_path = LocalStateDir + \"/lib/icinga2/certs/\" + NodeName + \".key\"\n"
|
<< " key_path = LocalStateDir + \"/lib/icinga2/certs/\" + NodeName + \".key\"\n"
|
||||||
<< " ca_path = LocalStateDir + \"/lib/icinga2/certs/ca.crt\"\n"
|
<< " ca_path = LocalStateDir + \"/lib/icinga2/certs/ca.crt\"\n"
|
||||||
<< "\n"
|
<< "\n"
|
||||||
<< " accept_config = " << accept_config << "\n"
|
<< " accept_config = " << acceptConfig << "\n"
|
||||||
<< " accept_commands = " << accept_commands << "\n";
|
<< " accept_commands = " << acceptCommands << "\n";
|
||||||
|
|
||||||
if (!bind_host.IsEmpty())
|
if (!bindHost.IsEmpty())
|
||||||
fp << " bind_host = \"" << bind_host << "\"\n";
|
fp << " bind_host = \"" << bindHost << "\"\n";
|
||||||
if (!bind_port.IsEmpty())
|
if (!bindPort.IsEmpty())
|
||||||
fp << " bind_port = " << bind_port << "\n";
|
fp << " bind_port = " << bindPort << "\n";
|
||||||
|
|
||||||
fp << "\n"
|
fp << "}\n";
|
||||||
<< "}\n";
|
|
||||||
|
|
||||||
fp.close();
|
fp.close();
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
_unlink(apipath.CStr());
|
_unlink(apiConfPath.CStr());
|
||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
|
|
||||||
if (rename(tempApiPath.CStr(), apipath.CStr()) < 0) {
|
if (rename(tempApiConfPath.CStr(), apiConfPath.CStr()) < 0) {
|
||||||
BOOST_THROW_EXCEPTION(posix_error()
|
BOOST_THROW_EXCEPTION(posix_error()
|
||||||
<< boost::errinfo_api_function("rename")
|
<< boost::errinfo_api_function("rename")
|
||||||
<< boost::errinfo_errno(errno)
|
<< boost::errinfo_errno(errno)
|
||||||
<< boost::errinfo_file_name(tempApiPath));
|
<< boost::errinfo_file_name(tempApiConfPath));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* apilistener config */
|
/* apilistener config */
|
||||||
|
@ -480,8 +503,15 @@ wizard_ticket:
|
||||||
<< boost::errinfo_errno(errno)
|
<< boost::errinfo_errno(errno)
|
||||||
<< boost::errinfo_file_name(tempTicketPath));
|
<< boost::errinfo_file_name(tempTicketPath));
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
/* master setup */
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int NodeWizardCommand::MasterSetup(void) const
|
||||||
|
{
|
||||||
|
std::string answer;
|
||||||
|
String choice;
|
||||||
|
|
||||||
std::cout << ConsoleColorTag(Console_Bold) << "Starting the Master setup routine...\n";
|
std::cout << ConsoleColorTag(Console_Bold) << "Starting the Master setup routine...\n";
|
||||||
|
|
||||||
/* CN */
|
/* CN */
|
||||||
|
@ -531,23 +561,23 @@ wizard_ticket:
|
||||||
|
|
||||||
std::getline(std::cin, answer);
|
std::getline(std::cin, answer);
|
||||||
|
|
||||||
String bind_host = answer;
|
String bindHost = answer;
|
||||||
bind_host = bind_host.Trim();
|
bindHost = bindHost.Trim();
|
||||||
|
|
||||||
std::cout << ConsoleColorTag(Console_Bold)
|
std::cout << ConsoleColorTag(Console_Bold)
|
||||||
<< "Bind Port" << ConsoleColorTag(Console_Normal) << " []: ";
|
<< "Bind Port" << ConsoleColorTag(Console_Normal) << " []: ";
|
||||||
|
|
||||||
std::getline(std::cin, answer);
|
std::getline(std::cin, answer);
|
||||||
|
|
||||||
String bind_port = answer;
|
String bindPort = answer;
|
||||||
bind_port = bind_port.Trim();
|
bindPort = bindPort.Trim();
|
||||||
|
|
||||||
/* api feature is always enabled, check above */
|
/* api feature is always enabled, check above */
|
||||||
String apipath = FeatureUtility::GetFeaturesAvailablePath() + "/api.conf";
|
String apiConfPath = FeatureUtility::GetFeaturesAvailablePath() + "/api.conf";
|
||||||
NodeUtility::CreateBackupFile(apipath);
|
NodeUtility::CreateBackupFile(apiConfPath);
|
||||||
|
|
||||||
std::fstream fp;
|
std::fstream fp;
|
||||||
String tempApiPath = Utility::CreateTempFile(apipath + ".XXXXXX", 0644, fp);
|
String tempApiConfPath = Utility::CreateTempFile(apiConfPath + ".XXXXXX", 0644, fp);
|
||||||
|
|
||||||
fp << "/**\n"
|
fp << "/**\n"
|
||||||
<< " * The API listener is used for distributed monitoring setups.\n"
|
<< " * The API listener is used for distributed monitoring setups.\n"
|
||||||
|
@ -557,10 +587,10 @@ wizard_ticket:
|
||||||
<< " key_path = LocalStateDir + \"/lib/icinga2/certs/\" + NodeName + \".key\"\n"
|
<< " key_path = LocalStateDir + \"/lib/icinga2/certs/\" + NodeName + \".key\"\n"
|
||||||
<< " ca_path = LocalStateDir + \"/lib/icinga2/certs/ca.crt\"\n";
|
<< " ca_path = LocalStateDir + \"/lib/icinga2/certs/ca.crt\"\n";
|
||||||
|
|
||||||
if (!bind_host.IsEmpty())
|
if (!bindHost.IsEmpty())
|
||||||
fp << " bind_host = \"" << bind_host << "\"\n";
|
fp << " bind_host = \"" << bindHost << "\"\n";
|
||||||
if (!bind_port.IsEmpty())
|
if (!bindPort.IsEmpty())
|
||||||
fp << " bind_port = " << bind_port << "\n";
|
fp << " bind_port = " << bindPort << "\n";
|
||||||
|
|
||||||
fp << "\n"
|
fp << "\n"
|
||||||
<< " ticket_salt = TicketSalt\n"
|
<< " ticket_salt = TicketSalt\n"
|
||||||
|
@ -569,21 +599,21 @@ wizard_ticket:
|
||||||
fp.close();
|
fp.close();
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
_unlink(apipath.CStr());
|
_unlink(apiConfPath.CStr());
|
||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
|
|
||||||
if (rename(tempApiPath.CStr(), apipath.CStr()) < 0) {
|
if (rename(tempApiConfPath.CStr(), apiConfPath.CStr()) < 0) {
|
||||||
BOOST_THROW_EXCEPTION(posix_error()
|
BOOST_THROW_EXCEPTION(posix_error()
|
||||||
<< boost::errinfo_api_function("rename")
|
<< boost::errinfo_api_function("rename")
|
||||||
<< boost::errinfo_errno(errno)
|
<< boost::errinfo_errno(errno)
|
||||||
<< boost::errinfo_file_name(tempApiPath));
|
<< boost::errinfo_file_name(tempApiConfPath));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* update constants.conf with NodeName = CN + TicketSalt = random value */
|
/* update constants.conf with NodeName = CN + TicketSalt = random value */
|
||||||
if (cn != Utility::GetFQDN()) {
|
if (cn != Utility::GetFQDN()) {
|
||||||
Log(LogWarning, "cli")
|
Log(LogWarning, "cli")
|
||||||
<< "CN '" << cn << "' does not match the default FQDN '"
|
<< "CN '" << cn << "' does not match the default FQDN '"
|
||||||
<< Utility::GetFQDN() << "'. Requires update for NodeName constant in constants.conf!";
|
<< Utility::GetFQDN() << "'. Requires an update for the NodeName constant in constants.conf!";
|
||||||
}
|
}
|
||||||
|
|
||||||
Log(LogInformation, "cli", "Updating constants.conf.");
|
Log(LogInformation, "cli", "Updating constants.conf.");
|
||||||
|
@ -598,11 +628,6 @@ wizard_ticket:
|
||||||
String salt = RandomString(16);
|
String salt = RandomString(16);
|
||||||
|
|
||||||
NodeUtility::UpdateConstant("TicketSalt", salt);
|
NodeUtility::UpdateConstant("TicketSalt", salt);
|
||||||
}
|
|
||||||
|
|
||||||
std::cout << "Done.\n\n";
|
|
||||||
|
|
||||||
std::cout << "Now restart your Icinga 2 daemon to finish the installation!\n\n";
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,6 +40,10 @@ public:
|
||||||
virtual int GetMaxArguments(void) const override;
|
virtual int GetMaxArguments(void) const override;
|
||||||
virtual int Run(const boost::program_options::variables_map& vm, const std::vector<std::string>& ap) const override;
|
virtual int Run(const boost::program_options::variables_map& vm, const std::vector<std::string>& ap) const override;
|
||||||
virtual ImpersonationLevel GetImpersonationLevel(void) const override;
|
virtual ImpersonationLevel GetImpersonationLevel(void) const override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
int ClientSetup(void) const;
|
||||||
|
int MasterSetup(void) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue