RBAC/ABAC通过XACML策略

Har*_*shi 8 authorization rbac xacml wso2is abac

我正在研究各种类型的访问控制模型,并且知道是受欢迎的模型.

对于我的一个项目,我有一个基本的场景,我无法理解我应该选择RBAC还是ABAC.显然RBACABAC我应该去的子集,ABAC但是ABAC需要一些经验才能在编写策略.我们正在使用WSOIS和APIM.

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

  • 管理员可以查看,删除和更新用户.
  • 所有者可以查看和更新​​.
  • 会员只能查看.

在某个时刻,我使用HTTP动词来实现愿望结果,即所有者无法访问DELETE请求,成员无法访问PUT&DELETE.

问题

我有一个仪表板,我在其中显示不同的部分,如最高用户,计费,服务,顶级消费者等.

  1. 我需要nav-bar根据服务器的用户角色和属性进行填充,例如,成员不应该有权访问其他用户(添加,列表)nav-bar.nav-bar项目依赖于用户角色,以便我们可以通过RBAC
  2. 我们已经计划增加与OPS一样,营销的作用,支持等等.这是否意味着我们需要创建一个单独的DB-模式,以保持每个角色的访问权限?
  3. 在仪表板中,我需要隐藏/显示用户,服务等中的视图,更新和删除按钮.现在,成员可以看到用户但无权更新或删除它们.无法查看统计信息,结算和其他私人信息.
  4. 所有者可以查看与其部门/组织相关的所有用户,但管理员可以查看所有部门/组织的所有用户.在这里,我们需要为所有消费者使用相同的API,但api对不同的角色应该有不同的响应.角色可以是10s和100s,因此ee不能为每个角色创建不同的api.

我们可以实现所有这些场景,RBAC但是为了管理nav-bar和查看相关的实现,我们需要在服务器中添加业务逻辑而不是使用WSO2-ISWSO2-APIM.有没有办法管理隐藏/显示按钮和部分等视图权限,甚至消费相同,API但它应该为不同的api消费者返回不同的结果.

Dav*_*ard 9

首先,我对迟到的回复表示歉意。这是我的内联评论。

ACL、RBAC、ABAC

我正在研究各种类型的访问控制模型,并了解到 abac 和 rbac 是流行的模型。

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

为什么是ABAC?

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

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

ABAC 架构

您的用例

我的一个项目有一个基本场景,我不明白我是否应该使用 RBACor ABAC。显然 RBAC 是 ABAC 的子集,所以我绝对应该选择 ABAC,但 ABAC 需要一些经验才能在 xacml 中编写策略。我们正在使用 WSO IS 和 APIM。

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

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

  • 管理员可以查看、删除和更新用户。
  • 业主可以查看和更新​​。
  • 会员只能查看。

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

此刻我正在使用 HTTP 动词来实现期望的结果,即所有者无法访问 DELETE 请求,成员无法访问 PUT 和 DELETE。

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

你的挑战

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

我有一个仪表板,我在其中显示不同的部分,例如顶级用户、计费、服务、顶级消费者等。

我需要根据用户角色和服务器的属性填充导航栏,例如,成员不应有权查看导航栏中的其他用户(添加、列表)。导航栏项目依赖于用户角色,所以我们可以通过 RBAC 管理它们?

这将通过 ABAC 策略处理。见下文

我们计划添加操作、营销、支持等角色。这是否意味着我们需要创建一个单独的 db-schema 来维护每个角色的访问权限?

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

在仪表板中,我需要隐藏/显示用户、服务等中的视图、更新和删除按钮。现在成员可以看到用户但无权更新或删除它们。他们无法查看统计数据、账单和其他私人信息。

所有者可以查看与其部门/组织相关的所有用户,管理员可以查看所有部门/组织的所有用户。这里我们需要为所有消费者使用相同的 API,但 api 应该对不同的角色做出不同的响应。角色可以是 10s 和 100s,所以 ee 不能为每个角色创建不同的 api。题

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

当然是。这就是使用 ABAC 和策略的目的。鉴于您使用的是 WSO2 IS,请查看该产品内部的 PDP Balana。还有其他解决方案,例如 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                
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

和 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>
Run Code Online (Sandbox Code Playgroud)

执行政策

我将如何为单个 api 但为不同的角色/用户返回不同的数据。

假设您有一个 API,例如/api/profiles/{profileID}. 您可以通过两种方式使用 API:

  • GET /api/profiles 将返回用户有权访问的所有配置文件
  • 如果用户有权访问,则 GET /api/profiles/123 将返回配置文件 123,否则返回 HTTP 403(或 404 - 您可以争辩说您甚至不想透露所述配置文件确实存在)。

为此,您需要实施策略执行点 (PEP)。这可能是 WSO2 的 API 管理器。PEP 负责

  1. 解析传入的 API 调用 (GET /api/profile/123)
  2. 将其转换为授权请求,例如 Alice 可以查看个人资料 123 吗?
  3. 向 PDP 发送请求

Har*_*shi 2

经过一番观察,我想到了一件事。

使用上面的WSO2 APIMapi 来获取给swagger.json定的API(这些应该/将具有所有可用的 api)。现在使用相关性HTTP-verbs将资源与角色和响应进行映射。

例如,如果成员不应该有权访问,DELETE那么使用这种方法我们可以要求服务器返回当前页面/视图的所有权限,并将这些值映射到前端以隐藏/显示按钮/视图或整个内容。

缺点: 为了避免重复,我们可以将这些映射保存在数据库中。但这个逻辑需要你自己的服务器中有一些业务逻辑以及访问数据库的读/写操作。