我們使用git-shell
來確保git帳戶僅用於git操作。這很好。使用git-shell並限制開發人員承諾自己的項目
然而,在我們開始使用git全職工作之前,我們如何設置它類似於github,根據您的公鑰,您可能只能提交給自己的存儲庫?
至於我可以告訴GitHub的人可能會被自己卷git-shell
,該source code appears to be very simple to hack
我們使用git-shell
來確保git帳戶僅用於git操作。這很好。使用git-shell並限制開發人員承諾自己的項目
然而,在我們開始使用git全職工作之前,我們如何設置它類似於github,根據您的公鑰,您可能只能提交給自己的存儲庫?
至於我可以告訴GitHub的人可能會被自己卷git-shell
,該source code appears to be very simple to hack
我用的東西有點簡單,你只需要設置三個文件,該文件authorized_keys
的gitsecurity.rb
文件和文件的權限gitpermissions
。爲了簡單起見,他們都可以進入git accounts .ssh文件夾。 (需要基本的UNIX管理員的技能在此理解)
的gitpermissions
文件看起來是這樣的,應該是相當自我explanitory:
repo1.git|jane|rw
repo1.git|james|r
repo2.git|bob|rw
的autorized_keys
文件看起來是這樣的:
command="/Users/git/.ssh/gitsecurity.rb jacob",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty ssh-rsa rFaivBw.....5Rws jacob
command="/Users/git/.ssh/gitsecurity.rb bob",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty ssh-rsa rFaivBw.....5Rws bob
最後是gitsecurity.rb
腳本,只需複製並粘貼即可:
#!/usr/bin/ruby
class GitPermission
attr_accessor :username;
attr_accessor :repository;
attr_accessor :read;
attr_accessor :write;
def initialize(line)
bits = line.split('|');
if(bits.length!=3)
$stderr.puts "Invalid configuration file"
Process.exit(4)
end
@repository = bits[0]
@username = bits[1]
@read = bits[2].include?("r")
@write = bits[2].include?("w")
end
end
if(!ENV.has_key?("SSH_ORIGINAL_COMMAND"))
$stderr.puts "SSH not allowed to the git account."
Process.exit(1);
end
command = ENV["SSH_ORIGINAL_COMMAND"];
if(!ARGV.length == 1)
$stderr.puts "Authorised keys file misconfigured, username not specified correctly."
Process.exit(1);
end
if(!ARGV[0].match(/^[A-Za-z0-9]+$/))
$stderr.puts "Authorised keys file misconfigured, username contains invalid characters: "+ARGV[0];
Process.exit(1);
end
username = ARGV[0]
if(!command.match(/^git[ -]upload-pack /) && !command.match(/^git[ -]receive-pack /))
$stderr.puts "Only git commands are allowed."
Process.exit(2);
end
repository = command[(command.index(' ')+1)..-1]
if(!repository.match(/'.*'/))
$stderr.puts "Repository parameter incorrect."
Process.exit(2);
end
repository = repository[1,repository.length-2]
begin
file = File.new("/Users/git/.ssh/gitpermissions", "r")
while (line = file.gets)
p = GitPermission.new(line);
if(p.repository == repository && p.username == username)
if((p.write == true || (p.read == true && command.match(/^git[ -]upload-pack/))))
exec "/usr/local/git/bin/" + command
Process.exit(0);
end
end
end
file.close
rescue => err
$stderr.puts "Problem with server configuration: #{err}"
Process.exit(4)
end
$stderr.puts "You do not have permission to complete this operation"
Process.exit(5)
該腳本允許經過身份驗證的用戶可以作爲git用戶運行任意代碼。
實施例利用:https://gist.github.com/ranmrdrakono/4959641
建議的修復:https://gist.github.com/ranmrdrakono/4959672
注意EXEC給出的兩個參數。第一個是要執行的命令(常量),第二個是參數(shell不會被解釋)。
謝謝。修復它的答案。 – Jacob 2013-04-26 06:15:53
多數民衆贊成在酷,這正是我以後,簡單快速和容易。謝謝! – corydoras 2010-01-18 22:08:16