system-config/modules/iptables/manifests/init.pp
Monty Taylor 98604d0215 Don't manage iptables if we're in a choot
In chroots, as with diskimage-builder, managing service starts is
tricky. Also, we don't need to restart the service then, because
the service will get started on boot of the image.

Change-Id: Iaf90005039b8196ba3a0ac05c96d71e034f0b0b1
2014-07-05 15:58:05 -07:00

89 lines
2.5 KiB
Puppet

# Class: iptables
#
# http://projects.puppetlabs.com/projects/1/wiki/Module_Iptables_Patterns
#
# params:
# rules4: A list of additional iptables v4 rules
# eg: [ '-m udp -p udp -s 127.0.0.1 --dport 8125 -j ACCEPT' ]
# rules6: A list of additional iptables v6 rules
# eg: [ '-m udp -p udp -s ::1 --dport 8125 -j ACCEPT' ]
# public_tcp_ports: List of integer TCP ports on which to allow all traffic
# public_udp_ports: List of integer UDP ports on which to allow all traffic
class iptables(
$rules4 = [],
$rules6 = [],
$public_tcp_ports = [],
$public_udp_ports = []
) {
include iptables::params
package { 'iptables':
ensure => present,
name => $::iptables::params::package_name,
}
if ($::in_chroot) {
notify { 'iptables in chroot':
message => 'Iptables not refreshed, running in chroot',
}
$notify_iptables = []
}
else {
service { 'iptables':
name => $::iptables::params::service_name,
require => Package['iptables'],
hasstatus => $::iptables::params::service_has_status,
status => $::iptables::params::service_status_cmd,
hasrestart => $::iptables::params::service_has_restart,
}
$notify_iptables = Service['iptables']
}
file { $::iptables::params::rules_dir:
ensure => directory,
require => Package['iptables'],
}
# This file is not required on Red Hat distros... but it
# won't hurt to softlink to it either
file { "${::iptables::params::rules_dir}/rules":
ensure => present,
owner => 'root',
group => 'root',
mode => '0640',
content => template('iptables/rules.erb'),
require => [
Package['iptables'],
File[$::iptables::params::rules_dir],
],
# When this file is updated, make sure the rules get reloaded.
notify => $notify_iptables,
}
file { $::iptables::params::ipv4_rules:
ensure => link,
owner => 'root',
group => 'root',
mode => '0640',
target => "${::iptables::params::rules_dir}/rules",
require => File["${::iptables::params::rules_dir}/rules"],
notify => $notify_iptables,
}
file { $::iptables::params::ipv6_rules:
ensure => present,
owner => 'root',
group => 'root',
mode => '0640',
content => template('iptables/rules.v6.erb'),
require => [
Package['iptables'],
File[$::iptables::params::rules_dir],
],
# When this file is updated, make sure the rules get reloaded.
notify => $notify_iptables,
replace => true,
}
}