2016-03-03 67 views
0

我想用github私有存儲庫爲本地開發環境創建食譜。Github存儲庫返回在食譜中拒絕的權限

但是,當廚師試圖克隆git repo時,github返回權限被拒絕的錯誤。

SSH轉發工作,SSH_AUTH_SOCK env由cookbook'sudo'設置。

通過vagrant sshsudo ssh -T [email protected]sudo git clone [email protected]:myorg/myproject.git都成功。

我該如何解決這個問題?

這是我的食譜

deploy_user = node["git_repository_to_deploy"]["deploy_user"] 

ssh_known_hosts_entry 'github.com' 

git "/home/#{deploy_user}/sync_folder" do 
    repository '[email protected]:myorg/myproject.git' 
    reference 'master' 
    action :sync 
    user deploy_user 
    group deploy_user 
    retries 3 
end 

的一部分,下面是角色[ '網絡'] JSON的一部分。

{ 
    "name": "web", 
    "chef_type": "role", 
    "json_class": "Chef::Role", 
    "default_attributes": { 
     "authorization": { 

     "sudo": { 
       "include_sudoers_d": true, 
       "passwordless": true, 
       "sudoers_defaults": [ 
        "env_reset", 
        "env_keep = \"COLORS DISPLAY HOSTNAME HISTSIZE INPUTRC KDEDIR\"", 
        "env_keep += \"LS_COLORS MAIL PS1 PS2 QTDIR USERNAME\"", 
        "env_keep += \"LANG LC_ADDRESS LC_CTYPE LC_COLLATE LC_IDENTIFICATION\"", 
        "env_keep += \"LC_MEASUREMENT LC_MESSAGES LC_MONETARY LC_NAME LC_NUMERIC\"", 
        "env_keep += \"LC_PAPER LC_TELEPHONE LC_TIME LC_ALL LANGUAGE LINGUAS \"", 
        "env_keep += \"_XKB_CHARSET XAUTHORITY SSH_AUTH_SOCK\"" 
       ] 
      } 
     }, 
     "nginx": { 
      "env": ["ruby"] 
     }, 
     "ruby-env": { 
      "version": "2.3.0", 
      "rbenv_url":  "https://github.com/sstephenson/rbenv", 
      "ruby-build_url": "https://github.com/sstephenson/ruby-build" 
     } 
    }, 
    "run_list": [ 
     "recipe[yum-epel]", 
     "recipe[nginx]", 
     "recipe[nginx-conf]", 
     "recipe[nodejs]", 
     "recipe[readline]", 
     "recipe[ruby-env]", 
     "recipe[postgresql]", 
     "recipe[imagemagick]", 
     "recipe[sudo]", 
     "recipe[github]", 
    ] 
} 

以下是Vagrantfile。

Vagrant.configure(2) do |config| 
    config.vm.box = "bento/centos-6.7" 
    config.vm.network "private_network", ip: "192.168.33.10" 
    config.ssh.forward_agent = true 
    config.vm.synced_folder "./sync_folder", "/home/vagrant/sync_folder" 
end 

以下是我的〜/ .ssh/config中

Host github.com 
    ForwardAgent yes 

當我輸入

bundle exec knife solo bootstrap local-development 

廚師返回此錯誤。

Recipe: github::default 
    * git[/home/vagrant/sync_folder] action sync 

    ================================================================================ 
    Error executing action `sync` on resource 'git[/home/vagrant/sync_folder]' 
    ================================================================================ 

    Mixlib::ShellOut::ShellCommandFailed 
    ------------------------------------ 
    Expected process to exit with [0], but received '128' 
    ---- Begin output of git ls-remote "[email protected]:myorg/myproject.git" "master*" ---- 
    STDOUT: 
    STDERR: Permission denied (publickey). 
    fatal: The remote end hung up unexpectedly 
    ---- End output of git ls-remote "[email protected]:myorg/myproject.git" "master*" ---- 
    Ran git ls-remote "[email protected]:myorg/myproject.git" "master*" returned 128 


    Running handlers: 
    [2016-03-03T09:02:23+00:00] ERROR: Running exception handlers 
    Running handlers complete 
    [2016-03-03T09:02:23+00:00] ERROR: Exception handlers complete 
    Chef Client failed. 8 resources updated in 25 seconds 
    [2016-03-03T09:02:23+00:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out 
    [2016-03-03T09:02:23+00:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report 
    [2016-03-03T09:02:23+00:00] ERROR: git[/home/vagrant/sync_folder] (cloudtip::default line 10) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '128' 
    ---- Begin output of git ls-remote "[email protected]:myorg/myproject.git" "master*" ---- 
    STDOUT: 
    STDERR: Permission denied (publickey). 
    fatal: The remote end hung up unexpectedly 
    ---- End output of git ls-remote "[email protected]:myorg/myproject.git" "master*" ---- 
    Ran git ls-remote "[email protected]:myorg/myproject.git" "master*" returned 128 
    [2016-03-03T09:02:23+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1) 
    ERROR: RuntimeError: chef-solo failed. See output above. 

回答

0

事實上,這是預期。 knife solo不會轉發您的SSH代理憑據。期望的是,您將使用Chef來部署您的部署密鑰,並使用包含git資源的SSH包裝器。查看application_git cookbook獲取資源,使其更容易一些。