使用XACML进行复杂授权

时间:2017-01-04 21:45:04

标签: authorization access-control xacml abac alfa

我的公司正在寻求实施集中式安全服务,它似乎是一个流行的标准是XACML。我有一个复杂的授权方案,我一直在弄清楚如何使用XACML策略的属性来定义它。

我正在处理的系统有几个与此身份验证方案相关的部分:

  • 用户创建项目以组织他们的工作。每个项目都有一个团队成员和查看者列表(可以查看项目但不能修改项目的用户或组)。
  • 在这些项目中,用户可以创建配方来描述应该如何制造某些东西。
  • 用户要求其他组制作这些食谱。

如果用户想要查看特定商品的配方,则必须满足以下任何条件:

  • 用户必须是食谱的所有者(撰写者的所有者)。
  • 用户必须是创建配方的项目的团队成员。 (直接或通过团体会员资格)
  • 用户必须是制作配方的组的成员。 (他们需要看到制作它的配方。)
  • 用户必须是过去两周内制作配方的组的成员。 (即,在完成制作配方的请求后,他们可以继续查看配方两周以纠正任何问题。)
  • 用户必须是管理员。

根据这些规则,确定用户是否可以查看配方所需的属性似乎包括:

  • 用户
  • 用户的组成员资格(用于项目访问,制造组或管理员访问权限)
  • 项目团队成员和观众
  • 制作配方请求

问题:

  • PIP如何收集这些信息?直接来自数据库?通过服务调用存储此信息的系统?
  • 如何为XACML(通常)表示此信息?我见过的大多数例子都使用了不使用数据集合的简单模型(如制造请求列表);简单地直接归属于被访问的对象。数据是否会以某种方式被夷为平地,例如" isBeingManufacturedByUserGroup"? (如果是,那么如何确定该属性的值?)
  • 如何构建策略来评估这些规则?
  • 是否有其他方法可以处理此类授权(除了XACML)? OAuth 2.0能否更轻松地处理这类问题?

1 个答案:

答案 0 :(得分:4)

(免责声明 - 我为Axiomatics工作,这是XACML和ABAC的领先实现)

好问题。我实际上已经整合了一个授权策略生命周期,它引导用户完成收集需求,识别属性和实施策略的过程。

Authorization Policy Lifecycle

在您的情况下,让我们完成您的要求

要求收集

您的原始要求

  

以下任何一项都必须为真:

     
      
  • 用户必须是食谱的所有者(撰写者的所有者)。
  •   
  • 用户必须是创建配方的项目的团队成员。 (直接或通过团体会员资格)
  •   
  • 用户必须是制作配方的组的成员。 (他们需要看到制作它的配方。)
  •   
  • 用户必须是过去两周内制作配方的组的成员。 (即,在完成制作配方的请求后,他们可以继续查看配方两周以纠正任何问题。)
  •   
  • 用户必须是管理员。
  •   

重组要求

我喜欢将要求作为主语 - 动词 - 对象重新修改,例如:用户可以查看配方...根据此模型,您的原始要求可以重新编写如下:

  1. 用户可以查看他/她拥有的食谱。
  2. 用户可以查看在用户所属的项目中创建的配方
  3. 用户可以在制造阶段查看属于用户所属(制造)组的配方。
  4. 用户可以在制造阶段查看属于用户所属(制造)组的配方,以及制造日期是否在今天的2周之内。
  5. 管理员可以查看食谱。
  6. 识别属性

    您可以将属性分解为不同的类别(或语法功能)。 XACML本身使用类别,因此这是实现使用XACML(或ALFA)的自然步骤。

    主题属性

    • userId:此类别中的键属性。它将用于识别用户,但也可以检索所有其他派生属性。
    • 项目:用户所属的项目列表
    • group:用户所属的群组列表
    • 角色:用户的角色,例如

    资源属性

    • objectType:这是一个属性,用于区分要控制访问的不同类型的项目,例如:食谱,文件或交易
    • recipeId:食谱的关键属性。它将用于识别您想要访问的特定配方,并且还将用作查找其他属性的密钥,例如配方所处的状态,它所属的组和项目。
    • group:配方所属的组
    • 项目:食谱所属的项目

    动作属性

    在这个类别中,从它的外观来看,你只有:

    • actionId,潜在值为{view,edit,delete ...}。

    使用属性

    重写的要求
    1. 任何人都可以采取行动=="查看" on objectType ==" recipe" if recipe.owner == userId
    2. 任何人都可以采取行动=="查看" on objectType ==" recipe"如果recipe.project == user.project
    3. 任何人都可以采取行动=="查看" on objectType ==" recipe"如果recipe.stage =="制造"和recipe.group == user.group
    4. 任何人都可以采取行动=="查看" on objectType ==" recipe"如果recipe.stage =="制造"和recipe.group == user.group和currentDate< = recipe.manufacturedDate +" 2周"。
    5. 任何有角色的人=="管理员"可以做的动作=="查看" on objectType ==" recipe"。
    6. 使用ALFA或XACML

      实施策略

      下一步是实施您的政策。您可以使用ALFA(授权的缩写语言)。 Axiomatics有一个Eclipse plugin,可将ALFA转换为XACML 3.0。

      让我们创建一个处理食谱的策略集。该策略集将包含处理操作视图的策略。反过来,该政策将包含满足每项要求的规则。

      policyset recipe{
          target clause objectType == "recipe"
          apply firstApplicable
          /**
           * View recipes
           */
          policy viewRecipe{
              target clause actionId == "view"
              apply firstApplicable
              /**
               * Administrators can view all recipes
               */
              rule administrator{
                  target clause user.role == "administrator"
                  permit
              }
              /**
               * Recipe owners can view their own recipes
               */
              rule owner{
                  permit
                  condition user.userId == recipe.owner
              }
              /**
               * Users can view recipes in their project
               */
               rule sameProject{
                   permit
                   condition user.assignedProject == recipe.assignedProject
               }
              /**
               * Users can view recipes in their project
               */
               rule sameGroup{
                   target clause recipe.stage == "manufacturing"
                   permit
                   condition user.assignedGroup == recipe.assignedGroup
               }
              /**
               * Users can view recipes in their project
               */
               rule sameGroupManufactured{
                   target clause recipe.stage == "manufacturing"
                   permit
                   condition user.assignedGroup == recipe.assignedGroup && currentDate<=dateTimeAddDayTimeDuration(dateTimeOneAndOnly(recipe.manufacturedDate),"P14D":dayTimeDuration)
               }
          }
      }
      

      使用政策信息点

        

      PIP如何收集这些信息?直接来自数据库?通过服务调用存储此信息的系统?

      PIP只是外部属性源的抽象概念。它可以是任何东西。不同的实现将具有不同的PIP连接器。例如,Axiomatics Policy Server提供SQL,LDAP和REST服务的连接器。这涵盖了客户的大部分需求。

      XACML和OAuth 2.0

      您比较两种技术,但它们有点不同。 OAuth 2.0首先关注身份验证。它开始打败password anti-pattern。然后需要定义权限,或者在OAuth中调用它们的范围。但是这些范围只是准时权限。您仍然依赖目标应用程序来发布一组有效的作用域,但您仍然无法进行细粒度的访问控制。我的同事写了一篇关于这个主题的三部分博客,第一部分你可以read here

      我希望这会有所帮助。随意向我询问后续问题或推文。

      XACML输出(奖励)

      <?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 xmlns:xacml3="urn:oasis:names:tc:xacml:3.0:core:schema:wd-17"
          PolicySetId="http://axiomatics.com/alfa/identifier/so.recipe"
          PolicyCombiningAlgId="urn:oasis:names:tc:xacml:1.0:policy-combining-algorithm:first-applicable"
          Version="1.0">
          <xacml3:Description>Control access to recipes</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">recipe</xacml3:AttributeValue>
                          <xacml3:AttributeDesignator 
                              AttributeId="so.objectType"
                              DataType="http://www.w3.org/2001/XMLSchema#string"
                              Category="urn:oasis:names:tc:xacml:3.0:attribute-category:resource"
                              MustBePresent="false"
                          />
                      </xacml3:Match>
                  </xacml3:AllOf>
              </xacml3:AnyOf>
          </xacml3:Target>
          <xacml3:Policy xmlns:xacml3="urn:oasis:names:tc:xacml:3.0:core:schema:wd-17"
              PolicyId="http://axiomatics.com/alfa/identifier/so.recipe.viewRecipe"
              RuleCombiningAlgId="urn:oasis:names:tc:xacml:1.0:rule-combining-algorithm:first-applicable"
              Version="1.0">
              <xacml3:Description>View recipes</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="so.actionId"
                                  DataType="http://www.w3.org/2001/XMLSchema#string"
                                  Category="urn:oasis:names:tc:xacml:3.0:attribute-category:action"
                                  MustBePresent="false"
                              />
                          </xacml3:Match>
                      </xacml3:AllOf>
                  </xacml3:AnyOf>
              </xacml3:Target>
              <xacml3:Rule 
                      Effect="Permit"
                      RuleId="http://axiomatics.com/alfa/identifier/so.recipe.viewRecipe.administrator">
                  <xacml3:Description>Administrators can view all recipes</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="so.user.role"
                                      DataType="http://www.w3.org/2001/XMLSchema#string"
                                      Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject"
                                      MustBePresent="false"
                                  />
                              </xacml3:Match>
                          </xacml3:AllOf>
                      </xacml3:AnyOf>
                  </xacml3:Target>
              </xacml3:Rule>
              <xacml3:Rule 
                      Effect="Permit"
                      RuleId="http://axiomatics.com/alfa/identifier/so.recipe.viewRecipe.owner">
                  <xacml3:Description>Recipe owners can view their own recipes</xacml3:Description>
                  <xacml3:Target />
                  <xacml3:Condition>
                      <xacml3:Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:any-of-any">
                          <xacml3:Function FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-equal"/>
                          <xacml3:AttributeDesignator 
                              AttributeId="so.user.userId"
                              DataType="http://www.w3.org/2001/XMLSchema#string"
                              Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject"
                              MustBePresent="false"
                          />
                          <xacml3:AttributeDesignator 
                              AttributeId="so.recipe.owner"
                              DataType="http://www.w3.org/2001/XMLSchema#string"
                              Category="urn:oasis:names:tc:xacml:3.0:attribute-category:resource"
                              MustBePresent="false"
                          />
                      </xacml3:Apply>
                  </xacml3:Condition>
              </xacml3:Rule>
              <xacml3:Rule 
                      Effect="Permit"
                      RuleId="http://axiomatics.com/alfa/identifier/so.recipe.viewRecipe.sameProject">
                  <xacml3:Description>Users can view recipes in their project</xacml3:Description>
                  <xacml3:Target />
                  <xacml3:Condition>
                      <xacml3:Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:any-of-any">
                          <xacml3:Function FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-equal"/>
                          <xacml3:AttributeDesignator 
                              AttributeId="so.user.assignedProject"
                              DataType="http://www.w3.org/2001/XMLSchema#string"
                              Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject"
                              MustBePresent="false"
                          />
                          <xacml3:AttributeDesignator 
                              AttributeId="so.recipe.assignedProject"
                              DataType="http://www.w3.org/2001/XMLSchema#string"
                              Category="urn:oasis:names:tc:xacml:3.0:attribute-category:resource"
                              MustBePresent="false"
                          />
                      </xacml3:Apply>
                  </xacml3:Condition>
              </xacml3:Rule>
              <xacml3:Rule 
                      Effect="Permit"
                      RuleId="http://axiomatics.com/alfa/identifier/so.recipe.viewRecipe.sameGroup">
                  <xacml3:Description>Users can view recipes in their project</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">manufacturing</xacml3:AttributeValue>
                                  <xacml3:AttributeDesignator 
                                      AttributeId="so.recipe.stage"
                                      DataType="http://www.w3.org/2001/XMLSchema#string"
                                      Category="urn:oasis:names:tc:xacml:3.0:attribute-category:resource"
                                      MustBePresent="false"
                                  />
                              </xacml3:Match>
                          </xacml3:AllOf>
                      </xacml3:AnyOf>
                  </xacml3:Target>
                  <xacml3:Condition>
                      <xacml3:Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:any-of-any">
                          <xacml3:Function FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-equal"/>
                          <xacml3:AttributeDesignator 
                              AttributeId="so.user.assignedGroup"
                              DataType="http://www.w3.org/2001/XMLSchema#string"
                              Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject"
                              MustBePresent="false"
                          />
                          <xacml3:AttributeDesignator 
                              AttributeId="so.recipe.assignedGroup"
                              DataType="http://www.w3.org/2001/XMLSchema#string"
                              Category="urn:oasis:names:tc:xacml:3.0:attribute-category:resource"
                              MustBePresent="false"
                          />
                      </xacml3:Apply>
                  </xacml3:Condition>
              </xacml3:Rule>
              <xacml3:Rule 
                      Effect="Permit"
                      RuleId="http://axiomatics.com/alfa/identifier/so.recipe.viewRecipe.sameGroupManufactured">
                  <xacml3:Description>Users can view recipes in their project</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">manufacturing</xacml3:AttributeValue>
                                  <xacml3:AttributeDesignator 
                                      AttributeId="so.recipe.stage"
                                      DataType="http://www.w3.org/2001/XMLSchema#string"
                                      Category="urn:oasis:names:tc:xacml:3.0:attribute-category:resource"
                                      MustBePresent="false"
                                  />
                              </xacml3:Match>
                          </xacml3:AllOf>
                      </xacml3:AnyOf>
                  </xacml3:Target>
                  <xacml3:Condition>
                      <xacml3:Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:and">
                          <xacml3:Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:any-of-any">
                              <xacml3:Function FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-equal"/>
                              <xacml3:AttributeDesignator 
                                  AttributeId="so.user.assignedGroup"
                                  DataType="http://www.w3.org/2001/XMLSchema#string"
                                  Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject"
                                  MustBePresent="false"
                              />
                              <xacml3:AttributeDesignator 
                                  AttributeId="so.recipe.assignedGroup"
                                  DataType="http://www.w3.org/2001/XMLSchema#string"
                                  Category="urn:oasis:names:tc:xacml:3.0:attribute-category:resource"
                                  MustBePresent="false"
                              />
                          </xacml3:Apply>
                          <xacml3:Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:any-of">
                              <xacml3:Function FunctionId="urn:oasis:names:tc:xacml:1.0:function:dateTime-greater-than-or-equal"/>
                              <xacml3:Apply FunctionId="urn:oasis:names:tc:xacml:3.0:function:dateTime-add-dayTimeDuration" >
                                  <xacml3:Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:dateTime-one-and-only" >
                                      <xacml3:AttributeDesignator 
                                          AttributeId="so.recipe.manufacturedDate"
                                          DataType="http://www.w3.org/2001/XMLSchema#dateTime"
                                          Category="urn:oasis:names:tc:xacml:3.0:attribute-category:resource"
                                          MustBePresent="false"
                                      />
                                  </xacml3:Apply>
                                  <xacml3:AttributeValue
                                      DataType="http://www.w3.org/2001/XMLSchema#dayTimeDuration">P14D</xacml3:AttributeValue>
                              </xacml3:Apply>
                              <xacml3:AttributeDesignator 
                                  AttributeId="currentDate"
                                  DataType="http://www.w3.org/2001/XMLSchema#dateTime"
                                  Category="urn:oasis:names:tc:xacml:3.0:attribute-category:environment"
                                  MustBePresent="false"
                              />
                          </xacml3:Apply>
                      </xacml3:Apply>
                  </xacml3:Condition>
              </xacml3:Rule>
          </xacml3:Policy>
      </xacml3:PolicySet>