The idea of managing our iptables
rules with Puppet has been brought up. I see that augeas
has an iptables
lense but it is currently experimental.
Does anyone have any suggestions as to how to handle this? Ideally, I'd like to construct the chains based on a server's class.
Puppet Labs has an example right in their wiki: Module Iptables Patterns
In short: You create fragments for each service and then install them by invoking the ipt_fragment defined-type:
When a fragment is installed (they're in /etc/iptables.d/), it triggers the execution of a script that concatenates all the fragments and restarts iptables.
Here's what I'm doing with Red Hat Enterprise (RHEL).
RHEL has an
iptables
service that loads rules from/etc/sysconfig/iptables
and I'm working with modifying that file and restarting the iptables service. Many people like to drop fragments into an iptables.d directory and build an iptables (via make or something like that) ruleset from that. I include stuff for rebuilding the default ruleset, but that usually never does anything. If your needs are simple you could just copy an iptables file to the system.Despite how ugly this seems, it's quite thoroughly tested on RHEL4, RHEL5 and RHEL6.
I had this going before augeas support was in puppet. If I was writing it again today I'd look at the augeas iptables lens before resorting to
exec { "perl ...": }
.Some global defines for editing files in place
Based on stuff originally from http://reductivelabs.com/trac/puppet/wiki/SimpleTextRecipes
My iptables class:
Some examples of usage in other classes:
The question is, what do you intend to accomplish?
Putting iptables on Puppet is easy: put the script on the puppet server, and serve it to wherever you need it. If it needs some customization, make it a template.
Now, perhaps you want something like "If host X has WebServer, then ports 80 and 443 to it must be open". In that case, what I suggest you to do is to compose the script from multiple file parts, using Common module's
concatenated_file
orconcatfilepart
(I prefer the latter, which enables ordering, but it is not available on all forks -- I'm point you to camptocamp's, which has it).These file parts can be easily be written using templates. The trick is that you export the
concatfilepart
on theApache
class (possibly by calling a define that prepares aconcatfilepart
based on parameters such as IP address and port), and on theiptables
class you'd realize all the exportedconcatfilepart
tagged withiptables
or something like that.If you do that, I'd love to see that module on github. I never got to write an iptables module. :-)