pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
About revoking large number of privileges; And the PUBLIC role.
6+ messages / 5 participants
[nested] [flat]

* About revoking large number of privileges; And the PUBLIC role.
@ 2022-07-07 07:47 Dominique Devienne <ddevienne@gmail.com>
  2022-07-07 13:52 ` Re: About revoking large number of privileges; And the PUBLIC role. Tom Lane <tgl@sss.pgh.pa.us>
  2022-07-08 09:24 ` Re: About revoking large number of privileges; And the PUBLIC role. Peter J. Holzer <hjp-pgsql@hjp.at>
  2022-07-15 17:33 ` Re: About revoking large number of privileges; And the PUBLIC role. Stephen Frost <sfrost@snowman.net>
  0 siblings, 3 replies; 6+ messages in thread

From: Dominique Devienne @ 2022-07-07 07:47 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

Hi. I'm struggling to delete databases because of grants to roles on
objects of those DBs.

These DBs can have a large'ish number of schemas, 100-300 is typical.
and define a bunch of ROLEs "specific" to those schemas. Normally "login user"
ROLEs are never granted explicit access to objects, instead only the
"db specific" ROLEs
get those grants, and regular users are granted some of those ROLEs.

So my goal is to delete all those "db specific" ROLEs, then the DB
with all its schemas.
Which implies REVOKE'ing grants on all those "db specific" ROLEs first.
(and "login users" just implicitly lose membership in "db specific"
roles when the latter are dropped)

OK, so to help me achieve that "mass revoking", I thought I'd use pg_shdepend,
but turns out to not be that easy to figure this shared catalog out...
I'm made some
progress on that, but then trying various manual REVOKEs, I often don't see any
changes in pg_shdepend, and I'm not sure whether it's because of PUBLIC, or
because of DEFAULT PRIVILEGES, or because I'm not always revoking using the
same ROLE as the one that did the grants, or something else I don't
yet know about...

So I'd thought I'd seek clarifications here, and go back to asking a
few basic basic-principle questions.

The way the GRANTs are made right now is via:
`ALTER DEFAULT PRIVILEGES IN SCHEMA $schema GRANT $priv TO $role`

With (so far) $priv taking all these values:
- "SELECT ON TABLES",
- "USAGE, SELECT ON SEQUENCES",
- "EXECUTE ON ROUTINES",
- "USAGE ON TYPES".

the default privileges are updated *before* schema objects are created.
those all "db specific" (and "schema specific" too) roles are getting
their object grants via DEFAULT PRIVILEGES.

So my first question is whether revoking from the DEFAULT PRIVILEGES
is enough to "ungrant" all those object privileges?

My reading of the doc seem to imply it does, but after for example

ALTER DEFAULT PRIVILEGES IN SCHEMA $schema REVOKE SELECT ON TABLES FROM $role

nothing in pg_shdepend changed.  Could it be related to the PUBLIC role?

Which bring me to questions on PUBLIC. I suspect there's something I
don't understand here.


^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: About revoking large number of privileges; And the PUBLIC role.
  2022-07-07 07:47 About revoking large number of privileges; And the PUBLIC role. Dominique Devienne <ddevienne@gmail.com>
@ 2022-07-07 13:52 ` Tom Lane <tgl@sss.pgh.pa.us>
  2022-07-07 14:36   ` Re: About revoking large number of privileges; And the PUBLIC role. Dominique Devienne <ddevienne@gmail.com>
  2 siblings, 1 reply; 6+ messages in thread

From: Tom Lane @ 2022-07-07 13:52 UTC (permalink / raw)
  To: Dominique Devienne <ddevienne@gmail.com>; +Cc: pgsql-general@lists.postgresql.org

Dominique Devienne <ddevienne@gmail.com> writes:
> Hi. I'm struggling to delete databases because of grants to roles on
> objects of those DBs.

> These DBs can have a large'ish number of schemas, 100-300 is typical.
> and define a bunch of ROLEs "specific" to those schemas. Normally "login user"
> ROLEs are never granted explicit access to objects, instead only the
> "db specific" ROLEs
> get those grants, and regular users are granted some of those ROLEs.

> So my goal is to delete all those "db specific" ROLEs, then the DB
> with all its schemas.
> Which implies REVOKE'ing grants on all those "db specific" ROLEs first.

You should not really have to revoke those manually.
The normal process for that is to use DROP OWNED BY.

https://www.postgresql.org/docs/current/role-removal.html

			regards, tom lane





^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: About revoking large number of privileges; And the PUBLIC role.
  2022-07-07 07:47 About revoking large number of privileges; And the PUBLIC role. Dominique Devienne <ddevienne@gmail.com>
  2022-07-07 13:52 ` Re: About revoking large number of privileges; And the PUBLIC role. Tom Lane <tgl@sss.pgh.pa.us>
@ 2022-07-07 14:36   ` Dominique Devienne <ddevienne@gmail.com>
  2022-07-07 16:10     ` Re: About revoking large number of privileges; And the PUBLIC role. Laurenz Albe <laurenz.albe@cybertec.at>
  0 siblings, 1 reply; 6+ messages in thread

From: Dominique Devienne @ 2022-07-07 14:36 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-general@lists.postgresql.org

On Thu, Jul 7, 2022 at 3:52 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
>
> Dominique Devienne <ddevienne@gmail.com> writes:
> > Hi. I'm struggling to delete databases because of grants to roles on
> > objects of those DBs.
>
> > These DBs can have a large'ish number of schemas, 100-300 is typical.
> > and define a bunch of ROLEs "specific" to those schemas. Normally "login user"
> > ROLEs are never granted explicit access to objects, instead only the
> > "db specific" ROLEs
> > get those grants, and regular users are granted some of those ROLEs.
>
> > So my goal is to delete all those "db specific" ROLEs, then the DB
> > with all its schemas.
> > Which implies REVOKE'ing grants on all those "db specific" ROLEs first.
>
> You should not really have to revoke those manually.
> The normal process for that is to use DROP OWNED BY.

Except we already went through that, that DROP OWNED BY acquires too many locks.
Increasing max_locks_per_transaction when it fails is just not an option IMHO.
One user had to raise it to 32K for his particular DB, which is not
even that large.

Or are you saying setting it to 1M or 1B is "safe", and should be
required setup for users?

Is revoking privileges taking locks? Is dropping a DB taking locks?
If neither are, then I can work around the limitations of DROP OWNED BY.

So will the community help me figure this out?

BTW, I'm also hoping revoking privs, and dropping roles and dbs will
be faster than DROP OWNED BY.
That DB took 30min to 1h to get rid of, via DROP OWNED BY, which seems
to long to delete a bunch of files, no?





^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: About revoking large number of privileges; And the PUBLIC role.
  2022-07-07 07:47 About revoking large number of privileges; And the PUBLIC role. Dominique Devienne <ddevienne@gmail.com>
  2022-07-07 13:52 ` Re: About revoking large number of privileges; And the PUBLIC role. Tom Lane <tgl@sss.pgh.pa.us>
  2022-07-07 14:36   ` Re: About revoking large number of privileges; And the PUBLIC role. Dominique Devienne <ddevienne@gmail.com>
@ 2022-07-07 16:10     ` Laurenz Albe <laurenz.albe@cybertec.at>
  0 siblings, 0 replies; 6+ messages in thread

From: Laurenz Albe @ 2022-07-07 16:10 UTC (permalink / raw)
  To: Dominique Devienne <ddevienne@gmail.com>; Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-general@lists.postgresql.org

On Thu, 2022-07-07 at 16:36 +0200, Dominique Devienne wrote:
> > > So my goal is to delete all those "db specific" ROLEs, then the DB
> > > with all its schemas.
> > > Which implies REVOKE'ing grants on all those "db specific" ROLEs first.
> > 
> > You should not really have to revoke those manually.
> > The normal process for that is to use DROP OWNED BY.
> 
> Except we already went through that, that DROP OWNED BY acquires too many locks.
> Increasing max_locks_per_transaction when it fails is just not an option IMHO.
> One user had to raise it to 32K for his particular DB, which is not
> even that large.
> 
> Or are you saying setting it to 1M or 1B is "safe", and should be
> required setup for users?

If you want to do this on a routine basis, you are doing something wrong.
Never grant a user privileges if the user could be removed.
Use groups in that case.

For a one-time cleanup operation, increasing "max_locks_per_transaction"
and restarting is painful, but not impossible.  See it as down time.

> Is revoking privileges taking locks?

Yes.

> Is dropping a DB taking locks?

Not a lot.  That should never be a problem.

> If neither are, then I can work around the limitations of DROP OWNED BY.
> 
> So will the community help me figure this out?
> 
> BTW, I'm also hoping revoking privs, and dropping roles and dbs will
> be faster than DROP OWNED BY.
> That DB took 30min to 1h to get rid of, via DROP OWNED BY, which seems
> to long to delete a bunch of files, no?

As I wrote, avoid getting there in the first place.

Yours,
Laurenz Albe





^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: About revoking large number of privileges; And the PUBLIC role.
  2022-07-07 07:47 About revoking large number of privileges; And the PUBLIC role. Dominique Devienne <ddevienne@gmail.com>
@ 2022-07-08 09:24 ` Peter J. Holzer <hjp-pgsql@hjp.at>
  2 siblings, 0 replies; 6+ messages in thread

From: Peter J. Holzer @ 2022-07-08 09:24 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

On 2022-07-07 09:47:38 +0200, Dominique Devienne wrote:
> Hi. I'm struggling to delete databases because of grants to roles on
> objects of those DBs.

I don't understand this. You can drop objects (and databases containing
objects) with grants to existing roles. It would be very inconvenient if
that wasn't possible.

Do you have an example on where a grant prevents dropping an object?

        hp

-- 
   _  | Peter J. Holzer    | Story must make more sense than reality.
|_|_) |                    |
| |   | hjp@hjp.at         |    -- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |       challenge!"

Attachments:

  signature.asc (application/pgp-signature, 832B) download

^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: About revoking large number of privileges; And the PUBLIC role.
  2022-07-07 07:47 About revoking large number of privileges; And the PUBLIC role. Dominique Devienne <ddevienne@gmail.com>
@ 2022-07-15 17:33 ` Stephen Frost <sfrost@snowman.net>
  2 siblings, 0 replies; 6+ messages in thread

From: Stephen Frost @ 2022-07-15 17:33 UTC (permalink / raw)
  To: Dominique Devienne <ddevienne@gmail.com>; +Cc: pgsql-general@lists.postgresql.org

Greetings,

* Dominique Devienne (ddevienne@gmail.com) wrote:
> So my goal is to delete all those "db specific" ROLEs, then the DB
> with all its schemas.

If you want to drop the database anyway.. then why not simply do that
first?  Nothing can be connected to a DB that's being dropped and we
don't actually try to lock all the objects in a to-be-dropped DB.

Thanks,

Stephen

Attachments:

  signature.asc (application/pgp-signature, 818B) download

^ permalink  raw  reply  [nested|flat] 6+ messages in thread


end of thread, other threads:[~2022-07-15 17:33 UTC | newest]

Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2022-07-07 07:47 About revoking large number of privileges; And the PUBLIC role. Dominique Devienne <ddevienne@gmail.com>
2022-07-07 13:52 ` Tom Lane <tgl@sss.pgh.pa.us>
2022-07-07 14:36   ` Dominique Devienne <ddevienne@gmail.com>
2022-07-07 16:10     ` Laurenz Albe <laurenz.albe@cybertec.at>
2022-07-08 09:24 ` Peter J. Holzer <hjp-pgsql@hjp.at>
2022-07-15 17:33 ` Stephen Frost <sfrost@snowman.net>

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