简体   繁体   English

如何在 cube.js 中访问驱动程序中的当前安全上下文

[英]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.我正在开发一个自定义的cube.js数据库驱动程序,它使用一个私有的 http 服务,它接受任意的原始 sql 并将结果作为 json 返回。

The http service uses Authorization header to identify the user (so that it can enforce appropriate access controls). http 服务使用Authorization标头来识别用户(以便它可以强制执行适当的访问控制)。

I was looking for ways in which I can pass cube.js security context to the driver.我一直在寻找可以将cube.js安全上下文传递给驱动程序的方法。


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.它仅在我第一次能够访问driverFactory()回调中的安全上下文时才有效。 There I initialise the new driver instance with the user's token in securityContext .在那里,我使用securityContext中的用户令牌初始化新的驱动程序实例。

For subsequent calls though (event with different user!), cube.js reuses the same instance.但是对于后续调用(具有不同用户的事件!), cube.js重用相同的实例。 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.我们可以使用contextToOrchestratorId函数(在v0.29中引入)结合contextToAppId来实现。

According to the documentation,根据文件,

contextToOrchestratorId is a function used to determine a caching key for the Query Orchestrator instance. contextToOrchestratorId是一个用于确定 Query Orchestrator 实例的缓存键的函数。 The Query Orchestrator holds database connections, execution queues, pre-aggregation table caches. Query Orchestrator 保存数据库连接、执行队列、预聚合表缓存。 By default, the same instance is used for all tenants;默认情况下,所有租户使用同一个实例; override this property in situations where each tenant requires their own Query Orchestrator.在每个租户都需要自己的 Query Orchestrator 的情况下覆盖此属性。


Thanks to Ivan Vdovin on Cube.js' community slack for providing directions +1感谢Cube.js 社区 slack上的 Ivan Vdovin 提供方向 +1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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