You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

fail2ban-setup.md 1.6 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. ---
  2. date: "2018-05-11T11:00:00+02:00"
  3. title: "Usage: Setup fail2ban"
  4. slug: "fail2ban-setup"
  5. weight: 16
  6. toc: true
  7. draft: false
  8. menu:
  9. sidebar:
  10. parent: "usage"
  11. name: "Fail2ban setup"
  12. weight: 16
  13. identifier: "fail2ban-setup"
  14. ---
  15. # Fail2ban setup to block users after failed login attemts
  16. **Remember that fail2ban is powerful and can cause lots of issues if you do it incorrectly, so make
  17. sure to test this before relying on it so you don't lock yourself out.**
  18. Gitea returns an HTTP 200 for bad logins in the web logs, but if you have logging options on in
  19. `app.ini`, then you should be able to go off of `log/gitea.log`, which gives you something like this
  20. on a bad authentication:
  21. ```log
  22. 2018/04/26 18:15:54 [I] Failed authentication attempt for user from xxx.xxx.xxx.xxx
  23. ```
  24. So we set our filter in `/etc/fail2ban/filter.d/gitea.conf`:
  25. ```ini
  26. # gitea.conf
  27. [Definition]
  28. failregex = .*Failed authentication attempt for .* from <HOST>
  29. ignoreregex =
  30. ```
  31. And configure it in `/etc/fail2ban/jail.d/jail.local`:
  32. ```ini
  33. [gitea]
  34. enabled = true
  35. port = http,https
  36. filter = gitea
  37. logpath = /home/git/gitea/log/gitea.log
  38. maxretry = 10
  39. findtime = 3600
  40. bantime = 900
  41. action = iptables-allports
  42. ```
  43. Make sure and read up on fail2ban and configure it to your needs, this bans someone
  44. for **15 minutes** (from all ports) when they fail authentication 10 times in an hour.
  45. If you run Gitea behind a reverse proxy with Nginx (for example with Docker), you need to add
  46. this to your Nginx configuration so that IPs don't show up as 127.0.0.1:
  47. ```
  48. proxy_set_header X-Real-IP $remote_addr;
  49. ```