A CKAN extension that helps protect your portal from brute-force login attacks by tracking failed login attempts and temporarily locking accounts or IPs after too many failures.
The original code was taken as an base from ckanext-security.
- 🔒 Tracks unsuccessful login attempts in Redis
- 🔑 Lock based on IP address (default) or username
- ⏳ Temporary lockout (default: 15 minutes) after too many failed attempts
- 📧 Sends warning email to the affected user when lockout occurs
- ⚙️ Fully configurable via CKAN config settings
If your extension works across different versions you can add the following table:
Compatibility with core CKAN versions:
| CKAN version | Compatible? |
|---|---|
| 2.10+ | not tested |
| 2.11.3 | tested |
Suggested values:
- "yes"
- "not tested" - I can't think of a reason why it wouldn't work
- "not yet" - there is an intention to get it working
- "no"
To install ckanext-login-throttle:
-
Activate your CKAN virtual environment, for example:
. /usr/lib/ckan/default/bin/activate
-
Clone the source and install it on the virtualenv
git clone https://github.com/Datashades/ckanext-login-throttle.git cd ckanext-login-throttle pip install -e .
-
Add
login-throttleto theckan.pluginssetting in your CKAN config file (by default the config file is located at/etc/ckan/default/ckan.ini). -
Restart CKAN. For example if you've deployed CKAN with Apache on Ubuntu:
sudo service apache2 reload
Login flows that do not call CKAN's IAuthenticator.authenticate() can use the
same configured throttle directly:
from ckanext.login_throttle.api import is_login_locked, record_failed_login
if is_login_locked(login):
return locked_response
result = check_credentials()
if not result:
record_failed_login(login)Both functions use the configured IP- or username-based key and the current request. Credential validation remains the responsibility of the calling login flow.
Default value: 900
(integer) (optional) The time User is going to be locked while reaching the Attempts limit. By default its 900 seconds (e.g. 15 minutes).
Default value: 10
(integer) (optional) The amount of tries User can do before being locked. By default its 10.
Default value: none
(optional) Updates the logic based on what information the User will be locked. By default it using IP Address. Accepts only and string user_name value as an alternative to lock User by name.
Default value: none
(path) (optional) Can be used to override the footer text of the Email notification. By default it takes local file in the repo lockout_footer.txt.
Default value: False
(boolean) (optional) If True provided, notification won't be sent to the User. By default its False.
To install ckanext-login-throttle for development, activate your CKAN virtualenv and do:
git clone https://github.com/Datashades/ckanext-login-throttle.git
cd ckanext-login-throttle
pip install -e .
To run the tests, do:
pytest --ckan-ini=test.ini