7f4c2a
From d51815d7d0b065e447e5f51f26f1f724d2a3406f Mon Sep 17 00:00:00 2001
7f4c2a
From: anand <anekkunt@redhat.com>
7f4c2a
Date: Sat, 22 Aug 2015 01:09:53 +0530
7f4c2a
Subject: [PATCH 326/330] firewall/spec: Create glusterfs firewall service if firewalld installed.
7f4c2a
7f4c2a
It creates glusterfs firewall service during installation.
7f4c2a
7f4c2a
glusterfs service : It contains all default ports which needs to be opened.
7f4c2a
During installation  glusterfs.xml is copied into firewall service directory(/usr/lib/firewalld/services/).
7f4c2a
7f4c2a
Note:
7f4c2a
1.For bricks: It opens the 512 ports, if brick is running out side this range(>49664) then admin need to open the port
7f4c2a
for that brick.
7f4c2a
2.By default this service is not enabled in any of zone.
7f4c2a
7f4c2a
To enable this service(glusterfs) in firewall:
7f4c2a
7f4c2a
1. Get active zone(s) in node
7f4c2a
     firewall-cmd  --get-active-zones
7f4c2a
7f4c2a
2. Enable this service(glusterfs) to zone(s)
7f4c2a
   firewall-cmd  --zone=<zone_name>  --add-service=glusterfs               --To apply runtime
7f4c2a
   firewall-cmd  --permanent  --zone=<zone_name>  --add-service=glusterfs  --To apply permanent
7f4c2a
7f4c2a
Note:
7f4c2a
  we can also use firewall-config which gives GUI to configure firewall.
7f4c2a
7f4c2a
Backportof:
7f4c2a
>>http://review.gluster.org/#/c/11989/19
7f4c2a
>>Change-Id: Id97fe620c560fd10599511d751aed11a99ba4da5
7f4c2a
>>BUG: 1253967
7f4c2a
7f4c2a
Change-Id: I8fde5d908098d490aa4ab39877aab8dc44ebeacc
7f4c2a
BUG: 1253774
7f4c2a
Signed-off-by: anand <anekkunt@redhat.com>
7f4c2a
Reviewed-on: https://code.engineering.redhat.com/gerrit/57564
7f4c2a
Reviewed-by: Kaushal Madappa <kaushal@redhat.com>
7f4c2a
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
7f4c2a
Tested-by: Atin Mukherjee <amukherj@redhat.com>
7f4c2a
---
7f4c2a
 configure.ac                   |   18 ++++++++++++++++++
7f4c2a
 extras/Makefile.am             |    2 +-
7f4c2a
 extras/firewalld/Makefile.am   |    6 ++++++
7f4c2a
 extras/firewalld/glusterfs.xml |   13 +++++++++++++
7f4c2a
 glusterfs.spec.in              |   36 ++++++++++++++++++++++++++++++++++++
7f4c2a
 5 files changed, 74 insertions(+), 1 deletions(-)
7f4c2a
 create mode 100644 extras/firewalld/Makefile.am
7f4c2a
 create mode 100644 extras/firewalld/glusterfs.xml
7f4c2a
7f4c2a
diff --git a/configure.ac b/configure.ac
7f4c2a
index a93c1cd..dfe105f 100644
7f4c2a
--- a/configure.ac
7f4c2a
+++ b/configure.ac
7f4c2a
@@ -211,6 +211,7 @@ AC_CONFIG_FILES([Makefile
7f4c2a
                 extras/ocf/volume
7f4c2a
                 extras/LinuxRPM/Makefile
7f4c2a
                 extras/geo-rep/Makefile
7f4c2a
+                extras/firewalld/Makefile
7f4c2a
                 extras/hook-scripts/add-brick/Makefile
7f4c2a
                 extras/hook-scripts/add-brick/pre/Makefile
7f4c2a
                 extras/hook-scripts/add-brick/post/Makefile
7f4c2a
@@ -731,6 +732,22 @@ AC_SUBST(ZLIB_CFLAGS)
7f4c2a
 AC_SUBST(ZLIB_LIBS)
7f4c2a
 # end CDC xlator secion
7f4c2a
 
7f4c2a
+#start firewalld section
7f4c2a
+BUILD_FIREWALLD="no"
7f4c2a
+AC_ARG_ENABLE([firewalld],
7f4c2a
+              AC_HELP_STRING([--enable-firewalld],
7f4c2a
+                             [enable installation configuration for firewalld]),
7f4c2a
+              [BUILD_FIREWALLD="${enableval}"], [BUILD_FIREWALLD="no"])
7f4c2a
+
7f4c2a
+if test "x${BUILD_FIREWALLD}" = "xyes"; then
7f4c2a
+        if !(which firewalld 1>/dev/null 2>&1) ; then
7f4c2a
+                BUILD_FIREWALLD="no (firewalld not installed)"
7f4c2a
+        fi
7f4c2a
+fi
7f4c2a
+AM_CONDITIONAL([USE_FIREWALLD],test ["x${BUILD_FIREWALLD}" =  "xyes"])
7f4c2a
+
7f4c2a
+#endof firewald section
7f4c2a
+
7f4c2a
 # Data tiering requires sqlite
7f4c2a
 AC_ARG_ENABLE([tiering],
7f4c2a
                AC_HELP_STRING([--disable-tiering],
7f4c2a
@@ -1343,4 +1360,5 @@ echo "Encryption xlator    : $BUILD_CRYPT_XLATOR"
7f4c2a
 echo "Unit Tests           : $BUILD_UNITTEST"
7f4c2a
 echo "POSIX ACLs           : $BUILD_POSIX_ACLS"
7f4c2a
 echo "Data Classification  : $BUILD_GFDB"
7f4c2a
+echo "firewalld-config     : $BUILD_FIREWALLD"
7f4c2a
 echo
7f4c2a
diff --git a/extras/Makefile.am b/extras/Makefile.am
7f4c2a
index ba2bef3..da99ecc 100644
7f4c2a
--- a/extras/Makefile.am
7f4c2a
+++ b/extras/Makefile.am
7f4c2a
@@ -5,7 +5,7 @@ EditorModedir = $(docdir)
7f4c2a
 EditorMode_DATA = glusterfs-mode.el glusterfs.vim
7f4c2a
 
7f4c2a
 SUBDIRS = init.d systemd benchmarking hook-scripts $(OCF_SUBDIR) LinuxRPM \
7f4c2a
-          $(GEOREP_EXTRAS_SUBDIR) ganesha snap_scheduler
7f4c2a
+          $(GEOREP_EXTRAS_SUBDIR) ganesha snap_scheduler firewalld
7f4c2a
 
7f4c2a
 confdir = $(sysconfdir)/glusterfs
7f4c2a
 conf_DATA = glusterfs-logrotate gluster-rsyslog-7.2.conf gluster-rsyslog-5.8.conf \
7f4c2a
diff --git a/extras/firewalld/Makefile.am b/extras/firewalld/Makefile.am
7f4c2a
new file mode 100644
7f4c2a
index 0000000..a5c11b0
7f4c2a
--- /dev/null
7f4c2a
+++ b/extras/firewalld/Makefile.am
7f4c2a
@@ -0,0 +1,6 @@
7f4c2a
+EXTRA_DIST = glusterfs.xml
7f4c2a
+
7f4c2a
+if USE_FIREWALLD
7f4c2a
+staticdir = /usr/lib/firewalld/services/
7f4c2a
+static_DATA = glusterfs.xml
7f4c2a
+endif
7f4c2a
diff --git a/extras/firewalld/glusterfs.xml b/extras/firewalld/glusterfs.xml
7f4c2a
new file mode 100644
7f4c2a
index 0000000..f8efd90
7f4c2a
--- /dev/null
7f4c2a
+++ b/extras/firewalld/glusterfs.xml
7f4c2a
@@ -0,0 +1,13 @@
7f4c2a
+
7f4c2a
+<service>
7f4c2a
+<short>glusterfs-static</short>
7f4c2a
+<description>Default ports for gluster-distributed storage</description>
7f4c2a
+<port protocol="tcp" port="24007"/>    
7f4c2a
+<port protocol="tcp" port="24008"/>    
7f4c2a
+<port protocol="tcp" port="38465"/>    
7f4c2a
+<port protocol="tcp" port="38466"/>    
7f4c2a
+<port protocol="tcp" port="38467"/>    
7f4c2a
+<port protocol="tcp" port="38468"/>    
7f4c2a
+<port protocol="tcp" port="38469"/>    
7f4c2a
+<port protocol="tcp" port="49152-49664"/>  
7f4c2a
+</service>
7f4c2a
diff --git a/glusterfs.spec.in b/glusterfs.spec.in
7f4c2a
index 78bd311..f9e0447 100644
7f4c2a
--- a/glusterfs.spec.in
7f4c2a
+++ b/glusterfs.spec.in
7f4c2a
@@ -103,6 +103,10 @@
7f4c2a
 %global _with_systemd true
7f4c2a
 %endif
7f4c2a
 
7f4c2a
+%if ( 0%{?fedora} ) || ( 0%{?rhel} && 0%{?rhel} >= 7 )
7f4c2a
+%global _with_firewalld --enable-firewalld
7f4c2a
+%endif
7f4c2a
+
7f4c2a
 %if 0%{?_tmpfilesdir:1}
7f4c2a
 %define _with_tmpfilesdir --with-tmpfilesdir=%{_tmpfilesdir}
7f4c2a
 %else
7f4c2a
@@ -243,6 +247,10 @@ BuildRequires:    glib2-devel
7f4c2a
 BuildRequires:    libattr-devel
7f4c2a
 %endif
7f4c2a
 
7f4c2a
+%if (0%{?_with_firewalld:1})
7f4c2a
+BuildRequires:    firewalld
7f4c2a
+%endif
7f4c2a
+
7f4c2a
 Obsoletes:        hekafs
7f4c2a
 Obsoletes:        %{name}-common < %{version}-%{release}
7f4c2a
 Obsoletes:        %{name}-core < %{version}-%{release}
7f4c2a
@@ -639,6 +647,7 @@ export LDFLAGS
7f4c2a
         %{?_without_epoll} \
7f4c2a
         %{?_without_fusermount} \
7f4c2a
         %{?_without_georeplication} \
7f4c2a
+        %{?_with_firewalld} \
7f4c2a
         %{?_without_ocf} \
7f4c2a
         %{?_without_qemu_block} \
7f4c2a
         %{?_without_rdma} \
7f4c2a
@@ -896,6 +905,15 @@ if [ -e /etc/ld.so.conf.d/glusterfs.conf ]; then
7f4c2a
     rm -f /etc/ld.so.conf.d/glusterfs.conf
7f4c2a
     /sbin/ldconfig
7f4c2a
 fi
7f4c2a
+
7f4c2a
+%if (0%{?_with_firewalld:1})
7f4c2a
+#reload service files if firewalld running
7f4c2a
+if $(systemctl is-active firewalld 1>/dev/null 2>&1;; then
7f4c2a
+  #firewalld-filesystem is not available for rhel7, so command used for reload.
7f4c2a
+  firewall-cmd  --reload
7f4c2a
+fi
7f4c2a
+%endif
7f4c2a
+
7f4c2a
 pidof -c -o %PPID -x glusterd &> /dev/null
7f4c2a
 if [ $? -eq 0 ]; then
7f4c2a
     kill -9 `pgrep -f gsyncd.py` &> /dev/null
7f4c2a
@@ -956,6 +974,17 @@ fi
7f4c2a
 %postun api
7f4c2a
 /sbin/ldconfig
7f4c2a
 
7f4c2a
+%if ( 0%{?_build_server} )
7f4c2a
+%postun server
7f4c2a
+%if (0%{?_with_firewalld:1})
7f4c2a
+#reload service files if firewalld running
7f4c2a
+if $(systemctl is-active firewalld 1>/dev/null 2>&1;; then
7f4c2a
+    firewall-cmd  --reload
7f4c2a
+fi
7f4c2a
+%endif
7f4c2a
+%endif
7f4c2a
+
7f4c2a
+
7f4c2a
 %postun libs
7f4c2a
 /sbin/ldconfig
7f4c2a
 
7f4c2a
@@ -1339,6 +1368,10 @@ fi
7f4c2a
 %{_libexecdir}/glusterfs/peer_add_secret_pub
7f4c2a
 %endif
7f4c2a
 
7f4c2a
+%if ( 0%{?_with_firewalld:1} )
7f4c2a
+/usr/lib/firewalld/services/glusterfs.xml
7f4c2a
+%endif
7f4c2a
+
7f4c2a
 
7f4c2a
 ##-----------------------------------------------------------------------------
7f4c2a
 ## All %pretrans should be placed here and keep them sorted
7f4c2a
@@ -1931,6 +1964,9 @@ end
7f4c2a
 
7f4c2a
 %changelog
7f4c2a
 
7f4c2a
+* Tue Aug 25 2015 Anand Nekkunti <anekkunt@redhat.com>
7f4c2a
+- adding glusterfs-firewalld service (#1253774)
7f4c2a
+
7f4c2a
 * Fri Jun 19 2015 Bala.FA <barumuga@redhat.com>
7f4c2a
 - exclude libgfdb.pc conditionally for rhel-5 (#1233486)
7f4c2a
 
7f4c2a
-- 
7f4c2a
1.7.1
7f4c2a