pgsql: Ensure that pg_auth_members.grantor is always valid.

Поиск
Список
Период
Сортировка
От Robert Haas
Тема pgsql: Ensure that pg_auth_members.grantor is always valid.
Дата
Msg-id E1oOjHN-00092c-RO@gemulon.postgresql.org
обсуждение исходный текст
Ответы Re: pgsql: Ensure that pg_auth_members.grantor is always valid.  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-committers
Ensure that pg_auth_members.grantor is always valid.

Previously, "GRANT foo TO bar" or "GRANT foo TO bar GRANTED BY baz"
would record the OID of the grantor in pg_auth_members.grantor, but
that role could later be dropped without modifying or removing the
pg_auth_members record. That's not great, because we typically try
to avoid dangling references in catalog data.

Now, a role grant depends on the grantor, and the grantor can't be
dropped without removing the grant or changing the grantor.  "DROP
OWNED BY" will remove the grant, just as it does for other kinds of
privileges. "REASSIGN OWNED BY" will not, again just like what we do
in other cases involving privileges.

pg_auth_members now has an OID column, because that is needed in order
for dependencies to work. It also now has an index on the grantor
column, because otherwise dropping a role would require a sequential
scan of the entire table to see whether the role's OID is in use as
a grantor. That probably wouldn't be too large a problem in practice,
but it seems better to have an index just in case.

A follow-on patch is planned with the goal of more thoroughly
rationalizing the behavior of role grants. This patch is just trying
to do enough to make sure that the data we store in the catalogs is at
some basic level valid.

Patch by me, reviewed by Stephen Frost

Discussion: http://postgr.es/m/CA+TgmoaFr-RZeQ+WoQ5nKPv97oT9+aDgK_a5+qWHSgbDsMp1Vg@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/6566133c5f52771198aca07ed18f84519fac1be7

Modified Files
--------------
doc/src/sgml/catalogs.sgml                |   9 ++
src/backend/catalog/catalog.c             |   2 +
src/backend/catalog/dependency.c          |  14 ++-
src/backend/catalog/objectaddress.c       | 108 +++++++++++++++++
src/backend/catalog/pg_shdepend.c         |  47 +++++---
src/backend/catalog/system_views.sql      |   2 +-
src/backend/commands/alter.c              |   1 +
src/backend/commands/event_trigger.c      |   1 +
src/backend/commands/tablecmds.c          |   1 +
src/backend/commands/user.c               | 192 +++++++++++++++++++++++-------
src/include/catalog/dependency.h          |   1 +
src/include/catalog/pg_auth_members.h     |   5 +-
src/test/regress/expected/create_role.out |  16 ++-
src/test/regress/expected/privileges.out  |  32 +++++
src/test/regress/sql/create_role.sql      |   7 +-
src/test/regress/sql/privileges.sql       |  27 +++++
16 files changed, 397 insertions(+), 68 deletions(-)


В списке pgsql-committers по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: pgsql: Improve performance of adjust_appendrel_attrs_multilevel.
Следующее
От: Andres Freund
Дата:
Сообщение: pgsql: Don't add HAVE_LDAP_H HAVE_WINLDAP_H to pg_config.h