Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Add automatic firewalling for replicas.
This adds automatic firewalling so that all the replicas have the right ports open, and only the right ports open to the right replicas.
- Loading branch information
1 parent
73712d1
commit 31ede1a
Showing
5 changed files
with
208 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| # FreeIPA templating module by James | ||
| # Copyright (C) 2012-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' | ||
| require 'resolv' | ||
|
|
||
| # try and pick the _right_ ip that ipa should use by default... | ||
| fqdn = Facter.value('fqdn') | ||
| if not fqdn.nil? | ||
| ip = Resolv.getaddress "#{fqdn}" | ||
| if not ip.nil? | ||
| Facter.add('ipa_host_ip') do | ||
| #confine :operatingsystem => %w{CentOS, RedHat, Fedora} | ||
| setcode { | ||
| ip | ||
| } | ||
| end | ||
| end | ||
| end | ||
|
|
||
| # vim: ts=8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| # FreeIPA templating module by James | ||
| # Copyright (C) 2012-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/>. | ||
|
|
||
| # NOTE: this wraps shorewall::rule so that we can add on additional fake 'tags' | ||
| define ipa::rulewrapper( | ||
| $action = '', | ||
| $source = '', | ||
| $source_ips = [], | ||
| $dest = '', | ||
| $dest_ips = [], | ||
| $proto = '', | ||
| $port = [], | ||
| $sport = [], | ||
| $original = [], | ||
| $comment = '', | ||
| $ensure = present, | ||
| $match = '' # additional tag parameter | ||
| ) { | ||
| shorewall::rule { "${name}": | ||
| action => "${action}", | ||
| source => "${source}", | ||
| source_ips => $source_ips, | ||
| dest => "${dest}", | ||
| dest_ips => $dest_ips, | ||
| proto => "${proto}", | ||
| port => $port, | ||
| sport => $sport, | ||
| comment => "${comment}", | ||
| ensure => $ensure, | ||
| } | ||
| } | ||
|
|
||
| # vim: ts=8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| # FreeIPA templating module by James | ||
| # Copyright (C) 2012-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/>. | ||
|
|
||
| # NOTE: all replication agreements are bi-directional for now due to FreeIPA... | ||
| # NOTE: in the future, it would be quite cool to allow uni-directional replicas | ||
| # NOTE: this type has been engineered to fit easily with the topology datatype: | ||
| # $ring = { # example flat topology as expressed in the std. format | ||
| # 'fqdn1': ['fqdn2', 'fqdn3'], | ||
| # 'fqdn2': ['fqdn3', 'fqdn1'], | ||
| # 'fqdn3': ['fqdn1', 'fqdn2'], | ||
| # } | ||
| # | ||
| # ipa::server::replica::firewall { $ring["${::fqdn}"]: # all automatic | ||
| # peer => "${::fqdn}", | ||
| # } | ||
| define ipa::server::replica::firewall( # to | ||
| $peer = '', # from (usually we run this on itself!) | ||
| $ip = '' # you can specify which ip address to use (if multiple) | ||
| ) { | ||
|
|
||
| include ipa::server::replica::firewall::base | ||
|
|
||
| # NOTE: the peer vs. valid_peer names are by convention (but confusing) | ||
| $self = "${peer}" # from (a) | ||
| if "${self}" != "${::fqdn}" { | ||
| fail('Are you sure you want to run this on a different host ?') | ||
| } | ||
| $valid_peer = "${name}" # to (b) | ||
|
|
||
| $zone = $::ipa::server::zone # firewall zone | ||
| $valid_ip = "${ip}" ? { | ||
| '' => "${::ipa_host_ip}" ? { # smart fact... | ||
| '' => "${::ipaddress}", # puppet picks! | ||
| default => "${::ipa_host_ip}", # smart | ||
| }, | ||
| default => "${ip}", # user selected | ||
| } | ||
| if "${valid_ip}" == '' { | ||
| fail('No valid IP exists!') | ||
| } | ||
|
|
||
| # NOTE: an exported resource here says: "i would like to connect to you" | ||
| # this means the collector's (receiver) perspective source ip is *my* ip | ||
|
|
||
| # NOTE: we need to add the $fqdn so that exported resources | ||
| # don't conflict... I'm not sure they should anyways though | ||
| @@ipa::rulewrapper { "ipa-server-replica-ldaps-${name}-${::fqdn}": | ||
| action => 'LDAPS/ACCEPT', | ||
| source => "${zone}", # override this on collect... | ||
| source_ips => ["${valid_ip}"], # i am the source ! | ||
| dest => '$FW', | ||
| proto => 'tcp', | ||
| #port => '', # comma separated string or list | ||
| comment => 'Allow incoming tcp:636 from ${::fqdn}.', | ||
| tag => 'ipa-server-replica', | ||
| match => "${name}", # used for collection | ||
| ensure => present, | ||
| } | ||
|
|
||
| # FIXME: add all the necessary ports for ipa-replication here... | ||
| } | ||
|
|
||
| # vim: ts=8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| # FreeIPA templating module by James | ||
| # Copyright (C) 2012-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 ipa::server::replica::firewall::base { | ||
| include ipa::server | ||
|
|
||
| $zone = $::ipa::server::zone # firewall zone | ||
| $shorewall = $::ipa::server::shorewall # enable fw...? | ||
|
|
||
| # open the firewall so that replicas can connect to what they will need | ||
| Ipa::Rulewrapper <<| tag == 'ipa-server-replica' and match == "${::fqdn}" |>> { | ||
| #Shorewall::Rule <<| tag == 'ipa-server-replica' and match == "${::fqdn}" |>> { | ||
| source => "${zone}", # use our source zone | ||
| # TODO: this below before is basically untested for usefulness! | ||
| before => Exec['ipa-install'], # open bi-directional fw first! | ||
| # TODO: the below require is basically untested for usefulness! | ||
| require => Exec['ipa-clean-peers'], # let the peers clean up first! | ||
| ensure => $shorewall ? { | ||
| absent => absent, | ||
| 'absent' => absent, | ||
| present => present, | ||
| 'present' => present, | ||
| default => present, | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| # vim: ts=8 |