Skip to content
Restrict Django admin access based on incoming IPs
Branch: master
Clone or download
sdonk Merge pull request #21 from sdonk/handle-prefixed-apps
Handle situations where request.path is not a resolvable url
Latest commit 29c9486 Oct 25, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
admin_ip_restrictor
tests fix reverse_lazy import for django 2 Apr 25, 2018
.coveragerc added missing files Mar 21, 2018
.gitignore
LICENSE added missing files Mar 21, 2018
MANIFEST.in added missing files Mar 21, 2018
README.rst
circle.yml force python 3 in the circle ci machine Apr 25, 2018
makefile
requirements_flake8.txt
setup.cfg restrict any app based on name Apr 4, 2018
setup.py
tox.ini

README.rst

Django Admin IP Restrictor

https://circleci.com/gh/uktrade/django-admin-ip-restrictor/tree/master.svg?style=shield

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!

You can’t perform that action at this time.