Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!cs.uu.nl!news.stack.nl!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.009 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'skip:[ 40': 0.07; 'python': 0.08; 'content-type:multipart/signed': 0.09; 'design?': 0.09; 'filename:fname piece:signature': 0.09; 'subject:access': 0.09; 'content-type:application/pgp-signature': 0.16; 'filename:fname piece:asc': 0.16; 'filename:fname:signature.asc': 0.16; 'filesystem': 0.16; 'neat': 0.16; 'privileges.': 0.16; 'workaround': 0.16; '>>>': 0.18; 'seems': 0.20; '(most': 0.21; 'wonder': 0.23; 'literal': 0.23; 'traceback': 0.24; 'function': 0.27; 'import': 0.27; 'pass': 0.29; "skip:' 30": 0.29; 'problem': 0.29; 'loads': 0.30; 'skip:g 40': 0.30; 'does': 0.32; 'header :User-Agent:1': 0.33; 'there': 0.33; 'to:addr:python-list': 0.34; 'last):': 0.34; 'try:': 0.34; 'something': 0.35; 'however,': 0.36; 'file': 0.36; 'except': 0.37; 'received:192': 0.37; 'not,': 0.37; 'easiest': 0.38; 'i.e.': 0.39; "i'd": 0.39; 'goes': 0.39; 'to:addr:python.org': 0.40; 'received:192.168': 0.40; 'happens': 0.40; 'love': 0.62; 'subject: / ': 0.63; 'subject:without': 0.67; 'touch': 0.70; 'filesystem.': 0.84; 'forbid': 0.84 Date: Tue, 10 Jan 2012 01:41:04 +0100 From: Philipp Hagemeister User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:8.0) Gecko/20120104 Icedove/8.0 MIME-Version: 1.0 To: python-list@python.org Subject: codecs in a chroot / without fs access X-Enigmail-Version: 1.3.4 OpenPGP: id=FAFB085C Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="------------enig16330BAF5CFBD700358B8707" X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 62 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1326157245 news.xs4all.nl 6921 [2001:888:2000:d::a6]:50377 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:18724 This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enig16330BAF5CFBD700358B8707 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable I want to forbid my application to access the filesystem. The easiest way seems to be chrooting and droping privileges. However, surprisingly, python loads the codecs from the filesystem on-demand, which makes my program crash: >>> import os >>> os.getuid() 0 >>> os.chroot('/tmp') >>> ''.decode('raw-unicode-escape') Traceback (most recent call last): File "", line 1, in (Interestingly, Python goes looking for the literal file "" in sys.path. Wonder what happens if I touch /usr/lib/python2.7/dist-packages/). Is there a neat way to solve this problem, i.e. have access to all codecs in a chroot? If not, I'd love to have a function codecs.preload_all() that does what my workaround does: import codecs,glob,os.path encs =3D [os.path.splitext(os.path.basename(f))[0] for f in glob.glob('/usr/lib/python*/encodings/*.py')] for e in encs: try: codecs.lookup(e) except LookupError: pass # __init__.py or something enumerate /usr/lib/python.*/encodings/*.py and call codecs.lookup for every os.path.splitext(os.path.basename(filename))[0] Dou you see any problem with this design? - Philipp --------------enig16330BAF5CFBD700358B8707 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) iEYEAREKAAYFAk8LiSIACgkQ9eq1gvr7CFz0gQCgnF2n2+Wg8aArEvbWD0pxdKXL ttcAoLczX1p7qJNGh2UPF8WXGCSwS9dM =uuiz -----END PGP SIGNATURE----- --------------enig16330BAF5CFBD700358B8707--