DBMS_RLS v14
The DBMS_RLS
package enables you to implement Virtual Private Database on certain EDB Postgres Advanced Server database objects.
EDB Postgres Advanced Server's implementation of DBMS_RLS
is a partial implementation when compared to Oracle's version. Only those functions and procedures listed in the table are supported.
Function/procedure | Function or procedure | Return type | Description |
---|---|---|---|
ADD_POLICY(object_schema, object_name, policy_name, function_schema, policy_function [, statement_types [, update_check [, enable [, static_policy [, policy_type [, long_predicate [, sec_relevant_cols [, sec_relevant_cols_opt ]]]]]]]]) | Procedure | n/a | Add a security policy to a database object. |
DROP_POLICY(object_schema, object_name, policy_name) | Procedure | n/a | Remove a security policy from a database object. |
ENABLE_POLICY(object_schema, object_name, policy_name, enable) | Procedure | n/a | Enable or disable a security policy. |
Virtual Private Database is a type of fine-grained access control using security policies. Fine-grained access control in Virtual Private Database means that you can control access to data down to specific rows as defined by the security policy.
The rules that encode a security policy are defined in a policy function, which is an SPL function with certain input parameters and return values. The security policy is the named association of the policy function to a particular database object, typically a table.
Note
In EDB Postgres Advanced Server, you can write the policy function in any language supported by EDB Postgres Advanced Server, such as SQL, PL/pgSQL, and SPL.
Note
The database objects currently supported by EDB Postgres Advanced Server Virtual Private Database are tables. You can't apply policies to views or synonyms.
Virtual Private Database has these advantages:
- It provides a fine-grained level of security. Database object-level privileges given by the
GRANT
command determine access privileges to the entire instance of a database object, while Virtual Private Database provides access control for the individual rows of a database object instance. - You can apply a different security policy depending on the type of SQL command (
INSERT
,UPDATE
,DELETE
, orSELECT
). - The security policy can vary dynamically for each applicable SQL command affecting the database object, depending on factors such as the session user of the application accessing the database object.
- Invoking the security policy is transparent to all applications that access the database object. Thus, you don't have to modify individual applications to apply the security policy.
- Once a security policy is enabled, applications (including new applications) can't circumvent the security policy except by the system privilege described in the note that follows.
- Even superusers can't circumvent the security policy except by the system privilege described in the note that follows.
Note
The only way to circumvent security policies is if the EXEMPT ACCESS POLICY
system privilege is granted to a user. Grant the EXEMPT ACCESS POLICY
privilege with extreme care as a user with this privilege is exempted from all policies in the database.
The DBMS_RLS
package provides procedures to create policies, remove policies, enable policies, and disable policies.
The process for implementing Virtual Private Database is as follows:
- Create a policy function. The function must have two input parameters of type
VARCHAR2
. The first input parameter is for the schema containing the database object to which the policy applies. The second input parameter is for the name of that database object. The function must have aVARCHAR2
return type and return a string in the form of aWHERE
clause predicate. This predicate is dynamically appended as anAND
condition to the SQL command that acts on the database object. Thus, rows that don't satisfy the policy function predicate are filtered out from the SQL command result set. - Use the
ADD_POLICY
procedure to define a new policy, which is the association of a policy function with a database object. With theADD_POLICY
procedure, you can also specify:- The types of SQL commands (
INSERT
,UPDATE
,DELETE
, orSELECT
) to which the policy applies - Whether to enable the policy at the time of its creation
- Whether the policy applies to newly inserted rows or the modified image of updated rows
- The types of SQL commands (
- Use the
ENABLE_POLICY
procedure to disable or enable an existing policy. - Use the
DROP_POLICY
procedure to remove an existing policy. TheDROP_POLICY
procedure doesn't drop the policy function or the associated database object.
Once you create policies, you can view them in the catalog views compatible with Oracle databases: ALL_POLICIES
, DBA_POLICIES
, or USER_POLICIES
. The supported compatible views are listed in Catalog views.
The SYS_CONTEXT
function is often used with DBMS_RLS
. The signature is: