Skip to content

Commit 339cf4c

Browse files
authored
Skip crew-sudo when called by non-chronos user
1 parent 5756937 commit 339cf4c

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

component/client.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,13 @@ def restore_console
1010
end
1111

1212
def runas_client(argv)
13-
$mode = :client
13+
$mode = :client
14+
15+
unless Process.euid == 1000
16+
message 'Client executed by non-chronos user, falling back to sudo...'
17+
exec($0, *ARGV)
18+
end
19+
1420
is_tty = $stdin.isatty && $stdout.isatty && $stderr.isatty
1521
$tty_attr = %x[/bin/stty -g].chomp if is_tty
1622
socket = UNIXSocket.open(SOCKET_PATH) # connect to daemon

component/daemon.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ def runas_daemon(argv)
4141
File.chown(0, 1000, SOCKET_PATH) if Process.uid.zero?
4242

4343
Socket.accept_loop(@server) do |socket, _|
44+
client_pid, client_uid, client_gid = socket.getsockopt(:SOL_SOCKET, :SO_PEERCRED).unpack('L*')
45+
46+
unless client_uid == 1000
47+
message "Request from PID #{client_pid} rejected (only chronos user is allowed)"
48+
socket.close
49+
next
50+
end
51+
4452
Thread.new do
4553
# receive client's stdin/stdout/stderr io from client
4654
client_stdin, client_stdout, client_stderr = [socket.recv_io, socket.recv_io, socket.recv_io]
@@ -64,7 +72,7 @@ def runas_daemon(argv)
6472
chdir: client_request[:cwd]
6573
end
6674

67-
message "Process #{pid} spawned: #{cmdline}"
75+
message "Process #{pid} spawned by client (#{client_pid}): #{cmdline}"
6876
send_event(socket, 'cmdSpawned', { pid: pid })
6977

7078
# listen to client events

0 commit comments

Comments
 (0)