Обсуждение: Access disk from plpython

Поиск
Список
Период
Сортировка

Access disk from plpython

От
"Rhys A.D. Stewart"
Дата:
Greetings all,

having a permission issue with writing a file using plpython to a local folder, changed permissions to everyone read and write and even changed the owner to postgres. but no joy, any suggestions?

Regards,

Rhys

 

Re: Access disk from plpython

От
Adrian Klaver
Дата:
On 11/14/2012 08:44 AM, Rhys A.D. Stewart wrote:
> Greetings all,
>
> having a permission issue with writing a file using plpython to a local
> folder, changed permissions to everyone read and write and even changed
> the owner to postgres. but no joy, any suggestions?


What is the actual error message?

>
> Regards,
>
> Rhys
>


--
Adrian Klaver
adrian.klaver@gmail.com


Re: Access disk from plpython

От
Adrian Klaver
Дата:
On 11/14/2012 08:48 AM, Rhys A.D. Stewart wrote:
> This is it:
>
> ERROR:  IOError: [Errno 13] Permission denied: '/root/p1/me.txt'
>
> CONTEXT:  Traceback (most recent call last):
>
>    PL/Python anonymous code block, line 3, in <module>
>
>      t = open('/root/p1/me.txt','w')
>
> PL/Python anonymous code block
>

CCing the list.

Does the file already exist?
If so, does the file itself have the correct permissions?

--
Adrian Klaver
adrian.klaver@gmail.com


Re: Access disk from plpython

От
Jeff Janes
Дата:
On Wed, Nov 14, 2012 at 8:44 AM, Rhys A.D. Stewart
<rhys.stewart@gmail.com> wrote:
> Greetings all,
>
> having a permission issue with writing a file using plpython to a local
> folder, changed permissions to everyone read and write and even changed the
> owner to postgres. but no joy, any suggestions?

plpython is a "trusted" langauge.  That means pgsql trusts it not to
allow you to break out of the sandbox and interact directly with the
file system or the database server internals.

If you need to do those things, you can use plpythonu.

Cheers,

Jeff


Re: Access disk from plpython

От
Adrian Klaver
Дата:
On 11/14/2012 09:03 AM, Jeff Janes wrote:
> On Wed, Nov 14, 2012 at 8:44 AM, Rhys A.D. Stewart
> <rhys.stewart@gmail.com> wrote:
>> Greetings all,
>>
>> having a permission issue with writing a file using plpython to a local
>> folder, changed permissions to everyone read and write and even changed the
>> owner to postgres. but no joy, any suggestions?
>
> plpython is a "trusted" langauge.  That means pgsql trusts it not to
> allow you to break out of the sandbox and interact directly with the
> file system or the database server internals.
>
> If you need to do those things, you can use plpythonu.

My understanding is that of Postgres 7.4 plpython does not exist. In
other words only the untrusted version is available.

>
> Cheers,
>
> Jeff
>
>


--
Adrian Klaver
adrian.klaver@gmail.com


Re: Access disk from plpython

От
Adrian Klaver
Дата:
On 11/14/2012 08:56 AM, Rhys A.D. Stewart wrote:
> No it doesn't, I was hoping to create the file.
>

Some testing here confirms it is saving file with postgres user
permissions. I could get it to save by creating a directory owned by the
postgres user in my home directory and saving to there. My guess is a
directory in you path has permissions that are preventing saving. At a
guess, /root/.


--
Adrian Klaver
adrian.klaver@gmail.com


Re: Access disk from plpython

От
Craig Ringer
Дата:
On 11/15/2012 01:08 AM, Adrian Klaver wrote:
On 11/14/2012 09:03 AM, Jeff Janes wrote:
On Wed, Nov 14, 2012 at 8:44 AM, Rhys A.D. Stewart
<rhys.stewart@gmail.com> wrote:
Greetings all,

having a permission issue with writing a file using plpython to a local
folder, changed permissions to everyone read and write and even changed the
owner to postgres. but no joy, any suggestions?

plpython is a "trusted" langauge.  That means pgsql trusts it not to
allow you to break out of the sandbox and interact directly with the
file system or the database server internals.

If you need to do those things, you can use plpythonu.

My understanding is that of Postgres 7.4 plpython does not exist. In other words only the untrusted version is available.

... and that's because Python's design - in particular, the introspection features - means the the restricted mode wasn't particularly restricted. See http://docs.python.org/2/library/restricted.html , http://wiki.python.org/moin/SandboxedPython .
-- Craig Ringer                   http://www.2ndQuadrant.com/PostgreSQL Development, 24x7 Support, Training & Services