如何授予非超级用户执行pg_read_binary_file函数的权限?

6
在PostgreSQL中,我有一个带有自定义函数的数据库,该函数使用系统函数pg_read_binary_file将文件的二进制内容加载到数据库表中。
如果我在具有超级用户权限的用户下运行此自定义函数,则可以成功执行。但是当用户没有超级用户权限时,我会收到一个错误:
permission denied for function pg_read_binary_file

我认为我所需要做的就是简单地为这个用户授予执行该函数的权限,因此我执行了以下操作:

GRANT
GRANT EXECUTE ON FUNCTION pg_read_binary_file(text,bigint,bigint,boolean) TO someuser;
GRANT EXECUTE ON FUNCTION pg_read_binary_file(text,bigint,bigint) TO someuser; 
GRANT EXECUTE ON FUNCTION pg_read_binary_file(text) TO someuser;

如果我通过检查权限
SELECT proacl FROM pg_proc WHERE proname='pg_read_binary_file';

我得到:
{postgres=X/postgres,someuser=X/postgres}
{postgres=X/postgres,someuser=X/postgres}
{postgres=X/postgres,someuser=X/postgres}

据我所知,现在someuser有权限执行函数pg_read_binary_file。但是当我尝试运行我的自定义函数时,仍然收到相同的错误:
permission denied for function pg_read_binary_file

所以问题是如何授予非超级用户执行函数pg_read_binary_file的权限?可能需要授予一些附加权限,但这并不明显。在Portgres系统函数文档中的pg_read_binary_file中写道:默认情况下仅限超级用户,但可以授予其他用户EXECUTE以运行该函数。我搜索了一些关于如何授予此类权限的附加信息,但没有成功。
1个回答

4
有三种可能性:
  1. You are using an old PostgreSQL version.

    Before commit e79350fef2917522571add750e3e21af293b50fe, this was not governed by permissions on the functions, but by hard-coded checks in the function itself.

    This doesn't seem to be your case, however, because the error messages would then read:

    ERROR:  must be superuser to read files
    
  2. You are not someuser when you try to execute the function. Test with

    SELECT current_user;
    
  3. You are connected to a different database (e.g., you changed the permissions in the postgres database, but someuser connects to a different database).


1
感谢您的回答。这是第3种情况。我授予了数据库postgres的权限,因为我认为每当数据库连接用户时,系统函数都会从postgres数据库调用,并且我只在postgres数据库的对象树中看到了pg_read_binary_file。在您的回答之后,我在工作数据库中授予了权限,现在一切正常运作。所以答案是 - 我必须执行GRANT EXECUTE ON FUNCTION pg_read_binary_file(text) TO someuser;不是在postgres数据库上,而是在工作的数据库上执行。再次感谢您。 - user2248760

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接