我正在研究各种类型的访问控制模型,并且发现abacrbac是流行的模型。

我为我的一个项目提供了一个基本方案,但我不知道应该选择RBAC还是ABAC。显然RBACABAC的子集,因此,我绝对应该去ABAC,但是ABAC需要一些经验来在xacml中编写策略。我们正在使用WSO IS和APIM。

我在身份服务器(IS)中具有管理员,所有者和成员角色。

  • 管理员可以查看,删除和更新用户。
  • 所有者可以查看和更新​​。
  • 成员(member)只能查看。

  • 我现在正在使用HTTP动词来实现期望的结果,即所有者无法访问DELETE请求,而成员无法访问PUTDELETE

    问题

    我有一个仪表板,其中显示了不同的部分,例如顶级用户,账单,服务,顶级消费者等。
  • 我需要根据用户角色和服务器中的属性来填充nav-bar,例如成员无权查看nav-bar中的其他用户(添加,列表)。 nav-bar项取决于用户角色,因此我们可以通过RBAC对其进行管理?
  • 我们已经计划添加操作,市场营销,支持等角色。这是否意味着我们需要创建单独的数据库模式来维护每个角色的访问权限?
  • 在仪表板中,我需要隐藏/显示 View ,更新和删除用户,服务等中的按钮。现在成员可以看到用户,但无权更新或删除它们。不能查看统计信息,账单和其他私有(private)信息。
  • 所有者可以查看与其部门/组织相关的所有用户,但管理员可以查看所有部门/组织的所有用户。在这里,我们需要为所有使用者使用相同的api,但是api对于不同的角色应该有不同的响应。角色可以是10或100,因此ee不能为每个角色创建不同的api。

  • 问题

    我们可以通过RBAC来实现所有这些场景,但是为了管理nav-bar并查看相关的实现,我们需要在服务器中添加业务逻辑,而不是使用WSO2-ISWSO2-APIM。有什么方法可以管理 View 权限,例如隐藏/显示按钮和部分,甚至使用相同的API,但对于不同的api消费者,它应该返回不同的结果。

    最佳答案

    首先,我对最近的回应表示歉意。这是我的内联评论。

    ACL,RBAC,ABAC



    历史上,访问控制是通过访问控制列表(ACL),然后是基于角色的访问控制(RBAC)和最近基于属性的访问控制(ABAC)解决的。 ACL变得笨拙且难以管理,这就是NIST在1992年提出RBAC的原因(是那么古老)。 RBAC是众所周知的,成熟的,并已内置在大多数IAM产品和应用程序中。例如,用户目录(LDAP,AD ...)维护用户和角色分配,并为应用程序提供那些角色,然后应用程序可以使用这些角色来确定是否应授予访问权限。使用RBAC,更细粒度的访问是不可能的(例如,根据您的情况进行的基于关系的访问,即用户只能看到自己的数据),因此(a)应用程序开发人员编写了自定义代码来实现正确的访问,或者(b)您使用ABAC。

    为什么选择ABAC?

    ABAC使您能够通过使用策略来描述可能(或不可以)发生的事情,基于任何种类的属性(不仅是角色而且不仅是用户属性)来定义细粒度的访问。 ABAC有时也称为PBAC(基于策略的访问控制)。您指的是XACML,这是实现ABAC策略的语言。您还可以研究alfa(Wikipedia),这是一种直接映射到XACML的简单语言。

    ABAC还以策略决策点(PDP)的概念定义了一种体系结构,该策略根据配置的策略处理您的授权请求。 PDP(在您的情况下是WSO2 IS的WSO2 Balana部分)是从策略执行点(PEP)调用的,例如您的应用程序或位于应用程序前面的东西(例如,您的情况下为WSO2 API管理器的API网关或拦截器)。

    authorization - 通过XACML策略进行RBAC/ABAC-LMLPHP

    您的用例



    我不会说RBAC是ABAC的子集。确实是从功能的角度来看。但这不是一个与另一个。 ABAC将通过引入更多属性,策略和上述架构来扩展RBAC。



    这很棒。您正在做的是定义您的授权要求。这些将直接映射到您的ALFA/XACML策略。



    在ABAC中,我们还使用 Action 。这些可能是普通的旧人类 Action (查看,编辑,删除,批准...),然后可以将其映射到HTTP动词。

    你的挑战

    在下面的文字中,我以粗体标记了我认为是您的其他授权要求的内容。



    这将通过ABAC政策进行处理。见下文



    不!您不必创建新的数据库模式,更不用说维护定制系统中的访问权限了。使用策略来做到这一点。



    当然是。这是使用ABAC和策略的目的。鉴于您正在使用WSO2 IS,请查看Balana(该产品内部的PDP)。还有其他解决方案,例如AuthZForce(开源)或Axiomatics(我在这里工作)

    解决方案

    这是用ALFA和下面的XACML转换编写的示例策略

    namespace haris {
        /**
         * User Records
         */
        policyset users {
            target clause axiomatics.objectType == "user record"
            apply firstApplicable
            /**
             * View user record
             */
            policy viewUser {
                target clause axiomatics.actionId == "view" // This can be the HTTP verb
                apply firstApplicable
    
                /**
                 * Administrators can view all users
                 */
                rule administrator{
                     target clause axiomatics.user.role == "administrator"
                    permit
                }
                /**
                 * Owners can view users in their department
                 */
                rule owners{
                     target clause axiomatics.user.role == "owner"
                     permit
                     condition axiomatics.user.department == axiomatics.record.department
                 }
                /**
                 * Members can view their own user record only
                 */
                rule member{
                      permit
                      condition axiomatics.user.username == axiomatics.record.owner
                }
            }
            /**
             * Update user
             */
            policy updateUser {
                target clause axiomatics.actionId == "update" // This can be the HTTP verb
                apply firstApplicable
    
                /**
                 * Administrator can update any user
                 */
                rule administrator{
                    target clause axiomatics.user.role == "administrator"
                    permit
                }
                /**
                 * Owner can update any user
                 */
                rule owner{
                    target clause axiomatics.user.role == "owner"
                    permit
                    // TODO: determine what an owner can update
                }
            }
            /**
             * Delete user
             */
            policy deleteUser {
                target clause axiomatics.actionId == "delete" // This can be the HTTP verb
                apply firstApplicable
                /**
                 * Administrator can delete any user
                 */
                rule administrator{
                    target clause axiomatics.user.role == "administrator"
                    permit
                }
            }
        }
    }
    

    和XML版本

    <?xml version="1.0" encoding="UTF-8"?><!--This file was generated by the
        ALFA Plugin for Eclipse from Axiomatics AB (http://www.axiomatics.com). --><!--Any modification to this file will
        be lost upon recompilation of the source ALFA file -->
    <xacml3:PolicySet
        PolicyCombiningAlgId="urn:oasis:names:tc:xacml:1.0:policy-combining-algorithm:first-applicable"
        PolicySetId="http://axiomatics.com/alfa/identifier/haris.users"
        Version="1.0"
        xmlns:xacml3="urn:oasis:names:tc:xacml:3.0:core:schema:wd-17">
        <xacml3:Description>User Records</xacml3:Description>
        <xacml3:PolicySetDefaults>
            <xacml3:XPathVersion>http://www.w3.org/TR/1999/REC-xpath-19991116
            </xacml3:XPathVersion>
        </xacml3:PolicySetDefaults>
        <xacml3:Target>
            <xacml3:AnyOf>
                <xacml3:AllOf>
                    <xacml3:Match
                        MatchId="urn:oasis:names:tc:xacml:1.0:function:string-equal">
                        <xacml3:AttributeValue
                            DataType="http://www.w3.org/2001/XMLSchema#string">user record</xacml3:AttributeValue>
                        <xacml3:AttributeDesignator
                            AttributeId="axiomatics.objectType"
                            Category="urn:oasis:names:tc:xacml:3.0:attribute-category:resource"
                            DataType="http://www.w3.org/2001/XMLSchema#string"
                            MustBePresent="false" />
                    </xacml3:Match>
                </xacml3:AllOf>
            </xacml3:AnyOf>
        </xacml3:Target>
        <xacml3:Policy
            PolicyId="http://axiomatics.com/alfa/identifier/haris.users.viewUser"
            RuleCombiningAlgId="urn:oasis:names:tc:xacml:1.0:rule-combining-algorithm:first-applicable"
            Version="1.0">
            <xacml3:Description>View user record</xacml3:Description>
            <xacml3:PolicyDefaults>
                <xacml3:XPathVersion>http://www.w3.org/TR/1999/REC-xpath-19991116
                </xacml3:XPathVersion>
            </xacml3:PolicyDefaults>
            <xacml3:Target>
                <xacml3:AnyOf>
                    <xacml3:AllOf>
                        <xacml3:Match
                            MatchId="urn:oasis:names:tc:xacml:1.0:function:string-equal">
                            <xacml3:AttributeValue
                                DataType="http://www.w3.org/2001/XMLSchema#string">view</xacml3:AttributeValue>
                            <xacml3:AttributeDesignator
                                AttributeId="axiomatics.actionId"
                                Category="urn:oasis:names:tc:xacml:3.0:attribute-category:action"
                                DataType="http://www.w3.org/2001/XMLSchema#string"
                                MustBePresent="false" />
                        </xacml3:Match>
                    </xacml3:AllOf>
                </xacml3:AnyOf>
            </xacml3:Target>
            <xacml3:Rule Effect="Permit"
                RuleId="haris.users.viewUser.administrator">
                <xacml3:Description>Administrators can view all users
                </xacml3:Description>
                <xacml3:Target>
                    <xacml3:AnyOf>
                        <xacml3:AllOf>
                            <xacml3:Match
                                MatchId="urn:oasis:names:tc:xacml:1.0:function:string-equal">
                                <xacml3:AttributeValue
                                    DataType="http://www.w3.org/2001/XMLSchema#string">administrator</xacml3:AttributeValue>
                                <xacml3:AttributeDesignator
                                    AttributeId="axiomatics.user.role"
                                    Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject"
                                    DataType="http://www.w3.org/2001/XMLSchema#string"
                                    MustBePresent="false" />
                            </xacml3:Match>
                        </xacml3:AllOf>
                    </xacml3:AnyOf>
                </xacml3:Target>
            </xacml3:Rule>
            <xacml3:Rule Effect="Permit"
                RuleId="haris.users.viewUser.owners">
                <xacml3:Description>Owners can view users in their department
                </xacml3:Description>
                <xacml3:Target>
                    <xacml3:AnyOf>
                        <xacml3:AllOf>
                            <xacml3:Match
                                MatchId="urn:oasis:names:tc:xacml:1.0:function:string-equal">
                                <xacml3:AttributeValue
                                    DataType="http://www.w3.org/2001/XMLSchema#string">owner</xacml3:AttributeValue>
                                <xacml3:AttributeDesignator
                                    AttributeId="axiomatics.user.role"
                                    Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject"
                                    DataType="http://www.w3.org/2001/XMLSchema#string"
                                    MustBePresent="false" />
                            </xacml3:Match>
                        </xacml3:AllOf>
                    </xacml3:AnyOf>
                </xacml3:Target>
                <xacml3:Condition>
                    <xacml3:Apply
                        FunctionId="urn:oasis:names:tc:xacml:3.0:function:any-of-any">
                        <xacml3:Function
                            FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-equal" />
                        <xacml3:AttributeDesignator
                            AttributeId="axiomatics.user.department"
                            Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject"
                            DataType="http://www.w3.org/2001/XMLSchema#string"
                            MustBePresent="false" />
                        <xacml3:AttributeDesignator
                            AttributeId="axiomatics.record.department"
                            Category="urn:oasis:names:tc:xacml:3.0:attribute-category:resource"
                            DataType="http://www.w3.org/2001/XMLSchema#string"
                            MustBePresent="false" />
                    </xacml3:Apply>
                </xacml3:Condition>
            </xacml3:Rule>
            <xacml3:Rule Effect="Permit"
                RuleId="haris.users.viewUser.member">
                <xacml3:Description>Members can view their own user record only
                </xacml3:Description>
                <xacml3:Target />
                <xacml3:Condition>
                    <xacml3:Apply
                        FunctionId="urn:oasis:names:tc:xacml:3.0:function:any-of-any">
                        <xacml3:Function
                            FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-equal" />
                        <xacml3:AttributeDesignator
                            AttributeId="axiomatics.user.username"
                            Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject"
                            DataType="http://www.w3.org/2001/XMLSchema#string"
                            MustBePresent="false" />
                        <xacml3:AttributeDesignator
                            AttributeId="axiomatics.record.owner"
                            Category="urn:oasis:names:tc:xacml:3.0:attribute-category:resource"
                            DataType="http://www.w3.org/2001/XMLSchema#string"
                            MustBePresent="false" />
                    </xacml3:Apply>
                </xacml3:Condition>
            </xacml3:Rule>
        </xacml3:Policy>
        <xacml3:Policy
            PolicyId="http://axiomatics.com/alfa/identifier/haris.users.updateUser"
            RuleCombiningAlgId="urn:oasis:names:tc:xacml:1.0:rule-combining-algorithm:first-applicable"
            Version="1.0">
            <xacml3:Description>Update user</xacml3:Description>
            <xacml3:PolicyDefaults>
                <xacml3:XPathVersion>http://www.w3.org/TR/1999/REC-xpath-19991116
                </xacml3:XPathVersion>
            </xacml3:PolicyDefaults>
            <xacml3:Target>
                <xacml3:AnyOf>
                    <xacml3:AllOf>
                        <xacml3:Match
                            MatchId="urn:oasis:names:tc:xacml:1.0:function:string-equal">
                            <xacml3:AttributeValue
                                DataType="http://www.w3.org/2001/XMLSchema#string">update</xacml3:AttributeValue>
                            <xacml3:AttributeDesignator
                                AttributeId="axiomatics.actionId"
                                Category="urn:oasis:names:tc:xacml:3.0:attribute-category:action"
                                DataType="http://www.w3.org/2001/XMLSchema#string"
                                MustBePresent="false" />
                        </xacml3:Match>
                    </xacml3:AllOf>
                </xacml3:AnyOf>
            </xacml3:Target>
            <xacml3:Rule Effect="Permit"
                RuleId="haris.users.updateUser.administrator">
                <xacml3:Description>Administrator can update any user
                </xacml3:Description>
                <xacml3:Target>
                    <xacml3:AnyOf>
                        <xacml3:AllOf>
                            <xacml3:Match
                                MatchId="urn:oasis:names:tc:xacml:1.0:function:string-equal">
                                <xacml3:AttributeValue
                                    DataType="http://www.w3.org/2001/XMLSchema#string">administrator</xacml3:AttributeValue>
                                <xacml3:AttributeDesignator
                                    AttributeId="axiomatics.user.role"
                                    Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject"
                                    DataType="http://www.w3.org/2001/XMLSchema#string"
                                    MustBePresent="false" />
                            </xacml3:Match>
                        </xacml3:AllOf>
                    </xacml3:AnyOf>
                </xacml3:Target>
            </xacml3:Rule>
            <xacml3:Rule Effect="Permit"
                RuleId="haris.users.updateUser.owner">
                <xacml3:Description>Owner can update any user</xacml3:Description>
                <xacml3:Target>
                    <xacml3:AnyOf>
                        <xacml3:AllOf>
                            <xacml3:Match
                                MatchId="urn:oasis:names:tc:xacml:1.0:function:string-equal">
                                <xacml3:AttributeValue
                                    DataType="http://www.w3.org/2001/XMLSchema#string">owner</xacml3:AttributeValue>
                                <xacml3:AttributeDesignator
                                    AttributeId="axiomatics.user.role"
                                    Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject"
                                    DataType="http://www.w3.org/2001/XMLSchema#string"
                                    MustBePresent="false" />
                            </xacml3:Match>
                        </xacml3:AllOf>
                    </xacml3:AnyOf>
                </xacml3:Target>
            </xacml3:Rule>
        </xacml3:Policy>
        <xacml3:Policy
            PolicyId="http://axiomatics.com/alfa/identifier/haris.users.deleteUser"
            RuleCombiningAlgId="urn:oasis:names:tc:xacml:1.0:rule-combining-algorithm:first-applicable"
            Version="1.0">
            <xacml3:Description>Delete user</xacml3:Description>
            <xacml3:PolicyDefaults>
                <xacml3:XPathVersion>http://www.w3.org/TR/1999/REC-xpath-19991116
                </xacml3:XPathVersion>
            </xacml3:PolicyDefaults>
            <xacml3:Target>
                <xacml3:AnyOf>
                    <xacml3:AllOf>
                        <xacml3:Match
                            MatchId="urn:oasis:names:tc:xacml:1.0:function:string-equal">
                            <xacml3:AttributeValue
                                DataType="http://www.w3.org/2001/XMLSchema#string">delete</xacml3:AttributeValue>
                            <xacml3:AttributeDesignator
                                AttributeId="axiomatics.actionId"
                                Category="urn:oasis:names:tc:xacml:3.0:attribute-category:action"
                                DataType="http://www.w3.org/2001/XMLSchema#string"
                                MustBePresent="false" />
                        </xacml3:Match>
                    </xacml3:AllOf>
                </xacml3:AnyOf>
            </xacml3:Target>
            <xacml3:Rule Effect="Permit"
                RuleId="haris.users.deleteUser.administrator">
                <xacml3:Description>Administrator can delete any user
                </xacml3:Description>
                <xacml3:Target>
                    <xacml3:AnyOf>
                        <xacml3:AllOf>
                            <xacml3:Match
                                MatchId="urn:oasis:names:tc:xacml:1.0:function:string-equal">
                                <xacml3:AttributeValue
                                    DataType="http://www.w3.org/2001/XMLSchema#string">administrator</xacml3:AttributeValue>
                                <xacml3:AttributeDesignator
                                    AttributeId="axiomatics.user.role"
                                    Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject"
                                    DataType="http://www.w3.org/2001/XMLSchema#string"
                                    MustBePresent="false" />
                            </xacml3:Match>
                        </xacml3:AllOf>
                    </xacml3:AnyOf>
                </xacml3:Target>
            </xacml3:Rule>
        </xacml3:Policy>
    </xacml3:PolicySet>
    

    执行政策



    假设您有一个API,例如/api/profiles/{profileID}。您可以通过2种方式使用API​​:
  • GET/api/profiles将返回用户有权使用
  • 的所有配置文件
    如果用户有权访问,则
  • GET/api/profiles/123将返回配置文件123,否则将返回HTTP 403(或404-您可能会说甚至不想透露该配置文件确实存在)。

  • 为此,您需要实现一个策略执行点(PEP)。这可能是WSO2的API管理器。 PEP负责
  • 解析传入的API调用(GET/api/profile/123)
  • 将其转换为授权请求,例如爱丽丝可以查看个人资料123吗?
  • 将请求发送到PDP
  • 处理从PDP返回的响应-尤其是提取决策(例如,许可)。

  • 如果决定是许可,则将调用转发到您的后端API。如果不是,则可以返回HTTP 403/404,如所讨论。

    如果是403,则调用确实转到了后端,最终响应从您的后端转向并经过了PEP,在此它可以再次调用PDP,例如,对数据进行编辑。



    不,你不知道。构建菜单或导航项目时,您还可以调用PDP并询问给定用户是否可以访问给定功能集,例如: “爱丽丝可以查看导航栏项目#123吗?”。您需要最少的业务逻辑来调用PDP。

    关于authorization - 通过XACML策略进行RBAC/ABAC,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/53883722/

    10-11 08:03