[PATCH] Make sure that only root user runs kimchi

Modify server.py to accept only root user to run kimchi. This will avoid some message errors if non-root users tries to run. Test: ramonn@jarvis:~/Gittrees/KIMCHI (master *)$ ./src/kimchid You need root privileges to run this script. Exiting. ramonn@jarvis:~/Gittrees/KIMCHI (master *)$ $? bash: 1: command not found... ramonn@jarvis:~/Gittrees/KIMCHI (master *)$ sudo ./src/kimchid Loading YumUpdate features. [18/Feb/2014:09:54:05] ENGINE Bus STARTING [18/Feb/2014:09:54:05] ENGINE Started monitor thread 'Autoreloader'. [18/Feb/2014:09:54:05] ENGINE Started monitor thread '_TimeoutMonitor'. WebSocket server settings: - Listen on :64667 - Flash security policy server - No SSL/TLS support (no cert file) - proxying from :64667 to targets in /var/lib/kimchi/vnc-tokens [18/Feb/2014:09:54:05] ENGINE Serving on 0.0.0.0:8000 [18/Feb/2014:09:54:05] ENGINE Serving on 0.0.0.0:8001 *** Running feature tests *** 127.0.0.1 - - [18/Feb/2014:09:54:05] "HEAD /images/icon-fedora.png HTTP/1.1" 200 4449 "" "" 127.0.0.1 - - [18/Feb/2014:09:54:05] "GET /images/icon-fedora.png HTTP/1.1" 206 4449 "" "" 127.0.0.1 - - [18/Feb/2014:09:54:05] "HEAD /images/icon-fedora.png HTTP/1.1" 200 4449 "" "" 127.0.0.1 - - [18/Feb/2014:09:54:05] "GET /images/icon-fedora.png HTTP/1.1" 206 4449 "" "" *** Feature tests completed *** Ramon Medeiros (1): Forbid non-root users to start kimchi src/kimchi/server.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) -- 1.8.3.1

Only root users can use kimchi. If a non-root user tries to start, some error messages to access data files and libvirt features will be displayed. Signed-off-by: Ramon Medeiros <ramonn@linux.vnet.ibm.com> --- src/kimchi/server.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/kimchi/server.py b/src/kimchi/server.py index 6dd0404..f48b2f8 100644 --- a/src/kimchi/server.py +++ b/src/kimchi/server.py @@ -38,7 +38,7 @@ from kimchi.control import sub_nodes from kimchi.root import KimchiRoot from kimchi.utils import get_enabled_plugins, import_class - +NOT_ROOT_USER = "You need root privileges to run this script.\nExiting." LOGGING_LEVEL = {"debug": logging.DEBUG, "info": logging.INFO, "warning": logging.WARNING, @@ -269,7 +269,21 @@ class Server(object): def stop(self): cherrypy.engine.exit() +def checkRootUser(): + """ + Checks if the running user is root + + @rtype: None + @returns: Nothing + """ + if os.geteuid() != 0: + exit(NOT_ROOT_USER) def main(options): + + # check if user is root + checkRootUser() + + # user is root: start kimchi srv = Server(options) srv.start() -- 1.8.3.1
participants (1)
-
Ramon Medeiros