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

Apply firewall resources alphabetically #342

Merged
merged 2 commits into from
May 7, 2014

Conversation

mcanevet
Copy link
Contributor

This will apply firewall resources by alphabetical order.
This greatly simplify Module usage IMHO.

Just:

include ::firewall

resources { "firewall":
  purge => true
}

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

firewall { '001 accept all to lo interface':
  proto   => 'all',
  iniface => 'lo',
  action  => 'accept',
}

firewall { '002 accept related established rules':
  proto   => 'all',
  ctstate => ['RELATED', 'ESTABLISHED'],
  action  => 'accept',
}

firewall { '999 drop all':
  proto   => 'all',
  action  => 'drop',
}

No more

Firewall {
  before  => Class['my_fw::post'],
  require => Class['my_fw::pre'],
}
class { ['my_fw::pre', 'my_fw::post']: }

@mcanevet
Copy link
Contributor Author

@hunner @apenney my goal is to add next a rules parameter to init and a create_resources('firewall', $rules) so that we can use databinding to store firewall rules in hiera like this:

---
firewall::rules:
  000 accept all icmp:
    proto: icmp
    action: accept
  001 accept all to lo interface:
    proto: all
    iniface: lo
    action: accept
  002 accept related established rules:
    proto: all
    ctstate: ['RELATED', 'ESTABLISHED']
    action: accept
  999 drop all:
    proto: all
    action: drop

@mcanevet
Copy link
Contributor Author

hmmm travis fails with ruby1.8.7. I just tested with master and it also fails so it does not come from my patch.

@mcanevet
Copy link
Contributor Author

This PR fixes unit tests : #341

@apenney
Copy link
Contributor

apenney commented Apr 15, 2014

I merged in #341, can you rebase this one against master?

@mcanevet
Copy link
Contributor Author

@apenney done

@mcanevet
Copy link
Contributor Author

@apenney now travis is happy !

@csschwe
Copy link
Contributor

csschwe commented Apr 21, 2014

+1 works great.

@apenney
Copy link
Contributor

apenney commented Apr 22, 2014

@hunner raised the issue that this causes all further rules to be skipped if a single rule fails to apply for any reason, which is not the current behavior. Do we think that's a significant problem?

@hunner
Copy link
Contributor

hunner commented Apr 22, 2014

It's cool to have an easier way to order rules that are applied first vs. later, but do we want to enforce that rules ordered first in the chain should almost always be applied to the machine first? It's going to overload the semantics of the title leading-numbers, and isn't the normal Puppet Way of ordering resource application.

OTOH, I don't want convention to stand in the way of ease-of-use when it wouldn't hurt to add it.

@csschwe
Copy link
Contributor

csschwe commented Apr 22, 2014

On the plus side you usually want firewall rules applied in a specific order since the first rule that is matched wins and this give an easy way to accomplish that (lots of fun with Cisco ACLs in the past). This also should mean you want all rules to apply top down and probably have a further down rules skipped if a rule before it fails. We don't really want a deny all rule to be processed if our allow port 22 rule failed.

You could look at it like the File auto dependency chain between /etc and /etc/hosts, in this case the 000 and 001 are being used to make this auto dependency.

Personally I like the idea of knowing how what order all firewall rules will be applied in without having to create a manual requires for each one. But I can also understand it isn't really the normal way, but it does seem to make sense for firewall rules since order matters much more than in a normal puppet run.

@hunner
Copy link
Contributor

hunner commented Apr 22, 2014

Okay. Sounds good.

This should probably also come with some updates in the README, as it has a pretty large section dedicated to talking about pre/post classes to avoid locking yourself out of a box.

@mcanevet
Copy link
Contributor Author

@hunner README updated.

@phemmer
Copy link
Contributor

phemmer commented Apr 26, 2014

Would it not make more sense to do this similar to how the concat module works? Each concat_fragment has an order parameter, and that parameter defines the order in which the fragment gets included.

Then you don't have to rely upon alphabetically sorting the title, which is problematic in itself. What happens when you have 010, 20, and 030. It'll get applied as 010, 030, 20 because you forgot a zero on the 20. This has bit me in the ass numerous times.

Having an order parameter would allow this field to be explicitly converted into an integer and would solve this issue. It also keeps us from defining yet another way of ordering resources.

@mcanevet
Copy link
Contributor Author

@phemmer hmmm, if you have 010, 20 and 030 will it be ordered 010, 20 and 030 in iptables's filter table or 010, 030 and 20 ?

If it's ordered 010, 030 and 20, then IMHO it makes sense that resources are applied in the same order without the need of an additional order parameter.

If it's ordered 010, 20 and 030, then you're probably right and my patch may confuse some people.

I'll try to look at the code to see what order is actually applied.

@mcanevet
Copy link
Contributor Author

mcanevet commented May 2, 2014

@phemmer I just tried and it looks like rules are also ordered alphabetically, 030 comes before 20. So I think my patch is relevant and there is no need to add an additional order parameter.
@hunner @apenney is there something preventing this to be merged ?

@phemmer
Copy link
Contributor

phemmer commented May 2, 2014

@mckern that was my point. It is unintuitive for 030 to come before 20, and introduces yet another ordering convention.

@mcanevet
Copy link
Contributor Author

mcanevet commented May 2, 2014

@phemmer maybe, but my patch is consistent with the ordering convention already applied. So I think your point shouldn't block this PR to be merged.
BTW, to follow your more intuitive ordering convention, I'd prefer extract the order from the begining of the title and order towards it than adding a new order parameter.

@hunner
Copy link
Contributor

hunner commented May 2, 2014

The concat sorts the same way (alphabetically instead of numerically) and I've always hated that. It's also backwards incompatible to change the ordering to numeric.

I'd rather not make the same mistake here. Since we don't yet make guarantees about ordering, it will not be backwards incompatible to merge this. But as soon as we do, it will be backwards incompatible to change the way that ordering works.

If possible I'd rather get it right on the first try, now that firewall is 1.x

@mcanevet
Copy link
Contributor Author

mcanevet commented May 5, 2014

@hunner changing the ordering to numeric is not tricky at all:

autorequire(:firewall) do
  catalog.resources.select { |r| (r.class.to_s == "Puppet::Type::Firewall") and (r.name.split(' ')[0].to_i < name.split(' ')[0].to_i) }.sort.last
end

But this will mismatch the actual logic applied in iptables.
Can't we still merge my patch as it clearly simplify the module implementation and does not break bakwards compatibility, then change the code once the ordering is changed in the provider ?

@hunner
Copy link
Contributor

hunner commented May 7, 2014

Sigh, good point.

hunner added a commit that referenced this pull request May 7, 2014
Apply firewall resources alphabetically
@hunner hunner merged commit e5cbfbe into puppetlabs:master May 7, 2014
@mcanevet mcanevet deleted the feature/autorequire branch May 7, 2014 16:26
hunner added a commit to hunner/puppetlabs-firewall that referenced this pull request May 15, 2014
…equire"

This reverts commit e5cbfbe, reversing
changes made to eb2e51f.

Conflicts:
	README.markdown
apenney pushed a commit that referenced this pull request May 15, 2014
Revert "Merge pull request #342 from mcanevet/feature/autorequire"
cegeka-jenkins pushed a commit to cegeka/puppet-firewall that referenced this pull request Oct 23, 2017
cegeka-jenkins pushed a commit to cegeka/puppet-firewall that referenced this pull request Oct 23, 2017
…equire"

This reverts commit e5cbfbe, reversing
changes made to eb2e51f.

Conflicts:
	README.markdown
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants