Skip to content
This repository has been archived by the owner on Dec 16, 2020. It is now read-only.

ufw::allow any:all unless not matching #41

Open
exptom opened this issue Mar 3, 2015 · 4 comments
Open

ufw::allow any:all unless not matching #41

exptom opened this issue Mar 3, 2015 · 4 comments
Labels
Milestone

Comments

@exptom
Copy link

exptom commented Mar 3, 2015

Hi,

I have a particular firewall rule that gets executed on every puppet run because the unless statement is never matching.

ufw::allow { "allow-replication-from-${::fqdn}":
    proto => 'tcp',
    from  => $replication_ip,
    ip    => 'any',
  }

This produces this ufw rule:

To                         Action      From
--                         ------      ----
Anywhere                   ALLOW       10.0.0.10/tcp

Which is handled by line 23 of allow.pp

'any:all'    => "ufw status | grep -qE ' +ALLOW +${from_match}$'",

The problem is the regex is ensuring that ${from_match} is at the end of the output but the output actually ends with the protocol (/tcp in this case).

There seem to be some cases when a From IP is not suffixed with the protocol so the regex needs adjusting to account for both cases.

Could the regex be changed to this?

'any:all'    => "ufw status | grep -qE ' +ALLOW +${from_match}(/${proto})?$'",
@attachmentgenie
Copy link
Owner

my regex foo is a bit rusty, but do feel free to turn this into some unit tests. that would be most welcome

@exptom
Copy link
Author

exptom commented Mar 4, 2015

I haven't got any experience of that but I'll give it a go :)

@flavius
Copy link

flavius commented Jun 10, 2016

@exptom, @attachmentgenie I still have this issue with rules using the following parameters:

"allow-tcp-from-OLD_Frontend" => array("type" => "allow", "from" => "x.x.x.x", "proto" => "tcp", "port" => "all", "ip" => "any"),
"allow-tcp-from-OLD_Backend" => array("type" => "allow", "from" => "x.x.x.x", "proto" => "tcp", "port" => "all", "ip" => "any"),
"allow-tcp-from-OLD_Service" => array("type" => "allow", "from" => "x.x.x.x", "proto" => "tcp", "port" => "all", "ip" => "any"),

The problematic line is

'any:all'    => "grep -qE ' +ALLOW +${from_match}$'",

if I change it to

'any:all'    => "ufw status | grep -qE ' +ALLOW +${from_match}${proto_match}$'",

then it works.

@igalic
Copy link
Collaborator

igalic commented Jun 15, 2016

wow, how did this ever work??

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants