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 2.1 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 attempts
  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. Add 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. Add our jail in `/etc/fail2ban/jail.d/gitea.conf`:
  32. ```ini
  33. [gitea]
  34. enabled = true
  35. filter = gitea
  36. logpath = /home/git/gitea/log/gitea.log
  37. maxretry = 10
  38. findtime = 3600
  39. bantime = 900
  40. action = iptables-allports
  41. ```
  42. If you're using Docker, you'll also need to add an additional jail to handle the **FORWARD**
  43. chain in **iptables**. Configure it in `/etc/fail2ban/jail.d/gitea-docker.conf`:
  44. ```ini
  45. [gitea-docker]
  46. enabled = true
  47. filter = gitea
  48. logpath = /home/git/gitea/log/gitea.log
  49. maxretry = 10
  50. findtime = 3600
  51. bantime = 900
  52. action = iptables-allports[chain="FORWARD"]
  53. ```
  54. Then simply run `service fail2ban restart` to apply your changes. You can check to see if
  55. fail2ban has accepted your configuration using `service fail2ban status`.
  56. Make sure and read up on fail2ban and configure it to your needs, this bans someone
  57. for **15 minutes** (from all ports) when they fail authentication 10 times in an hour.
  58. If you run Gitea behind a reverse proxy with Nginx (for example with Docker), you need to add
  59. this to your Nginx configuration so that IPs don't show up as 127.0.0.1:
  60. ```
  61. proxy_set_header X-Real-IP $remote_addr;
  62. ```