3.5 Using Expressions to Define Conditions for Data Redaction Policies
The expression parameter in the
DBMS_REDACT.ADD_POLICY or
DBMS_REDACT.ALTER_POLICY procedures sets the
conditions under which those policies apply.
- About Using Expressions in Data Redaction Policies
TheDBMS_REDACT.ADD_POLICYandDBMS_REDACT.ALTER_POLICYexpressionparameter define a boolean expression that must evaluate toTRUEto enable redaction. - Supported Functions for Data Redaction Expressions
You can create expressions that use functions to return specific types of data, such asSYS_CONTEXTnamespaces. - Applying the Redaction Policy Based on User Environment
You can apply a Data Redaction policy based on the user’s environment, such as the session user name or a client identifier. - Applying the Redaction Policy Based on Database Roles
You can apply a Data Redaction policy based on a database role. - Applying the Redaction Policy Based on Application Express Session States
You can apply a Data Redaction policy based on an Oracle Application Express (APEX) session state. - Applying the Redaction Policy Based on Oracle Label Security Label Dominance
You can set a condition on which to apply a Data Redaction policy based on the dominance of Oracle Label Security labels. - Managing the Application of Redaction Policies to All Users
You can manage the application of policies irrespective of the context to any user, with no filtering.
Parent topic: Configuring Oracle Data Redaction Policies
3.5.1 About Using Expressions in Data Redaction Policies
The DBMS_REDACT.ADD_POLICY and
DBMS_REDACT.ALTER_POLICY
expression parameter define a boolean expression that must evaluate to
TRUE to enable redaction.
The expression that is defined in the expression parameter is the
default expression for the Oracle Data Redaction policy. If you apply a named policy
expression for the columns that will be redacted by the Data Redaction policy, then the
named policy expression takes precedence over the expression defined in the Data
Redaction policy. If 1=1 is specified for the expression parameter
which is a policy expression that evaluates to TRUE, it enables the
redaction to be performed so long as the querying user is not exempt from the redaction
policy. Using this condition saves CPU time during the fetch operation from a redacted
column. By avoiding the need to evaluate any policy expression, the performance of
fetching from any column that is protected by a Data Redaction policy is improved.
You can create expressions that make use of other Oracle Database features. For example, you can create expressions that are based on a user’s environment (using the SYS_CONTEXT and XS_SYS_CONTEXT functions), character string functions, the Oracle Label Security label dominance functions, or Oracle Application Express functions.
Follow these guidelines when you write the expression:
-
Use only the following operators:
AND,OR,IN,NOT IN,=,!=,<>,<,>,>=,<= -
Because the expression must evaluate to
TRUEfor redaction, be careful when making comparisons withNULL. Remember that in SQL the valueNULLis undefined, so comparisons withNULLtend to returnFALSE. -
Do not use user-created functions in the
expressionparameter; this is not permitted. -
Remember that for user
SYSand users who have theEXEMPT REDACTION POLICYsystem or schema privilege, all of the Data Redaction policies are bypassed, so the results of their queries are not redacted. When you exempt a user from a Data Redaction policy, you should be aware of how the exemption is affected by users with specific privileges (such as theDBArole) and by Oracle Data Pump.
3.5.2 Supported Functions for Data Redaction Expressions
You can create expressions that use functions to return specific types of data, such as SYS_CONTEXT namespaces.
- Expressions Using Namespace Functions
You can use theSYS_CONTEXTandXS_SYS_CONTEXTnamespace functions in Data Redaction expressions. - Expressions Using the SUBSTR Function
You can use theSUBSTRfunction, which returns portion (such as characters 1–3) of the character string specified, in Data Redaction expressions. The first parameter must be a constant string or a call to theSYS_CONTEXTfunction or theXS_SYS_CONTEXTfunction. - Expressions Using Length of Character String Functions
You can use functions that return the length of character strings, in Data Redaction expressions. - Expressions Using Oracle Application Express Functions
You can use Oracle Application Express functions in Data Redaction expressions. - Expressions Using Oracle Label Security Functions
You can use Oracle Label Security functions with Data Redaction expressions.
3.5.2.1 Expressions Using Namespace Functions
You can use the SYS_CONTEXT and XS_SYS_CONTEXT namespace functions in Data Redaction expressions.
Table 3-3 Expressions Using Namespace Functions
| Namespace Function | Description |
|---|---|
|
|
Returns the value associated with a namespace. The following namespace functions are valid:
|
|
|
Similar to
|
3.5.2.2 Expressions Using the SUBSTR Function
You can use the SUBSTR function, which returns portion (such as characters 1–3) of the character string specified, in Data Redaction expressions. The first parameter must be a constant string or a call to the SYS_CONTEXT function or the XS_SYS_CONTEXT function.
Table 3-4 Expressions Using SUBSTR String Functions
| SUBSTR String Function | Description |
|---|---|
|
|
Returns a portion of the input |
|
|
Returns the specified portion of the input value in bytes |
|
|
Returns the specified portion of the input value in Unicode complete characters |
|
|
Returns the specified portion of the input value in UCS2 code points |
|
|
Returns the specified portion of the input value in UCS4 code points |
Related Topics
Parent topic: Supported Functions for Data Redaction Expressions
3.5.2.3 Expressions Using Length of Character String Functions
You can use functions that return the length of character strings, in Data Redaction expressions.
Oracle Database also checks that the arguments to each of these operators is either a constant string or a call to the SYS_CONTEXT or XS_SYS_CONTEXT function.
Table 3-5 Expressions Using Character String Functions
| Character String Function | Description |
|---|---|
|
|
Returns the length of the input |
|
|
Returns the length of the input value in bytes |
|
|
Returns the length of the input value in Unicode complete characters |
|
|
Returns the length of the input value in UCS2 code points |
|
|
Returns the length of the input value in UCS4 code points |
Related Topics
Parent topic: Supported Functions for Data Redaction Expressions
3.5.2.4 Expressions Using Oracle Application Express Functions
You can use Oracle Application Express functions in Data Redaction expressions.
Table 3-6 Oracle Application Express Functions
| Oracle Application Express Function | Description |
|---|---|
|
|
Returns the session state for an item. It is a wrapper for the |
|
|
Returns the numeric value for a numeric item. It is a wrapper for the |
Related Topics
Parent topic: Supported Functions for Data Redaction Expressions
3.5.2.5 Expressions Using Oracle Label Security Functions
You can use Oracle Label Security functions with Data Redaction expressions.
Table 3-7 Oracle Label Security Functions
| Oracle Label Security Function | Description |
|---|---|
|
|
Checks if the session label of an Oracle Label Security policy dominates or is equal to another OLS label |
|
|
Checks if one OLS label is dominant to a second OLS label.
|
|
|
Checks if one OLS label is dominant to a second OLS label |
|
|
Checks if one OLS label is dominant to a second OLS label |
|
|
Checks if one OLS label is dominant to a second OLS label and is not equal to it |
|
|
Checks if one OLS label is dominant to a second OLS label and is not equal to it |
|
|
Checks if one OLS label dominates a second OLS label or if the session label for a given OLS policy dominates an OLS label |
|
|
Checks if a user can read a policy-protected row |
|
|
Returns the current session OLS label |
|
|
Converts a character string to an OLS label tag |
|
|
Returns the label that is associated with the specified OLS policy |
* Oracle Data Redaction checks that their parameters are either constants or calls to
only one of the SA_UTL.NUMERIC_LABEL,
CHAR_TO_LABEL, and SA_SESSION.LABEL functions,
and that the arguments to those functions are constant.
Related Topics
Parent topic: Supported Functions for Data Redaction Expressions
3.5.3 Applying the Redaction Policy Based on User Environment
You can apply a Data Redaction policy based on the user’s environment, such as the session user name or a client identifier.
Related Topics
3.5.4 Applying the Redaction Policy Based on Database Roles
You can apply a Data Redaction policy based on a database role.
Use the SYS_SESSION_ROLES namespace in the
SYS_CONTEXT function to apply the policy based on a user
role.
This namespace contains attributes for each role. The value of the
attribute is TRUE if the specified role is enabled for the querying
application user; the value is FALSE if the role is not enabled. If
the expression is TRUE, redacted data is returned to the user. If
the expression is FALSE, actual data is returned to the user.
DBMS_REDACT.ADD_POLICY
expression parameter to set the policy to show the actual data to
any application user who has the supervisor role enabled, but
redact the data for all of the other application
users.expression => 'SYS_CONTEXT(''SYS_SESSION_ROLES'',''SUPERVISOR'') = ''FALSE'''expression
parameter. The following example checks for the presence of the
SUPERVISOR, CLERK, and
TEMP_WORKER roles. Actual data will be displayed to a user with
the SUPERVISOR role. Users who have the CLERK or
TEMP_WORKER roles will see redacted
data.expression => 'SYS_CONTEXT(''SYS_SESSION_ROLES'',''SUPERVISOR'') = ''FALSE''
OR SYS_CONTEXT(''SYS_SESSION_ROLES'',''CLERK'') = ''TRUE''
OR SYS_CONTEXT(''SYS_SESSION_ROLES'',''TEMP_WORKER'') = ''TRUE'''All roles are disabled in any named PL/SQL block that runs with
definer's rights. Procedures and functions are created with definer's rights by
default. For the policy expression with SYS_SESSION_ROLES to take
effect, create the procedure or function to be invoker's rights so that the enabled
roles are effective. Alternatively, you can use code based access controls to grant
a role to a program unit (function, package, or procedure), allowing the program
unit to use the role in either definer's or invoker's rights. For more information,
see Managing Security for Definer's Rights and
Invoker's Rights in the Oracle AI Database
Security Guide.
3.5.5 Applying the Redaction Policy Based on Application Express Session States
You can apply a Data Redaction policy based on an Oracle Application Express (APEX) session state.
Related Topics
3.5.6 Applying the Redaction Policy Based on Oracle Label Security Label Dominance
You can set a condition on which to apply a Data Redaction policy based on the dominance of Oracle Label Security labels.
Related Topics
3.5.7 Managing the Application of Redaction Policies to All Users
You can manage the application of policies irrespective of the context to any user, with no filtering.
SYS and users who have the
EXEMPT REDACTION POLICY system or schema privilege are always
exempt from Oracle Data Redaction policies.
Related Topics