2

I'm trying to come up with a rule that says the string must begin with ABC but not be ABC123, ABC456, ABC789.

I'm trying write this to evaluate against a string bag, any pointers much appreciated.

David Brossard
  • 13,584
  • 6
  • 55
  • 88

1 Answers1

2

You'll need two things:

  1. A check that matches your attribute (e.g. a) with the value (ABC)
  2. A condition that checks the same attribute is not either of ABC123, ABC456, ABC789.

There are (at least) two ways you could do this:

  1. You could write a policy that checks the attribute starts with ABC and then have a rule that denies access if the value is one of the 3 forbidden ones or
  2. You could write a policy that checks the attribute starts with ABC and only returns permit if the the value is not one of the 3 forbidden ones.

ALFA Example

ALFA, the abbreviated language for AuthZ, is a lightweight syntax for XACML policies. (Source: , Wikipedia)

namespace com.axiomatics{
    attribute a{
        category = subjectCat
        id = "com.axiomatics.a"
        type = string
    }
    /**
     * This policy allows access if the string starts with ABC but is not ABC123, ABC456, or ABC789
     */
    policy example{
        apply firstApplicable
        /**
         * Deny specific values
         */
        rule denySpecificValues{
            target clause a == "ABC123" or a == "ABC456" or a == "ABC789"
            deny
        }
        /**
         * Allow if the string starts with ABC
         */
        rule startsWithABC{
            target clause stringStartsWith("ABC", a)
            permit
        }
    }
    /**
     * This policy allows access if the string starts with ABC but is not ABC123, ABC456, or ABC789
     */
    policy anotherExample{
        apply firstApplicable
        /**
         * Allow if the string with ABC
         */
        rule startsWithABC{
            target clause stringStartsWith("ABC", a)
            permit
            condition not (a == "ABC123") && not(a == "ABC456") || not(a == "ABC789")
        }
    }
}

XACML XML Equivalent

<?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/com.axiomatics.example"
    RuleCombiningAlgId="urn:oasis:names:tc:xacml:1.0:rule-combining-algorithm:first-applicable"
    Version="1.0">
    <xacml3:Description>This policy allows access if the string starts with
        ABC but is not ABC123, ABC456, or ABC789</xacml3:Description>
    <xacml3:PolicyDefaults>
        <xacml3:XPathVersion>http://www.w3.org/TR/1999/REC-xpath-19991116
        </xacml3:XPathVersion>
    </xacml3:PolicyDefaults>
    <xacml3:Target />
    <xacml3:Rule Effect="Deny"
        RuleId="com.axiomatics.example.denySpecificValues">
        <xacml3:Description>Deny specific values</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">ABC123</xacml3:AttributeValue>
                        <xacml3:AttributeDesignator
                            AttributeId="com.axiomatics.a"
                            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:AllOf>
                    <xacml3:Match
                        MatchId="urn:oasis:names:tc:xacml:1.0:function:string-equal">
                        <xacml3:AttributeValue
                            DataType="http://www.w3.org/2001/XMLSchema#string">ABC456</xacml3:AttributeValue>
                        <xacml3:AttributeDesignator
                            AttributeId="com.axiomatics.a"
                            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:AllOf>
                    <xacml3:Match
                        MatchId="urn:oasis:names:tc:xacml:1.0:function:string-equal">
                        <xacml3:AttributeValue
                            DataType="http://www.w3.org/2001/XMLSchema#string">ABC789</xacml3:AttributeValue>
                        <xacml3:AttributeDesignator
                            AttributeId="com.axiomatics.a"
                            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="com.axiomatics.example.startsWithABC">
        <xacml3:Description>Allow if the string starts with ABC
        </xacml3:Description>
        <xacml3:Target>
            <xacml3:AnyOf>
                <xacml3:AllOf>
                    <xacml3:Match
                        MatchId="urn:oasis:names:tc:xacml:3.0:function:string-starts-with">
                        <xacml3:AttributeValue
                            DataType="http://www.w3.org/2001/XMLSchema#string">ABC</xacml3:AttributeValue>
                        <xacml3:AttributeDesignator
                            AttributeId="com.axiomatics.a"
                            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>
David Brossard
  • 13,584
  • 6
  • 55
  • 88
  • 1
    Thanks for the reply. i have to add these in one rule and in Condition tag. I cannot have in check , since i check other values in Target. im looking to check this condition in Condition tag. Can i use starts-with and all-of-any? thanks again – Gooberq Gob Oct 21 '19 at 19:53
  • Or can i use a regular expression to check if bag of values starts with "abc" but not equal to abc123 and abc456 and abc789. Or i was thinking to remove the "abc123" , "abc456" and "abc789" from the bag of values and then check if any string starts with "abc" not sure how to do that. – Gooberq Gob Oct 21 '19 at 22:08