Git Product home page Git Product logo

puppetlabs-firewall's Introduction

firewall

PR Testing

Table of Contents

  1. Overview - What is the firewall module?
  2. Module description - What does the module do?
  3. Setup - The basics of getting started with firewall
  4. Usage - Configuration and customization options
  5. Reference - An under-the-hood peek at what the module is doing
  6. Limitations - OS compatibility, etc.
  7. License
  8. Firewall_multi - Arrays for certain parameters
  9. Development - Guide for contributing to the module

Overview

The firewall module lets you manage firewall rules with Puppet.

Module description

PuppetLabs' firewall module introduces the firewall resource, which is used to manage and configure firewall rules from within the Puppet DSL. This module offers support for iptables and ip6tables. The module also introduces the firewallchain resource, which allows you to manage chains or firewall lists and ebtables for bridging support. At the moment, only iptables and ip6tables chains are supported.

The firewall module acts on your running firewall, making immediate changes as the catalog executes. Defining default pre and post rules allows you to provide global defaults for your hosts before and after any custom rules. Defining pre and post rules is also necessary to help you avoid locking yourself out of your own boxes when Puppet runs.

Setup

What firewall affects

  • Every node running a firewall
  • Firewall settings in your system
  • Connection settings for managed nodes
  • Unmanaged resources (get purged)

Setup requirements

Firewall uses Ruby-based providers, so you must enable pluginsync.

Beginning with firewall

In the following two sections, you create new classes and then create firewall rules related to those classes. These steps are optional but provide a framework for firewall rules, which is helpful if you’re just starting to create them.

If you already have rules in place, then you don’t need to do these two sections. However, be aware of the ordering of your firewall rules. The module will dynamically apply rules in the order they appear in the catalog, meaning a deny rule could be applied before the allow rules. This might mean the module hasn’t established some of the important connections, such as the connection to the Puppet server.

The following steps are designed to ensure that you keep your SSH and other connections, primarily your connection to your Puppet server. If you create the pre and post classes described in the first section, then you also need to create the rules described in the second section.

Create the my_fw::pre and my_fw::post Classes

This approach employs a whitelist setup, so you can define what rules you want and everything else is ignored rather than removed.

The code in this section does the following:

  • The 'require' parameter in firewall {} ensures my_fw::pre is run before any other rules.
  • In the my_fw::post class declaration, the 'before' parameter ensures my_fw::post is run after any other rules.

The rules in the pre and post classes are fairly general. These two classes ensure that you retain connectivity and that you drop unmatched packets appropriately. The rules you define in your manifests are likely to be specific to the applications you run.

  1. Add the pre class to my_fw/manifests/pre.pp, and any default rules to your pre.pp file first — in the order you want them to run.
class my_fw::pre {
  Firewall {
    require => undef,
  }

  # Default firewall rules
  firewall { '000 accept all icmp':
    proto => 'icmp',
    jump  => 'accept',
  }
  -> firewall { '001 accept all to lo interface':
    proto   => 'all',
    iniface => 'lo',
    jump    => 'accept',
  }
  -> firewall { '002 reject local traffic not on loopback interface':
    iniface     => '! lo',
    proto       => 'all',
    destination => '127.0.0.1/8',
    jump        => 'reject',
  }
  -> firewall { '003 accept related established rules':
    proto  => 'all',
    state  => ['RELATED', 'ESTABLISHED'],
    jump   => 'accept',
  }
}

The rules in pre allow basic networking (such as ICMP and TCP) and ensure that existing connections are not closed.

  1. Add the post class to my_fw/manifests/post.pp and include any default rules — apply these last.
class my_fw::post {
  firewall { '999 drop all':
    proto  => 'all',
    jump   => 'drop',
    before => undef,
  }
}

Alternatively, the firewallchain type can be used to set the default policy:

firewallchain { 'INPUT:filter:IPv4':
  ensure => present,
  policy => drop,
  before => undef,
}

Create firewall rules

The rules you create here are helpful if you don’t have any existing rules; they help you order your firewall configurations so you don’t lock yourself out of your box.

Rules are persisted automatically between reboots, although there are known issues with ip6tables on older Debian/Ubuntu distributions. There are also known issues with ebtables.

  1. Use the following code to set up the default parameters for all of the firewall rules that you will establish later. These defaults will ensure that the pre and post classes are run in the correct order and avoid locking you out of your box during the first Puppet run.
Firewall {
  before  => Class['my_fw::post'],
  require => Class['my_fw::pre'],
}
  1. Declare the my_fw::pre and my_fw::post classes to satisfy dependencies. You can declare these classes using an external node classifier or the following code:
class { ['my_fw::pre', 'my_fw::post']: }
  1. Include the firewall class to ensure the correct packages are installed:
class { 'firewall': }
  1. If you want to remove unmanaged firewall rules, add the following code to set up a metatype to purge unmanaged firewall resources in your site.pp or another top-scope file. This will clear any existing rules and make sure that only rules defined in Puppet exist on the machine.
resources { 'firewall':
  purge => true,
}

To purge unmanaged firewall chains, add:

resources { 'firewallchain':
  purge => true,
}

Internal chains can not be deleted. In order to avoid all the confusing Warning/Notice messages when using purge => true, like these ones:

Warning: Inbuilt Chains may not be deleted. Chain POSTROUTING:mangle:IPv6 will be flushed and have it's policy reverted to default.

Please create firewallchains for every internal chain. Here is an example:

firewallchain { 'POSTROUTING:mangle:IPv6':
  ensure  => present,
}

resources { 'firewallchain':
  purge => true,
}

Note: If you need more fine-grained control about which unmananged rules get removed, investigate the purge and ignore_foreign parameters available in firewallchain.

Note: ignore_foreign of firewallchain does not work as expected with a resources purge of firewall.

Upgrading

Use these steps if you already have a version of the firewall module installed.

From version 0.2.0 and more recent

Upgrade the module with the puppet module tool as normal:

puppet module upgrade puppetlabs/firewall

Usage

There are two kinds of firewall rules you can use with firewall: default rules and application-specific rules. Default rules apply to general firewall settings, whereas application-specific rules manage firewall settings for a specific application, node, etc.

All rules employ a numbering system in the resource's title that is used for ordering. When titling your rules, make sure you prefix the rule with a number, for example, '000 accept all icmp requests'. 000 runs first, 999 runs last.

Note: The ordering range 9000-9999 is reserved for unmanaged rules. Do not specify any firewall rules in this range.

Default rules

You can place default rules in either my_fw::pre or my_fw::post, depending on when you would like them to run. Rules placed in the pre class will run first, and rules in the post class, last.

In iptables, the title of the rule is stored using the comment feature of the underlying firewall subsystem. Values must match '/^\d+[[:graph:][:space:]]+$/'.

Examples of default rules

Basic accept ICMP request example:

firewall { '000 accept all icmp requests':
  proto => 'icmp',
  jump  => 'accept',
}

Drop all:

firewall { '999 drop all other requests':
  jump => 'drop',
}

Example of an IPv6 rule

IPv6 rules can be specified using the ip6tables provider:

firewall { '006 Allow inbound SSH (v6)':
  dport    => 22,
  proto    => 'tcp',
  jump     => 'accept',
  protocol => 'ip6tables',
}

Application-specific rules

Puppet doesn't care where you define rules, and this means that you can place your firewall resources as close to the applications and services that you manage as you wish. If you use the roles and profiles pattern then it makes sense to create your firewall rules in the profiles, so they remain close to the services managed by the profile.

This is an example of firewall rules in a profile:

class profile::apache {
  include apache
  apache::vhost { 'mysite':
    ensure => present,
  }

  firewall { '100 allow http and https access':
    dport  => [80, 443],
    proto  => 'tcp',
    jump   => 'accept',
  }
}

Rule inversion

Firewall rules may be inverted by prefixing the value of a parameter by "! ".

Parameters that understand inversion are: connmark, ctstate, destination, dport, dst_range, dst_type, iniface, outiface, port, proto, source, sport, src_range and src_type.

If the value is an array, then either the first value of the array, or all of its values must be prefixed in order to invert them all. For most array attributes it is not possible to invert only one passed value.

Examples:

firewall { '001 disallow esp protocol':
  jump   => 'accept',
  proto  => '! esp',
}

firewall { '002 drop NEW external website packets with FIN/RST/ACK set and SYN unset':
  chain     => 'INPUT',
  state     => 'NEW',
  jump      => 'drop',
  proto     => 'tcp',
  sport     => ['! http', '443'],
  source    => '! 10.0.0.0/8',
  tcp_flags => '! FIN,SYN,RST,ACK SYN',
}

There are exceptions to this however, with attributes such as src_type, dst_type and ipset allowing the user to negate each passed values seperately.

Examples:

firewall { '001 allow local disallow anycast':
  jump     => 'accept',
  src_type => ['LOCAL', '! ANYCAST'],
}

Additional uses for the firewall module

You can apply firewall rules to specific nodes. Usually, you should put the firewall rule in another class and apply that class to a node. Apply a rule to a node as follows:

node 'some.node.com' {
  firewall { '111 open port 111':
    dport => 111,
  }
}

You can also do more complex things with the firewall resource. This example sets up static NAT for the source network 10.1.2.0/24:

firewall { '100 snat for network foo2':
  chain    => 'POSTROUTING',
  jump     => 'MASQUERADE',
  proto    => 'all',
  outiface => 'eth0',
  source   => '10.1.2.0/24',
  table    => 'nat',
}

You can also change the TCP MSS value for VPN client traffic:

firewall { '110 TCPMSS for VPN clients':
  chain     => 'FORWARD',
  table     => 'mangle',
  source    => '10.0.2.0/24',
  proto     => 'tcp',
  tcp_flags => 'SYN,RST SYN',
  mss       => '1361:1541',
  set_mss   => '1360',
  jump      => 'TCPMSS',
}

The following will mirror all traffic sent to the server to a secondary host on the LAN with the TEE target:

firewall { '503 Mirror traffic to IDS':
  proto   => 'all',
  jump    => 'TEE',
  gateway => '10.0.0.2',
  chain   => 'PREROUTING',
  table   => 'mangle',
}

The following example creates a new chain and forwards any port 5000 access to it.

firewall { '100 forward to MY_CHAIN':
  chain   => 'INPUT',
  jump    => 'MY_CHAIN',
}

# The namevar here is in the format chain_name:table:protocol
firewallchain { 'MY_CHAIN:filter:IPv4':
  ensure  => present,
}

firewall { '100 my rule':
  chain   => 'MY_CHAIN',
  jump    => 'accept',
  proto   => 'tcp',
  dport   => 5000,
}

Setup NFLOG for a rule.

firewall {'666 for NFLOG':
  proto           => 'all',
  jump            => 'NFLOG',
  nflog_group     => 3,
  nflog_prefix    => 'nflog-test',
  nflog_size      => 256,
  nflog_threshold => 1,
}

Duplicate rule behaviour

It is possible for an unmanaged rule to exist on the target system that has the same comment as the rule specified in the manifest. This configuration is not supported by the firewall module.

In the event of a duplicate rule, the module will throw an error message notifying the user that it has found a duplicate and halt in it's update.

This behaviour was previously configurable via the onduplicaterulebehaviour parameter. However the implementation of this resulted in a massive slowdown of the module and so this has been removed in favour of a simple error being thrown whenever a duplicate is detected.

Additional information

Access the inline documentation:

puppet describe firewall

Or

puppet doc -r type
(and search for firewall)

Reference

For information on the classes and types, see the REFERENCE.md. For information on the facts, see below.

Facts:

Fact: ip6tables_version

A Facter fact that can be used to determine what the default version of ip6tables is for your operating system/distribution.

Fact: iptables_version

A Facter fact that can be used to determine what the default version of iptables is for your operating system/distribution.

Fact: iptables_persistent_version

Retrieves the version of iptables-persistent from your OS. This is a Debian/Ubuntu specific fact.

Limitations

For an extensive list of supported operating systems, see metadata.json

SLES

The socket parameter is not supported on SLES. In this release it will cause the catalog to fail with iptables failures, rather than correctly warn you that the features are unusable.

Oracle Enterprise Linux

The socket and owner parameters are unsupported on Oracle Enterprise Linux when the "Unbreakable" kernel is used. These may function correctly when using the stock RedHat kernel instead. Declaring either of these parameters on an unsupported system will result in iptable rules failing to apply.

Passing firewall parameter values as arrays with firewall_multi module

You might sometimes need to pass arrays, such as arrays of source or destination addresses, to some parameters in contexts where iptables itself does not allow arrays.

A community module, alexharvey-firewall_multi, provides a defined type wrapper to spawn firewall resources for arrays of certain inputs.

For example:

firewall_multi { '100 allow http and https access':
  source => [
    '10.0.10.0/24',
    '10.0.12.0/24',
    '10.1.1.128',
  ],
  dport  => [80, 443],
  proto  => 'tcp',
  jump   => 'accept',
}

For more information see the documentation at alexharvey-firewall_multi.

Known issues

MCollective causes PE to reverse firewall rule order

Firewall rules appear in reverse order if you use MCollective to run Puppet in Puppet Enterprise 2016.1, 2015.3, 2015.2, or 3.8.x.

If you use MCollective to kick off Puppet runs (mco puppet runonce -I agent.example.com) while also using the puppetlabs/firewall module, your firewall rules might be listed in reverse order.

In many firewall configurations, the last rule drops all packets. If the rule order is reversed, this rule is listed first and network connectivity fails.

To prevent this issue, do not use MCollective to kick off Puppet runs. Use any of the following instead:

  • Run puppet agent -t on the command line.
  • Use a cron job.
  • Click Run Puppet in the console.

condition parameter

The condition parameter requires xtables-addons to be installed locally. For ubuntu distributions xtables-addons-common package can be installed by running command: apt-get install xtables-addons-common or running a manifest:

package { 'xtables-addons-common':
  ensure => 'latest',
}

For other distributions (RedHat, Debian, Centos etc) manual installation of the xtables-addons package is required.

Reporting Issues

Please report any bugs in the Puppetlabs GitHub issue tracker:

https://github.com/puppetlabs/puppetlabs-firewall/issues

License

This codebase is licensed under the Apache2.0 licensing, however due to the nature of the codebase the open source dependencies may also use a combination of AGPL, BSD-2, BSD-3, GPL2.0, LGPL, MIT and MPL Licensing.

Development

Acceptance tests for this module leverage puppet_litmus. To run the acceptance tests follow the instructions here. You can also find a tutorial and walkthrough of using Litmus and the PDK on YouTube.

If you run into an issue with this module, or if you would like to request a feature, please file a ticket. Every Monday the Puppet IA Content Team has office hours in the Puppet Community Slack, alternating between an EMEA friendly time (1300 UTC) and an Americas friendly time (0900 Pacific, 1700 UTC).

If you have problems getting this module up and running, please contact Support.

If you submit a change to this module, be sure to regenerate the reference documentation as follows:

puppet strings generate --format markdown --out REFERENCE.md

Testing

Make sure you have:

  • rake
  • bundler

Install the necessary gems:

bundle install

And run the tests from the root of the source code:

bundle exec rake parallel_spec

See the Github Action runs for information on running the acceptance and other tests.

Migration path to v7.0.0

As of v7.0.0 of this module a major rework has been done to adopt the puppet-resource_api into the module and use it style of code in place of the original form of Puppet Type and Providers. This was done in the most part to increase the ease with with the module could be maintained and updated in the future, the changes helping to structure the module in such a way as to be more easily understood and altered going forward.

As part of this process several breaking changes where made to the code that will need to be accounted for whenever you update to this new version of the module, with these changes including:

  • The provider attibute within the firewall type has been renamed to protocol, both to bring it in line with the matching attribute within the firewallchain type and due to the resource_api forbidding the use of provider as a attribute name. As part of this the attribute has also been updated to accept IPv4 and IPv6 in place of iptables or ip6tables, though they are still valid as input.
  • The action attribute within the firewall type has been removed as it was merely a restricted version of the jump attribute, both of them managing the same function, this being reasoned as a way to enforce the use of generic parameters. From this point the parameters formerly unique to action should now be passed to jump.
  • Strict types have now been implemented for all attributes, while this should not require changes on the user end in most cases, there may be some instances where manifests will require updated to match the new expected form of input.
  • Attributes that allow both arrays and negated values have now been updated.
    • For attributes that require that all passed values be negated as one, you now merely have to negate the first value within the array, rather than all of them, though negating all is still accepted.
    • For attributes that allow passed values to be negated seperately this is not the case. All attributes in this situation are noted within their description.
  • The sport and dport attributes have been updated so that they will now accept with : or - as a separator when passing ranges, with : being preferred as it matches what is passed to iptables.

Two pairs of manifest taken from the tests can be seen below, illustrating the changes that may be required, the first applying a hoplimit on ip6tables:

firewall { '571 - hop_limit':
  ensure    => present,
  proto     => 'tcp',
  dport     => '571',
  action    => 'ACCEPT',
  hop_limit => '5',
  provider  => 'ip6tables',
}
firewall { '571 - hop_limit':
  ensure    => present,
  proto     => 'tcp',
  dport     => '571',
  jump      => 'accept',
  hop_limit => '5',
  protocol  => 'IPv6',
}

And the second negating access to a range of ports on iptables:

firewall { '560 - negated ports':
  proto  => `tcp`,
  sport  => ['! 560-570','! 580'],
  action => `accept`,
}
firewall { '560 - negated ports':
  proto  => `tcp`,
  sport  => '! 560:570','580',
  jump   => `accept`,
}

puppetlabs-firewall's People

Contributors

adrianiurca avatar alexharv074 avatar bmjen avatar chelnak avatar cmurphy avatar cyberious avatar daianamezdrea avatar david22swan avatar davids avatar dcarley avatar eimlav avatar eputnam avatar greatflyingsteve avatar hunner avatar jonnytdevops avatar jordanbreen28 avatar kbarber avatar lionce avatar lukasaud avatar malikparvez avatar michaeltlombardi avatar phemmer avatar pmcmaw avatar ramesh7 avatar sanfrancrisko avatar saysjonathan avatar sheenaajay avatar tphoney avatar tskirvin avatar vstone avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

puppetlabs-firewall's Issues

using log_prefix seems to result in error on second puppet run

If we have the following

class rcac_firewall::post_accept_all {

firewall { '975 log test':
    state      => 'NEW',
    log_level  => 'debug',
    log_prefix => 'iptables A: ',
    jump       => 'LOG'
}

...
}

On the first puppet run the rule is inserted ok... however, on the second
run we get some errors like this:


info: Applying configuration version '1365457738'
err: /Firewall[975 log test]/log_level: change from iptables A: to 7 failed: The iptables provider can not handle attribute log_level at /etc/puppet/modules/rcac_firewall/manifests/post_accept_all.pp:8
err: /Firewall[975 log test]/log_prefix: change from 7 to iptables A: failed: The iptables provider can not handle attribute log_prefix at /etc/puppet/modules/rcac_firewall/manifests/post_accept_all.pp:8
notice: Finished catalog run in 18.76 seconds


If it is of interest, this is puppet version 2.7.21 running under RHEL 6.3.

(#20125) Support for archlinux

Currently, the firewall module doesn’t work on Archlinux because Arch has (ip|ip6|eb)tables in /usr/sbin instead of /sbin. See also #94.

Persistence: may fail on fresh Debian nodes

Improvements on #133

Persistence may fail on fresh Debian/Ubuntu nodes if Package['iptables-persistent'] isn't installed before the first Firewall[] resource is created.

Possible solutions:

  1. Have the type auto-require the package if it exists in the catalog. Is this bad form?
  2. Write a flag file to indicate that persistence should be attempted on the next run even if no rules have changed.

failed rule is cached

I just tried to create a log all rule - but it failed, due to comment and log_prefix NOT being enclosed in ". (see issue before this)

I removed that - but puppet run still fails EVERY time - because it for some reason - still tries to apply it:
err: /Firewall[998 Log all]/ensure: change from present to absent failed: Execution of '/sbin/iptables -t filter -D INPUT -m comment --comment 998 Log all -j LOG --log-prefix default drop' returned 1: iptables: Bad rule (does a matching rule exist in that chain?).

It must be caching somewhere?

Persistence: flush shells out on every resource

Improvements on #133

The flush method, and thus the shell out in persist_iptables, is called on every modified resource. It would be more cost effective to call it once after all Firewall/Firewallchain resources have been synced.

@kbarber, any idea if this is technically possible?

Opensuse/Suse Enterprise support

Could it be possible to make opensuse/SLES support available for puppetlabs-firewall.
both have iptables in there default repo's.

comment and log prefix NOT enclosed in " - makes iptables fail

When I have this:

firewall { '998 log all':
   proto   => 'all',
   jump => LOG,
   log_level => 'debug',
   before  => undef,
}

It fails on run:

err: /Firewall[998 Log all]/ensure: change from present to absent failed: Execution of '/sbin/iptables -t filter -D INPUT -m comment --comment 998 Log all -j LOG --log-prefix default drop' returned 1: iptables: Bad rule (does a matching rule exist in that chain?).

But the rule is inserted into /etc/sysconfig/iptables (there the comment and log_prefix is enclosed in ") - and if I alter the above iptables command, so that I enclose the comment and log_prefix - it works.

This is on RHEL 6.4

Integration with fail2ban

Hello!

How i can combine fail2ban and this module?
I tryed:

exec { 'fail2ban':
command => $operatingsystem ? {
/(debian|Ubuntu)/ => '/usr/bin/fail2ban-client reload',
/(RedHat|CentOS)/ => '/usr/bin/fail2ban-client reload',
},
schedule => 'daily',
refreshonly => true,
subscribe => Resources["firewall"],
}

But it is not help for me. I want to f2b was not related to the firewall-module. And if Firewall was changed - f2b make reload. Thanks.
I don't know where i can asking is yet.

Issue with firewall in 3.0

Although I can't replicate this in 3.1.0, Puppet 3.0.1 used to have a problem with method_missing. Has this just disappeared or is something up with that version of Puppet?

Cleaning of previous incompatible rules

Hi
When running module for the first time on a system with already-defined rules, it fails:

err: Could not prefetch firewall provider 'iptables': private method gsub' called for nil:NilClass info: Applying configuration version '1311006570' err: //iptables/Firewall[998 OUTPUT drop invalid]: Failed to retrieve current state of resource: private methodgsub' called for nil:NilClass
err: //iptables/Firewall[999 OUTPUT drop invalid]: Failed to retrieve current state of resource: private method `gsub' called for nil:NilClass

But iptables -L still shows the old defined rules (the ones of system-config-securitylevel-tui), of course, new rules are not appended either...

Regards
Pablo

existing rules not detected (centos 5.6)

Hey, Iv tried using puppet firewall on centos with the following rules:

firewall { "JMS port":
dport => "5672",
jump => "ACCEPT",
state => "NEW",
proto => "tcp",
}

firewall { "Allowing rabbit managment port":
  dport => "55672",
  jump => "ACCEPT",
  state => "NEW",
  proto => "tcp",
}

firewall { "Allow jmx":
dport => "9999",
jump => "ACCEPT",
state => "NEW",
proto => "tcp",
}

firewall { "Allow rmi":
dport => "1099",
jump => "ACCEPT",
state => "NEW",
proto => "tcp",
}

firewall { "Allow clarity":
dport => "80",
jump => "ACCEPT",
state => "NEW",
proto => "tcp",
}

Instead of skipping existing rules on consecutive runs same rules are duplicated again:

-A INPUT -p tcp -m multiport --dports 80 -m comment --comment "Allow clarity" -m state --state NEW -j ACCEPT
-A INPUT -p tcp -m multiport --dports 9999 -m comment --comment "Allow jmx" -m state --state NEW -j ACCEPT
-A INPUT -p tcp -m multiport --dports 5672 -m comment --comment "JMS port" -m state --state NEW -j ACCEPT
-A INPUT -p tcp -m multiport --dports 1099 -m comment --comment "Allow rmi" -m state --state NEW -j ACCEPT
-A INPUT -p tcp -m multiport --dports 55672 -m comment --comment "Allowing rabbit managment port" -m state --state NEW -j ACCEPT
-A INPUT -p tcp -m multiport --dports 9999 -m comment --comment "Allow jmx" -m state --state NEW -j ACCEPT
-A INPUT -p tcp -m multiport --dports 55672 -m comment --comment "Allowing rabbit managment port" -m state --state NEW -j ACCEPT
-A INPUT -p tcp -m multiport --dports 1099 -m comment --comment "Allow rmi" -m state --state NEW -j ACCEPT
-A INPUT -p tcp -m multiport --dports 80 -m comment --comment "Allow clarity" -m state --state NEW -j ACCEPT
-A INPUT -p tcp -m multiport --dports 5672 -m comment --comment "JMS port" -m state --state NEW -j ACCEPT

Iv also had to change the following method so that it will work on ruby 1.8.5 (I know old but its centos default):

def self.instances
debug "Converting existing rules to resources"
rules = []
# lines method isn't defined in ruby 1.8.5
ipsave.split("\n") do |line|
unless line =~ /^#\s+|^:\S+|^COMMIT/
if line =~ /^/
table = line.sub(/
/, "")
else
if hash = rule_to_hash(line, table)
rules << new(hash)
end
end
end
end
rules
end

Let me know if I can provide more info

Thanks
Ronen

skip purging on rules marked as unmanaged at a chain level

Sample code to obtain catalogue info from another resource:

def delete
  catalog = self.resource.catalog
  chain_resource = catalog.resource("Firewallchain[mychain]")
  chain_properties = chain_resource.properties
  chain_properties.each do |p|
    notice("  #{p.name} #{p.value}")
  end

  ... and the rest ...
end

persistance exec is not triggered on a purge

I configured the firewall for persistence as described at http://forge.puppetlabs.com/puppetlabs/firewall:

exec { "persist-firewall":
  command => "/sbin/iptables-save >/etc/iptables.rules",
  refreshonly => true,
}
Firewall {
  notify => Exec["persist-firewall"]
}

No notification occurs and no /etc/iptables.rules is created when purging is setup:

resources { "firewall":
  purge => true,
}

And a rule is removed due to purge ...

Support Windows Firewall through win32ole/hnetcfg/fwpolicy2 API

It would be nice to support other firewall engines such as Windows Firewall. I have an almost working type/provider, but the terminology is quite different from iptables. Windows uses remote/local instead of source/destination, there are also some other major differences. I can generate a provider for puppetlabs-firewall, just not sure the best route.

unable to delete a PREROUTING chain rule

If you have a rule like the following:

firewall { "090 preroute 192.168.1.1:80":
    chain       => 'PREROUTING',
    proto       => 'tcp',
    destination => "192.168.1.1",
    dport       => '80',
    toports     => '80',
    jump        => 'REDIRECT',
    table       => 'nat',
}

If you later delete the firewall rule, on the next puppet run it is unable to
delete the rule with output something along the lines of:

err: /Firewall[090 preroute 192.168.1.1:80]/ensure: change from present to absent failed: Execution of '/sbin/iptables -D PREROUTING -d 192.168.1.1/32 -p tcp -m multiport --dports 80 -m comment --comment 090 preroute 192.168.1.1:80 -j REDIRECT --to-ports 80' returned 1: iptables: Bad rule (does a matching rule exist in that chain?).

proto as an array of protocols

        firewall { '520 dns':
                chain => 'OUTPUT',
                dport => '53',
                proto => [ 'tcp','udp' ],
                action => 'accept',
        }

Currently generates only tcp

Chain OUTPUT (policy ACCEPT 133 packets, 14604 bytes)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           multiport dports 53 /* 520 dns */ 

Support for Linux Kernel 3.7+

As of Linux Kernel 3.7, the "state" module is an obsolete version of "conntrack".

Firewall rules specifying state are re-added everytime Puppet is run (because they're converted to conntrack in /etc/sysconfig/iptables and no longer match the original firewall rule). This problem was discovered on Fedora 18.

There are (at least) two possible solutions for this issue.

  1. Add ctstate, which will specify state requirements using conntrack syntax.
  2. Modify state to specify state requirements using conntrack syntax rather than state syntax.

My preferences is solution 2, because then all state requirements are specified using the same syntax for all rules.

I will be working on a patch for this issue and would appreciate feedback regarding which solution is preferred by the project maintainers.

Support for extra chains

Hi
RH-based distros use a chain created by system-config-firewall named "RH-Firewall-1-INPUT" which is the first target for INPUT and FORWARD chains.

"RH-Firewall-1-INPUT" ends 'rejecting anything not aproved previously' thus returning to INPUT or FORWARD chains.

This allows to use RH-Firewall-1-INPUT for system default firewalls, and use INPUT to put temorary changes to firewall rules.

puppetlabs-firewall 'firewall', doesn't accept RH-Firewall-1-INPUT as a valid chain ( INPUT, FORWARD, OUTPUT, PREROUTING, POSTROUTING).

Allowing the definition of custom chains could help in writing diferent rules.

Regards
Pablo

The firewall class should support stopping the iptables service

The firewall class, as it currently stands, doesn't take any parameters and ensures that the appropriate service is running and enabled for the operating system returned by factor. It would be nice for the class to take an ensure parameter that would be passed along to support stopping the iptables service. By default, the service should obviously be running.

Attribute configure_firewall available at the base apache class level

Currently it is only available in the type apache::vhost

If you just use the base class you install apache but you can't open the http port.

You could add an independent firewall resource, but if you include apache more than once (ex : apache required by many other modules), then :

  • you get errors because of multiple declaration if you use the same resource name
    or
  • you have many rules in the live firewall, just to open port 80, and this is not clean

Currently I use a separate module 'apachefw' that just opens the http port and I

include apache
include apachefw

I can't use apache::vhost for the same reason : I include it in other modules and then I would have multiple declarations of the vhost

That's why it would be nice to have it handled with the apache module

Module does not parse negated rules correctly

I have an iptables configuration that contains a few rules in the nat table similar to the following:

-A POSTROUTING -s 192.168.1.0/24 ! -d 192.168.1.0/24 -p tcp -j MASQUERADE --to-ports 1024-65535

The parsing code appears to be choking on the exclamation point in the rule:

$ puppet agent --test --debug
[snip]
debug: Prefetching iptables resources for firewall
debug: Puppet::Type::Firewall::ProviderIptables: [prefetch(resources)]
debug: Puppet::Type::Firewall::ProviderIptables: [instances]
debug: Puppet::Type::Firewall::ProviderIptables: Executing '/sbin/iptables-save'
err: Could not prefetch firewall provider 'iptables': Invalid address from IPAddr.new: !
[snip]
info: Applying configuration version '1363803270'
debug: Puppet::Type::Firewall::ProviderIptables: [instances]
debug: Puppet::Type::Firewall::ProviderIptables: Executing '/sbin/iptables-save'
err: /Firewall[500 accept munin connections from munin master]: Could not evaluate: Invalid address from IPAddr.new: !

I would maybe like it not to do that or at least fail in a way that still allows it to apply the rules I've specified in my manifests.

Install the iptables package

Yesterday I tried to use puppetlabs-firewall on a very minimal CentOS 5 and it bailed because the iptables package was not installed. After installing that there was also an error about iptables_save exiting with code 1 which I could work around with by calling service iptables save manually. I'd expect puppetlabs-firewall to do this for me.

Issue setting UID as username in OUTPUT chain

Hi guys, we're experiencing a problem whereby when we set a UID as a username, the run applies cleanly, but a subsequent run will attempt to amend the change by substituting the UID for the username.

For example:

class test_firewall {

        $uid = 'root'

        firewall { '00001 test uid':
            chain       => 'OUTPUT',
            proto       => 'tcp',
            dport       => '3189',
            source      => undef,
            destination => undef,
            action      => 'accept',
            uid         => $uid,
        }
}

class { 'test_firewall': }

results in (and repeated in subsequent runs):

vagrant@server:~$ sudo puppet apply --verbose --logdest console --detailed-exitcodes --show_diff --color=true firewall_test.pp
info: Applying configuration version '1366800808'
notice: /Firewall[00001 test uid]/uid: uid changed '0' to 'root'
notice: Firewall[00001 test uid](provider=iptables): Properties changed - updating rule
notice: Finished catalog run in 0.69 seconds

Is this expected behavior? If so, is there any way to set the UID as a username without experiencing the change on a subsequent run?

Thanks,
Andrew

allow established or related sessions

From my iptables-save output:
-A INPUT -m state --state RELATED,ESTABLISHED -m comment --comment "000b allow established or related sessions" -j ACCEPT

Then from "puppet resource firewall"

Error: Could not run: Parameter name failed on Firewall[RELATED,ESTABLISHED]: Invalid value "RELATED,ESTABLISHED". Valid values match /^\d+[[:alpha:][:digit:][:punct:][:space:]]+$/.

Tried reversing the order for my input, but iptables-save puts it in that order.

puppetlabs-firewall (v0.2.1)
puppet 3.1.1
RHEL 5, 64 bit

Rules do not appear to be running in string order

I have rules named things like '000 Allow everything from localhost' and '999 deny everything else'. According to the documentation, they should be run in string order, but they appear to be running randomly.

Am I missing anything?

Run 1:

info: Applying configuration version '1310608761'
notice: /Firewall[001 allow ssh]/ensure: created
notice: /Firewall[002 allow snmp]/ensure: created
notice: /Firewall[101 allow puppet internally]/ensure: created
notice: /Firewall[000 allow localhost]/ensure: created
notice: /Firewall[100 allow puppet internally]/ensure: created
notice: /Firewall[998 allow everything from office]/ensure: created
notice: /Firewall[999 deny all other requests]/ensure: created
notice: Finished catalog run in 1.33 seconds

Run 2:

info: Applying configuration version '1310608813'
notice: /Firewall[999 deny all other requests]/ensure: created
[timeout]

unable to purge rules that don't match comment regexp

The puppetlabs-firewall module is unable to purge existing IPtables rules that don’t have a comment matching the regex:

newvalues(/^\d+[a-zA-Z0-9\s\-_]+$/)

This can be reproduced with a simple example:

[root@papp0 ~]# iptables -F
[root@papp0 ~]# iptables -t filter -A INPUT -j ACCEPT -p tcp --dport 80 -m comment --comment "http"
[root@papp0 ~]# puppet apply --modulepath /vagrant/puppet/modules
resources { "firewall":
    purge => true,
}
^D
err: /Stage[main]//Resources[firewall]: Failed to generate additional resources using 'generate': Parameter name failed: Invalid value "http". Valid values match /^\d+[a-zA-Z0-9\s\-_]+$/.
notice: Finished catalog run in 0.07 seconds

Ubuntu can't match `iptables-persistent` package

I'm using Ubuntu 12.10 and the firewall module keeps throwing these:

Info: Loading facts in /var/lib/puppet/lib/facter/iptables_version.rb
dpkg-query: no packages found matching iptables-persistent
dpkg-query: no packages found matching iptables-persistent
dpkg-query: no packages found matching iptables-persistent

Note: I've installed the package as a git submodule using the master branch, not though the puppet forge.

proposal: action property

After discussion with Jonathan it was proposed we create a generic non-iptables property for basic filtering actions (well only filtering for now).

So the proposal is to create a new property action which accepts: accept, deny or reject.

firewall { "000 accept icmp":
  action => "accept",
  proto => "icmp",
}

Now ... we believe that 'jump' for iptables is still important but provider specific. So this will become a feature only available to iptables. So a new feature 'iptables' should probably be created to handle this.

The behaviour when these items are mixed should be thus:

  • If action is provided and jump is not - action is used
  • If action is provied and jump is provided - jump overrides action. However we throw an error when the jump is: ACCEPT, DENY, REJECT ... this way we ensure there is only 1 way to set these states.

Action should also default to 'accept' to save typing - most people would expect if they define a rule it means acceptance by default. Also the ratio of accept rules to deny rules are higher.

iptables_ng provider: Evaluate using the 'iptables' gem to parse instead of the existing parser

So I wrote this:

https://rubygems.org/gems/iptables

The concept being that I wanted to externalise the concept of decoding and encoding iptables rules to another library that didn't have the same modelling constraints as Puppet imposes. I would have preferred to use something off the shelf, but nothing existed that suited my needs.

The 'iptables' gem itself is built from the ground up to reliably parse 'iptables-save' output into a complex data structure that mirrors the internal model of iptables itself. It has achieved full feature capability it would seem, as it doesn't try to do the transformation at the same time, this was much simpler.

By doing it this way, we no longer limit features by what the parser can do - as the parser does everything. Previously parser modifications were always buggy and very easy to regress on, this way the parser layer is kept isolated. As the parser doesn't have to do the transformation itself - it should be more reliable.

More or less this isolates the transformation and parsing into two separate pieces that can be maintained individually.

The ticket tracks the development of an experimental provider that utilises this new parser and architecture.

Rules applying every time

Hi
Using those rules:

  firewall { '999 OUTPUT drop invalid':
            jump => "ACCEPT",
            sport => "666",
            proto => "tcp",
            destination => "10.31.66.9/24",
            chain => 'RH-Firewall-1-INPUT',
    }
    firewall { '998 OUTPUT drop invalid':
            jump => "ACCEPT",
            sport => "667",
            proto => "tcp",
            destination => "10.31.66.9/24",
            chain => 'RH-Firewall-1-INPUT',
    }

I get the system applying once and over again the same rules:

notice: //iptables/Firewall[998 OUTPUT drop invalid]/destination: destination changed '10.31.66.0/255.255.255.0' to '10.31.66.9/24'
notice: Firewall998 OUTPUT drop invalid: Properties changed - updating rule
notice: //iptables/Firewall[999 OUTPUT drop invalid]/destination: destination changed '10.31.66.0/255.255.255.0' to '10.31.66.9/24'
notice: Firewall999 OUTPUT drop invalid: Properties changed - updating rule
notice: Finished catalog run in 53.68 seconds

¿Shouldn't this just apply once?

Thanks
Pablo

setting the dest to 'undef' after being set doesn't clear it

We had a firewall rule defining a "destination", after some time we want to change the destination from the already set ip-range to everything (0.0.0.0/0). We did this by removing the destination entry.

This change didn't cause the firewall rules to be updated, as it now doesn't check the destination anymore.

Initial mac ipfw support

Submit some initial IPFW work - supporting at least filtering on source, dest, sport, dport and protocol.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.