No project description provided
Project description
django-fast-iprestrict
Django-fast-iprestrict provides a secure facility based on the django admin framework to restrict the access for the whole project or for parts of it to special ips or denylisting some ip networks. Internal only networks are used for ip matching and for path matching regex is used (Note: when regex is turned of (default) the pathmatcher just escapes the strings before feeding them to the regex pattern)
The name comes from the relationship to django-fast-ratelimit.
It is even possible to use django-fast-iprestrict in django-fast-ratelimit
Installation
pip install django-fast-iprestrict
Now add to python settings
settings:
INSTALLED_APPS = [
...
"django_fast_iprestrict",
]
# if wanted (it is also possible to use this tool only with django-fast-ratelimit)
MIDDLEWARE = [
...
"django_fast_iprestrict.middleware.fast_iprestrict",
...
]
Note: pip >= 19 is required
usage
In the admin panel is now a section Rule and Rule Pathes. Rule pathes like .*
can be used to match for the whole project.
Rules are evalutated like a waterfall: the lowest position to the highest position. State disabled rules are skipped
Note: ipv4 and ipv6 rules are not interoperable yet. If the network does not match they are skipped like if they are in state "disabled".
The rule names can be used for the django-fast-ratelimit adapter:
import ratelimit
@ratelimit.decorate(key="django_fast_iprestrict.apply_iprestrict", groups="rulename")
def foo(request):
return "
settings
IPRESTRICT_DEFAULT_ACTION: "allow"/"deny" : default action when no rule matches, default, when unset is "allow". Recommended otherwise a lockout is easily possible IPRESTRICT_TRUSTED_PROXIES: set list of trusted proxies RATELIMIT_TRUSTED_PROXIES: fallback when IPRESTRICT_TRUSTED_PROXIES is unset IPRESTRICT_TESTCLIENT_FALLBACK: fallback for the string testclient in the ip field. Dev setting for tests RATELIMIT_TESTCLIENT_FALLBACK: fallback when IPRESTRICT_TESTCLIENT_FALLBACK is unset
development
a development environment can be setup this way (poetry is recommended):
# installation then
poetry run ./manage.py createsuperuser
poetry run ./manage.py runserver
Note:
given the lack of tests and the early development state, it is possible that some parts have erratas.
TODO
- tests
- localization?
- compare ipv6 mapped ip4 with ipv4 rules
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for django_fast_iprestrict-0.4.4.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | e2fff22c8f5d6ce7efa6d7d615dd46c54b8aa3aa2d864d0bf5120824eeb2b23d |
|
MD5 | 7a7d7fbf8b7cb22950333c17c748501b |
|
BLAKE2b-256 | 8f03de2da5fd9ffe934746e91a7315f4f2652e407e57290ff78a2f0f109fb383 |
Hashes for django_fast_iprestrict-0.4.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cf5fbe429b91e1ea48dd0ae8ec63def8cfc7a11cb42625f32eaea0c754831b66 |
|
MD5 | e378dd621268b750d1eb6adbd6253be2 |
|
BLAKE2b-256 | 3749b3c08329bdf4c9d2b5c8106ec85997d4acee13df89b2e248c351f3c176e0 |