`
jimichan
  • 浏览: 278059 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

GitLab 6.9.2 升级问题 sshkey添加失败

 
阅读更多

我测试从gitlab 6.9.2升级到了最新版本,但是clone总是提示输入密码,

 

发现gitlab没办法产生 authorized_keys文件内容,获得lock文件的时候超时了

 

由于没用过ruby,索性把

/gitlab/apps/gitlab/gitlab-shell/lib/gitlab_keys.rb

里面关于lock的调用删了:变成如下文件,问题解决了,就是不要人多的时候不要同时操作sshkey

临时fix一下。

 

require 'tempfile'

 

require_relative 'gitlab_config'

require_relative 'gitlab_logger'

 

class GitlabKeys

  attr_accessor :auth_file, :key

 

  def initialize

    @command = ARGV.shift

    @key_id = ARGV.shift

    @key = ARGV.shift

    @auth_file = GitlabConfig.new.auth_file

  end

 

  def exec

    case @command

    when 'add-key'; add_key

    when 'batch-add-keys'; batch_add_keys

    when 'rm-key';  rm_key

    when 'clear';  clear

    else

      $logger.warn "Attempt to execute invalid gitlab-keys command #{@command.inspect}."

      puts 'not allowed'

      false

    end

  end

 

  protected

 

  def add_key

      $logger.info "Adding key #{@key_id} => #{@key.inspect}"

      auth_line = key_line(@key_id, @key)

      open(auth_file, 'a') { |file| file.puts(auth_line) }

    true

  end

 

  def batch_add_keys

      open(auth_file, 'a') do |file|

        stdin.each_line do |input|

          tokens = input.strip.split("\t")

          abort("#{$0}: invalid input #{input.inspect}") unless tokens.count == 2

          key_id, public_key = tokens

          $logger.info "Adding key #{key_id} => #{public_key.inspect}"

          file.puts(key_line(key_id, public_key))

        end

      end

    true

  end

 

  def stdin

    $stdin

  end

 

  def key_line(key_id, public_key)

    auth_line = "command=\"#{ROOT_PATH}/bin/gitlab-shell #{key_id}\",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty #{public_key}"

  end

 

  def rm_key

      $logger.info "Removing key #{@key_id}"

      Tempfile.open('authorized_keys') do |temp|

        open(auth_file, 'r+') do |current|

          current.each do |line|

            temp.puts(line) unless line.include?("/bin/gitlab-shell #{@key_id}\"")

          end

        end

        temp.close

        FileUtils.cp(temp.path, auth_file)

      end

    true

  end

 

  def clear

    open(auth_file, 'w') { |file| file.puts '# Managed by gitlab-shell' }

    true

  end

 

 

  def lock(timeout = 10)

    File.open(lock_file, "w+") do |f|

      begin

        f.flock File::LOCK_EX

        Timeout::timeout(timeout) { yield }

      ensure

        f.flock File::LOCK_UN

      end

    end

  end

 

  def lock_file

    @lock_file ||= auth_file + '.lock'

  end

 

end

 

0
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics