Skip to contentSkip to conversation

provide real error message when trying to run xm as non root

PATCH In review Sean Dague 3 participants 4 messages Jul 26, 2005

lore
Share & tools
lore

Sean Dague

author
#0 lore raw

PATCH 1/1 provide real error message when trying to run xm as non root

This patch prevents you from getting a screen full of stack trace when trying to run commands like xm list as a normal user, and instead provides a helpful error message.

Diffstat output:

 main.py |    7 +++++++
 1 files changed, 7 insertions(+)
tools/python/xen/xm/main.py +7 -0
diff -r 48aed1403fe3 tools/python/xen/xm/main.py
@@ -11,6 +11,13 @@
 
 from xen.xend import PrettyPrint
 from xen.xend import sxp
+# this is a nasty place to stick this in, but required because
+# log file access is set up via a 5 deep import chain.  This
+# ensures the user sees a useful message instead of a stack trace
+if os.getuid() != 0:
+    print "xm requires root access to execute, please try again as root"
+    sys.exit(1)
+
 from xen.xend.XendClient import XendError, server
 from xen.xend.XendClient import main as xend_client_main
 from xen.xm import create, destroy, migrate, shutdown, sysrq

-Sean

Signature · 9 lines
__________________________________________________________________

Sean Dague                                       Mid-Hudson Valley
sean at dague dot net                            Linux Users Group
http://dague.net                                 http://mhvlug.org

There is no silver bullet.  Plus, werewolves make better neighbors
than zombies, and they tend to keep the vampire population down.
__________________________________________________________________

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#1 lore raw
Quoted 3 lines · Sean Dague

This patch prevents you from getting a screen full of stack trace when trying to run commands like xm list as a normal user, and instead provides a helpful error message.

+1, Admirable. (non-binding/non-voter/non-commiter)

Quoted 13 lines

Diffstat output:

 main.py |    7 +++++++
 1 files changed, 7 insertions(+)

diff -r 48aed1403fe3 tools/python/xen/xm/main.py

tools/python/xen/xm/main.py +0 -0
@@ -11,6 +11,13 @@
 
 from xen.xend import PrettyPrint
 from xen.xend import sxp

tools/python/xen/xm/main.py line 23

Quoted 10 lines
tools/python/xen/xm/main.py +7 -0
+# this is a nasty place to stick this in, but required because
+# log file access is set up via a 5 deep import chain.  This
+# ensures the user sees a useful message instead of a stack trace
+if os.getuid() != 0:
+    print "xm requires root access to execute, please try again as root"
+    sys.exit(1)
+
 from xen.xend.XendClient import XendError, server
 from xen.xend.XendClient import main as xend_client_main
 from xen.xm import create, destroy, migrate, shutdown, sysrq

Please allow me to show my possible ignorance...

Is there no better way to test for elevated privileges?
Would it be unreasonable to think xm maintenance tasks could be handed off to members of a non-root group?

Signature · 2 lines
Andrew Thompson
http://aktzero.com/

begin:vcard
fn:Andrew Thompson
n:Thompson;Andrew
email;internet:[email protected]
x-mozilla-html:FALSE
url:http://aktzero.com/
version:2.1
end:vcard

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

author
#2 lore raw
Quoted 34 lines · Andrew Thompson
Quoted 4 lines · Sean Dague

This patch prevents you from getting a screen full of stack trace when trying to run commands like xm list as a normal user, and instead provides a
helpful error message.

+1, Admirable. (non-binding/non-voter/non-commiter)

Quoted 20 lines

Diffstat output:
main.py | 7 +++++++

1 files changed, 7 insertions(+)

diff -r 48aed1403fe3 tools/python/xen/xm/main.py

tools/python/xen/xm/main.py +0 -0
@@ -11,6 +11,13 @@
 

from xen.xend import PrettyPrint
from xen.xend import sxp

tools/python/xen/xm/main.py +7 -0
+# this is a nasty place to stick this in, but required because
+# log file access is set up via a 5 deep import chain.  This
+# ensures the user sees a useful message instead of a stack trace
+if os.getuid() != 0:
+    print "xm requires root access to execute, please try again as root"
+    sys.exit(1)
+
Quoted 3 lines

from xen.xend.XendClient import XendError, server from xen.xend.XendClient import main as xend_client_main from xen.xm import create, destroy, migrate, shutdown, sysrq

Please allow me to show my possible ignorance...

Quoted 3 lines

Is there no better way to test for elevated privileges? Would it be unreasonable to think xm maintenance tasks could be handed off to members of a non-root group?

Unfortunately the root problem comes from the fact that xm writes to the xend log file directly, and in unprivileged state, throws an exception because it doesn't have write access to that file. The 2nd part of this problem is that this exception is buried down a whole series of 5 level magical import object creation paths, and hence is very hard to reasonably get to from the xm main().

I'm sure you *could* reorder xm code to make this a strict perms check, but the level of spagetti sorting to get there may not really be worth it. I also think you'd have to remove the direct logging from xm to be able to do priv seperate between xm and xend, and that is really strewn throughout all the code.

-Sean

Signature · 9 lines
__________________________________________________________________

Sean Dague                                       Mid-Hudson Valley
sean at dague dot net                            Linux Users Group
http://dague.net                                 http://mhvlug.org

There is no silver bullet.  Plus, werewolves make better neighbors
than zombies, and they tend to keep the vampire population down.
__________________________________________________________________

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#3 lore raw
Quoted 39 lines · Sean Dague
Quoted 34 lines · Andrew Thompson
Quoted 4 lines · Sean Dague

This patch prevents you from getting a screen full of stack trace when trying to run commands like xm list as a normal user, and instead provides a
helpful error message.

+1, Admirable. (non-binding/non-voter/non-commiter)

Quoted 20 lines

Diffstat output:
main.py | 7 +++++++

1 files changed, 7 insertions(+)

diff -r 48aed1403fe3 tools/python/xen/xm/main.py

tools/python/xen/xm/main.py Tue Jul 26 10:31:24 2005 renamed from tools/python/xen/xm/main.py Fri Jul 22 16:44:33 2005 +0 -0
@@ -11,6 +11,13 @@
 

from xen.xend import PrettyPrint
from xen.xend import sxp

tools/python/xen/xm/main.py Tue Jul 26 10:31:24 2005 renamed from tools/python/xen/xm/main.py Fri Jul 22 16:44:33 2005 +7 -0
+# this is a nasty place to stick this in, but required because
+# log file access is set up via a 5 deep import chain.  This
+# ensures the user sees a useful message instead of a stack trace
+if os.getuid() != 0:
+    print "xm requires root access to execute, please try again as root"
+    sys.exit(1)
+
Quoted 3 lines

from xen.xend.XendClient import XendError, server from xen.xend.XendClient import main as xend_client_main from xen.xm import create, destroy, migrate, shutdown, sysrq

Please allow me to show my possible ignorance...

Quoted 3 lines

Is there no better way to test for elevated privileges? Would it be unreasonable to think xm maintenance tasks could be handed off to members of a non-root group?

Quoted 7 lines

Unfortunately the root problem comes from the fact that xm writes to the xend log file directly, and in unprivileged state, throws an exception because it doesn't have write access to that file. The 2nd part of this problem is that this exception is buried down a whole series of 5 level magical import object creation paths, and hence is very hard to reasonably get to from the xm main().

yes, most of the problem comes from the fact that most call to XendRoot.py is to get xend configuations (in xend-config.sxp), but too bad XendRoot has another function: to open a log file, wich is the job of root.

actually i had a patch to split XendRoot.py (to make a new XendConfig.py) and convert most call to XendRoot to XendConfig, but never have a chance to submit it. probably i will give another attempt this weekend.

regards,
aq