Repository navigation
crypto: export certificate expiry as a Prometheus metric - #27771
Conversation
Adds authentik_crypto_certificate_expiry_timestamp_seconds, labelled with the certificate-key pair's name and UUID, so expiring certificates can be alerted on from the metrics endpoint. Pairs that disappear are reported as NaN, since a labelset persists under multiprocess collection and 0 would look like a certificate that has already expired. Co-Authored-By: Claude Opus 5.5 <[email protected]>
✅ Deploy Preview for authentik-integrations ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for authentik-storybook ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for authentik-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
BeryJu
left a comment
There was a problem hiding this comment.
Good idea, surprised this hasn't come up before
only thing I'm kinda on the fence about is whether the metric should be the expiry timestamp, or now() - timestamp
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #27771 +/- ##
==========================================
- Coverage 93.04% 92.93% -0.12%
==========================================
Files 1237 1237
Lines 86355 86380 +25
Branches 4894 4894
==========================================
- Hits 80350 80275 -75
- Misses 5918 6018 +100
Partials 87 87
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
|
Thanks! I'd keep the timestamp, that's what Prometheus's instrumentation guide recommends, and most of the other projects I've interacted with behave this way, so I would assume other users are familiar with this pattern (for example blackbox_exporter and cert-manager). I noticed I'd be happy to either update this PR to match |
yeah ok thats fair, lets keep it as timestamp then and we'll update the enterprise license expiry the same way |
* main: (35 commits) providers/saml: share xml signature generation (#27786) tests/openid_conformance: upload JPEG screenshots (#27749) crypto: export certificate expiry as a Prometheus metric (#27771) core: bump openapitools/openapi-generator-cli from v7.26.0 to v7.27.0 in /packages/client-ts (#27663) core: bump openapitools/openapi-generator-cli from v7.26.0 to v7.27.0 in /packages/client-rust (#27662) core: bump goauthentik/fips-debian from `d363011` to `16c391c` in /lifecycle/container (#27368) web: bump body-parser from 1.20.6 to 1.20.9 (#27521) core: bump library/node from `6d2c7d5` to `438603b` in /website (#27709) core: bump library/nginx from `5ab5b0b` to `165ddde` in /website (#27710) web: bump postcss-selector-parser from 7.1.7 to 7.2.0 in /web (#27742) web: bump glob from 13.0.6 to 13.0.7 (#27744) web: bump colord from 2.10.0 to 2.11.0 (#27745) web: bump colord from 2.10.0 to 2.11.0 in /website (#27746) root: resolve squashed migrations' dependencies (#27751) ci: add django-migration-linter (#27748) core: bump deepmerge from 3.0.1 to 4.0.0 (#27767) website/docs: Enhance reverse proxy NGINX configuration (#27774) providers/oauth2: drop the GrantTypes session alias (#27788) website/integrations: add calendarbridge (#27779) website/integrations: add onecal (#27778) ...
…t-info' into web/element/ak-event-info * refs/remotes/origin/web/element/ak-event-info: (44 commits) A spelling error? In this economy? Convert one-line functions into arrow functions. Just explaining a seemingly random export in one of the renderers. web/component: ak-event-info Broke out renderers and switched to pattern matching. Holding pattern. First: Turn the renderer switch into a _function_ web/elements: AttributeView and TreeView: Provide a multi-modal view of raw JSON or YAML information (#27687) providers/oauth2: speed up the discovery endpoint (#27696) providers/saml: share xml signature generation (#27786) tests/openid_conformance: upload JPEG screenshots (#27749) crypto: export certificate expiry as a Prometheus metric (#27771) core: bump openapitools/openapi-generator-cli from v7.26.0 to v7.27.0 in /packages/client-ts (#27663) core: bump openapitools/openapi-generator-cli from v7.26.0 to v7.27.0 in /packages/client-rust (#27662) core: bump goauthentik/fips-debian from `d363011` to `16c391c` in /lifecycle/container (#27368) web: bump body-parser from 1.20.6 to 1.20.9 (#27521) core: bump library/node from `6d2c7d5` to `438603b` in /website (#27709) core: bump library/nginx from `5ab5b0b` to `165ddde` in /website (#27710) web: bump postcss-selector-parser from 7.1.7 to 7.2.0 in /web (#27742) web: bump glob from 13.0.6 to 13.0.7 (#27744) ...
Details
What does this PR change?
Adds
authentik_crypto_certificate_expiry_timestamp_seconds, a gauge labelled with each certificate-key pair'snameandkp_uuid, set fromcert_expiryon every metrics request. A pair that is deleted or renamed reportsNaNfor its old labels.Why is this change needed?
Expiring SAML/OIDC signing certificates currently have to be tracked outside authentik. With the expiry exported, an alert is one rule:
Under multiprocess collection a labelset stays in the process's file until it is overwritten, so a deleted pair cannot simply disappear.
0would read as a certificate that expired in 1970;NaNnever matches a comparison, so it cannot trigger an alert.How was this tested?
authentik/crypto/tests.py: expiry exported, deleted pair readsNaN.mainwith this change: generated, renamed and deleted pairs and read/metricson port 9300 after each step.Linked issues
refs #27772: without it, a pair deleted just before a container restart keeps its old expiry.
AI disclosure: written with Claude Code (Claude Opus 5.5), which drafted the code, tests and this description; I reviewed, ran and tested the change myself.
Checklist
make all)make docs)