Skip to content

Keycloak provider gives 500 on expired access token #59277

Closed

Description

@Ilardi

Apache Airflow version

Other Airflow 2/3 version (please specify below)

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

  1. Create a token at /auth/token
  2. 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

Anything else?

No response

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Activity

  1. added
    kind:bug
    needs-triage
    on Dec 10, 2025
  2. boring-cyborg commented on Dec 10, 2025

    @boring-cyborg

    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.

  3. vincbeck commented on Dec 10, 2025

    @vincbeck
    Contributor

    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

  4. removed
    needs-triage
    on Dec 10, 2025
  5. vincbeck commented on Dec 10, 2025

    @vincbeck
    Contributor
  6. vincbeck commented on Dec 10, 2025

    @vincbeck
    Contributor

    Another question, what should be the desired behavior? Returning 403 or refreshing the token?

  7. Ilardi commented on Dec 10, 2025

    @Ilardi
    Author

    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.

  8. bugraoz93 commented on Dec 10, 2025

    @bugraoz93
    Contributor

    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

  9. vincbeck commented on Dec 10, 2025

    @vincbeck
    Contributor

    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

  10. vincbeck commented on Dec 10, 2025

    @vincbeck
    Contributor

    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

  11. potiuk commented on Dec 10, 2025

    @potiuk
    Member

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

  12. potiuk commented on Dec 10, 2025

    @potiuk
    Member

    BTW. Does it mean that we should remove KeyCloak and have rc2 ?

  13. vincbeck commented on Dec 10, 2025

    @vincbeck
    Contributor

    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).

  14. potiuk commented on Dec 11, 2025

    @potiuk
    Member

    Yeah - not a blocker and no regression I guess

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:APIarea:autharea:corekind:bugprovider:keycloak

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions