collections - DocumentDB 对集合的权限

标签 collections user-permissions azure-cosmosdb

在我的设计中,我想使用 DocumentDB 作为 Multi-Tenancy SAAS 应用程序的后端。 由于每个租户的数据可能 > 10GB,我想使用每个租户模型的集合。 需求是如何确保应用程序中的数据隔离。租户 1 不应该能够在代码中和 Azure 门户上查看租户 2 的数据。如何设置相同集合的权限?

最佳答案

I want to use a collection per tenant model

您可以尝试create DocumentDB users for each tenant and associate the permissions with the user控制用户对集合/文档的访问。

string documentCollectionlink = UriFactory.CreateDocumentCollectionUri("{database id}", "{collection id}").ToString();

string databaseLink = UriFactory.CreateDatabaseUri("{database id}").ToString();

Permission docPermission = new Permission
{
    PermissionMode = PermissionMode.All,
    ResourceLink = documentCollectionlink,
    Id = "tenant1perm"
};

await client.CreateUserAsync(databaseLink, new User { Id = "tuser" });

docPermission = await client.CreatePermissionAsync(UriFactory.CreateUserUri("{database id}", "tuser"), docPermission);

然后您可以读取DocumentDB用户的权限并根据租户获取访问 token ,并使用 token 创建一个新的DocumentClient实例来操作资源。

var qclient = new DocumentClient(new Uri(EndpointUri), token);

关于collections - DocumentDB 对集合的权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43597690/

相关文章:

java - 起初我在 TreeSet 中插入 null。之后我插入任何其他值为什么它会给出 NPE?

sql - 我应该如何在数据库中记录 'all' 组可见的项目/产品?

java - 如何按属性查找集合中的元素?

java - 字符串值时区排序

laravel - 具有 Laravel 权限的 Vue.js

c++ - 使用读取系统调用 C++ 输出文本

azure - 比较 Azure SQL 和 Cosmos DB 之间的读取性能的好方法是什么?

c# - 从 azure 函数运行 azure 存储过程

c# - 如何正确限制从 WebJobs 对 DocumentDb 的访问

java - Java中如何通过各种参数对这个ArrayList进行排序?