AWS CodeBuild 与 Github Enterprise Deploy Keys 要求输入密码

Tyl*_*ler 5 git ssh amazon-web-services key-pair aws-codebuild

我正在尝试为我的 Github Enterprise 存储库使用部署密钥,以便我可以使用 CodeBuild 项目推送新部署的标签。无论我如何尝试,我都无法让它发挥作用。

在我的本地计算机中:(MacOS)

我使用如下命令生成密钥:ssh-keygen -t ecdsa -b 521 -f $PATH_TO_SSH_KEY -q -N ""
我将$PATH_TO_SSH_KEYAWS SSM Parameter Store 中的内容作为 SecureString 保存。
我从参数存储中加载此参数到我的 CodeBuild 环境中,而不是加载到我的 buildspec.yml 中。
我将 $PATH_TO_SSH_KEY.pub作为新的部署密钥保存到 github 企业存储库。

在我的 CodeBuild 项目 buildspec.yml 中:

我将密钥保存到文件中:printf -- "$GITHUB_PRIVATE_KEY" > ~/.ssh/id_ecdsa

现在,我尝试了两种不同的方法,但都失败了。

方法一:

将企业站点的指纹保存到known_hosts:ssh-keyscan "$GITHUB_ENTERPRISE_URL" >> ~/.ssh/known_hosts
配置git以使用我的凭据:GIT_SSH_COMMAND="ssh -i ~/.ssh/id_ecdsa" git push --tags
此方法失败并出现错误:

git@<ENTERPRISE_URL>: Permission denied (publickey).
fatal: Could not read from remote repository.
Run Code Online (Sandbox Code Playgroud)

方法2:

使用 SSH 代理保存密钥并尝试以这种方式克隆:
eval $(ssh-agent)
ssh-add ~/.ssh/id_ecdsa
git push --tags
此方法失败,因为出现以下消息:

Enter passphrase for /root/.ssh/id_ecdsa:
Run Code Online (Sandbox Code Playgroud)

(我的密钥没有密码,并且在我的本地计算机上运行良好)

问题:

有可能让这个工作吗?我见过使用代码构建部署密钥的其他示例,但是当我尝试完全相同的设置时,我因上述错误之一而失败。我已经为此工作了两天了,所以我已经束手无策了。任何帮助将不胜感激。

如果需要任何其他信息,我很乐意在此处获取并进行编辑。

Ale*_*tin 1

Hopefully in the near future, codebuild will begin supporting deploy keys natively through AWS instead of in the buildspec file

Yeah, I agree that would be a great addition. For now we're working around the shortcoming simply keeping the SSH private key in plain text form but stored encrypted in SSM parameter store, e.g:

version: 0.2
env:
  parameter-store:
    SSH_PRIVATE_KEY: /ssm/key/name/here
phases:
  install:
    on-failure: ABORT
    commands:
      - mkdir -p ~/.ssh && chmod 0700 ~/.ssh
      - echo -n "${SSH_PRIVATE_KEY}" > ~/.ssh/id_rsa && chmod 0400 ~/.ssh/id_rsa
      - md5sum ~/.ssh/id_rsa
  build:
    on-failure: ABORT
    commands:
      - eval $(ssh-agent)
      - ssh-add ~/.ssh/id_rsa
Run Code Online (Sandbox Code Playgroud)

not ideal and quite some boilerplate added but it's good enough in our scenario.