Creating and Managing Multiple Named Policy Expressions
A named, centrally managed Oracle Data Redaction policy expression can be used in multiple redaction policies and applied to multiple tables or views.
-
About Data Redaction Policy Expressions to Define Conditions
A Oracle Data Redaction named policy expression is designed to work as an alternative to the policy expression that is used in existing Data Redaction policies.
-
Creating and Applying a Data Redaction Named Policy Expression
The
DBMS_REDACT.CREATE_POLICY_EXPRESSIONandDBMS_REDACT.APPLY_POLICY_EXPR_TO_COLenable you to create and apply a Data Redaction named policy expression. -
Updating a Data Redaction Named Policy Expression
You can use the
DBMS_REDACT.UPDATE_POLICY_EXPRESSIONprocedure to update a Data Redaction named policy expression. The update takes place immediately and is reflected in all the columns that use the named policy expression. -
Dropping a Data Redaction Named Policy Expression
You can use the
DBMS_REDACT.DROP_POLICY_EXPRESSIONprocedure to drop a Data Redaction named policy expression. -
Tutorial: Creating and Sharing a Data Redaction Named Policy Expression
This tutorial shows how to create an Oracle Data Redaction named policy expression, apply it to multiple tables, and centrally manage the named policy expression.
About Data Redaction Policy Expressions to Define Conditions
A Oracle Data Redaction named policy expression is designed to work as an alternative to the policy expression that is used in existing Data Redaction policies.
A policy expression enables you to redact data based on runtime conditions. This type of policy expression can affect whether or not redaction takes place on columns of the table or view on which the redaction policy is defined. By default, a Data Redaction policy expression applies to all the columns that belong to the Data Redaction policy defined on that table or view. Alternatively, you can choose to create and associate a policy expression for individual columns of a table or view. These column level policy expressions are called named policy expressions. The column to which you apply a named policy expression must already be redacted by a Data Redaction policy.
You can use Data Redaction named policy expressions in the following ways:
-
Each named policy expression can be associated with multiple columns of the same or different tables or views.
-
Each named policy expression can be associated with columns within the same or different Data Redaction policies.
-
The named policy expression overrides the default policy expression of the associated columns. The default policy expression still applies to columns that have no named policy expressions applied to them.
-
Any updates made to a named policy expression apply to all of the column associations of the expression.
-
You cannot associate multiple named policy expressions for the same column.
-
You cannot associate named policy expressions with columns in a different pluggable database (PDB).
The following table describes the DBMS_REDACT PL/SQL procedures that you can use to create and manage named policy expressions. To find information about policy expressions, query the REDACTION_EXPRESSIONS data dictionary view.
| Procedure | Description |
|---|---|
DBMS_REDACT.CREATE_POLICY_EXPRESSION |
Creates a Data Redaction named policy expression |
DBMS_REDACT.UPDATE_POLICY_EXPRESSION |
Updates a Data Redaction named policy expression |
DBMS_REDACT.APPLY_POLICY_EXPR_TO_COL |
Applies a Data Redaction named policy expression to a table or a view column |
DBMS_REDACT.DROP_POLICY_EXPRESSION |
Drops a Data Redaction named policy expression |
Related Topics
Creating and Applying a Data Redaction Named Policy Expression
The DBMS_REDACT.CREATE_POLICY_EXPRESSION and DBMS_REDACT.APPLY_POLICY_EXPR_TO_COL enable you to create and apply a Data Redaction named policy expression.
-
Connect to the PDB as a user who has the
EXECUTEprivilege on theDBMS_REDACTPL/SQL package and theADMINISTER REDACTION POLICYsystem or schema privilege. -
Ensure that the
COMPATIBLEinitialization parameter is set to12.2.0.0or later.To find the current
COMPATIBLEsetting, use theSHOW PARAMETERcommand. -
To create the named policy expression, run the
DBMS_REDACT.CREATE_POLICY_EXPRESSIONprocedure.For example:
BEGIN DBMS_REDACT.CREATE_POLICY_EXPRESSION ( policy_expression_name => 'redact_pol', expression => '1=1', policy_expression_description => 'Determines whether the column will be redacted'); END; / -
Run the
DBMS_REDACT.APPLY_POLICY_EXPR_TO_COLprocedure to apply the named policy expression to a table or view column.For example, assume that you have already created a Data Redaction policy on the
SALARYcolumn of theHR.EMPLOYEEStable, as follows:BEGIN DBMS_REDACT.ADD_POLICY ( object_schema => 'hr', object_name => 'employees', policy_name => 'overall_policy', expression => '1=0'); END; / BEGIN DBMS_REDACT.ALTER_POLICY ( object_schema => 'hr', object_name => 'employees' , policy_name => 'overall_policy', function_type => DBMS_REDACT.FULL, action => DBMS_REDACT.ADD_COLUMN, column_name => 'salary'); END; /Then you can apply the policy expression to the
SALARYcolumn as follows:BEGIN DBMS_REDACT.APPLY_POLICY_EXPR_TO_COL ( object_schema => 'hr', object_name => 'employees', column_name => 'salary', policy_expression_name => 'redact_pol'); END; /In this specification:
-
object_schema: Specifies the schema of the object on which named policy expression will be applied. If you omit this setting (or enterNULL), then Oracle Database uses the name of the current schema. -
object_name: Specifies the name of the table or view to be used for the named policy expression. -
column_name: Specifies the column to which you want to apply the named policy expression. -
policy_expression_name: Specifies the name of the named policy expression.
-
Updating a Data Redaction Named Policy Expression
You can use the DBMS_REDACT.UPDATE_POLICY_EXPRESSION procedure to update a Data Redaction named policy expression. The update takes place immediately and is reflected in all the columns that use the named policy expression.
You can query the REDACTION_EXPRESSIONS data dictionary view to find existing Data Redaction policy expressions.
-
Connect to the PDB as a user who has the
EXECUTEprivilege on theDBMS_REDACTPL/SQL package and theADMINISTER REDACTION POLICYsystem or schema privilege. -
Ensure that the
COMPATIBLEinitialization parameter is set to12.2.0.0or later.To find the current
COMPATIBLEsetting, use theSHOW PARAMETERcommand. -
Run the
DBMS_REDACT.UPDATE_POLICY_EXPRESSIONprocedure to perform the update.For example:
BEGIN DBMS_REDACT.UPDATE_POLICY_EXPRESSION( policy_expression_name => 'redact_pol', expression => '1=0'); END; /
Dropping a Data Redaction Named Policy Expression
You can use the DBMS_REDACT.DROP_POLICY_EXPRESSION procedure to drop a Data Redaction named policy expression.
You can query the REDACTION_EXPRESSIONS data dictionary view to find the existing Data Redaction named policy expressions.
-
Connect to the PDB as a user who has the
EXECUTEprivilege on theDBMS_REDACTPL/SQL package and theADMINISTER REDACTION POLICYsystem or schema privilege. -
Ensure that the
COMPATIBLEinitialization parameter is set to12.2.0.0or later.To find the current
COMPATIBLEsetting, use theSHOW PARAMETERcommand. -
Remove the named policy expression’s association with any table or view column.
You cannot drop a named policy expression if it is associated with an existing table or view column. To remove a given column’s association with a named policy expression (to revert to redacting that column based on the evaluation result of the default policy expression), you must set the
policy_expression_nameparameter of theDBMS_REDACT.APPLY_POLICY_EXPR_TO_COLprocedure toNULL.For example:
BEGIN DBMS_REDACT.APPLY_POLICY_EXPR_TO_COL( object_schema => 'hr', object_name => 'employees', column_name => 'salary', policy_expression_name => null); END; / -
Run
DBMS_REDACT.DROP_POLICY_EXPRESSIONto drop the policy expression.For example:
BEGIN DBMS_REDACT.DROP_POLICY_EXPRESSION( policy_expression_name => 'redact_pol'); END; /
Tutorial: Creating and Sharing a Data Redaction Named Policy Expression
This tutorial shows how to create an Oracle Data Redaction named policy expression, apply it to multiple tables, and centrally manage the named policy expression.
-
Step 1: Create Users for This Tutorial
You must create two users for this tutorial:
dr_admin, who will create the Oracle Data Redaction policies, andhr_clerk, who will test them. -
Step 2: Create an Oracle Data Redaction Policy
User
dr_adminis ready to create an Oracle Data Redaction policy to protect theHR.EMPLOYEESandHR.JOBStables. -
Step 3: Test the Oracle Data Redaction Policy
User
hr_clerkis ready to query the tables that have redacted data. -
Step 4: Create and Apply a Named Policy Expression to the Redacted Table Columns
Next, user
dr_adminis ready to create a Data Redaction named policy expression (hr_redact_pol) and apply it to two of the three redacted table columns. -
Step 5: Test the Data Redaction Named Policy Expression
User
hr_clerkis now ready to test thehr_redact_polnamed policy expression. -
Step 6: Modify the Data Redaction Named Policy Expression
User
dr_admindecides to modify the Data Redaction named policy expression so that userhr_clerkwill get redacted data, not userHR. -
Step 7: Test the Modified Named Policy Expression
Users
HRandhr_clerkare ready to test the modified Data Redaction named policy expression. -
Step 8: Remove the Components of This Tutorial
If you do not need the components of this tutorial, then you can remove them.
Step 1: Create Users for This Tutorial
You must create two users for this tutorial: dr_admin, who will create the Oracle Data Redaction policies, and hr_clerk, who will test them.
Before you begin this tutorial, ensure that the COMPATIBLE initialization parameter is set to 12.2.0.0 or later. You can check this setting by using the SHOW PARAMETER command.
-
Connect to a PDB as user
SYSwith theSYSDBAadministrative privilege. -
Create the
dr_adminandhr_clerkuser accounts.GRANT CREATE SESSION TO dr_admin IDENTIFIED BY password; GRANT CREATE SESSION TO hr_clerk IDENTIFIED BY password; -
Grant the following privileges to the
dr_adminuser:GRANT EXECUTE ON DBMS_REDACT TO dr_admin; GRANT ADMINISTER REDACTION POLICY TO dr_admin; -
Connect as user
HR. -
Grant
hr_clerktheSELECTprivilege on theEMPLOYEESandJOBStables.GRANT SELECT on EMPLOYEES to hr_clerk; GRANT SELECT on JOBS to hr_clerk;
Step 2: Create an Oracle Data Redaction Policy
User dr_admin is ready to create an Oracle Data Redaction policy to protect the HR.EMPLOYEES and HR.JOBS tables.
-
Connect to the PDB as user
dr_admin. -
Create the
hr_emp_redact_comp_polpolicy, which will perform full redaction of theHR.EMPLOYEES.SALARYcolumn.BEGIN DBMS_REDACT.ADD_POLICY( object_schema => 'hr', object_name => 'employees', column_name => 'salary', policy_name => 'hr_emp_redact_comp_pol', function_type => DBMS_REDACT.FULL, expression => '1=1'); END; / -
Alter the
hr_redact_comp_polpolicy to also redact theCOMMISSION_PCTcolumn of theHR.EMPLOYEEStable.BEGIN DBMS_REDACT.ALTER_POLICY( object_schema => 'hr', object_name => 'employees', policy_name => 'hr_emp_redact_comp_pol', action => DBMS_REDACT.ADD_COLUMN, column_name => 'commission_pct', function_type => DBMS_REDACT.FULL); END; / -
Create the
hr_jobs_redact_comp_polpolicy for themax_salarycolumn of theHR.JOBStable.BEGIN DBMS_REDACT.ADD_POLICY( object_schema => 'hr', object_name => 'jobs', column_name => 'max_salary', policy_name => 'hr_jobs_redact_comp_pol', function_type => DBMS_REDACT.FULL, expression => '1=1'); END; /
At this stage, the data in the HR.EMPLOYEES.SALARY, HR.EMPLOYEES.COMMISSION_PCT, and HR.JOBS.MAX_SALARY columns are redacted.
Step 3: Test the Oracle Data Redaction Policy
User hr_clerk is ready to query the tables that have redacted data.
-
Connect as user
hr_clerk. -
Query the
HR.EMPLOYEEStable.SELECT SALARY, COMMISSION_PCT FROM HR.EMPLOYEES WHERE SALARY > 15000;The output should be as follows:
SALARY COMMISSION_PCT ---------- -------------- 0 0 0 -
Query the
HR.JOBStable.SELECT MAX_SALARY FROM HR.JOBS WHERE MAX_SALARY > 15000;The output should be as follows:
MAX_SALARY ---------- 0 0 0 0 0
Step 4: Create and Apply a Named Policy Expression to the Redacted Table Columns
Next, user dr_admin is ready to create a Data Redaction named policy expression (hr_redact_pol) and apply it to two of the three redacted table columns.
This policy expression will enable user hr_clerk to view the redacted data.
-
Connect as user
dr_admin. -
Create the policy expression.
BEGIN DBMS_REDACT.CREATE_POLICY_EXPRESSION( policy_expression_name => 'hr_redact_pol', expression => 'SYS_CONTEXT(''USERENV'',''SESSION_USER'') != ''HR_CLERK'''); END; /This expression returns
FALSEfor thehr_clerkuser, which enables thehr_clerkuser to view actual data in theHR.EMPLOYEESandHR.JOBStables that are subject to the Data Redaction policies. -
Apply the
hr_redact_polpolicy expression to theHR.EMPLOYEES.SALARYcolumn.BEGIN DBMS_REDACT.APPLY_POLICY_EXPR_TO_COL( object_schema => 'hr', object_name => 'employees', column_name => 'salary', policy_expression_name => 'hr_redact_pol'); END; / -
Apply the
hr_redact_polpolicy expression to theHR.JOBS.MAX_SALARYcolumn.BEGIN DBMS_REDACT.APPLY_POLICY_EXPR_TO_COL( object_schema => 'hr', object_name => 'jobs', column_name => 'max_salary', policy_expression_name => 'hr_redact_pol'); END; /
User hr_clerk can view data in the HR.EMPLOYEES.SALARY and HR.JOBS.MAX_SALARY, but the data in the HR.EMPLOYEES.COMMISSION_PCT column will still be redacted for this user.
Step 5: Test the Data Redaction Named Policy Expression
User hr_clerk is now ready to test the hr_redact_pol named policy expression.
-
Connect as user
hr_clerk. -
Query the
HR.EMPLOYEEStable.SELECT SALARY, COMMISSION_PCT FROM HR.EMPLOYEES WHERE SALARY > 15000;The output should be as follows:
SALARY COMMISSION_PCT ---------- -------------- 24000 17000 17000User
hr_clerknow can view theSALARYcolumn data, but still has no access to theCOMMISSION_PCTcolumn data. -
Query the
HR.JOBStable.SELECT MAX_SALARY FROM HR.JOBS WHERE MAX_SALARY > 15000;The output should be as follows:
MAX_SALARY ---------- 40000 30000 16000 16000 20080User
hr_clerknow can view theMAX_SALARYcolumn data.
Step 6: Modify the Data Redaction Named Policy Expression
User dr_admin decides to modify the Data Redaction named policy expression so that user hr_clerk will get redacted data, not user HR.
-
Connect as user
dr_admin. -
Modify the
hr_redact_polpolicy as follows:BEGIN DBMS_REDACT.UPDATE_POLICY_EXPRESSION( policy_expression_name => 'hr_redact_pol', expression => 'SYS_CONTEXT(''USERENV'',''SESSION_USER'') != ''HR'''); END; /
Step 7: Test the Modified Named Policy Expression
Users HR and hr_clerk are ready to test the modified Data Redaction named policy expression.
-
Connect as user
HR. -
Query the
HR.EMPLOYEEStable.SELECT SALARY, COMMISSION_PCT FROM HR.EMPLOYEES WHERE SALARY > 15000;The output should be as follows:
SALARY COMMISSION_PCT ---------- -------------- 24000 17000 17000User
HRnow has access to the actual data. A query byHRon theHR.JOBS.MAX_SALARYcolumn will produce similar results.SELECT MAX_SALARY FROM HR.JOBS WHERE MAX_SALARY > 15000; MAX_SALARY ---------- 40000 30000 16000 16000 20080 -
Connect as user
hr_clerk. -
Query the
HR.EMPLOYEESandHR.JOBStables and then observe the results.SELECT SALARY, COMMISSION_PCT FROM HR.EMPLOYEES WHERE SALARY > 15000; SALARY COMMISSION_PCT ---------- -------------- 0 0 0 SELECT MAX_SALARY FROM HR.JOBS WHERE MAX_SALARY > 15000; MAX_SALARY ---------- 0 0 0 0 0
Step 8: Remove the Components of This Tutorial
If you do not need the components of this tutorial, then you can remove them.
-
Connect as user
dr_admin. -
Modify the policy expression so that it is no longer associated with the table columns that are associated with the expression.
To do so, you must set the
policy_expression_nameparameter toNULL.BEGIN DBMS_REDACT.APPLY_POLICY_EXPR_TO_COL( object_schema => 'hr', object_name => 'employees', column_name => 'salary', policy_expression_name => null); END; / BEGIN DBMS_REDACT.APPLY_POLICY_EXPR_TO_COL( object_schema => 'hr', object_name => 'jobs', column_name => 'max_salary', policy_expression_name => null); END; / -
Drop the policy expression.
BEGIN DBMS_REDACT.DROP_POLICY_EXPRESSION( policy_expression_name => 'hr_redact_pol'); END; / -
Drop the
hr_emp_redact_comp_polandhr_jobs_redact_comp_polData Redaction policies.BEGIN DBMS_REDACT.DROP_POLICY ( object_schema => 'hr', object_name => 'employees', policy_name => 'hr_emp_redact_comp_pol'); END; / BEGIN DBMS_REDACT.DROP_POLICY ( object_schema => 'hr', object_name => 'jobs', policy_name => 'hr_jobs_redact_comp_pol'); END; / -
Connect as the
SYSTEMuser or a user who has privileges to drop user accounts. -
Drop the
dr_adminandhr_clerkuser accounts.DROP USER dr_admin; DROP USER hr_clerk;