You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Keycloak provider gives 500 on expired access token #59277
If "Other Airflow 2/3 version" selected, which one?
3.1.4
What happened?
I have the same issue described in #56614.
When i make a request to the Airflow API using a valid Airflow token that contains an expired access token from Keycloak i receive a 500 internal server error instead of 401/403 or such. I thought the issue would be fixed in 3.1.4 but apparently it is not.
What you think should happen instead?
The application should not raise an exception but it should handle it with an appropriate http response code.
How to reproduce
Create a token at /auth/token
Wait 5 minutes (or whatever the access token expiration date is) and make a request to the Airflow API using that token
Operating System
Ubuntu 24.04.1 LTS
Versions of Apache Airflow Providers
No response
Deployment
Docker-Compose
Deployment details
I use this Dockerfile to build a custom image: FROM apache/airflow:3.1.4
USER airflow
COPY requirements.txt /
RUN pip install --no-cache-dir "apache-airflow==${AIRFLOW_VERSION}" -r /requirements.txt
The package installed from requirements is apache-airflow-providers-keycloak
I am using keycloak:26.4.0
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.
The issue is slightly different here. #56614 is about UI and the issue you are describing now is related to the API. But regardless, both should work :) I'll look into it
I am not sure about this, but i think that since airflow has its own /auth/token endpoint, a request made with a valid Airflow token should be treated as valid regardless of the access_token expiration. Basically my idea was that an API (or UI) user should not care about what authentication manager is used.
I am not sure about this, but i think that since airflow has its own /auth/token endpoint, a request made with a valid Airflow token should be treated as valid regardless of the access_token expiration. Basically my idea was that an API (or UI) user should not care about what authentication manager is used.
I think this could be a problem and possibly blocking a security mitigation. Normally, a token or a session should be able to invalidated/blocked which in this case admins should be able to invaltidate a session or a token when it is leaked. If you have a token working for Airflow which is leaked, you can never invalidate unless it is expired from Keycloak. Even if we have the auth flow, if you are using an 3rd party tooling, I think we should leave the management to the tool. Otherwise it could be unmanagable and can open backdoors
Even though the issue has been automatically closed because I merged my PR we can continue the discussion whether the token should be refreshed for an API user
That's a good question - I think it also goes hand-in-hand with the discussion on token invalidation strategy that @bugraoz93 talked about. We might want to re-start the discussio on documenting and agreeing future strategies of authentication in the security team soon. I hoped to do it this week - but .. life..
I do not know to be honest. My fix makes the API return a 403 instead of a 500, that's it. It does not refresh the token. I do not think it blocks users (I might be wrong).
Activity
boring-cyborg commentedon Dec 10, 2025
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.
vincbeck commentedon Dec 10, 2025
The issue is slightly different here. #56614 is about UI and the issue you are describing now is related to the API. But regardless, both should work :) I'll look into it
vincbeck commentedon Dec 10, 2025
#59281
vincbeck commentedon Dec 10, 2025
Another question, what should be the desired behavior? Returning 403 or refreshing the token?
Ilardi commentedon Dec 10, 2025
I am not sure about this, but i think that since airflow has its own /auth/token endpoint, a request made with a valid Airflow token should be treated as valid regardless of the access_token expiration. Basically my idea was that an API (or UI) user should not care about what authentication manager is used.
bugraoz93 commentedon Dec 10, 2025
I think this could be a problem and possibly blocking a security mitigation. Normally, a token or a session should be able to invalidated/blocked which in this case admins should be able to invaltidate a session or a token when it is leaked. If you have a token working for Airflow which is leaked, you can never invalidate unless it is expired from Keycloak. Even if we have the auth flow, if you are using an 3rd party tooling, I think we should leave the management to the tool. Otherwise it could be unmanagable and can open backdoors
vincbeck commentedon Dec 10, 2025
Even though the issue has been automatically closed because I merged my PR we can continue the discussion whether the token should be refreshed for an API user
vincbeck commentedon Dec 10, 2025
To me, to be honest, we should not make a difference between a UI user and and API user. We should refresh the token in both cases
potiuk commentedon Dec 10, 2025
That's a good question - I think it also goes hand-in-hand with the discussion on token invalidation strategy that @bugraoz93 talked about. We might want to re-start the discussio on documenting and agreeing future strategies of authentication in the security team soon. I hoped to do it this week - but .. life..
potiuk commentedon Dec 10, 2025
BTW. Does it mean that we should remove KeyCloak and have rc2 ?
vincbeck commentedon Dec 10, 2025
I do not know to be honest. My fix makes the API return a 403 instead of a 500, that's it. It does not refresh the token. I do not think it blocks users (I might be wrong).
potiuk commentedon Dec 11, 2025
Yeah - not a blocker and no regression I guess