{"id":22191275,"url":"https://github.com/dunderrrrrr/fail2ban-fastapi","last_synced_at":"2025-07-26T22:31:24.851Z","repository":{"id":50376221,"uuid":"245363477","full_name":"dunderrrrrr/Fail2ban-FastAPI","owner":"dunderrrrrr","description":"FastAPI for Fail2ban with vuejs frontend for easy management","archived":false,"fork":false,"pushed_at":"2020-03-06T08:11:31.000Z","size":25,"stargazers_count":14,"open_issues_count":0,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2023-08-20T14:37:29.309Z","etag":null,"topics":["api","api-rest","fail2ban","fail2ban-dashboard","fastapi","python","python3","vuejs"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dunderrrrrr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-03-06T08:11:01.000Z","updated_at":"2023-08-10T16:47:51.000Z","dependencies_parsed_at":"2022-08-19T13:31:53.189Z","dependency_job_id":null,"html_url":"https://github.com/dunderrrrrr/Fail2ban-FastAPI","commit_stats":null,"previous_names":[],"tags_count":0,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dunderrrrrr%2FFail2ban-FastAPI","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dunderrrrrr%2FFail2ban-FastAPI/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dunderrrrrr%2FFail2ban-FastAPI/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dunderrrrrr%2FFail2ban-FastAPI/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dunderrrrrr","download_url":"https://codeload.github.com/dunderrrrrr/Fail2ban-FastAPI/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227724176,"owners_count":17810036,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","api-rest","fail2ban","fail2ban-dashboard","fastapi","python","python3","vuejs"],"created_at":"2024-12-02T12:15:14.687Z","updated_at":"2024-12-02T12:15:15.363Z","avatar_url":"https://github.com/dunderrrrrr.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"fail2ban-fastapi\n----------\n  \nFail2Ban operates by monitoring log files (e.g. `/var/log/auth.log`, `/var/log/apache/access.log`, etc.) for selected entries and running scripts based on them. Most commonly this is used to block selected IP addresses that may belong to hosts that are trying to breach the system's security.\n\n**What is fail2ban-fastapi?**  \nFrontend (vuejs) and backend (fastapi). FastAPI reads it's data from files created by this script (since Fail2ban's internal sqlite database is not human readable). The script user must have permissions to execute `$ fail2ban-client` to generate this data.\n```\n.\n├── api\n│   └── data/\n│       └── jails.txt\n│       └── jail_\u003cjailname\u003e.txt\n│       └── jail_\u003cjailname\u003e.txt\n```\n\n![Fail2ban-FastAPI Demo](https://i.imgur.com/7sQhGeh.gif)\n\n## Installation\n\n### Fail2ban Setup\n\nFirst of all, the script needs to be able to run `fail2ban-client` command. This is usually done with root permissions. To solve this, you need to create a new (non-root) user and run fail2ban as this user. \n\n```bash\n$ sudo apt install fail2ban\n$ sudo adduser fail2ban\n```\n\nSet `User` to \"fail2ban\" in the [Service] section in `/lib/systemd/system/fail2ban.service`\n```text\n...\n[Service]\nUser=fail2ban\n...\n```\n\nChange permissions of `/var/run/fail2ban`.\n```bash\n$ sudo chown -R fail2ban:root /var/run/fail2ban\n```\n\nVerify permissions with `sudo ls -la /var/run/fail2ban/`. Make sure fail2ban user can read and write to this location.\n\nDepending on your jails, the fail2ban user needs to be able read your logfiles (ex. `/var/log/auth.log`). An example configuration can be found in [jail.local.sample](./jail.local.sample).  \n  \nSo change permisions of your logfiles.\n```bash\n$ sudo chown fail2ban:root /var/log/auth.log\n```\n\nNow you should be all set to reload `systemctl daemon` and restart fail2ban.\n\n```bash\n$ sudo systemctl daemon-reload\n$ sudo systemctl restart fail2ban.service\n```\n\nCheck status of fail2ban.service to make sure we're all set and you have no errors.\n\n## Install Fail2ban-FastAPI\n\nClone rep, create virtualenv and install requirements.\n```bash\n$ git clone git@github.com:dunderrrrrr/fail2ban-fastapi.git\n$ mkvirtualenv --python=/usr/bin/python3 fail2ban-fastapi\n$ pip install -r requirements.txt\n```\n\nBefore starting FastAPI backend we'll need to generate some Fail2ban data. This will only be necessary once when setting up Fail2ban-FastAPI for the first time on.\n```bash\n$ cd api/\n$ python first_init.py\n```\n\nStart FastAPI backend.\n```bash\n$ python main.py\n```\n\nStart vuejs frontend.\n```bash\n$ npm install\n$ npm run dev\n```\n\nFastAPI backend can be access at `http://localhost:8000`.  \nFrontend access at `http://localhost:8080`.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdunderrrrrr%2Ffail2ban-fastapi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdunderrrrrr%2Ffail2ban-fastapi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdunderrrrrr%2Ffail2ban-fastapi/lists"}