lidalei opened a new issue #16245: URL: https://github.com/apache/airflow/issues/16245
Using `private_key` in an [SFTP connection](https://airflow.apache.org/docs/apache-airflow-providers-sftp/stable/connections/sftp.html)'s extra field causes SSHException. **Apache Airflow version**: 2.0.2 **What happened**: I set an SFTP connection's private_key field to the key's path and it causes an SSHException. ``` File "airflow/providers/sftp/sensors/sftp.py", line 48, in poke self.hook = SFTPHook(self.sftp_conn_id) File "airflow/providers/sftp/hooks/sftp.py", line 66, in __init__ super().__init__(*args, **kwargs) File "airflow/providers/ssh/hooks/ssh.py", line 132, in __init__ self.pkey = paramiko.RSAKey.from_private_key(StringIO(private_key)) File "paramiko/pkey.py", line 256, in from_private_key key = cls(file_obj=file_obj, password=password) File "paramiko/rsakey.py", line 52, in __init__ self._from_private_key(file_obj, password) File "paramiko/rsakey.py", line 179, in _from_private_key data = self._read_private_key("RSA", file_obj, password) File "paramiko/pkey.py", line 324, in _read_private_key raise SSHException("not a valid {} private key file".format(tag)) ``` **What you expected to happen**: Allow us to use both key_file and private_key to in an SFTP connection or simply rename private_key to key_file. <!-- What do you think went wrong? --> SFTPHook inherits from SSHHook and SSHHook supports both private_key (content) and key_file (path). When initializing an SFTPHook, it calls super().__init__ which initializes an SSHHook. And SSHHook finds the private_key is not valid. **How to reproduce it**: ``` import os from airflow.providers.sftp.hooks.sftp import SFTPHook os.environ['AIRFLOW_CONN_SFTP'] = 'sftp://:@?private_key=/tmp/ssh' sh = SFTPHook(ftp_conn_id='sftp') ``` -- 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. For queries about this service, please contact Infrastructure at: [email protected]
