Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #18724

codecs in a chroot / without fs access

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 <phihag@phihag.de>
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 <phihag@phihag.de>
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 <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.4565.1326157245.27778.python-list@python.org> (permalink)
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

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

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 "<stdin>", line 1, in <module>

(Interestingly, Python goes looking for the literal file "<stdin>" in
sys.path. Wonder what happens if I touch
/usr/lib/python2.7/dist-packages/<stdin>).

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 = [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

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

codecs in a chroot / without fs access Philipp Hagemeister <phihag@phihag.de> - 2012-01-10 01:41 +0100
  Re: codecs in a chroot / without fs access Miki Tebeka <miki.tebeka@gmail.com> - 2012-01-10 08:33 -0800
  Re: codecs in a chroot / without fs access Miki Tebeka <miki.tebeka@gmail.com> - 2012-01-10 08:33 -0800
  Re: codecs in a chroot / without fs access K Richard Pixley <rich@noir.com> - 2012-01-10 08:42 -0800

csiph-web