Improve security with Nagios-Monitor-Server: Difference between revisions
No edit summary |
No edit summary |
||
(12 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
[[File: | [[File:image.png|thumb|300px| Nagios monitoring system]] | ||
Author: | Author: | ||
Line 6: | Line 6: | ||
Cyber Security Engineering (C21) | Cyber Security Engineering (C21) | ||
Page Created: | Page Created: 25 November 2017 | ||
Last modified: | Last modified: 07 January 2017 | ||
Line 35: | Line 35: | ||
! Software | ! Software | ||
! Version | ! Version | ||
|- | |- | ||
| Apache | | Apache | ||
| 1.3.12 or later | | 1.3.12 or later | ||
|- | |- | ||
| PHP | | PHP | ||
Line 53: | Line 51: | ||
*Customized Dashboards | *Customized Dashboards | ||
*Ease of Use | *Ease of Use | ||
* | *Infinite Scalability | ||
*Data in Real Time | |||
*Network Security | *Network Security | ||
= Why monitoring is important for cyber security = | = Why monitoring is important for cyber security = | ||
Line 66: | Line 62: | ||
*Fifth the debugging, when system have error the monitor tool should have a readable debugging.. | *Fifth the debugging, when system have error the monitor tool should have a readable debugging.. | ||
= Setting up | = Setting up Nagios= | ||
<span style="color:#FF0000"> | <span style="color:#FF0000"> | ||
In the following tutorial, Ubuntu 16.04 64-bit distribution will be used LTS. | In the following tutorial, Ubuntu 16.04 64-bit distribution will be used LTS. | ||
Line 72: | Line 68: | ||
==== Prerequisites ==== | ==== Prerequisites ==== | ||
Ubuntu Linux machine, sudo access and some Linux beginner skills are needed. | Ubuntu Linux machine, sudo access and some Linux beginner skills are needed. | ||
This tutorial describes the commands and configuration to make the services work together | This tutorial describes the commands and configuration to make the services work together Nagios. | ||
*It is important to have the latest package lists to update them to get info on the newest versions of packages and their dependencies. So we need to run the following command to update them: | *It is important to have the latest package lists to update them to get info on the newest versions of packages and their dependencies. So we need to run the following command to update them: | ||
Line 87: | Line 82: | ||
Begin with the commands: | Begin with the commands: | ||
<code> wget | <code> sudo apt install wget build-essential apache2 php apache2-mod-php7.0 php-gd libgd-dev sendmail unzip </code> | ||
User and group configuration | |||
<code> | <code> useradd nagios </code> | ||
<code> groupadd nagcmd </code> | |||
<code> usermod -a -G nagcmd nagios </code> | |||
<code> usermod -a -G nagios,nagcmd www-data </code> | |||
Download and extract the Nagios core | |||
<code> | <code> wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.2.0.tar.gz </code> | ||
<code> | Extract the file | ||
<code> tar -xzf nagios*.tar.gz </code> | |||
System administrator need to configure it with the user and the group you have created earlier | |||
<code> | <code> ./configure --with-nagios-group=nagios --with-command-group=nagcmd </code> | ||
<code> make all </code> | |||
<code> make install </code> | |||
<code> make install-commandmode </code> | |||
<code> make install-init </code> | |||
<code> make install-config </code> | |||
<code> /usr/bin/install -c -m 644 sample-config/httpd.conf /etc/apache2/sites-available/nagios.conf </code> | |||
Copy even-handler directory to the nagios directory | |||
<code> | <code> cp -R contrib/eventhandlers/ /usr/local/nagios/libexec/ </code> | ||
<code> chown -R nagios:nagios /usr/local/nagios/libexec/eventhandlers </code> | |||
Install the Nagios Plugins | |||
<code> | <code> wget https://nagios-plugins.org/download/nagios-plugins-2.1.2.tar.gz </code> | ||
Extract it | |||
<code> | <code> tar -xzf nagios-plugins*.tar.gz </code> | ||
<code> | Install the Nagios plugin's with the commands below | ||
<code> ./configure --with-nagios-user=nagios --with-nagios-group=nagios --with-openssl </code> | |||
<code> make </code> | |||
<code> make install </code> | |||
System administrator can find the default configuration of Nagios in /usr/local/nagios/. to configure Nagios and Nagios contact. Edit default Nagios configuration with nano | |||
<code> nano -c /usr/local/nagios/etc/nagios.cfg </code> | |||
uncomment line 51 for the host monitor configuration. | |||
Save and exit. | |||
Add a new folder named servers. | |||
<code> mkdir -p /usr/local/nagios/etc/servers </code> | |||
Change the user and group for the new folder to Nagios: | |||
<code> chown nagios:nagios /usr/local/nagios/etc/server </code> | |||
Enable Apache modules | |||
<code> sudo a2enmod rewrite </code> | |||
<code> sudo a2enmod cgi </code> | |||
System administrator can use the htpasswd command to configure a user nagiosadmin for the Nagios web interface | |||
<code> sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin </code> | |||
Enable the Nagios virtualhost | |||
<code> sudo ln -s /etc/apache2/sites-available/nagios.conf /etc/apache2/sites-enable </code> | |||
Start Apache | |||
<code> service apache2 restart </code> | |||
When Nagios starts, you may see the following error | |||
Starting nagios (via systemctl): nagios.serviceFaile | |||
System administrator can fix with the following | |||
<code> cd /etc/init.d/ </code> | |||
<code> cp /etc/init.d/skeleton /etc/init.d/nagios </code> | |||
<code> nano /etc/init.d/nagios </code> | |||
Paste this code at the end of the file | |||
<pre> | |||
DESC="Nagios" | |||
NAME=nagios | |||
DAEMON=/usr/local/nagios/bin/$NAME | |||
DAEMON_ARGS="-d /usr/local/nagios/etc/nagios.cfg" | |||
PIDFILE=/usr/local/nagios/var/$NAME.lock | |||
</pre> | |||
Make it executable and start Nagios | |||
<code> chmod +x /etc/init.d/nagios </code> | |||
<code> service apache2 restart </code> | <code> service apache2 restart </code> | ||
< | <span style="color:#FF0000"> | ||
Still it there is another process to fix the issue | |||
First we are going to create/change the nagios.service | |||
<code> | <code> nano /etc/systemd/system/nagios.service </code> | ||
Paste the following code of the file | |||
<pre> | |||
[ | [Unit] | ||
Description=Nagios | |||
BindTo=network.target | |||
= | [Install] | ||
WantedBy=multi-user.target | |||
[Service] | |||
User=nagios | |||
Group=nagios | |||
Type=simple | |||
ExecStart=/usr/local/nagios/bin/nagios /usr/local/nagios/etc/nagios.cfg | |||
</pre> | |||
System administrator need to enable created nagios.service config | |||
<code> systemctl enable /etc/systemd/system/nagios.service </code> | |||
<code> | |||
<code> service nagios start </code> | |||
<code> | |||
To check the service is working | |||
$ service nagios status | |||
*Open web browser and YOURIPADDRESS/nagios | |||
[[File:Nagios-server.png|thumb|center| Nagios monitoring system]] | |||
[[File:Nagios-server-monitor.png|thumb|center| Nagios monitoring system]] | |||
=Enable the encryption Front-end Web= | =Enable the encryption Front-end Web= | ||
Line 254: | Line 304: | ||
<VirtualHost *:80> | <VirtualHost *:80> | ||
ServerName | ServerName | ||
Redirect "/" "https:// | Redirect "/" "https://Nagios-server/" | ||
</VirtualHost> | </VirtualHost> | ||
</pre> | </pre> | ||
=Enable the encryption between the server and the agent= | |||
<span style="color:#FF0000"> | |||
The connection need to be secure between the server and the agent, it's not easy and it's not hard to make it for the security. | |||
* Setup Directories: | |||
<code> cd /usr/local/nagios/etc/ </code> | |||
<code> mkdir ssl </code> | |||
<code> chown root:nagios ssl </code> | |||
<code> mkdir ca nagios_server_certs client_certs </code> | |||
<code> chown root:nagios * </code> | |||
<code> mkdir ./demoCA </code> | |||
<code> mkdir ./demoCA/newcerts </code> | |||
<code> cd ./demoCA </code> | |||
<code> touch index.txt </code> | |||
<code> echo '1000' Angle brackets serial </code> | |||
* Create Certificate Authority | |||
<code> openssl req -x509 -newkey rsa:4096 -keyout ca_key.pem -out ca_cert.pem -utf8 -days 3650 </code> | |||
* NRPE Client Certificate | |||
<code> cd /usr/local/nagios/etc/ssl/client_certs/ </code> | |||
<code> openssl req -new -newkey rsa:2048 -keyout client_cert.key -out client_cert.csr -nodes </code> | |||
* Sign this certificate request by our CA: | |||
<code> openssl ca -days 365 -notext -md sha256 -keyfile ca/ca_key.pem -cert ca/ca_cert.pem -in client_certs/client_cert.csr -out client_certs/client_cert.pem </code> | |||
Copy NRPE Client Certificates to the agent: | |||
1- First you can make it with sftp://user@IP | |||
Or you can copy it with secure copy | |||
<code> scp root@IP:/usr/local/nagios/etc/ssl/ca/ca_cert.pem /usr/local/nagios/etc/ssl/ </code> | |||
<code> scp root@IP:/usr/local/nagios/etc/ssl/client_certs/client_cert.key /usr/local/nagios/etc/ssl/ </code> | |||
<code> scp root@IP:/usr/local/nagios/etc/ssl/client_certs/client_cert.pem /usr/local/nagios/etc/ssl/ </code> | |||
* Next the NRPE client config file needs updating so it knows to use the new certificate. In the file /usr/local/nagios/etc/nrpe.cfg | |||
<code> nano nrpe.cfg </code> | |||
* In line 238 uncomment: | |||
<code> | |||
ssl_cacert_file=/usr/local/nagios/etc/ssl/ca/ca_cert.pem | |||
ssl_cert_file=/usr/local/nagios/etc/ssl/client_certs/client_cert.pem | |||
ssl_privatekey_file=/usr/local/nagios/etc/ssl/client_certs/client_cert.key | |||
</code> | |||
* restart nrpe: | |||
<code> service nrpe restart </code> | |||
* Don't forgot to uncomment the follow: | |||
<code> | |||
1- ssl_logging=0xff | |||
2 ssl_client_certs=2 | |||
</code> | |||
check_nrpe Plugin Certificate | |||
<code> cd /usr/local/nagios/etc/ssl/nagios_server_certs/ </code> | |||
<code> openssl req -new -newkey rsa:2048 -keyout nagios_server.key -out nagios_server.csr -nodes </code> | |||
<code> cd /usr/local/nagios/etc/ssl/ </code> | |||
<code> openssl ca -days 365 -notext -md sha256 -keyfile ca/ca_key.pem -cert ca/ca_cert.pem -in nagios_server_certs/nagios_server.csr -out nagios_server_certs/nagios_server.pem </code> | |||
* Using Certificates With check_nrpe Plugin | |||
<code> /usr/local/nagios/libexec/check_nrpe -A /usr/local/nagios/etc/ssl/ca/ca_cert.pem -C /usr/local/nagios/etc/ssl/nagios_server_certs/nagios_server.pem -K /usr/local/nagios/etc/ssl/nagios_server_certs/nagios_server.key -H yourIPaddress </code> | |||
<span style="color:#FF0000"> | |||
* To make the handshake: | |||
<code> nano /usr/local/nagios/etc/services </code> | |||
* add the following next to the chech_nrpe services | |||
<code> -A /usr/local/nagios/etc/ssl/ca/ca_cert.pem -C /usr/local/nagios/etc/ssl//client_certs/client_cert.pem -K /usr/local/nagios/etc/ssl/client_certs/client_cert.key </code> | |||
<code> service nagios restart </code> | |||
To check the logs from the agent side | |||
<code> tail -f /var/log/syslog </code> | |||
Make sure that server IP address in the nrpe.cfg | |||
<code> cd /usr/local/nagios/etc </code> | |||
<code> nano nrpe.cfg </code> | |||
In line 106 | |||
Put the server IP address | |||
=Summary= | =Summary= | ||
Nagios is an open source application for monitoring a system. Nagios has been widely used because of the ease of configuration. Nagios in support by various plugins, and you can even create your own plugins. Look here for more information. [https://www.nagios.org/about/overview/ Nagios-main-documentation]. | |||
=See also= | =See also= | ||
Nagios installation by Cyber-Tect-Tips | |||
1- [https://www.youtube.com/watch?v= | 1- [https://www.youtube.com/watch?v=EpzTJH85y8Y Nagios-Server-Installation Step one] | ||
2- [https://www.youtube.com/watch?v= | 2- [https://www.youtube.com/watch?v=4vZELdYa7O4 Nagios-Agent configuration using NRPE plugin - Step two] | ||
3- [https://www.youtube.com/watch?v=TzlYyzj7BkQ Nagios-Agent send checks to Nagios-Server - Step three] | |||
4- [https://www.youtube.com/watch?v=Ci_FgH-dwr0 Nagios-Agent using NRPE plugin with the Monitor Server side (Full configuration)] | |||
5- [https://www.youtube.com/watch?v=Kz-Z-dL0T_U&list=PLKAuFoXV02VqeLyddX-CIMcMdqWcI2UoP&index=5 Customize Nagios (Agent - Server) adding new services check (Swap - SSH) Final step] | |||
6- [https://support.nagios.com/kb/article.php?id=519 NRPE - v3 Enhanced Security] | |||
7- [https://support.nagios.com/kb/article/nrpe-check_nrpe-error-could-not-complete-ssl-handshake-615.html NRPE - CHECK_NRPE: Error - Could Not Complete SSL Handshake] | |||
=References= | =References= | ||
1- [https:// | 1- [https://www.nagios.org/ Nagios System monitoring] | ||
2- [https://en.wikipedia.org/wiki/Information_security CIA] | 2- [https://en.wikipedia.org/wiki/Information_security CIA] | ||
3- [https:// | 3- [https://en.wikipedia.org/wiki/Nagios Nagios-Information] | ||
4- [https://www.youtube.com/channel/UChHzqszXw_5edX-9DOK4JxA Cyber-Tech-Tips] | 4- [https://www.youtube.com/channel/UChHzqszXw_5edX-9DOK4JxA Cyber-Tech-Tips] | ||
5- [https://www. | 5- [https://www.youtube.com/watch?v=EpzTJH85y8Y&list=PLKAuFoXV02VqeLyddX-CIMcMdqWcI2UoP Nagios installation 4.2.0 (Ubuntu Server 16.04.1 LTS) - Step one] | ||
6- [https://www.youtube.com/watch?v=4vZELdYa7O4&index=2&list=PLKAuFoXV02VqeLyddX-CIMcMdqWcI2UoP Nagios-Agent configuration using NRPE plugin - Step two] | |||
7- [https://www.youtube.com/watch?v=TzlYyzj7BkQ&list=PLKAuFoXV02VqeLyddX-CIMcMdqWcI2UoP&index=3 Nagios-Agent send checks to Nagios-Server - Step three] | |||
8- [https://www.youtube.com/watch?v=Kz-Z-dL0T_U&list=PLKAuFoXV02VqeLyddX-CIMcMdqWcI2UoP&index=5 Customize Nagios (Agent - Server) adding new services check (Swap - SSH) Final step] | |||
9- [https://www.youtube.com/watch?v=jg_zan7f_YQ&list=PLKAuFoXV02VqeLyddX-CIMcMdqWcI2UoP&index=6 How to send checks to Nagios-Server & How to create own script] | |||
10- [https://www.youtube.com/watch?v=MnG8Embgfgw&list=PLKAuFoXV02VqeLyddX-CIMcMdqWcI2UoP&index=10 Secure the connection between Nagios (Server - Agent) NRPE - v3 Enhanced Security] | |||
11- [https://www.youtube.com/watch?v=7En5kheIwOM SSL Handshake between Nagios (Server - Agent)] | |||
------ | ------ | ||
[[Category:Monitoring]] | [[Category:Monitoring]] |
Latest revision as of 11:16, 7 January 2018
Author: Mohanad Aly
Cyber Security Engineering (C21)
Page Created: 25 November 2017
Last modified: 07 January 2017
Introduction
This article introduces the Monitoring application called Nagios.
Monitoring
Monitoring is the process of keep tracking of system resources.
Monitoring is the process of observing and checking the progress or quality of something over a period of time; keep under systematic review.[1] Monitoring cannot be achieved without logging. That is the reason integrated solutions combine the two processes. Monitoring is used to:
- Check performance
- Detect if something worth noticing happened
- Prevent something to happen
- Detect whether a system is under attack and that is the most important part for the cyber security
Nagios Monitoring system
Nagios now known as Nagios Core, is a free and open source computer-software application that monitors systems, networks and infrastructure. Nagios offers monitoring and alerting services for servers, switches, applications and services. It alerts users when things go wrong and alerts them a second time when the problem has been resolved. [2]
Monitoring is made of three components:
Software | Version |
---|---|
Apache | 1.3.12 or later |
PHP | 5.0 or later |
MySQL php-mysql | 3.22 or later |
The main advantages of Nagios
- Open-source
- Customized Dashboards
- Ease of Use
- Infinite Scalability
- Data in Real Time
- Network Security
Why monitoring is important for cyber security
- First thing is important for the cyber security professional is the CIA (Confidentiality, Integrity and Availability)What is CIA, and to get to the standards we need to implement the tools that provides the security for our data and servers that hosting the data.
- Second system administrator need tools to react when something happened to the server, so system administrator need real time checks to make sure that everything is working in order.
- Third Monitoring tools alerts should be readable for the administrator and fast, when something happened to the server or the service the monitoring tool should send the alerts in the exact time to give the administrator the time to fix it.
- Fourth the attacks and threats which is more difficult to the system administrator to figure out what is going in the server, and the monitoring tools should has the detection solution for the common attacks.
- Fifth the debugging, when system have error the monitor tool should have a readable debugging..
Setting up Nagios
In the following tutorial, Ubuntu 16.04 64-bit distribution will be used LTS.
Prerequisites
Ubuntu Linux machine, sudo access and some Linux beginner skills are needed.
This tutorial describes the commands and configuration to make the services work together Nagios.
- It is important to have the latest package lists to update them to get info on the newest versions of packages and their dependencies. So we need to run the following command to update them:
Command
sudo apt update
sudo apt upgrade
Installing the prerequisites
- The server has the ability to check standard networking services (HTTP, FTP, SMTP, IMAP etc) without the need to install extra software on the monitored hosts.
Begin with the commands:
sudo apt install wget build-essential apache2 php apache2-mod-php7.0 php-gd libgd-dev sendmail unzip
User and group configuration
useradd nagios
groupadd nagcmd
usermod -a -G nagcmd nagios
usermod -a -G nagios,nagcmd www-data
Download and extract the Nagios core
wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.2.0.tar.gz
Extract the file
tar -xzf nagios*.tar.gz
System administrator need to configure it with the user and the group you have created earlier
./configure --with-nagios-group=nagios --with-command-group=nagcmd
make all
make install
make install-commandmode
make install-init
make install-config
/usr/bin/install -c -m 644 sample-config/httpd.conf /etc/apache2/sites-available/nagios.conf
Copy even-handler directory to the nagios directory
cp -R contrib/eventhandlers/ /usr/local/nagios/libexec/
chown -R nagios:nagios /usr/local/nagios/libexec/eventhandlers
Install the Nagios Plugins
wget https://nagios-plugins.org/download/nagios-plugins-2.1.2.tar.gz
Extract it
tar -xzf nagios-plugins*.tar.gz
Install the Nagios plugin's with the commands below
./configure --with-nagios-user=nagios --with-nagios-group=nagios --with-openssl
make
make install
System administrator can find the default configuration of Nagios in /usr/local/nagios/. to configure Nagios and Nagios contact. Edit default Nagios configuration with nano
nano -c /usr/local/nagios/etc/nagios.cfg
uncomment line 51 for the host monitor configuration.
Save and exit.
Add a new folder named servers.
mkdir -p /usr/local/nagios/etc/servers
Change the user and group for the new folder to Nagios:
chown nagios:nagios /usr/local/nagios/etc/server
Enable Apache modules
sudo a2enmod rewrite
sudo a2enmod cgi
System administrator can use the htpasswd command to configure a user nagiosadmin for the Nagios web interface
sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
Enable the Nagios virtualhost
sudo ln -s /etc/apache2/sites-available/nagios.conf /etc/apache2/sites-enable
Start Apache
service apache2 restart
When Nagios starts, you may see the following error Starting nagios (via systemctl): nagios.serviceFaile System administrator can fix with the following
cd /etc/init.d/
cp /etc/init.d/skeleton /etc/init.d/nagios
nano /etc/init.d/nagios
Paste this code at the end of the file
DESC="Nagios" NAME=nagios DAEMON=/usr/local/nagios/bin/$NAME DAEMON_ARGS="-d /usr/local/nagios/etc/nagios.cfg" PIDFILE=/usr/local/nagios/var/$NAME.lock
Make it executable and start Nagios
chmod +x /etc/init.d/nagios
service apache2 restart
Still it there is another process to fix the issue
First we are going to create/change the nagios.service
nano /etc/systemd/system/nagios.service
Paste the following code of the file
[Unit] Description=Nagios BindTo=network.target [Install] WantedBy=multi-user.target [Service] User=nagios Group=nagios Type=simple ExecStart=/usr/local/nagios/bin/nagios /usr/local/nagios/etc/nagios.cfg
System administrator need to enable created nagios.service config
systemctl enable /etc/systemd/system/nagios.service
service nagios start
To check the service is working
$ service nagios status
- Open web browser and YOURIPADDRESS/nagios
Enable the encryption Front-end Web
SSL support actually comes standard in the Ubuntu 16.04 Apache package. We simply need to enable it to take advantage of SSL on our system.
Enable the module by typing:
sudo a2enmod ssl
Creating a subdirectory within Apache's configuration hierarchy to place the certificate files that we will be making
sudo mkdir /etc/apache2/ssl
Now that we have a location to place our key and certificate, we can create them both in one step by typing
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/apache2/ssl/apache.key -out /etc/apache2/ssl/apache.crt
Country Name (2 letter code) [AU]:EE State or Province Name (full name) [Some-State]:Harjumaa Locality Name (eg, city) []:Tallinn Organization Name (eg, company) [Internet Widgits Pty Ltd]: Incorporated Company Organizational Unit Name (eg, section) []:Head Common Name (e.g. server FQDN or YOUR name) []: domain.com Email Address []: Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []: An optional company name []:
- openssl: This is the basic command line tool provided by OpenSSL to create and manage certificates, keys, signing requests, etc.
- req: This specifies a subcommand for X.509 certificate signing request (CSR) management. X.509 is a public key infrastructure standard that SSL adheres to for its key and certificate managment. Since we are wanting to create a new X.509 certificate, this is what we want.
- -x509: This option specifies that we want to make a self-signed certificate file instead of generating a certificate request.
- -nodes: This option tells OpenSSL that we do not wish to secure our key file with a passphrase. Having a password protected key file would get in the way of Apache starting automatically as we would have to enter the password every time the service restarts.
- -days 365: This specifies that the certificate we are creating will be valid for one year.
- -newkey rsa:2048: This option will create the certificate request and a new private key at the same time. This is necessary since we didn't create a private key in advance. The rsa:2048 tells OpenSSL to generate an RSA key that is 2048 bits long.
- -keyout: This parameter names the output file for the private key file that is being created.
- -out: This option names the output file for the certificate that we are generating.
Open the file with root privileges now:
sudo nano /etc/apache2/sites-available/default-ssl.conf
<IfModule mod_ssl.c> <VirtualHost _default_:443> ServerAdmin admin@example.com ServerName your_domain.com ServerAlias www.your_domain.com DocumentRoot /var/www/html ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined SSLEngine on ----> SSLCertificateFile /etc/apache2/ssl/apache.crt ----> SSLCertificateKeyFile /etc/apache2/ssl/apache.key <FilesMatch "\.(cgi|shtml|phtml|php)$"> SSLOptions +StdEnvVars </FilesMatch> <Directory /usr/lib/cgi-bin> SSLOptions +StdEnvVars </Directory> BrowserMatch "MSIE [2-6]" \ nokeepalive ssl-unclean-shutdown \ downgrade-1.0 force-response-1.0 BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown </VirtualHost> </IfModule>
SSL-enabled virtual host
sudo a2ensite default-ssl.conf
Restart Apache to load our new virtual host file
service apache2 restart
Test the configuration by visiting the server's domain name or public IP address after specifying the https:// protocol, like this:
https://server_domain_name_or_IP
This to solve the problem to enable the ssl
nano 000-default.conf
# Special virtulhost only for redirecting <VirtualHost *:80> ServerName Redirect "/" "https://Nagios-server/" </VirtualHost>
Enable the encryption between the server and the agent
The connection need to be secure between the server and the agent, it's not easy and it's not hard to make it for the security.
- Setup Directories:
cd /usr/local/nagios/etc/
mkdir ssl
chown root:nagios ssl
mkdir ca nagios_server_certs client_certs
chown root:nagios *
mkdir ./demoCA
mkdir ./demoCA/newcerts
cd ./demoCA
touch index.txt
echo '1000' Angle brackets serial
- Create Certificate Authority
openssl req -x509 -newkey rsa:4096 -keyout ca_key.pem -out ca_cert.pem -utf8 -days 3650
- NRPE Client Certificate
cd /usr/local/nagios/etc/ssl/client_certs/
openssl req -new -newkey rsa:2048 -keyout client_cert.key -out client_cert.csr -nodes
- Sign this certificate request by our CA:
openssl ca -days 365 -notext -md sha256 -keyfile ca/ca_key.pem -cert ca/ca_cert.pem -in client_certs/client_cert.csr -out client_certs/client_cert.pem
Copy NRPE Client Certificates to the agent:
1- First you can make it with sftp://user@IP
Or you can copy it with secure copy
scp root@IP:/usr/local/nagios/etc/ssl/ca/ca_cert.pem /usr/local/nagios/etc/ssl/
scp root@IP:/usr/local/nagios/etc/ssl/client_certs/client_cert.key /usr/local/nagios/etc/ssl/
scp root@IP:/usr/local/nagios/etc/ssl/client_certs/client_cert.pem /usr/local/nagios/etc/ssl/
- Next the NRPE client config file needs updating so it knows to use the new certificate. In the file /usr/local/nagios/etc/nrpe.cfg
nano nrpe.cfg
- In line 238 uncomment:
ssl_cacert_file=/usr/local/nagios/etc/ssl/ca/ca_cert.pem
ssl_cert_file=/usr/local/nagios/etc/ssl/client_certs/client_cert.pem
ssl_privatekey_file=/usr/local/nagios/etc/ssl/client_certs/client_cert.key
- restart nrpe:
service nrpe restart
- Don't forgot to uncomment the follow:
1- ssl_logging=0xff
2 ssl_client_certs=2
check_nrpe Plugin Certificate
cd /usr/local/nagios/etc/ssl/nagios_server_certs/
openssl req -new -newkey rsa:2048 -keyout nagios_server.key -out nagios_server.csr -nodes
cd /usr/local/nagios/etc/ssl/
openssl ca -days 365 -notext -md sha256 -keyfile ca/ca_key.pem -cert ca/ca_cert.pem -in nagios_server_certs/nagios_server.csr -out nagios_server_certs/nagios_server.pem
- Using Certificates With check_nrpe Plugin
/usr/local/nagios/libexec/check_nrpe -A /usr/local/nagios/etc/ssl/ca/ca_cert.pem -C /usr/local/nagios/etc/ssl/nagios_server_certs/nagios_server.pem -K /usr/local/nagios/etc/ssl/nagios_server_certs/nagios_server.key -H yourIPaddress
- To make the handshake:
nano /usr/local/nagios/etc/services
- add the following next to the chech_nrpe services
-A /usr/local/nagios/etc/ssl/ca/ca_cert.pem -C /usr/local/nagios/etc/ssl//client_certs/client_cert.pem -K /usr/local/nagios/etc/ssl/client_certs/client_cert.key
service nagios restart
To check the logs from the agent side
tail -f /var/log/syslog
Make sure that server IP address in the nrpe.cfg
cd /usr/local/nagios/etc
nano nrpe.cfg
In line 106 Put the server IP address
Summary
Nagios is an open source application for monitoring a system. Nagios has been widely used because of the ease of configuration. Nagios in support by various plugins, and you can even create your own plugins. Look here for more information. Nagios-main-documentation.
See also
Nagios installation by Cyber-Tect-Tips
1- Nagios-Server-Installation Step one
2- Nagios-Agent configuration using NRPE plugin - Step two
3- Nagios-Agent send checks to Nagios-Server - Step three
4- Nagios-Agent using NRPE plugin with the Monitor Server side (Full configuration)
5- Customize Nagios (Agent - Server) adding new services check (Swap - SSH) Final step
6- NRPE - v3 Enhanced Security
7- NRPE - CHECK_NRPE: Error - Could Not Complete SSL Handshake
References
2- CIA
5- Nagios installation 4.2.0 (Ubuntu Server 16.04.1 LTS) - Step one
6- Nagios-Agent configuration using NRPE plugin - Step two
7- Nagios-Agent send checks to Nagios-Server - Step three
8- Customize Nagios (Agent - Server) adding new services check (Swap - SSH) Final step
9- How to send checks to Nagios-Server & How to create own script
10- Secure the connection between Nagios (Server - Agent) NRPE - v3 Enhanced Security
11- SSL Handshake between Nagios (Server - Agent)