Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module does not parse negated rules correctly #141

Closed
asciipip opened this issue Mar 20, 2013 · 14 comments
Closed

Module does not parse negated rules correctly #141

asciipip opened this issue Mar 20, 2013 · 14 comments

Comments

@asciipip
Copy link

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.

@kbarber
Copy link
Contributor

kbarber commented Mar 20, 2013

Yeah, I've been working on a new parser that should help with this: https://github.com/kbarber/ruby-iptables and https://rubygems.org/gems/iptables. It is, at least according to a lot of my tests - fairly much feature complete which is nice, as apposed to our current parser which is not. This is because I spent the extra effort analyzing the model that iptables uses and making the iptables.rb code as generic as possible to fit that model.

The idea is that the gem 'iptables' is a closer model to iptables and the iptables provider can then just act as a bridge. I haven't yet done this work though ... its in my grand plan, just wanted to get the iptables library stable first.

@bodepd
Copy link
Contributor

bodepd commented Mar 22, 2013

is there a version I can safely revert to?

@aglarendil
Copy link

This is a really critical bug. It is impossible to use firewall module if rules with "!" get inserted. Is it possible to workaround this bug or revert to some stable version of firewall module ?

@drt24
Copy link

drt24 commented May 29, 2013

We (DTG) are staying on v0.0.4 rather than upgrading to 0.3.0 (there is probably a working version higher than our current one but I am not going looking for it).

@mrwacky42
Copy link

How's progress on this going kbarber? This is a big stinky problem for us too.

@ITBlogger
Copy link

Yep, hard to do the rules that IPTables automatically sets up for bridging interfaces which is needed for KVM without this feature.

@NewpTone
Copy link

It seems this bugs has not been resolved. I have try the latest version but it failed.

@BillWeiss
Copy link

I'll just add my +1 here: this is messing me up. I can't even create the rule outside of puppet, because the provider blows up badly if I've got that rule with a negation in there.

@rlpowell
Copy link

rlpowell commented Oct 9, 2013

Since this bug, which is really quite major, has been here for 7 months, I wasn't inclined to wait for a new parser.

This will solve the problem enough to allow you to add other rules. It does NOT allow you to add your own negated rules, but it does not appear to munge or break any that are already there:

 [rlpowell@shell01 puppet3]$ gd modules/firewall/
 diff --git a/modules/firewall/lib/puppet/provider/firewall/iptables.rb b/modules/firewall/lib/puppet/provider/firewall/iptables.rb
 index 1e8617e..3ed4541 100644
 --- a/modules/firewall/lib/puppet/provider/firewall/iptables.rb
 +++ b/modules/firewall/lib/puppet/provider/firewall/iptables.rb
 @@ -166,6 +166,9 @@ Puppet::Type.type(:firewall).provide :iptables, :parent => Puppet::Provider::Fir
      # so it behaves like --comment
      values = values.sub(/--tcp-flags (\S*) (\S*)/, '--tcp-flags "\1 \2"')

 +    # Remove negators entirely
 +    values = values.gsub(%r{!},'')
 +
      # Trick the system for booleans
      known_booleans.each do |bool|
        if bool == :socket then

@rlpowell
Copy link

rlpowell commented Oct 9, 2013

Having done so, on some hosts I got this:

 Error: /Firewall[010 iptables PUPPET: accept all to lo interface]: Could not evaluate: Invalid address from IPAddr.new: eth0

Apparently caused by:

-A POSTROUTING -s 172.30.0.0/16 -o eth0 -j MASQUERADE --random

And, in fact, it's the --random that causes the problem, despite the message.

I fixed this with a hack just as nasty as the last, but again, it doesn't seem to break any of the currently extant rules, which is all I care about.

The new diff:

  diff --git a/modules/firewall/lib/puppet/provider/firewall/iptables.rb b/modules/firewall/lib/puppet/provider/firewall/iptables.rb
 index 1e8617e..f43084d 100644
 --- a/modules/firewall/lib/puppet/provider/firewall/iptables.rb
 +++ b/modules/firewall/lib/puppet/provider/firewall/iptables.rb
 @@ -166,6 +166,12 @@ Puppet::Type.type(:firewall).provide :iptables, :parent => Puppet::Provider::Fir
      # so it behaves like --comment
      values = values.sub(/--tcp-flags (\S*) (\S*)/, '--tcp-flags "\1 \2"')

 +    # Remove negators entirely
 +    values = values.gsub(%r{!},'')
 +
 +    # Remove interface flags entirely
 +    values = values.gsub(%r{[-][-]random},'')
 +
      # Trick the system for booleans
      known_booleans.each do |bool|
        if bool == :socket then

@cardil
Copy link

cardil commented Nov 7, 2013

+1 on KVM

@luisfdez
Copy link

Hello,
What's the status of this issue? is the proposed patch safe to use so far?

@rlpowell
Copy link

I don't know that I would consider my updates a patch. They don't improve the capability of the module, they simply throw out the things that confuse it. Having said that, umm, it works fine for me! :D

@phemmer
Copy link
Contributor

phemmer commented Dec 19, 2013

This bug would be fixed by PR #267 which both handles existing rules and lets you add them.

hunner added a commit to hunner/puppetlabs-firewall that referenced this issue Feb 5, 2014
hunner added a commit to hunner/puppetlabs-firewall that referenced this issue Feb 5, 2014
hunner added a commit to hunner/puppetlabs-firewall that referenced this issue Feb 5, 2014
This adds tests mentioned in puppetlabs#141 and MODULES-48 to make sure that they
are covered by puppetlabs#267

Closes puppetlabs#141
apenney pushed a commit that referenced this issue Feb 5, 2014
Add --random support as per #141 comment
hunner added a commit to hunner/puppetlabs-firewall that referenced this issue Feb 5, 2014
This adds tests mentioned in puppetlabs#141 and MODULES-48 to make sure that they
are covered by puppetlabs#267

Closes puppetlabs#141
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests