Policy Implementation

Prev Next

The Policy Implementation article outlines the enforcement capabilities supported by the SQL Authorizer when applying PlainID Policies to SQL-based systems. These capabilities allow fine-grained control over query results by dynamically modifying SQL statements based on user identity, context, and Policy decisions.

This article focuses on core enforcement features such as Row-Level Filtering, Column-Level Filtering, Conditional Masking, and SELECT * resolution, with a dedicated section on advanced masking capabilities, including static, conditional, and function-based masking behaviors, in addition to nesting behaviors. It also provides practical examples that illustrate how masking logic is applied under different Policy configurations.

After deploying and integrating your patterns, you can start using the capabilities below.

Enforcement Modes

The SQL Authorizer supports two enforcement modes. You select the mode once per Authorizer deployment, at startup.

Mode How the Authorizer masks columns Default
Resolution The PDP returns a Policy Resolution response, and the Authorizer derives masking values from its local configuration (MASKING_* settings). Yes
Data Instructions The PDP returns explicit filtering and masking instructions for each table, and the Authorizer applies them exactly as received. Masking values, functions, and Conditions all come from your Policies. No

Resolution mode remains the default and behaves exactly as before, so upgrading the Authorizer changes nothing until you opt in. Masking Capabilities describes Resolution mode. Data Instructions Mode describes the alternative mode, including how to enable it.

Google BigQuery

Google BigQuery is supported by the SQL Authorizer, enabling enforcement of PlainID Policies at the query level. This includes applying row- and column-level controls, masking sensitive data, and resolving wildcard selections based on the user's permissions. BigQuery-specific considerations, such as how Asset Types are mapped to rows and columns, are detailed in the linked article below. Use this section to understand how the core enforcement capabilities behave in the context of BigQuery.
Refer to Google BigQuery for information about Asset Types in rows and columns.

Supported Capabilities

Capability Description
Row-Level Filtering Filters query results based on Policy decisions.
Column-Level Filtering Removes unauthorized columns from query results. In Data Instructions mode, the Authorizer returns NULL for unauthorized columns instead of removing them.
Masking Types Supports Conditional Masking, NULLs, static values, and function-based masking (DB access required). See Masking Capabilities for more details.
Select * Expands SELECT * to permitted columns (requires DB connectivity).

Masking Capabilities

Note: This section describes Resolution mode, the default enforcement mode. In Data Instructions mode, the masking variables below have no effect. See Data Instructions Mode.

The SQL Database Authorizer includes masking capabilities designed to protect sensitive data while maintaining its usability in various contexts. By implementing these masking techniques, users can ensure that sensitive information remains confidential and compliant with data protection regulations.

Some Masking capabilities require "masking instructions" as part of the PDP Policy Resolution response. These masking instructions derived from the Actions are used in Policy modeling and are returned as part of the PDP calculation.

See the Environment Variables for the Docker Container for information on how to use these masking capabilities as Environment Variables.

Masking Null

By default if a column is not permitted, it will be masked as NULL in the modified query. This parameter allows users to set a default masking for any column with an unknown data type which does not get a more specific masking instruction. The parameters below allow setting specific masking characters for typed columns. DB connectivity may be required for the Authorizer to retrieve the data type. See example in Masking Capability Examples.

Masking Alphanumeric

This variable allows users to obscure alphanumeric data, ensuring that characters are replaced or altered to prevent unauthorized access while preserving the overall structure. By default alphanumeric values will be masked using asterisks (****), but you can use this variable to define any other character for masking.

Masking Numeric

Numeric values can be masked to hide sensitive numeric information, such as age, salary, phone number, social security number, etc., ensuring that only authorized users can view the actual figures. By default, numeric values are masked as '0' (zero) but you can use this variable to define any other number for masking, like '999', '-1' etc.

Masking Date

Date columns can be masked to secure sensitive dates such as Date of Birth and others. By default masked date columns use 00/00/0000 but can be adjusted with this variable.

Masking Default Mask as String

This Boolean variable guides the Authorizer to use string masking as default instead of NULL. If set to 'true' the default masking uses the masking characters defined for MASKING_DEFAULT_STRING_MASKING.

Masking Default String Masking

This variable is used as the default masking when MASKING_DEFAULT_MASK_AS_STRING is set to 'true'.

Masking Supported Functions

This variable is applied when using database functions (native or custom) as masking functions, guided by Actions in the Policy Resolution response. The variable holds a list of functions. If the Action associated with column access is included in this list, masking is applied to the column by using the specified function, which will execute when the query is sent to the database.

Masking within a Function

If the original query includes columns within functions, and these columns require masking according to Policies, masking is applied directly to the column within the function. This ensures that function use does not bypass masking and expose unauthorized data. This behavior holds across complex query structures, including columns referenced inside LATERAL joins, aggregate FILTER clauses, and ordered-set aggregates. Masking is applied consistently regardless of how the column is structured in the query.

This is not a configurable variable, but a generic masking behavior, and it applies in both enforcement modes. See example in Masking Capability Examples.

Conditional Masking

This advanced feature applies masking based on specified Conditions or Rules, ensuring that data is only revealed to authorized users under predefined circumstances.

By setting specific Actions in the Conditional_Masking_Actions variable, users can direct the Authorizer to apply conditional masking based on privilege response sections, rather than default row-level filtering. The order of Actions in this variable determines the sequence in which conditions are applied to the masked column.

To create a conditional masking policy, connect conditions within the same policy using Rulesets on a data asset type that represents a table, alongside a predefined Action and specific columns (as defined by a separate asset type). This predefined Action is then set in the Conditional_Masking_Actions variable, enabling conditional masking instead of row filtering. See example in Masking Capability Examples.

Masking Capability Examples

Below are a few examples of Masking Capability SQL requests and responses based on an original query labelled accordingly:

Original Query

SELECT id, fullName, dateOfBirth, ssn, location, revenue, customerType
FROM Customers c
WHERE c.customerType = 'A'

Full Query Response Table

id fullName dateOfBirth ssn location revenue customerType
u123 David Cohen 21/03/1984 29837645 NY 80000 A
u234 Sam Watts 12/08/1971 817239434 LA 110000 B
u345 Alexandra Claire 08/02/2001 983474597 SF 90000 A

Masking Null Example
SQL Query

SELECT id, NULL as fullName, NULL as dateOfBirth, NULL as ssn, location, NULL as revenue, customerType
FROM Customers c

Response Table:

id fullName dateOfBirth ssn location revenue customerType
u123 NULL NULL NULL NY NULL A
u234 NULL NULL NULL LA NULL B
u345 NULL NULL NULL SF NULL A

Masking Default String Masking Example
SQL Query

SELECT id, '****' as fullName, '00/00/0000' as dateOfBirth, 0 as ssn, location, 0 as revenue, customerType
FROM Customers c
WHERE c.customerType = 'private'

Response Table

id fullName dateOfBirth ssn location revenue customerType
u123 *** 00/00/0000 0 NY 0 A
u234 *** 00/00/0000 0 LA 0 B
u345 *** 00/00/0000 0 SF 0 A

Masking Function for SSN - Keeping the last three characters
SQL Query

SELECT id, NULL as fullName, NULL as dateOfBirth, ThreeCharsMasking(ssn) as ssn, location, NULL as revenue, customerType
FROM Customers c

Response Table

id fullName dateOfBirth ssn location revenue customerType
u123 NULL NULL ***645 NY NULL A
u234 NULL NULL ***434 LA NULL B
u345 NULL NULL ***597 SF NULL A

Masking within a Function Example

This function allows sensitive data to be masked even when used as arguments in functions. This ensures that any sensitive information processed remains protected throughout the execution of queries.

Original SQL Query:

SELECT id, CONCAT(firstName,lastName), DATE_PART('year', dateOfBirth) as yearOfBirth, ssn, location, ROUND(revenue) as revenue, customerType FROM Customers c

Modified SQL Query:

SELECT
  id, CONCAT('***', lastName), DATE_PART('year', '00/00/0000') as yearOfBirth,  ssn,  location, ROUND(0) as revenue, customerType FROM Customers c

Response Table

id fullName dateOfBirth ssn location revenue customerType
u123 *** Cohen 00/00/0000 29837645 NY 0 A
u234 *** Watts 00/00/0000 817239434 LA 0 B
u345 *** Claire 00/00/0000 983474597 SF 0 A

Conditional Masking Example:
In this example, we demonstrate how multiple conditional masking policies interact to determine the masking outcome for sensitive data, specifically Social Security Numbers (SSNs).

Policies Defined:

Policy 1: Mask SSN with '*' when the location is 'NY'.
Policy 2: Mask SSN using a function that keeps the last three characters when the account type is 'Private'.
Policy 3: Apply Access action on records when location is not 'CH'.

Conditional Masking Actions Configured: asteriskMasking, 3chars (in this order).

Outcome:

  1. David: SSN masked according to Policy 2 (keeping the last three characters): ------789.
  2. John: Both Policy 1 and Policy 2 apply, resulting in conflicting masking rules. The masking is resolved based on the order of conditional masking actions, resulting in full masking as per Policy 1: *********.
  3. Robert: SSN masked according to Policy 1: *********.
  4. Alice: No Policies apply, so the SSN remains unmasked: 8734651295.
  5. Sidney: Although Sidney's SSN fits Policy 2, the record is filtered out completely due to Policy 3 (location = 'CH').

Table Data Overview:

Id Name SSN Location Account Type
123 David ------789 LA Private
234 John ********* NY Private
345 Robert ********* NY Business
567 Alice 873465129 SF Basic
987 Sidney 48375873 CH Private

HasValue Masking

The HASVALUE function enables conditional masking based on whether a specific Attribute has a value. It supports checks for NULL, EMPTY, or both (NULLANDEMPTY), and is typically used in Calculated Attributes to control when sensitive data should be shown or masked.
To use this capability, define a Calculated Attribute that evaluates the presence of another Attribute.

Example:

HASVALUE({{role}}, NULLANDEMPTY)

This expression returns true only when the role Attribute is present and not empty. In the SQL Database Authorizer, Policies using this logic can dynamically trigger masking, hiding columns for users who lack the required Attribute. The Authorizer automatically translates this condition into SQL logic, such as IS NULL or empty string checks, ensuring enforcement is based on the completeness of identity data.

For more information about how HASVALUE is defined and used in Calculated Attributes, refer to Working with Calculated Attributes.


Example: HasValue Masking

Original Query

SELECT id, fullName, dateOfBirth, ssn, location, revenue, customerType
FROM Customers c

Policy Condition

HASVALUE({{role}}, NULLANDEMPTY)

This condition instructs the Authorizer to mask data for users whose role Attribute is either null, an empty string, or an empty array.


Masked Query for Users Without Role Value (HASVALUE = false)

SELECT id, NULL as fullName, NULL as dateOfBirth, NULL as ssn, location, NULL as revenue, customerType
FROM Customers c

Response Table

id fullName dateOfBirth ssn location revenue customerType
u123 NULL NULL NULL NY NULL A
u234 NULL NULL NULL LA NULL B
u345 NULL NULL NULL SF NULL A

Data Instructions Mode

In Data Instructions mode, the PDP returns explicit row-filtering and column-masking instructions for each table referenced in the query. The Authorizer applies those instructions to the SQL statement exactly as received. You define masking values, masking functions, and masking Conditions in your Policies, so you no longer maintain masking literals in the Authorizer configuration.

Data Instructions mode supports PostgreSQL, Microsoft SQL Server, and Google BigQuery.

Enabling Data Instructions Mode

Data Instructions mode is off by default. You enable it per Authorizer deployment in the Helm values.yaml file or through Docker environment variables.

  1. Set the enforcement mode to Data Instructions.
  2. Set the PDP host and port. The Authorizer builds the correct endpoint path for the selected mode from these values.
  3. Remove RUNTIME_URL if your deployment sets it. A deployment that defines only RUNTIME_URL cannot start in Data Instructions mode.
  4. Restart the Authorizer.
Setting Helm key Environment variable Default Description
Enforcement mode <TBD_HELM_MODE_KEY> <TBD_MODE_ENV_VAR> Resolution Selects the enforcement mode at startup.
PDP host <TBD_HELM_HOST_KEY> <TBD_HOST_ENV_VAR> None Address of the PDP Runtime. Required in Data Instructions mode.
PDP port <TBD_HELM_PORT_KEY> <TBD_PORT_ENV_VAR> None Port of the PDP Runtime. Required in Data Instructions mode.

The Authorizer validates these settings at startup. If the mode value is invalid, or the PDP host and port are missing, the service does not start and writes the reason to the startup log.

The MASKING_* variables described in Masking Capabilities have no effect in this mode. All other settings, including database connectivity, caching, Redis, secret management, and pass-through headers, work the same in both modes. For the full list of deployment settings, see Deployment Patterns.

Least Privileges

Data Instructions mode adds the leastPrivileges request flag. Send it in the flags object of the /resql request. It defaults to true, so if you omit it, the Authorizer applies the most restrictive behavior.

{
  "sql": "SELECT id, fullName, ssn FROM Customers c",
  "user": "Jordan",
  "entityTypeId": "Main",
  "clientID": "YOUR_CLIENT_ID",
  "clientSecret": "YOUR_CLIENT_SECRET",
  "flags": {
    "leastPrivileges": true,
    "expandStarColumn": true
  }
}

Row access and column access are independent. A Policy that grants all rows does not grant access to any column. With leastPrivileges on, the query returns only the columns your Policies explicitly cover.

Row instructions Column instructions leastPrivileges Result
None None true The whole query returns no rows.
None None false The query runs unchanged.
Present Present true The Authorizer filters rows, applies column instructions, and returns NULL for every column without an instruction.
Present Present false The Authorizer filters rows, applies column instructions, and leaves every other column unchanged.
Present None true The Authorizer filters rows and returns NULL for every column.
Present None false The Authorizer filters rows and leaves every column unchanged.

When a query references several tables and any one of them has no instructions, leastPrivileges: true denies the whole query, including joins, subqueries, and CTEs. The Authorizer never denies a single table in isolation.

The following flags apply to Resolution mode only. In Data Instructions mode, leastPrivileges and your Policies determine the same behavior.

Resolution mode flag Equivalent in Data Instructions mode
emptyRLSTreatAsDenied leastPrivileges: true
emptyCLSTreatAsPermitted leastPrivileges: false
oppositeColumnFilteringBehavior leastPrivileges
ignoreRuntimeCLSResponse Remove column instructions in your Policies

Row Filtering

The PDP returns an allow condition and, optionally, a deny condition for each table. The Authorizer injects both into the WHERE clause, so a row must match the allow condition and must not match the deny condition.

SELECT id FROM Customers c WHERE (location IN ('NY','SF')) AND NOT location = 'SF'

A table with only a deny condition, or with a deny condition that covers all rows, returns no rows.

Column Masking

Each column instruction specifies an operation and, when relevant, a value.

Operation Effect Example output
REPLACE Replaces the column value with the value from the Policy. '****' AS fullName
FUNCTION Wraps the column in the database function named in the Policy. ThreeCharsMasking(ssn) AS ssn
VIEW Leaves the column unchanged. location

When a masking instruction includes a Condition, the Authorizer applies it as a CASE WHEN expression. The PDP resolves competing instructions for the same column before it responds, so the Authorizer receives at most one instruction per column, and you do not configure an order of Actions. Masking within a Function applies in this mode as well.

Data Instructions Example

This example uses the same original query and data as Masking Capability Examples, with leastPrivileges on.

Policies Defined:

  • Row-level Policy: Allow rows where location is 'NY' or 'SF'.
  • Masking Policy 1: Replace fullName with '****' when the location is 'NY'.
  • Masking Policy 2: Mask ssn with the ThreeCharsMasking function.
  • Masking Policy 3: View id, location, and customerType.

No Policy covers dateOfBirth or revenue.

Modified SQL Query

SELECT id, CASE WHEN location = 'NY' THEN '****' ELSE fullName END AS fullName, NULL AS dateOfBirth, ThreeCharsMasking(ssn) AS ssn, location, NULL AS revenue, customerType
FROM Customers c
WHERE c.customerType = 'A' AND (location IN ('NY','SF'))

Response Table

id fullName dateOfBirth ssn location revenue customerType
u123 **** NULL ***645 NY NULL A
u345 Alexandra Claire NULL ***597 SF NULL A

dateOfBirth and revenue return NULL because no instruction covers them. With leastPrivileges off, both columns return their original values.

Modeling Policies for Data Instructions Mode

  • Pair every masking Policy with a Row-level Policy. The PDP returns instructions for a table only when a Row-level Policy covers it. A Column-level Policy without a matching Row-level Policy returns nothing for that table, and with leastPrivileges on, the query returns no rows.
  • Grant all rows explicitly. To give full row access to a table, create a Row-level Policy whose Condition permits all rows.
  • Grant column access explicitly. With leastPrivileges on, a column without an instruction returns NULL. Use the VIEW operation, or turn leastPrivileges off, to return a column unchanged.
  • Define a value for every REPLACE instruction. The Authorizer returns NULL for a REPLACE instruction with a blank value.

For Asset Type configuration, see Data Access Policies.

What a Denied Query Returns

A denied query returns a successful response with a rewritten statement that runs normally but returns zero rows. For PostgreSQL and BigQuery, the Authorizer wraps your original query so it keeps the same column list:

SELECT * FROM (SELECT id, fullName FROM Customers c) AS t WHERE 1=0

For SQL Server, the Authorizer returns a fixed statement that returns zero rows and does not preserve the original column list.

Every deny looks the same in the response. To find out why the Authorizer denied a query, check the Authorizer logs.

Nested Queries from Related Tables

Some access rules depend on data in a different table from the one a query reads. For example, a user may see an order only if the order's customer is in their region, but the region lives in the customers table. The SQL Database Authorizer handles this with a Correlate Action.

A Correlate Action relates a column in the queried table to a column in a related table, such as orders.customer_id and customers.id. Filter rules on the related table define which of its rows can take part in that relationship. The Authorizer combines both into a nested SQL Condition and returns a row from the queried table only when at least one related row matches the relationship and passes the related table's Filter rules. It does this even when the original query doesn't reference the related table.

The Authorizer builds the nested Condition with EXISTS. The results therefore never include columns from the related table, and the Authorizer never duplicates a row when several related rows qualify. The Authorizer adds the Condition to the query's existing WHERE clause, and every other row-level restriction on the queried table still applies.

Supported Operators

Operator Nested Condition The Authorizer returns a queried row when
Equals EXISTS (... t1.attr1 = t2.attr1 AND <related filter>) At least one qualifying related row has the same value.
Not equals EXISTS (... t1.attr1 != t2.attr1 AND <related filter>) At least one qualifying related row has a different value.

With either operator, the Authorizer excludes a row when no related row qualifies, or when the row's correlated column is NULL.

How the Authorizer Builds the Related Filter

The related filter is the same filter the user gets when they query the related table directly, combined from all of the user's Policies. If a Policy grants all rows of the related table (a rule with no filter), only the column match applies.

Example

A user may see an order only if the order's customer is in the US. The query reads only the orders table, but the region is stored in the customers table.

Data Mappers map the Orders Asset Type to the orders table and the Customers Asset Type to the customers table.

Policy Resolution Response

Asset Type Action Attribute Operator Value Meaning
Orders Correlate customer_id EQUALS customers.id Relate each order to the customer with the matching ID.
Customers Filter region EQUALS US Only customers in the US qualify.

In the Correlate Action, the value (customers.id) refers to a column in the related table. In the Filter Action, the value (US) is a literal string.

Customers Table

id region
c1 US
c2 EU

Original Query

SELECT * FROM orders;

Modified Query

SELECT o.*
FROM orders AS o
WHERE EXISTS (
    SELECT 1
    FROM customers AS c
    WHERE o.customer_id = c.id
      AND c.region = 'US'
);

Response Table

id customer_id
1 c1
2 c2
3 NULL
4 c2

The Authorizer returns order 1 only, because its customer, c1, is in the US. Orders 2 and 4 belong to c2, which is in the EU. Order 3 has no customer, and a NULL value never matches.

Not Equals Example

With the same data and a Correlate Action that uses not equals (orders.customer_id != customers.id), the Authorizer produces:

SELECT o.*
FROM orders AS o
WHERE EXISTS (
    SELECT 1
    FROM customers AS c
    WHERE o.customer_id != c.id
      AND c.region = 'US'
);
id customer_id
1 c1
2 c2
3 NULL
4 c2

The only US customer is c1. Orders 2 and 4 belong to a different customer, so the Authorizer returns them. The Authorizer excludes order 1 because its customer is c1, and order 3 because its customer is NULL.
:::

Requirements

  • Data Mappers for both tables. The Authorizer matches each table to its Asset Type to apply the rules. For more information, see Data Mappers.
  • A PDP response that includes the related table. Make sure that:
    • A Policy grants the user access to the related table.
    • If you limit runtimeFineTune.resourceTypes, the list includes the related table, not only the tables in the query.
    • The table name in the Correlate value matches the related table's name in the PDP response exactly, apart from letter case. For example, public.t2.attr1 doesn't match a related table named postgres.public.t2.
  • Resolvable Correlate Actions. If the Authorizer can't resolve or translate a Correlate Action, it returns an error. It never drops the Condition silently.

Data Mappers

The SQL Database Authorizer supports Data Mappers, providing a translation layer between your physical data model and logical Asset Types. Asset Types represent business concepts (e.g., Location, Country), while Data Mappers associate them with physical SQL objects: schemas, tables, fully qualified names (FQDNs), or even JSON fields.

This enables you to define a single Policy against a logical Asset Type and enforce it across multiple physical structures with differing schemas or column names. For example, db1.schema1.country and db2.schema2.city can both be mapped to the Location Asset Type. During query processing, the Authorizer matches the object in the SQL FROM clause to its Data Mapper definition, translating it to the logical Asset Type for consistent row-level Policy enforcement.

Configuration

The SQL Database Authorizer uses Data Mappers to translate between physical SQL objects and logical Asset Types for row-level filtering. For row-level filtering Asset Types, Data Mappers are mandatory. The Data Mapper must match the FROM clause of the SQL query for the Asset you want to protect. For example, if the query is:

SELECT * FROM marketing.orders("122")

Then the Data Mapper for this Asset Type must be marketing.orders.

Data Mappers are not required or available for column-level filtering. For more information, refer to our article on Dynamic Data Mapping.


Notes

  • Database Connectivity Required: Some features, such as SELECT * resolution and type-aware masking, require a live connection to the database.
  • Masking Type Limitations: Certain masking types may be restricted based on the underlying database engine.
  • SELECT * in Data Instructions mode: A SELECT * query on a masked table returns no rows by default, because the Authorizer never returns an unmasked *. To mask columns in a SELECT * query, set expandStarColumn: true and enable database connectivity. Expanded columns appear with masked columns first, then the remaining columns in alphabetical order. A SELECT * query on a table with only row filtering runs with the filter injected.
  • Unreachable PDP: If the Authorizer cannot reach the PDP or cannot read its response, it returns the statement rewritten to return zero rows, with the error in the error field. This applies in both enforcement modes. The Authorizer never falls back to the other mode.
  • Unknown masking operations: In Data Instructions mode, the Authorizer skips a column instruction with an unrecognized operation and writes a warning to the log. With leastPrivileges on, that column returns NULL.
  • Switching modes: Each mode caches PDP responses under its own key, so switching modes never reuses a cached response from the other mode. The Authorizer logs the active enforcement mode at startup.

© 2026 PlainID LTD. All rights reserved.