Operating System Installation and Configuration¶
Base Operating System Installation¶
Perform a minimal OS installation of a recent RHEL6/7 or derivative Linux distribution, using your preferred installation method (manual install, Kickstart, etc). The details of how to perform this task are out of the scope of this document.
The system should have IP connectivity, using a fixed IP address and a resolvable fully qualified domain name. For performing the installation, the system needs to be able to establish outgoing TCP connections (mainly to download additional components).
Additionally, a local or remote MTA (e.g. Postfix or Sendmail) needs to be installed and configured so the system is capable of sending email.
Boot up the system and log in as the root user.
Enable Time Synchronization With NTP¶
We strongly advise that the clocks of all servers in a TeamDrive installation are synchronized using the Network Time Protocol (NTP). This can be achieved by installing the ntp package and enabling the NTP daemon:
[root@regserver install]# yum install ntp
[root@regserver install]# service ntpd start
[root@regserver install]# chkconfig ntpd on
Edit and update the configuration file /etc/ntp.conf
, if necessary for your
local environment.
Disable SELinux¶
The TeamDrive Registration Server currently can not be run when SELinux is enabled.
Edit the file /etc/selinux/config
and set SELINUX=disabled
.
Reboot the system or change the SELinux enforcing mode at run time using the following command:
[root@regserver install]# setenforce 0
Firewall Configuration¶
You should configure a local firewall so the server is protected against remote attacks. The only TCP ports that must be reachable from the Internet are 80 (http) and 443 (https). Optionally, port 22 (SSH) can be opened to facilitate remote administration, but access to this port should be restricted to known and trusted IP addresses or networks only.
On a minimal installation, you can install and use the text-based firewall configuration utility to enable access to the following services:
- SSH
- Secure WWW (HTTPS)
- WWW (HTTP)
To configure the firewall, you need to run the following commands:
[root@regserver install]# yum install system-config-firewall-tui \
newt-python
[root@regserver install]# system-config-firewall-tui
Follow the instructions to configure the firewall. Enable additional protections based on your local requirements or security policies.
You can check the result with iptables -L
:
[root@regserver ~]# iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED
ACCEPT icmp -- anywhere anywhere
ACCEPT all -- anywhere anywhere
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:ssh
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:http
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:https
REJECT all -- anywhere anywhere reject-with icmp-host-prohibited
Chain FORWARD (policy ACCEPT)
target prot opt source destination
REJECT all -- anywhere anywhere reject-with icmp-host-prohibited
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
In case of using an external company firewall enable the above ports for the incoming traffic. For outgoing communication please enable:
- Secure WWW (Port 443 for HTTPS)
- WWW (Port 80 for HTTP)
- SMTP (Port 25 for sending mails using a public mail server; in case of using SSL-communication to the mail server, also Ports 465, 587)
- DNS Lookup (Port 53 for DNS communication with a public DNS server)
CentOS Hardening¶
Install a rootkit scanner:
yum install epel-release
yum --enablerepo=epel -y install rkhunter
and update the email in MAILTO
in the rkhunter config file:
/etc/sysconfig/rkhunter
The rootkit scanner will automatically be started once a day and will send a status email to the above email.
Update rkhunter and run the rootkit check:
rkhunter --update
rkhunter --propupd
rkhunter --check --sk
Install USBGuard to protect your systems against intrusive USB devices:
yum install usbguard
Change config for PresentControllerPolicy
in /etc/usbguard/usbguard-daemon.conf
and set this to:
PresentControllerPolicy=block
Enable usbguard:
systemctl enable --now usbguard
We recommend to harden the CentOS system based on the DevSec Hardening Framework:
https://github.com/dev-sec/linux-baseline
and the Lynis - Security auditing tool for Linux:
https://cisofy.com/lynis/
Install both tools:
curl https://omnitruck.chef.io/install.sh | sudo bash -s -- -P inspec
yum install epel-release
yum install lynis
To analyze the system using DevSec execute:
inspec exec https://github.com/dev-sec/linux-baseline
and for Lynis execute:
lynis audit system
The DevSec report will show the test results with a green and red staus. Lynis generates a similar test result with a green, yellow and red status and calculates a Hardening index.
For hardening the system we offer a script which will be installed with the TeamDrive Registration Server software. The script will be executed later on in the documentation.
Installing MySQL Server¶
The TeamDrive Registration Server requires a MySQL database to store its information. This document assumes that the MySQL instance runs on the same host as the Registration Server itself, connecting to it via the local socket file.
Alternatively, it’s possible to use an external MySQL Server. In this case,
you need to make sure that this external MySQL instance is reachable via TCP
from the Registration Server (usually via TCP port 3306) and that the
teamdrive
MySQL user is defined correctly (e.g. the MySQL username
in the remote database would become teamdrive@regserver.yourdomain.com
instead of teamdrive@localhost
).
Most MySQL installations usually do not allow the root
user to log in from
a remote host. In this case the installation script is unable to create the
dedicated teamdrive
user automatically and you need to perform this step
manually before performing the installation of the TeamDrive Registration
Server databases.
Especially the correct definition of the host part is critical, as MySQL
considers username@regserver
and username@regserver.yourdomain.com
as two different users.
Note
Since CentOS 7 MySQL is no longer in CentOS’s repositories and MariaDB has become the default database system offered. We recommend installing the mysql community server instead. If you are installing on CentOS 7 then perform the following steps by downloading the MySQL 8.0 repository (this is note necessary on CentOS 8, because MySQL is in CentOS’s repository):
yum localinstall https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm
yum install mysql-community-server
On CentOS 8 install the MySQL Client and Server packages from the default repository:
dnf install mysql mysql-server
For reliablility and performance reasons, we recommend placing the MySQL data
directory /var/lib/mysql
on a dedicated file system or storage volume.
The default maximum file handle limit in CentOS 7 is 1024 which might be to less for the amount of file handles and database connections for the TeamDrive apache module. The amount of file handles can be calculated: tables (currently 26) x 2 (2 files per table) x apache processes x 2 (for restarting the apache). For less than 100 users it will be 26 x 2 x 20 x 2 = 2080 file handles, for 500 users 26 x 2 x 50 x 2 = 2200 file handles and for more than 1000 users 26 x 150 x 2 = 15600
To be save, we increase the value to 65535 in the following three configuration files.
First: Edit /etc/sysctl.conf
and add the below line, save and exit:
fs.file-max = 65535
Second: Increase the hard and soft limits in /etc/security/limits.conf
. Add the below lines before
the #End
, save and exit:
* soft nproc 65535
* hard nproc 65535
* soft nofile 65535
* hard nofile 65535
After the change execute:
sysctl -p
Third: For MySQL, edit /usr/lib/systemd/system/mysqld.service
and add the 2 lines below at the end:
LimitNOFILE=65535
LimitNPROC=65535
After the change execute:
systemctl daemon-reload
Please start the MySQL server now and tell systemd to start the service automatically at boot:
[root@regserver ~ ]# systemctl start mysqld.service
[root@regserver ~ ]# systemctl enable mysqld.service
Run the secure installation script and follow the recommendations. The latest version of mysql generates
a temporary password which is written to the log. Use the password to run mysql_secure_installation
and set a new password for the MySQL root
user and take note of it:
[root@regserver ~ ]# grep 'temporary password' /var/log/mysqld.log
2021-07-22T17:47:13.315642Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: 4>x...k4s
[root@regserver ~ ]# mysql_secure_installation
Securing the MySQL server deployment.
Enter password for user root:
The existing password for the user account root has expired. Please set
a new password.
...
Answer all question with Y for:
- Remove anonymous users?
- Disallow root login remotely?
- Remove test database and access to it?
- Reload privilege tables now?
MySQL is now up and running. It will be populated with the required databases and tables during the Registration Server installation process.
Apache Setup and Configuration¶
The TeamDrive Clients use the HTTP protocol to communicate with the Registration Server. The Registration Server’s Administraion Console is based on the PHP scripting language; both are served by the Apache HTTP server.
Install the Apache HTTP Server and the mod_ssl
Apache module by running
the following command:
yum install httpd mod_ssl
For security reasons, we also advise to disable the so-called “Server
Signature” - a feature that adds a line containing the server version and
virtual host name to server-generated pages (e.g. internal error documents,
directory listings, etc). Change the configuration in
/etc/httpd/conf/httpd.conf
as follows:
ServerSignature Off
By default, the server version and operating system is also displayed in the
Server
response header field, e.g. Server: Apache/2.4.6 (CentOS)
.
To suppress this output, we suggest to update the ServerTokens
option as
follows:
ServerTokens Prod
The TeamDrive Registration Server only requires a few Apache modules to be enabled. To reduce the memory footprint, please deactivate unnecessary modules in the apache configuration.
Enable “Prefork” Mode (CentOS 8)¶
The mod_yvva
module requires that apache run in prefork mode. Note that
Apache will crash when running in a different mode.
To set the mode, execute:
sed -e '/LoadModule mpm_event_module/ s/^#*/#/' -i /etc/httpd/conf.modules.d/00-mpm.conf
sed -e '/#LoadModule mpm_prefork_module/ s/^#*//' -i /etc/httpd/conf.modules.d/00-mpm.conf
which will comment out the mpm_event_module and uncomment the mpm_prefork_module. The result should look:
# Select the MPM module which should be used by uncommenting exactly
# one of the following LoadModule lines. See the httpd.conf(5) man
# page for more information on changing the MPM.
...
LoadModule mpm_prefork_module modules/mod_mpm_prefork.so
...
#LoadModule mpm_worker_module modules/mod_mpm_worker.so
...
#LoadModule mpm_event_module modules/mod_mpm_event.so
Apache 2.4 (CentOS 7 / 8)¶
In the directory: /etc/httpd/conf.modules.d
comment out all modules in the
following config files. Using the linux stream editor (sed) with the following
regular expression will add a ‘#’ comment sign in each line starting with
‘LoadModule’:
sed -e '/LoadModule/ s/^#*/#/' -i /etc/httpd/conf.modules.d/00-dav.conf
sed -e '/LoadModule/ s/^#*/#/' -i /etc/httpd/conf.modules.d/00-lua.conf
sed -e '/LoadModule/ s/^#*/#/' -i /etc/httpd/conf.modules.d/00-proxy.conf
sed -e '/LoadModule/ s/^#*/#/' -i /etc/httpd/conf.modules.d/01-cgi.conf
sed -e '/LoadModule/ s/^#*/#/' -i /etc/httpd/conf.modules.d/10-proxy_h2.conf
Disable all modules in /etc/httpd/conf.modules.d/00-base.conf
and re-enable
only the required modules:
sed -e '/LoadModule/ s/^#*/#/' -i /etc/httpd/conf.modules.d/00-base.conf
sed -e '/#LoadModule access_compat_module/ s/^#*//' -i /etc/httpd/conf.modules.d/00-base.conf
sed -e '/#LoadModule actions_module/ s/^#*//' -i /etc/httpd/conf.modules.d/00-base.conf
sed -e '/#LoadModule alias_module/ s/^#*//' -i /etc/httpd/conf.modules.d/00-base.conf
sed -e '/#LoadModule authz_core_module/ s/^#*//' -i /etc/httpd/conf.modules.d/00-base.conf
sed -e '/#LoadModule autoindex_module/ s/^#*//' -i /etc/httpd/conf.modules.d/00-base.conf
sed -e '/#LoadModule dir_module/ s/^#*//' -i /etc/httpd/conf.modules.d/00-base.conf
sed -e '/#LoadModule headers_module/ s/^#*//' -i /etc/httpd/conf.modules.d/00-base.conf
sed -e '/#LoadModule log_config_module/ s/^#*//' -i /etc/httpd/conf.modules.d/00-base.conf
sed -e '/#LoadModule mime_module/ s/^#*//' -i /etc/httpd/conf.modules.d/00-base.conf
sed -e '/#LoadModule rewrite_module/ s/^#*//' -i /etc/httpd/conf.modules.d/00-base.conf
sed -e '/#LoadModule setenvif_module/ s/^#*//' -i /etc/httpd/conf.modules.d/00-base.conf
sed -e '/#LoadModule slotmem_shm_module/ s/^#*//' -i /etc/httpd/conf.modules.d/00-base.conf
sed -e '/#LoadModule socache_shmcb_module/ s/^#*//' -i /etc/httpd/conf.modules.d/00-base.conf
sed -e '/#LoadModule unixd_module/ s/^#*//' -i /etc/httpd/conf.modules.d/00-base.conf
sed -e '/#LoadModule version_module/ s/^#*//' -i /etc/httpd/conf.modules.d/00-base.conf
Configure mod_ssl
¶
In order to facilitate access to the Registration Server’s API and initial
setup screens via SSL, the following needs to be added to the end of the
default <VirtualHost>
section in /etc/httpd/conf.d/ssl.conf
:
Include conf.d/td-regserver.httpd.conf.ssl
</VirtualHost>
Note
The Apache HTTP Server package includes a self-signed SSL certificate for testing purposes. If you connect to the server using a web browser, it will likely raise an error about an untrusted/insecure connection. You should consider replacing this certificate with an appropriate one.
Follow the instructions provided by your certificate authority on how to obtain and install an SSL certificate for the Apache HTTP Server.
Verify your SSL configuration using the service from SSL Labs:
https://www.ssllabs.com/ssltest/analyze.html
and make sure that
the “Handshake Simulation” is working for current platforms and browser. The
following ssl parameters on CentOS 7 for the apache web server will create an
A-rating and make sure that the handshake is working for current platforms
and browser (for CentOS 8 no changes on the default configurations are necessary):
SSLProtocol all -SSLv2 -SSLv3
SSLHonorCipherOrder on
SSLCipherSuite ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS
PHP and PEAR framework¶
The Registration Server’s Admin Console requires PHP and the PEAR framework to enable a few additional PHP packages which are not available in RPM format.
CentOS 7/8 will be shipped with a not longer supported PHP version. PHP only supports version 7.x. To install the latest version 7 add the two additional Remi and EPEL repositories and enable PHP 7.4.
For CentOS 7:
yum -y install epel-release
yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm -y
yum update
Please activate the PHP 7.4 version in the new repository:
yum-config-manager --enable remi-php74
If yum-config-manager
can’t be found, install it with:
yum install yum-utils
Use the following command to install the required PHP components:
yum install php php-pear php-mysqlnd.x86_64 php-mbstring
For CentOS 8:
dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
dnf install https://rpms.remirepo.net/enterprise/remi-release-8.rpm
dnf module enable php:remi-7.4
dnf install php php-cli php-common php-pear php-mysqlnd php-mbstring
CentOS 7 and 8:
pear channel-update pear.php.net
pear install Log
You can use pear list
to get a list of installed PHP packages.
Finally, we need to change a few PHP-related configuration options. Please edit
the /etc/php.ini
file and change the following values by executing the search
and replace calls using sed
:
sed -i 's/expose_php = On/expose_php = Off/g' /etc/php.ini
sed -i 's/max_execution_time = 30/max_execution_time = 900/g' /etc/php.ini
sed -i 's/max_input_time = 60/max_input_time = 900/g' /etc/php.ini
sed -i 's/post_max_size = 8M/post_max_size = 55M/g' /etc/php.ini
sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 50M/g' /etc/php.ini
sed -i 's/memory_limit = 128M/memory_limit = 512M/g' /etc/php.ini
sed -i 's/session.use_strict_mode = 0/session.use_strict_mode=On/g' /etc/php.ini
sed -i 's/session.cookie_httponly =/session.cookie_httponly=On/g' /etc/php.ini
sed -i 's/session.cookie_secure =/session.cookie_secure=On/g' /etc/php.ini
sed -i 's/session.cookie_samesite =/session.cookie_samesite="Strict"/g' /etc/php.ini
sed -i 's/;date.timezone =/date.timezone = Europe\/Berlin/g' /etc/php.ini
Now create the following directory for storing the PHP session data:
install -d -o apache -g apache /var/lib/php/session
Optional for CentOS 7:
The Reg-Server Admin-Console offers a new functionality to ping all host servers and listing their SSL certificates and their expiration dates. This functionality requires a curl version >= 7.50. CentOS 7 offers only the curl version 7.29. A newer curl version is available in an alternative repository (this configuration is not necessary for CentOS 8 which already uses the curl version 7.61):
rpm -Uvh http://www.city-fan.org/ftp/contrib/yum-repo/city-fan.org-release-2-2.rhel7.noarch.rpm
yum --enablerepo=city-fan.org update curl
Warning
Do not start the Apache HTTP Server until you have concluded the Registration Server installation and you are ready to proceed with the Registration Server Setup!