简体   繁体   中英

How to access current security context within a driver in cube.js

I'm working on a custom cube.js database driver that uses a private http service which accepts arbitrary, raw sql and returns the result as json.

The http service uses Authorization header to identify the user (so that it can enforce appropriate access controls).

I was looking for ways in which I can pass cube.js security context to the driver.


I tried steps mentioned in their multi-tenancy document, specifically the Multiple Schema and Drivers one.

It only works the first time where I'm able to access the security context in the driverFactory() callback. There I initialise the new driver instance with the user's token in securityContext .

For subsequent calls though (event with different user!), cube.js reuses the same instance. And this is the cause of the problem. I cannot reuse driver between different application users.

Is there a way to solve this? Or am I not implementing multi-tenancy correctly here?

We can use contextToOrchestratorId function (introduced in v0.29 ), in conjunction with contextToAppId , to achieve this.

According to the documentation,

contextToOrchestratorId is a function used to determine a caching key for the Query Orchestrator instance. The Query Orchestrator holds database connections, execution queues, pre-aggregation table caches. By default, the same instance is used for all tenants; override this property in situations where each tenant requires their own Query Orchestrator.


Thanks to Ivan Vdovin on Cube.js' community slack for providing directions +1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM