Skip to content

root: implement liveness endpoint in a middleware - #25598

Draft
severin wants to merge 1 commit into
goauthentik:mainfrom
severin:core/liveness-probes-without-db
Draft

root: implement liveness endpoint in a middleware#25598
severin wants to merge 1 commit into
goauthentik:mainfrom
severin:core/liveness-probes-without-db

Conversation

@severin

@severin severin commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

This is a suggestion on top of #25597. I personally find it the better approach because there's no easy way for regressions (i.e. new middlewares that add database queries and would have to be remembered to skip). Also, it's more efficient (and therefore probably more performant, though I'm not sure how quantifiable the impact is) since almost the whole Django request processing can be skipped.


As per Kubernetes best practices liveness probes should not hit any dependencies (like databases):

When your app has a strict dependency on back-end services, you can implement both a liveness and a readiness probe. The liveness probe passes when the app itself is healthy, but the readiness probe additionally checks that each required back-end service is available. This helps you avoid directing traffic to Pods that can only respond with error messages.
(from https://kubernetes.io/docs/concepts/workloads/pods/probes)

Currently the liveness probe implementation triggers a few database queries (for tenant and brand; from middlewares).

This PR proposes the following way to address this: It implements the liveness endpoint in a middleware that runs before anything else, therefore any side-effects from other middlewares are skipped.

Note: This means that liveness endpoint calls no longer are treated as "normal" Django requests and won't be reported in e.g. Prometheus metrics. I added a mention of this in the docs but it should probably also be called out in the release notes.

Since this is quite a big change to how things work currently I'm also proposing a less intrusive (but more manual) approach in #25597

Details

What does this PR change?

It implements the liveness endpoint in a middleware that runs before anything else instead of a Django view. Therefore any side-effects from other middlewares are skipped.

Why is this change needed?

To remove any (accidental) external dependencies for the liveness probe endpoint

How was this tested?

By adding a unit test and manually verifying that the endpoint returns the desired status.

Disclaimer

I used an AI agent (opencode with Claude Opus and Gemini Flash) to help with the implementation. But all the changes were reviewed and tested manually.

Checklist

  • The project has been linted, built, and tested (make all)
  • The documentation has been updated and formatted (make docs)
  • I have read the AI usage policy.
As per Kubernetes best practices liveness probes should not hit any
dependencies (like databases). Currently the liveness probe
implementation triggers multiple database queries (for tenant and brand; from
middlewares).

This change implements the liveness endpoint in a middleware that runs
before anything else, therefore any side-effects from other middlewares
are skipped.

Note: This means that liveness endpoint calls no longer are treated as
"normal" Django requests and won't be reported in e.g. Prometheus
metrics.
@netlify

netlify Bot commented Aug 31, 2026

Copy link
Copy Markdown

Deploy Preview for authentik-storybook ready!

Name Link
🔨 Latest commit 6b57cd0
🔍 Latest deploy log https://app.netlify.com/projects/authentik-storybook/deploys/6a9544859c53a60008e0f00f
😎 Deploy Preview https://deploy-preview-25598--authentik-storybook.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented Aug 31, 2026

Copy link
Copy Markdown

Deploy Preview for authentik-integrations ready!

Name Link
🔨 Latest commit 6b57cd0
🔍 Latest deploy log https://app.netlify.com/projects/authentik-integrations/deploys/6a954485c9b9350008549e58
😎 Deploy Preview https://deploy-preview-25598--authentik-integrations.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented Aug 31, 2026

Copy link
Copy Markdown

Deploy Preview for authentik-docs ready!

Name Link
🔨 Latest commit 6b57cd0
🔍 Latest deploy log https://app.netlify.com/projects/authentik-docs/deploys/6a954485ca12fe0008a2be15
😎 Deploy Preview https://deploy-preview-25598--authentik-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@codecov

codecov Bot commented Aug 31, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.65%. Comparing base (9bd8fab) to head (6b57cd0).
⚠️ Report is 17 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #25598      +/-   ##
==========================================
- Coverage   91.67%   91.65%   -0.02%     
==========================================
  Files        1151     1152       +1     
  Lines       73416    73508      +92     
  Branches     4054     4054              
==========================================
+ Hits        67302    67373      +71     
- Misses       6072     6093      +21     
  Partials       42       42              
Flag Coverage Δ
conformance 34.38% <72.72%> (-0.04%) ⬇️
e2e 39.02% <72.72%> (-0.05%) ⬇️
integration 30.52% <36.36%> (-0.49%) ⬇️
rust 42.92% <ø> (ø)
unit 93.23% <100.00%> (+0.01%) ⬆️
unit-migrate 93.25% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

Comment thread authentik/root/urls.py
urlpatterns = [
path(CONFIG.get("web.path", "/")[1:], include(_urlpatterns)),
path("-/metrics/", MetricsView.as_view(), name="metrics"),
path("-/health/live/", LiveView.as_view(), name="health-live"),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer keeping this as a placeholder view (doesn't have to have any logic), just so we can be consistent with using reverse for the path

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants