Repository navigation
Description
Under which category would you file this issue?
Providers
Apache Airflow version / provider version
Apache Airflow 3.3.0 with apache-airflow-providers-keycloak==0.8.1. The same _is_authorized 400 path is still present on provider 0.10.0 and on main.
What happened and how to reproduce it?
Issue Description
POST /auth/token with client_credentials returns an Airflow JWT whose exp follows [api_auth] jwt_expiration_time (default 24h). The Keycloak access token nested in that session still expires on Keycloak’s accessTokenLifespan (often 1h). Service-account tokens have no refresh token (refresh_user returns None).
After the inner Keycloak bearer expires, API calls such as POST /api/v2/dags/{dag_id}/dagRuns still present a valid Airflow JWT. Authorization then calls Keycloak’s UMA ticket grant (grant_type=urn:ietf:params:oauth:grant-type:uma-ticket) with that expired bearer.
Keycloak answers HTTP 400:
{"error":"invalid_grant","error_description":"Invalid bearer token"}KeycloakAuthManager._is_authorized only maps:
Any other 400, including invalid_grant, does:
raise AirflowException(
f"Request not recognized by Keycloak. {error.get('error')}. {error.get('error_description')}"
)Starlette/FastAPI turns that unhandled exception into HTTP 500. Clients that remint only on 401/403 keep retrying the dead token and stay in a 500 loop until they mint a new Airflow JWT.
This is distinct from #59359 / #59361 (UI refresh_user when the refresh token is dead) and from #59277 (401 path only). Keycloak often returns 400, not 401, for this UMA grant.
Steps to reproduce
- Configure Airflow 3.3+ with
KeycloakAuthManager. - Set Keycloak client/realm
accessTokenLifespanshorter than[api_auth] jwt_expiration_time(e.g. 60s vs 24h). POST /auth/tokenwithgrant_type=client_credentials.- Wait until the Keycloak access token expires but the Airflow JWT is still valid.
POST /api/v2/dags/{dag_id}/dagRunswithAuthorization: Bearer <airflow-jwt>.
Observed: API 500, api-server log AirflowException: Request not recognized by Keycloak. invalid_grant. Invalid bearer token. Keycloak event PERMISSION_TOKEN_ERROR / invalid_token on uma-ticket.
Still true on current main in _is_authorized / _is_batch_authorized:
What you think should happen instead?
Treat UMA 400 invalid_grant the same as 401: deny (return False / empty set) so the API returns 403 (or 401), not 500. Callers can then remint.
Refreshing/reminting the nested Keycloak token for client_credentials would be a larger follow-up. Mapping invalid_grant to unauthorized is the same class of fix as #59281.
Operating System
Linux (Kubernetes)
Deployment
Official Apache Airflow Helm Chart
Apache Airflow Provider(s)
keycloak
Versions of Apache Airflow Providers
apache-airflow-providers-keycloak==0.8.1 (also unfixed in 0.10.0 and main)
Official Helm Chart version
Not Applicable
Kubernetes Version
Not Applicable
Helm Chart configuration
Not Applicable
Docker Image customizations
Not Applicable
Anything else?
Related:
- #59277 / #59281 — 401 → 403; does not cover Keycloak 400
invalid_grant - #56614 — UI 500 on expired access token
- #59359 —
refresh_userKeycloakPostErroron dead refresh token - #69028 — 400
invalid_resourceonly
I am submitting a PR that maps invalid_grant to deny in _is_authorized and _is_batch_authorized.
Are you willing to submit PR?
- Yes I am willing to submit a PR!
Code of Conduct
- I agree to follow this project's Code of Conduct
Activity
boring-cyborg commentedon Sep 16, 2026
Thanks for opening your first issue here! Be sure to follow the issue template! If you are willing to raise PR to address this issue please do so, no need to wait for approval.
Return 403 when Keycloak UMA ticket grant returns invalid_grant (apac…