Power BI Desktop 行级别安全性 (RLS)Row-level security (RLS) with Power BI Desktop

Power BI Desktop 行级别安全性 (RLS) 可用于限制给定用户的数据访问。Row-level security (RLS) with Power BI Desktop can be used to restrict data access for given users. 筛选器可限制行级别上的数据。Filters restrict data at the row level. 你可以定义角色中的筛选器。You can define filters within roles.

现在,你可以使用 Power BI Desktop 为导入到 Power BI 的数据模型配置 RLS。You can now configure RLS for data models imported into Power BI with Power BI Desktop. 你还可以在使用 DirectQuery(如 SQL Server)的数据集上配置 RLS。You can also configure RLS on datasets that are using DirectQuery, such as SQL Server. 在此之前,你只能在 Power BI 外的本地 Analysis Services 模型中实现 RLS。Previously, you were only able to implement RLS within on-premises Analysis Services models outside of Power BI. 对于 Analysis Services 的实时连接,你可以在本地模型上配置行级别安全性。For Analysis Services live connections, you configure Row-level security on the on-premises model. 实时连接数据集不会显示安全选项。The security option will not show up for live connection datasets.

重要

如果在 Power BI 服务中定义了角色/规则,则需要在 Power BI Desktop 中重新创建这些角色,然后将报表发布到服务。If you defined roles/rules within the Power BI service, you will need to recreate those roles within Power BI Desktop and publish the report to the service.

了解有关 Power BI 服务中的 RLS 选项的详细信息。Learn more about options for RLS within the Power BI Service.

在 Power BI Desktop 中定义角色和规则Define roles and rules within Power BI Desktop

你可以在 Power BI Desktop 中定义角色和规则。You can define roles and rules within Power BI Desktop. 当你发布到 Power BI 时,它还将发布角色定义。When you publish to Power BI, it will also publish the role definitions.

若要定义安全角色,你可以执行以下操作。To define security roles, you can do the following.

  1. 将数据导入 Power BI Desktop 报表,或配置 DirectQuery 连接。Import data into your Power BI Desktop report, or configure a DirectQuery connection.

    备注

    不能在 Power BI Desktop 中为 Analysis Services 实时连接定义角色。You cannot define roles within Power BI Desktop for Analysis Services live connections. 你需要在 Analysis Services 模型中执行此操作。You will need to do that within the Analysis Services model.

  2. 选择“建模”选项卡。Select the Modeling tab.
  3. 选择“管理角色”。Select Manage Roles.

  4. 选择“创建”。Select Create.

  5. 为角色提供名称。Provide a name for the role.
  6. 选择你想要应用 DAX 规则的表。Select the table that you want to apply a DAX rule.
  7. 输入 DAX 表达式。Enter the DAX expressions. 此表达式应返回 true 或 false。This expression should return a true or false. 例如:[实体 ID] =“值”。For example: [Entity ID] = “Value”.

    备注

    可以在此表达式内使用 username()You can use username() within this expression. 请注意,username() 在 Power BI Desktop 中将采用域\用户名的格式。Be aware that username() will have the format of DOMAIN\username within Power BI Desktop. 在 Power BI 服务中,它的格式则为用户的 UPN。Within the Power BI service, it will be in the format of the user's UPN. 或者,可以使用 userprincipalname(),它将始终返回采用其用户主体名称格式的用户。Alternatively, you can use userprincipalname() which will always return the user in the format of their user principal name.

  8. 创建 DAX 表达式后,你可以选择表达式框上方的“检查”以验证该表达式。After you have created the DAX expression, you can select the check above the expression box to validate the expression.

  9. 选择“保存”。Select Save.

你无法在 Power BI Desktop 中将用户分配到角色。You cannot assign users to a role within Power BI Desktop. 此操作在 Power BI 服务中执行。This is done within the Power BI service. 通过使用 username() 或 userprincipalname() DAX 函数并配置好正确的关系,则可以启用 Power BI Desktop 中的动态安全。You can enable dynamic security within Power BI Desktop by making use of the username() or userprincipalname() DAX functions and having the proper relationships configured.

验证 Power BI Desktop 中的角色Validating the role within Power BI Desktop

创建角色后,你可以测试 Power BI Desktop 中的角色结果。After you have created your role, you can test the results of the role within Power BI Desktop. 若要执行此操作,请选择“以角色身份查看”。To do this, select View As Roles.

“以角色身份查看”对话框允许更改正在查看的特定用户或角色的视图。The View as roles dialog allows you to change the view of what you are seeing for that specific user or role. 你将看到创建的角色。You will see the roles you have created.

选择创建的角色,然后选择“确定”,将角色应用于正在查看的视图。You select the role you created and then select OK to apply that role to what you are viewing. 报表将仅呈现与该角色相关的数据。The reports will only render the data relevant for that role.

你还可以选择其他用户,并提供给定用户。You can also select Other user and supply a given user. 最好提供用户主体名称 (UPN),因为 Power BI 服务将使用该名称。It is best to supply the User Principal Name (UPN) as that is what the Power BI service will use. 选择“确定”,报表将呈现基于该用户能看到的内容。Select OK and the reports will render based on what that user can see.

备注

在 Power BI Desktop 中,如果使用的是基于 DAX 表达式的动态安全,报表将仅显示不同的结果。Within Power BI Desktop, this will only display different results if you are using dynamic security based on your DAX expressions.

限制Limitations

这是云模型上有关行级安全性的当前限制列表。Here is a list of the current limitations for row-level security on cloud models.

  • 如果你以前有在 Power BI 服务中定义了角色/规则,则将需要在 Power BI Desktop 中重新创建它们。If you previously had roles/rules defined within the Power BI service, you will need to recreate them within Power BI Desktop.
  • 只能通过使用 Power BI Desktop 客户端在创建的数据集上定义 RLS。You can define RLS only on the datasets created using Power BI Desktop client. 若想为使用 Excel 创建的数据集启用 RLS,首先需要将你的文件转换为 PBIX 文件。If you want to enable RLS for datasets created with Excel, you will need to convert your files into PBIX files first. 了解详细信息Learn more
  • 仅支持 ETL 和 DirectQuery 连接。Only ETL, and DirectQuery connections are supported. 在本地模型上处理到 Analysis Services 的实时连接。Live connections to Analysis Services are handled in the on-premises model.
  • 问与答以及 Cortana 此时不受 RLS 的支持。Q&A and Cortana is not supported with RLS at this time. 如果对所有模型配置了 RLS,你将无法看到仪表板的问与答输入框。You will not see the Q&A input box for dashboards if all models have RLS configured. 这还在规划之中,但具体日程尚不可知。This is on the roadmap, but a timeline is not available.
  • 对于使用 RLS 的数据集,暂不支持外部共享。External sharing is not currently supported with datasets that use RLS.
  • 对于任何给定的模型,可以分配给安全角色的 Azure AD 主体(例如单个用户或安全组)的最大数量为 1,000。For any given model, the maximum number of Azure AD principals (i.e. individual users or security groups) that can be assigned to security roles is 1,000. 若要将大量用户分配给角色,请确保分配安全组,而不是单个用户。To assign large numbers of users to roles, be sure to assign security groups, rather than individual users.

已知问题Known issues

有一个已知的问题,那就是当尝试从 Power BI Desktop 发布以前已发布过的内容时,将收到一个错误信息。There is a known issue where you will receive an error message when trying to publish from Power BI Desktop if it was previously published. 该场景如下所示。The scenario is as follows.

  1. Anna 有一个已发布到 Power BI 服务且已配置了 RLS 的数据集。Anna has a dataset that is publised to the Power BI service and has configured RLS.
  2. Anna 在 Power BI Desktop 中更新报表并重新发布。Anna updates the report in Power BI Desktop and re-publishes.
  3. Anna 将收到一个错误。Anna will receive an error.

解决方法:重新从 Power BI 服务中发布 Power BI Desktop 文件,直到此问题得到解决。Workaround: Re-publish the Power BI Desktop file from the Power BI service until this issue is resolved. 可以通过选择“获取数据” > “文件”来执行此操作。You can do that by select Get Data > Files.

常见问题解答FAQ

问:如果我以前在 Power BI 服务中为数据集创建了角色/规则会怎么样?Question: What if I had previously created roles/rules for a dataset in the Power BI service? 如果我不执行任何操作,它们是否仍将起作用?Will they still work if I do nothing?
答:不能。Answer: No. 视觉对象将不会正确呈现。Visuals will not render properly. 你需要重新创建 Power BI Desktop 中的角色/规则,然后发布到 Power BI 服务。You will have to re-create the roles/rules within Power BI Desktop and then published to the Power BI service.

问:我是否可以为 Analysis Services 数据源创建这些角色?Question: Can I creates these roles for Analysis Services data sources?
答︰如果你将数据导入 Power BI Desktop 中,那么你就可以创建。Answer: You can if you imported the data into Power BI Desktop. 如果你正在使用实时连接,那么你将不能配置 Power BI 服务中的 RLS。If you are using a live connection, you will not be able to configure RLS within the Power BI service. 这是在 Analysis Services 模型内部部署中定义的。This is defined within the Analysis Services model on-premises.

问:我能使用 RLS 限制用户可以访问的列或度量值吗?Question: Can I use RLS to limit the columns or measures accessible by my users?
答:不能。Answer: No. 如果用户有权访问特定数据行,那么他们可以查看该行的所有数据列。If a user has access to a particular row of data, they can see all the columns of data for that row.

问:RLS 是否允许我隐藏详细的数据,但提供对在视觉对象中汇总的数据的访问权限?Question: Does RLS allow me to hide detailed data but give access to data summarized in visuals?
答:不允许,可以保护单个数据行,但用户始终可以查看详细信息或汇总的数据。Answer: No, you secure individual rows of data but users can always see either the details or summarized data.

后续步骤Next steps

Power BI 服务行级别安全性 (RLS)Row-level security (RLS) with the Power BI service

更多问题?More questions? 尝试咨询 Power BI 社区Try asking the Power BI Community