Hi
It has taken me a while but I managed to install and configure fail2ban in an Ubuntu 22 VM running the self hosted Bitwarden Docker install from Linux Standard Deployment | Bitwarden Help Center.
Here is a short/concise description of the steps I have taken:
The following change is needed in Bitwarden environment variables after install to create correct log files.
nano ~/bwdata/env/global.override.env
globalSettings__logRollBySizeLimit=1073741824
Now install and configure Fail2ban
install
sudo apt install fail2ban
add jail
nano /etc/fail2ban/jail.conf
Search for the [bitwarden] jail configuration block, delete and replace with (modify last 4 lines as needed)
[bitwarden]
enabled = true
port = 80,443
filter = bitwarden
#action = iptables-allports[name=bitwarden]
action = iptables-allports[name=bitwarden, chain=FORWARD]
logpath = /root/bwdata/logs/identity/Identity/*.txt
maxretry = 5
bantime = 1h
findtime = 10m
ignoreip=127.0.0.1/8 ::1
enable fail2ban service
sudo systemctl enable fail2ban
start fail2ban
sudo systemctl start fail2ban
check if running
sudo systemctl status fail2ban.service
You should get:
ā fail2ban.service - Fail2Ban Service
Loaded: loaded (/lib/systemd/system/fail2ban.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2023-01-04 19:06:58 UTC; 14h ago
Docs: man:fail2ban(1)
Process: 28657 ExecStartPre=/bin/mkdir -p /run/fail2ban (code=exited, status=0/SUCCESS)
Main PID: 28658 (f2b/server)
Tasks: 7 (limit: 76987)
Memory: 13.4M
CPU: 19.478s
CGroup: /system.slice/fail2ban.service
āā28658 /usr/bin/python3 /usr/bin/fail2ban-server -xf startJan 04 19:06:58 BW systemd[1]: Starting Fail2Ban Serviceā¦
Jan 04 19:06:58 BW systemd[1]: Started Fail2Ban Service.
Jan 04 19:06:58 BW fail2ban-server[28658]: Server ready
check fail2ban ban status
fail2ban-client status bitwarden
If all is OK you should get
Status for the jail: bitwarden
|- Filter
| |- Currently failed: 0
| |- Total failed: 0
|- File list: /root/bwdata/logs/identity/Identity/log.txt
- Actions
|- Currently banned: 0
|- Total banned: 0
`- Banned IP list:
To unban:
unban all
fail2ban-client unban āall
unban ip
fail2ban-client unban xx.xx.xx.xx
Useful links:
Thanks Adam from support for helping on this.
Hope it helps others. While Bitwarden as is, is supposed to be safe on its own when exposed to the internet (thereās no way around it when self hosting) it certainly helps to have an additional layer of security.