Data Redaction v13
Data redaction limits sensitive data exposure by dynamically changing data as it is displayed for certain users.
For example, a social security number (SSN) is stored as 021-23-9567
. Privileged users can see the full SSN, while other users only see the last four digits xxx-xx-9567
.
Data redaction is implemented by defining a function for each field to which redaction is to be applied. The function returns the value that should be displayed to the users subject to the data redaction.
So for example, for the SSN field, the redaction function would return xxx-xx-9567
for an input SSN of 021-23-9567
.
For a salary field, a redaction function would always return $0.00
regardless of the input salary value.
These functions are then incorporated into a redaction policy by using the CREATE REDACTION POLICY
command. This command specifies the table on which the policy applies, the table columns to be affected by the specified redaction functions, expressions to determine which session users are to be affected, and other options.
The edb_data_redaction
parameter in the postgresql.conf
file then determines whether or not data redaction is to be applied.
By default, the parameter is enabled so the redaction policy is in effect and the following occurs:
- Superusers and the table owner bypass data redaction and see the original data.
- All other users get the redaction policy applied and see the reformatted data.
If the parameter is disabled by having it set to FALSE
during the session, then the following occurs:
- Superusers and the table owner bypass data redaction and see the original data.
- All other users get will get an error.
A redaction policy can be changed by using the ALTER REDACTION POLICY
command, or it can be eliminated using the DROP REDACTION POLICY
command.
The redaction policy commands are described in more detail in the subsequent sections.
CREATE REDACTION POLICY
CREATE REDACTION POLICY
defines a new data redaction policy for a table.
Synopsis
where redaction_option
is:
Description
The CREATE REDACTION POLICY
command defines a new column-level security policy for a table by redacting column data using redaction function. A newly created data redaction policy will be enabled by default. The policy can be disabled using ALTER REDACTION POLICY ... DISABLE
.
FOR ( expression )
This form adds a redaction policy expression.
ADD [ COLUMN ]
This optional form adds a column of the table to the data redaction policy. The USING
specifies a redaction function expression. Multiple ADD [ COLUMN ]
form can be used, if you want to add multiple columns of the table to the data redaction policy being created. The optional WITH OPTIONS ( ... )
clause specifies a scope and/or an exception to the data redaction policy to be applied. If the scope and/or exception are not specified, the default values for scope and exception will be query
and none
respectively.
Parameters
name
The name of the data redaction policy to be created. This must be distinct from the name of any other existing data redaction policy for the table.
table_name
The name (optionally schema-qualified) of the table the data redaction policy applies to.
expression
The data redaction policy expression. No redaction will be applied if this expression evaluates to false.
column_name
Name of the existing column of the table on which the data redaction policy being created.
funcname_clause
The data redaction function which decides how to compute the redacted column value. Return type of the redaction function should be same as the column type on which data redaction policy being added.
scope_value
The scope identified the query part where redaction to be applied for the column. Scope value could be query, top_tlist
or top_tlist_or_error
. If the scope is query
then, the redaction applied on the column irrespective of where it appears in the query. If the scope is top_tlist
then, the redaction applied on the column only when it appears in the query’s top target list. If the scope is top_tlist_or_error
the behavior will be same as the top_tlist
, but throws an errors when the column appears anywhere else in the query.
exception_value
The exception identified the query part where redaction to be exempted. Exception value could be none, equal
or leakproof
. If exception is none
then there is no exemption. If exception is equal
, then the column is not redacted when used in an equality test. If exception is leakproof
, the column will is not redacted when a leakproof function is applied to it.
Notes:
You must be the owner of a table to create or change data redaction policies for it.
The superuser and the table owner are exempt from the data redaction policy.
Examples
Below is an example of how this feature can be used in production environments. Create the components for a data redaction policy on the employees
table: