Site-wide perimeter access control for Django projects.
Project description
This package now requires Python 3.7+ and Django 2.2+. For previous versions please refer to the relevant branch.
Django Perimeter
Perimeter is a Django app that provides middleware that allows you to ‘secure the perimeter’ of your django site outside of any existing auth process that you have.
Why?
Most django sites have some kind of user registration and security model - a login process, decorators to secure certain URLs, user accounts - everything that comes with django.contrib.auth and associated apps (django-registration).
Sometimes, however, you want to simply secure the entire site to prevent prying eyes - the classic example being before a site goes live. You want to erect a secure perimeter fence around the entire thing. If you have control over your front-end web server (e.g. Apache, Nginx) then this can be used to do this using their in-built access control features. However, if you are running your app on a hosting platform you may not have admin access to these parts. Even if you do have control over your webserver, you may not want to be re-configuring it every time you want to grant someone access.
That’s when you need Perimeter.
Perimeter provides simple tokenised access control over your entire Django site (everything, including the admin site and login pages).
How does it work?
Once you have installed and enabled Perimeter, everyone requiring access will need an authorisation token (not authentication - there is nothing inherent in Perimeter to prevent people swapping / sharing tokens - that is an accepted use case).
Perimeter runs as middleware that will inspect the user’s session for a token. If they have a valid token, then they continue to use the site uninterrupted. If they do not have a token, or the token is invalid (expired or set to inactive), then they are redirected to the Perimeter ‘Gateway’, where they must enter a valid token, along with their name and email (for auditing purposes - this is stored in the database).
To create a new token you need to head to the admin site, and create a new token under the Perimeter app. If you have PERIMETER_ENABLED set to True already you won’t be able to access the admin site (as Perimeter covers everything except for the perimeter ‘gateway’ form), and so there is a management command (create_access_token) that you can use to create your first token. (This is analagous to the Django setup process where it prompts you to create a superuser.)
Setup
Add ‘perimeter’ to your installed apps.
Add ‘perimeter.middleware.PerimeterAccessMiddleware’ to the list of MIDDLEWARE_CLASSES
Add the perimeter urls - NB must use the ‘perimeter’ namespace
Add PERIMETER_ENABLED=True to your settings file. This setting can be used to enable or disable Perimeter in different environments.
Settings:
PERIMETER_ENABLED = True
INSTALLED_APPS = (
...
'perimeter',
...
)
# perimeter must appear after sessions middleware as it relies on there
# being a valid request.session
MIDDLEWARE_CLASSES = [
...
'django.contrib.sessions.middleware.SessionMiddleware',
'perimeter.middleware.PerimeterAccessMiddleware',
...
]
Site urls:
# in site urls
urlpatterns = patterns(
'',
...
# NB you must include the namespace, as it is referenced in the app
url(r'^perimeter/', include('perimeter.urls', namespace='perimeter')),
...
)
Tests
The app has a suite of tests, and a tox.ini file configured to run them when using tox (recommended).
Project details
Release history Release notifications | RSS feed
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
File details
Details for the file perimeter-0.14.tar.gz
.
File metadata
- Download URL: perimeter-0.14.tar.gz
- Upload date:
- Size: 13.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.0.2 CPython/3.8.1 Darwin/19.5.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 718620878cdf9e26b7ba360005dae0ef2dc75dcceaefdefe27b8ab561752a487 |
|
MD5 | e4e8366e8cfaaced9ba71369ec53387e |
|
BLAKE2b-256 | 792605afb98464aa9836aa9c5a7ebbbeab20e9a040414477e9a7f10d4e4524d2 |
File details
Details for the file perimeter-0.14-py3-none-any.whl
.
File metadata
- Download URL: perimeter-0.14-py3-none-any.whl
- Upload date:
- Size: 17.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.0.2 CPython/3.8.1 Darwin/19.5.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5238ccea1c86f854ab76cf542e30b2d9b1953344a72523325328d230e36fbe05 |
|
MD5 | ad3a8d184eabe9fe7a7211d899ee5ad0 |
|
BLAKE2b-256 | b2612326fd4563d17ee949b4b79d14bfbc491375b8436748a2d6720f128e61f6 |