mailcow-dockerized icon indicating copy to clipboard operation
mailcow-dockerized copied to clipboard

Add support for crowdsec

Open StarkZarn opened this issue 4 years ago โ€ข 27 comments

Summary

I think it would modernize and increase the security of the stack to replace fail2ban with crowdsec. It's and open source replacement that provides crowdsourced threat intelligence and more log parsing support.

Motivation

This would provide additional security, richer data, and stay ahead of the ever-changing security curve.

Additional context

Crowdsec's homepage is https://crowdsec.net/ Github: https://github.com/crowdsecurity/crowdsec/

StarkZarn avatar Jan 21 '22 23:01 StarkZarn

I am head of community at CrowdSec. I think it's great that you want integration with CrowdSec :-)

We would love to help out as much as we can.

Please come to our Discord community to discuss this further. Also please elaborate a bit on how it would make sense to integrate as we don't really know that much about mailcow (yet! :-).

klausagnoletti avatar Jan 25 '22 11:01 klausagnoletti

Hey :)

Your product sounds cool! But as iยดm not the main developer or operator of this project i canยดt decide that on my own how and where to implement.

Weยดll keep you up to date :)

DerLinkman avatar Jan 25 '22 15:01 DerLinkman

I'm writing a blog post how to make this possible (crowdsec installed on the host and reading the logs from nginx, postfix and soon dovecot). The only thing stopping me from reading the dovecot-logs are somehow related to the tty: yes parameter on the docker container. The issue is reported at the crowdsec github. After that bug is squashed i will finalize the blogpost at https://blog.vacum.se :)

vacumet avatar Apr 04 '22 18:04 vacumet

Hey, to begin with: we don't use "Fail2ban" but our own interpretation of it. Yes, I see it is a bit confusing. :) Fail2ban would have been too huge for our use case so we simply wrote something similar/more tiny to read a Redis stream of logs for patterns and run actions on hits.

CrowdSec looks very nice, I will check it out for myself, too. I think it is a tool too powerful to "just attach" to mailcow for people to carry with them and forget they actually have it. It is a tool you should from time to time care about and check some cli commands here and there.

There should be a guide how to protect mailcow with CrowdSec (and at that point thanks to @vacumet ! :)). Perhaps we can tune mailcow at some points to make it easier for CrowdSec to work with mailcow.

Easiest seems to be to read Dockers stdout stream, while that will only work as long as an admin did not setup another Docker log driver.

Or, another approach: Setup journald as log driver for Docker (yeah, not good either) and feed CrowdSec via journald and a filter:

{
  "ipv6":true,
  "fixed-cidr-v6":"fd00:dead:beef:c0::/80",
  "experimental":true,
  "ip6tables":true,
  "log-driver": "journald"
}
crowdsec -type syslog -dsn journalctl://filters=CONTAINER_NAME=CONTAINER_NAME=mailcowdockerized_nginx-mailcow_1&filters=CONTAINER_NAME=CONTAINER_NAME=mailcowdockerized_postfix-mailcow_1&filters=CONTAINER_NAME=mailcowdockerized_dovecot-mailcow_1

It's something.

andryyy avatar Apr 04 '22 21:04 andryyy

Thank you @andryyy I will try that on my setup. I try not to modify my mailcow setup as local modifications often can cause problems when doing upgrades :)

vacumet avatar Apr 05 '22 07:04 vacumet

The bugfix in crowdsec is done and will be available in a future version: https://github.com/crowdsecurity/crowdsec/pull/1422/files No need to modify mailcow. Blog post will be released when the new version of crowdsec is released

vacumet avatar Apr 05 '22 11:04 vacumet

Nice!

andryyy avatar Apr 06 '22 05:04 andryyy

The bugfix in crowdsec is done and will be available in a future version: https://github.com/crowdsecurity/crowdsec/pull/1422/files No need to modify mailcow. Blog post will be released when the new version of crowdsec is released

Looks like the last release fixed this. All my logs are being parsed now. :+1:

StarkZarn avatar Apr 28 '22 16:04 StarkZarn

@vacumet Thanks so much for creating that blog about mailcow and crowdsec. I just wanted to reach out to you as I am experiencing differing behaviour when running/setting up.

cscli parsers inspect crowdsecurity/nginx-logs image I only see nginx in the list.

That said when starting I see the other start and appear to be running. image

Any suggestions?

daygle avatar Nov 03 '22 10:11 daygle

Oh hang on, looking further by running 'cscli parsers inspect crowdsecurity/syslog-logs' I see the below:- image

@vacumet maybe this is correct? We might need to update the blog?

daygle avatar Nov 03 '22 10:11 daygle

I just made CrowdSec work yesterday using https://github.com/docker-mailserver/docker-mailserver The mail.log file has dovecot and postfix log so that's enough

See docker-compose: https://github.com/datacenters-network/mails/blob/24a3e3df7f471a90e319b62748c309272735f16c/docker-compose.yml#L261-L284

williamdes avatar Nov 03 '22 10:11 williamdes

Thanks @williamdes .

@andryyy and @vacumet are you able to suggest the recommended way to configure mailcow and CrowdSec - @williamdes way is much different to what was documented on the blog.

daygle avatar Nov 03 '22 11:11 daygle

Thanks @williamdes .

@andryyy and @vacumet are you able to suggest the recommended way to configure mailcow and CrowdSec - @williamdes way is much different to what was documented on the blog.

And it's very easy, just provide the log file to the CrowdSec instance and

cscli collections install crowdsec/postfix
cscli collections install crowdsec/dovecot

I also mount some custom scenarios and parsers (that I will probably upstream): https://github.com/datacenters-network/mails/tree/24a3e3df7f471a90e319b62748c309272735f16c/crowdsec

williamdes avatar Nov 03 '22 11:11 williamdes

@williamdes are you able to document the steps from start to finish? This will help myself and others.

daygle avatar Nov 03 '22 11:11 daygle

@williamdes are you able to document the steps from start to finish? This will help myself and others.

For sure here is my blog post for pfsense https://blog.williamdes.eu/Infrastructure/tutorials/install-crowdsec-and-bouncer-on-pfsense/

I will consider writing a blog post on this for docker mailserver Does someone have a docker compose example of this project that works?

williamdes avatar Nov 03 '22 12:11 williamdes

I think this can be implemented aswell as netfilter (which I personally think should be replaced with Fail2ban, since it's more widely used) @DerLinkman

vermium avatar Jan 20 '23 12:01 vermium

"Because it is widely used" does not mean it is a drop-in replacement. The nf implementation isnโ€™t any package at all but a simple as heck implementation of a ban mechanism that is controllable via and integrated into the UI.

It would also mean to carry another third party application for something that is so simple.

No...

andryyy avatar Jan 20 '23 14:01 andryyy

I think its too simple...scripts are getting better and better and learn to avoid getting banned...i dont get any machine banned since they tune their timing to get around that...i think mailcow needs a much more complex mechanism to ban hosts.

riwin avatar Mar 22 '23 21:03 riwin

Maybe would be a good Idea, so it would stop such shit here: grafik

And no, my Mailserver is only used by me and my brother for Personal use, so I am not sure, but it's very infrequently used from 3rd parties (receiving mails)

calvinthefreak avatar Mar 27 '23 19:03 calvinthefreak

It can stop all attacks that are:

  • repeating on the same ip/network
  • provide you a list to use on your firewall to block all already know bad actors https://blog.williamdes.eu/Infrastructure/tutorials/install-crowdsec-and-bouncer-on-pfsense/
  • About what I just said, other people built such lists. See https://iplists.firehol.org/
  • I built such lists:
    • https://github.com/datacenters-network/security/blob/main/bad-ips.txt
    • https://github.com/datacenters-network/security/blob/main/bad-networks.txt

Until now I found no tool that manages to block attacks from changing IPs that are not already well known to do attacks

williamdes avatar Mar 27 '23 19:03 williamdes

I am using crowdsec since its first release and love it. It also works fine with mailcow as outlined here. But I also must agree with @andryyy that it increases the overall complexity of the stack. A note that crowdsec as solution for mailcow is available in the documentation and link here would be great (without any liability or support)

Kofl avatar Apr 09 '23 18:04 Kofl

It is indeed still a very cool solution for spam fighting. :)

andryyy avatar Apr 09 '23 18:04 andryyy

It is indeed still a very cool solution for spam fighting. :)

It's not technically for spam but indeed it could be if you have some log of received spams by IP That's actually an interesting idea to test CrowdSec only parses log files

williamdes avatar Apr 09 '23 18:04 williamdes

@vacumet I have read your blog and Googled this thread. You have mentioned in the blog that Crowdsec did not read Dovecot logs and awaiting to be fixed. And in this thread you mentioned it was fixed. Running sudo cscli parsers inspect crowdsecurity/nginx-logs on my server, only nginx is shown:

type: parsers
stage: s01-parse
name: crowdsecurity/nginx-logs
filename: nginx-logs.yaml
description: Parse nginx access and error logs
author: crowdsecurity
belongs_to_collections:
- crowdsecurity/nginx
remote_path: parsers/s01-parse/crowdsecurity/nginx-logs.yaml
version: "1.4"
local_path: /etc/crowdsec/parsers/s01-parse/nginx-logs.yaml
localversion: "1.4"
localhash: ffd447fc906aa86bc3fa4c352d0d0829074c999d9f5257c6a20728c58a237e3a
installed: true
downloaded: true
uptodate: true
tainted: false
local: false

Current metrics : 

 - (Parser) crowdsecurity/nginx-logs:
โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚                 Parsers                  โ”‚ Hits โ”‚ Parsed โ”‚ Unparsed โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ docker:mailcowdockerized-nginx-mailcow-1 โ”‚ 2077 โ”‚ 2045   โ”‚ 32       โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

And I am still getting tons of suspicious access: image

So it seems to be not working correctly? Is there any update after your first writing of your blog?

Thanks.

thematrixdev avatar Sep 13 '23 14:09 thematrixdev

@thematrixdev I am getting requests from exactly the same IP addresses. And none of this is caught by crowdsec ๐Ÿ˜•

martinjgrunwald avatar Sep 19 '23 16:09 martinjgrunwald

I am head of community at CrowdSec. I think it's great that you want integration with CrowdSec :-)

We would love to help out as much as we can.

Please come to our Discord community to discuss this further. Also please elaborate a bit on how it would make sense to integrate as we don't really know that much about mailcow (yet! :-).

How did the guys of crowdsec managed to jump from a free plan to $2,500 a month :) https://www.crowdsec.net/pricing

semaf avatar Feb 01 '24 15:02 semaf

How did the guys of crowdsec managed to jump from a free plan to $2,500 a month :)

Luckly you can also run in locally in your own docker stack - probably they are mainly billing for premium blocklists and their Enterprise SaaS console

Kofl avatar Feb 01 '24 15:02 Kofl