-
Notifications
You must be signed in to change notification settings - Fork 482
sftp_list not handling known_hosts correctly #3619
Description
Expected behaviour:
Successfully open a SFTP connection No hostkey for host $host found.
Actual behaviour:
Failure opening SFTP connection
Steps to reproduce:
- Step 1: Run docker container
docker build -t flexget . && docker run -v "some/path/to/flexget:/home/flexget/.flexget" -v "some/path/to/ssh:/home/flexget/.ssh" -it flexget
The root of this problem appears to be that pysftp doesn't support port numbers in known_hosts, and is also appears to be abandoned (last update made in 2016). I tried the work around of not defining the port number in known hosts, but ran into unpack requires a buffer of 4 bytes
The known_hosts file is valid, ssh-keygen -l -f ~/some/path/to/ssh/known_hosts -F $host lists the fingerprints correctly.
Apparently Paramiko on which pysftp is based doesn't have these issues, so potentilly converting sftp_client to use Paramiko directly would be a fix.
Config:
templates:
bar:
sftp_list:
host: '{? sftp.host ?}'
port: '{? sftp.port ?}'
username: '{? sftp.username ?}'
private_key: '{? sftp.private_key ?}'
recursive: True
get_size: True
files_only: False
dirs:
- "/srv/file"
tasks:
foo task:
template:
- barLog:
(click to expand)
Salient parts of the logs
With port defined in known_hosts
2022-11-29 10:55:23 DEBUG sftp_client foo task Connecting to $host
2022-11-29 10:55:23 DEBUG sftp_client foo task Caught exception: No hostkey for host $host found.
2022-11-29 10:55:23 WARNING sftp_client foo task Failed to connect to $host; waiting 15 seconds before retrying.
Without port defined 'workaround' in known_hosts
2022-11-29 10:57:27 DEBUG sftp_client foo task Connecting to $host
2022-11-29 10:57:27 DEBUG sftp_client foo task Caught exception: unpack requires a buffer of 4 bytes
2022-11-29 10:57:27 WARNING sftp_client foo task Failed to connect to$host; waiting 15 seconds before retrying.
Additional information:
- FlexGet version: 3.5.6
- Python version: 3.10.6
- Installation method: In Docker container (see below)
- Using daemon (yes/no): no
- OS and version:
- Link to crash log:
Docker container
FROM ubuntu:jammy
RUN \
echo "**** Create User ****" && \
groupadd -g 1000 flexget && \
useradd -m -g 1000 -u 1000 flexget && \
echo "**** Install Packages ****" && \
apt-get update && \
apt-get install -y \
python3-pip && \
pip3 install \
--no-cache-dir \
flexget \
pysftp && \
apt-get remove -y python3-pip && \
echo "**** Cleanup ****" && \
rm -rf /tmp/* \
/var/lib/apt/lists/* \
/var/tmp/*
# Contains config.yml
VOLUME /home/flexget/.flexget
# Contains known_hosts
VOLUME /home/flexget/.ssh
USER flexget
CMD /usr/local/bin/flexget --loglevel DEBUG execute