Permalink
Browse files

Finally, Fancy Firewalling...

This adds experimental support for automatic firewalling. Initially, we
don't know the other hosts (until they are exported and collected) so we
start with an blank firewall to all hosts. After hosts start checking
in, we start only allowing specify host ips. For the volume building, we
can't predict (AFAICT) which ports will be used until after the volume
is started, so we initially allow all ports inbound, until the fact gets
the data from the started volume and uses those specific ports. This
naturally takes multiple puppet runs to complete.
  • Loading branch information...
1 parent 269be1c commit 4dbba38fc44e8d7226fdecec12b1237fc24d026d @purpleidea committed Sep 18, 2013
Showing with 150 additions and 12 deletions.
  1. +80 −0 lib/facter/gluster_ports.rb
  2. +9 −1 manifests/host.pp
  3. +26 −0 manifests/host/data.pp
  4. +35 −11 manifests/volume.pp
@@ -0,0 +1,80 @@
+# Simple? gluster module by James
+# Copyright (C) 2010-2013+ James Shubin
+# Written by James Shubin <james@shubin.ca>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+require 'facter'
+
+# find the module_vardir
+dir = Facter.value('puppet_vardirtmp') # nil if missing
+if dir.nil? # let puppet decide if present!
+ dir = Facter.value('puppet_vardir')
+ if dir.nil?
+ var = nil
+ else
+ var = dir.gsub(/\/$/, '')+'/'+'tmp/' # ensure trailing slash
+ end
+else
+ var = dir.gsub(/\/$/, '')+'/'
+end
+
+if var.nil?
+ # if we can't get a valid vardirtmp, then we can't continue
+ uuidfile = nil
+else
+ module_vardir = var+'gluster/'
+ xmlfile = module_vardir+'xml.py'
+end
+
+host = Facter.value('fqdn')
+found = {}
+
+# we need the script installed first to be able to generate the port facts...
+if File.exist?(xmlfile)
+ volumes = `/usr/sbin/gluster volume list`
+ if $?.exitstatus == 0
+ volumes.split.each do |x|
+ # values come out as comma separated strings for direct usage
+ cmd = '/usr/sbin/gluster volume status --xml | '+xmlfile+" ports --volume '"+x+"' --host '"+host+"'"
+ result = `#{cmd}`
+ if $?.exitstatus == 0
+ found[x] = result
+ # TODO: else, print warning
+ end
+ end
+ # TODO: else, print warning
+ end
+end
+
+found.keys.each do |x|
+ Facter.add('gluster_ports_volume_'+x) do
+ #confine :operatingsystem => %w{CentOS, RedHat, Fedora}
+ setcode {
+ # don't reuse single variable to avoid bug #:
+ # http://projects.puppetlabs.com/issues/22455
+ found[x]
+ }
+ end
+end
+
+# list of generated gluster_ports_volume's
+Facter.add('gluster_ports_volumes_facts') do
+ #confine :operatingsystem => %w{CentOS, RedHat, Fedora}
+ setcode {
+ found.keys.collect {|x| 'gluster_ports_volume_'+x }.join(',')
+ }
+end
+
+# vim: ts=8
View
@@ -31,7 +31,15 @@
Gluster::Host[$name] -> Service['glusterd'] # glusterd requires host
# if we're on itself
- if ( "${fqdn}" == "${name}" ) {
+ if "${fqdn}" == "${name}" {
+
+ # store the ip here so that it can be accessed by bricks...
+ class { '::gluster::host::data':
+ #name => $name,
+ ip => "${ip}",
+ fqdn => "${fqdn}",
+ }
+
# don't purge the uuid file generated within
file { "${vardir}/uuid/":
ensure => directory, # make sure this is a directory
View
@@ -0,0 +1,26 @@
+# Simple? gluster module by James
+# Copyright (C) 2010-2013+ James Shubin
+# Written by James Shubin <james@shubin.ca>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+class gluster::host::data(
+ #$name,
+ $ip,
+ $fqdn
+) {
+ # so far, this does nothing but 'store' variables
+}
+
+# vim: ts=8
View
@@ -122,17 +122,6 @@
}
}
- # TODO:
- #if $shorewall {
- # shorewall::rule { 'gluster-TODO':
- # rule => "
- # ACCEPT ${zone} $FW tcp 24009:${endport}
- # ",
- # comment => 'TODO',
- # before => Service['glusterd'],
- # }
- #}
-
# run if vip not defined (by pass mode) or vip exists on this machine
if ($vip == '' or $vipif != '') {
if $start == true {
@@ -161,6 +150,41 @@
# don't manage volume run state
}
}
+
+ $shorewall = $::gluster::server::shorewall
+ if $shorewall {
+ $zone = $::gluster::server::zone # firewall zone
+
+ $ips = $::gluster::server::ips # override host ip list
+ $ip = $::gluster::host::data::ip # ip of brick's host...
+ $source_ips = type($ips) ? {
+ 'array' => inline_template("<%= (ips+[]).uniq.delete_if {|x| x.empty? }.join(',') %>"),
+ default => ["${ip}"],
+ }
+
+ $port = getvar("gluster_ports_volume_${name}") # fact !
+
+ # NOTE: we need to add the $fqdn so that exported resources
+ # don't conflict... I'm not sure they should anyways though
+ @@shorewall::rule { "gluster-volume-${name}-${fqdn}":
+ action => 'ACCEPT',
+ source => "${zone}", # override this on collect...
+ source_ips => $source_ips,
+ dest => '$FW',
+ proto => 'tcp',
+ port => "${port}", # comma separated string or list
+ #comment => "${fqdn}",
+ comment => 'Allow incoming tcp port from glusterfsds.',
+ tag => 'gluster_firewall_volume',
+ ensure => present,
+ }
+ # we probably shouldn't collect the above rule from our self...
+ #Shorewall::Rule <<| tag == 'gluster_firewall_volume' and comment != "${fqdn}" |>> {
+ Shorewall::Rule <<| tag == 'gluster_firewall_volume' |>> {
+ source => "${zone}", # use our source zone
+ before => Service['glusterd'],
+ }
+ }
}
# vim: ts=8

0 comments on commit 4dbba38

Please sign in to comment.