Skip to main content

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.

GEOIP

GEOIP can be done via sources (WIP)

TODO

  • tests
  • localization?
  • compare ipv6 mapped ip4 with ipv4 rules
  • remote fetch sources and cache them. Use get_many set_many to retrieve them

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_fast_iprestrict-0.5.0a1.tar.gz (12.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_fast_iprestrict-0.5.0a1-py3-none-any.whl (16.1 kB view details)

Uploaded Python 3

File details

Details for the file django_fast_iprestrict-0.5.0a1.tar.gz.

File metadata

  • Download URL: django_fast_iprestrict-0.5.0a1.tar.gz
  • Upload date:
  • Size: 12.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.11.6 Linux/6.6.7-arch1-1

File hashes

Hashes for django_fast_iprestrict-0.5.0a1.tar.gz
Algorithm Hash digest
SHA256 d1c80136dfb1bedca19fe8975153226c873ff05c8657d7a1c0f9da57daab0d85
MD5 6abeefd3c65421ac3d780fd3c43576cd
BLAKE2b-256 496e1db7d91d7f7ec9b8914442eb3bb4878aa26a6956497a79821a5211848fd0

See more details on using hashes here.

File details

Details for the file django_fast_iprestrict-0.5.0a1-py3-none-any.whl.

File metadata

File hashes

Hashes for django_fast_iprestrict-0.5.0a1-py3-none-any.whl
Algorithm Hash digest
SHA256 850a5e96b16077e5e2dee1cdc9e50b5a282ff0c98a0f7eb90a2d89ffe7130d1d
MD5 fc8fb935c7298009eb009d0a92c5094a
BLAKE2b-256 5ac62a13df41c9fc3879ccca2382264adfb7dc0b9fd6e44984f75643d388955d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page