You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by as...@apache.org on 2025/08/13 11:08:02 UTC

(airflow) branch v3-0-test updated: [v3-0-test] Explicitly set the JWTGenerator private_key field to None for service logs retrieval (#54442) (#54444)

This is an automated email from the ASF dual-hosted git repository.

ash pushed a commit to branch v3-0-test
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/v3-0-test by this push:
     new 2d12289975d [v3-0-test] Explicitly set the JWTGenerator private_key field to None for service logs retrieval (#54442) (#54444)
2d12289975d is described below

commit 2d12289975d01c521ce607b9a9eadb18afa74bcb
Author: github-actions[bot] <41...@users.noreply.github.com>
AuthorDate: Wed Aug 13 12:07:55 2025 +0100

    [v3-0-test] Explicitly set the JWTGenerator private_key field to None for service logs retrieval (#54442) (#54444)
    
    In a recent change, the private_key parameter is left empty when instantiating the JWTGenerator used to authenticate log serving requests for in-progress tasks. Such requests use the shared secret_key instead. However, leaving private_key unset means that it is automatically populated through the attrs field factory and this leads to a failure in the post init which asserts mutual exclusivity of secret_key and private_key. The result is stack traces in the API Server logs like the fol [...]
    
    ```
    [2025-08-12T19:33:59.403+0000] {file_task_handler.py:907} ERROR - Could not read served logs
    Traceback (most recent call last):
      File "/usr/local/lib/python3.12/site-packages/airflow/utils/log/file_task_handler.py", line 878, in _read_from_logs_server
        response = _fetch_logs_from_service(url, rel_path)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/local/lib/python3.12/site-packages/airflow/utils/log/file_task_handler.py", line 173, in _fetch_logs_from_service
        generator = JWTGenerator(
                    ^^^^^^^^^^^^^
      File "<attrs generated methods airflow.api_fastapi.auth.tokens.JWTGenerator>", line 34, in __init__
        self.__attrs_post_init__()
      File "/usr/local/lib/python3.12/site-packages/airflow/api_fastapi/auth/tokens.py", line 417, in __attrs_post_init__
        raise ValueError("Exactly one of private_key and secret_key must be specified")
    ValueError: Exactly one of private_key and secret_key must be specified
    ```
    
    The fix is to add back the explicit `private_key=None`, for which we have to add a mypy type ignore comment as it does not seem to understand that `None` is allowed for `AllowedPrivateKeys | None`.
    (cherry picked from commit 4fa0d01d047f7dd9b43fa2041729228010eaa3bc)
    
    Co-authored-by: Ian Buss <ia...@users.noreply.github.com>
---
 airflow-core/src/airflow/utils/log/file_task_handler.py | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/airflow-core/src/airflow/utils/log/file_task_handler.py b/airflow-core/src/airflow/utils/log/file_task_handler.py
index 37149b05d6c..062ea4a7603 100644
--- a/airflow-core/src/airflow/utils/log/file_task_handler.py
+++ b/airflow-core/src/airflow/utils/log/file_task_handler.py
@@ -174,6 +174,9 @@ def _fetch_logs_from_service(url: str, log_relative_path: str) -> Response:
         secret_key=get_signing_key("api", "secret_key"),
         # Since we are using a secret key, we need to be explicit about the algorithm here too
         algorithm="HS512",
+        # We must set an empty private key here as otherwise it can be automatically loaded by JWTGenerator
+        # and secret_key and private_key cannot be set together
+        private_key=None,  #  type: ignore[arg-type]
         issuer=None,
         valid_for=conf.getint("webserver", "log_request_clock_grace", fallback=30),
         audience="task-instance-logs",