pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Bryn Llewellyn <bryn@yugabyte.com>
To: David G. Johnston <david.g.johnston@gmail.com>
To: Tom Lane PostgreSQL <tgl@sss.pgh.pa.us>
Cc: jeremy@musicsmith.net, pgsql-general list <pgsql-general@lists.postgresql.org>
Subject: Re: "grant usage on schema" confers the ability to execute all user-defined functions in that schema, with needing to grant "execute"
Date: Fri, 11 Feb 2022 15:48:29 -0800
Message-ID: <613f1225-26ae-6772-c5da-1cb725674e4f@aklaver.com> (raw)
In-Reply-To: <2162E383-66F7-432A-BFEF-16B922C57C79@yugabyte.com>
References: <0994D6C4-EDF0-4854-B528-88DDE429172E@yugabyte.com>
	<CAKFQuwZUuL6ek+6noEg13eXJBqK9WKhQww-wn+pqowf+Qub3UA@mail.gmail.com>
	<46C22E9C-280C-446E-911F-6915702E554E@yugabyte.com>
	<2188505.1644617120@sss.pgh.pa.us>
	<CAKFQuwaQo9_KjEniKBhq=kGJWFS4TSRyJ9NS7WAO4nzmsJxMmg@mail.gmail.com>
	<2162E383-66F7-432A-BFEF-16B922C57C79@yugabyte.com>

On 2/11/22 15:14, Bryn Llewellyn wrote:
>> /david.g.johnston@gmail.com <mailto:david.g.johnston@gmail.com> wrote:/
>>

> I looked at Chapter 52, "System Catalogs" at 
> https://www.postgresql.org/docs/current/catalogs.html 
> <https://www.postgresql.org/docs/current/catalogs.html;. It lists 97 
> relations. I'll have to defer reading about every one of these to 
> another day. I searched the page for likely names looking for ones with 
> "priv" and "rol". There's just a small number of hits. I drilled down on 
> these. But none seemed to help finding out which objects, of which 
> kinds, have which privileges (or roles) granted to which grantees.
> 
> Which catalog relations are sufficient to support a query that lists 
> out, for example, every user-defined function and procedure with its (at 
> least first-level) grantees?

Tip if you do:

psql -d test -U postgres -h localhost -E

the -E will get you the queries for the \ meta-commands.

So:

\df+ tag_changeset_fnc

Yields:

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 p.prokind
   WHEN 'a' THEN 'agg'
   WHEN 'w' THEN 'window'
   WHEN 'p' THEN 'proc'
   ELSE 'func'
  END as "Type",
  CASE
   WHEN p.provolatile = 'i' THEN 'immutable'
   WHEN p.provolatile = 's' THEN 'stable'
   WHEN p.provolatile = 'v' THEN 'volatile'
  END as "Volatility",
  CASE
   WHEN p.proparallel = 'r' THEN 'restricted'
   WHEN p.proparallel = 's' THEN 'safe'
   WHEN p.proparallel = 'u' THEN 'unsafe'
  END as "Parallel",
  pg_catalog.pg_get_userbyid(p.proowner) as "Owner",
  CASE WHEN prosecdef THEN 'definer' ELSE 'invoker' END AS "Security",
  pg_catalog.array_to_string(p.proacl, E'\n') AS "Access privileges",
  l.lanname as "Language",
  p.prosrc as "Source code",
  pg_catalog.obj_description(p.oid, 'pg_proc') as "Description"
FROM pg_catalog.pg_proc p
      LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace
      LEFT JOIN pg_catalog.pg_language l ON l.oid = p.prolang
WHERE p.proname OPERATOR(pg_catalog.~) '^(tag_changeset_fnc)$' COLLATE 
pg_catalog.default
   AND pg_catalog.pg_function_is_visible(p.oid)
ORDER BY 1, 2, 4;

The parts you would be interested in are "Owner", "Security" and "Access 
privileges". You could modify the query to slim the results down some.

-- 
Adrian Klaver
adrian.klaver@aklaver.com





view thread (18+ messages)  latest in thread

Message-ID: <613f1225-26ae-6772-c5da-1cb725674e4f@aklaver.com>
Permalink:  ../613f1225-26ae-6772-c5da-1cb725674e4f@aklaver.com/
Also on:    postgresql.org/message-id/613f1225-26ae-6772-c5da-1cb725674e4f@aklaver.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: adrian.klaver@aklaver.com, bryn@yugabyte.com, david.g.johnston@gmail.com, tgl@sss.pgh.pa.us
  Subject: Re: "grant usage on schema" confers the ability to execute all user-defined functions in that schema, with needing to grant "execute"
  In-Reply-To: <613f1225-26ae-6772-c5da-1cb725674e4f@aklaver.com>
  References: <0994D6C4-EDF0-4854-B528-88DDE429172E@yugabyte.com> <CAKFQuwZUuL6ek+6noEg13eXJBqK9WKhQww-wn+pqowf+Qub3UA@mail.gmail.com> <46C22E9C-280C-446E-911F-6915702E554E@yugabyte.com> <2188505.1644617120@sss.pgh.pa.us> <CAKFQuwaQo9_KjEniKBhq=kGJWFS4TSRyJ9NS7WAO4nzmsJxMmg@mail.gmail.com> <2162E383-66F7-432A-BFEF-16B922C57C79@yugabyte.com> <613f1225-26ae-6772-c5da-1cb725674e4f@aklaver.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox