You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "potiuk (via GitHub)" <gi...@apache.org> on 2026/09/07 16:08:03 UTC

[PR] Revoke every credential presented to the Core API logout endpoint [airflow]

potiuk opened a new pull request, #72649:
URL: https://github.com/apache/airflow/pull/72649

   The Core API logout endpoint read only the `_token` cookie.
   
   A client authenticating with an `Authorization: Bearer` header — the documented
   way to call the Core API — therefore received a normal logout response while its
   token was never revoked. The token stayed valid until it expired; the default
   lifetime is 24 hours and is configurable.
   
   The practical effect is that a copy of the token held by anyone else survives the
   holder's logout: asking to be logged out did not end the session it was presented
   for.
   
   ### The change
   
   * `get_user()`'s credential selection is extracted into `select_request_token()`
     and shared, so authentication and logout agree on what a request's credential
     is instead of each hard-coding a choice.
   * Logout uses `collect_request_tokens()` and revokes **all** credentials
     presented, not just the precedence-selected one. Revoking only the winner would
     leave any other credential the caller presented valid after they asked to be
     logged out — and which credential wins is a question about *authentication*
     that should not decide what a *logout* terminates.
   * Revocation still happens before any redirect or cookie deletion, so an external
     auth-manager logout URL cannot skip it.
   
   The refactor is behaviour-preserving for `get_user()`: the trusted-middleware
   shortcut is untouched and the same precedence (bearer → OAuth token → cookie)
   applies after it.
   
   ### Tests
   
   Bearer-only logout, bearer plus cookie together, bearer before an external
   redirect, and revocation when a user has been cached by `JWTRefreshMiddleware`
   (so the trusted-user shortcut cannot cause logout to skip revocation).
   
   Against unpatched sources the bearer tests fail with `assert False is True` —
   the token is simply not revoked. The existing cookie tests are unchanged and
   still pass, as do the 129 tests in `test_security.py` plus this file.
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   - [X] Yes (please specify the tool below)
   
   Generated-by: Claude Code following [the guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)
   


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Revoke every credential presented to the Core API logout endpoint [airflow]

Posted by "pierrejeambrun (via GitHub)" <gi...@apache.org>.
pierrejeambrun commented on code in PR #72649:
URL: https://github.com/apache/airflow/pull/72649#discussion_r3979933186


##########
airflow-core/src/airflow/api_fastapi/core_api/routes/public/auth.py:
##########
@@ -57,11 +64,21 @@ def login(request: Request, auth_manager: AuthManagerDep, next: None | str = Non
     "/logout",
     responses=create_openapi_http_exception_doc([status.HTTP_307_TEMPORARY_REDIRECT]),
 )
-def logout(request: Request, auth_manager: AuthManagerDep) -> RedirectResponse:
+def logout(
+    request: Request,
+    auth_manager: AuthManagerDep,
+    oauth_token: str | None = Depends(oauth2_scheme),
+    bearer_credentials: HTTPAuthorizationCredentials | None = Depends(bearer_scheme),

Review Comment:
   both `oauth_token` and `beaerer_credentials` read the same header and only one need invalidation I believe.
   
   But that follows the same pattern as `get_user` I assume. 
   
   Not worth blocking but I'll open a PR to fix that.



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Revoke every credential presented to the Core API logout endpoint [airflow]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #72649:
URL: https://github.com/apache/airflow/pull/72649#issuecomment-5632459702

   ### Backport successfully created: v3-3-test
   
   Note: As of [Merging PRs targeted for Airflow 3.X](https://github.com/apache/airflow/blob/main/dev/README_AIRFLOW3_DEV.md#merging-prs-targeted-for-airflow-3x)
   the committer who merges the PR is responsible for backporting the PRs that are bug fixes (generally speaking) to the maintenance branches.
   
   In matter of doubt please ask in [#release-management](https://apache-airflow.slack.com/archives/C03G9H97MM2) Slack channel.
   
   <table>
           <tr>
           <th>Status</th>
           <th>Branch</th>
           <th>Result</th>
       </tr>
       <tr>
           <td>✅</td>
           <td>v3-3-test</td>
           <td><a href="https://github.com/apache/airflow/pull/72933"><img src="https://img.shields.io/badge/PR-72933-blue" alt="PR Link"></a></td>
       </tr>
   </table>


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Revoke every credential presented to the Core API logout endpoint [airflow]

Posted by "vatsrahul1001 (via GitHub)" <gi...@apache.org>.
vatsrahul1001 merged PR #72649:
URL: https://github.com/apache/airflow/pull/72649


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Revoke every credential presented to the Core API logout endpoint [airflow]

Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk commented on PR #72649:
URL: https://github.com/apache/airflow/pull/72649#issuecomment-5614791455

   Would love that one approved :)


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Revoke every credential presented to the Core API logout endpoint [airflow]

Posted by "pierrejeambrun (via GitHub)" <gi...@apache.org>.
pierrejeambrun commented on code in PR #72649:
URL: https://github.com/apache/airflow/pull/72649#discussion_r3979946524


##########
airflow-core/src/airflow/api_fastapi/core_api/routes/public/auth.py:
##########
@@ -57,11 +64,21 @@ def login(request: Request, auth_manager: AuthManagerDep, next: None | str = Non
     "/logout",
     responses=create_openapi_http_exception_doc([status.HTTP_307_TEMPORARY_REDIRECT]),
 )
-def logout(request: Request, auth_manager: AuthManagerDep) -> RedirectResponse:
+def logout(
+    request: Request,
+    auth_manager: AuthManagerDep,
+    oauth_token: str | None = Depends(oauth2_scheme),
+    bearer_credentials: HTTPAuthorizationCredentials | None = Depends(bearer_scheme),
+) -> RedirectResponse:
     """Logout the user."""
-    # Revoke the current token before any redirect or cookie deletion so the JWT
-    # is invalidated even when the auth manager redirects to an external logout URL.
-    if token_str := request.cookies.get(COOKIE_NAME_JWT_TOKEN):
+    # Revoke every credential presented before any redirect or cookie deletion, so the
+    # JWT is invalidated even when the auth manager redirects to an external logout URL.
+    #
+    # This previously read only the `_token` cookie. A client that authenticates with an
+    # `Authorization: Bearer` header -- the documented way to call the API -- therefore
+    # got a successful logout response while its token was never revoked, and the token
+    # stayed valid until it expired.

Review Comment:
   I would remove this. Very verbose for no reason.
   
   "Invalidate both tokens cotains in cookies and authorization headers if present" or something like this.



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Revoke every credential presented to the Core API logout endpoint [airflow]

Posted by "pierrejeambrun (via GitHub)" <gi...@apache.org>.
pierrejeambrun commented on code in PR #72649:
URL: https://github.com/apache/airflow/pull/72649#discussion_r3987818066


##########
airflow-core/src/airflow/api_fastapi/core_api/routes/public/auth.py:
##########
@@ -57,11 +64,21 @@ def login(request: Request, auth_manager: AuthManagerDep, next: None | str = Non
     "/logout",
     responses=create_openapi_http_exception_doc([status.HTTP_307_TEMPORARY_REDIRECT]),
 )
-def logout(request: Request, auth_manager: AuthManagerDep) -> RedirectResponse:
+def logout(
+    request: Request,
+    auth_manager: AuthManagerDep,
+    oauth_token: str | None = Depends(oauth2_scheme),
+    bearer_credentials: HTTPAuthorizationCredentials | None = Depends(bearer_scheme),
+) -> RedirectResponse:
     """Logout the user."""
-    # Revoke the current token before any redirect or cookie deletion so the JWT
-    # is invalidated even when the auth manager redirects to an external logout URL.
-    if token_str := request.cookies.get(COOKIE_NAME_JWT_TOKEN):
+    # Revoke every credential presented before any redirect or cookie deletion, so the
+    # JWT is invalidated even when the auth manager redirects to an external logout URL.
+    #
+    # This previously read only the `_token` cookie. A client that authenticates with an
+    # `Authorization: Bearer` header -- the documented way to call the API -- therefore
+    # got a successful logout response while its token was never revoked, and the token
+    # stayed valid until it expired.

Review Comment:
   I'll do that in the follow up PR. too 
   



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Revoke every credential presented to the Core API logout endpoint [airflow]

Posted by "pierrejeambrun (via GitHub)" <gi...@apache.org>.
pierrejeambrun commented on code in PR #72649:
URL: https://github.com/apache/airflow/pull/72649#discussion_r3987816859


##########
airflow-core/src/airflow/api_fastapi/core_api/routes/public/auth.py:
##########
@@ -57,11 +64,21 @@ def login(request: Request, auth_manager: AuthManagerDep, next: None | str = Non
     "/logout",
     responses=create_openapi_http_exception_doc([status.HTTP_307_TEMPORARY_REDIRECT]),
 )
-def logout(request: Request, auth_manager: AuthManagerDep) -> RedirectResponse:
+def logout(
+    request: Request,
+    auth_manager: AuthManagerDep,
+    oauth_token: str | None = Depends(oauth2_scheme),
+    bearer_credentials: HTTPAuthorizationCredentials | None = Depends(bearer_scheme),

Review Comment:
   https://github.com/apache/airflow/pull/72889



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org