Execute script with git permissions

This commit is contained in:
Patrick Lühne 2020-05-26 05:44:08 +02:00
parent 0eb22fcfd9
commit 0eb9f4929d
Signed by: patrick
GPG Key ID: 05F3611E97A70ABF
3 changed files with 59 additions and 54 deletions

View File

@ -1,2 +1,2 @@
#/usr/bin/env bash #/usr/bin/env bash
/usr/lib/github-fast-env/github-fast-env.rb "$@" sudo /usr/lib/github-fast-env/github-fast-env.rb "$@"

View File

@ -176,11 +176,11 @@ while true
mode = arguments[1] mode = arguments[1]
if mode == "named-pipes" if mode == "named-pipes"
if arguments.length < 3 if arguments.length < 4
raise ClientError.new "malformed command" raise ClientError.new "malformed command"
end end
elsif mode == "pseudoterminal" elsif mode == "pseudoterminal"
if arguments.length < 4 if arguments.length < 5
raise ClientError.new "malformed command" raise ClientError.new "malformed command"
end end
@ -189,11 +189,13 @@ while true
raise ClientError.new "unknown mode (#{mode})" raise ClientError.new "unknown mode (#{mode})"
end end
script_path = Base64.decode64(arguments.last) working_directory = Base64.decode64(arguments[-2])
script_path = Base64.decode64(arguments[-1])
connection_id += 1 connection_id += 1
child_process = fork { child_process = fork {
Dir.chdir(working_directory) do
process_id = Process.pid process_id = Process.pid
control_socket.puts "pid #{process_id}" control_socket.puts "pid #{process_id}"
@ -205,6 +207,9 @@ while true
set_up_pseudoterminal(control_socket, pseudoterminal_path) set_up_pseudoterminal(control_socket, pseudoterminal_path)
end end
Process.gid = Process.egid = "git"
Process.uid = Process.euid = "git"
$original_stderr.puts " executing script #{script_path} (#{process_id})" $original_stderr.puts " executing script #{script_path} (#{process_id})"
begin begin
@ -252,8 +257,7 @@ while true
end end
$original_stderr.puts " finished handling request (#{process_id})" $original_stderr.puts " finished handling request (#{process_id})"
end
Kernel.exit!
} }
Process.detach(child_process) Process.detach(child_process)

View File

@ -156,6 +156,7 @@ end
log "info", "connected to control socket" log "info", "connected to control socket"
working_directory = Base64.encode64(Dir.pwd).delete("\n")
encoded_script_path = Base64.encode64(script_path).delete("\n") encoded_script_path = Base64.encode64(script_path).delete("\n")
read_ios = [$control_socket] read_ios = [$control_socket]
@ -164,9 +165,9 @@ if $options[:interactive]
pseudoterminal_path = File.readlink("/proc/self/fd/0") pseudoterminal_path = File.readlink("/proc/self/fd/0")
encoded_pseudoterminal_path = Base64.encode64(pseudoterminal_path).delete("\n") encoded_pseudoterminal_path = Base64.encode64(pseudoterminal_path).delete("\n")
$control_socket.puts "new v1 pseudoterminal #{encoded_pseudoterminal_path} #{encoded_script_path}" $control_socket.puts "new v1 pseudoterminal #{encoded_pseudoterminal_path} #{working_directory} #{encoded_script_path}"
else else
$control_socket.puts "new v1 named-pipes #{encoded_script_path}" $control_socket.puts "new v1 named-pipes #{working_directory} #{encoded_script_path}"
end end
pipes = {"stdin" => nil, "stdout" => nil, "stderr" => nil} pipes = {"stdin" => nil, "stdout" => nil, "stderr" => nil}