Implement Row-Level Security in RisingWave
Row Security Policies serve as a powerful PostgreSQL feature that controls row-level access based on specific policies. While RisingWave does not natively support Row Security Policies, you can achieve equivalent row-level security through a combination of logical views with access control. This approach ensures that users can only access data they are authorized to see.
In versions prior to v2.4, a bug in logical views’ access control failed to prevent unauthorized access. Ensure your RisingWave runs v2.4 or later.
Scenario
Imagine you have a table employees
that stores employee information, including their department and salary. You want to enforce the following access rules:
- HR Managers can view all employees in the HR department.
- Engineering Managers can view all employees in the Engineering department.
- The CEO can view all employees.
To achieve this, we’ll use logical views to filter data based on user roles and user permissions to restrict access to the underlying table.
Procedure
Create the `employees` table
Create the employees
table to store employee data:
Insert sample data
Insert some sample data into the employees
table:
Create users
Create three users: hr_manager, engineering_manager, and ceo.
Create logical views for each user
Create logical views for each user to restrict their access to specific data.
HR Manager can only view employees in the HR department:
Engineering Manager can only view employees in the Engineering department:
The CEO can view all employees:
Verify privileges
Now we can connect to the database as the user hr_manager
to ensure that they can only query the hr_employee_view
and cannot access the employees
table or other views.