Django Allow Health-Checks
Background
Kubernetes, load-balancers and other PaaS have a concept of a health check. These are simple GET requests against an endpoint that you define which tells the orchestrator if a web worker is healthy or not. The problem is that these requests come from within the same network running your app using an non-deterministic hostname or IP address. So instead of making your allowed hosts wide open with ['*'] (to allow any requests to get by), you can simply install this package to allow these requests to occur without introducing more technical/security risks then necessary.
For example, given a kubernetes deployment with the following details:
#... other details
containers:
- name: app
image: registry.gitlab.com/username/cool-app/app
livenessProbe:
httpGet:
path: /health-check/
port: 8000
httpHeaders:
- name: X-Health
value: XYZ-123
initialDelaySeconds: 3
periodSeconds: 60
imagePullPolicy: Always
You can allow these requests to get by by simply adding this to your settings
HEALTH_CHECK_HEADER_VALUE = 'XYZ-123'
Setup
Install django-allow-healthchecks
pip3 install django-allow-healthchecks
Add the class to your middleware, ideally first in the list
MIDDLEWARE = [
'django_allow_healthchecks.middleware.ByPassForHealthChecks', # <~ Add this
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
Assign your magical header value
HEALTH_CHECK_HEADER_VALUE = 'XYZ-Health'
Notes
Python3.5+ + Django 2.2+! Get on board!!
Metadata
Release files for django-allow-healthchecks 0.1.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django-allow-healthchecks-0.1.4.tar.gz | 5.7 kB | Without provenance | Details for django-allow-healthchecks-0.1.4.tar.gz |
Release files / django-allow-healthchecks-0.1.4.tar.gz
| Download URL | django-allow-healthchecks-0.1.4.tar.gz |
|---|---|
| Size | 5.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1a680e82341e1e449849d244b0520c825763e149ec3a94fb10ca75bf0f58cece
|
|
BLAKE2b-256 checksum How to use checksums |
f330e10d6631007eccfa5f3e4e178fffa2e7e16a7d2edb696e47e75464b49db7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.20.1 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.4
|
Security for django-allow-healthchecks 0.1.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.