1

I have a python script which is owned by a particular user and I want to run it from a browser. When I access it from the browser it comes in as www-data user which obviously has very little permissions. Can I do this without changing any permissions or groups? I have tried a few things like Running python script as another user and use pexpect module of python but as www-data has no permissions I cannot fire my script as a different user. My script does not return anything, it generates new data so it needs write permissions.

4
  • How do you "access it from the browser"? Are you going through a web server? Can you install scripts on the web server?
    – tdelaney
    Commented Aug 8, 2013 at 20:17
  • As long as the script has +r permissions for www-data (and the python interpreter +x permissions), it shouldn't matter who owns it. So just chmod it.
    – abarnert
    Commented Aug 8, 2013 at 20:18
  • Had my question before as an answer, sorry. How do you want it to be accessed? Do you want the return data to be displayed in a webbrowser? If you want the last thing, I can help you with that. I have a simple python webserver which will display things on a webpage, you can create a simple do_GET function which will write the return data to a webpage and send it to the webbrowser. However, you are too unclear in the OP.
    – IPDGino
    Commented Aug 8, 2013 at 20:25
  • My only target is running the python script. So I have php script from which I had tried to access the python script directly and didn't work. So I then made a another proxy script and kept that in the webserver which calls the my python script further. Also the data which is created, I don't want to return it. abarnert, I had tried your way earlier but I get permission denied which new files are being written by the script
    – anupam das
    Commented Aug 8, 2013 at 20:57

1 Answer 1

0

If...

  • the script has read permissions for all
  • it only writes to the current directory (or you can configure where it writes)
  • you have a web server on the local machine
  • you can put scripts on that web server

...then something equivalent to this would work:

subprocess.call(['python', '/path/to/script.py'], cwd='/tmp')
2
  • I cannot move my scripts from its current location. I know about this framework called apache thrift which is used for cross language service development. I imagine it to work like a root user which can interact between platforms. I am starting to wonder if my issue is even solvable. Isn't not letting the client make changes in the server a fundamental security feature of client-server architecture?
    – anupam das
    Commented Aug 8, 2013 at 21:07
  • apache thrift is one of many frameworks for client server interaction, but it requires changes on the server (you need to run a thrift service on the server) so you have the same problem. Generally, clients can make changes on servers, but only under the control of server programs. For instance, stackoverflow lets me write this comment which is stored on the server. It doesn't let me take over its server farm to crack passwords. In your case, you have a script on a server that the server doesn't want to let you run. It would be a security violation if you could do it anyway.
    – tdelaney
    Commented Aug 8, 2013 at 21:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.