stegololz commented on code in PR #76353:
URL: https://github.com/apache/airflow/pull/76353#discussion_r4578123482
##########
providers/keycloak/src/airflow/providers/keycloak/auth_manager/middleware.py:
##########
@@ -82,6 +82,11 @@ async def dispatch(self, request: Request, call_next):
HTTPException,
):
new_token = ""
+ # The session ends here and the response clears the Airflow
JWT. Hide it
+ # from the inner middlewares and the route too: resolving it
again without
+ # the Keycloak tokens yields no user, which ``get_user`` would
hand to the
+ # authorization checks instead of answering 401.
+ self._drop_cookie(request, COOKIE_NAME_JWT_TOKEN)
Review Comment:
Side effect on logout: this middleware is outermost, so once `_token` is
removed from the scope the core `/auth/logout` route no longer sees it, and
`collect_request_tokens` returns nothing to revoke. Typical case: an idle user
whose Keycloak refresh token expired clicks Logout. The browser cookie is still
cleared, but the Airflow JWT is no longer added to the revoked list and stays
valid until `exp`.
Could we revoke it here before hiding it
(`get_auth_manager().revoke_token(jwt_token)` when the JWT itself is still
valid), since the session ends here anyway? A test that logout with an expired
Keycloak refresh token still revokes the jti would pin it.
Small behaviour change worth noting with this: an invalid or revoked JWT now
answers 401 "Not authenticated" instead of 403 "Invalid JWT token", because
`_refresh_user` raises 403, which lands here, and the route then sees no
cookie. 401 is arguably better for the UI, which redirects to login, but there
is no test for the `InvalidTokenError` case. Only the expired refresh token and
missing access cookie cases are covered.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]