Giter Club home page Giter Club logo

fail2ban-fastapi's Introduction

fail2ban-fastapi

Fail2Ban 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.

What is fail2ban-fastapi?
Frontend (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.

.
├── api
│   └── data/
│       └── jails.txt
│       └── jail_<jailname>.txt
│       └── jail_<jailname>.txt

Fail2ban-FastAPI Demo

Installation

Fail2ban Setup

First 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.

$ sudo apt install fail2ban
$ sudo adduser fail2ban

Set User to "fail2ban" in the [Service] section in /lib/systemd/system/fail2ban.service

...
[Service]
User=fail2ban
...

Change permissions of /var/run/fail2ban.

$ sudo chown -R fail2ban:root /var/run/fail2ban

Verify permissions with sudo ls -la /var/run/fail2ban/. Make sure fail2ban user can read and write to this location.

Depending 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.

So change permisions of your logfiles.

$ sudo chown fail2ban:root /var/log/auth.log

Now you should be all set to reload systemctl daemon and restart fail2ban.

$ sudo systemctl daemon-reload
$ sudo systemctl restart fail2ban.service

Check status of fail2ban.service to make sure we're all set and you have no errors.

Install Fail2ban-FastAPI

Clone rep, create virtualenv and install requirements.

$ git clone [email protected]:dunderrrrrr/fail2ban-fastapi.git
$ mkvirtualenv --python=/usr/bin/python3 fail2ban-fastapi
$ pip install -r requirements.txt

Before 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.

$ cd api/
$ python first_init.py

Start FastAPI backend.

$ python main.py

Start vuejs frontend.

$ npm install
$ npm run dev

FastAPI backend can be access at http://localhost:8000.
Frontend access at http://localhost:8080.

fail2ban-fastapi's People

Contributors

dunderrrrrr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

fail2ban-fastapi's Issues

Licence

Hello, your project seems really nice, thank you for sharing. Can you add a licence because i don't see any ref. about it.
Thank you.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.