细粒度权限 个性化数据访问 细粒度权限管控允许为不同用户或角色定制数据访问视图。例如,在一个销售系统中,销售人员可能只需要访问客户的基本信息,而经理则可以查看更详细的销售记录和分析数据。这种个性化的权限配置提高了工作效率。 多租户环境 在多租户环境中,细粒度权限管控能够有效隔离不同租户的数据,确保每个租户只能访问自己的数据。即使多个租户共享同一个搜索引擎集群,他们的数据依然能够得到严格的保护。 最小权限原则 细粒度权限控制支持最小权限原则(Principle of Least Privilege),确保用户仅能访问其工作所需的最小数据范围,从而减少潜在的安全风险。 技术实现与应用 管理员可以通过 OpenSearch 的安全模块,使用文档级别安全(DocumentLevel Security, DLS)和字段级别安全(FieldLevel Security, FLS)配置细粒度权限。DLS 允许基于查询条件限制用户对特定文档的访问,而 FLS 则允许管理员指定哪些字段对特定用户可见或不可见。 这些权限配置可以通过 OpenSearch 的 REST API 或管理工具来实现和管理。管理员还可以结合角色和用户组的概念,为不同用户群体配置统一的权限策略,从而简化权限管理流程。 操作示例 我们创建一个role publicrole,创建一个user publicuser1,目标是让这个user只能查看pub开头的索引里public字段为true的文档。 创建角色: PUT plugins/security/api/roles/publicrole { "clusterpermissions": [ "" ], "indexpermissions": [{ "indexpatterns": [ "pub" ], "dls": "{"term": { "public": "true"}}", "allowedactions": [ "read" ] }] } 创建用户: PUT plugins/security/api/internalusers/publicuser1 { "password": "" } 创建Mapping: PUT plugins/security/api/rolesmapping/publicrole { "users" : [ "publicuser1" ] } 创建索引: pub索引,插入两条数据 POST pubindex/doc/ { "name": "robert", "age": "30", "public": "true" } POST pubindex/doc/ { "name": "mike", "age": "55", "public": "false" } 非pub索引 POST secindex/doc/ { "name": "jane", "age": "18", "public": "true" } 我们开始搜索,预期是publicuser1搜索pubindex可以返回一条结果,搜索secindex无结果。而admin用户搜索pubindex可以返回两条结果,搜索secindex可以返回一条结果。 GET pubindex/search {"size": 10,"query": {"matchall": {}}} { "took" : 4, "timedout" : false, "shards" : { "total" : 1, "successful" : 1, "skipped" : 0, "failed" : 0 }, "hits" : { "total" : { "value" : 1, "relation" : "eq" }, "maxscore" : 2.0, "hits" : [ { "index" : "pubindex", "id" : "xBnh0okBxCORqeQrGobf", "score" : 2.0, "source" : { "name" : "robert", "age" : "30", "public" : "true" } } ] } } GET pubindex/search {"size": 10,"query": {"matchall": {}}} { "took" : 1, "timedout" : false, "shards" : { "total" : 1, "successful" : 1, "skipped" : 0, "failed" : 0 }, "hits" : { "total" : { "value" : 2, "relation" : "eq" }, "maxscore" : 1.0, "hits" : [ { "index" : "pubindex", "id" : "xBnh0okBxCORqeQrGobf", "score" : 1.0, "source" : { "name" : "robert", "age" : "30", "public" : "true" } }, { "index" : "pubindex", "id" : "xRnh0okBxCORqeQrMobq", "score" : 1.0, "source" : { "name" : "mike", "age" : "55", "public" : "false" } } ] } } GET secindex/search {"size": 10,"query": {"matchall": {}}} { "error" : { "rootcause" : [ { "type" : "securityexception", "reason" : "no permissions for [indices:data/read/search] and User [namepublicuser1, backendroles[], requestedTenantnull]" } ], "type" : "securityexception", "reason" : "no permissions for [indices:data/read/search] and User [namepublicuser1, backendroles[], requestedTenantnull]" }, "status" : 403 } GET secindex/search {"size": 10,"query": {"matchall": {}}} { "took" : 1, "timedout" : false, "shards" : { "total" : 1, "successful" : 1, "skipped" : 0, "failed" : 0 }, "hits" : { "total" : { "value" : 1, "relation" : "eq" }, "maxscore" : 1.0, "hits" : [ { "index" : "secindex", "id" : "xhnh0okBxCORqeQrTYbM", "score" : 1.0, "source" : { "name" : "jane", "age" : "18", "public" : "true" } } ] } } 搜索引擎的细粒度权限管控功能通过支持文档级别和字段级别的权限控制,为企业提供了强大的数据安全和管理能力。 这种精确的权限配置不仅帮助企业保护敏感信息,还能够在多租户环境和个性化数据访问需求下提供高效的解决方案。通过细粒度的权限管控,企业可以确保数据的安全性、隐私性和合规性,同时实现灵活的业务支持。