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

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


当前回答

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

与其创建反映业务角色的授权角色,不如创建反映操作角色的角色,例如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.

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

如果你想要一个真实的例子;

你有一个学校系统,老师可以登录并看到他们的学生。这些老师属于“老师”角色。但我们不希望所有的老师看到所有的学生,所以我们需要区分同一水平的人与他们的主张。

玛丽-数学老师(声称:数学)->只能看到数学学生 约翰-物理老师(声称:物理)->只能看到物理学生 亚当-物理和化学老师(声称:物理,化学)->可以看到物理和化学的学生。

虽然这三位老师都在教师角色下,但他们只能看到学生的相应要求。

有一个叫迈克的校长

Mike -校长(角色:管理员,索赔:n/a) ->可以看到和管理所有学生,因为他是管理员角色,无论他没有任何索赔。

如果我们需要区分管理员级别的人员,我们可以将相关的声明分配给每个人。

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

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

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

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

在决定哪种方法是最好的之前,首先分析身份验证需要什么是很重要的。来自基于声明的授权:

A claim is not what the subject can do. For example, you may have a driver's license, issued by a local driving license authority. Your driver's license has your date of birth on it. In this case the claim name would be DateOfBirth, the claim value would be your date of birth, for example 8th June 1970 and the issuer would be the driving license authority. Claims based authorization, at its simplest, checks the value of a claim and allows access to a resource based upon that value. For example if you want access to a night club the authorization process might be: The door security officer would evaluate the value of your date of birth claim and whether they trust the issuer (the driving license authority) before granting you access.

从这个例子我们可以看到,使用声明式授权访问几乎俱乐部退出不同的授权类型需要的员工在夜总会工作,在这种情况下,员工俱乐部需要一个基于角色的授权而不是必需的夜总会游客的夜总会的游客都有一个共同的目的在夜总会因此在这种情况下的声明式授权适用于夜总会游客。

来自基于角色的授权:

当创建一个标识时,它可能属于一个或多个角色。例如,Tracy可能属于管理员和用户角色,而Scott可能只属于用户角色。如何创建和管理这些角色取决于授权过程的备份存储区。角色通过ClaimsPrincipal类上的IsInRole方法向开发人员公开。