Skip to content

crypto: export certificate expiry as a Prometheus metric - #27771

Merged
BeryJu merged 1 commit into
goauthentik:mainfrom
andrein:crypto-certificate-expiry-metric
Nov 12, 2026
Merged

BeryJu merged 1 commit into
goauthentik:mainfrom
andrein:crypto-certificate-expiry-metric

Conversation

@andrein

@andrein andrein commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Details

What does this PR change?

Adds authentik_crypto_certificate_expiry_timestamp_seconds, a gauge labelled with each certificate-key pair's name and kp_uuid, set from cert_expiry on every metrics request. A pair that is deleted or renamed reports NaN for 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:

authentik_crypto_certificate_expiry_timestamp_seconds - time() < 30 * 86400

Under multiprocess collection a labelset stays in the process's file until it is overwritten, so a deleted pair cannot simply disappear. 0 would read as a certificate that expired in 1970; NaN never matches a comparison, so it cannot trigger an alert.

How was this tested?

  • Unit tests in authentik/crypto/tests.py: expiry exported, deleted pair reads NaN.
  • Ran a dev image of main with this change: generated, renamed and deleted pairs and read /metrics on port 9300 after each step.
  • CI on my fork: lints and unit tests pass; image builds fail there only because the fork cannot push to the registry.

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

  • 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.

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]>
@andrein
andrein requested a review from a team as a code owner November 11, 2026 05:35
@netlify

netlify Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for authentik-integrations ready!

Name Link
🔨 Latest commit 89ef680
🔍 Latest deploy log https://app.netlify.com/projects/authentik-integrations/deploys/6af3fe9f1a5e131bc680dac0
😎 Deploy Preview https://deploy-preview-27771--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 Nov 11, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for authentik-storybook ready!

Name Link
🔨 Latest commit 89ef680
🔍 Latest deploy log https://app.netlify.com/projects/authentik-storybook/deploys/6af3fe9fd9bc224ee868b15a
😎 Deploy Preview https://deploy-preview-27771--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 Nov 11, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for authentik-docs ready!

Name Link
🔨 Latest commit 89ef680
🔍 Latest deploy log https://app.netlify.com/projects/authentik-docs/deploys/6af3fe9f7a95d3479483f01a
😎 Deploy Preview https://deploy-preview-27771--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.

@BeryJu BeryJu left a comment

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.

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

codecov Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.93%. Comparing base (bd6c49c) to head (89ef680).
⚠️ Report is 56 commits behind head on main.

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              
Flag Coverage Δ
conformance 30.38% <16.00%> (-0.01%) ⬇️
e2e 34.61% <16.00%> (-0.44%) ⬇️
integration 27.56% <16.00%> (-0.32%) ⬇️
rust 51.12% <ø> (ø)
unit 94.57% <100.00%> (+<0.01%) ⬆️
unit-migrate 94.58% <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.

@andrein

andrein commented Nov 12, 2026

Copy link
Copy Markdown
Contributor Author

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 authentik_enterprise_license_expiry_seconds is actually latest_valid - now() so I understand if you want it done that way for consistency.

I'd be happy to either update this PR to match authentik_enterprise_license_expiry_seconds or submit another PR to deprecate authentik_enterprise_license_expiry_seconds and add authentik_enterprise_license_expiry_timestamp_seconds in order to be compliant with the Prometheus guidelines.

@BeryJu

BeryJu commented Nov 12, 2026

Copy link
Copy Markdown
Member

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 authentik_enterprise_license_expiry_seconds is actually latest_valid - now() so I understand if you want it done that way for consistency.

I'd be happy to either update this PR to match authentik_enterprise_license_expiry_seconds or submit another PR to deprecate authentik_enterprise_license_expiry_seconds and add authentik_enterprise_license_expiry_timestamp_seconds in order to be compliant with the Prometheus guidelines.

yeah ok thats fair, lets keep it as timestamp then and we'll update the enterprise license expiry the same way

@BeryJu
BeryJu merged commit 1b3867a into goauthentik:main Nov 12, 2026
149 of 151 checks passed
@andrein
andrein deleted the crypto-certificate-expiry-metric branch November 12, 2026 15:21
kensternberg-authentik added a commit that referenced this pull request Nov 12, 2026
* 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)
  ...
kensternberg-authentik added a commit that referenced this pull request Nov 25, 2026
…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)
  ...
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.

2 participants