row-level security

/ˌrəʊ ˌlev.əl sɪˈkjʊə.rə.ti/noun

Row-level security (RLS) is database access control in which rules for each row determine which records a user may view, insert, update or delete.

With row-level security, each customer sees only orders belonging to their own organization.

Row-level security, often abbreviated to RLS, applies access rules to individual rows in a Glossary · In briefdatabaseA database is a structured collection of data that software can store, retrieve and modify. A database management system controls access to that data.Read more. A table can contain data from several users or organizations while each user sees only permitted records. The database performs this check while processing a Glossary · In briefqueryA query is a targeted instruction to a system to retrieve, filter, combine or modify data.Read more.

How does row-level protection work?

An administrator attaches policies to a table. A rule might check whether a row's organization ID matches that of the signed-in user. Only rows satisfying the rule may be read or modified. A separate rule can check whether a user may save new or changed data.

This is particularly useful when customers share tables, as in a Glossary · In briefmultitenantMultitenant describes software in which several customers share one application, each with a separate environment for data, users and settings.Read more application. Because the database enforces the rule, it also applies when different parts of the application access the database.

How it differs from ordinary database permissions

Ordinary database permissions usually determine whether a user may access an entire table or certain columns. Row-level security distinguishes between records within that table. Someone may have access to the invoices table yet only retrieve invoices from their own organization.

RLS does not replace other security measures. Roles, table permissions and user Glossary · In briefauthenticationAuthentication is the process by which a system verifies the claimed identity of a user, device or application.Read more remain necessary. Policies need careful testing: an incorrect rule can hide data unintentionally or expose it. Some databases also have roles, such as administrators or table owners, that can bypass row-level security.