ubuntu - How do I change to su to modify a file in ruby script -


i have existing ruby on rails app work fine, need add line system file app not have access to. there simple way open file su? (ruby 1.9.3, rails 3.2, ubuntu 12.4)

it's bad idea security perspective allow general su or sudo privileges application accepts requests world. couple safer approaches:

1) change group ownership of particular system file share group application user belongs , set group-write permission on file.

# assuming want manipulate /etc/foobar , app runs user rails in group rails chgrp rails /etc/foobar chmod g+rw /etc/foobar 

2) safer yet. write separate program implements limited changes target system file based on arguments passed it. enable rails app user have passwordless sudo privledge execute 1 program. see sudoers documentation info on how enable limited privilege.

with either method, careful not use data got outside application source without validating via formal parser and/or whitelist.


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -