diff --git a/doc/src/sgml/ref/alter_policy.sgml b/doc/src/sgml/ref/alter_policy.sgml
index 2e63206014c..d70bc48f334 100644
--- a/doc/src/sgml/ref/alter_policy.sgml
+++ b/doc/src/sgml/ref/alter_policy.sgml
@@ -90,11 +90,8 @@ ALTER POLICY name ON using_expression
- The USING expression for the policy. This expression will be added as a
- security-barrier qualification to queries which use the table
- automatically. If multiple policies are being applied for a given
- table then they are all combined and added using OR. The USING
- expression applies to records which are being retrieved from the table.
+ The USING expression for the policy.
+ See for details.
@@ -103,11 +100,8 @@ ALTER POLICY name ON check_expression
- The with-check expression for the policy. This expression will be
- added as a WITH CHECK OPTION qualification to queries which use the
- table automatically. If multiple policies are being applied for a
- given table then they are all combined and added using OR. The WITH
- CHECK expression applies to records which are being added to the table.
+ The WITH CHECK expression for the policy.
+ See for details.
diff --git a/doc/src/sgml/ref/create_policy.sgml b/doc/src/sgml/ref/create_policy.sgml
index a4043f629db..72bf6915823 100644
--- a/doc/src/sgml/ref/create_policy.sgml
+++ b/doc/src/sgml/ref/create_policy.sgml
@@ -39,13 +39,13 @@ CREATE POLICY name ON
- A policy grants the ability to SELECT, INSERT, UPDATE, or DELETE rows
- which match the relevant policy expression. Existing table rows are
- checked against the expression specified via USING, while new rows that
- would be created via INSERT or UPDATE are checked against the expression
- specified via WITH CHECK. When a USING expression returns true for a given
+ A policy grants the permission to select, insert, update, or delete rows
+ that match the relevant policy expression. Existing table rows are
+ checked against the expression specified via USING, while new rows that
+ would be created via INSERT or UPDATE are checked against the expression
+ specified via WITH CHECK. When a USING expression returns true for a given
row then that row is visible to the user, while if a false or null is
- returned then the row is not visible. When a WITH CHECK expression
+ returned then the row is not visible. When a WITH CHECK expression
returns true for a row then that row is added, while if a false or null is
returned then an error occurs.
@@ -56,20 +56,21 @@ CREATE POLICY name ON LEAKPROOF may be evaluated before policy
expressions, as they are assumed to be trustworthy.
- For INSERT and UPDATE queries, WITH CHECK expressions are enforced after
- BEFORE triggers are fired, and before any data modifications are made.
- Thus a BEFORE ROW trigger may modify the data to be inserted, affecting
- the result of the security policy check. WITH CHECK expressions are
- enforced before any other constraints.
+ For INSERT and UPDATE statements,
+ WITH CHECK expressions are enforced after
+ BEFORE triggers are fired, and before any data modifications are made.
+ Thus a BEFORE ROW trigger may modify the data to be inserted, affecting
+ the result of the security policy check. WITH CHECK expressions are
+ enforced before any other constraints.
- Policy names are per-table, therefore one policy name can be used for many
+ Policy names are per-table. Therefore, one policy name can be used for many
different tables and have a definition for each table which is appropriate to
that table.
@@ -78,46 +79,19 @@ CREATE POLICY name ON ON CONFLICT DO
+ statement, they will be combined using or
(although ON CONFLICT DO
UPDATE> and INSERT> policies are not combined in this way, but
rather enforced as noted at each stage of ON CONFLICT> execution).
- Further, for commands which can have both USING and WITH CHECK policies (ALL
- and UPDATE), if no WITH CHECK policy is defined then the USING policy will be
- used for both what rows are visible (normal USING case) and which rows will
- be allowed to be added (WITH CHECK case).
- Note that while policies will be applied for explicit queries against tables
- in the system, they are not applied when the system is performing internal
- referential integrity checks or validating constraints. This means there are
- indirect ways to determine that a given value exists. An example of this is
- attempting to insert a duplicate value into a column which is the primary key
- or has a unique constraint. If the insert fails then the user can infer that
- the value already exists (this example assumes that the user is permitted by
- policy to insert records which they are not allowed to see). Another example
- is where a user is allowed to insert into a table which references another,
- otherwise hidden table. Existence can be determined by the user inserting
- values into the referencing table, where success would indicate that the
- value exists in the referenced table. These issues can be addressed by
- carefully crafting policies which prevent users from being able to insert,
- delete, or update records at all which might possibly indicate a value they
- are not otherwise able to see, or by using generated values (e.g.: surrogate
- keys) instead.
+ Further, for commands that can have both USING
+ and WITH CHECK policies (ALL
+ and UPDATE), if no WITH CHECK policy
+ is defined, then the USING policy will be used for both
+ what rows are visible (normal USING case) and which rows
+ will be allowed to be added (WITH CHECK case).
-
-
- Regarding how policy expressions interact with the user: as the expressions
- are added to the user's query directly, they will be run with the rights of
- the user running the overall query. Therefore, users who are using a given
- policy must be able to access any tables or functions referenced in the
- expression or they will simply receive a permission denied error when
- attempting to query the table that has row-level security enabled. This does not change how views
- work, however. As with normal queries and views, permission checks and
- policies for the tables which are referenced by a view will use the view
- owner's rights and any policies which apply to the view owner.
-
-
@@ -194,15 +168,14 @@ CREATE POLICY name ON
-
-
+
Per-Command policies
@@ -216,20 +189,21 @@ CREATE POLICY name ON ALL policy exists and more specific policies
exist, then both the ALL policy and the more
specific policy (or policies) will be combined using
- OR, as usual for overlapping policies.
+ or
, as usual for overlapping policies.
Additionally, ALL policies will be applied to
both the selection side of a query and the modification side, using
- the USING policy for both if only a USING policy has been defined.
-
+ the USING policy for both if only a USING policy has been defined.
+
+
As an example, if an UPDATE is issued, then the
ALL policy will be applicable to both what the
UPDATE will be able to select out as rows to be
- updated (with the USING expression being applied), and it will be
- applied to rows which result from the UPDATE
+ updated (with the USING expression being applied), and it will be
+ applied to rows that result from the UPDATE
statement, to check if they are permitted to be added to the table
- (using the WITH CHECK expression, if defined, and the USING expression
- otherwise). If an INSERT or UPDATE command attempts to add rows to
- the table which do not pass the ALL WITH CHECK
+ (using the WITH CHECK expression, if defined, and the USING expression
+ otherwise). If an INSERT or UPDATE command attempts to add rows to
+ the table that do not pass the ALL WITH CHECK
expression, the entire command will be aborted. Note that if only a
USING clause is specified then that clause will be
used for both USING and
@@ -244,9 +218,9 @@ CREATE POLICY name ON
Using SELECT for a policy means that it will apply
to SELECT commands. The result is that only those
- records from the relation which pass the SELECT
+ records from the relation that pass the SELECT
policy will be returned, even if other records exist in the relation.
- The SELECT policy only accepts the USING expression
+ The SELECT policy only accepts the USING expression
as it only ever applies in cases where records are being retrieved from
the relation.
@@ -258,18 +232,18 @@ CREATE POLICY name ON
Using INSERT for a policy means that it will apply
- to INSERT commands. Rows being inserted which do
- not pass this policy will result in a policy violation ERROR and the
+ to INSERT commands. Rows being inserted that do
+ not pass this policy will result in a policy violation error, and the
entire INSERT command will be aborted. The
- INSERT policy only accepts the WITH CHECK expression
+ INSERT policy only accepts the WITH CHECK expression
as it only ever applies in cases where records are being added to the
relation.
Note that INSERT with ON CONFLICT DO
UPDATE requires that any INSERT policy
- WITH CHECK expression passes for any rows appended to the relation by
- the INSERT path only.
+ WITH CHECK expression passes for any rows appended to the relation by
+ the INSERT path only.
@@ -291,8 +265,8 @@ CREATE POLICY name ON INSERT policy). Any rows whose
resulting values do not pass the WITH CHECK
- expression will cause an ERROR and the entire command will be aborted.
- Note that if only a USING clause is specified then
+ expression will cause an error, and the entire command will be aborted.
+ Note that if only a USING clause is specified, then
that clause will be used for both USING and
WITH CHECK cases.
@@ -304,11 +278,11 @@ CREATE POLICY name ON UPDATE policy must always pass when the
UPDATE path is taken. Any existing row that
necessitates that the UPDATE path be taken must pass
- the (UPDATE or ALL) USING qualifications (combined
- using OR), which are always enforced as WITH CHECK
- options in this context (the UPDATE path will
+ the (UPDATE or ALL) USING qualifications (combined
+ using or
), which are always enforced as WITH CHECK
+ options in this context. (The UPDATE path will
never> be silently avoided; an error will be thrown
- instead). Finally, the final row appended to the relation must pass
+ instead.) Finally, the final row appended to the relation must pass
any WITH CHECK options that a conventional
UPDATE is required to pass.
@@ -320,14 +294,14 @@ CREATE POLICY name ON
Using DELETE for a policy means that it will apply
- to DELETE commands. Only rows which pass this
- policy will be seen by a DELETE command. Rows may
- be visible through a SELECT which are not seen by a
- DELETE, as they do not pass the USING expression
- for the DELETE, and rows which are not visible
- through the SELECT policy may be deleted if they
- pass the DELETE USING policy. The
- DELETE policy only accepts the USING expression as
+ to DELETE commands. Only rows that pass this
+ policy will be seen by a DELETE command. There can be rows
+ that are visible through a SELECT that are not seen by a
+ DELETE, if they do not pass the USING expression
+ for the DELETE. Conversely, there can be rows that are not visible
+ through the SELECT policy but may be deleted if they
+ pass the DELETE USING policy. The
+ DELETE policy only accepts the USING expression as
it only ever applies in cases where records are being extracted from
the relation for deletion.
@@ -335,6 +309,7 @@ CREATE POLICY name ON
+
@@ -345,11 +320,35 @@ CREATE POLICY name ON
- In order to maintain referential integrity between
- two related tables, policies are not applied when the system performs
- checks on foreign key constraints.
+ Note that while policies will be applied for explicit queries against tables
+ in the system, they are not applied when the system is performing internal
+ referential integrity checks or validating constraints. This means there are
+ indirect ways to determine that a given value exists. An example of this is
+ attempting to insert a duplicate value into a column which is the primary key
+ or has a unique constraint. If the insert fails then the user can infer that
+ the value already exists. (This example assumes that the user is permitted by
+ policy to insert records which they are not allowed to see.) Another example
+ is where a user is allowed to insert into a table which references another,
+ otherwise hidden table. Existence can be determined by the user inserting
+ values into the referencing table, where success would indicate that the
+ value exists in the referenced table. These issues can be addressed by
+ carefully crafting policies that prevent users from being able to insert,
+ delete, or update records at all which might possibly indicate a value they
+ are not otherwise able to see, or by using generated values (e.g., surrogate
+ keys) instead.
+
+ Regarding how policy expressions interact with the user: as the expressions
+ are added to the user's query directly, they will be run with the rights of
+ the user running the overall query. Therefore, users who are using a given
+ policy must be able to access any tables or functions referenced in the
+ expression or they will simply receive a permission denied error when
+ attempting to query the table that has row-level security enabled. This does not change how views
+ work, however. As with normal queries and views, permission checks and
+ policies for the tables which are referenced by a view will use the view
+ owner's rights and any policies which apply to the view owner.
+