Our data-center backups (2016-2018):
+-------------------------+ +--------------------------+ | server : HP rx2800-i2 | | server : HP DL385p-gen8 | | OS : OpenVMS-8.4 | | OS : CentOS-7 | | client : MariaDB-5.5-60 | | server : MariaDB-10.3.11 | | net-1 : TCP/IP +<--+ net-1 : TCP/IP | | net-2 : TCP/IP | +--------------------------+ | net-3 : DECnet +<--- 4 other OpenVMS systems | net-4 : TCP/IP +---> Windows-7 PC (backup host) +-------------------------+
Changes in 2019:
Command(s) | Comments |
---|---|
yum install vsftpd vi /etc/vsftpd.conf |
install an ftp server configure the settings file |
firewall-cmd --permanent --zone public --add-service ftp firewall-cmd --reload | prep the firewall |
systemctl stop vsftpd.service systemctl start vsftpd.service systemctl status vsftpd.service | |
systemctl enable vsftpd.service | auto-start this service during reboot |
yum install epel-release yum install ntfs-3g -y | install ntfs software |
caveat: on 2022-03-31 I realized that proftpd might be a better choice (at least for some applications) than vsftpd.
Commands | Comments |
---|---|
fdisk -l | |
fdisk -l /dev/sd* | |
ls -la /dev/disk/by-label/ | |
ls -la /dev/disk/by-label/BKUP* | see all disks with a label beginning with BKUP |
SELinux was developed by America's NSA (National Security Agency) and combines two approaches to security. (read on)
#---------------------------------------------------------------------------- # inspect a file # note: DAC information is shown in red #---------------------------------------------------------------------------- [root@localhost ~]# ls -la /icsis total 8 drwxr-xr-x. 3 root root 16 Jan 25 11:11 . dr-xr-xr-x. 18 root root 4096 Jan 25 11:30 .. drwxrwxrwx. 1 root root 4096 Sep 20 17:02 win [root@localhost ~]# #---------------------------------------------------------------------------- # inspect a process # note: owner in red #---------------------------------------------------------------------------- [root@localhost ~]# ps -ef | grep vsftp root 6051 1 0 Jan25 ? 00:00:00 /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf
#---------------------------------------------------------------------------- # inspect a file (append "Z" to also see SELinux data) # notes: # 1) MAC information is shown in red # 2) breakout: # system_u is a user context # object_r is a role context # root_t is a type context # s0 is a security level # 3) notice that the second line has a context type of "fusefs_t" #---------------------------------------------------------------------------- [root@localhost ~]# ls -laZ /icsis drwxr-xr-x. root root unconfined_u:object_r:default_t:s0 . dr-xr-xr-x. root root system_u:object_r:root_t:s0 .. drwxrwxrwx. root root system_u:object_r:fusefs_t:s0 win #---------------------------------------------------------------------------- # inspect a process (append "Z" to also see SELinux data) # note: MAC information is shown in red #---------------------------------------------------------------------------- [root@localhost ~]# ps -efZ | grep vsftp system_u:system_r:ftpd_t:s0-s0:c0.c1023 root 6051 1 0 Jan25 ...
... 00:00:00 /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf
You will not learn SELinux in one day. In fact, there are large tomes available on Amazon dedicated to this single topic; but you might be able to learn just enough about this to get yourself over the hump provided you are willing to do a little hacking. So try these two commands:
Commands | Comments | Additional Info |
---|---|---|
man ftpd_selinux | view SELinux info specific to ftpd | All FTPd programs are required to follow these rules |
man httpd_selinux | view SELinux info specific to httpd | All HTTPd programs are required to follow these rules |
If neither one of these commands worked but you would like them to then follow these steps:
Commands | Comments |
---|---|
yum install selinux-policy-devel | |
sepolicy manpage -a -p /usr/local/man/man8 | generate new manpages |
mandb | integrate the new manpages into your index |
At this point commands like "man ftpd_selinux" should work properly. Be sure to read the whole thing taking special note of any predefined sebooleans (these are topic-specific boolean variables stored in SELinux)
Commands | Comments |
---|---|
semanage boolean -l | list all booleans |
semanage boolean -l | grep ftp | list booleans specific to ftp and sftp |
Commands | Comments |
---|---|
mkdir /icsis/win chmod 777 /icsis/win |
this will be my mount point (where my USB-DISK will be connected) note: only need to do this once |
setsebool ftpd_use_fusefs 1 | since my USB-DISK is being attached by fusefs (see blue text below) this change will allow all FTPd programs to access directories attached to path /icsis/win |
#------------------------------------------------------------ # inspect a file # tack on "Z" to also see SELinux data # note: MAC stuff in red and blue #------------------------------------------------------------ [root@localhost ~]# ls -laZ /icsis drwxr-xr-x. root root unconfined_u:object_r:default_t:s0 . dr-xr-xr-x. root root system_u:object_r:root_t:s0 .. drwxrwxrwx. root root system_u:object_r:fusefs_t:s0 win #------------------------------------------------------------
Commands | Comments |
---|---|
ls -la /dev/disk/by-label/BKUP* | take notice where CentOS auto-mounted my USB-DISK probably will be /dev/sdb1 depending upon how many other drives are present |
umount /dev/sdb1 | dismount my USB-DISK from where ever it is right now |
mount -t /dev/sdb1 /icsis/win | mount it in a place where OpenVMS expects it |
semanage fcontext -a -t public_content_rw_t "/icsis/win(/.*)?" | tell SELinux that this location is sanctioned for read+write |
restorecon -F -R -v /icsis/win | necessary voodoo (copies info from SELinux back to the file system) |
setsebool -P ftpd_anon_write 1 | an optional "hall pass" |
At this point the attached USB-DISK can be written to via FTP
caveat: on 2022-03-31 I realized that the account associated with this process should be added to "semanage login" with a label of "user_r". In fact, everyone logging into your system should be constrained in this way. See general-selinux-tips further down this page.
[prompt]# pwd /var/www [prompt]# ls -laZ drwxr-xr-x. root root system_u:object_r:httpd_sys_content_t:s0 . drwxr-xr-x. root root system_u:object_r:var_t:s0 .. drwxrwxrwx. root root system_u:object_r:httpd_sys_script_exec_t:s0 cgi-bin drwxrwxrwx. root root unconfined_u:object_r:httpd_sys_rw_content_t:s0 click_log drwxrwxrwx. root root unconfined_u:object_r:httpd_sys_content_t:s0 css drwxrwxrwx. root root unconfined_u:object_r:httpd_sys_content_t:s0 documents -rwxrwxrwx. root root unconfined_u:object_r:httpd_sys_content_t:s0 favicon.ico drwxrwxrwx. root root unconfined_u:object_r:httpd_sys_content_t:s0 fonts drwxrwxrwx. root root unconfined_u:object_r:httpd_sys_content_t:s0 fragments drwxrwxrwx. root root system_u:object_r:httpd_sys_content_t:s0 html drwxrwxrwx. root root unconfined_u:object_r:httpd_sys_content_t:s0 images drwxrwxrwx. root root unconfined_u:object_r:httpd_sys_content_t:s0 js drwxrwxrwx. root root unconfined_u:object_r:httpd_sys_content_t:s0 mam drwxrwxrwx. root root unconfined_u:object_r:httpd_sys_content_t:s0 tmp [prompt]#
[prompt]# pwd /var/www [prompt]# semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/tmp(/.*)?" [prompt]# restorecon -R -v /var/www/tmp [prompt]# ls -laZ drwxr-xr-x. root root system_u:object_r:httpd_sys_content_t:s0 . drwxr-xr-x. root root system_u:object_r:var_t:s0 .. drwxrwxrwx. root root system_u:object_r:httpd_sys_script_exec_t:s0 cgi-bin drwxrwxrwx. root root unconfined_u:object_r:httpd_sys_rw_content_t:s0 click_log drwxrwxrwx. root root unconfined_u:object_r:httpd_sys_content_t:s0 css drwxrwxrwx. root root unconfined_u:object_r:httpd_sys_content_t:s0 documents -rwxrwxrwx. root root unconfined_u:object_r:httpd_sys_content_t:s0 favicon.ico drwxrwxrwx. root root unconfined_u:object_r:httpd_sys_content_t:s0 fonts drwxrwxrwx. root root unconfined_u:object_r:httpd_sys_content_t:s0 fragments drwxrwxrwx. root root system_u:object_r:httpd_sys_content_t:s0 html drwxrwxrwx. root root unconfined_u:object_r:httpd_sys_content_t:s0 images drwxrwxrwx. root root unconfined_u:object_r:httpd_sys_content_t:s0 js drwxrwxrwx. root root unconfined_u:object_r:httpd_sys_content_t:s0 mam drwxrwxrwx. root root unconfined_u:object_r:httpd_sys_rw_content_t:s0 tmp [prompt]#
Caveat: although the following works, it is not the correct way to solve the problem. Why? Relabeling the files for ownership by procmail_t means that they will not be accessible by user esppats (although this is not a real user). I am leaving this here because it is instructive.
type: man procmail_selinux #
#
# 1) the first three lines update SELinux config
# 2) "sequencer" is a small binary program which needs to run
# 3) "munpack" is a small binary program which needs to run
# 4) the fourth line is just a little hacking
# 4) the fifth line changes file labeling based upon SELinux config
#
type: semanage fcontext -a -t procmail_exec_t "/home/esppats/espp(.*\.sh)?" # scripts type: semanage fcontext -a -t procmail_exec_t "/home/esppats/sequencer" # this program type: semanage fcontext -a -t procmail_exec_t "/home/esppats/munpack" # this program type: semanage fcontext -l | grep esppats # hacking type: restorecon -FRv /home/esppats # now apply to files
#
# now allow two more ports
#
type: sealert -a /var/log/audit/audit.log # magic happens type: ausearch -c 'espp_step2.sh' --raw | audit2allow -o junk.txt # -+- just hacking type: cat junk.txt # -+ #============= procmail_t ============== #!!!! This avc is allowed in the current policy allow procmail_t mysqld_port_t:tcp_socket name_connect; #!!!! This avc is allowed in the current policy allow procmail_t smtp_port_t:tcp_socket name_connect; type: ausearch -c 'espp_step2.sh' --raw | audit2allow -M my-esppstep2sh # -+- not hacking
type: cat my-esppstep2sh.te # | type: semodule -i my-esppstep2sh.pp # -+
#
# problem solved
#
#
# begin by removing everything related to the previous hack
#
type: semanage login -d esppats # might fail if nothing found
type: semanage fcontext -D "/home/esppats" # remove everything matching this path
type: restorecon -FRv /home/esppats # all files relabeled unconfined_u
type: semanage fcontext -l | grep "/home/esppats" # double check
#
# new solution starts here
#
type: semanage login -a -s user_u esppats # define this user type: restorecon -FRv /home/esppats # all files now labeled user_u event: generate some activity to cause SELinux to log AVC messages in permissive mode type: cat /var/log/audit/audit.log | audit2allow -m esppats > esppats.te (this is promiscuous; running through grep will NOT help) type: cat esppats.te (cuz not everything is usable; might want to remove http stuff) --------------------------------------------------------------------- contents start module esppats 1.0; require { type httpd_sys_script_exec_t; type user_home_t; type smtp_port_t; type mysqld_port_t; type httpd_sys_script_t; type procmail_t; class tcp_socket name_connect; class dir { add_name remove_name write }; class file { create execute execute_no_trans rename unlink write }; } #============= httpd_sys_script_t ============== allow httpd_sys_script_t httpd_sys_script_exec_t:dir { add_name remove_name write }; allow httpd_sys_script_t httpd_sys_script_exec_t:file { create rename unlink write }; #============= procmail_t ============== allow procmail_t mysqld_port_t:tcp_socket name_connect; #!!!! This avc can be allowed using the boolean 'nis_enabled' allow procmail_t smtp_port_t:tcp_socket name_connect; allow procmail_t user_home_t:file { execute execute_no_trans }; --------------------------------------------------------------------- contents end
type: vim esppats.te
(to remove the stuff in red) type: make -f /usr/share/selinux/devel/Makefile esppats.pp type: semodule -i esppats.pp
#
# problem solved
#
type: semodule -d esppats # disabling module causes problem to return
type: semodule -e esppats # enabling module solves problem
type: ausearch -c 'python3' --raw | audit2allow -M my-python3 # magic happens ******************** IMPORTANT *********************** To make this policy package active, execute: semodule -i my-python3.pp (note: two files were just created: my-python3.te followed by my-python3.pp) type: cat my-python3.te # is it what you want? type: semodule -i my-python3.pp # YES ---------------------------------------------------------------- otherwise type: vi my-python3.te # remove want you don’t want type: rm my-python3.pp # delete old .pp type: make -f /usr/share/selinux/devel/Makefile my-python3.pp # create new .pp type: semodule -i my-python3.pp # install it
Aug 26 14:55:32 kawc3v systemd: Stopping The Apache HTTP Server...
Aug 26 14:55:33 kawc3v systemd: Stopped The Apache HTTP Server.
Aug 26 14:55:33 kawc3v systemd: Starting The Apache HTTP Server...
Aug 26 14:55:33 kawc3v httpd: AH00526: Syntax error on line 114 of /etc/httpd/conf.d/ssl.conf:
Aug 26 14:55:33 kawc3v httpd: SSLCertificateKeyFile: file '/etc/pki/tls/private/kawc96_20220822.key' does not exist or is empty
Aug 26 14:55:33 kawc3v systemd: httpd.service: main process exited, code=exited, status=1/FAILURE
Aug 26 14:55:33 kawc3v systemd: Failed to start The Apache HTTP Server.
Aug 26 14:55:33 kawc3v systemd: Unit httpd.service entered failed state.
Aug 26 14:55:33 kawc3v systemd: httpd.service failed.
restorecon -F -R -v /etc/pki/tls/certs restorecon -F -R -v /etc/pki/tls/private
First type these two commands:
#
# legend: problems in red
#
[prompt]sestatus SELinux status: enabled SELinuxfs mount: /sys/fs/selinux SELinux root directory: /etc/selinux Loaded policy name: targeted Current mode: permissive Mode from config file: enforcing Policy MLS status: enabled Policy deny_unknown status: allowed Max kernel policy version: 31 # [prompt]sudo semanage login -l [sudo] password for neil: Login Name SELinux User MLS/MCS Range Service __default__ unconfined_u s0-s0:c0.c1023 *
ungar user_u s0-s0:c0.c0 *
admin sysadm_u s0-s0:c0.c1023 *
rootish system_u s0-s0:c0.c1023 * root unconfined_u s0-s0:c0.c1023 * system_u system_u s0-s0:c0.c1023 *
What is the security level of your Linux system?
SELinux status |
Current Mode |
Any Unconfined Users? |
Result | Security Level |
---|---|---|---|---|
disabled | your system is no more secure than a typical UNIX system of the 1990s | unix | ||
enabled | permissive | your system is no more secure than a typical UNIX system of the 1990s | unix | |
enabled | enforcing | yes | still better than UNIX because some processes (like httpd) are confined (even though they are not found in semanage login) |
u+1 |
enabled | enforcing | only root | better because most users are confined in a way similar to vendor installed stuff like httpd | u+2 |
enabled | enforcing | no | best because now everything and everyone is confined | u+3 |
modify the default account named __default__ from unconfined_u to user_u | relaxed |
modify the default account named __default__ from unconfined_u to guest_u | stricter |
delete the default account named __default__ | strict |