【问题标题】:How does missing-attribute work in XACML?XACML 中的缺失属性如何工作?
【发布时间】:2022-01-26 23:55:46
【问题描述】:

我正在使用 XACML 进行访问控制应用程序,特别是 PDP 的 Balana 实现。

在此应用程序中,特定类型的用户帐户只能访问确定的资源。 这是政策的精简版:

<Policy xmlns="urn:oasis:names:tc:xacml:3.0:core:schema:wd-17" PolicyId="NormalMode" RuleCombiningAlgId="urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:deny-overrides" Version="1.0">
    <Description>Medical Records access control policy in Normal operational Mode</Description>
    <Target />
    <Rule Effect="Deny" RuleId="doctors">
        <Target>
            <AnyOf>
                <AllOf>
                    <Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-equal">
                        <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">PersonalData</AttributeValue>
                        <AttributeDesignator AttributeId="urn:oasis:names:tc:xacml:1.0:resource:resource-id" Category="urn:oasis:names:tc:xacml:3.0:attribute-category:resource" DataType="http://www.w3.org/2001/XMLSchema#string" MustBePresent="true" />
                    </Match>
                    <Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-equal">
                        <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">DOCTOR</AttributeValue>
                        <AttributeDesignator AttributeId="urn:oasis:names:tc:xacml:1.0:subject:subject-id" Category="urn:oasis:names:tc:xacml:3.0:attribute-category:access-subject" DataType="http://www.w3.org/2001/XMLSchema#string" MustBePresent="true" />
                    </Match>
                    <Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-equal">
                        <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">read</AttributeValue>
                        <AttributeDesignator AttributeId="urn:oasis:names:tc:xacml:1.0:action:action-id" Category="urn:oasis:names:tc:xacml:3.0:attribute-category:action" DataType="http://www.w3.org/2001/XMLSchema#string" MustBePresent="true" />
                    </Match>
                </AllOf>
            </AnyOf>
        </Target>
        <AdviceExpressions>
            <AdviceExpression AdviceId="doctors_advice" AppliesTo="Deny">
                <AttributeAssignmentExpression AttributeId="urn:oasis:names:tc:xacml:2.0:example:attribute:text">
                    <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">Doctors are not allowed to see Personal Data</AttributeValue>
                </AttributeAssignmentExpression>
            </AdviceExpression>
        </AdviceExpressions>
    </Rule>
<Rule RuleId="permit-rule" Effect="Permit" />
</Policy>

实际上有更多规则涵盖所有帐户类型和所有资源类型,但它们都具有相同的结构:目标是一个主题 ID(帐户类型),试图访问一个 [或多个] 资源[s] 通过一个动作。所有规则都具有“拒绝”效果,因为组合算法是“拒绝覆盖”。 在所有规则的最后,有一条通用规则允许每个人通过任何操作访问任何内容(我知道这不是最好的方法,将来我将切换到“最小权限”方法)。 如果请求匹配任何拒绝规则(以及最后一个“允许”规则),则最终决定将是“拒绝”,否则只有最后一个规则是匹配的,而决定将是“允许”。

以下是 PEP 向 Balana PDP 生成的请求:

    <Request xmlns="urn:oasis:names:tc:xacml:3.0:core:schema:wd-17" CombinedDecision="false" ReturnPolicyIdList="false">
        <Attributes Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject">
            <Attribute AttributeId="urn:oasis:names:tc:xacml:1.0:subject:subject-id" IncludeInResult="false">
                <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">DOCTOR</AttributeValue>
            </Attribute>
        </Attributes>
        <Attributes Category="urn:oasis:names:tc:xacml:3.0:attribute-category:resource">
            <Attribute AttributeId="urn:oasis:names:tc:xacml:1.0:resource:resource-id" IncludeInResult="false">
                <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">NameSurname</AttributeValue>
            </Attribute>
        </Attributes>
        <Attributes Category="urn:oasis:names:tc:xacml:3.0:attribute-category:action">
            <Attribute AttributeId="urn:oasis:names:tc:xacml:1.0:action:action-id" IncludeInResult="false">
                <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">read</AttributeValue>
            </Attribute>
        </Attributes>
    </Request>

具有此特定请求的 PDP 的决定应该是“允许”,因为由于请求的资源 ID,它不匹配第一个规则,它将仅匹配最后一个允许规则。

现在的问题是,无论我发送什么请求,PDP 决定的结果如下:

    <Response xmlns="urn:oasis:names:tc:xacml:3.0:core:schema:wd-17">
    <Result>
        <Decision>Indeterminate</Decision>
        <Status>
            <StatusCode Value="urn:oasis:names:tc:xacml:1.0:status:missing-attribute" />
            <StatusMessage>Couldn't find AttributeDesignator attribute</StatusMessage>
            <StatusDetail>
                <MissingAttributeDetail AttributeId="urn:oasis:names:tc:xacml:1.0:subject:subject-id" DataType="http://www.w3.org/2001/XMLSchema#string" Category="urn:oasis:names:tc:xacml:3.0:attribute-category:access-subject"></MissingAttributeDetail>
            </StatusDetail>
        </Status>
    </Result>
</Response>

我不知道为什么。

https://docs.oasis-open.org/xacml/3.0/xacml-3.0-core-spec-cd-1-en.html

XACML 文档说这是由于“在请求上下文中没有任何属性指示符属性或策略中找到的选择器的匹配属性”,但我不明白为什么,因为最后一条规则应该永远是一个匹配。 (此政策“格式”由官方 Balana Github 存储库采用: https://github.com/wso2/balana/blob/master/modules/balana-samples/kmarket-trading-sample/resources/kmarket-blue-policy.xml)

【问题讨论】:

    标签: java access-control xacml balana


    【解决方案1】:

    首先,提供的政策不完整。它缺少结束标记和 Permit 规则。在我的测试中,我添加了这些,它“对我有用”,但由于我们不确切知道你有什么,你可能还有其他错误。

    您的问题似乎是您复制/粘贴了策略中的属性,并且使用了错误的主题 ID 类别。应该是:

    urn:oasis:names:tc:xacml:1.0:subject-category:access-subject

    代替:

    urn:oasis:names:tc:xacml:3.0:subject-category:access-subject

    所以是的,请求缺少必需的主题 ID 属性,因为请求使用的主题 ID 类别与策略中定义的类别不同。

    当我使用以下更正后的政策并请求时,我确实获得了许可。请注意,我没有使用 Balana,但您应该会看到相同的结果。

    政策:

    <xacml3:Policy xmlns:xacml3="urn:oasis:names:tc:xacml:3.0:core:schema:wd-17" PolicyId="NormalMode" Version="1" RuleCombiningAlgId="urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:deny-overrides">
      <xacml3:Description>Medical Records access control policy in Normal operational Mode</xacml3:Description>
      <xacml3:PolicyDefaults>
        <xacml3:XPathVersion>http://www.w3.org/TR/1999/REC-xpath-19991116</xacml3:XPathVersion>
      </xacml3:PolicyDefaults>
      <xacml3:Target/>
      <xacml3:Rule RuleId="doctors" Effect="Deny">
        <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">PersonalData</xacml3:AttributeValue>
                <xacml3:AttributeDesignator Category="urn:oasis:names:tc:xacml:3.0:attribute-category:resource" AttributeId="urn:oasis:names:tc:xacml:1.0:resource:resource-id" DataType="http://www.w3.org/2001/XMLSchema#string" MustBePresent="true"/>
              </xacml3:Match>
              <xacml3:Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-equal">
                <xacml3:AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">DOCTOR</xacml3:AttributeValue>
                <xacml3:AttributeDesignator Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject" AttributeId="urn:oasis:names:tc:xacml:1.0:subject:subject-id" DataType="http://www.w3.org/2001/XMLSchema#string" MustBePresent="false"/>
              </xacml3:Match>
              <xacml3:Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-equal">
                <xacml3:AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">read</xacml3:AttributeValue>
                <xacml3:AttributeDesignator Category="urn:oasis:names:tc:xacml:3.0:attribute-category:action" AttributeId="urn:oasis:names:tc:xacml:1.0:action:action-id" DataType="http://www.w3.org/2001/XMLSchema#string" MustBePresent="true"/>
              </xacml3:Match>
            </xacml3:AllOf>
          </xacml3:AnyOf>
        </xacml3:Target>
        <xacml3:AdviceExpressions>
          <xacml3:AdviceExpression AdviceId="doctors_advice" AppliesTo="Deny">
            <xacml3:AttributeAssignmentExpression AttributeId="urn:oasis:names:tc:xacml:2.0:example:attribute:text" Category="http://axiomatics.com/ObligationAndAdvice/DefaultCategory">
              <xacml3:AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">Doctors are not allowed to see Personal Data</xacml3:AttributeValue>
            </xacml3:AttributeAssignmentExpression>
          </xacml3:AdviceExpression>
        </xacml3:AdviceExpressions>
      </xacml3:Rule>
      <xacml3:Rule RuleId="d3a90374-79e6-47e6-9cfd-f3e23f737c99" Effect="Permit">
        <xacml3:Description>Rule description</xacml3:Description>
        <xacml3:Target/>
      </xacml3:Rule>
    </xacml3:Policy>
    

    请求:

    <xacml-ctx:Request ReturnPolicyIdList="true" CombinedDecision="false" xmlns:xacml-ctx="urn:oasis:names:tc:xacml:3.0:core:schema:wd-17">
      <xacml-ctx:RequestDefaults>
        <xacml-ctx:XPathVersion>http://www.w3.org/TR/1999/REC-xpath-19991116</xacml-ctx:XPathVersion>
      </xacml-ctx:RequestDefaults>
      <xacml-ctx:Attributes Category="urn:oasis:names:tc:xacml:3.0:attribute-category:resource">
        <xacml-ctx:Attribute AttributeId="urn:oasis:names:tc:xacml:1.0:resource:resource-id" IncludeInResult="false">
          <xacml-ctx:AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">NameSurname</xacml-ctx:AttributeValue>
        </xacml-ctx:Attribute>
      </xacml-ctx:Attributes>
      <xacml-ctx:Attributes Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject">
        <xacml-ctx:Attribute AttributeId="urn:oasis:names:tc:xacml:1.0:subject:subject-id" IncludeInResult="false">
          <xacml-ctx:AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">DOCTOR</xacml-ctx:AttributeValue>
        </xacml-ctx:Attribute>
      </xacml-ctx:Attributes>
      <xacml-ctx:Attributes Category="urn:oasis:names:tc:xacml:3.0:attribute-category:action">
        <xacml-ctx:Attribute AttributeId="urn:oasis:names:tc:xacml:1.0:action:action-id" IncludeInResult="false">
          <xacml-ctx:AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">read</xacml-ctx:AttributeValue>
        </xacml-ctx:Attribute>
      </xacml-ctx:Attributes>
    </xacml-ctx:Request>
    

    【讨论】:

    • 我很抱歉,这是一个格式错误。现在可见
    • 我没有注意到我应该对主题 ID 使用主题类别,对资源 ID 和操作 ID 使用属性类别。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-20
    • 2019-05-31
    • 1970-01-01
    • 1970-01-01
    • 2018-08-14
    相关资源
    最近更新 更多