A Django middleware to restrict incoming IPs to admin panel
Project description
A Django middleware to restrict the access to the Django admin based on incoming IPs
Requirements
Python >= 3.5
Django >= 1.11,<4
django-ipware=>2,<4
Note that Django 3 has dropped support for Python 3.5
Usage
First install the package:
$ pip install django-admin-ip-restrictor
Then add the middleware to your settings:
MIDDLEWARE = [
...
'admin_ip_restrictor.middleware.AdminIPRestrictorMiddleware'
]
Set these variables in your settings.py to control who has access to the admin (IPV4 and IPV6 can be mixed):
RESTRICT_ADMIN=True ALLOWED_ADMIN_IPS=['127.0.0.1', '::1'] ALLOWED_ADMIN_IP_RANGES=['127.0.0.0/24', '::/1'] RESTRICTED_APP_NAMES=['admin'] TRUST_PRIVATE_IP=True
Use RESTRICTED_APP_NAMES to restrict the access to more apps. Admin app is always included.
If using environment variables make sure that the variables receive the right type of value. django-admin-ip-restrictor automatically converts the following formats:
$ export RESTRICT_ADMIN='true' $ export ALLOWED_ADMIN_IPS='127.0.0.1,::1' $ export ALLOWED_ADMIN_IP_RANGES='127.0.0.0/24,::/1' $ export RESTRICTED_APP_NAMES='wagtail_admin,foo'
For RESTRICT_ADMIN also these values can be used: True, 1, false, False, 0
Use TRUST_PRIVATE_IP to skip checking IP addresses from a trusted private network.
Changelog
Full changelog at https://github.com/sdonk/django-admin-ip-restrictor/blob/master/CHANGELOG.rst
Run tests
Install tox:
$ pip install tox
Install pyenv, use https://github.com/pyenv/pyenv#installation as reference.
Install Python versions in pyenv:
$ pyenv install 3.5.10 $ pyenv install 3.6.12 $ pyenv install 3.7.9 $ pyenv install 3.8.6
Specify the Python versions you want to test with:
$ pyenv local 3.5.10 3.6.12 3.7.9 3.8.6
Run tests:
$ tox
Contribute
Fork the project and submit a PR!
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
File details
Details for the file django-admin-ip-restrictor-2.2.0.tar.gz.
File metadata
- Download URL: django-admin-ip-restrictor-2.2.0.tar.gz
- Upload date:
- Size: 4.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.7.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c6dbb2baf4b52b77e91c406bb258acd057acfe1f22dac20fd01daef0f656e1ac
|
|
| MD5 |
04ccd7448e69afeae7739338f53666f4
|
|
| BLAKE2b-256 |
b50f4130eb740242af03b6d8b55c9b3cb2a14d6c51074d8302f3361b0f1f9865
|