OnlyDash guide ·
Postgres row-level security for an admin panel
Postgres can limit which rows a database role can read or write. That feature is row-level security, often called RLS. It runs in the database, on every query that uses the table.
An admin panel also needs a way to show each person only some rows. OnlyDash does that with server-side filters in the panel. Those filters are not RLS. You can use RLS in the database, OnlyDash filters in the panel, or both.
What row-level security does
You enable RLS on a table, then you add policies. A policy names the command, the role, and the condition that must pass. The condition is an ordinary SQL expression. It can use the current database role, or a session setting that your app fills in.
A simple policy for a SELECT might compare a column to current_user. current_user is the database role name, not an email address in the application. Many apps set a session value, such as an email, and the policy reads that value with current_setting.
Once RLS is on, Postgres adds the policy condition to each query for roles that the policy covers. The person does not have to remember a WHERE clause. A direct connection with psql, a SQL client or an app all hit the same rule.
This is part of PostgreSQL. You can read the official description in the PostgreSQL documentation on row security policies.
Limits you should know
The table owner normally bypasses RLS. To apply the policies to the owner too, run ALTER TABLE ... FORCE ROW LEVEL SECURITY. Superusers, and roles with the BYPASSRLS attribute, also bypass RLS. A connection that uses one of those roles still sees every row.
A policy is only as accurate as its condition. If the session setting is missing, the query can fail, or the policy can hide every row. The same can happen if the role name does not match the column. If you enable RLS and add no policy, Postgres uses a default-deny policy. Roles that do not bypass RLS then see no rows.
RLS does not build a grid, a form or a chart. It does not hide a table from a menu. It does not stop you from sharing a connection string. It also does not record who edited a row in an application.
OnlyDash does not show views or materialized views in the panel. If you grant a client access only to a view, that view will not appear there.
How OnlyDash filters rows
Paste a connection string. OnlyDash reads your base tables and builds a grid, filters and forms for each one. Invite a teammate. Give them a Viewer, Editor or Custom role. A Custom rule can hide a table, or limit it to view or edit.
Then set a row filter for that person. A row filter uses is, is one of, or contains. The value can be a fixed value, or the member's own email. OnlyDash applies the filter on the server, so it also limits charts, search, exports and edits.
The filter lives in OnlyDash. A person who connects to the database with psql, or with another tool, is not limited by that filter. If you need the same limit on every connection, add RLS in Postgres as well.
Chart totals use only the rows in the filter. Activity history records writes made in the panel. It does not record edits made directly in the database.
For the invite flow, see Share Postgres data without sharing credentials. For a client who should see only their rows, see Give clients only their rows in Postgres.
Owner sees 17 of 17 rows
No row filter.
| Status | Amount | Due date | Issued date | Paid date |
|---|---|---|---|---|
| Unpaid | 5,000.00 | Jul 1 | Jun 1 | |
| Paid | 7,500.00 | Aug 1 | Jul 1 | Jul 15 |
| Paid | 24,000.00 | May 1 | Apr 1 | Apr 24 |
| Paid | 31,500.00 | Jul 1 | Jun 1 | Jun 19 |
| Paid | 42,000.00 | Jun 1 | May 1 | May 28 |
| Paid | 18,500.00 | Apr 1 | Mar 1 | Mar 21 |
| Paid | 12,750.00 | May 1 | Apr 1 | Apr 15 |
| Paid | 9,800.00 | Jun 1 | May 1 | May 9 |
| Unpaid | 27,300.00 | Sep 1 | Aug 1 | |
| Unpaid | 33,900.00 | Sep 1 | Aug 1 | |
| Unpaid | 15,600.00 | Aug 1 | Jul 1 | |
| Unpaid | 21,400.00 | Sep 1 | Aug 1 | |
| Overdue | 8,900.00 | Jun 1 | May 1 | |
| Overdue | 46,200.00 | Jul 1 | Jun 1 | |
| Overdue | 5,400.00 | May 1 | Apr 1 | |
| Draft | 19,750.00 | Oct 1 | Aug 1 | |
| Draft | 6,300.00 | Oct 1 | Aug 1 |
Swipe to see more.
Connect your Postgres database
Paste a connection string, or try the demo with no sign-up. OnlyDash is in beta.
Use both methods together
A common plan is to keep RLS on the table for every database login. Then set OnlyDash row filters for people who work in the panel. The RLS policy protects direct SQL access. The OnlyDash filter shapes the table, charts, search, exports and edits for each invited person.
OnlyDash connects with the role in your connection string. Postgres applies your RLS policies to that role. If that role is a superuser, the table owner, or has BYPASSRLS, the policies do not limit the panel. If the policies hide rows from that role, those rows do not show in the panel.
Do not assume the two rules use the same column. Align the policy and the filter on a stable key, such as a client id or an email. Test with a non-owner database role, because the owner may bypass RLS.
For each person, you can hide a column or make it read-only, per table, from the Share panel. A hidden column does not show in that person's table, record details, charts, search, CSV export or row history.
See also the Postgres admin panel.
Questions
Does OnlyDash use Postgres row-level security?
No. OnlyDash uses server-side filters in the panel. RLS is a Postgres feature that you can still enable on your tables.
Can I use RLS and OnlyDash filters at the same time?
Yes. RLS applies to database sessions. OnlyDash filters apply to the panel. Use both when people can also connect with other tools.
Why might a table owner still see every row under RLS?
The table owner normally bypasses RLS. To apply the policies to the owner too, run ALTER TABLE ... FORCE ROW LEVEL SECURITY. Superusers and roles with BYPASSRLS also bypass it.
Do OnlyDash row filters apply to charts, search, exports and edits?
Yes. OnlyDash applies the row filter on the server to the table, charts, search, exports and edits.
Connect your Postgres database
Paste a connection string, or try the demo with no sign-up. OnlyDash is in beta.
For a product overview, see the Postgres admin panel.