Skip to content

blueprints: reapply when !Env values change and key the hashed values - #26932

Open
dominic-r wants to merge 5 commits into
mainfrom
dominic/blueprint-hash-external-values
Open

dominic-r wants to merge 5 commits into
mainfrom
dominic/blueprint-hash-external-values

Conversation

@dominic-r

@dominic-r dominic-r commented Oct 14, 2026 •

Copy link
Copy Markdown
Member

Details

What does this PR change?

The blueprint hash used by discovery and stored in last_applied_hash now also covers the current values of a blueprint's !Env tags, so discovery reapplies a blueprint when one of those variables changes. #26402 already does this for !File contents in blueprints/v1/hash.py. This PR extends that walk to !Env tags and changes how the values are folded in: instead of adding a plain sha512 of each value, all !Env and !File values go through one HMAC keyed with the secret key (salted_hmac), which is then added to the sha512 of the blueprint content.

The blueprints overview in the docs now mentions that !Env and !File value changes trigger a reapply.

Why is this change needed?

A blueprint that reads a secret through !Env was never reapplied when only that variable changed, for example after a rotation. It kept the old value until the file was edited or the blueprint was applied by hand.

The values are never stored, but last_applied_hash is visible in the API, and a plain hash of a short secret can be brute-forced. That applies to the !File digests added in #26402 as well, so they're keyed too.

Blueprints without !Env or !File tags keep their current hash, so upgrading doesn't reapply them. Blueprints that use these tags are reapplied once after the upgrade, and again whenever the secret key changes. This includes blueprints whose variables are unset, such as the default ones that use !Env with a default. An unset variable, like a missing file, takes a placeholder in the hash so its position still counts.

A !File path outside the blueprints directory isn't watched, and environment variable changes don't produce file events, so these changes are picked up by the next scheduled discovery run. It runs hourly and on startup.

How was this tested?

  • Added a test that discovers a blueprint using !Env and !File and runs discovery again with the same values to check the hash is unchanged. It then changes the environment variable and the file in turn and checks that each change reapplies the blueprint with a new hash. Without the !Env handling it fails at the environment variable change.
  • Added an !Env key with a lone surrogate and one with a null byte to the cases that must not stop other blueprints from being discovered. Without a guard, the surrogate makes getenv raise and discovery aborts.
  • Updated the existing test that pins the exact digest for an aliased !File to the keyed digest. All other !File tests from blueprints: re-apply when a file referenced by !File changes #26402 pass unchanged.
  • Ran the blueprints tests locally after merging main; they all pass.
  • I did not test this with a real rotated secret on a running instance, and I did not build the docs site.

Linked issues

closes #26925


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.

The values are keyed with the secret key before they go into the hash, since
the hash is visible in the API and a plain hash of a short secret could be
guessed. Blueprints without these tags keep their current hash.

Closes: #26925
@dominic-r
dominic-r requested a review from a team as a code owner October 14, 2026 19:34
@dominic-r
dominic-r requested a review from a team as a code owner October 14, 2026 19:35
@codecov

codecov Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.36066% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 92.40%. Comparing base (7ff197b) to head (9b02d89).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
authentik/blueprints/v1/hash.py 96.66% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main   #26932   +/-   ##
=======================================
  Coverage   92.40%   92.40%           
=======================================
  Files        1191     1191           
  Lines       80332    80376   +44     
  Branches     4351     4351           
=======================================
+ Hits        74227    74271   +44     
  Misses       6039     6039           
  Partials       66       66           
Flag Coverage Δ
conformance 32.31% <8.19%> (-0.02%) ⬇️
e2e 36.98% <8.19%> (-0.02%) ⬇️
integration 29.19% <8.19%> (-0.02%) ⬇️
rust 44.42% <ø> (ø)
unit 94.05% <98.36%> (+<0.01%) ⬆️
unit-migrate 94.05% <98.36%> (+<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.

@netlify

netlify Bot commented Oct 14, 2026

Copy link
Copy Markdown

✅ Deploy Preview for authentik-docs ready!

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

@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Playwright e2e

Download this run's HTML report and traces, then open the report:

gh run download 40248406219 -D playwright-artifacts
npx playwright show-report playwright-artifacts/playwright-report

Installation instructions

Instructions for docker-compose

Add the following block to your .env file:

AUTHENTIK_IMAGE=ghcr.io/goauthentik/dev-server
AUTHENTIK_TAG=gh-9b02d8921ea9a5f3a7f994f64aa88aee7cce6f30
# Distroless image: AUTHENTIK_TAG=gh-9b02d8921ea9a5f3a7f994f64aa88aee7cce6f30-distroless
AUTHENTIK_OUTPOSTS__CONTAINER_IMAGE_BASE=ghcr.io/goauthentik/dev-%(type)s:gh-%(build_hash)s

Afterwards, run the upgrade commands from the latest release notes.

Instructions for Kubernetes

Add the following block to your values.yml file:

authentik:
    outposts:
        container_image_base: ghcr.io/goauthentik/dev-%(type)s:gh-%(build_hash)s
global:
    image:
        repository: ghcr.io/goauthentik/dev-server
        tag: gh-9b02d8921ea9a5f3a7f994f64aa88aee7cce6f30
        # Distroless image: tag: gh-9b02d8921ea9a5f3a7f994f64aa88aee7cce6f30-distroless

Afterwards, run the upgrade commands from the latest release notes.

@dominic-r dominic-r self-assigned this Oct 14, 2026
@dominic-r dominic-r added area:backend area:docs Features or issues related to Docusaurus labels Oct 14, 2026
main now hashes the contents of `!File` references in
blueprints/v1/hash.py, which overlaps with this branch's own hashing in
tasks.py. Keep main's implementation and its edge-case handling, and
extend it to `!Env` values instead of keeping both.

The referenced values now go through one HMAC keyed with the secret key
rather than being folded in as plain digests, since the hash is visible
in the API and a plain digest of a short secret can be brute-forced.
Blueprints without resolvable tags keep their plain content hash.
@dominic-r dominic-r changed the title blueprints: reapply when !Env or !File values change blueprints: reapply when !Env values change and key the hashed values Oct 15, 2026

This branch has not been deployed

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

Labels

area:backend area:docs Features or issues related to Docusaurus

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

Blueprints aren't reapplied when only their !Env or !File values change

2 participants