将 EXECUTE 授予许多 PostGIS 函数

发布于 2024-09-26 16:06:42 字数 373 浏览 3 评论 0原文

我有一个基于 MapServer 的 Web 应用程序,它使用 PostGIS 作为底层数据库扩展。现在我想要一个用于 MapServer 的专用数据库角色,因为我不想通过 postgres 超级用户访问数据库。该角色应该只具有公共表的 SELECT 权限(这很容易实现)和公共 PostGIS 函数的 EXECUTE 权限。

出现了几个问题:所有 PostGIS 相关函数是否都存储在数据库的公共模式中,或者还有其他需要考虑的吗?

如何从数据库的 information_schema 或 pg_catalog 中提取所有函数信息 - 即函数名称、参数数量和名称?我需要此信息来将函数(参数)上的 GRANT EXECUTE 授予 MapServerUser 语句!

先感谢您!!!

I have a Web Application which is based on MapServer, which uses PostGIS as underlying database extension. Now I want to have a dedicated database role which is used for MapServer, cause I don't want to access the database via the postgres superuser. This role should only have SELECT permission on public tables (which is easy to achieve) and EXECUTE permissions on public PostGIS functions.

Several questions arise: Are ALL the PostGIS relevant functions stored in the public schema of a database or is there anything else to consider?

How can I extract all the functions information - i.e. function name, number and names of arguments - from the information_schema or the pg_catalog of the database?! I need this information for the GRANT EXECUTE on function(args) to MapServerUser statements!

Thank you in advance!!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

静赏你的温柔 2024-10-03 16:06:42

在 PostgreSQL 8.4.x 中:

SELECT n.nspname as "Schema",
  p.proname as "Name",
  pg_catalog.pg_get_function_result(p.oid) as "Result data type",
  pg_catalog.pg_get_function_arguments(p.oid) as "Argument data types",
CASE
  WHEN p.proisagg THEN 'agg'
  WHEN p.proiswindow THEN 'window'
  WHEN p.prorettype = 'pg_catalog.trigger'::pg_catalog.regtype THEN 'trigger'
  ELSE 'normal'
END as "Type"
FROM pg_catalog.pg_proc p
    LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace
WHERE pg_catalog.pg_function_is_visible(p.oid)
     AND n.nspname <> 'pg_catalog'
  AND n.nspname <> 'information_schema'
ORDER BY 1, 2, 4;

通过使用 -E 参数运行 psql(显示隐藏查询)然后运行 ​​\df 命令来找到。

另外,PostgreSQL 中的“公共”模式就是这样命名的。它没有什么特殊意义。这是一个坏名字。您需要注意的是“公共”角色(全部大写)。虽然表不会自动被授予 PUBLIC 角色,但我的经验是 PUBLIC 自动获得使用 SECURITY INVOKER 定义的函数的执行权限。

In PostgreSQL 8.4.x:

SELECT n.nspname as "Schema",
  p.proname as "Name",
  pg_catalog.pg_get_function_result(p.oid) as "Result data type",
  pg_catalog.pg_get_function_arguments(p.oid) as "Argument data types",
CASE
  WHEN p.proisagg THEN 'agg'
  WHEN p.proiswindow THEN 'window'
  WHEN p.prorettype = 'pg_catalog.trigger'::pg_catalog.regtype THEN 'trigger'
  ELSE 'normal'
END as "Type"
FROM pg_catalog.pg_proc p
    LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace
WHERE pg_catalog.pg_function_is_visible(p.oid)
     AND n.nspname <> 'pg_catalog'
  AND n.nspname <> 'information_schema'
ORDER BY 1, 2, 4;

Found by running psql with the -E parameter (show hidden queries) and then running the \df command.

Also, the "public" schema in PostgreSQL is just named that way. It carries no special meaning. It's a bad name. What you DO need to look out for is the "PUBLIC" role (all caps). While tables are not automatically granted the PUBLIC role, my experience is that PUBLIC automatically gets execute permission on functions defined with SECURITY INVOKER.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文