Airflow SFTPHook transport.py Authentication (password) failed using Private Key #31318
-
Apache Airflow versionOther Airflow 2 version (please specify below) What happenedI am running Airflow v2.3.2 / Python 3.10 from the Docker Image below.
The Docker Image has set When calling the sftp, I am using the following: I have also tried it without the In the Connections within the Airflow UI, I have configured the Extra section as follows: When I test the connection within the UI, it reports Connection successfully tested. However, when the script that calls the Hook runs, I receive the following: I have also attempted to pass the "host_key" in the Extras field but get the same Authentication error. To be explicit, I have tried the following -
Referenced SO questions - Additional Logging from Paramiko - What you think should happen insteadAuthentication should verify and allow for the SFTPHook to perform as expected. How to reproduceNeeds to be on a deployed version of Airflow or Docker Container not containing the ~/.ssh/known_hosts
Operating Systemapache/airflow:2.3.2-python3.10 Versions of Apache Airflow Providersapache-airflow-providers-sftp==4.2.4 DeploymentOther 3rd-party Helm chart Deployment detailsNo response Anything elseNo response Are you willing to submit PR?
Code of Conduct
|
Beta Was this translation helpful? Give feedback.
Replies: 8 comments 4 replies
-
|
Thanks for opening your first issue here! Be sure to follow the issue template! If you are willing to raise PR to address this issue please do so, no need to wait for approval. |
Beta Was this translation helpful? Give feedback.
-
|
Was the public key of the key pair uploaded on the SFTP server? |
Beta Was this translation helpful? Give feedback.
-
|
You have not explained that in your report so let me ask - is you DAG failing? Or is only abou the message you see? Do you ACTUALLY see an error message or things not working? FWIW any ssh authentication tries out different authentication mechanisms and you can even sometimes decide usually which one should be used - so is your conection and DAG not working, or you are worrying about INFO level from Paramiko when the Password method fails? Do you see failure message and was there an attempt to authenticate with teh private key of yours made? What are the logs for that? If there is no error and the problem is the message and you would like the info message to not appear there, then you should direct your question to Paramiko not to Airflow. If there is an error - could you please show the error messages that you see and the authentication attempt made with the private key? |
Beta Was this translation helpful? Give feedback.
-
|
BTW. Can you also try more recent provider? 2.3.2 is pretty old - check your provider version and see in the released notes for SSH and https://airflow.apache.org/docs/apache-airflow-providers-ssh/stable/index.html and SFTP provider if there are no similar problems, upgrade to the latest versions you can and see if that helps (and report it back here) |
Beta Was this translation helpful? Give feedback.
-
Do you mean aside from adding the |
Beta Was this translation helpful? Give feedback.
-
Please find some theory below for public-private key pair authentication as I believe you're missing to add the public key on the SFTP server.
The security of this authentication method relies on the fact that the private key is kept secret and cannot be derived from the corresponding public key. The server trusts that if someone possesses the private key and can sign the challenge correctly, they must be the legitimate user who owns the private key. By using public-key authentication, SSH offers a more secure alternative to password-based authentication, as it eliminates the need to transmit and store passwords on the server. how to store public key?
And with this, when you specify your private_key in the Airflow connection, the connection should be successful. |
Beta Was this translation helpful? Give feedback.
-
|
I am converting this to a discussion as it does not seem to be an issue at this point time. If after following all the steps, you still feel this is an issue, please let me know and I will convert it back to an issue. |
Beta Was this translation helpful? Give feedback.
-
|
@pankajkoti - just wanted to clarify the below - The SFTP Server already has the public key and be be connected to using the private key (verified both using CyberDuck as well as a locally running version of Airflow). Even on the hosted version of Airflow, in the |
Beta Was this translation helpful? Give feedback.
Hey @pankajkoti - I ended up changing it to not use the SFTPHook and got it to work.