【发布时间】:2021-12-07 07:51:15
【问题描述】:
我正在尝试在 docker 构建过程中的 known_hosts 文件中识别公钥,我正在使用的 dockerfile 的相关部分是这样的:
RUN mkdir -p -m 0700 ~/.ssh
# Copy SSH host config to use port 443
COPY docker/config/gitlab_host.txt /root/.ssh/config
RUN cat ~/.ssh/config
# Download public key for gitlab.com
RUN ssh-keyscan -p443 gitlab.com >> ~/.ssh/known_hosts
RUN cat ~/.ssh/known_hosts
为了补全,ssh配置文件(docker/config/gitlab_host.txt):
Host gitlab.com
Hostname altssh.gitlab.com
User git
Port 443
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
首先,我在企业防火墙后面,端口 22 上没有出站流量。因此,我们将 ssh 配置配置为使用端口 443,幸好 gitlab 提供了此选项。但是,ssh-keyscan 似乎不支持此配置,指定此端口似乎也不起作用,ssh-keyscan 部分只是静默失败。我已经尝试了命令的多种排列:
ssh-keyscan -p 443 gitlab.com
ssh-keyscan gitlab.com:443
一切都无济于事。为详细程度提供 -v 标志也不会生成输出。
我能想到的唯一其他选择是复制到我自己的 known_hosts 文件中,这是否有效并且安全吗?存储库的实际克隆是通过“传递”主机 ssh 来完成的。
RUN --mount=type=ssh,uid=1001 pip install git+ssh://git@gitlab.com/<private>.git
RUN --mount=type=ssh,uid=1001 pip install git+ssh://git@gitlab.com/<another_private>.git
我必须通过什么选项让主机知道以便我可以 git clone?
【问题讨论】:
-
对于端口 443,命令应该是
ssh-keyscan -p 443 altssh.gitlab.com和pip install git+ssh://git@altssh.gitlab.com:443/ -
是的,那是我的问题之一。现在扫描那个网址我得到
0.219 getaddrinfo altssh.gitlab.com: Temporary failure in name resolutionz。我会用这个新信息修改我的问题。