fail2ban 配置第三方邮件服务器

fail2ban configure third-party email server

我在 Google Compute Engine 上使用 fail2ban,我无法在其中安装 sendmail 或其他电子邮件服务器,我想将 sendgrid 设置为电子邮件服务器。

在jail.local中有这个配置:

destemail = myemail@myhost.it
mta = mail

我在哪里可以设置通过sendgrid.com发送电子邮件的主机、用户、密码?

我认为fail2ban使用机器mail命令发送电子邮件,因此它使用机器邮件守护程序。如果您查看此代码段:

# Option:  actionstart
# Notes.:  command executed once at the start of Fail2Ban.
# Values:  CMD
#
actionstart = printf %%b "Hi,\n
              The jail <name> has been started successfully.\n
              Regards,\n
              Fail2Ban"|mail -s "[Fail2Ban] <name>: started  on <fq-hostname>" <dest>

取自 here (fail2ban sources on github),您可以看到 fail2ban 的消息通过管道传送到 mail 命令(在基于 Debian 的发行版中,这是通过 mailutils 包)。由于我认为你的问题是你不能使用或配置这个mail命令(这意味着配置邮件服务器),你可能会想写一个非常简单的mail 二进制文件(使用您喜欢的语言),具有非常相似的界面,可以使用 Gmail App Script 之类的东西发送电子邮件,甚至可以使用 Gunmail 或 Sendgrid 从该机器实际发送电子邮件(带有 POST通过 REST Api 请求?他们允许吗?),并将此自定义二进制文件添加到运行 fail2ban.

的用户的 $PATH

编辑: 有一个 page in the Google compute documentation related to Send Grid. Also according to this 你不能 使用 sendmail: 端口已关闭。

Google Compute Engine does not allow outbound connections on ports 25, 465, and 587. By default, these outbound SMTP ports are blocked because of the large amount of abuse these ports are susceptible to. In addition, having a trusted third-party provider such as SendGrid, Mailgun, or Mailjet relieves Compute Engine and you from maintaining IP reputation with your receivers.