2

I'm trying to encapsulate a whole bunch of logic into one Python function and pass that as an argument to remote RPyC method where I want to execute it on the server. But RPyC treats the function as a callback and execute it locally. Is there a way around that? Can I force the server to execute it on the server instead of on the client?

Thank you.

mottosan
  • 466
  • 3
  • 14
  • can you give an example of a function you want to run? is the function already defined in the server process, or a random piece of code? Even if you pass the complete function as a string, it is impossible to pass its entire context (global variables, name bindings, external packages it might call...) – shx2 Jul 19 '14 at 21:28

2 Answers2

3

The teleport_function allows me transport functions from client to server.

http://rpyc.readthedocs.org/en/latest/api/utils_classic.html#rpyc.utils.classic.teleport_function

mottosan
  • 466
  • 3
  • 14
1

RPyC seems to transfer int, long, bool, str, float, unicode, bytes, slice, complex, tuple (of simple types), forzenset (of simple types) as well as the following singletons: None, NotImplemented, and Ellipsis (from the RPyC manual), so as you can send unicode, you can send code as a string, and eval it server side.

Note that if you do so, I'll be able to send things like os.unlink(sys.argv[0]) on your server, or this kind of stuff you may not want. In other words allowing the server to run arbitrary code is a huge security breach.

So if you're in a server to server case, it's a go but I don't think you really need it, if you completely trust both sides, but if it's a client-server application, it's a no go.

If you decide to go this way, eval may not be the right choice, opening your server far too much. You have explore some ways to restrict possibilities, according to what you want to allow your bunch of logic to do, search about "python eval security", you'll find some interesting threads.

Julien Palard
  • 8,736
  • 2
  • 37
  • 44
  • Tomer Filiba (author of RPyC) pointed out the teleport_function in the library that is pretty much what I'm looking for. – mottosan Jul 20 '14 at 23:34