security - run part of python script as sudo -


i'm trying run part of script task.py in sudo mode. ideally run task.py following structure:

if __name__ == '__main__':     print('running normal parts')             .            .              .     . [running normal commands] .     .            .              .      print('running sudo parts')     .            .              .     .  [running sudo commands]  .     .            .              . 

where don't have enter password sudo parts of script can make single call $ python task.py command line.

is there nice tell python run second block sudo? saw subprocess module had way call command sudo privelages, i'd rather not put "sudo parts" separate script "running sudo commands" part.

i highly recommend putting sudo parts separate script documentation recommended. approach improves security posture of script dramatically part necessary execute elevated privileges (aka "least privilege"--a fundamental security principle).

i haven't read documentation in detail, suspect mentions limiting write privileges sudo portion of script , file or resource may read from. trust me, there great reasons this...


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -