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:
message=socket.recv().decode()
words = message.split()
if words[0] =='get_os':
execute_another_root_operation()
socket.send(b'done')
elif words[0] =='chroot':
execute_a_root_operation()
socket.send(b"started chroot")
elif words[0]=='reinstall_grub_package':
reinstall_grub_package()
else:
socket.send(b"unknown")
Is this method secure? Does this have any vulnerablities?