Row-Level Security 101: The Basics of Row-Level Security - Satori

Row-Level Security 101: The Basics of Row-Level Security

What Is Row-Level Security?

Row-Level Security, or RLS, is a security mechanism that limits the records in a SQL Server table based on the current user’s authorization context. This type of security means that the data from the tables are presented based on the user’s identity and the records to which the user has access. This option provides certain users access to their data solely, with no authority to view the data of other users.

Instead of handling limits at the application level, Row-Level Security restricts users at the database level. The database applies this access control to the table whenever a query runs, regardless of which application tier gets used. This feature enables a more advanced security system to handle the limits without external circumstances.

Platform Specific Examples of Row-Level Security

Row-level security can be applied at the database level by native capabilities. As an example, you can refer to our guides for Snowflake row-level security, MS SQL row-level security, or Postgres row-level security.

Even in databases that do not have native support, you may craft your own RLS by using abstraction layers (such as views and functions). For example, you can refer to our guide for Amazon Redshift row-level security.

It is important to note that with Satori, you can apply row-level security on any data platform, as access control policies are decoupled from the native data store’s capabilities.

Advantages of Row-Level Security

Row Level Security enables programmatic control over whether or not a user can access or edit a row of data. Switching these constraints to the database level has several significant benefits:

Disadvantages of Row-Level Security

Row-level security is a development of user-level security. The visibility of distinct database rows or records is determined by the level of access granted to specific users or user groups. It does, however, have a few drawbacks:

Examples of Row-Level Security

To give a better understanding of when row-level security can be a good solution, let’s discuss some use-cases of what challenges it can solve.

Example 1: Data Localization

In the first example, ACME Industries, a global company, has data analysts from different regions. To meet compliance requirements, the requirement is to enforce limitations on data access, so that analysts from different regions can only access details of customers from their own region.

For this to happen, regardless of the data store technology, what’s needed is a row-level security policy, that adds filtering according to a mapping between the users’ identity groups (or other attributes), and the data in the tables. For example, the policy can add a filter of “WHERE region IN (‘eu’, ‘uk’)” when an analyst is allowed to view customer details from Europe & UK.

Example 2: Event Types

In the second example, data for different system events is kept in a table, with a semi-structured report containing the technical details of the event. In certain cases, the technical details may contain sensitive operational data. A row-level security policy can be placed to add filtering on the event_type column, according to the user’s identity.

Implementation Example: Postgres

The following implementation example is taken from our PostgreSQL RLS guide:

Allowing managers to edit their own rows

Here is an example showing how to create a policy that ensures only members of the “manager” role can access only the rows for a specific account. The code in this and the following example was shared in the PostgreSQL documentation.

CREATE POLICY manager_policy ON accounts
  FOR SELECT, UPDATE, DELETE
  USING (user_id = current_user);

Row-Level Security vs. Column-Level Security

Data access is restricted at the row level with Row-Level Security, whereas data access gets restricted at the column level with Column-Level Security. For example, because Boston is a value (row) in the City Dimension, only salespeople in Boston can view sales in this city. This is row-level security.

Only members of the Marketing Team, on the other hand, have access to the discount value (one of the columns). Discount is a column; hence this is an example of Column-Level Security.

Summary

Row-Level security may appear to be a difficult and intimidating task, but it is necessary.

RLS is an important part of a company’s data security strategy. You may ensure that each user has proper data visibility by adopting RLS. Without RLS, end users may have access to data they should not, such as payroll or sales data, generating unforeseen problems for your company.

Companies must keep up with changes within their own company and efficiently comply with new standards and regulations, given the current needs in information privacy and security.