[whish] Support for --user and --group

0 views
Skip to first unread message

Kamil Kukura

unread,
Apr 4, 2008, 5:23:22 AM4/4/08
to ebbebb
I am using switchpipe (see http://switchpipe.org) and it is possible
to add support for "ebb_rails" into it quite easily. However, it would
be great to have support for specifying which user and group the ebb
process has to run as.

ry

unread,
Apr 4, 2008, 7:47:39 AM4/4/08
to ebbebb
Actually I removed this functionality in the name of minimalism. Is it
nessesary? monit, for example, has arguments to start processes as
specific users and groups.

ry

On 4 Apr., 11:23, Kamil Kukura <kamil.kuk...@gmail.com> wrote:
> I am using switchpipe (seehttp://switchpipe.org) and it is possible

Kamil Kukura

unread,
Apr 4, 2008, 9:40:15 AM4/4/08
to ebbebb
I've checked monit and I think even sudo should be okay with it.
Thanks for answer.

Jason Rojas

unread,
Apr 17, 2008, 12:00:23 AM4/17/08
to ebbebb
Actually in a security sense, this is necessary. With mongrel you
specify --user --group and it runs as an unprivileged user.-
Here is the patch below, it is pretty lightweight.

--- ruby_lib/ebb/runner.rb.orig
+++ ruby_lib/ebb/runner.rb
@@ -23,6 +23,21 @@ module Ebb
# Classes are modules and I hate this 'Base' class pattern. I'm
putting
# other classes inside this one.
autoload :Rails, LIBDIR + '/ebb/runner/rails'
+
+ def change_user(user, group)
+ begin
+ if group
+ Process::GID.change_privilege(Etc.getgrnam(group).gid)
+ end
+
+ if user
+ Process::UID.change_privilege(Etc.getpwnam(user).uid)
+ end
+ rescue Errno::EPERM
+ Ebb.log.puts "FAILED to change user:group #{user}:#{group}: #
$!"
+ exit 1
+ end
+ end

# Kill the process which PID is stored in +pid_file+.
def self.kill(pid_file, timeout=60)
@@ -73,6 +88,8 @@ module Ebb
@parser.on("-d", "--daemonize", "Daemonize")
{ @options[:daemonize] = true }
@parser.on("-l", "--log-file FILE", "File to redirect output")
{ |f| @options[:log_file]=f }
@parser.on("-P", "--pid-file FILE", "File to store PID") { |f|
@options[:pid_file]=f }
+ @parser.on("-u", "--user group", "User to daemonize as") { |u|
@options[:user]=u }
+ @parser.on("-g", "--group group", "Group to daemonize as") { |
g| @options[:group]=g }
# @parser.on("-t", "--timeout SECONDS", "(default:
#{@options[:timeout]})") { |s| @options[:timeout]=s }

@parser.separator ""
@@ -100,6 +117,10 @@ module Ebb

if @options[:daemonize]
pwd = Dir.pwd # Current directory is changed during
daemonization, so store it
+ if @options[:user] and @options[:group]
+ Ebb.log.puts("Switching users...")
+ change_user(@options[:user],@options[:group])
+ end
Kernel.daemonize
Dir.chdir pwd
trap('HUP', 'IGNORE') # Don't die upon logout










Ry

unread,
Apr 22, 2008, 9:27:33 AM4/22/08
to ebbebb
Hi Jason,

> Actually in a security sense, this is necessary

Can't you get the launching process to do this?

ry

Jason Rojas

unread,
Apr 23, 2008, 4:55:59 PM4/23/08
to ebbebb
Yes a launching process can do this but what is the harm of Ebb
forking itself as a different user/group?
The minimalist approach is never a bad idea, but it may not be a good
idea when trying to make a successful product.
Take apache1.3 for example, it is still one of the most widely used
http servers in the world. They couldn't use a minimalist approach
because every environment is unique to an extent.
Things are a little simpler with rails, but it doesn't mean you have
to take functionality that a lot of people are familiar with away.
Ideally Ebb becoming a "drop in" replacement for a slow web server
like mongrel is something I could only dream of. From my perspective,
I would upgrade all 30 of my webservers to Ebb if it had certain
features or abilities if you wish that mongrel does.
Please don't take this as an attack on your or Ebb, this is merely a
point of view from someone using rails in an enterprise environment.
-jason
Reply all
Reply to author
Forward
0 new messages