【问题标题】:Chef & git ssh authentication woes. BitbucketChef & git ssh 身份验证问题。比特桶
【发布时间】:2017-03-28 17:52:02
【问题描述】:

编辑:我的工作解决方案基于以下答案。

    include_recipe 'chef-vault'
include_recipe 'build-essential'

#installation of git
package 'git' do
  action :install
end

repo = 'emrwebapp'

application "/root/#{repo}" do
  owner 'root'
  group 'root'
  git "/root/#{repo}" do
    repository "git@bitbucket.org:sgreen22/#{repo}.git"
    deploy_key chef_vault_item(:credentials, 'git')['bitbucketKey']
  end
end

'-1 guy' - 粉丝!现在祝你有美好的一天。

我是 Chef 的新手,我正在尝试克隆一个 repo 以完成我自己设定的一个简单的学习任务。

我已经学习了很多教程并尝试了很多建议,但由于公钥错误仍然无法克隆 repo。

我正在本地终端上复制步骤,以确保我没有弄乱 url 或任何东西。

我已经:

创建了一个新密钥,确保没有设置密码,将公钥上传到 bitbucket 并使用 ssh -T hg@bitbucket.org 从本地机器测试密钥。

然后,我将此密钥添加到厨师保险库,并验证它存在且可见。

然后使用 chef 我将密钥复制到客户端节点上的某个位置,然后尝试克隆 repo。

有趣的是,当我在客户端节点上运行 hg@bit... 命令时,系统会提示我输入密码,然后按回车键失败。

我已经对本地和客户端的文件进行了分类,并且可以确认它们是正确的。
我在客户端节点上以 root 身份运行,并将密钥放在 /root/.ssh 中,再次通过 pwd 验证。

在客户端上运行详细的 hg@bit... 命令再次要求输入密码,输入权限被拒绝。

非常感谢任何帮助。以下是日志和厨师食谱,谢谢。

/root/.ssh
[root@ip-172-22-4-44 .ssh]# ssh -T hg@bitbucket.org -v
OpenSSH_6.6.1, OpenSSL 1.0.1e-fips 11 Feb 2013
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 56: Applying options for *
debug1: Connecting to bitbucket.org [104.192.143.1] port 22.
debug1: Connection established.
debug1: permanently_set_uid: 0/0
debug1: identity file /root/.ssh/id_rsa type -1
debug1: identity file /root/.ssh/id_rsa-cert type -1
debug1: identity file /root/.ssh/id_dsa type -1
debug1: identity file /root/.ssh/id_dsa-cert type -1
debug1: identity file /root/.ssh/id_ecdsa type -1
debug1: identity file /root/.ssh/id_ecdsa-cert type -1
debug1: identity file /root/.ssh/id_ed25519 type -1
debug1: identity file /root/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.6.1
debug1: Remote protocol version 2.0, remote software version conker_1.0.287-a1d21a7 app-126
debug1: no match: conker_1.0.287-a1d21a7 app-126
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-sha1 none
debug1: kex: client->server aes128-ctr hmac-sha1 none
debug1: kex: curve25519-sha256@libssh.org need=20 dh_need=20
debug1: kex: curve25519-sha256@libssh.org need=20 dh_need=20
debug1: sending SSH2_MSG_KEX_ECDH_INIT
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: RSA 97:8c:1b:f2:6f:14:6b:5c:3b:ec:aa:46:46:74:7c:40
debug1: Host 'bitbucket.org' is known and matches the RSA host key.
debug1: Found key in /root/.ssh/known_hosts:2
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Trying private key: /root/.ssh/id_rsa
debug1: key_parse_private2: missing begin marker
debug1: key_parse_private_pem: PEM_read_PrivateKey failed
debug1: read PEM private key done: type <unknown>
Enter passphrase for key '/root/.ssh/id_rsa':
debug1: Trying private key: /root/.ssh/id_dsa
debug1: Trying private key: /root/.ssh/id_ecdsa
debug1: Trying private key: /root/.ssh/id_ed25519
debug1: No more authentication methods to try.
Permission denied (publickey).
[root@ip-172-22-4-44 .ssh]#


    include_recipe 'chef-vault'

#installation of git
package 'git' do
  action :install
end

#declare the vault
gitKey = chef_vault_item(:credentialsGit, 'git')

file "/root/.ssh/id_rsa" do
  content gitKey['git-key']
  mode 0600
  owner node['user']
  action :create
  notifies :run, 'execute[git ssh]', :immediately
end

execute 'git ssh' do
  command 'GIT_SSH_COMMAND="ssh -i /root/.ssh/id_rsa"'
  user node['user']
end

#pull down the repo
git "/home/ec2-user/spring-app" do
  repository "git@bitbucket.org:sgreen22/emrwebapp.git"
  #I've tried a variety of these using the ext helper as per a guide, but still no good.
  # repository "ext::ssh -i /root/.ssh/id_rsa -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no git@bitbucket.org %S /sgreen22/emrwebapp.git"
  # repository "ext::ssh -i /root/.ssh/id_rsa -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no git@bitbucket.org:sgreen22/emrwebapp.git"
  checkout_branch "master"
  action :sync
  # ssh_wrapper "ssh -i /home/ec2-user/.ssh/id_rsa"  #I've tried this but no effect
end

【问题讨论】:

    标签: git ssh chef-infra bitbucket


    【解决方案1】:

    作为对上述问题的一种更简单的解决方案,application_git cookbook 有一个资源可以为您处理所有这些,只需提供 deploy_key 值,它会处理其余的事情。

    【讨论】:

    • ...几个小时的 ggogle-fu,这根本没有显示。悲伤的时光。感谢您花时间发帖 - 我需要先尝试上一个答案来解决好奇心,但这看起来要简单得多。谢谢。
    • 我正在努力,不久将发布重构版的食谱,希望有更好的 SEO :)
    • 你写的?好吧,做得好 :D 我只是从字面上来选择答案,因为它工作得很好。在另一种方法上再挣扎一两个小时,但没有成功。作为新手,我觉得尴尬的一件事是不知道如何调用 lwrp(?),但我遵循了几个示例并注意到包含构建食谱。完美运行,谢谢!
    • 我也不知道这个食谱,所以我把我的例子放在那里。当我回到那个状态时,我会重新设计它。
    【解决方案2】:

    这是一个如何使用 ssh 包装器从 GitHub 更新 Chef 存储库的示例。

    repo = 'emrwebapp'
    wrapper = "git_wrapper_#{repo}.sh"
    
    file wrapper do
        owner 'ec2-user'
        group 'ec2-user'
        mode 00755
        content "#!/bin/sh\nexec /usr/bin/ssh -o UserKnownHostsFile=/dev/null "\
        '-o StrictHostKeyChecking=no '\
        "-i /home/ec2-user/.ssh/id_rsa \"$@\""
    end
    
    git repo do
        repository "git@bitbucket.org:sgreen22/#{repo}.git"
        reference 'master'
        ssh_wrapper wrapper
        user 'ec2-user'
        group 'ec2-user'
    end
    

    最后,您将获得 git_wrapper_emrwebapp.sh 由厨师生成的文件,该文件将用于 ssh_wrappergit resource

    SSH 包装文件如下所示:

    #!/bin/sh 
    exec /usr/bin/ssh -o UserKnownHostsFile=/dev/null
    StrictHostKeyChecking=no -i /home/ec2-user/.ssh/id_rsa "$@"
    

    【讨论】:

    • 嘿,glg,所以在这个例子中,我仍然需要将 ssh 密钥从保险库复制到客户端,然后使用包装器来调用该密钥?还想询问您示例中的 /home/ec2-user 。我必须以 root 身份运行 chef,就像放置该目录的文件一样,您的示例中是否有一些东西使这成为非问题,或者我只需要用 root 替换您的 home/ec2 吗?
    • 嘿@null,是的,您仍然需要从保管库中复制密钥并将其放在您喜欢的 /home/ec2-user/.ssh 或 /root/.ssh 中。关于第二个问题:我只是在您的示例中看到您正在使用此路径 /home/ec2-user 并没有什么特别之处,我决定将其放在我的示例中。您可以选择您想要的任何目录,并在需要时分配适当的权限。
    猜你喜欢
    • 2019-09-28
    • 2015-12-03
    • 2013-12-26
    • 2011-01-22
    • 2019-12-18
    • 1970-01-01
    • 2015-10-15
    • 2014-02-26
    相关资源
    最近更新 更多