RLS (row-level security) enables you to restrict data access for users or user group within a single dataset. For example, you can introduce data access control for different customers.
Warning
When using RLS, restrict access to the connection by using the Execute permission. This will prevent changes to row access permissions and restrict access to opening the preview window and creating a new dataset based on the connection.
RLS only supports access control for row values.
The RLS limits apply to whole rows, not just the fields used to configure access control.
You can introduce row-level access control either in a dataset or a data source.
allowed_value: Grant access to all rows with specified field value. You need to specify the value only if pattern_type is set to value; otherwise, it takes the null value.
pattern_type: How to grant the access:
value: For the specific field value from the allowed_value field.
all: For any field values. In this case, allowed_value must be null.
Configuring RLS at the dataset level requires editing the datatset every time the RLS settings change.
To avoid this, you can move the row-level security logic to the data source side:
Add a new field for storing the DataLens user ID to the source data. All requests to the source will be filtered by this field.
You can view your ID in your account parameters. If you need another user's ID, ask them to open their account and send you the ID.
For each source data row, specify the ID of the DataLens user who should get access to this row. If multiple users must have access to the same row, you can move the access control logic to a separate table and join it to the main table at the dataset level.
In the dataset, configure access to the field containing user IDs:
Interface
JSON
In the RLS settings window, on the Tables tab, click Add rule.
Select User IDs for the Who has access parameter.
Configuring RLS by user ID
Click Save.
In the RLS configuration window, set the RLS configuration in JSON format on the JSON tab:
On the right side of the row, click and select Access permissions.
In the window that opens, set the access permissions for the field:
Interface
JSON
On the Table tab, click Add rule and specify the users, groups, or All users and the field value. For example, to configure user access to all rows with the first-company value:
Who has access: Select the user.
Field values: Enter first-company.
Click Save.
On the JSON tab, set the RLS configuration in JSON format. For example, to configure user access to all rows with the first-company value:
In the source, add a field with the DataLens user IDs to use for filtering. You can add this field to a new table and join it using the JOIN operator.
Add a field with user IDs to the dataset:
If you added a field to an existing table, go to the Fields tab in the dataset and click Update fields at the top of the screen. The user ID field will appear in the list.
If you added a field to a new table, join it using the JOIN operator. To do this, go to the Sources tab in the dataset and drag the new table to the workspace. The table will be automatically linked with the existing table. If required, edit the link between the tables and remove duplicate fields left after the join.
Configure field access permissions:
In the dataset, go to the Fields tab.
Find the field with user IDs. On the right side of the row, click and select Access permissions.
In the window that opens, set the access permissions for the field:
Interface
JSON
In the RLS settings window, on the Tables tab, click Add rule.
Select User IDs for the Who has access parameter.
Click Save. Access will be granted to users whose IDs are specified in the field.
In the RLS configuration window, set the RLS configuration in JSON format on the JSON tab:
Click Save. Access will be granted to users whose IDs are specified in the field.
Save the dataset.
Example
Let's create a dashboard based on sales data by four regions (West, East, North, and South). Regional managers should only have access to their own data, while the company's CEO, to all data.
Define DataLens user IDs.
In the source, create a table named MANAGER_ID, where the region is mapped to the user ID. If a single ID is associated with multiple regions, add all unique pairs:
REGION
MANAGER_NAME
MANAGER_ID
West
Arkady
19287318273912873
East
Vassily
92877912837318927
North
Olga
02993284928374346
South
Dmitry
10836293849237642
West
Maxim
71726123712891283
East
Maxim
71726123712891283
North
Maxim
71726123712891283
South
Maxim
71726123712891283
Open the dataset and add the new table: on the Sources tab, drag the table to the workspace.
Make sure the JOIN is based on the REGION field.
Based on the MANAGER_ID field, customize RLS.
Interface
JSON
Each user will only see data for regions they have access to.
To change the access permissions, update the data in the source table.