【发布时间】:2017-09-15 19:08:09
【问题描述】:
我的 Node.JS 项目包含对托管在 github 上的私有 NPM 存储库的引用。这在本地工作得很好,但我很难让它在 Elastic Beanstalk 上工作。
dependencies: {
...
"express": "^4.12.4",
"jsonwebtoken": "^5.0.5",
"my-private-module": "git@github.com:<my-user>/<my-repo>.git#<my-version>",
...
}
-
我需要能够在我的 Elastic Beanstalk 实例上为 git 设置有效的 SSH 配置,而无需在源代码控制中存储密钥等。
显然,EB 实例没有访问我的私有 github 存储库所需的 SSH 密钥。如果我使用带有username:password@github.com 内联的HTTPS 样式的git URL,它可以正常工作。它也可以使用 github 提供的oauth token method (本质上是一个用户:pass)。但我不希望将任何凭据签入源代码控制,因此我试图从 github 克隆以通过 SSH 在我的 EB 实例上工作。
我已经尝试了一百万种方法,包括根据this blog post 编写的npm preinstall 脚本,它曾经一直有效,直到 npm2 更改了 preinstall 以在树构建后运行,并且修复该问题的 PR 仍然存在待办的。
我尝试了一个 .ebextensions 命令配置,它试图调用 git config 将 git@github.com 上的 insteadof 放入一个带有来自环境变量的 OAUTH 令牌的 HTTPS URL(因为它本身就很棘手)启动周期此时没有设置env变量,缺少$HOME会使git config混乱)。
我还尝试了使用.ebextensions 在我的EB 实例上设置SSH 的各种不同方式,包括this solution from the comments on the mentioned blog post。这基本上就是我现在卡住的地方。
- 我已经成功创建了一个密钥对,在我的 github 配置文件中设置了它,并验证了我的本地客户端可以使用私钥来克隆我的 repo
- 我已将我的私钥和 ssh 配置文件放在私有 S3 存储桶中
- 根据this example,我创建了一个
.ebextensionsfiles配置,它将这两个文件从我的S3 存储桶复制到/tmp/.ssh/ - 我创建了一个调试
commands.ebextensions配置,其中列出 /tmp/.ssh 并显示文件已成功从 S3 下载:
/tmp/.ssh/config 包含:
Host github.com
IdentityFile /tmp/.ssh/deploy_key
IdentitiesOnly yes
UserKnownHostsFile=/dev/null
StrictHostKeyChecking no
/tmp/.ssh/deploy_key 包含我的私钥,已验证可以在本地工作。
但是,git 还是会报错:
npm ERR! Command failed: git clone --template=/tmp/.npm/_git-remotes/_templates --mirror ssh://git@github.com/[.....]
npm ERR! Cloning into bare repository '/tmp/.npm/_git-remotes/git-ssh-git-github-com-[...]
npm ERR! Host key verification failed.
npm ERR! fatal: Could not read from remote repository.
npm ERR!
npm ERR! Please make sure you have the correct access rights
npm ERR! and the repository exists.
我现在没有想法了。我最好的猜测是 /tmp/.ssh 不是 git 查找 ssh 配置文件的路径 - 它可能是在提出链接解决方案时出现的,但可能在以后的 AMI:s 等中发生了变化。使用的环境EB 何时启动似乎有点受限;命令以用户 nodejs 运行,但 /tmp 似乎被用作主目录,即使 $HOME 没有在任何地方设置。
如何让 git 获取我的 SSH 配置,然后使用我的 SSH 密钥?如何找出 git 在哪里寻找 SSH 配置文件?通常它在 ~/.ssh 中,但由于 $HOME 没有设置,嗯...这应该很容易,但让我抓狂。
【问题讨论】:
标签: node.js git ssh amazon-elastic-beanstalk ebextensions