Contents
About
This proposal is to define declarative policy expressions in XDI so they can be used wherever policies need to be applied, e.g., in XDI link contract evaluation or XDI message evaluation.
Change Log
- 2014-03-27 - Dan Blum updated to accomplish the symbol shift
- 2013-04-23 - Drummond Reed: updated to revised XDI syntax.
2013-01-25 - Markus Sabadello - updated event-related examples to conform to XdiEvents
- 2013-01-04 - Markus Sabadello - expanded the proposal and added examples
2013-01-03 - Drummond Reed - archived previous outdated proposal at JavascriptPolicyExpression and refactored the policy expression syntax and dictionary per the declarative policy expression proposal (see the Discussion page).
Motivations/Requirements
- To have a standard interoperable semantics for expressing and evaluating policies in XDI, including:
- XDI link contract policies.
- XDI message policies.
To be able to interpret and evaluate policies in pure XDI, without the need for a scripting language such as JavaScript.
Use of Policy Expressions
In order to evaluate policy expressions, two elements are needed to set the evaluation context:
The XDI graph that is the target of an XDI message (called the object graph).
An XDI message that is meant to be be executed against the object graph (called the input message).
An XDI link contract policy is part of the object graph. It provides a way for an XDI endpoint to determine if the input message is authorized.
An XDI message policy is part of the input message. It provides a way for an XDI client to request execution of the input message only if certain conditions are met.
In both cases, the policy is evaluated by the XDI endpoint that hosts the target graph and receives the input message.
Policy Expression Pattern Rules
A policy MUST consist of one or more XDI statements in the following pattern: A link contract MUST consist of a set XDI statements in one of the two following patterns:
Policy Singleton Pattern
<--policy-context-->$do$if<--boolean-context-->/<--operator-->/<--condition-->
Policy Collection Pattern
<--policy-context-->[$do]<--instance-id-->$if<--boolean-context-->/<--operator-->/<--condition-->
Where:
<--policy-context--> is the context of the policy expression, e.g. an XDI link contract or an XDI message.
<--instance-id--> is an entity instance that serves as the unique immutable ID for a member of a link contract collection.
<--boolean-context--> is an optional hierarchy of subcontexts expressing the XDI boolean operators ($and, $or, $not) needed to produce a boolean logic tree for policy evaluation (see below).
<--operator--> is either a boolean operator ($true, $false), or an XDI operation being requested by a message (e.g., $get, $set, $del, $do<--extension-->).
<--condition--> is either a comparison condition ($is, $equals, matches, $greater, $lesser), or an arbitrary XDI statement.
Policy Expression Dictionary Rules
The following reserved words are proposed for policy expression.
$if
$if defines the root context node of a policy expression subgraph.
$if MUST be a child context of a $do context (the root context of an XDI link contract or the operation context of an XDI message).
$if MUST be an entity singleton.
$if MAY have zero or more boolean subcontexts.
$if MAY have zero or more operator predicates.
$if evaluates to true, if
- ANY of its boolean subcontexts evaluate to true, OR
- ANY of its operator predicates evaluate to true.
$if evaluates to false, if it has neither boolean subcontexts nor operator predicates.
<--boolean-context-->
$and
$and is the boolean context expressing logical conjunction.
$and MAY be an entity singleton for a single logical conjunction.
$and MUST be an entity collection if there are multiple logical conjunctions that must be evaluated independently.
$and MAY have zero or more boolean subcontexts.
$and MAY have zero or more operator predicates.
$and evaluates to true, if
- ALL of its boolean subcontexts evaluate to true, AND
- ALL of its operator predicates evaluate to true
$and evaluates to true, if it has neither boolean subcontexts nor operator predicates.
$or
$or is the boolean context defining logical disjunction.
$or MAY be an entity singleton for a single logical disjunction.
$or MUST be an entity collection if there are multiple logical disjunctions that must be evaluated independently.
$or MAY have zero or more boolean subcontexts.
$or MAY have zero or more operator predicates.
$or evaluates to true, if
- ANY of its boolean subcontexts evaluate to true, OR
- ANY of its operator predicates evaluate to true.
$or evaluates to false, if it has neither boolean subcontexts nor operator predicates.
$not
$not is the boolean context defining logical negation.
$not MAY be an entity singleton for a single logical negation.
$not MUST be an entity collection if there are multiple logical negations that must be evaluated independently.
$not MUST either have exactly one boolean subcontext, OR have exactly one operator predicate.
$not evaluates to true, if
- its single boolean subcontext evaluates to false, OR
- its single operator predicate evaluates to false.
<--operator-->
$true
$true is the boolean operator expressing that a condition statement MUST be true.
$true evaluates to true, if
- its condition evaluates to true.
$false
$false is the boolean operator expressing that a condition statement MUST be false.
$false evaluates to true, if
- its condition evaluates to false.
<--operation-->
If an operator is used that does not correspond to any of boolean operators ($true, $false), it is considered to be an XDI operation (e.g., $get, $set, $del, $do<--extension-->).
- The XDI operation evaluates to true, if
- it exists in the input message.
<--condition-->
{$from} Variable
{$from} is a global XDI variable representing the sender of the input message (see <--from--> in the XdiMessagePatterns proposal).
{$from} MUST be replaced by the XDI address of the sender of the input message before the condition is evaluated.
{$msg} Variable
{$msg} is a global XDI variable representing the global context of the input message (see <--from-->[$msg]!<--id--> in the XdiMessagePatterns proposal).
{$msg} MUST be replaced by the XDI address of the input message before the condition is evaluated.
$is
$is expresses that the subject and object nodes of the condition represent the same logical entity (see the EquivalenceLinks proposal).
$is evaluates to true, if
- the subject node and object node of the condition represent the same logical entity.
$equals
$equals expresses that the subject and object nodes of the condition have the same literal values.
$equals evaluates to true, if
- both the subject node and object node of the condition identify an XDI literal, AND
- the literal values are equivalent.
$matches
$matches expresses that the literal value of the subject node of the condition matches the regular expression specified in the literal value of the object node of the condition. [TODO: define which regular expression syntax to use]
$matches evaluates to true, if
- both the subject node and object node of the condition identify an XDI literal, AND
- the literal value of the subject node of the condition matches the regular expression specified in the literal value of the object node of the condition.
$greater
$greater expresses that the literal value of the subject node of the condition must be greater than the literal value of the object node of the condition.
$greater evaluates to true, if
- both the subject node and object node of the condition identify an XDI literal, AND
- both literal values are numerical, AND
- the numerical literal value of the subject node is greater than the numerical literal value of the object node.
$lesser
$lesser expresses that the literal value of the subject node of the condition must be lesser than the literal value of the object node of the condition.
$lesser evaluates to true, if
- both the subject node and object node of the condition identify an XDI literal, AND
- both literal values are numerical, AND
- the numerical literal value of the subject node is lesser than the numerical literal value of the object node.
<--statement-->
If a condition is used that does not correspond to any of comparison conditions ($is, $equals, $greater, $lesser), it is considered to be an arbitrary XDI statement.
- The XDI statement evaluates to true, if
- it exists in the target graph.
Examples
These examples are written in XDI Display Format. See JSON Serialization Rules for the over-the-wire format.
Link contract policy that checks that the secret token in the message matches the secret token in the graph:
$secret<$token>&/&/"s3cr3t"
$do$if/$true/({$msg}$secret<$token>/$equals/$secret<$token>)Link contract policy that checks that the message timestamp comes before a certain time:
$do$if/$true/({$msg}<$t>/$lesser/...$do#expiration<$t>)
$do#expiration<$t>&/&/"2012-12-12"Link contract policy that checks that the message comes from one of the approved senders:
$do$if/$true/({$from}/$is/[=]!2222)
$do$if/$true/({$from}/$is/[=]!3333)
$do$if/$true/({$from}/$is/[=]!4444)Link contract policy that excludes a certain sender:
$do$if/$false/({$from}/$is/[=]!1111)Link contract policy that excludes a certain sender (other way of doing it):
$do$if$not/$true/({$from}/$is/[=]!1111)Link contract for "root access" to an authority's own graph:
$secret<$token>&/&/"s3cr3t"
$do$if$and/$true/({$from}/$is/[=]!1111)
$do$if$and/$true/({$msg}$secret<$token>/$equals/$secret<$token>)
$do/$all/()Link contract for the "public branch" of an XDI graph:
$public$do/$get/$public
Link contract to allow Bob access to Alice's phone number:
=alice/$ref/[=]!1111
=bob/$ref/[=]!2222
[=]!1111$<#tel>&/&/"#1-123-567-8900"
$do$if/$true/({$from}/$is/[=]!2222)
$do/$get/[=]!1111<#tel>Link contract policy that checks that the message comes either from myself ([=]!1111) or from one of my friends:
$do$if$or/$true/([=]!1111/$is/{$from})
$do$if$or/$true/([=]!1111/#friend/{$from})Link contract that allows a $do$signal operation only on certain statements (with variables):
$do/$do$signal/[=]!1111[#channel]!23[#event]
$do$if$and/$do$signal/([=]!1111[#channel]!23[#event]{1}/#domain/#cloudos)
$do$if$and$or/$do$signal/([=]!1111[#channel]!23[#event]{1}/#type/#notification)
$do$if$and$or/$do$signal/([=]!1111[#channel]!23[#event]{1}/#type/#subscription)
$do$if$and$or/$do$signal/([=]!1111[#channel]!23[#event]{1}/#type/#deletion)Combination of the previous two examples:
[=]!1111/#friend/[=]!2222
$do/$do$signal/[=]!1111[#channel]!23[#event]
$do$if$and[$or]!2/$true/([=]!1111/$is/{$from})
$do$if$and[$or]!2/$true/([=]!1111/#friend/{$from})
$do$if$and/$do$signal/([=]!1111[#channel]!23[#event]{1}/#domain/#cloudos)
$do$if$and[$or]!1/$do$signal/([=]!1111[#channel]!23[#event]{1}/#type/#notification)
$do$if$and[$or]!1/$do$signal/([=]!1111[#channel]!23[#event]{1}/#type/#subscription)
$do$if$and[$or]!1/$do$signal/([=]!1111[#channel]!23[#event]{1}/#type/#deletion)Link contract policy that allows the message if it is not sent on Friday 13th, and it is not sent by =drummond or =markus. (Note that the weekday and day-of-month definitions still need to be defined in the XDI $ Dictionary.)
$do$if$and[$not]!1$and/$true/[weekday_is_friday]
$do$if$and[$not]!1$and/$true/[day_is_13th]
$do$if$and[$not]!2$or/$true/(=drummond/$is/{$from})
$do$if$and[$not]!2$or/$true/(=markus/$is/{$from})
XDI Wiki