Skip to main content
Python Software Foundation 20th Year Anniversary Fundraiser  Donate today!

A Django middleware to restrict incoming IPs to admin panel

Project description

https://circleci.com/gh/uktrade/django-admin-ip-restrictor/tree/master.svg?style=shield https://codecov.io/gh/uktrade/django-admin-ip-restrictor/branch/master/graph/badge.svg https://img.shields.io/pypi/v/django-admin-ip-restrictor.svg https://img.shields.io/pypi/pyversions/django-admin-ip-restrictor.svg https://img.shields.io/pypi/l/django-admin-ip-restrictor.svg

A Django middleware to restrict the access to the Django admin based on incoming IPs

Requirements

  • Python >= 3.4
  • Django >= 1.10
  • django-ipware=>2,<3

Usage

First install the package:

$ pip install django-admin-ip-restrictor

Then add the middleware to your settings:

# Django 1.10+
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']

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

Run tests

Install tox and pyenv:

$ pip install tox pyenv

Install Python versions in pyenv:

$ pyenv install 3.4.4
$ pyenv install 3.5.3
$ pyenv install 3.6.2

Specify the Python versions you want to test with:

$ pyenv local 3.4.4 3.5.3 3.6.2

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.

Files for django-admin-ip-restrictor, version 1.0.0
Filename, size File type Python version Upload date Hashes
Filename, size django_admin_ip_restrictor-1.0.0-py3-none-any.whl (4.5 kB) File type Wheel Python version py3 Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page