【问题标题】:Using XACML to express policy which is a logical expression使用 XACML 表示策略,这是一个逻辑表达式
【发布时间】:2014-07-02 00:02:24
【问题描述】:

我对 XACML 非常陌生。我正在使用 XACML 来表达策略。但除了OASIS XACML Technical Committee 中的一些例子外,我找不到任何好的例子。

好的,这是我的问题:

我想使用 XACML 来表达策略。只有满足策略的用户才能访问资源。策略是一个逻辑表达式。例如:

(非 A1)和(A2 OR A3)和(2 of (A4, A5,A6))

2 of (A4,A5,A6) 是指只有当 A4,A5,A6 中有 2 个或多个为真时才为真。

“AllOf”和“AnyOf”可以用来表示“AND”和“OR”,但是我不知道如何表示“2 of (A4,A5,A6)”和“not A1”。

谢谢!

【问题讨论】:

    标签: authorization access-control policy xacml alfa


    【解决方案1】:

    根据您的要求,您需要使用 XACML 条件。条件只存在于规则中,因此这意味着您必须将逻辑放入规则中。

    这是因为您需要一个 XACML 目标中不允许的函数:n-of。

    这也是因为 XACML 目标不能有否定表达式。表达 Not(A1) 的唯一方法是通过条件。

    原因是 XACML 处理属性包。所以当你写一个目标时:

    role==manager
    

    您实际上是在说:如果用户至少有一个角色等于经理......

    那么相反的情况是什么?

    对于您的 2 of (a,b,c),您可以使用称为 n-of (urn:oasis:names:tc:xacml:1.0:function:n-of 在A.3.5 Logical functions 中定义的 XACML 函数)

    结果在ALFA

    /**
     * (not A1) and (A2 OR A3) and (2 of (A4, A5,A6))
     */
    policy stackoverflow{
        apply firstApplicable
        rule so{
            condition not(A1=="some value") && (A2=="" || A3=="") && nOf(2, stringOneAndOnly(A4)=="value", stringOneAndOnly(A5)=="value", stringOneAndOnly(A6)=="value")
            permit
        }
    }   
    

    在上面的示例中,我使用 A1 到 A6 字符串属性而不是布尔值来显示如何与值进行比较。请注意,我必须使用 stringOneAndOnly 函数来确保 nOf 函数中使用的每个属性都有一个值。

    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:Policy xmlns:xacml3="urn:oasis:names:tc:xacml:3.0:core:schema:wd-17"
        PolicyId="http://axiomatics.com/alfa/identifier/policing.principles.stackoverflow"
        RuleCombiningAlgId="urn:oasis:names:tc:xacml:1.0:rule-combining-algorithm:first-applicable"
        Version="1.0">
        <xacml3:Description>(not A1) and (A2 OR A3) and (2 of (A4, A5,A6))</xacml3:Description>
        <xacml3:PolicyDefaults>
            <xacml3:XPathVersion>http://www.w3.org/TR/1999/REC-xpath-19991116</xacml3:XPathVersion>
        </xacml3:PolicyDefaults>
        <xacml3:Target />
        <xacml3:Rule 
                Effect="Permit"
                RuleId="http://axiomatics.com/alfa/identifier/policing.principles.stackoverflow.so">
            <xacml3:Description />
            <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:not" >
                        <xacml3:Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:any-of">
                            <xacml3:Function FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-equal"/>
                            <xacml3:AttributeValue
                                DataType="http://www.w3.org/2001/XMLSchema#string">some value</xacml3:AttributeValue>
                            <xacml3:AttributeDesignator 
                                AttributeId="A1"
                                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>
                    <xacml3:Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:and">
                        <xacml3:Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:or">
                            <xacml3:Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:any-of">
                                <xacml3:Function FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-equal"/>
                                <xacml3:AttributeValue
                                    DataType="http://www.w3.org/2001/XMLSchema#string"></xacml3:AttributeValue>
                                <xacml3:AttributeDesignator 
                                    AttributeId="A2"
                                    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:string-equal"/>
                                <xacml3:AttributeValue
                                    DataType="http://www.w3.org/2001/XMLSchema#string"></xacml3:AttributeValue>
                                <xacml3:AttributeDesignator 
                                    AttributeId="A3"
                                    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>
                        <xacml3:Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:n-of" >
                            <xacml3:AttributeValue
                                DataType="http://www.w3.org/2001/XMLSchema#integer">2</xacml3:AttributeValue>
                            <xacml3:Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-equal">
                                <xacml3:Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-one-and-only" >
                                    <xacml3:AttributeDesignator 
                                        AttributeId="A4"
                                        DataType="http://www.w3.org/2001/XMLSchema#string"
                                        Category="urn:oasis:names:tc:xacml:3.0:attribute-category:resource"
                                        MustBePresent="false"
                                    />
                                </xacml3:Apply>
                                <xacml3:AttributeValue
                                    DataType="http://www.w3.org/2001/XMLSchema#string">value</xacml3:AttributeValue>
                            </xacml3:Apply>
                            <xacml3:Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-equal">
                                <xacml3:Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-one-and-only" >
                                    <xacml3:AttributeDesignator 
                                        AttributeId="A5"
                                        DataType="http://www.w3.org/2001/XMLSchema#string"
                                        Category="urn:oasis:names:tc:xacml:3.0:attribute-category:resource"
                                        MustBePresent="false"
                                    />
                                </xacml3:Apply>
                                <xacml3:AttributeValue
                                    DataType="http://www.w3.org/2001/XMLSchema#string">value</xacml3:AttributeValue>
                            </xacml3:Apply>
                            <xacml3:Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-equal">
                                <xacml3:Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-one-and-only" >
                                    <xacml3:AttributeDesignator 
                                        AttributeId="A6"
                                        DataType="http://www.w3.org/2001/XMLSchema#string"
                                        Category="urn:oasis:names:tc:xacml:3.0:attribute-category:resource"
                                        MustBePresent="false"
                                    />
                                </xacml3:Apply>
                                <xacml3:AttributeValue
                                    DataType="http://www.w3.org/2001/XMLSchema#string">value</xacml3:AttributeValue>
                            </xacml3:Apply>
                        </xacml3:Apply>
                    </xacml3:Apply>
                </xacml3:Apply>
            </xacml3:Condition>
        </xacml3:Rule>
    </xacml3:Policy>
    

    --- 编辑 ---

    表达否定条件,例如not(gender==male),你有两种选择:

    • 任一可能值的集合都是有限的,例如真/假、男/女、热/暖/冷,您很乐意为每个案例制定政策或规则。
    • 或可能值集太长或无限,例如数值或公民身份列表(其中 180 多个)。

    在前一种情况下,您可以编写以下内容:

    policy checkGender{
        apply firstApplicable
        rule male{
            target clause gender=="male"
            permit
        }
        rule female{
            target clause gender=="female"
            permit
        }
        /**
         * Optionally add a catch all case
         */
        rule other{
            target clause ... // Here you'd have to define other checks you are interested in
        }
    }
    

    在后一种情况下,你需要写一个否定条件。为此,您需要使用 XACML 条件。由于 XACML 条件只存在于规则中,因此您需要深入到 XACML 规则级别。

    policy checkGender{
        apply firstApplicable
        rule notMale{
            condition not(gender=="male")
            permit
        }
    }
    

    【讨论】:

    • 谢谢!但是使用“NOT”还有另一个问题。我想表达一个像“NOT male”这样的政策,而不是“NOT gender=='male'”。操作“NOT”对值起作用,但对属性不起作用。我怎么能那样做?谢谢。
    • 这是我回答的一部分。如果要表达 NOT 策略,则需要在 XACML 规则中使用 XACML 条件。您还可以列出所有可能的值。您必须是男性或女性,因此您可以拥有女性保单、男性保单,并且可能还有未指定价值的保单。
    • 我添加了一个例子。如果答案正确,别忘了接受。
    • 在 XACML 请求中,您不能只发送一个值。您总是发送具有 0 个或多个值的属性。你总是会说性别=男性。
    • 好的,我明白了。 XACML 策略中也不能只存在没有属性名称的值。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多