You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Alexandr Nalbandyan <an...@googlemail.com> on 2010/04/27 13:11:35 UTC

[daemon] Problems of downgrading user prevelegies.

Hi Following is the problem we have faced when specifying "-user" option in
jsvc.

In the following code snipped in init method definition we have tried to
create file output stream.
"
    public final void init(final DaemonContext arg0) throws Exception {
        FileOutputStream fileOutputStream = new
FileOutputStream("logs/test.out");
"
But this code throws exception saying "Permission Denied".

But if we remove -user  option it works.
According to the documentation init method should run  with "super user"
prevelages.

Used environment
Jsvc version : 1.0.2
 java version "1.6.0_15"
OS version: Linux ubuntu 2.6.31-16-generic


Thanks in advance.
Alik

Re: [daemon] Problems of downgrading user prevelegies.

Posted by Mladen Turk <mt...@apache.org>.
On 04/27/2010 03:11 PM, Alexandr Nalbandyan wrote:
> Hi
> Thank you  for the feedback actually the reason why we came to such
> conclusion is following.
> Here is snapshot from init method comment
> "  perform all operations
>       *   requiring<i>super-user</i>  privileges in the underlying operating
>       *   system.
> ".
>> From this we came to conclusion that during execution of this process user
> has
> super-user privileges and it is still root user.

Nope. The javadoc is somehow miss-leading here.
JVM is initialized in child process after user downgrade.


> If this is wrong then what is the actual reason of failure specified in
> email.

Reason is security.
You start the daemon as root and downgrade to the regular user.
If that user cannot create or access the file, it'll fail.

>
> And it helps to fix the problem.
> But this is not actually the preferred solution.
> Can you please advise how to fix the problem correctly.
>

Make sure you don't mix the access to logs/test.out between
root and downgraded user.
If you start the jsvc as a root it'll be the owner of that file.
next invocation with -user will always fail.


Regards
-- 
^TM

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: [daemon] Problems of downgrading user prevelegies.

Posted by Alexandr Nalbandyan <an...@googlemail.com>.
Hi
Thank you  for the feedback actually the reason why we came to such
conclusion is following.
Here is snapshot from init method comment
"  perform all operations
     *   requiring <i>super-user</i> privileges in the underlying operating
     *   system.
".
>From this we came to conclusion that during execution of this process user
has
super-user privileges and it is still root user.
If this is wrong then what is the actual reason of failure specified in
email.
Actually  I have tried following I have looked at jsvc-unix.c file
and fine the method "linuxset_user_group" which is executed before jvm
initialization.
and changed the following part from
#################################
if (caps_set) {
        /* set capability to binding port 80 read conf */
        if (set_caps(CAPSMIN)!=0) {
            if (getuid()!= uid) {
                log_error("set_caps(CAPSMIN) failed");
                return(-1);
            }
            log_debug("set_caps(CAPSMIN) failed");
        }
    }
###################################
To
#################################
if (caps_set) {
        /* set capability to binding port 80 read conf */
        if (set_caps(CAPSMIN)!=0) {
            if (getuid()!= uid) {
                log_error("set_caps(CAPSALL) failed");
                return(-1);
            }
            log_debug("set_caps(CAPSALL) failed");
        }
    }
###################################

And it helps to fix the problem.
But this is not actually the preferred solution.
Can you please advise how to fix the problem correctly.

On Tue, Apr 27, 2010 at 5:58 PM, Mladen Turk <mt...@apache.org> wrote:

> On 04/27/2010 01:11 PM, Alexandr Nalbandyan wrote:
>
>> Hi Following is the problem we have faced when specifying "-user" option
>> in
>> jsvc.
>>
>> In the following code snipped in init method definition we have tried to
>> create file output stream.
>> "
>>     public final void init(final DaemonContext arg0) throws Exception {
>>         FileOutputStream fileOutputStream = new
>> FileOutputStream("logs/test.out");
>> "
>> But this code throws exception saying "Permission Denied".
>>
>> But if we remove -user  option it works.
>> According to the documentation init method should run  with "super user"
>> prevelages.
>>
>>
> Can you point to the documentation where is that stated, cause it's wrong,
> and needs to be fixed.
>
> init() is called after user downgrade.
> Basically the JVM cannot be forked, because threads cannot be
> forked, and would left JVM without GC thread.
>
>
> Regards
> --
> ^TM
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>

Re: [daemon] Problems of downgrading user prevelegies.

Posted by Mladen Turk <mt...@apache.org>.
On 04/27/2010 01:11 PM, Alexandr Nalbandyan wrote:
> Hi Following is the problem we have faced when specifying "-user" option in
> jsvc.
>
> In the following code snipped in init method definition we have tried to
> create file output stream.
> "
>      public final void init(final DaemonContext arg0) throws Exception {
>          FileOutputStream fileOutputStream = new
> FileOutputStream("logs/test.out");
> "
> But this code throws exception saying "Permission Denied".
>
> But if we remove -user  option it works.
> According to the documentation init method should run  with "super user"
> prevelages.
>

Can you point to the documentation where is that stated, cause it's wrong,
and needs to be fixed.

init() is called after user downgrade.
Basically the JVM cannot be forked, because threads cannot be
forked, and would left JVM without GC thread.


Regards
-- 
^TM

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org