Fail2ban Failed to access socket path: /var/run/fail2ban/fail2ban.sock. Is fail2ban running?

Bonjour,
Ce sujet a déjà été abordé mais pas de solution claire n’a été trouvée.
J’ai un RPI4 sur lequel j’ai réinstallé Debian 11 et ensuite installé Jeedom. Je me suis basé sur ce tuto très bien fait:

J’ai voulu vérifier le fonctionnement de fail2ban et j’ai le message d’erreur suivant:
pi@jeedom:/ $ fail2ban-client status
2024-05-06 20:12:29,367 fail2ban [31637]: ERROR Failed to access socket path: /var/run/fail2ban/fail2ban.sock. Is fail2ban running?

si je vérifie avec la commande: systemctl status fail2ban

J’ai également essayé ces commandes sans succès:
sudo systemctl restart fail2ban.service
Et ensuite: systemctl daemon-reload

J’ai beau chercher dans tout les sens je n’y arrive pas
Merci de votre aide

Hello,

Je pars, depuis peu, d’une fresh install et en voyant ton sujet je me suis dit que j’allais jeter un coup d’oeil et même constat…

:roll_eyes:

sudo systemctl status fail2ban

● fail2ban.service - Fail2Ban Service
     Loaded: loaded (/lib/systemd/system/fail2ban.service; enabled; vendor preset: enabled)
    Drop-In: /usr/lib/systemd/system/fail2ban.service.d
             └─override.conf
     Active: failed (Result: exit-code) since Tue 2024-05-07 10:12:36 CEST; 5min ago
       Docs: man:fail2ban(1)
    Process: 772007 ExecStartPre=/bin/mkdir -p /run/fail2ban (code=exited, status=0/SUCCESS)
    Process: 772008 ExecStart=/usr/bin/fail2ban-server -xf start (code=exited, status=255/EXCEPTION)
   Main PID: 772008 (code=exited, status=255/EXCEPTION)
        CPU: 266ms

mai 07 10:12:35 Jeedom systemd[1]: Starting Fail2Ban Service...
mai 07 10:12:35 Jeedom systemd[1]: Started Fail2Ban Service.
mai 07 10:12:35 Jeedom fail2ban-server[772008]: 2024-05-07 10:12:35,991 fail2ban                [772008]: ERROR   Failed during configuration: Have not found any log f>
mai 07 10:12:35 Jeedom fail2ban-server[772008]: 2024-05-07 10:12:35,996 fail2ban                [772008]: ERROR   Async configuration of server failed
mai 07 10:12:36 Jeedom systemd[1]: fail2ban.service: Main process exited, code=exited, status=255/EXCEPTION
mai 07 10:12:36 Jeedom systemd[1]: fail2ban.service: Failed with result 'exit-code'.

Et pourtant je suis tout propre !!!

Il semble que fail2ban n’arrive pas à demarrer avec les paramètres de configuration spécifiques présent dans /etc/fail2ban/jail.d/jeedom.conf

cat /etc/fail2ban/jail.d/jeedom.conf

#Ne pas bloque localhost ni s'auto-bloquer.
ignoreip = 127.0.0.1/8 192.168.1.0/24 192.168.0.0/24 10.0.0.0/8

# ban de  60 minutes
bantime  = 28800

# on regarde les attaques sur les 2 dernières heures. Les 5 minutes par défaut, ça ne marche plus, les pirates se sont adaptés
findtime = 7200
maxretry = 3

# on surveille tous les ports
banaction = iptables-multiport

# action a prendre: ban + log détaillé
action = %(action_)s

# Ne pas activer cette regle qui bloque l'accès a jeedom trop facile a cause d'erreur de type [access_compat:error] [pid 10800] [client 192.168.0.67:62801] AH01797: client denied by server configuration: /var/www/html/plugins/zigbee/core/config/devices/undefined, referer: http://192.168.0.49/index.php?v=d&p=zigbee&m=zigbee&id=189
#[apache-multiport]
#enabled = false
#port      = http,https
#filter    = apache-auth
#logpath   = /var/www/html/log/http*.error
#maxretry = 3

[apache-botsearch]
enabled  = true
port     = http,https
filter   = apache-botsearch
logpath   = /var/www/html/log/http*.error
maxretry = 6

[apache-overflows]
enabled  = true
port     = http,https
filter   = apache-overflows
logpath   = /var/www/html/log/http*.error
maxretry = 2

[apache-noscript]
enabled  = true
port     = http,https
filter   = apache-noscript
logpath   = /var/www/html/log/http*.error
maxretry = 1

si on fait :
sudo cp -r /etc/fail2ban/jail.d/jeedom.conf /etc/fail2ban/jail.d_backup
sudo rm -r /etc/fail2ban/jail.d/jeedom.conf
sudo systemctl restart fail2ban
sudo systemctl status fail2ban

● fail2ban.service - Fail2Ban Service
     Loaded: loaded (/lib/systemd/system/fail2ban.service; enabled; vendor preset: enabled)
    Drop-In: /usr/lib/systemd/system/fail2ban.service.d
             └─override.conf
     Active: active (running) since Tue 2024-05-07 10:43:31 CEST; 5s ago
       Docs: man:fail2ban(1)
    Process: 802898 ExecStartPre=/bin/mkdir -p /run/fail2ban (code=exited, status=0/SUCCESS)
   Main PID: 802899 (fail2ban-server)
      Tasks: 3 (limit: 14131)
     Memory: 9.7M
        CPU: 221ms
     CGroup: /system.slice/fail2ban.service
             └─802899 /usr/bin/python3 /usr/bin/fail2ban-server -xf start

Et des que l’on restaure :
sudo cp -r /etc/fail2ban/jail.d_backup/jeedom.conf /etc/fail2ban/jail.d/
sudo systemctl restart fail2ban
sudo systemctl status fail2ban

● fail2ban.service - Fail2Ban Service
     Loaded: loaded (/lib/systemd/system/fail2ban.service; enabled; vendor preset: enabled)
    Drop-In: /usr/lib/systemd/system/fail2ban.service.d
             └─override.conf
     Active: failed (Result: exit-code) since Tue 2024-05-07 10:44:49 CEST; 5s ago
       Docs: man:fail2ban(1)
    Process: 803995 ExecStartPre=/bin/mkdir -p /run/fail2ban (code=exited, status=0/SUCCESS)
    Process: 803996 ExecStart=/usr/bin/fail2ban-server -xf start (code=exited, status=255/EXCEPTION)
   Main PID: 803996 (code=exited, status=255/EXCEPTION)
        CPU: 262ms

mai 07 10:44:49 Jeedom systemd[1]: Starting Fail2Ban Service...
mai 07 10:44:49 Jeedom systemd[1]: Started Fail2Ban Service.
mai 07 10:44:49 Jeedom fail2ban-server[803996]: 2024-05-07 10:44:49,392 fail2ban                [803996]: ERROR   Failed during configuration: Have not found any log f>
mai 07 10:44:49 Jeedom fail2ban-server[803996]: 2024-05-07 10:44:49,397 fail2ban                [803996]: ERROR   Async configuration of server failed
mai 07 10:44:49 Jeedom systemd[1]: fail2ban.service: Main process exited, code=exited, status=255/EXCEPTION
mai 07 10:44:49 Jeedom systemd[1]: fail2ban.service: Failed with result 'exit-code'.

Pour le moment, je désactive toutes les règles en passant leurs parametres enabled = false

edit :je commente les lignes

Bonjour,
Le problème est donc avec le fichier jeedom.conf si j’ai bien compris?

Si tu désactives toutes les règles, fail2ban ne bloquera plus rien :confused:

Tu as sans doute raison car jeedom.conf agit comme un complément aux configurations existantes de Fail2Ban et donc vaut mieux commenter les lignes plutot que désactiver les règles.

Bonjour

au vu du log :

fail2ban ne trouve pas le fichier de log de la règle apache-noscript

image

Regarder si le log http.error existe :

root@jeedom:/var/www/html/log# ls /var/www/html/log | grep http*.error
http.error

Les 3 règles apache font référence à ce fichier. Chez moi le fichier existe et fail2ban est running.

Cordialement

Ajout:

Dans l’aide Jeedom ici :
https://doc.jeedom.com/fr_FR/core/4.4/log?theme=dark

Il est dit :

Alors attention, a prendre avec des pincettes car je ne suis pas un expert alors vaut mieux attendre ceux qui le sont…

Le probleme est que certains journaux peuvent ne pas exister ce qui plante le démarrage de fail2ban. Et la solution apportée dans certains forum et de mettre backend=systemd.

En l’occurence je n’ai pas http.error meme apres un redémarrage

sudo ls /var/www/html/log
alexaapi_node   gshd                  openvpn_DNS_Jeedom  ttscast_daemon
broadlink       jMQTTd                plugin              tvremote_daemon
camera_record   listener_execution    rfxcom              worxLandroidS_daemon
cron_execution  mqtt2d                scenario_execution  z2md
espeasy_node    MQTTDiscovery_daemon  scenarioLog         zwavejsd
fullyKiosK      mymodbus              tgw_1514

nano /etc/fail2ban/jail.d/jeedom.conf

[apache-botsearch]
backend = systemd
enabled  = true
port     = http,https
filter   = apache-botsearch
logpath   = /var/www/html/log/http*.error
maxretry = 6

[apache-overflows]
backend = systemd
enabled  = true
port     = http,https
filter   = apache-overflows
logpath   = /var/www/html/log/http*.error
maxretry = 2

[apache-noscript]
backend = systemd
enabled  = true
port     = http,https
filter   = apache-noscript
logpath   = /var/www/html/log/http*.error
maxretry = 1

sudo systemctl restart fail2ban
sudo systemctl status fail2ban

● fail2ban.service - Fail2Ban Service
     Loaded: loaded (/lib/systemd/system/fail2ban.service; enabled; vendor preset: enabled)
    Drop-In: /usr/lib/systemd/system/fail2ban.service.d
             └─override.conf
     Active: active (running) since Tue 2024-05-07 18:54:02 CEST; 3s ago
       Docs: man:fail2ban(1)
    Process: 67385 ExecStartPre=/bin/mkdir -p /run/fail2ban (code=exited, status=0/SUCCESS)
   Main PID: 67387 (fail2ban-server)
      Tasks: 11 (limit: 14131)
     Memory: 31.1M
        CPU: 882ms
     CGroup: /system.slice/fail2ban.service
             └─67387 /usr/bin/python3 /usr/bin/fail2ban-server -xf start

mai 07 18:54:02 Jeedom systemd[1]: Starting Fail2Ban Service...
mai 07 18:54:02 Jeedom systemd[1]: Started Fail2Ban Service.
mai 07 18:54:03 Jeedom fail2ban-server[67387]: Server ready

fail2ban-client status

Status
|- Number of jail:      4
`- Jail list:   apache-botsearch, apache-noscript, apache-overflows, sshd

Et on a bien tous les services
et on reboot pour vérifier…

Je le répète, je fais peut être de la merde, mais c’est toute ma vie ca :smile:
Et au pire faut bien apprendre !

Bonjour

Effectivement c’est ce qui est recommandé dans le fichier jail.conf:

# "backend" specifies the backend used to get files modification.
# Available options are "pyinotify", "gamin", "polling", "systemd" and "auto".
# **This option can be overridden in each jail as well.**
#
# pyinotify: requires pyinotify (a file alteration monitor) to be installed.
#              If pyinotify is not installed, Fail2ban will use auto.
# gamin:     requires Gamin (a file alteration monitor) to be installed.
#              If Gamin is not installed, Fail2ban will use auto.
# polling:   uses a polling algorithm which does not require external libraries.
# systemd:   uses systemd python library to access the systemd journal.
#              Specifying "logpath" is not valid for this backend.
#              See "journalmatch" in the jails associated filter config
# auto:      will try to use the following backends, in order:
#              pyinotify, gamin, polling.
#
# Note: if systemd backend is chosen as the default but you enable a jail
#       for which logs are present only in its own log files, specify some other
#       backend for that jail (e.g. polling) and provide empty value for
#       journalmatch. See https://github.com/fail2ban/fail2ban/issues/959#issuecomment-74901200
backend = auto

A priori en mettant systemd, Fail2ban accède au journal de systemd et pas au fichier http.error.

Personnellement je suis sur une VM Proxmox et non sur un RPI, le fichier d’installation install.sh de Jeedom est peut être différent par rapport à une version Debian ou a un comportement différent sur RPI. Cela devrait être pris en compte par l’équipe Jeedom.

C’est vrai qu’avant on avait toujours http.error dans les log de jeedom même après suppression des logs par le bouton du core…

Pourquoi il n’y est plus mais surtout pourquoi il ne revient pas au moins au redémarrage comme le stipule la doc et ainsi ne pas bloquer le démarrage d fail2ban ??? :flushed::face_with_monocle:

Bonjour Theking31

Dans le fichier jail.conf pour un backend = systemd, il parle de journalmatch qui est à paramétrer dans chaque règle. J’ai peur que d’ajouter backend = systemd ne soit pas suffisant. Il faudrait plutôt remonter vos problèmes comme bug à l’équipe de Jeedom.

Cordialement

Ajout : On touche à la sécurité des accès externes de Jeedom, on ne rigole pas. Le risque de piratage est trop important.

Je viens d’une fresh install de 3 jours, sans trop de magouilles…

Le plus inquiétant c’est combien d’utilisateurs sont dans ca cas sans le savoir :grimacing:

Car c’est un peu invisible comme problème…

Sur quel matériel tu as fait ton installation?

Ajout :
Dans les fichiers dans le répertoire /etc/apache2/sites-available :
000-default-le-ssl.conf
000-default.conf
Est ce que vous avez bien la ligne suivante:
ErrorLog /var/www/html/log/http.error

Salut,

Intel NUC 6CAYH

Non pas de ErrorLog /var/www/html/log/http.error :face_with_raised_eyebrow:

 sudo ls /etc/apache2/sites-available
000-default.conf  default-ssl.conf

/etc/apache2/sites-available/default-ssl.conf

<IfModule mod_ssl.c>
        <VirtualHost _default_:443>
                ServerAdmin webmaster@localhost

                DocumentRoot /var/www/html

                # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
                # error, crit, alert, emerg.
                # It is also possible to configure the loglevel for particular
                # modules, e.g.
                #LogLevel info ssl:warn

                ErrorLog ${APACHE_LOG_DIR}/error.log
                CustomLog ${APACHE_LOG_DIR}/access.log combined

                # For most configuration files from conf-available/, which are
                # enabled or disabled at a global level, it is possible to
                # include a line for only one particular virtual host. For example the
                # following line enables the CGI configuration for this host only
                # after it has been globally disabled with "a2disconf".
                #Include conf-available/serve-cgi-bin.conf

                #   SSL Engine Switch:
                #   Enable/Disable SSL for this virtual host.
                SSLEngine on

                #   A self-signed (snakeoil) certificate can be created by installing
                #   the ssl-cert package. See
                #   /usr/share/doc/apache2/README.Debian.gz for more info.
                #   If both key and certificate are stored in the same file, only the
                #   SSLCertificateFile directive is needed.
                SSLCertificateFile      /etc/ssl/certs/ssl-cert-snakeoil.pem
                SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key

                #   Server Certificate Chain:
                #   Point SSLCertificateChainFile at a file containing the
                #   concatenation of PEM encoded CA certificates which form the
                #   certificate chain for the server certificate. Alternatively
                #   the referenced file can be the same as SSLCertificateFile
                #   when the CA certificates are directly appended to the server
                #   certificate for convinience.
                #SSLCertificateChainFile /etc/apache2/ssl.crt/server-ca.crt

                #   Certificate Authority (CA):
                #   Set the CA certificate verification path where to find CA
                #   certificates for client authentication or alternatively one
                #   huge file containing all of them (file must be PEM encoded)
                #   Note: Inside SSLCACertificatePath you need hash symlinks
                #                to point to the certificate files. Use the provided
                #                Makefile to update the hash symlinks after changes.
                #SSLCACertificatePath /etc/ssl/certs/
                #SSLCACertificateFile /etc/apache2/ssl.crt/ca-bundle.crt

                #   Certificate Revocation Lists (CRL):
                #   Set the CA revocation path where to find CA CRLs for client
                #   authentication or alternatively one huge file containing all
                #   of them (file must be PEM encoded)
                #   Note: Inside SSLCARevocationPath you need hash symlinks
                #                to point to the certificate files. Use the provided
                #                Makefile to update the hash symlinks after changes.
                #SSLCARevocationPath /etc/apache2/ssl.crl/
                #SSLCARevocationFile /etc/apache2/ssl.crl/ca-bundle.crl

                #   Client Authentication (Type):
                #   Client certificate verification type and depth.  Types are
                #   none, optional, require and optional_no_ca.  Depth is a
                #   number which specifies how deeply to verify the certificate
                #   issuer chain before deciding the certificate is not valid.
                #SSLVerifyClient require
                #SSLVerifyDepth  10

                #   SSL Engine Options:
                #   Set various options for the SSL engine.
                #   o FakeBasicAuth:
                #        Translate the client X.509 into a Basic Authorisation.  This means that
                #        the standard Auth/DBMAuth methods can be used for access control.  The
                #        user name is the `one line' version of the client's X.509 certificate.
                #        Note that no password is obtained from the user. Every entry in the user
                #        file needs this password: `xxj31ZMTZzkVA'.
                #   o ExportCertData:
                #        This exports two additional environment variables: SSL_CLIENT_CERT and
                #        SSL_SERVER_CERT. These contain the PEM-encoded certificates of the
                #        server (always existing) and the client (only existing when client
                #        authentication is used). This can be used to import the certificates
                #        into CGI scripts.
                #   o StdEnvVars:
                #        This exports the standard SSL/TLS related `SSL_*' environment variables.
                #        Per default this exportation is switched off for performance reasons,
                #        because the extraction step is an expensive operation and is usually
                #        useless for serving static content. So one usually enables the
                #        exportation for CGI and SSI requests only.
                #   o OptRenegotiate:
                #        This enables optimized SSL connection renegotiation handling when SSL
                #        directives are used in per-directory context.
                #SSLOptions +FakeBasicAuth +ExportCertData +StrictRequire
                <FilesMatch "\.(cgi|shtml|phtml|php)$">
                                SSLOptions +StdEnvVars
                </FilesMatch>
                <Directory /usr/lib/cgi-bin>
                                SSLOptions +StdEnvVars
                </Directory>

                #   SSL Protocol Adjustments:
                #   The safe and default but still SSL/TLS standard compliant shutdown
                #   approach is that mod_ssl sends the close notify alert but doesn't wait for
                #   the close notify alert from client. When you need a different shutdown
                #   approach you can use one of the following variables:
                #   o ssl-unclean-shutdown:
                #        This forces an unclean shutdown when the connection is closed, i.e. no
                #        SSL close notify alert is send or allowed to received.  This violates
                #        the SSL/TLS standard but is needed for some brain-dead browsers. Use
                #        this when you receive I/O errors because of the standard approach where
                #        mod_ssl sends the close notify alert.
                #   o ssl-accurate-shutdown:
                #        This forces an accurate shutdown when the connection is closed, i.e. a
                #        SSL close notify alert is send and mod_ssl waits for the close notify
                #        alert of the client. This is 100% SSL/TLS standard compliant, but in
                #        practice often causes hanging connections with brain-dead browsers. Use
                #        this only for browsers where you know that their SSL implementation
                #        works correctly.
                #   Notice: Most problems of broken clients are also related to the HTTP
                #   keep-alive facility, so you usually additionally want to disable
                #   keep-alive for those clients, too. Use variable "nokeepalive" for this.
                #   Similarly, one has to force some clients to use HTTP/1.0 to workaround
                #   their broken HTTP/1.1 implementation. Use variables "downgrade-1.0" and
                #   "force-response-1.0" for this.
                # BrowserMatch "MSIE [2-6]" \
                #               nokeepalive ssl-unclean-shutdown \
                #               downgrade-1.0 force-response-1.0

        </VirtualHost>
</IfModule>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

/etc/apache2/sites-available/000-default.conf

<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html
</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

Hello,

Et grep -nr '/var/www/html/log/http.error' /etc/apache2/
Moi j’ai /etc/apache2/apache2.conf:134:ErrorLog /var/www/html/log/http.error

Salut

Cette commande ne donne rien car je pense que le fichier http.error n’hésite pas !

Bonjour

moi j’ai :

root@jeedom:/etc/apache2/sites-available# cat 000-default.conf
<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html
        ErrorLog /var/www/html/log/http.error
RewriteEngine on
RewriteCond %{SERVER_NAME} =echo.dlefevre.fr
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

et :

root@jeedom:/etc/apache2# grep -nr '/var/www/html/log/http.error' /etc/apache2/
/etc/apache2/sites-available/000-default-le-ssl.conf:5:        ErrorLog /var/www/html/log/http.error
/etc/apache2/sites-available/000-default.conf:4:        ErrorLog /var/www/html/log/http.error

Les configurations sont différentes, je suis en Debian version 11 bulleye oldstable.

Je pense que c’est lier à la distribution utilisé.

Distributor ID: Debian
Description: Debian GNU/Linux 11 (bullseye)
Release: 11
Codename: bullseye

Il faut que je fasse quoi pour corriger le prblème, une reinstall ?

Bonjour

Tu est passé par l’iso ou par une installation manuelle ?

Par ISO

Je suis en train de reprendre avec une nouvelle image netinst… On verra bien :wink: