【问题标题】:What is the right/secure way to pip install a private git repo on a Heroku app?在 Heroku 应用程序上 pip 安装私有 git 存储库的正确/安全方法是什么?
【发布时间】:2020-09-26 07:38:36
【问题描述】:

应用结构(Python FastAPI):

-my_app
  -server.py
  -Procfile
  -requirements.txt

为了安装我的 Heroku 应用所需的私有 git 存储库,我在requirements.txt 中添加了以下行:

git+https://<github-token>@github.com/me/my-private-repo.git

然而,在推送时,Github 给我发邮件说,由于我在提交中暴露了我的令牌,它已经撤销了令牌。 (我的应用程序仓库是私有的。)完全公平!但是,我的 Heroku 构建现在失败了,因为它在尝试安装私有存储库时提示输入密码。

我已经多次搜索 SO/互联网:私人回购,但总是遇到相互矛盾的建议。

很高兴听到在这种情况下的最佳做法是在自动构建中安全地安装私有存储库

到目前为止我已经尝试过:

  • git+git://username:password@github.com/me/myrepo.git 而不是 token 显然有同样的问题
  • git+ssh://git@github.com/me/myrepo.git - 产生错误Host key verification failed.
  • 将用户名:密码(或令牌)存储为 Heroku 环境变量 - 从 here 看来,pip 不可能做到这一点

要扩展 ssh 选项,请在我的本地计算机上执行以下操作:

  • pip3 install git+ssh://git@github.com/me/my_private-repo.git
  • git clone https://github.com/me/my_private-repo.git

但是,当我的 requirements.txt 包含 git+ssh://git@github.com/me/my_private-repo.git 时,我的 Heroku 构建返回 Host key verification failed. fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.

【问题讨论】:

  • 您尝试了哪些相互矛盾的建议,为什么它们不能让您满意?
  • 扩大了问题以包括这个
  • Host key verification failed. 可以是easily fixed: ssh-keygen -R github.com; ssh-keyscan -t rsa github.com &gt;&gt; ~/.ssh/known_hostsstackoverflow.com/…

标签: git github heroku pip


【解决方案1】:

终于搞定了。我感谢 Michel Blancard 的 answer 和相关的 gist,以及 Bo Jeanes 的 custom buidpack

requirements.txt:

git+ssh://git@github.com/me/my-private-repo.git

将我的私有 SSH 密钥转换为 Heroku(!) 的(旧)PEM 格式:

ssh-keygen  -f ~/.ssh/id_rsa -m PEM -p

(归功于this answer

将私有 SSH 密钥添加为 Heroku 变量:

heroku config:set SSH_KEY="$(cat ~/.ssh/id_rsa)"

添加 this 自定义 buildpack 以在启用私有 SSH 密钥的 Python buildpack 之前运行:

heroku buildpacks:add --index 1 https://github.com/heroku/heroku-buildpack-ssh-key.git

部署!

【讨论】:

猜你喜欢
  • 2013-03-23
  • 2020-11-19
  • 1970-01-01
  • 2018-11-29
  • 2021-10-21
  • 2019-09-19
  • 2012-12-19
  • 2014-06-24
  • 1970-01-01
相关资源
最近更新 更多