DBMS_RLS v11
The DBMS_RLS
package enables the implementation of Virtual Private Database on certain Advanced Server database objects.
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. |
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 above are supported.
Virtual Private Database is a type of fine-grained access control using security policies. Fine-grained access control in Virtual Private Database means that access to data can be controlled 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 value. The security policy is the named association of the policy function to a particular database object, typically a table.
Note
In Advanced Server, the policy function can be written in any language supported by Advanced Server such as SQL, PL/pgSQL and SPL.
Note
The database objects currently supported by Advanced Server Virtual Private Database are tables. Policies cannot be applied to views or synonyms.
The advantages of using Virtual Private Database are the following:
- 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. - A different security policy can be applied depending upon 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 upon factors such as the session user of the application accessing the database object.
- Invocation of the security policy is transparent to all applications that access the database object and thus, individual applications do not have to be modified to apply the security policy.
- Once a security policy is enabled, it is not possible for any application (including new applications) to circumvent the security policy except by the system privilege noted by the following.
- Even superusers cannot circumvent the security policy except by the system privilege noted by the following.
Note
The only way security policies can be circumvented is if the EXEMPT ACCESS POLICY
system privilege has been granted to a user. The EXEMPT ACCESS POLICY
privilege should be granted 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 is to apply and the second input parameter is for the name of that database object. The function must have aVARCHAR2
return type. The function must return a string in the form of aWHERE
clause predicate. This predicate is dynamically appended as anAND
condition to the SQL command that acts upon the database object. Thus, rows that do not 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 is to apply, whether or not to enable the policy at the time of its creation, and if the policy should apply to newly inserted rows or the modified image of updated rows. - 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 does not drop the policy function or the associated database object.
Once policies are created, they can be viewed in the catalog views, compatible with Oracle databases: ALL_POLICIES, DBA_POLICIES
, or USER_POLICIES
. The supported compatible views are listed in the Database Compatibility for Oracle Developers Catalog Views Guide, available at the EDB website at:
https://www.enterprisedb.com/docs/
The SYS_CONTEXT
function is often used with DBMS_RLS
. The signature is:
Where:
namespace
is a VARCHAR2
; the only accepted value is USERENV
. Any other value will return NULL
.
attribute
is a VARCHAR2
. attribute
may be:
attribute Value | Equivalent Value |
---|---|
SESSION_USER | pg_catalog.session_user |
CURRENT_USER | pg_catalog.current_user |
CURRENT_SCHEMA | pg_catalog.current_schema |
HOST | pg_catalog.inet_host |
IP_ADDRESS | pg_catalog.inet_client_addr |
SERVER_HOST | pg_catalog.inet_server_addr |
Note
The examples used to illustrate the DBMS_RLS
package are based on a modified copy of the sample emp
table provided with Advanced Server along with a role named salesmgr
that is granted all privileges on the table. You can create the modified copy of the emp
table named vpemp
and the salesmgr
role as shown by the following: