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.10
Django >= 4.0
django-ipware >= 7
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 uv (https://docs.astral.sh/uv/getting-started/installation/) then run:
$ uv run 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_admin_ip_restrictor-3.0.0.tar.gz.
File metadata
- Download URL: django_admin_ip_restrictor-3.0.0.tar.gz
- Upload date:
- Size: 38.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5f4beba0a0fd6f1e3501cb2ed711b3a36c7056a009ab5b55db6c95ba99bb97e7
|
|
| MD5 |
716500b5662f7e9fd153674213a1b366
|
|
| BLAKE2b-256 |
340d1e42b3f6ed97621b0501ec04bdce4cb4e912f83fc5ca8192a8d4cc01b23e
|
Provenance
The following attestation bundles were made for django_admin_ip_restrictor-3.0.0.tar.gz:
Publisher:
publish.yml on sdonk/django-admin-ip-restrictor
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_admin_ip_restrictor-3.0.0.tar.gz -
Subject digest:
5f4beba0a0fd6f1e3501cb2ed711b3a36c7056a009ab5b55db6c95ba99bb97e7 - Sigstore transparency entry: 1077171889
- Sigstore integration time:
-
Permalink:
sdonk/django-admin-ip-restrictor@1106e399bc15bd2f4de73d54431d318977d63b72 -
Branch / Tag:
refs/tags/3.0.0 - Owner: https://github.com/sdonk
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@1106e399bc15bd2f4de73d54431d318977d63b72 -
Trigger Event:
release
-
Statement type:
File details
Details for the file django_admin_ip_restrictor-3.0.0-py3-none-any.whl.
File metadata
- Download URL: django_admin_ip_restrictor-3.0.0-py3-none-any.whl
- Upload date:
- Size: 4.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
68c0094539504c4f6570b90aa79072862369ea24555b946cc79e58aaa35af7f7
|
|
| MD5 |
3cc545ac5f800ea7806135779af95134
|
|
| BLAKE2b-256 |
d7a7dc1d9aeadb66274c9953888be4e23c7c9183df5997bee2be61b87f33dcc5
|
Provenance
The following attestation bundles were made for django_admin_ip_restrictor-3.0.0-py3-none-any.whl:
Publisher:
publish.yml on sdonk/django-admin-ip-restrictor
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_admin_ip_restrictor-3.0.0-py3-none-any.whl -
Subject digest:
68c0094539504c4f6570b90aa79072862369ea24555b946cc79e58aaa35af7f7 - Sigstore transparency entry: 1077171916
- Sigstore integration time:
-
Permalink:
sdonk/django-admin-ip-restrictor@1106e399bc15bd2f4de73d54431d318977d63b72 -
Branch / Tag:
refs/tags/3.0.0 - Owner: https://github.com/sdonk
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@1106e399bc15bd2f4de73d54431d318977d63b72 -
Trigger Event:
release
-
Statement type: