Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / amd64 / html / python / lib / restricted.html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<link rel="STYLESHEET" href="lib.css" type='text/css' />
<link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" />
<link rel='start' href='../index.html' title='Python Documentation Index' />
<link rel="first" href="lib.html" title='Python Library Reference' />
<link rel='contents' href='contents.html' title="Contents" />
<link rel='index' href='genindex.html' title='Index' />
<link rel='last' href='about.html' title='About this document...' />
<link rel='help' href='about.html' title='About this document...' />
<link rel="next" href="language.html" />
<link rel="prev" href="tkinter.html" />
<link rel="parent" href="lib.html" />
<link rel="next" href="module-rexec.html" />
<meta name='aesop' content='information' />
<title>17. Restricted Execution </title>
</head>
<body>
<DIV CLASS="navigation">
<div id='top-navigation-panel' xml:id='top-navigation-panel'>
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="16.6 Other Graphical User"
href="other-gui-packages.html"><img src='../icons/previous.png'
border='0' height='32' alt='Previous Page' width='32' /></A></td>
<td class='online-navigation'><a rel="parent" title="Python Library Reference"
href="lib.html"><img src='../icons/up.png'
border='0' height='32' alt='Up One Level' width='32' /></A></td>
<td class='online-navigation'><a rel="next" title="17.1 rexec "
href="module-rexec.html"><img src='../icons/next.png'
border='0' height='32' alt='Next Page' width='32' /></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
href="contents.html"><img src='../icons/contents.png'
border='0' height='32' alt='Contents' width='32' /></A></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
border='0' height='32' alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
href="genindex.html"><img src='../icons/index.png'
border='0' height='32' alt='Index' width='32' /></A></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="other-gui-packages.html">16.6 Other Graphical User</A>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="lib.html">Python Library Reference</A>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="module-rexec.html">17.1 rexec </A>
</div>
<hr /></div>
</DIV>
<!--End of Navigation Panel-->
<H1><A NAME="SECTION0019000000000000000000"></A><A NAME="restricted"></A>
<BR>
17. Restricted Execution
</H1>
<P>
<div class="warning"><b class="label">Warning:</b>
In Python 2.3 these modules have been disabled due to various known
and not readily fixable security holes. The modules are still
documented here to help in reading old code that uses the
<tt class="module">rexec</tt> and <tt class="module">Bastion</tt> modules.
</div>
<P>
<em>Restricted execution</em> is the basic framework in Python that allows
for the segregation of trusted and untrusted code. The framework is based on the
notion that trusted Python code (a <em>supervisor</em>) can create a
``padded cell' (or environment) with limited permissions, and run the
untrusted code within this cell. The untrusted code cannot break out
of its cell, and can only interact with sensitive system resources
through interfaces defined and managed by the trusted code. The term
``restricted execution'' is favored over ``safe-Python''
since true safety is hard to define, and is determined by the way the
restricted environment is created. Note that the restricted
environments can be nested, with inner cells creating subcells of
lesser, but never greater, privilege.
<P>
An interesting aspect of Python's restricted execution model is that
the interfaces presented to untrusted code usually have the same names
as those presented to trusted code. Therefore no special interfaces
need to be learned to write code designed to run in a restricted
environment. And because the exact nature of the padded cell is
determined by the supervisor, different restrictions can be imposed,
depending on the application. For example, it might be deemed
``safe'' for untrusted code to read any file within a specified
directory, but never to write a file. In this case, the supervisor
may redefine the built-in <tt class="function">open()</tt> function so that it raises
an exception whenever the <var>mode</var> parameter is <code>'w'</code>. It
might also perform a <tt class="cfunction">chroot()</tt>-like operation on the
<var>filename</var> parameter, such that root is always relative to some
safe ``sandbox'' area of the filesystem. In this case, the untrusted
code would still see an built-in <tt class="function">open()</tt> function in its
environment, with the same calling interface. The semantics would be
identical too, with <tt class="exception">IOError</tt>s being raised when the
supervisor determined that an unallowable parameter is being used.
<P>
The Python run-time determines whether a particular code block is
executing in restricted execution mode based on the identity of the
<code>__builtins__</code> object in its global variables: if this is (the
dictionary of) the standard <tt class="module"><a href="module-builtin.html">__builtin__</a></tt> module,
the code is deemed to be unrestricted, else it is deemed to be
restricted.
<P>
Python code executing in restricted mode faces a number of limitations
that are designed to prevent it from escaping from the padded cell.
For instance, the function object attribute <tt class="member">func_globals</tt> and
the class and instance object attribute <tt class="member">__dict__</tt> are
unavailable.
<P>
Two modules provide the framework for setting up restricted execution
environments:
<P>
<table class='synopsistable' valign='baseline'>
<tr class='oddrow'>
<td><b><tt class='module'><a href='module-rexec.html'>rexec</a></tt></b></td>
<td>&nbsp;</td>
<td class='synopsis'>Basic restricted execution framework.</td></tr>
<tr><td><b><tt class='module'><a href='module-Bastion.html'>Bastion</a></tt></b></td>
<td>&nbsp;</td>
<td class='synopsis'>Providing restricted access to objects.</td></tr>
</table>
<BR>
<P>
<div class="seealso">
<p class="heading">See Also:</p>
<dl compact="compact" class="seetitle">
<dt><em class="citetitle"><a href="http://grail.sourceforge.net/"
>Grail Home Page</a></em></dt>
<dd>Grail, an Internet browser written in Python, uses these
modules to support Python applets. More
information on the use of Python's restricted execution
mode in Grail is available on the Web site.</dd>
</dl>
</div>
<DIV CLASS="navigation">
<div class='online-navigation'>
<p></p><hr />
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="16.6 Other Graphical User"
href="other-gui-packages.html"><img src='../icons/previous.png'
border='0' height='32' alt='Previous Page' width='32' /></A></td>
<td class='online-navigation'><a rel="parent" title="Python Library Reference"
href="lib.html"><img src='../icons/up.png'
border='0' height='32' alt='Up One Level' width='32' /></A></td>
<td class='online-navigation'><a rel="next" title="17.1 rexec "
href="module-rexec.html"><img src='../icons/next.png'
border='0' height='32' alt='Next Page' width='32' /></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
href="contents.html"><img src='../icons/contents.png'
border='0' height='32' alt='Contents' width='32' /></A></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
border='0' height='32' alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
href="genindex.html"><img src='../icons/index.png'
border='0' height='32' alt='Index' width='32' /></A></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="other-gui-packages.html">16.6 Other Graphical User</A>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="lib.html">Python Library Reference</A>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="module-rexec.html">17.1 rexec </A>
</div>
</div>
<hr />
<span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span>
</DIV>
<!--End of Navigation Panel-->
<ADDRESS>
See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
</ADDRESS>
</BODY>
</HTML>