airflow.providers.ssh.tunnel¶
SSH tunnel implementations for the Airflow SSH provider.
This module provides SSHTunnel (sync, paramiko-based) and AsyncSSHTunnel
(async, asyncssh-based) as replacements for the removed sshtunnel.SSHTunnelForwarder.
SSHTunnel reuses an already-connected paramiko.SSHClient from
SSHHook.get_conn(), so all authentication and proxy configuration is inherited
automatically. It binds a local TCP socket and forwards connections to a remote
host/port through the SSH transport using open_channel('direct-tcpip', ...).
AsyncSSHTunnel wraps asyncssh.forward_local_port() and is intended for use
with SSHHookAsync.
Migration from sshtunnel.SSHTunnelForwarder¶
Before:
from sshtunnel import SSHTunnelForwarder
tunnel = hook.get_tunnel(remote_port=5432)
tunnel.start()
# use tunnel.local_bind_port
tunnel.stop()
After:
with hook.get_tunnel(remote_port=5432) as tunnel:
# use tunnel.local_bind_port
The .start() / .stop() methods still exist but emit deprecation warnings.
Use the context manager interface instead.
Attributes¶
Classes¶
Local port-forwarding tunnel over an existing paramiko SSH connection. |
|
Async local port-forwarding tunnel over an asyncssh SSH connection. |
Module Contents¶
- class airflow.providers.ssh.tunnel.SSHTunnel(ssh_client, remote_host, remote_port, local_port=None, logger=None)[source]¶
Local port-forwarding tunnel over an existing paramiko SSH connection.
This replaces
sshtunnel.SSHTunnelForwarderby using the SSH client’s transport directly viaopen_channel('direct-tcpip', ...).The recommended usage is as a context manager:
client = hook.get_conn() with SSHTunnel(client, "dbhost", 5432) as tunnel: connect_to_db("localhost", tunnel.local_bind_port)
- Parameters:
ssh_client (paramiko.SSHClient) – An already-connected
paramiko.SSHClient.remote_host (str) – The destination host to forward to (from the SSH server’s perspective).
remote_port (int) – The destination port to forward to.
local_port (int | None) – Local port to bind.
Nonemeans an OS-assigned ephemeral port.logger (logging.Logger | airflow.sdk.types.Logger | None) – Optional logger instance. Falls back to the module logger.
- class airflow.providers.ssh.tunnel.AsyncSSHTunnel(ssh_conn, remote_host, remote_port, local_port=None)[source]¶
Async local port-forwarding tunnel over an asyncssh SSH connection.
This wraps
asyncssh.SSHClientConnection.forward_local_port()and is intended for use withSSHHookAsync.Usage:
async with await hook.get_tunnel(remote_port=5432) as tunnel: connect_to_db("localhost", tunnel.local_bind_port)
On exit, both the forwarding listener and the underlying SSH connection are closed.
- Parameters: