<br><br><div><span class="gmail_quote">On 7/8/06, <b class="gmail_sendername">Talin</b> &lt;<a href="mailto:talin@acm.org">talin@acm.org</a>&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Brett Cannon wrote:<br>&gt; On 7/7/06, Guido van Rossum &lt;<a href="mailto:guido@python.org">guido@python.org</a>&gt; wrote:<br>&gt;&gt; On 7/8/06, Ka-Ping Yee &lt;<a href="mailto:python-dev@zesty.ca">python-dev@zesty.ca
</a>&gt; wrote:<br>&gt;&gt; &gt; I'd like the answer to be yes.&nbsp;&nbsp;It sounded for a while like this<br>&gt;&gt; &gt; was not part of Brett's plan, though.&nbsp;&nbsp;Now i'm not so sure.&nbsp;&nbsp;It<br>&gt;&gt; &gt; sounds like you're also interested in having the answer be yes?
<br>&gt;&gt; &gt;<br>&gt;&gt; &gt; Let's keep talking about and playing with more examples -- i think<br>&gt;&gt; &gt; they'll help us understand what goals we should aim for and what<br>&gt;&gt; &gt; pitfalls to anticipate before we nail down too many details.
<br>&gt;&gt;<br>&gt;&gt; I'd like the answer to be no, because I don't believe that we can<br>&gt;&gt; trust the VM to provide sufficient barriers. The old pre-2.2<br>&gt;&gt; restricted execution mode tried to do this but 
2.2 punched a million<br>&gt;&gt; holes in it. Python isn't designed for this (it doesn't even enforce<br>&gt;&gt; private attributes). I guess this is also the main reason I'm<br>&gt;&gt; skeptical about capabilities for Python.
<br>&gt;<br>&gt; My plan is no.&nbsp;&nbsp;As Guido said, getting this right is&nbsp;&nbsp;feasibly<br>&gt; questionable.&nbsp;&nbsp;I do not plan on trying to have security proxies or such<br>&gt; implemented in Python code; it will need to be in C.&nbsp;&nbsp;If someone comes
<br>&gt; along<br>&gt; and manages to find a way to make Python work without significantly<br>&gt; changing<br>&gt; the languages, great, and we can toss out my security implementation for<br>&gt; that.<br>&gt;<br>&gt; But as of right now, I am not planning on making Python code safe to run in
<br>&gt; Python code.<br><br>It might be possible for the code *outside* the sandbox to create new<br>security policies written in Python.<br><br>Lets start with the concept of a generic &quot;protection&quot; wrapper - its a C
<br>proxy object which can wrap around any Python object, and which can<br>restrict access to a specific set of methods. So for example:<br><br>&nbsp;&nbsp;&nbsp;&nbsp;protected_object = protect(myObject, methods=set('open','close'))<br><br>
'protect' creates a C proxy which restricts access to the object,<br>allowing only those methods listed to be called.<br><br>Now, lets create a security policy, written in Python. The policy is<br>essentially a factory which creates wrapped objects:
<br><br>&nbsp;&nbsp;&nbsp;&nbsp;class MyPolicy:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # Ask the policy to create a file object<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; def file( path, perms ):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if perms == 'r':<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # Trivial example, a real proxy would be more<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # sophisticated, and probably configurable.
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return protect( file( path, perms ),<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; methods=set('open', 'read', 'close') )<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; raise SecurityException<br><br>Now, when we create our sandbox, we pass in the policy:
<br><br>&nbsp;&nbsp;&nbsp;&nbsp;sb = Sandbox( MyPolicy() )<br><br>The sandbox calls 'protect' on the policy object, preventing it from<br>being inspected or called inappropriately.</blockquote><div><br>Using a factory method callback, one could store the PyCodeObject in a C proxy object that just acts as a complete delegate, forwarding all method calls to the internally stored PyCodeObject.&nbsp; That would work.
<br><br><br>For this initial implementation, though, I am not going to try to support this.&nbsp;&nbsp; We can always add support like this later since it doesn't fundamentally break or change anything that is already planned.&nbsp; Let's focus on getting even more basic stuff working before we start to get too fancy.
<br><br>-Brett<br></div></div>