I'm writing a python application that will do some operations that will require root privileges. Instead of asking for user password every time i decided to use server client model.

A python script will be executed as root user using pkexec and it will act as a server. The main python script (gui) will ask the server to execute the commands it needs.

A minimal reproducible example:

while True:
    words = message.split()

    if words[0] =='get_os':
    elif words[0] =='chroot':
        socket.send(b"started chroot")
    elif words[0]=='reinstall_grub_package':

Is this method secure? Does this have any vulnerablities?

1 Answer 1



It's as secure as your authentication method. Accepting even predefined commands to be run as root may have some knock on effect which wasn't expected at engineering time. The server should still authenticate the client. This could be done using mutual TLS so no user interaction is required but they still should be authenticated. Worst case this application could become SSH into your server, it should be treated as such.

Least Privilege:

Servers should be run as least privilege. If there is ever an exploit in the server's code or one in the platform (Python, C, *nix) remote code execution or escape to shell will be pretty bad if the server is run as root. Servers should be evaluated for what permissions are actually needed and run at a level which gives them exactly that many permissions.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .