Thanks for the write-up, and for the HMAC docs fix. This is a worthwhile 
direction. A few thoughts from my end.

Please write down the threat model first. The right design depends on which of 
these we are defending against:
(a) a Superset user running arbitrary SQL in SQL Lab on the shared reader 
connection;
(b) a leaked or misused analytics_reader credential used directly with psql.

For (a) there may be a much cheaper fix than RLS. If the reader database 
connection is created with "Expose in SQL Lab" turned off, charts and 
dashboards keep working but nobody can type SQL against it. Please check 
whether that works in the Superset 4.1.1 we pin. If it does, SQL Lab 
restriction stops being "not provided" in SECURITY.md §9 with only a config 
change and a test. For (b), a signed token does not help: whoever holds the 
credential can set any session variable and replay any token. Only per-user 
roles do.

FORCE ROW LEVEL SECURITY would break dbt. The marts are owned by the loader 
role (dbt). With FORCE, the policies would apply to the owner too, so dbt's 
incremental windows, its deletes and its tests would see no rows. I'd create 
the policies only for analytics_reader and not use FORCE, or add an explicit 
permissive policy for the loader.

Watch for a fail-open gap when tables are rebuilt. In the roles script we set 
default privileges so the reader automatically gets read access to anything the 
loader creates in the analytics schema. That means a freshly recreated mart 
(full refresh, table materialization) is readable by the reader immediately, 
before the on-run-end macro has switched RLS on for it. I'd prefer the policy 
to be applied in a per-model post-hook inside the same transaction, or by an 
event trigger that fires when a table is created in that schema. Whichever we 
pick, add a catalog test that every table in the analytics schema has row 
security enabled, so a new mart can't ship unprotected.

On how to pass the user. You're right that a plain session setting can't be 
trusted: a SQL Lab user can overwrite it.

Signed token: this needs a query hook in Superset that sets it for every 
statement, including async queries, scheduled reports and thumbnails, which run 
as a different executor. It must be transaction-local or set on every 
statement, because pooled connections would otherwise carry one user's identity 
into the next request. A missing or expired token must give zero rows.

Per-user roles with impersonation: this is the stronger option, since there is 
no shared secret and it covers (b). Please verify that Superset 4.1.1's 
PostgreSQL engine spec supports impersonation, because I'm not sure it does. If 
it works by switching roles, a user can switch back, so the connection role 
must see nothing and only the per-user roles can see rows. The cost is 
provisioning and syncing roles with Superset users.

Superset's own RLS filters: I wouldn't rely on them for this. The SQL Lab flag 
for them is still marked as testing and it works on SQL parsing, which is the 
weakest of the options.

You are right about the cache. Today the username is part of the rendered SQL, 
and the Jinja username helper adds itself to the cache key, so cached chart 
data is per user. Once the datasets stop using it, they would share a cache 
entry. Please turn on Superset's per-user query caching and add a test for it.

Performance. The marts are loan-by-day tables, so the policy must evaluate the 
user's scope once per query (a sub-select so it becomes an init plan), not once 
per row, and the existing user-scope function approach should be benchmarked on 
a large mart.

Suggested plan in small steps: (1) a short design note with the threat model; 
(2) the SQL Lab configuration change, if it works; (3) deny-by-default RLS for 
the reader role plus the catalog test; (4) the identity mechanism, if still 
needed. Each step can be its own issue and PR, and test_rls_isolation.py can be 
extended at each step, including raw SQL as analytics_reader.

Please open an issue with the design note before coding so the maintainers can 
weigh in on question 1.

Best,
Aira

On 2026-11-14 07:56 UTC Abhishek Chaudhary wrote:
> Hi all,
>
> While going through the BI repo's PII handling, I noticed the docs still
> described client_hash as unsalted MD5, though platform.sql now uses keyed
> HMAC-SHA256. I've opened a small docs fix for that:
> https://github.com/apache/fineract-business-intelligence/pull/131
>
> That led me to the dashboard row scoping, which I'd like to work on next:
> enforcing it inside Postgres, as defence in depth on top of the Superset
> datasets.
>
> Today the scoping lives in the 6 superset/datasets/*.sql files, so it only
> applies to queries that go through those datasets. analytics_reader itself
> can read the marts unfiltered, which SECURITY.md §9 already notes for SQL
> Lab.
>
> Rough idea:
> - Postgres RLS policies (ENABLE + FORCE) on the analytics marts, reusing
> meta.user_scope / meta.is_admin_user, applied from a dbt macro so rebuilds
> and full refreshes keep them
> - Carry the Superset user into the session in a way a SQL Lab user can't
> overwrite. A plain session variable won't work, since set_config isn't
> blocked in SQL Lab. Options I see: per-user Postgres roles with Superset
> impersonation, or a signed user token checked by a SECURITY DEFINER function
> - Turn on CACHE_QUERY_BY_USER (or keep the username in the cache key), so
> cached chart data isn't shared across users once the datasets stop calling
> current_username()
> - Run the existing test_rls_isolation.py suite against the policies, plus
> tests that raw SQL as analytics_reader is filtered too
>
> Questions before I start:
> 1. Would you accept this, given SQL Lab restriction is currently listed in
> SECURITY.md §9 as not provided?
> 2. Any preference between impersonation and a signed token, or would you
> rather rely on Superset's own RLS filters (RLS_IN_SQLLAB is still marked
> testing)?
>
> Thanks,
> Abhishek Chaudhary
>

Reply via email to