Support for Benchmarking / Global Aggregates while enforcing Row-Level Security
- Dominant language
- Rust
- Stars
- 20.8k
- Forks
- 2.1k
- Avg merge
- 1d 10h
- Merged PRs (30d)
- 203
Description
I am relatively new to Cube, so I might have missed an existing feature, although I've spent significant time researching the documentation and experimenting.
## Use Case:
My use case is straightforward: I have cubes representing facts associated with some entities. For a given tenant/user, I need to allow them to compare their own performance against the global average (or sum, or whatever) (all users or tenants) without compromising the row-level security policy.
Basically, User A should be able to query:
- Their own granular data (filtered by user_id).
- Aggregated data for all users (global benchmark), but never the granular data of User B.
## Current Challenges:
While query_rewrite in cube.py is flexible, I haven't found a clean way to achieve this without falling into anti-patterns. I am ok with making two distinct API call for this end, so I do not ask for a solution all in one, but even then, my previous attempts felt hacky:
### Duplicating Cubes:
Maintaining two versions of the same cube (one with a row policy, one "public" but without sensitive dimensions to force aggregation). I even wrote a script to generate these "public" cubes, but it feels like a maintenance nightmare and is prone to errors.
### Runtime Inspection & securityContext:
I tried inspecting the requested cubes in query_rewrite and using a boolean flag like is_benchmark_query sent from the client. However, passing this metadata is not intuitive—I ended up sending a dummy measure and removing it in the rewrite. More importantly, this feels unsafe as it relies on client-side input to bypass the data policy.
## Question:
Is there a "Cube-native" way to implement this kind of benchmarking? How can I allow access to global aggregates while strictly forbidding access to other tenants' individual rows within the same model?
Contributor guide
Research direction
Start by reviewing the query_rewrite entry point in cube.py and the securityContext handling described in the issue, along with the relevant row-level security documentation. Compare the documented behavior with the two-query and benchmark scenarios. Done means identifying a supported Cube-native approach that permits global aggregates while preventing access to other tenants' granular rows.
Written by the indexing model from the issue text.
Assessment
- Domain
- authorization, databases, security
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100