Skip to content

Add KeycloakJWTMiddleware to KeycloakAuthManager - #70800

Merged
potiuk merged 1 commit into
apache:mainfrom
stephen-bracken:keycloak-jwt-middleware
Aug 2, 2026
Merged

Add KeycloakJWTMiddleware to KeycloakAuthManager#70800
potiuk merged 1 commit into
apache:mainfrom
stephen-bracken:keycloak-jwt-middleware

Conversation

@stephen-bracken

@stephen-bracken stephen-bracken commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

related: #70550 - adds access_token and refresh_token to user correctly

Add KeycloakJWTMiddleware to KeycloakAuthManager

  • Add KeycloakJWTMiddleware to the KeycloakAuthManager to extract Keycloak JWT tokens from the request cookies and attach them to the user during auth requests.
  • Pass Keycloak JWTs to get_user_from_token() in KeycloakJWTMiddleware, skip refreshing user when called in JWTRefreshMiddleware without the access_token and refresh_token parameters

Rename Keycloak JWT session cookies from access_token and refresh_token to _access_token and _refresh_token for consistency. Since the JWT cookies change is not yet released, this is safe to change.

Note: This change will logout any existing sessions for the KeycloakAuthManager, which should then be handled gracefully by issuing a new Airflow JWT token from the Keycloak login route.

Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)
  • No

@stephen-bracken
stephen-bracken force-pushed the keycloak-jwt-middleware branch 12 times, most recently from 87764ef to 40f0199 Compare July 31, 2026 17:32
@stephen-bracken
stephen-bracken marked this pull request as ready for review July 31, 2026 18:21
@vincbeck

Copy link
Copy Markdown
Contributor

Why do we need a config here?

@stephen-bracken

Copy link
Copy Markdown
Contributor Author

I thought I would make the new JWT management an opt-in feature initially, I can take out the config if you don't think its necessary

@vincbeck

Copy link
Copy Markdown
Contributor

Yeah I think it would be better without config. That creates complexity

@stephen-bracken
stephen-bracken force-pushed the keycloak-jwt-middleware branch 10 times, most recently from d34f246 to 526606a Compare August 1, 2026 16:02
@stephen-bracken
stephen-bracken force-pushed the keycloak-jwt-middleware branch 3 times, most recently from ba60d88 to 468c907 Compare August 1, 2026 17:26

@potiuk potiuk 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.

Reviewed the middleware end to end. The refresh flow reads well, the version-compat guard is used consistently in both source and tests, and the thirteen tests cover the cases I would want — refresh, expiry, missing Airflow JWT, missing Keycloak token, and root-cookie clearing.

I also checked the earlier discussion about the config: that has been handled. There is no provider.yaml change, no CONF_*_KEY, and no toggle wording left, so the opt-in has genuinely gone rather than moved somewhere else.

Three things below, one of which I would like resolved before merge.

Separately, and not inline-able: the PR description is still the unedited template. For a change of this size that renames session cookies in an auth manager, the reasoning behind the rename is exactly what a reviewer needs, and this body becomes the squash commit message and the raw material for the changelog. Worth a few lines.


Drafted-by: Claude Code (Opus 5); reviewed by @potiuk before posting

Comment thread providers/keycloak/src/airflow/providers/keycloak/auth_manager/middleware.py Outdated
@stephen-bracken
stephen-bracken force-pushed the keycloak-jwt-middleware branch from 468c907 to bc5806c Compare August 1, 2026 22:16
@stephen-bracken
stephen-bracken force-pushed the keycloak-jwt-middleware branch from bc5806c to 822e24b Compare August 1, 2026 22:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants