Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 9 additions & 12 deletions providers/sftp/src/airflow/providers/sftp/hooks/sftp.py
Original file line number Diff line number Diff line change
Expand Up @@ -718,19 +718,16 @@ def _parse_extras(self, conn: Connection) -> None:
self.private_key = extra_options["private_key"]

host_key = extra_options.get("host_key")
no_host_key_check = extra_options.get("no_host_key_check")

if no_host_key_check is not None:
no_host_key_check = str(no_host_key_check).lower() == "true"
if host_key is not None and no_host_key_check:
raise ValueError("Host key check was skipped, but `host_key` value was given")
if no_host_key_check:
self.log.warning(
"No Host Key Verification. This won't protect against Man-In-The-Middle attacks"
)
self.known_hosts = "none"
nhkc_raw = extra_options.get("no_host_key_check")
no_host_key_check = True if nhkc_raw is None else (str(nhkc_raw).lower() == "true")

if host_key is not None and no_host_key_check:
raise ValueError("Host key check was skipped, but `host_key` value was given")

if host_key is not None:
if no_host_key_check:
self.log.warning("No Host Key Verification. This won't protect against Man-In-The-Middle attacks")
self.known_hosts = "none"
elif host_key is not None:
self.known_hosts = f"{conn.host} {host_key}".encode()

async def _get_conn(self) -> asyncssh.SSHClientConnection:
Expand Down
3 changes: 2 additions & 1 deletion providers/sftp/tests/unit/sftp/hooks/test_sftp.py
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,7 @@ async def test_extra_dejson_fields_for_connection_building(self, mock_get_connec
"username": "username",
"password": "password",
"client_keys": "~/keys/my_key",
"known_hosts": "~/.ssh/known_hosts",
"known_hosts": None,
"passphrase": "mypassphrase",
}

Expand Down Expand Up @@ -882,6 +882,7 @@ async def test_connection_private(self, mock_get_connection, mock_import_private
"username": "username",
"password": "password",
"client_keys": ["test"],
"known_hosts": None,
"passphrase": "mypassphrase",
}

Expand Down
Loading