Add support for security invoker views.
authorDean Rasheed <dean.a.rasheed@gmail.com>
Tue, 22 Mar 2022 10:28:10 +0000 (10:28 +0000)
committerDean Rasheed <dean.a.rasheed@gmail.com>
Tue, 22 Mar 2022 10:28:10 +0000 (10:28 +0000)
commit7faa5fc84bf46ea6c543993cffb8be64dff60d25
tree5e2f4c3b96cd77946916cd64369f3d71d8e86dc8
parentf5576a21b0778f275d7418f6f7a44d9400ee90aa
Add support for security invoker views.

A security invoker view checks permissions for accessing its
underlying base relations using the privileges of the user of the
view, rather than the privileges of the view owner. Additionally, if
any of the base relations are tables with RLS enabled, the policies of
the user of the view are applied, rather than those of the view owner.

This allows views to be defined without giving away additional
privileges on the underlying base relations, and matches a similar
feature available in other database systems.

It also allows views to operate more naturally with RLS, without
affecting the assignments of policies to users.

Christoph Heiss, with some additional hacking by me. Reviewed by
Laurenz Albe and Wolfgang Walther.

Discussion: https://postgr.es/m/b66dd6d6-ad3e-c6f2-8b90-47be773da240%40cybertec.at
20 files changed:
doc/src/sgml/ref/alter_view.sgml
doc/src/sgml/ref/create_policy.sgml
doc/src/sgml/ref/create_view.sgml
doc/src/sgml/ref/lock.sgml
doc/src/sgml/rules.sgml
src/backend/access/common/reloptions.c
src/backend/commands/lockcmds.c
src/backend/rewrite/rewriteHandler.c
src/backend/utils/cache/relcache.c
src/include/utils/rel.h
src/test/regress/expected/create_view.out
src/test/regress/expected/lock.out
src/test/regress/expected/rowsecurity.out
src/test/regress/expected/rules.out
src/test/regress/expected/updatable_views.out
src/test/regress/sql/create_view.sql
src/test/regress/sql/lock.sql
src/test/regress/sql/rowsecurity.sql
src/test/regress/sql/rules.sql
src/test/regress/sql/updatable_views.sql