Fail2ban : impossible de démarrer le service (failed)

  • Debian Strech
  • Sur une raspberry-pi
  • yunohost: 3.4.2.4 (stable)
  • yunohost-admin 3.4.2 (stable)
  • moulinette 3.4.2 (stable)
  • ssowat 3.4.2 (stable)

PROBLEME:

  • Dans l’interface web d’aministration yunohost, fail2ban est marqué "failed"
  • Cron renvoit le message suivant:
    /etc/cron.daily/logrotate:
    ERROR  Found no accessible config files for 'fail2ban' under /etc/fail2ban
    ERROR  No section: 'Definition'
    ERROR  No section: 'Definition'
    ERROR  Failed to access socket path: /var/run/fail2ban/fail2ban.sock. Is fail2ban running?
    error: error running non-shared postrotate script for /var/log/fail2ban.log of '/var/log/fail2ban.log '
    run-parts: /etc/cron.daily/logrotate exited with return code 1

INFOS SUR FAIL2BAN INSTALLÉ

Version de fail2ban
Après connexion en ssh à la pi:

    $ apt-cache policy fail2ban

    fail2ban
      Installed: 0.9.6-2
      Candidate: 0.9.6-2
      Version table:
      *** 0.9.6-2 500
           500 http://raspbian.raspberrypi.org/raspbian stretch/main armhf Packages
           100 /var/lib/dpkg/status

STATUT DU SERVICE INSTALLÉ FAIL2BAN

    $ yunohost service status fail2ban

    active: failed
    active_at: 1970-01-01 00:00:00
    description: protects against bruteforce and other kind of attacks from the Internet
    loaded: enabled
    service_file_path: /lib/systemd/system/fail2ban.service
    status: failed

TENTATIVES ARRÊT / RELANCE DE FAIL2BAN

    $ yunohost service stop fail2ban

    Success! The service 'fail2ban' has been stopped

    $  yunohost service start fail2ban

    Job for fail2ban.service failed because the control process exited with error code.
    See "systemctl status fail2ban.service" and "journalctl -xe" for details.
    Warning: Unable to execute command 'systemctl start fail2ban'
    Error: Unable to start service 'fail2ban'

QUESTION: POUR RÉPARER, EST-CE QUE CE QUI SUIT SERAIT PERTINENT ?

    # 1. Stopper fail2ban
    $ yunohost service stop fail2ban

    # 2. Renommer le répertoire fail2ban (copie de sécurité)
    $ mv /etc/fail2ban /etc/fail2ban.old

    # 3. Supprimer fail2ban
    $ apt-get purge fail2ban

    # 4. Ré-installer fail2ban
    $ apt-get install fail2ban

    # 5. Re-configuration de fail2ban
    $ yunohost service regen-conf fail2ban --force

    # 6. Relancer fail2ban
    $ yunohost service restart fail2ban

    # 7. Vérification du statut
    $ yunohost service status fail2ban

Est-ce que ces commandes pourraient aider à remettre fail2ban en marche (à la faire passer de failed à active) ?

Perso j’investigerais les logs pour savoir pourquoi fail2ban ne démarre pas …

Que renvoie systemctl status fail2ban | cat ? Et un tail -n 50 /var/log/fail2ban.log ?

… pourquoi fail2ban ne démarre pas …

Que renvoie systemctl status fail2ban | cat ?

    systemctl status fail2ban | cat

    ● fail2ban.service - Fail2Ban Service
       Loaded: loaded (/lib/systemd/system/fail2ban.service; enabled; vendor preset: enabled)
       Active: failed (Result: exit-code) since Mon 2019-03-18 08:07:14 UTC; 6h ago
         Docs: man:fail2ban(1)
      Process: 15284 ExecStart=/usr/bin/fail2ban-client -x start (code=exited, status=255)

    Mar 18 08:07:14 NOMDUSITE.nohost.me systemd[1]: fail2ban.service: Unit entered failed state.
    Mar 18 08:07:14 NOMDUSITE.nohost.me systemd[1]: fail2ban.service: Failed with result 'exit-code'.
    Mar 18 08:07:14 NOMDUSITE.nohost.me systemd[1]: fail2ban.service: Service hold-off time over, scheduling restart.
    Mar 18 08:07:14 NOMDUSITE.nohost.me systemd[1]: Stopped Fail2Ban Service.
    Mar 18 08:07:14 NOMDUSITE.nohost.me systemd[1]: fail2ban.service: Start request repeated too quickly.
    Mar 18 08:07:14 NOMDUSITE.nohost.me systemd[1]: Failed to start Fail2Ban Service.
    Mar 18 08:07:14 NOMDUSITE.nohost.me systemd[1]: fail2ban.service: Unit entered failed state.
    Mar 18 08:07:14 NOMDUSITE.nohost.me systemd[1]: fail2ban.service: Failed with result 'exit-code'.

Et un tail -n 50 /var/log/fail2ban.log ?

`tail -n 50 /var/log/fail2ban.log`

Après lancement de de cette commande, elle ne retourne rien, et le fichier fail2ban.log est vide dans /var/log/

Complément: retour de la commande: journalctl -xe

    journalctl -xe
    Mar 18 14:48:40 NOMDUSITE.nohost.me sshd[23975]: rexec line 20: Deprecated option ServerKeyBits
    Mar 18 14:48:40 NOMDUSITE.nohost.me sshd[23975]: rexec line 31: Deprecated option RSAAuthentication
    Mar 18 14:48:40 NOMDUSITE.nohost.me sshd[23975]: rexec line 38: Deprecated option RhostsRSAAuthentication
    Mar 18 14:48:41 NOMDUSITE.nohost.me sshd[23975]: reprocess config line 31: Deprecated option RSAAuthentication
    Mar 18 14:48:41 NOMDUSITE.nohost.me sshd[23975]: reprocess config line 38: Deprecated option RhostsRSAAuthentication
    Mar 18 14:48:41 NOMDUSITE.nohost.me sshd[23975]: Invalid user access from xxx.xx.x.xx port xxxxx
    Mar 18 14:48:41 NOMDUSITE.nohost.me sshd[23975]: input_userauth_request: invalid user access [preauth]
    Mar 18 14:48:41 NOMDUSITE.nohost.me sshd[23975]: pam_unix(sshd:auth): check pass; user unknown
    Mar 18 14:48:41 NOMDUSITE.nohost.me sshd[23975]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=
    Mar 18 14:48:42 NOMDUSITE.nohost.me sshd[23980]: rexec line 19: Deprecated option KeyRegenerationInterval
    Mar 18 14:48:42 NOMDUSITE.nohost.me sshd[23980]: rexec line 20: Deprecated option ServerKeyBits
    Mar 18 14:48:42 NOMDUSITE.nohost.me sshd[23980]: rexec line 31: Deprecated option RSAAuthentication
    Mar 18 14:48:42 NOMDUSITE.nohost.me sshd[23980]: rexec line 38: Deprecated option RhostsRSAAuthentication
    Mar 18 14:48:42 NOMDUSITE.nohost.me sshd[23980]: reprocess config line 31: Deprecated option RSAAuthentication
    Mar 18 14:48:42 NOMDUSITE.nohost.me sshd[23980]: reprocess config line 38: Deprecated option RhostsRSAAuthentication
    Mar 18 14:48:42 NOMDUSITE.nohost.me sshd[23980]: Invalid user rstudio from zz.zz.zzz.zzz port zzzzz
    Mar 18 14:48:42 NOMDUSITE.nohost.me sshd[23980]: input_userauth_request: invalid user rstudio [preauth]
    Mar 18 14:48:42 NOMDUSITE.nohost.me sshd[23980]: pam_unix(sshd:auth): check pass; user unknown
    Mar 18 14:48:42 NOMDUSITE.nohost.me sshd[23980]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=
    Mar 18 14:48:43 NOMDUSITE.nohost.me sshd[23975]: Failed password for invalid user access from xxx.xx.x.xx port xxxxx ssh
    Mar 18 14:48:43 NOMDUSITE.nohost.me sshd[23975]: Received disconnect from xxx.xx.x.xx port xxxxx:11: Bye Bye [preauth]
    Mar 18 14:48:43 NOMDUSITE.nohost.me sshd[23975]: Disconnected from xxx.xx.x.xx port xxxxx [preauth]
    Mar 18 14:48:45 NOMDUSITE.nohost.me sshd[23980]: Failed password for invalid user rstudio from zz.zz.zzz.zzz port zzzzz 
    Mar 18 14:48:45 NOMDUSITE.nohost.me sshd[23980]: Received disconnect from zz.zz.zzz.zzz port zzzzz:11: Bye Bye [preauth]
    Mar 18 14:48:45 NOMDUSITE.nohost.me sshd[23980]: Disconnected from zz.zz.zzz.zzz port zzzzz [preauth]

Un soucis d’authentification semble-t-il ?

Non ca ne devrait pas avoir de rapport …

Sinon, que renvoie : tail -n 10000 /var/log/daemon | grep fail2ban

tail -n 10000 /var/log/daemon | grep fail2ban
tail: cannot open '/var/log/daemon' for reading: No such file or directory

arf désolé c’est daemon.log

:joy::joy:

Il est long le log … alors copié/collé dans un zerobin là

1 Like

Hmbon du coup ça a l’air de venir de :

Mar 18 14:39:51 NOMDUSITE fail2ban-client[23862]: ERROR  Found no accessible config files for 'action.d/iptables-multiport' under /etc/fail2ban
Mar 18 14:39:51 NOMDUSITE fail2ban-client[23862]: ERROR  Error in action definition iptables-multiport[name=yunohost, bantime="600", port="http,https", protocol="tcp", chain="INPUT"]

Est-ce que tu aurais modifié la conf fail2ban à la main par hasard ?

Sinon, peut-être qu’un yunohost service regen-conf fail2ban --force peut résoudre le problème…

Heuu … je viens de regarder dans mes notes, mais je ne vois rien qui s’y apparente. Le seul truc modifié à la main, sur ma pi, c’est postfix.

Allez, ça se tente …

Après avoir lancé la commande yunohost service regen-conf fail2ban --force, je vérifie avec la commande yunohost service status fail2ban: et … failed

yunohost service status fail2ban
active: failed
active_at: 1970-01-01 00:00:00
description: protects against bruteforce and other kind of attacks from the Internet
loaded: enabled
service_file_path: /lib/systemd/system/fail2ban.service
status: failed

Hmbon du coup on dirait qu’il te manque le fichier /etc/fail2ban/action.d/iptables-multiport.conf pour une raison obscure …

Du coup naivement je ferais :

apt install fail2ban --reinstall
yunohost service regen-conf fail2ban --force

Ourf ! j’ai tout pêté … Mauvaise manip … Yé suis oune sombré Stupido !

Et c’est reparti pour une réinstall total de yunohost sur ma pi … Horreur. Pas d’ta faute @Aleks, c’est moi qui ait fait une belle boulette. Je suis allé trop vite. Désolé … Je vais essayer de réparer tout ça.

Ok. Voici l’erreur fatale/débile, fatalement débile que j’ai fait.

    # arrêt de fail2ban
    yunohost service stop fail2ban

    # puis au lieu de reinstall, j'ai fait une supression complète !!!
    apt-get purge fail2ban

Je regardais deux trucs à la fois, et j’ai pas fait gaffe. Quand je me suis aperçu de mon erreur, c’était trop tard. Quand on purge fail2ban, cela supprime aussi yunohost et yunohost.admin

Bon, pour essayer de rattraper à l’arrache, j’ai fait ensuite:

    apt-get install fail2ban
    apt-get install yunohost

La blague maintenant c’est que:

  • mon site est accessible
  • mais l’admin ne l’est plus: cela me demande de faire une post-install qui n’aboutit pas

J’ai vraiment tout cassé. J’hésite à faire une réinstallation complète de yunohost, ou bien tenter de réparer pour partager la connaissnce sur le sujet (dans le cas où cela arrive à quelqu’un d’autre)

@Aleks: tu en penses quoi ? réinstall ou tentative de réparation ?

:confused:

Tente ceci :

touch /etc/yunohost/installed

Gagné ! Clap-Clap-Clap … Merci ! me revoici avec l’admin qui refonctionne, parfait ! Ouf ! C’te rigolade ! :joy: C’est déjà ça …

Bon, et du côté de fail2ban, avec tout ça, ça donne quoi ?

yunohost service status fail2ban
active: active
active_at: 2019-03-18 20:17:21
description: protects against bruteforce and other kind of attacks from the Internet
loaded: enabled
service_file_path: /lib/systemd/system/fail2ban.service
status: running

Youpi ! fail2ban est en mode active !

Parfait !

Le bonheur Yunohost ? Ça se distribue aussi en tube ?

Arghhh … me revoici avec fail2ban “failed”.

~# yunohost service status fail2ban
active: failed
active_at: 1970-01-01 00:00:00
description: protects against bruteforce and other kind of attacks from the Internet
loaded: enabled
service_file_path: /lib/systemd/system/fail2ban.service
status: failed

J’essaye dans l’ordre:

  • arrêt de fail2ban
  • ré-install de fai2ban
  • regénération forcée de la configuration

Arrêt de fail2ban:

~# yunohost service stop fail2ban
Success! The service 'fail2ban' has been stopped`

Puis réinstall:

~# apt install fail2ban --reinstall
Reading package lists... Done
Building dependency tree       
Reading state information... Done
0 upgraded, 0 newly installed, 1 reinstalled, 0 to remove and 0 not upgraded.
1 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
E: Internal Error, No file name for fail2ban:armhf

Ça retourne donc une erreur.

J’essaye tout de même de régénérer a conf:

yunohost service regen-conf fail2ban --force

Rien n’est retourné par le système

Vérification du status de Fail2ban:

~# yunohost service status fail2ban
active: failed
active_at: 1970-01-01 00:00:00
description: protects against bruteforce and other kind of attacks from the Internet
loaded: enabled
service_file_path: /lib/systemd/system/fail2ban.service
status: failed

Relance fail2ban

~# yunohost service start fail2ban
.../...
-- Unit fail2ban.service has failed.
-- 
-- The result is failed.
Apr 17 09:45:21 MONSITE systemd[1]: fail2ban.service: Unit entered failed state.
Apr 17 09:45:21 MONSITE systemd[1]: fail2ban.service: Failed with result 'exit-code'.
Apr 17 09:45:21 MONSITE systemd[1]: fail2ban.service: Service hold-off time over, scheduling restart.
Apr 17 09:45:21 MONSITE systemd[1]: Stopped Fail2Ban Service.
-- Subject: Unit fail2ban.service has finished shutting down
-- Defined-By: systemd
-- Support: https://www.debian.org/support
-- 
-- Unit fail2ban.service has finished shutting down.
Apr 17 09:45:21 MONSITE systemd[1]: Starting Fail2Ban Service...
-- Subject: Unit fail2ban.service has begun start-up
-- Defined-By: systemd
-- Support: https://www.debian.org/support
-- 
-- Unit fail2ban.service has begun starting up.

Vérification du statut

~# yunohost service status fail2ban
active: failed
active_at: 1970-01-01 00:00:00
description: protects against bruteforce and other kind of attacks from the Internet
loaded: enabled
service_file_path: /lib/systemd/system/fail2ban.service
status: failed

Donc, à ce stade: fail2ban est toujours en failed et sa ré-installation ne semble pas fonctionner …

Une idée ?

Ça m’inquiète un peu cette anomalie. Je me demande s’il ne faudrait pas faire une réinstallation complète de Yunohost après sauvegarde.

Youpi ! La solution pour relancer fail2ban, quand fail2ban est sur failed, était déjà sur le wiki (suffisait de chercher … :wink: ). La voici:

Les problèmes venaient d’une migration après une mise à jour du serveur, migration dont je n’avais pas pris conscience.

Il faut d’abord terminer la migration (un message sur la messagerie du serveur existe sans doute dans vos emails, en ce sens).

Terminer la migration:

  • Via l’interface “webadmin” de yunohost, aller dans Outils → Migration
  • En ligne de commande lancer: yunohost tools migrations migrate

Puis, une fois que la migration est terminée, si fail2ban n’est toujours pas actif, et toujours sur failed, alors la solution a consisté à réinstaller le paquet fail2ban.

Ce qui donne, en connexion ssh sur la raspberry pi, les commandes successives suivantes:

apt-cache policy fail2ban
systemctl stop fail2ban
mv /etc/fail2ban /etc/fail2ban.old.19.04.18.01
wget http://ftp.fr.debian.org/debian/pool/main/f/fail2ban/fail2ban_0.9.6-2_all.deb
dpkg -i --force-confmiss fail2ban_0.9.6-2_all.deb
dpkg -i --force-confmiss /var/cache/apt/archives/fail2ban*.deb
yunohost service regen-conf fail2ban --force
systemctl restart fail2ban
yunohost service status fail2ban

EN DÉTAILS :

Repérage de la version de fail2ban

apt-cache policy fail2ban

Cela retourne:

fail2ban:
  Installed: 0.9.6-2
  Candidate: 0.9.6-2
  Version table:
 *** 0.9.6-2 500
        500 http://raspbian.raspberrypi.org/raspbian stretch/main armhf Packages
        100 /var/lib/dpkg/status

Arrêt de fail2ban:

systemctl stop fail2ban

On renome le dossier fail2ban pour en faire une copie de sauvegarde si nécessaire

mv /etc/fail2ban /etc/fail2ban.old.19.04.18.01

Nota: Le fichier se termine ici par .old.19.04.18.01 pour signifier la date, car c’est pratique. Mais il est possible de préférer un nom se terminant simplement en .old.2 ou .old.3, etc …

Téléchargement du paquet fail2ban dans la version repérée précédement

wget http://ftp.fr.debian.org/debian/pool/main/f/fail2ban/fail2ban_0.9.6-2_all.deb

Ce qui retourne

--2019-04-18 13:31:27--  http://ftp.fr.debian.org/debian/pool/main/f/fail2ban/fail2ban_0.9.6-2_all.deb
Resolving ftp.fr.debian.org (ftp.fr.debian.org)... 212.27.32.66, 2a01:e0c:1:1598::2
Connecting to ftp.fr.debian.org (ftp.fr.debian.org)|212.27.32.66|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 287540 (281K) [application/x-debian-package]
Saving to: ‘fail2ban_0.9.6-2_all.deb.1’

fail2ban_0.9.6-2_all.deb.1         100%[=============================================================>] 280.80K  1.30MB/s    in 0.2s    

2019-04-18 13:31:27 (1.30 MB/s) - ‘fail2ban_0.9.6-2_all.deb.1’ saved [287540/287540]

Dépaquetage en forçant les manquants

dpkg -i --force-confmiss fail2ban_0.9.6-2_all.deb

Cela retourne:

(Reading database ... 66744 files and directories currently installed.)
Preparing to unpack fail2ban_0.9.6-2_all.deb ...
Unpacking fail2ban (0.9.6-2) over (0.9.6-2) ...
Setting up fail2ban (0.9.6-2) ...

Configuration file '/etc/fail2ban/action.d/apf.conf', does not exist on system.
Installing new config file as you requested.

.../... blablabla .../...

Configuration file '/etc/fail2ban/paths-debian.conf', does not exist on system.
Installing new config file as you requested.

Configuration file '/etc/fail2ban/paths-opensuse.conf', does not exist on system.
Installing new config file as you requested.
Processing triggers for systemd (232-25+deb9u11) ...
Processing triggers for man-db (2.7.6.1-2) ...

Recherche et application des config présentes et archivées

dpkg -i --force-confmiss /var/cache/apt/archives/fail2ban*.deb

Cela retourne:

(Reading database ... 66744 files and directories currently installed.)
Preparing to unpack .../fail2ban_0.9.6-2_all.deb ...
Unpacking fail2ban (0.9.6-2) over (0.9.6-2) ...
Setting up fail2ban (0.9.6-2) ...
Processing triggers for systemd (232-25+deb9u11) ...
Processing triggers for man-db (2.7.6.1-2) ...

Regénération de config de fail2ban

yunohost service regen-conf fail2ban --force

Cela retourne

Success! The configuration has been updated for service 'fail2ban'
fail2ban: 
  applied: 
    /etc/fail2ban/filter.d/yunohost.conf: 
      status: force-created
    /etc/fail2ban/jail.conf: 
      status: force-updated
    /etc/fail2ban/jail.d/yunohost-jails.conf: 
      status: force-created
  pending: 

Redémarrage de fail2ban

systemctl restart fail2ban

Vérification du statut de fail2ban

yunohost service status fail2ban

Cela retourne:

active: active
active_at: 2019-04-18 13:35:03
description: protects against bruteforce and other kind of attacks from the Internet
loaded: enabled
service_file_path: /lib/systemd/system/fail2ban.service
status: running

Et c’est gagné.

Merci !

2 Likes