• Uncategorized

About linux : How-to-able-postgres-user-to-create-folders-on-other-user-directory

Question Detail

Have a function in postgres like as:

AS $$
    import os
    os.mkdir('/home/%s/data' % TD['new']['user'])

    return "MODIFY"

But when call the function from trigger says: PermisionError[Errno 13] Permission denied: '/home/test/data'.

Postgres database runs the function as postgres user and /home/test is owned by test user. When need two users can access to same folder add a group to other user but in postgres can not add other group to access to other users folders.

How to postgres can access and create folders in other users without set a chmod 777 or open a security problem enabling to all other users to access to the test folder home?

Question Answer

You can create new group testpg, add user test and postgres to it, change folder’s group and grant group write permission to folder.

groupadd mygroup
usermod -a -G test testpg
usermod -a -G postgres testpg
chgrp testpg /home/test
chmod g+rwx /home/test

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.