Data Protection
QueryDesk implements a robust data protection system designed to ensure sensitive data never leaves your database while maintaining query functionality. This system is built with security-first principles and provides granular control over data access.
Security Architecture Overview
The data protection system operates at the query processing layer, where all queries are validated and potentially modified before execution. This ensures that employees cannot access sensitive data they shouldn't have permission to view, preventing PII leaks and maintaining data privacy.
Because the rewriting happens before the query runs, the database is never asked for the protected values in the first place. That is a stronger guarantee than masking a result set: tools that fetch the rows and then hide fields have already pulled the sensitive values across the network and through the application, where they can end up in memory, logs, and caches. Here they never leave the database at all.
Core Security Principles
- Data Never Leaves the Database: Protected values are never returned by the database, rather than being fetched and hidden afterwards
- Query Rewriting: Queries are dynamically modified to enforce protection policies
- Allow-List Validation: Only pre-approved SQL syntax and operations are permitted
- Fail Closed: Anything the rewriter cannot fully model is rejected rather than passed through
- Default Protection: By default, all columns are hidden unless explicitly allowed if a policy is assigned
How It Works
Each query is analyzed and then rewritten to enforce the data protection policy.
-- Original query
SELECT id, name, email FROM users;
-- Rewritten query with data protection
SELECT id, '***' AS name, '***' AS email FROM users;
In cases where a user selects with *, the * is replaced with all columns explicitly referenced.
-- Original query
SELECT * FROM users;
-- Rewritten query with data protection
SELECT id, '***' AS name, '***' AS email FROM users;
Protected fields are not allowed to be referenced anywhere in the query, including WHERE clauses as that would allow to infer sensitive data.
-- Original query
SELECT id FROM users WHERE email = 'test@example.com';
-- Rewritten query with data protection
SELECT id FROM users WHERE '***' = 'test@example.com';
Views
Views and materialized views are listed alongside tables (on Postgres, those in the public schema) and are governed by their own column actions. An action on a base table column does not carry through to a view that reads it, so a view column with no action is hidden until a policy or rule shows it.
-- users.email is shown, but the view's email column has no action
CREATE VIEW active_users AS SELECT id, email FROM users WHERE active;
-- Rewritten query with data protection
SELECT '***' AS id, '***' AS email FROM active_users;
Statements That Are Rejected
Protection can only be enforced on statements the rewriter fully understands: SELECT, INSERT, UPDATE, DELETE, and the unions and subqueries built from them. Anything else is rejected with an error rather than forwarded, because a statement that can't be rewritten can't be masked.
In practice this means the following are refused while a policy is in effect:
PREPARE p AS SELECT ssn FROM users; -- and the matching EXECUTE
DECLARE c CURSOR FOR SELECT ssn FROM users; -- and FETCH / MOVE
COPY users TO STDOUT;
DO $$ ... $$;
CALL some_procedure();
Functions that run SQL held in a string, or read a table named in one or on another server, are refused as well, because what they return never passes through the rewriter. The functions refused are the known ones on each engine, along with any function whose name starts with one of them:
- Postgres:
query_to_xml,table_to_xml,schema_to_xml,database_to_xml,cursor_to_xml,dblink,ts_stat,ts_rewrite,crosstab,connectby,xpath_table - Oracle:
DBMS_XMLGEN.getxml,getxmltypeandnewcontext - SQL Server:
OPENQUERY,OPENROWSET,OPENDATASOURCE - ClickHouse:
remote,remoteSecure,cluster,clusterAllReplicas,merge,view,mysql,postgresql,url,file,s3,jdbc,odbc
A function added by an extension that is not on this list is not refused, so review the extensions installed on a protected database.
SELECT query_to_xml('select ssn from users', true, false, '');
-- Function 'query_to_xml' runs SQL or reads a table by name, so it can't be masked
A redacted column also can't decide which rows come back or what they add up to. Masked inside a WHERE, HAVING or JOIN ... ON, any comparison (CASE WHEN, IN, BETWEEN, IS NULL), a GROUP BY, ORDER BY or DISTINCT, an aggregate such as count or max, or a UNION that removes duplicates, it would make the result silently wrong: '***' = '***' matches every pair of rows, '***' = 'x' matches none, and count(DISTINCT '***') is always 1. So the statement is refused with an error naming the column:
SELECT id FROM users WHERE ssn = '123-45-6789';
-- Column 'users.ssn' is redacted, so it can't be used to filter, join or compare rows
A column keeps its redaction when a CTE or a subquery in FROM returns it under another name, so filtering on that output is refused too. The error names the table column behind the output, since that is the one a policy lists, and the output it reached the filter through:
WITH recent AS (SELECT id, ssn AS tax_id FROM users)
SELECT id FROM recent WHERE tax_id = '123-45-6789';
-- Column 'users.ssn' is redacted, and 'recent.tax_id' is computed from it, so 'recent.tax_id' can't be used to filter, join or compare rows
The column named in the error is the one to show in the policy. Otherwise, filter on a column that is shown.
In the QueryDesk web UI the Data protection panel opens on a query refused this way, as it does on one that ran. It shows the query as it would have been rewritten and every column it referenced, and the redacted column can be requested there. The query itself is not run.
Session and transaction statements carry no row data, so they still pass through unchanged and drivers keep working: SET, SHOW, RESET, BEGIN, COMMIT, and ROLLBACK.
This applies to every path that runs a protected query — the QueryDesk web UI, database clients, the Postgres proxy, and the MCP run_query tool.
MongoDB
On MongoDB a policy redacts fields, nested ones included, and QueryDesk masks them inside MongoDB at the start of each read. A hidden field can't be used to filter, sort, group or join. See MongoDB.
System Tables
System catalogs (pg_stats, pg_class, information_schema.columns, MySQL's mysql.user, and so on) can expose real column values — pg_stats, for example, publishes sampled values from every table. They are therefore blocked by default: with a policy assigned, a query against a system table fails closed.
When a tool genuinely needs catalog access, list the tables it needs under Allowed system tables in the policy editor. Each entry is either a table name or a schema/database name that allows everything inside it:
pg_class
information_schema
Allowlisted tables bypass masking entirely, so only add catalogs you have confirmed do not surface protected data. The allowlist is per policy, so one role can be granted catalog access without widening it for everyone.
Managing Policies
Super admins manage policies from Data protection in the QueryDesk rail. Nobody else sees the item, and opening its address sends them to the home page. The page lists every database that has a policy, with its policies under it. A policy row shows:
- whether it is inherited, and from which database
- whether it is the database's AI data protection policy
- how many roles and members it governs
- how many of its columns have no action yet
- how many Unredaction requests are waiting on it
Search filters the list by database or policy name. Create policy asks which database the policy is for and lists every database, including those with no policy yet. The new policy opens once it is created, and its database is listed from then on.
Each database has an Actions menu:
- Auto apply rules opens the database's rules.
- Setup JSON protection action creates the
protect_jsonfunction the JSON structure action needs. It runs as the database credential you choose, which must be one of that database's credentials. The function is written for Postgres, so the item appears on Postgres databases only.
Inherited Policies
A policy can be put in effect on other databases with Add inherited database, which is how a replica is kept redacted exactly like its primary. The inherited policy has no actions of its own. Each time it is used, a column takes the action the source policy gives the column with the same table and column name (on Postgres, the same schema too), and the source policy's allowed system tables apply.
A change to the source policy, by hand or through an auto apply rule on the source database, is in effect on every inheriting database on the next query. Nothing has to be synced or edited on the inheriting side.
On an inheriting database a column is hidden when:
- the source database has no column with that table and column name, or
- the source policy has not given the column an action.
A column that is added to an inheriting database later takes the source policy's action once the database's schema is synced.
Auto apply rules created on the inheriting database do not change its inherited policies. Create the rule on the source database instead.
Access requests from people governed by an inherited policy are reviewed on the source policy's page, where each request shows the database it was made on. Approving one shows the column on the source database and on every inheriting database that has it. A column the source database does not have cannot be requested.
Syncing a policy from another installation
When several Devhub installations share one license, for example one in each region, a database on one installation can sync a policy from a database on another. The synced policy then matches the policy it comes from, kept up to date, so each policy is set up once.
In this section, the source installation is the one a policy is synced from, and the source database and source policy are the database and policy on it. Your installation and your database are where you sync it to. On your database, a synced policy is the read-only copy of the source policy, and a local policy is one created on your installation.
Installations are linked to the license under Billing. Once another installation is linked, the Data protection page on your installation lists every installation on the license with the address your installation reaches it at, and a super admin can sync a policy:
- Sync a policy, at the top of the page, works for any of your databases, including one with no policies yet.
- Sync a policy in a database's Actions menu starts with that database chosen.
Choose a source installation, one of its databases, then one of that database's policies. A source policy is listed but can't be picked when it is already synced onto your database, when it is itself a synced policy on the source installation, or when another synced policy from that source installation already has its name on your database. Before anything changes, the dialog says what arrives and whether a local policy has the same name. The first sync runs as soon as you confirm.
Each installation calls the others directly and signs every call and answer. Nothing goes through the licensing service. By default your installation calls a source installation at the public address the license lists for it.
When your installations share a private network, such as a peered VPC or a cluster service, a super admin can have your installation call a source installation there instead. Click Change on its card under Installations on this license, choose Private address, enter the address and click Test address. Your installation calls that address, and Save is offered only once the answer is signed by that source installation's key on the license. From then on every sync and access request to that source installation uses the private address. Each card shows whether it is reached at its public address or a private one, and a private one is shown beside the public address. To go back, click Change and choose Public address.
An answer from a private address is checked the same way as one from the public address. When something else starts answering there, its answers carry the wrong signature, so syncs from that source installation fail with nothing written.
From then on, every 5 minutes, the synced policy copies from the source policy:
- its column actions and allowed system tables
- which columns have an access request waiting
Columns are matched by table and column name (on Postgres, the same schema too). A column of your database that the source database does not have, or that the source policy gives no action, is hidden.
A synced policy's name only has to differ from other synced policies from the same source installation. A synced policy can have the same name as a local policy, and both stay: the local policy keeps its columns, its roles and members, and its access requests. In Database settings the synced policy is listed with its source installation, for example Support (Northwind US), so the two can be told apart.
A synced policy is always read only. Its page and its tables show the column actions and allowed system tables without a way to change them, auto apply rules skip it, and Edit is not offered. Which roles and members it governs, and which policy is your database's AI data protection policy, are set on your installation: assign it in Database settings like any other policy.
When someone governed by a synced policy clicks Request access, the request opens on the source installation, naming them by their name and email, and the column reads Requested. A super admin on the source installation approves or declines it, and an approved column shows on your installation within 5 minutes. Nobody on your installation can approve it. If the source installation can't be reached, the source database has no such column, or the source policy was deleted, the person is told and nothing is opened. A synced policy whose source policy was deleted offers no Request access at all, and says so before anyone asks.
Each synced policy shows its source database and source installation, and when it last synced. The Synced and Local filters list one kind or the other. A synced policy whose last sync failed is flagged with the reason and when its copy was last synced, and the failing ones have a filter of their own. A failed sync writes nothing: the last copy keeps redacting, so a failure never shows a column that was hidden. The same holds when the source installation answers without its signature or leaves the license. When the source installation can't find the source database, for example because it was deleted, the synced policy shows as a failing sync and keeps its last copy. Stop syncing removes it once nothing is assigned to it.
Stop syncing, on the synced policy's page, deletes it from your database. It can only be done once no role or member is assigned to it, it is not the AI data protection policy and no other database inherits it, since a grant left with no policy shows every column. Sync now on the same page syncs at once.
When the source installation deletes the source policy, the synced policy stays on your database, read only and still redacting with its last copy, and is labelled as deleted on the source installation. Move what it governs to another policy, then delete the synced policy with Delete on its page.
Policy Assignment and Evaluation
A data protection policy is attached to a grant on a database. The grant is made to a user directly or to a role. QueryDesk decides what a user sees in this order:
- Direct grant: A grant made to the user decides alone. If it has no policy, the user's queries are not redacted, whatever their roles carry.
- Role grants: With no direct grant, every grant the user's roles hold on the database counts, Run Queries and Approver alike. Their policies are combined, and the stricter action wins per column. A role grant with no policy lifts nothing.
- No policy: If none of those grants has a policy, no data protection is applied.
The same user gets the same result on every query. When a user's roles carry more than one policy, each column is decided like this:
| The policies give the column | The user gets |
|---|---|
| Show in every policy | The column as stored |
| Show in some, JSON in the rest | JSON redaction |
| Show in some, hide in the rest | Hidden |
| JSON in one, hide in another | Hidden |
| One custom action, in every policy or beside show | That custom action |
| Two different custom actions | Hidden |
| No action in at least one policy | Hidden |
A system table is reachable only when every one of those policies lists it under Allowed system tables.
The Data protection panel names every policy that applied to the query. With more than one, each redacted column has a line that says what each policy does to it. Request access opens one request on each policy that redacts the column, and the column stays redacted until every policy shows it. Run the query again after an approval to see the change.
Peer Review and Unredacted Runs
Data protection applies to every query, including one that waits for a peer review. A reviewer approves the query, not access to protected columns, so an approved query is redacted the same way as one on a credential that requires no review.
When someone needs to see protected values for one query, they can ask to run that query unredacted:
- Run the query. The result comes back redacted, or the query is refused because it filters on a redacted column.
- Open Data protection above the results and choose Request unredacted run.
- The query goes to the pending queue marked Unredacted run. It waits for at least one peer review, even on a credential that requires none. The reviewer sees which columns the run reveals and which policies redact them before approving. When more than one policy applies to the author, the reviewer sees what each one does to every column.
- Once approved, the author runs it once from pending queries with every column shown. A filter on a redacted column runs as written.
You can also ask before running anything: in the Run query window, turn on Run unredacted and choose Request unredacted run. The query goes to the pending queue as in step 3, and nothing runs until it is approved. The Run unredacted toggle appears only when a data protection policy applies to you on that database.
This is a different request from Request access on a column:
| Request unredacted run | Request access | |
|---|---|---|
| Asks for | One query, run once with nothing redacted | One column shown from now on |
| Approved by | A peer who can approve queries on the database | A super admin |
| Changes a policy | No | Yes, every policy that redacts the column, for everyone it applies to |
Whether members can ask at all is a database setting, Allow requests to run a query unredacted, which a super admin changes on the database's settings page, through the API or with Terraform (unredacted_runs_allowed). It is on for databases created before v2.46.0 and off for databases created since. Turning it off stops new requests and stops a request that has not run yet from being approved or run. Runs that already happened stay in the audit log.
Every unredacted run is marked in the audit log with who asked, who approved it or that it was a bypassed approval, every policy that applied to the author, and the columns it revealed. The audit log stream marks it too, with the columns it ran with unredacted. Show only in the audit log's header narrows the log to unredacted runs, to bypassed approvals, or to runs that are both. The result rows of an unredacted run are never retained.
A query refused because it filters, sorts or groups by a redacted column can be requested. A query refused for a reason that stops it from being rewritten at all cannot, such as sorting by the alias or position of a redacted column in the output, or a statement that can't be masked. AI queries and service account queries cannot be run unredacted.
Analyze in the run options is redacted the same way. A plan shows no values, but the row counts under a filter can give one away, so the query is planned as data protection rewrote it, and a filter, join or sort on a redacted column is refused. On a credential that requires reviews, an analyze waits for its review like any query. When one is refused, Data protection offers Request unredacted run as it does for a query, and once approved the author analyzes it from the pending queue, as written.
The request is offered when at least one column the query reads is redacted for its author, whichever of their policies redacts it. Until the request is approved, the query stays redacted by all of them. A user whose direct grant has no policy, or whose role grants all have none, sees every column already and has nothing to request.