AntibruteForce is a microservice designed to prevent password brute-force attacks during user authentication.
This service is called before user authentication and can either allow or block the attempt. It's intended for server-to-server use only and is hidden from end-users.
The service limits the frequency of authentication attempts for various parameter combinations specified in the config.yml
file:
- No more than N = 10 attempts per minute for a given login.
- No more than M = 100 attempts per minute for a given password (reverse brute-force protection).
- No more than K = 1000 attempts per minute for a given IP (high number due to NAT).
The Generic Cell Rate Algorithm (GCRA), also known as the leaky bucket algorithm, is used to count and limit request frequencies.
GCRA was chosen for its efficiency in managing rate limiting with minimal memory usage. In our context, it works by:
- Assigning a "bucket" to each login/password/IP.
- Each request "fills" the bucket by a certain amount.
- The bucket "leaks" at a constant rate.
- If a request would overflow the bucket, it's considered a brute-force attempt.
This approach allows for occasional bursts of traffic while still enforcing long-term rate limits.
The service configuration is located in the config.yml
file. The main configuration parameters are loginLimit, passLimit, and ipLimit - the limits at which the service considers an attempt to be a brute-force attack.
The microservice consists of:
- gRPC API
- Redis database for storing buckets
- PostgreSQL database for storing black/white lists
- Command-line interface for interacting with the service
To deploy the microservice:
-
Clone the repository:
git clone github.com/tabularasa31/antibruteforce.git cd antibruteforce
-
Set up the environment:
# Edit config.yml with your settings
-
Run the service:
make up
Run the test suite with:
make test
The service is designed to handle high loads:
- Tested up to 10,000 requests per second on a standard 4-core server.
- Redis and PostgreSQL should be properly tuned for production environments.
- Consider deploying multiple instances behind a load balancer for very high traffic scenarios.
This project is licensed under the MIT License.