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

Two new firewalld actions #1367

Closed
wants to merge 33 commits into from
Closed

Two new firewalld actions #1367

wants to merge 33 commits into from

Conversation

TorontoMedia
Copy link
Contributor

Added two new firewalld actions for a cleaner iptables layout and also fixed firewallcmd allports and multiport.

@codecov-io
Copy link

Current coverage is 89.84%

Merging #1367 into master will not affect coverage as of d37d02d

@@            master   #1367   diff @@
======================================
  Files           68      68       
  Stmts         7191    7191       
  Branches       995     995       
  Methods          0       0       
======================================
  Hit           6461    6461       
  Partial        147     147       
  Missed         583     583       

Review entire Coverage Diff as of d37d02d

Powered by Codecov. Updated on successful CI builds.

# Example actioncheck: firewall-cmd --direct --get-chains ipv4 filter | sed -e 's, ,\n,g' | grep -q '^f2b-recidive$'

actioncheck = firewall-cmd --direct --get-chains ipv4 filter | sed -e 's, ,\n,g' | grep -q '^f2b-<name>$'

actionban = firewall-cmd --direct --add-rule ipv4 filter f2b-<name> 0 -s <ip> -j <blocktype>
actionban = firewall-cmd --direct --add-rule ipv4 filter f2b-<name> 0 -s <ip> -j REJECT
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and also fixed firewallcmd allports and multiport.

??? What was fixed here?

Block type can also be specified in Init block as default, and can be rewritten in jail or in includes (if expected):

[Init]
blocktype = REJECT

BTW, I do not understand why following test does not fail by this action (

# Test for presence of blocktype (in relation to gh-232)
)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry that was a mistake. I wasn't synced with eed1a0d and was testing dependencies and copied the wrong file since I have three versions of fail2ban in my environment(gcm, xmpp, i18n).

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.7%) to 90.877% when pulling dd5e643 on TorontoMedia:rich-actions into bfac42e on fail2ban:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.7%) to 90.877% when pulling dd5e643 on TorontoMedia:rich-actions into bfac42e on fail2ban:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.7%) to 90.905% when pulling 7ef4449 on TorontoMedia:rich-actions into bfac42e on fail2ban:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 91.601% when pulling 7ef4449 on TorontoMedia:rich-actions into bfac42e on fail2ban:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 91.601% when pulling 6b3912f on TorontoMedia:rich-actions into bfac42e on fail2ban:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 91.601% when pulling 6b3912f on TorontoMedia:rich-actions into bfac42e on fail2ban:master.

@@ -29,10 +25,9 @@ actionunban = firewall-cmd --direct --remove-rule ipv4 filter f2b-<name> 0 -s <i

[Init]

# Default name of the chain
#
name = default
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a default name for the fail2ban chain ;-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll fix that. I don't know why I got the input chain mixed up with the f2b chains.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 91.601% when pulling 2861c8e on TorontoMedia:rich-actions into bfac42e on fail2ban:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 91.601% when pulling c82a91b on TorontoMedia:rich-actions into bfac42e on fail2ban:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 91.601% when pulling 307352e on TorontoMedia:rich-actions into bfac42e on fail2ban:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 91.601% when pulling 307352e on TorontoMedia:rich-actions into bfac42e on fail2ban:master.

@TorontoMedia
Copy link
Contributor Author

Sorry about all the commits my grammar is terrible today.

If someone could write something that executes the command for every port if a comma delimiter is used between ports that would be awesome. Since these new rich actions are limited to a single port or a range of ports.

@sebres
Copy link
Contributor

sebres commented Mar 22, 2016

If someone could write something that executes the command for every port if a comma delimiter is used between ports that would be awesome.

Something like this (should work in default shell):

ports="80,8080,88,8088" ; for p in $(echo $ports | tr "," " "); do echo execute command for port "$p"; done

or this (bash -c '...'):

ports="80,8080,88,8088" ; for p in ${ports//,/ }; do echo execute command for port "$p"; done

@TorontoMedia
Copy link
Contributor Author

I'm sorry but could you please give me an example that works in the config file since I can't for the life of me get it working in the config. I can only echo the commands in terminal but nothing is executed... My bash knowledge is poor.

@sebres
Copy link
Contributor

sebres commented Mar 23, 2016

Python seems to have a bug in ConfigParser with spaces in front of semicolon (I think it's a bug, because imho the comments should begin with new line...)

>>> s = '[def]\ntest1=1; 2\ntest2=3 ;-) 4\n'; print(s); p = ConfigParser.ConfigParser(); p.readfp(StringIO.StringIO(s)); p.items('def')
[def]
test1=1; 2
test2=3 ;-) 4

[('test1', '1; 2'), ('test2', '3')]

No way to escape, we can prospective extend our config reader to replace something like <SEMCOL> with ;. But atm it can be used still without leading space...

So either remove leading space for each ; or make a new sh-file (as executable) and put it in config... Below is an example for functioning config entry:

>>> s = '[def]\nactionban = ports="<port>"; for p in $(echo $ports | tr "," " "); do ban <HOST> --port "$p"; done\n'; print(s); p = ConfigParser.ConfigParser(); p.readfp(StringIO.StringIO(s)); p.items('def')
[def]
actionban = ports="<port>"; for p in $(echo $ports | tr "," " "); do ban <HOST> --port "$p"; done

[('actionban', 'ports="<port>"; for p in $(echo $ports | tr "," " "); do ban <HOST> --port "$p"; done')]

@TorontoMedia
Copy link
Contributor Author

I was able to get it working and it's awesome. Thank you. This is now ready to be committed if you guys want to.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 91.601% when pulling 4689da5 on TorontoMedia:rich-actions into bfac42e on fail2ban:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 91.601% when pulling 4f8aa45 on TorontoMedia:rich-actions into bfac42e on fail2ban:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 91.601% when pulling ed20d28 on TorontoMedia:rich-actions into bfac42e on fail2ban:master.

@TorontoMedia
Copy link
Contributor Author

Sorry I'm done editing them now.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 91.601% when pulling 8e24915 on TorontoMedia:rich-actions into bfac42e on fail2ban:master.

@sebres
Copy link
Contributor

sebres commented Mar 25, 2016

👍

@TorontoMedia
Copy link
Contributor Author

I have a question regarding "state" should we not be banning established connections too. Since blocking new connections works for a stateless connection but what about an established connection that has passed the queue and authentication and is now generating fail logs?

Also I just noticed firewallcmd-new has changed to multiports so besides the action check it is identical to my firewallcmd-multiport.

@sebres sebres closed this in 3d23921 Mar 25, 2016
@sebres
Copy link
Contributor

sebres commented Mar 25, 2016

Too many irrelevant commits, so I've rebased it onto current master (as single commit)...
(at the same time put away indifferent changes like styles, comments, white spaces etc.)

Use git commit -amend next time if you have amend changes...

yarikoptic added a commit to yarikoptic/fail2ban that referenced this pull request Jul 15, 2016
ver. 0.9.5 (2016/07/15) - old-not-obsolete
-----------

0.9.x line is no longer heavily developed.  If you are interested in
new features (e.g. IPv6 support), please consider 0.10 branch and its
releases.

* `filter.d/monit.conf`
    - Extended failregex with new monit "access denied" version (fail2bangh-1355)
    - failregex of previous monit version merged as single expression
* `filter.d/postfix.conf`, `filter.d/postfix-sasl.conf`
    - Extended failregex daemon part, matching also `postfix/smtps/smtpd`
      now (fail2bangh-1391)
* Fixed a grave bug within tags substitutions because of incorrect
  detection of recursion in case of multiple inline substitutions
  of the same tag (affected actions: `bsd-ipfw`, etc).  Now tracks
  the actual list of the already substituted tags (per tag instead
  of single list)
* `filter.d/common.conf`
    - Unexpected extra regex-space in generic `__prefix_line` (fail2bangh-1405)
    - All optional spaces normalized in `common.conf`, test covered now
    - Generic `__prefix_line` extended with optional brackets for the
     date ambit (fail2bangh-1421), added new parameter `__date_ambit`
* `gentoo-initd` fixed `--pidfile` bug: `--pidfile` is option of
  `start-stop-daemon`, not argument of fail2ban (see fail2bangh-1434)
* `filter.d/asterisk.conf`
    - Fixed security log support for PJSIP and Asterisk 13+ (fail2bangh-1456)
    - Improved log support for PJSIP and Asterisk 13+ with different
      callID (fail2bangh-1458)

* New Actions:
    - `action.d/firewallcmd-rich-rules` and `action.d/firewallcmd-rich-logging`
	(fail2bangh-1367)
* New filters:
    - slapd - ban hosts, that were failed to connect with invalid
	credentials: error code 49 (fail2bangh-1478)

* Extreme speedup of all sqlite database operations (fail2bangh-1436),
  by using of following sqlite options:
    - (synchronous = OFF) write data through OS without syncing
    - (journal_mode = MEMORY) use memory for the transaction logging
    - (temp_store = MEMORY) temporary tables and indices are kept in memory
* journald journalmatch for pure-ftpd (fail2bangh-1362)
* Added additional regex filter for dovecot ldap authentication failures (fail2bangh-1370)
* `filter.d/exim*conf`
    - Added additional regexes (fail2bangh-1371)
    - Made port entry optional

* tag '0.9.5': (70 commits)
  DOC: preparations for 0.9.5 release
  Added missing files to MANIFEST
  another variant of regex
  add trailing anchor to failregex
  DOC: Reformatted ChangeLog into legit Markdown (Closes fail2ban#962)
  DOC: tuned up ChangeLog entries for 0.9.5
  add PR id to ChangeLog
  improved failregex according to @sebres recomendations
  Improved changes of fail2bangh-1458:   `[^']*` after callid was wrong, changed to `[^\)]*`;   regexp anchored at the end;   almost the same regex grouped to one;
  Improve PJSIP log support for asterisk 13+ with different callID (Squash fail2bangh-1458) Change the asterisk pjsip filter to don't take the callId part Add optional part between "Request" and "from" Listed all log message from asterisk
  * add `__prefix_line` to regex * fix time in log file
  add info to log file
  added sample log lines for slapd
  adding openldap slapd filter
  badip timeout option introduced, set to 30 seconds in our test cases (fail2ban#1463)
  DOC: changelog for recent exim filters tune up
  Asterisk pjsip (fail2ban#1456)
  BF: finalize that sample log line for exim4
  amend for new option of `usedns=raw` - forgotten validation fix inside setUseDns
  RF: for consistency use (?:XXX)? instead of (?:|XXX)
  ...
yarikoptic added a commit that referenced this pull request Jul 15, 2016
ver. 0.9.5 (2016/07/15) - old-not-obsolete
-----------

0.9.x line is no longer heavily developed.  If you are interested in
new features (e.g. IPv6 support), please consider 0.10 branch and its
releases.

* `filter.d/monit.conf`
    - Extended failregex with new monit "access denied" version (gh-1355)
    - failregex of previous monit version merged as single expression
* `filter.d/postfix.conf`, `filter.d/postfix-sasl.conf`
    - Extended failregex daemon part, matching also `postfix/smtps/smtpd`
      now (gh-1391)
* Fixed a grave bug within tags substitutions because of incorrect
  detection of recursion in case of multiple inline substitutions
  of the same tag (affected actions: `bsd-ipfw`, etc).  Now tracks
  the actual list of the already substituted tags (per tag instead
  of single list)
* `filter.d/common.conf`
    - Unexpected extra regex-space in generic `__prefix_line` (gh-1405)
    - All optional spaces normalized in `common.conf`, test covered now
    - Generic `__prefix_line` extended with optional brackets for the
     date ambit (gh-1421), added new parameter `__date_ambit`
* `gentoo-initd` fixed `--pidfile` bug: `--pidfile` is option of
  `start-stop-daemon`, not argument of fail2ban (see gh-1434)
* `filter.d/asterisk.conf`
    - Fixed security log support for PJSIP and Asterisk 13+ (gh-1456)
    - Improved log support for PJSIP and Asterisk 13+ with different
      callID (gh-1458)

* New Actions:
    - `action.d/firewallcmd-rich-rules` and `action.d/firewallcmd-rich-logging`
        (gh-1367)
* New filters:
    - slapd - ban hosts, that were failed to connect with invalid
        credentials: error code 49 (gh-1478)

* Extreme speedup of all sqlite database operations (gh-1436),
  by using of following sqlite options:
    - (synchronous = OFF) write data through OS without syncing
    - (journal_mode = MEMORY) use memory for the transaction logging
    - (temp_store = MEMORY) temporary tables and indices are kept in memory
* journald journalmatch for pure-ftpd (gh-1362)
* Added additional regex filter for dovecot ldap authentication failures (gh-1370)
* `filter.d/exim*conf`
    - Added additional regexes (gh-1371)
    - Made port entry optional

* tag '0.9.5':
  Added missing files to MANIFEST
  BF: do not rely on long relative path to upstairs config - symlink common.conf
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

Successfully merging this pull request may close these issues.

5 participants