如何使用自定义属性编写XACML策略

时间:2012-10-04 11:33:29

标签: policy xacml fedora-commons

我正在尝试编写一个将使用自定义属性的XACML策略。我想的是:

<?xml version="1.0" encoding="UTF-8"?>
<Policy xmlns="urn:oasis:names:tc:xacml:1.0:policy"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" PolicyId="deny-demo100"
  RuleCombiningAlgId="urn:oasis:names:tc:xacml:1.0:rule-combining-algorithm:first-applicable">
  <Description> </Description>
  <Target>
    <Subjects>
      <AnySubject/>
    </Subjects>
    <Resources>
  <AnyResource/>
</Resources>
<Actions>
  <AnyAction/>
</Actions>
  </Target>

  <Rule Effect="Deny" RuleId="rule-deny-demo100">
    <Target>
      <Subjects>
        <AnySubject/>
      </Subjects>
      <Resources>
        <Resource>
           <AnyResource/>
        </Resource>
      </Resources>
      <Actions>
        <Action>
          <ActionMatch MatchId="urn:oasis:names:tc:xacml:1.0:function:string-equal">
            <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">customAttribute</AttributeValue>
            <ActionAttributeDesignator AttributeId="urn:oasis:names:tc:xacml:1.0:action:action-    id" MustBePresent="false" DataType="http://www.w3.org/2001/XMLSchema#string"/>
          </ActionMatch>
        </Action>
      </Actions>
    </Target>    
  </Rule>

  <Rule RuleId="deny-demo100-catch-all" Effect="Permit" />

</Policy>

(我们正在使用Fedora的XACML实现)。

我确信我在这里遗漏了一些非常简单和基本的东西,但无法弄清楚是什么。有人能指出我正确的方向吗?

3 个答案:

答案 0 :(得分:5)

自定义属性是什么意思?你想用“普通老英语”表达什么?

在XACML中,您可以使用您喜欢的任何属性,例如角色,公民身份,许可,资源分类,时间......当然,属性的可用性取决于您要保护的应用程序类型。你是如何使用Fedora实现的?它是否适用于Fedora Linux OS中的访问控制?

如果要将属性与值进行比较,例如公民身份==加拿大人,然后使用<Target/>。如果要将2个属性进行比较,例如清除&gt;分类,然后使用<Condition>

答案 1 :(得分:1)

我不确定你在寻找什么,但我想你需要做一些基于属性的访问控制。

在XACML中有一个名为PIP(策略信息点)的组件,您可以从中检索外部源的属性并检查授权。

这可能会对您有所帮助:Understanding PIP (Policy Information Point)

如果您需要以更简单的方式创建XACML政策,可以按照以下步骤操作:XACML Policy Editor in WSO2 Identity Server

答案 2 :(得分:0)

我不得不承认我对XACML和Fedora的实现有点新鲜,但我的理解是你应该能够查询检查用户对象时出现的任何值。默认Fedora Commons安装的URL应为“localhost:8080 / fedora / user”,并在登录以前创建的名为“Joe User”的LDAP用户后,在我的服务器上生成以下对象:

<user id="Joe User">
  <attribute name="uid">
    <value>userj</value>
  </attribute>
  <attribute name="mail">
    <value>UserJ@ldap.test.user.uconn.edu</value>
  </attribute>
  <attribute name="sn">
    <value>User</value>
  </attribute>
  <attribute name="ou">
    <value>DPT</value>
  </attribute>
  <attribute name="cn">
    <value>Joe User</value>
  </attribute>
  <attribute name="description">
    <value>sample user</value>
  </attribute>
  <attribute name="role"/>
  <attribute name="fedoraRole"/>
  <attribute name="objectClass">
    <value>organizationalPerson</value>
    <value>person</value>
    <value>inetOrgPerson</value>
    <value>top</value>
  </attribute>
  <attribute name="displayName">
    <value>Joe User (LDAP)</value>
  </attribute>
</user>

一旦通过某个JAAS身份验证模块(如上面使用LDAP模块的情况)将一个值注入用户对象,或者甚至是环境变量,您应该能够查询它。在下面的示例策略中,如果用户将OU设置为“DPT”,我将Fedora设置为授予fedoraAdmin访问API-M调用的权限:

<?xml version="1.0" encoding="UTF-8"?>
<Policy xmlns="urn:oasis:names:tc:xacml:1.0:policy"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        PolicyId="permit-apim-to-ldap-ou"
        RuleCombiningAlgId="urn:oasis:names:tc:xacml:1.0:rule-combining-algorithm:first-applicable"
>
  <!-- test policy to approve API-M operations if a specific LDAP OU exists -->
  <!-- make sure access to API-M in premitted from the current client IP address first (check "deny-apim-if-not-in-list.xml" or "deny-apim-if-not-localhost.xml" ) -->
  <Description>note that other policies may provide exceptions to this broad policy. This policy assumes api-m users have to be authenticated</Description>
  <Target>
    <Subjects>
      <Subject> 
        <!-- specific OU - need to get this working with a range of values -->
        <SubjectMatch MatchId="urn:oasis:names:tc:xacml:1.0:function:string-equal">
          <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">DPT</AttributeValue>
          <SubjectAttributeDesignator AttributeId="ou" MustBePresent="false" DataType="http://www.w3.org/2001/XMLSchema#string"/>
        </SubjectMatch>
      </Subject>
    </Subjects>
    <Resources>
      <AnyResource/>
    </Resources>    
    <Actions>
        <AnyAction/>
    </Actions>
  </Target>
  <Rule RuleId="1" Effect="Permit"/>
</Policy>

自定义属性甚至可以添加Fedora XML用户文件(而不是Tomcat用户文件)而不是使用LDAP。可能有更好的方法来做到这一点,但正如我之前所说的,我对XACML很新,并且不完全理解它。此规则适用于我的localhost测试服务器,该服务器也基于其他规则。你的旅费可能会改变。

此外,如示例策略文件中所述,确保您正在测试的客户端都可以被允许,然后在您放置这样的规则之前拒绝API-M访问,因为在Fedora中调试XACML策略似乎即使在调试模式下,将很少的数据写入日志文件也非常困难(您将看到一个操作已通过或失败,但从未发生导致通过/失败结果的规则名称)。

相关问题