Fix JWT token not refreshed when token expires between auth check and reissue middleware#67944
Open
GayathriSrividya wants to merge 3 commits into
Open
Fix JWT token not refreshed when token expires between auth check and reissue middleware#67944GayathriSrividya wants to merge 3 commits into
GayathriSrividya wants to merge 3 commits into
Conversation
Member
|
I'm initially skeptical about this. The current behaviour is to issue a new token when it is 80% through it's validity. |
ashb
requested changes
Jun 3, 2026
4c5afe1 to
5b55472
Compare
added 3 commits
June 3, 2026 23:19
When a task's JWT token expires while a request is being processed, the JWTReissueMiddleware was unable to refresh it: the strict avalidated_claims call raised ExpiredSignatureError, so no Refreshed-API-Token header was added to the response. The supervisor retries heartbeats on non-fatal errors; without a refreshed token in the response the client never updates its Bearer token, leading to consecutive 403 failures that eventually kill the task. Fix: when avalidated_claims raises ExpiredSignatureError in the reissue path, retry with a 60-second grace leeway so tokens that expired during request processing can still receive a replacement. The signature and all other claims are still fully verified; only the expiry window is relaxed in this specific code path. closes: apache#67939
5b55472 to
8c2ca2e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
closes: #67939
Problem
Long-running tasks fail with repeated 403 errors when their JWT token expires while a heartbeat request is in-flight. The race condition is:
expboundary is crossed during processing.JWTReissueMiddleware.dispatchcallsavalidated_claims(token, {})— this now raisesExpiredSignatureError.except Exceptionblock, logged as a warning, and noRefreshed-API-Tokenheader is set.Bearertoken.MAX_FAILED_HEARTBEATSconsecutive failures the supervisor kills the task.Fix
When
avalidated_claimsraisesExpiredSignatureErrorinsideJWTReissueMiddleware, retry the validation with a 60-second grace leeway (REISSUE_GRACE_LEEWAY). If the token is within that grace window its claims are extracted and a fresh replacement token is issued and returned in theRefreshed-API-Tokenresponse header.The signature and all other claims are still fully verified; only the expiry window is relaxed in this specific code path. The new token is generated from the same claims (same
sub,scope,ti_id), so there is no privilege escalation.The client's
_update_authhook already updates theBearertoken fromRefreshed-API-Tokenbefore raising on 4xx/5xx, so the next retry uses the fresh token and succeeds.Changes
airflow-core/src/airflow/api_fastapi/auth/tokens.py: addextra_leeway: float = 0keyword argument tovalidated_claimsandavalidated_claims; pass it on top ofself.leewaytojwt.decode.airflow-core/src/airflow/api_fastapi/execution_api/app.py: addREISSUE_GRACE_LEEWAY = 60class constant; catchExpiredSignatureErroron the inneravalidated_claimscall and retry with the grace leeway.airflow-core/tests/unit/api_fastapi/execution_api/versions/head/test_router.py: add regression testtest_just_expired_token_is_reissued_within_grace_period.