Conversation
The Papermill provider could reach remote Jupyter kernels only over raw ZMQ/TCP, which requires directly exposed kernel ports. Deployments based on JupyterHub, Jupyter Kernel Gateway, or Enterprise Gateway expose kernels through an HTTPS REST + WebSocket API secured with a token, so their users could not run notebooks on remote kernels at all. The Jupyter Kernel connection now also accepts an http(s):// URL with a token, and the notebook is executed through the gateway API in that case. This includes TLS options (verify_ssl, CA/client certificates), custom headers and timeouts, and attaching to a pre-existing kernel via a kernel_id extra. Kernel lifecycle is managed so that kernels started for a run are always shut down (even on failure) while attached kernels are never touched, and gateway credentials are scoped to a single run.
|
Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contributors' Guide
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The Papermill provider supports remote Jupyter kernels only over raw ZMQ/TCP, which requires the kernel's five ZMQ ports to be directly reachable. Deployments based on JupyterHub, Jupyter Kernel Gateway, or Enterprise Gateway instead expose kernels through an HTTPS REST + WebSocket API secured with a token, so their users cannot run notebooks on remote kernels at all.
This PR adds a second, parallel "gateway" mode to the Jupyter Kernel connection:
http(s)://URL (or theuse_gatewayextra is set), the hook returns aGatewayKernelConnectionand the notebook is executed through a new papermill engine built onjupyter_server's gateway machinery (GatewayKernelManager/GatewayKernelClient), which already implements the kernel REST + WebSocket protocol.tokenextra). Optional extras coververify_ssl(with properCERT_NONEhandling for self-signed certificates),ca_certs/client_cert/client_key,request_timeout/connect_timeout, customheaders, andkernel_idto attach to a pre-existing kernel instead of starting a new one.jupyter_server'sGatewayKernelClient.start_channels(present onmainand v2.21.0) are worked around in a small subclass: the kernel-channels WebSocket handshake is opened without the authorization/cookie headers thatload_connection_argsapplies to REST calls (any token-secured server rejects it with 403), andvalidate_cert=Falseis not honored for the WebSocket. The subclass routes the WebSocket headers throughload_connection_argsso token renewal and session cookies behave exactly as they do for REST requests.kernel_idfails fast instead of silently starting a leaked default-named kernel, and the gateway client singleton is rebuilt per run so one connection's credentials/timeouts cannot leak into another run in the same process.Includes unit tests, a system-test example Dag, and documentation for the new connection mode. The one new dependency is
jupyter_server(BSD-3-Clause, ASF Category A). Verified end-to-end against a local token-secured Jupyter Kernel Gateway over plain HTTP and over self-signed HTTPS, including attach mode and kernel-leak checks.closes: #52893
Was generative AI tooling used to co-author this PR?
Generated with AI assistance following the guidelines; all code was reviewed, statically checked, and tested locally (unit tests plus live end-to-end runs against a token-secured Jupyter Kernel Gateway).