Skip to content

root: implement liveness endpoint in a middleware - #25598

Merged
BeryJu merged 5 commits into
goauthentik:mainfrom
severin:core/liveness-probes-without-db
Sep 11, 2026
Merged

BeryJu merged 5 commits 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 b440e53
🔍 Latest deploy log https://app.netlify.com/projects/authentik-storybook/deploys/6aa3ad5244848f00082cdb59
😎 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 b440e53
🔍 Latest deploy log https://app.netlify.com/projects/authentik-integrations/deploys/6aa3ad521c93a600083408c3
😎 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 b440e53
🔍 Latest deploy log https://app.netlify.com/projects/authentik-docs/deploys/6aa3ad52a399d50008e835a7
😎 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.84%. Comparing base (7faf59c) to head (74ea864).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #25598      +/-   ##
==========================================
- Coverage   91.87%   91.84%   -0.04%     
==========================================
  Files        1170     1170              
  Lines       75514    75520       +6     
  Branches     4054     4054              
==========================================
- Hits        69381    69361      -20     
- Misses       6091     6117      +26     
  Partials       42       42              
Flag Coverage Δ
conformance 33.76% <75.00%> (+<0.01%) ⬆️
e2e 38.43% <75.00%> (+<0.01%) ⬆️
integration 30.01% <33.33%> (-0.45%) ⬇️
rust 42.92% <ø> (ø)
unit 93.43% <100.00%> (+<0.01%) ⬆️
unit-migrate 93.45% <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 Resolved
@severin
severin marked this pull request as ready for review September 11, 2026 06:50
@severin
severin requested review from a team as code owners September 11, 2026 06:50
Signed-off-by: Jens Langhammer <[email protected]>
Signed-off-by: Jens Langhammer <[email protected]>
@BeryJu
BeryJu merged commit d2ce018 into goauthentik:main Sep 11, 2026
229 of 231 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants