使用paramiko和sshtunnel与docker alpine的libssl问题

时间:2018-12-06 17:02:39

标签: python docker paramiko alpine ssh-tunnel

一段时间以来,我一直在努力进行一些工作,所以我决定大声呼救。

我有一个脚本,该脚本可以下载一些文件并将其拖放到sftp服务器中进行批处理。

我正在使用高山python容器,而我的Dockerfile如下所示

FROM python:3.7.1-alpine3.8

RUN \
echo "**** install build packages ****" && \
apk add --no-cache --virtual=build-dependencies \
g++ \
gcc \
make \
libffi-dev \
openssl-dev \
openssl \
python-dev && \
echo "**** install pip packages ****" && \
pip install --no-cache-dir -U \
pip && \
pip install --no-cache-dir -U \
cryptography \
paramiko \
sshtunnel \
datetime \
boto3 \
requests \
datetime && \
echo "**** clean up ****" && \
apk del --purge \
gcc \
g++\
make \
build-dependencies && \
rm -rf \
/root/.cache \
/var/cache/apk/* \
/tmp/*

COPY settle.py /
CMD [ "python3", "./settle.py" ]

我有一个名为resolve.py的文件,其相关片段为:

print("creating the tunnel")
  with SSHTunnelForwarder(
      (loaded_json["sftp_jumpbox_address"],int(loaded_json["sftp_jumpbox_port"])),
      ssh_username=loaded_json["sftp_jumpbox_user"],
      ssh_pkey=privateJumpboxKey,
      remote_bind_address=(loaded_json["sftp_target_address"],int(loaded_json["sftp_target_port"])),
      local_bind_address=("127.0.0.1",2222)

  ) as tunnel:
    print("making actual ssh paramiko connection")
    client = paramiko.SSHClient()
    client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    pemkey = paramiko.RSAKey.from_private_key_file(privateTargetKey)
    client.connect(hostname="127.0.0.1",port=2222,username=loaded_json["sftp_target_user"],pkey=pemkey, look_for_keys=False)
    print("Making the sftp connection")
    sftp = client.open_sftp()
    # filename="testing_20181119114841390.txt"
    # print(loaded_json)
    uploadFolder= targetUploadFolder+"/"
    print("destination file "+ filename)
    sftp.chdir(uploadFolder)
    print("dropping the file into the sftp")
    sftp.put(sourceFileToSend,filename)
    print("Closing the sftp connection")
    sftp.close()
    client.close()

    print("Completing the upload")
except Exception as e:
  print("type error: " + str(e))

每次安装软件包,python-dev,cryptograpy的任何组合时,我都运行它,但仍然会出现以下错误

creating the tunnel type error: Error loading shared library libssl.so.1.0.0: No such file or directory (needed by /usr/local/lib/python3.7/site-packages/cryptography/hazmat/bindings/_openssl.abi3.so)

与此同时,此python脚本在我的Mac上运行良好。我不确定我缺少什么。如果有人能照亮我将不胜感激。预先感谢

编辑1 我已经扔进了容器中,当我进行搜索时,下面是我发现的内容

/ # find / -iname libssl*
/lib/libssl.so.45
/lib/libssl.so.45.0.1
/usr/lib/libssl.so.45
/usr/lib/libssl.so.45.0.1

现在不知道哪个库需要更新,需要符号链接到libssl。由于可用的版本比加密库要求的版本要新。

1 个答案:

答案 0 :(得分:0)

在尝试了Alpine的许多其他功能之后,我偶然发现了Linux and Unix上的这篇帖子,据说对于C / C ++编写的python库要格外小心。因此,我切换到了一个基于Debian的发行版,这很简单。下面的Dockerfile完美运行。

FROM python:3.6-slim-jessie


RUN pip install --no-cache-dir -U \
cffi \
paramiko \
sshtunnel \
datetime \
boto3 \
requests \
datetime && \
echo "**** clean up ****" && \
rm -rf /var/lib/apt/lists/*
COPY settle.py /
CMD [ "python", "./settle.py" ]