使用CBAC与RBAC的主要好处是什么?什么时候使用CBAC更好,什么时候使用RBAC更好?

我试图理解CBAC模型的一般概念,但总体思想对我来说仍然不清楚。


当前回答

公认的答案似乎将角色定位为钝器,而声明定位为灵活的工具,但在其他方面使它们看起来几乎相同。不幸的是,这种定位有损于索赔的概念,并可能从根本上反映出对其目的的轻微误解。

Roles exist and make sense only within an implicit scope. Generally that is an application or organizational scope (i.e. Role=Administrator). Claims, on the other hand, can be 'made' by anyone. For example, Google authentication may produce claims including a user's "email", thus attaching that email to an identity. Google makes the claim, the application chooses whether to understand and accept that claim. The application itself might subsequently attach a claim called "authenticationmethod" (as ASP.NET MVC Core Identity does) with a value of "Google". Each claim includes a scope so that it's possible to identify whether a claim has meaning externally, locally, or both (or more fine grained as needed.)

关键点在于,所有声明都显式地附加到一个标识,并包括一个显式的范围。这些声明当然可以用于授权-和ASP。NET MVC通过Authorize属性提供了对此的支持,但这不是claim的唯一目的,甚至不一定是主要目的。它当然不会与role区分开来,后者可以以完全相同的方式用于本地范围的授权。

So one can choose to use Roles, or Claims, or both for the purpose of authorization and likely find no inherent advantage or disadvantage to either, so long as those Roles and Claims are locally scoped. But if, for instance, authorization depends upon external identity claims, then Roles will be inadequate. You would have to accept the external claim and translate it into a locally scoped role. There isn't necessarily anything wrong with that, but it introduces a layer of indirection and discards context.

其他回答

公认的答案似乎将角色定位为钝器,而声明定位为灵活的工具,但在其他方面使它们看起来几乎相同。不幸的是,这种定位有损于索赔的概念,并可能从根本上反映出对其目的的轻微误解。

Roles exist and make sense only within an implicit scope. Generally that is an application or organizational scope (i.e. Role=Administrator). Claims, on the other hand, can be 'made' by anyone. For example, Google authentication may produce claims including a user's "email", thus attaching that email to an identity. Google makes the claim, the application chooses whether to understand and accept that claim. The application itself might subsequently attach a claim called "authenticationmethod" (as ASP.NET MVC Core Identity does) with a value of "Google". Each claim includes a scope so that it's possible to identify whether a claim has meaning externally, locally, or both (or more fine grained as needed.)

关键点在于,所有声明都显式地附加到一个标识,并包括一个显式的范围。这些声明当然可以用于授权-和ASP。NET MVC通过Authorize属性提供了对此的支持,但这不是claim的唯一目的,甚至不一定是主要目的。它当然不会与role区分开来,后者可以以完全相同的方式用于本地范围的授权。

So one can choose to use Roles, or Claims, or both for the purpose of authorization and likely find no inherent advantage or disadvantage to either, so long as those Roles and Claims are locally scoped. But if, for instance, authorization depends upon external identity claims, then Roles will be inadequate. You would have to accept the external claim and translate it into a locally scoped role. There isn't necessarily anything wrong with that, but it introduces a layer of indirection and discards context.

还可以以声明的方式管理角色。

与其创建反映业务角色的授权角色,不如创建反映操作角色的角色,例如CreateCustomer、EditCustomer、DeleteCustomer。根据需要注释方法。

将个人映射到一组动作角色并不是一件简单的事情,特别是当角色列表变得越来越大时。因此,您需要在较低的粒度级别上管理业务角色(例如销售、市场营销),并将业务角色映射到所需的操作角色。例如,将用户添加到业务角色,并将其映射到现有授权表中所需的(操作)角色。

您甚至可以覆盖业务角色,并直接将人员添加到操作角色。

因为构建在已经工作的基础上,所以不会撤销现有的授权流程。您只需要几个表就可以实现这种方法

角色只是Claim的一种类型。与此类似,还可以有许多其他声明类型,例如用户名就是声明类型之一

我认为这个问题可以从数据库的角度来回答。 如果您注意到表是如何参与这个植入的,您将发现以下内容

AspNetUsers : each user has one row with all the attributes required by all users like email, address phone, password..... AspNetRoles ; defines different roles as per application requirements like GM , CTO, HRM,ADMIN, EMP. what each roles defines is as per application needs. AspNetUserRoles: each row links AspNetUsers and AspNetRoles and effectively links between one user and many roles. AspNetUserClaims: each row has key to AspNetUsers and one type and value. so effectively add one attribute for each user that could be added/removed at run time.

这个表的使用可以在用户/应用程序生命周期的某个时刻进行调整,以匹配特定的需求。

考虑到“采购经理”(PM)的早期阶段,我们可以有三种方法

Application populates AspNetUserRoles with one row to grants 'PM' right to buy. To issue purchasing order with any amount, user only need "PM" role. Application populates AspNetUserRoles with one row to grants 'PM' right to buy, and populates the AspNetUserClaims a claim of TYPE 'Purchasing Amount' type and "<1000" value to set the amount limit. To issue purchasing order, user need to has 'PM'and the order amount be less than claim value of claim TYPE 'Purchasing Amount'. Application populate AspNetUserClaims with claim of TYPE 'Purchasing Amount' type and "<1000" value. Any user can issue purchasing order, given the the amount to be less than claim value of claim TYPE 'Purchasing Amount' for this user.

可以注意到,基于角色的是粗粒度的刚性权限,从系统管理的角度来看,这将简化应用程序用户的生活。然而,从业务需求的角度来看,这将限制用户的能力。 另一方面,基于索赔的是非常精细的权利,需要分配给每个用户。以索赔为基础会把业务推到极限,但会使系统管理非常复杂。

另一个可以考虑的选项是ABAC。

基于属性的访问控制采用了一种不同的方法,它根据每个用户的属性、他们请求的资源以及他们发出请求的环境向用户授予访问权。

ABAC的主要好处是可以对每个用户的权限进行细粒度控制。例如,使用ABAC,您可以为人力资源应用程序的用户授予仅为他们负责的区域导出人员报告的权限。因为模型被设计成可以扩展到任意数量的属性和权限,所以在ABAC中构建更动态的权限通常更容易。

这里的好文章总结了差异https://cerbos.dev/blog/the-hidden-costs-of-user-authorization