{{announcement.body}}
{{announcement.title}}

A Basic Introduction to XACML

DZone 's Guide to

A Basic Introduction to XACML

XACML is an XML-based language for access control which is popular as a fine grain authorization method among the community.

· Security Zone ·
Free Resource

What Is XACML?

XACML (eXtensible Access Control Markup Language) is an XML-based language for access control that has been standardized by the Technical Committee of the OASIS consortium. XACML is popular as a fine grain authorization method among the community. XACML describes both an access control policy language, request/response language and reference architecture. The policy language is used to express access control policies (who can do what when). The request/response language expresses queries about whether a particular access should be allowed (requests) and describes answers to those queries(responses). The reference architecture proposes a standard for deployment of necessary software modules within an infrastructure to allow efficient enforcement of policies.

XACML supports Attribute-Based Access Control (ABAC) and evaluation can be done with the additional data retrieved from Policy Information Point (PIP) which is defined by the XACML reference architecture.

ABAC is an access control paradigm whereby access rights are granted to users through the use of policies that combine attributes together. The policies can use any type of attributes (user attributes, resource attributes, object, environment attributes, etc.). This model supports Boolean logic, in which rules contain “IF, THEN” statements about who is making the request, the resource, and the action.
For example: IF the requestor is a manager, THEN allow read/write access to sensitive data.

XACML Architecture



0
 Advanced issue found

 

XACML Architecture
XACML Architecture

Policy Decision Point (PDP) evaluates policies against access requests provided by Policy Enforcement Points (PEP). To provide the decisions, PDP may also need to query a Policy Information Point (PIP) to gather descriptive attributes about the user or any other missing attribute in the request. Policy Administration Point (PAP) is used to manage the PDP and PIP functionality.

XACML Policy Language Structure and Syntax

Three Top-Level Policy Elements

  • <Rule>: contains a Boolean expression that can be evaluated in isolation, but that is not intended to be accessed in isolation by a PDP. So, it is not intended to form the basis of an authorization decision by itself. It is intended to exist in isolation only within an XACML PAP, where it may form the basic unit of management
  • <Policy>: contains a set of <Rule> elements and a specified procedure for combining the results of their evaluation. It is the basic unit of the policy used by the PDP, and so it is intended to form the basis of an authorization decision
  • <PolicySet>: contains a set of <Policy> or other <PolicySet> elements and a specified procedure for combining the results of their evaluation.

Policy Set

Top-level Policy elements




0
 Advanced issue found


The diagram below shows the XACML policy model.


0
 Advanced issue found

 
XACML Policy Model
XACML Policy Model

Let’s take a closer look at each of these components.

Target

An XACML <PolicySet>, <Policy> or <Rule> element contains a <Target> element that specifies the set of requests to which it applies.

An empty <Target> matches any request. Otherwise, target value is “Match” if all the specified “AnyOf”s are matched in the request. Following tables show how the target evaluation is done based on <AnyOf>,<AllOf> and <Match>.



0
 Advanced issue found


Target Evaluation
Target Evaluation

Example:

If the target should be matched,

  • If the conditionA and conditionB is matched,
XML
 




x


 
1
<Target>
2
   <AnyOf>
3
      <AllOf>
4
         <Match>conditionA</Match>
5
         <Match>conditionB</Match>
6
      </AllOf>
7
   </AnyOf>
8
</Target>



  • if the conditionA or conditionB is matched,
XML
 




xxxxxxxxxx
1
10


 
1
<Target>
2
   <AnyOf>
3
      <AllOf>
4
         <Match>conditionA</Match>
5
      </AllOf>
6
      <AllOf>
7
         <Match>conditionB</Match>
8
      </AllOf>
9
   </AnyOf>
10
</Target>



Sample:

XML
 




xxxxxxxxxx
1
14


 
1
<Target>
2
      <AnyOf>
3
         <AllOf>
4
            <Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-equal">
5
               <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">Pamoda</AttributeValue>
6
               <AttributeDesignator AttributeId="urn:oasis:names:tc:xacml:1.0:subject:subject-id" Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject" DataType="http://www.w3.org/2001/XMLSchema#string" MustBePresent="true"/>
7
            </Match>
8
            <Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-equal">
9
               <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">GET</AttributeValue>
10
               <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"/>
11
            </Match>
12
         </AllOf>
13
      </AnyOf>
14
   </Target>



In the above Target definition, the target will validate whether the subject of the request is “Pamoda” and the action is “GET”

Rule-Combining Algorithms

The rule-combining algorithm specifies the procedure by which the results of evaluating the component rules are combined when evaluating the policy.

Some examples of standard combining algorithms are :

  • Deny-overrides (urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:deny-overrides)
    — If any decision is “Deny”, the result is “Deny”.
  • Permit-overrides (urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:permit-overrides)
    — If any decision is “Permit”, the result is “Permit”.
  • First-applicable (urn:oasis:names:tc:xacml:1.0:rule-combining-algorithm:first-applicable)
    — Each rule is evaluated in the order in which it is listed in the policy. For a particular rule, if the target matches and the condition evaluates to Permit, Deny, or Indeterminate corresponding effect of the rule SHALL be the result of the evaluation of the policy. Otherwise, return to the next rule.

Rule

A rule is the most elementary unit of policy. The heart of most of the rules is a Condition, which is a boolean function. If the condition evaluates to true, then the Rule’s Effect is returned. A Condition can be quite complex, built from an arbitrary nesting of non-boolean functions and attributes. The following table shows how the final effect of the rule is decided.

Rule Evaluation

Rule Evaluation




0
 Advanced issue found

 

Attributes, Attribute Values, and Functions

As XACML is used in Attribute-Based Access Controlling, in XACML all the attributes are categorized into four main categories. But from XACML 3.0, custom categories are also supported.

  • Subject (urn:oasis:names:tc:xacml:3.0:attribute-category:subject)
  • Resource (urn:oasis:names:tc:xacml:3.0:attribute-category:resource)
  • Action (urn:oasis:names:tc:xacml:3.0:attribute-category:action)
  • Environment (urn:oasis:names:tc:xacml:3.0:attribute-category:environment)

A Policy resolves attribute values from the request or retrieves values from the PIP.

<AttributeDesignator>: lets the policy specify an attribute with a given name and type, and optionally an issuer as well. <AttributeDesignator> can return multiple values. XACML provides a special attribute type called a “Bag”.

<AttributeValue>: contains a literal attribute value

XACML comes with a powerful system of functions. Functions can work on any combination of attribute values and can return any kind of attribute value supported in the system. Functions can also be nested, so we can have functions that consume the output of other functions, and this hierarchy can be arbitrarily complex.

<Apply>: denotes the application of a function to its arguments, thus encoding a function call.

�� NOTE: The XACML functions may consume different types and different numbers of attributes as inputs depending on the function definition. Some of the functions may consume a bag of attributes while some require a single attribute. Therefore before using the functions, we need to study the behavior.

Let’s take consider an example rule, where the request is permitted if only the request is performed by a user named “Pamoda”.

XML
 




xxxxxxxxxx
1
10


 
1
<Rule Effect="Permit" RuleId="rule1">
2
      <Condition>
3
         <Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-equal">
4
            <Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-one-and-only">
5
               <AttributeDesignator AttributeId="urn:oasis:names:tc:xacml:1.0:subject:subject-id" Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject" DataType="http://www.w3.org/2001/XMLSchema#string" MustBePresent="true"/>
6
            </Apply>
7
            <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">Pamoda</AttributeValue>
8
         </Apply>
9
      </Condition>
10
   </Rule>



In the sample rule,

  • If the condition given in the rule is successfully validated, the effect will be “Permit”
  • The function “urn:oasis:names:tc:xacml:1.0:function:string-equal” is used for the comparison. This function takes two arguments of type “http://www.w3.org/2001/XMLSchema#string”
  • <AttributeDesignator> selects a bag of type “http://www.w3.org/2001/XMLSchema#string
  • The function “urn:oasis:names:tc:xacml:1.0:function:string-one-and-only” guarantees that its argument evaluates to a bag containing exactly one value.
  • <AttributeValue> defines the second attribute for the comparison.

Obligation and Advice Expressions

A rule, policy, or policy set may contain one or more obligation or advice expressions. When such a rule, policy, or policy set is evaluated, the obligation or advice expression will be evaluated to an obligation or advice respectively, which is passed up to the next level of evaluation only if the result of the rule, policy, or policy set being evaluated matches the value of the FulfillOn attribute of the obligation or the AppliesTo attribute of the advice.

Advice is similar to obligation and it shares much of its syntax. The difference is contractual: the PEP can disregard any advice it receives. PEPs do not have to comply with advice statements; PEPs can consider or discard the statement.

Example for Obligation:

XML
 




xxxxxxxxxx
1


 
1
<ObligationExpressions>
2
  <ObligationExpression FulfillOn="Permit" ObligationId="email_obligation">
3
    <AttributeAssignmentExpression AttributeId="email">
4
       <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string"></AttributeValue>
5
    </AttributeAssignmentExpression>
6
  </ObligationExpression>
7
</ObligationExpressions>



Response after evaluating the policy with the above obligation.

XML
 




xxxxxxxxxx
1
14


 
1
<Response xmlns="urn:oasis:names:tc:xacml:3.0:core:schema:wd-17">
2
  <Result>
3
    <Decision>Permit</Decision>
4
    <Status>
5
      <StatusCode Value="urn:oasis:names:tc:xacml:1.0:status:ok"/>
6
    </Status>
7
    <Obligations>
8
       <Obligation ObligationId="email_obligation">
9
         <AttributeAssignment AttributeId="email" DataType="http://www.w3.org/2001/XMLSchema#string">
10
</AttributeAssignment>
11
       </Obligation>
12
    </Obligations>
13
  </Result>
14
</Response>



In the above Obligation expression,

  • the obligation will be added to the response when only the decision is “Permit”
  • The obligation value, “pamodaaw@gmail.com” is added to the response as defined in the policy.

Example for Advice Expression

XML
 




xxxxxxxxxx
1


 
1
<AdviceExpressions>
2
      <AdviceExpression AdviceId="email_advice" AppliesTo="Permit">
3
         <AttributeAssignmentExpression AttributeId="email">
4
            <AttributeDesignator AttributeId="http://wso2.org/claims/emailaddress" Category="urn:oasis:names:tc:xacml:3.0:subject-category:access-subject"
5
DataType="http://www.w3.org/2001/XMLSchema#string" MustBePresent="true">
6
            </AttributeDesignator>
7
         </AttributeAssignmentExpression>
8
      </AdviceExpression>
9
   </AdviceExpressions>



Response after evaluating the policy with the above obligation.

XML
 




xxxxxxxxxx
1
14


 
1
<Response xmlns="urn:oasis:names:tc:xacml:3.0:core:schema:wd-17">
2
  <Result>
3
    <Decision>Permit</Decision>
4
    <Status>
5
      <StatusCode Value="urn:oasis:names:tc:xacml:1.0:status:ok"/>
6
    </Status>
7
    <AssociatedAdvice>
8
      <Advice AdviceId="email_advice" >
9
         <AttributeAssignment  AttributeId="email" DataType="http://www.w3.org/2001/XMLSchema#string">
10
</AttributeAssignment>
11
      </Advice>
12
    </AssociatedAdvice>
13
  </Result>
14
</Response>



In the above Advice expression,

  • the advice will be added to the response when only the decision is “Permit”
  • In contrast to the obligation definition, here I have taken the advice return value from the user’s email claim. So that we can get dynamic values based on the user.

Putting It Together: An Example Policy

Please note that I have used the WSO2 Identity Server for trying out the XACML Policies.

Policy definition:

  • <Target>: policy is applied only if subject=“pamoda” and action=“GET”
  • <Rule>: Permits if the subject-id is equal “Pamoda”
  • <Obligation>: Returns the value “pamodaaw@gmail.com” if the rule is Permit
  • <Advice>: Returns the value of the user claim, “http://wso2.org/claims/emailaddress” if the rule is Permit.

  • XML
     




    xxxxxxxxxx
    1
    41


     
    1
    <Policy xmlns="urn:oasis:names:tc:xacml:3.0:core:schema:wd-17"  PolicyId="sample_policy_8" RuleCombiningAlgId="urn:oasis:names:tc:xacml:1.0:rule-combining-algorithm:first-applicable" Version="1.0">
    2
       <Target>
    3
          <AnyOf>
    4
             <AllOf>
    5
                <Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-equal">
    6
                   <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">pamoda</AttributeValue>
    7
                   <AttributeDesignator AttributeId="urn:oasis:names:tc:xacml:1.0:subject:subject-id" Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject" DataType="http://www.w3.org/2001/XMLSchema#string" MustBePresent="true"></AttributeDesignator>
    8
                </Match>
    9
                <Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-equal">
    10
                   <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">GET</AttributeValue>
    11
                   <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"></AttributeDesignator>
    12
                </Match>
    13
             </AllOf>
    14
          </AnyOf>
    15
       </Target>
    16
       <Rule Effect="Permit" RuleId="rule1">
    17
          <Condition>
    18
             <Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-equal">
    19
                <Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-one-and-only">
    20
                   <AttributeDesignator AttributeId="urn:oasis:names:tc:xacml:1.0:subject:subject-id" Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject" DataType="http://www.w3.org/2001/XMLSchema#string" MustBePresent="true"></AttributeDesignator>
    21
                </Apply>
    22
                <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">pamoda</AttributeValue>
    23
             </Apply>
    24
          </Condition>
    25
       </Rule>
    26
       <Rule Effect="Deny" RuleId="8b52dcce-cd23-44f0-a223-f80ca6cc1a05"></Rule>
    27
       <ObligationExpressions>
    28
          <ObligationExpression FulfillOn="Permit" ObligationId="email">
    29
             <AttributeAssignmentExpression AttributeId="email">
    30
                <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">pamodaaw@gmail.com</AttributeValue>
    31
             </AttributeAssignmentExpression>
    32
          </ObligationExpression>
    33
       </ObligationExpressions>
    34
       <AdviceExpressions>
    35
          <AdviceExpression AdviceId="email_advice" AppliesTo="Permit">
    36
             <AttributeAssignmentExpression AttributeId="email">
    37
                <AttributeDesignator AttributeId="http://wso2.org/claims/emailaddress" Category="urn:oasis:names:tc:xacml:3.0:subject-category:access-subject" DataType="http://www.w3.org/2001/XMLSchema#string" MustBePresent="true"></AttributeDesignator>
    38
             </AttributeAssignmentExpression>
    39
          </AdviceExpression>
    40
       </AdviceExpressions>
    41
    </Policy>      



Sample Request

XML
 




xxxxxxxxxx
1
13


 
1
<Request xmlns="urn:oasis:names:tc:xacml:3.0:core:schema:wd-17" CombinedDecision="false" ReturnPolicyIdList="false">
2
  <Attributes Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject">
3
    <Attribute AttributeId="urn:oasis:names:tc:xacml:1.0:subject:subject-id" IncludeInResult="false">
4
      <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">pamoda</AttributeValue>
5
    </Attribute>
6
  </Attributes>
7
  <Attributes Category="urn:oasis:names:tc:xacml:3.0:attribute-category:action">
8
    <Attribute AttributeId="urn:oasis:names:tc:xacml:1.0:action:action-id" IncludeInResult="false">
9
      <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">GET</AttributeValue>
10
    </Attribute>
11
  </Attributes>
12
</Request> 
13
              



Sample Response

XML
 




xxxxxxxxxx
1
18


1
<Response xmlns="urn:oasis:names:tc:xacml:3.0:core:schema:wd-17">
2
  <Result>
3
    <Decision>Permit</Decision>
4
    <Status>
5
      <StatusCode Value="urn:oasis:names:tc:xacml:1.0:status:ok"/>
6
    </Status>
7
    <Obligations>
8
      <Obligation ObligationId="email">
9
        <AttributeAssignment  AttributeId="email" DataType="http://www.w3.org/2001/XMLSchema#string">pamodaaw@gmail.com</AttributeAssignment>
10
      </Obligation>
11
    </Obligations>
12
    <AssociatedAdvice>
13
      <Advice AdviceId="email_advice" >
14
        <AttributeAssignment  AttributeId="email" DataType="http://www.w3.org/2001/XMLSchema#string">pamoda@wso2.com</AttributeAssignment>
15
      </Advice>
16
    </AssociatedAdvice>
17
  </Result>
18
</Response>



I hope that you could learn something from this post. If you have any concerns, please add a comment.

Happy reading!

Topics:
attributes, authorization, policies, security, wso2, wso2 identity server, xacml

Published at DZone with permission of Pamoda Wimalasiri . See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}