[4db1b6e] | 1 | #!/bin/bash |
---|
| 2 | #/** |
---|
| 3 | #@file security-config |
---|
| 4 | #@brief OpenGnsys Server security configuration. |
---|
[b37d5cb] | 5 | #@note Security configuration tipsx for UFW, FirewallD and SELinux. |
---|
[9ddd0ff] | 6 | #@version 1.1.0 - Initial version. |
---|
| 7 | #@author Ramón M. Gómez, ETSII Univ. Sevilla |
---|
| 8 | #@date 2016-04-18 |
---|
[4db1b6e] | 9 | #*/ ## |
---|
| 10 | |
---|
| 11 | |
---|
| 12 | # Variables. |
---|
| 13 | PROG=$(basename "$0") |
---|
| 14 | OPENGNSYS=/opt/opengnsys |
---|
| 15 | # Errors control. |
---|
| 16 | if [ "$USER" != "root" ]; then |
---|
| 17 | echo "$PROG: Need to be root." >&2 |
---|
| 18 | exit 1 |
---|
| 19 | fi |
---|
| 20 | |
---|
[9ddd0ff] | 21 | # UFW configuration. |
---|
| 22 | if which ufw 2>/dev/null; then |
---|
| 23 | # Adding active services. |
---|
| 24 | ufw allow "Apache Secure" |
---|
| 25 | ufw allow OpenSSH |
---|
| 26 | ufw allow Samba |
---|
| 27 | ufw allow mysql |
---|
| 28 | ufw allow rsync |
---|
| 29 | ufw allow tftp |
---|
| 30 | ufw allow 67,68/udp # DHCP |
---|
| 31 | ufw allow 2002,2008/tcp # OpenGnsys services |
---|
| 32 | ufw allow 9000:9051/udp # Multicast |
---|
| 33 | ufw allow 6881:6999/udp # BitTorrent |
---|
| 34 | # Applying configuration. |
---|
| 35 | ufw enable |
---|
[4db1b6e] | 36 | # FirewallD configuration. |
---|
[9ddd0ff] | 37 | elif which firewall-cmd 2>/dev/null; then |
---|
[4db1b6e] | 38 | # Defining OpenGnsys services. |
---|
| 39 | python -c " |
---|
| 40 | import firewall.core.io.service as ios |
---|
| 41 | s=ios.Service() |
---|
| 42 | s.short = 'OpenGnsys Server' |
---|
| 43 | s.name = 'ogAdmServer' |
---|
| 44 | s.ports = [('2008', 'tcp')] |
---|
| 45 | ios.service_writer(s, '/etc/firewalld/services') |
---|
[b73502c1] | 46 | s.short = 'OpenGnsys Repository' |
---|
| 47 | s.name = 'ogAdmRepo' |
---|
| 48 | s.ports = [('2002', 'tcp')] |
---|
| 49 | ios.service_writer(s, '/etc/firewalld/services')" |
---|
[4db1b6e] | 50 | # Adding active services. |
---|
| 51 | firewall-cmd --permanent --add-service=dhcp |
---|
| 52 | firewall-cmd --permanent --add-service=https |
---|
| 53 | firewall-cmd --permanent --add-service=mysql --zone internal |
---|
[b73502c1] | 54 | firewall-cmd --permanent --add-service=ogAdmRepo |
---|
[4db1b6e] | 55 | firewall-cmd --permanent --add-service=ogAdmServer |
---|
| 56 | # Ubuntu 14.04 does not define "rsyncd" service. |
---|
| 57 | firewall-cmd --permanent --add-service=rsyncd || \ |
---|
| 58 | firewall-cmd --permanent --add-port=873/tcp |
---|
| 59 | firewall-cmd --permanent --add-service=samba |
---|
| 60 | firewall-cmd --permanent --add-service=ssh |
---|
| 61 | firewall-cmd --permanent --add-service=tftp |
---|
| 62 | # Adding Multicast ports. |
---|
| 63 | firewall-cmd --permanent --add-port=9000-9051/udp |
---|
[9ddd0ff] | 64 | # Adding BitTorent ports. |
---|
| 65 | firewall-cmd --permanent --add-port=6881-6999/udp |
---|
[4db1b6e] | 66 | # Applying configuration. |
---|
| 67 | firewall-cmd --reload |
---|
| 68 | else |
---|
[9ddd0ff] | 69 | echo "$PROG: Warning: Firewall won't be configured (neither ufw or firewalld are installed)." |
---|
[4db1b6e] | 70 | fi |
---|
| 71 | |
---|
| 72 | # SELinux configuration. |
---|
| 73 | if which setsebool 2>/dev/null; then |
---|
| 74 | # Configuring Apache. |
---|
| 75 | setsebool -P httpd_can_connect_ldap on |
---|
| 76 | semanage fcontext -at httpd_sys_content_t "$OPENGNSYS/www(/.*)?" |
---|
| 77 | # Configuring Samba. |
---|
| 78 | setsebool -P samba_export_all_ro=1 samba_export_all_rw=1 |
---|
| 79 | semanage fcontext -at samba_share_t "$OPENGNSYS/client(/.*)?" |
---|
| 80 | semanage fcontext -at samba_share_t "$OPENGNSYS/images(/.*)?" |
---|
| 81 | # Applying configuration. |
---|
| 82 | restorecon -R $OPENGNSYS |
---|
| 83 | else |
---|
| 84 | echo "$PROG: Warning: SELinux won't be configured (policycoreutils is not installed)." |
---|
| 85 | fi |
---|
| 86 | |
---|