Django middleware for Kamal healthcheck requests
Project description
django-kamal-healthcheck
Django middleware that handles Kamal healthcheck requests.
The problem
kamal-proxy sends healthcheck requests to /up/ with a Host header that won't match your Django ALLOWED_HOSTS. The request hits Django's SecurityMiddleware or host validation and gets rejected before your app can respond, so kamal-proxy thinks the container is unhealthy.
The solution
HealthCheckMiddleware sits first in the middleware stack and intercepts healthcheck requests, returning a 200 OK response before any host validation or SSL redirect logic runs.
Installation
If you use uv:
uv add django-kamal-healthcheck
or
pip install django-kamal-healthcheck
Configuration
Add kamal_healthcheck to INSTALLED_APPS and put the middleware first in MIDDLEWARE:
# settings.py
INSTALLED_APPS = [
"kamal_healthcheck",
# ...
]
MIDDLEWARE = [
"kamal_healthcheck.middleware.HealthCheckMiddleware", # must precede SecurityMiddleware
"django.middleware.security.SecurityMiddleware",
# ...
]
That's it. Requests to /up/ will return a 200 OK plain text response.
Custom healthcheck path
The default path is /up/, matching kamal-proxy's default. To change it:
KAMAL_HEALTHCHECK_PATH = "/healthz/"
System checks
The app registers two Django system checks that run automatically:
-
kamal_healthcheck.W001: Warns ifSECURE_SSL_REDIRECT = TrueandSecurityMiddlewareis ordered beforeHealthCheckMiddleware. kamal-proxy handles SSL termination and does not follow redirects, so this combination causes healthcheck redirect loops. -
kamal_healthcheck.W002: Warns ifHealthCheckMiddlewareis not the first entry inMIDDLEWARE. It must run before host validation and other security middleware.
Requirements
- Python >= 3.10
- Django >= 4.2
License
MIT
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
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_kamal_healthcheck-0.1.0.tar.gz.
File metadata
- Download URL: django_kamal_healthcheck-0.1.0.tar.gz
- Upload date:
- Size: 13.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a635041690f453cafa771e37b91875ae1b25d55d14ce63eb9955bca549425667
|
|
| MD5 |
2b9101ab5d63bb6002a49243cdf38a05
|
|
| BLAKE2b-256 |
006a0c174c84aa1e1dd7c4aae97c495e4b61916daed31bf54fb2d449d4da2c3a
|
Provenance
The following attestation bundles were made for django_kamal_healthcheck-0.1.0.tar.gz:
Publisher:
ci.yml on smulloni/django-kamal-healthcheck
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_kamal_healthcheck-0.1.0.tar.gz -
Subject digest:
a635041690f453cafa771e37b91875ae1b25d55d14ce63eb9955bca549425667 - Sigstore transparency entry: 1005199336
- Sigstore integration time:
-
Permalink:
smulloni/django-kamal-healthcheck@ccd26390b06495981478a51d421e8066113b9eca -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/smulloni
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@ccd26390b06495981478a51d421e8066113b9eca -
Trigger Event:
push
-
Statement type:
File details
Details for the file django_kamal_healthcheck-0.1.0-py3-none-any.whl.
File metadata
- Download URL: django_kamal_healthcheck-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.4 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 |
8a6482aa9df00cb9de86cfe3d6c9e9fb4d7cc396f1705d9c7d9efedfbc850b53
|
|
| MD5 |
1441f674ab881e4dcf5ad722076911f5
|
|
| BLAKE2b-256 |
efd946849224a1229341b8bf48730ed6968fc8389ee4c26a069760e184d468cc
|
Provenance
The following attestation bundles were made for django_kamal_healthcheck-0.1.0-py3-none-any.whl:
Publisher:
ci.yml on smulloni/django-kamal-healthcheck
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_kamal_healthcheck-0.1.0-py3-none-any.whl -
Subject digest:
8a6482aa9df00cb9de86cfe3d6c9e9fb4d7cc396f1705d9c7d9efedfbc850b53 - Sigstore transparency entry: 1005199354
- Sigstore integration time:
-
Permalink:
smulloni/django-kamal-healthcheck@ccd26390b06495981478a51d421e8066113b9eca -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/smulloni
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@ccd26390b06495981478a51d421e8066113b9eca -
Trigger Event:
push
-
Statement type: