Update Tutorial Documentation
[policy/parent.git] / docs / xacml / xacml.rst
1 .. This work is licensed under a Creative Commons Attribution 4.0 International License.
2
3 .. _xacml-label:
4
5 Policy XACML PDP Engine
6 #######################
7
8 .. toctree::
9    :maxdepth: 2
10
11 The ONAP XACML Policy PDP Engine uses an `open source implementation <https://github.com/att/XACML>`__ of the `OASIS XACML 3.0 Standard <https://www.oasis-open.org/committees/tc_home.php?wg_abbrev=xacml>`__ to support fine-grained policy decisions in the ONAP. The XACML 3.0 Standard is a language for both policies and requests/responses for access control decisions. The ONAP XACML PDP translates TOSCA Compliant Policies into the XACML policy language, loads the policies into the XACML engine and exposes a Decision API which uses the XACML request/response language to render decisions for ONAP components.
12
13 ONAP XACML PDP Supported Policy Types
14 *************************************
15
16 The following Policy Types are supported by the XACML PDP Engine (PDP-X):
17
18 .. csv-table:: Supported Base Policy Types
19     :header: "Application", "Base Policy Type", "Action", "Description"
20
21     "Monitoring", "onap.policies.Monitoring", "configure", "Control Loop DCAE Monitoring Policies"
22     "Guard", "onap.policies.controlloop.guard.Common", "guard", "Control Loop Guard and Coordination Policies"
23     "Optimization", "onap.policies.Optimization", "optimize", "Optimization policy types used by OOF"
24     "Naming", "onap.policies.Naming", "naming", "Naming policy types used by SDNC"
25     "Native", "onap.policies.native.Xacml", "native", "Native XACML Policies"
26     "Match", "onap.policies.Match", "native", "Matchable Policy Types for the ONAP community to use"
27
28 Each Policy Type is implemented as an application that extends the **XacmlApplicationServiceProvider**, and provides a **ToscaPolicyTranslator** that translates the TOSCA representation of the policy into a XACML OASIS 3.0 standard policy.
29
30 By cloning the policy/xacml-pdp repository, a developer can run the JUnit tests for the applications to get a better understanding on how applications are built using translators and the XACML Policies that are generated for each Policy Type. Each application supports one or more Policy Types and an associated "action" used by the Decision API when making these calls.
31
32 See the :ref:`policy-development-tools-label` for more information on cloning and developing the policy repositories.
33
34 XACML-PDP applications are located in the 'applications' sub-module in the policy/xacml-pdp repo. `Click here to view the applications sub-modules <https://github.com/onap/policy-xacml-pdp/tree/master/applications>`_
35
36 XACML PDP TOSCA Translators
37 ===========================
38
39 The following common translators are available in ONAP for use by developers. Each is used or extended by the standard PDP-X applications in ONAP.
40
41 StdCombinedPolicyResultsTranslator Translator
42 ---------------------------------------------
43 A simple translator that wraps the TOSCA policy into a XACML policy and performs matching of the policy based on either policy-id and/or policy-type. The use of this translator is discouraged as it behaves like a database call and does not take advantage of the fine-grain decision making features described by the XACML OASIS 3.0 standard. It is used to support backward compatibility of legacy "configure" policies.
44
45 `Implementation of Combined Results Translator <https://github.com/onap/policy-xacml-pdp/blob/master/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdCombinedPolicyResultsTranslator.java>`_.
46
47 The Monitoring and Naming applications use this translator.
48
49 .. _xacml-matchable-label:
50
51 StdMatchableTranslator Translator
52 ---------------------------------
53 More robust translator that searches metadata of TOSCA properties for a **matchable** field set to **true**. The translator then uses those "matchable" properties to translate a policy into a XACML OASIS 3.0 policy which allows for fine-grained decision making such that ONAP applications can retrieve the appropriate policy(s) to be enforced during runtime.
54
55 Each of the properties designated as "matchable" are treated relative to each other as an "AND" during a Decision request call. In addition, each value of a "matchable property that is an array, is treated as an "OR". The more properties specified in a decision request, the more fine-grained a policy will be returned. In addition, the use of "policy-type" can be used in a decision request to further filter the decision results to a specific type of policy.
56
57 `Implementation of Matchable Translator <https://github.com/onap/policy-xacml-pdp/blob/master/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdMatchableTranslator.java>`_.
58
59 The Optimization application uses this translator.
60
61 GuardTranslator and CoordinationGuardTranslator
62 -----------------------------------------------
63 These two translators are used by the Guard application and are very specific to those Policy Types. They are good examples on how to build your own translator for a very specific implementation of a policy type. This can be the case if any of the Std* translators are not appropriate to use directly or override for your application.
64
65 `Implementation of Guard Translator <https://github.com/onap/policy-xacml-pdp/blob/master/applications/guard/src/main/java/org/onap/policy/xacml/pdp/application/guard/GuardTranslator.java>`_
66
67 `Implementation of Coordination Translator <https://github.com/onap/policy-xacml-pdp/blob/master/applications/guard/src/main/java/org/onap/policy/xacml/pdp/application/guard/CoordinationGuardTranslator.java>`_
68
69 Native XACML OAISIS 3.0 XML Policy Translator
70 -----------------------------------------------
71
72 This translator pulls a URL encoded XML XACML policy from a TOSCA Policy and loads it into a XACML Engine. This allows native XACML policies to be used to support complex use cases in which a translation from TOSCA to XACML is too difficult.
73
74 `Implementation of Native Policy Translator <https://github.com/onap/policy-xacml-pdp/tree/master/applications/native/src/main/java/org/onap/policy/xacml/pdp/application/nativ>`_
75
76 Monitoring Policy Types
77 =======================
78 These Policy Types are used by Control Loop DCAE microservice components to support monitoring of VNF/PNF entities to support an implementation of a Control Loops. The DCAE Platform makes a call to Decision API to request the contents of these policies. The implementation involves creating an overarching XACML Policy that contains the TOSCA policy as a payload that is returned to the DCAE Platform.
79
80 The following policy types derive from onap.policies.Monitoring:
81
82 .. csv-table::
83    :header: "Derived Policy Type", "Action", "Description"
84
85    "onap.policies.monitoring.tcagen2", "configure", "TCA DCAE microservice gen2 component"
86    "onap.policies.monitoring.dcaegen2.collectors.datafile.datafile-app-server", "configure", "REST Collector"
87    "onap.policies.monitoring.docker.sonhandler.app", "configure", "SON Handler microservice component"
88
89 .. note::
90    DCAE project deprecated TCA DCAE microservice in lieu for their gen2 microservice. Thus, the policy type onap.policies.monitoring.cdap.tca.hi.lo.app was removed from Policy Framework.
91
92 This is an example Decision API payload made to retrieve a decision for a Monitoring Policy by id. Not recommended - as users may change id's of a policy. Available for backward compatibility.
93
94 .. literalinclude:: decision.monitoring.json
95   :language: JSON
96
97 This is an example Decision API payload made to retrieve a decision for all deployed Monitoring Policies for a specific type of Monitoring policy.
98
99 .. literalinclude:: decision.monitoring.type.json
100   :language: JSON
101
102 Guard and Control Loop Coordination Policy Types
103 ================================================
104 These Policy Types are used by Control Loop Drools Engine to support guarding control loop operations and coordination of Control Loops during runtime control loop execution.
105
106 .. csv-table::
107    :header: "Policy Type", "Action", "Description"
108
109    "onap.policies.controlloop.guard.common.FrequencyLimiter", "guard", "Limits frequency of actions over a specified time period"
110    "onap.policies.controlloop.guard.common.Blacklist", "guard", "Blacklists a regexp of VNF IDs"
111    "onap.policies.controlloop.guard.common.MinMax", "guard", "For scaling, enforces a min/max number of VNFS"
112    "onap.policies.controlloop.guard.common.Filter", "guard", "Used for filtering entities in A&AI from Control Loop actions"
113    "onap.policies.controlloop.guard.coordination.FirstBlocksSecond", "guard", "Gives priority to one control loop vs another"
114
115 This is an example Decision API payload made to retrieve a decision for a Guard Policy Type.
116
117 .. literalinclude:: decision.guard.json
118   :language: JSON
119
120 The return decision simply has "permit" or "deny" in the response to tell the calling application whether they are allowed to perform the operation.
121
122 .. literalinclude:: decision.guard.response.json
123   :language: JSON
124
125 Guard Common Base Policy Type
126 -----------------------------
127 Each guard Policy Type derives from **onap.policies.controlloop.guard.Common** base policy type. Thus, they share a set of common
128 properties.
129
130 .. csv-table:: Common Properties for all Guards
131    :header: "Property", "Examples", "Required", "Type", "Description"
132
133    "actor", "APPC, SO", "Required", "String", "Identifies the actor involved in the Control Loop operation."
134    "operation", "Restart, VF Module Create", "Required", "String", "Identifies the Control Loop operation the actor must perform."
135    "timeRange", "start_time: T00:00:00Z end_time: T08:00:00Z", "Optional", "tosca.datatypes.TimeInterval", "A given time range the guard is in effect. Following the TOSCA specification the format should be ISO 8601 format "
136    "id", "control-loop-id", "Optional", "String", "A specific Control Loop id the guard is in effect."
137
138 `Common Guard Policy Type <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policytypes/onap.policies.controlloop.guard.Common.yaml>`__
139
140 Frequency Limiter Guard Policy Type
141 -----------------------------------
142 The Frequency Limiter Guard is used to specify limits as to how many operations can occur over a given time period.
143
144 .. csv-table:: Frequency Guard Properties
145    :header: "Property", "Examples", "Required", "Type", "Description"
146
147    "timeWindow", "10, 60", "Required", "integer", "The time window to count the actions against."
148    "timeUnits", "second minute, hour, day, week, month, year", "Required", "String", "The units of time the window is counting"
149    "limit", "5", "Required", "integer", "The limit value to be checked against."
150
151 .. literalinclude:: example.guard.limiter.yaml
152   :language: YAML
153
154 `Frequency Limiter Guard Policy Type <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policytypes/onap.policies.controlloop.guard.common.FrequencyLimiter.yaml>`__
155
156 Min/Max Guard Policy Type
157 -------------------------
158 The Min/Max Guard is used to specify a minimum or maximum number of instantiated entities in A&AI. Typically this is a VFModule for Scaling operations. One should specify either a min or a max value, or **both** a min and max value. At least one must be specified.
159
160 .. csv-table:: Min/Max Guard Properties
161    :header: "Property", "Examples", "Required", "Type", "Description"
162
163    "target", "e6130d03-56f1-4b0a-9a1d-e1b2ebc30e0e", "Required", "String", "The target entity that has scaling restricted."
164    "min", "1", "Optional", "integer", "Minimum value. Optional only if max is not specified."
165    "max", "5", "Optional", "integer", "Maximum value. Optional only if min is not specified."
166
167 .. literalinclude:: example.guard.minmax.yaml
168   :language: YAML
169
170 `Min/Max Guard Policy Type <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policytypes/onap.policies.controlloop.guard.common.MinMax.yaml>`__
171
172 Blacklist Guard Policy Type
173 ---------------------------
174 The Blacklist Guard is used to specify a list of A&AI entities that are blacklisted from having an operation performed on them. Recommendation is to use the vnf-id for the A&AI entity.
175
176 .. csv-table:: Blacklist Guard Properties
177    :header: "Property", "Examples", "Required", "Type", "Description"
178
179    "blacklist", "e6130d03-56f1-4b0a-9a1d-e1b2ebc30e0e", "Required", "list of string", "List of target entity's that are blacklisted from an operation."
180
181 .. literalinclude:: example.guard.blacklist.yaml
182   :language: YAML
183
184 `Blacklist Guard Policy Type <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policytypes/onap.policies.controlloop.guard.common.Blacklist.yaml>`__
185
186 Filter Guard Policy Type
187 ------------------------
188 The Filter Guard is a more robust guard for blacklisting and whitelisting A&AI entities when performing control loop operations. The intent for this guard is to filter in or out a block of entities, while allowing the ability to filter in or out specific entities. This allows a DevOps team to control the introduction of a Control Loop for a region or specific VNF's, as well as block specific VNF's that are being negatively affected when poor network conditions arise. Care and testing should be taken to understand the ramifications when combining multiple filters as well as their use in conjunction with other Guard Policy Types.
189
190 .. csv-table:: Filter Guard Properties
191    :header: "Property", "Examples", "Required", "Type", "Description"
192
193    "algorithm", "blacklist-overrides", "Required", "What algorithm to be applied", "blacklist-overrides or whitelist-overrides are the valid values. Indicates whether blacklisting or whitelisting has precedence."
194    "filters", "see table below", "Required", "list of onap.datatypes.guard.filter", "List of datatypes that describe the filter."
195
196 .. csv-table:: Filter Guard onap.datatypes.guard.filter Properties
197    :header: "Property", "Examples", "Required", "Type", "Description"
198
199    "field", "generic-vnf.vnf-name", "Required", "String", "Field used to perform filter on and must be a string value. See the Policy Type below for valid values."
200    "filter", "vnf-id-1", "Required", "String", "The filter being applied."
201    "function", "string-equal", "Required", "String", "The function that is applied to the filter. See the Policy Type below for valid values."
202    "blacklist", "true", "Required", "boolean", "Whether the result of the filter function applied to the filter is blacklisted or whitelisted (eg Deny or Permit)."
203
204 .. literalinclude:: example.guard.filter.yaml
205   :language: YAML
206
207 `Filter Guard Policy Type <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policytypes/onap.policies.controlloop.guard.common.Filter.yaml>`__
208
209 .. _xacml-optimization-label:
210
211 Optimization Policy Types
212 =========================
213 These Policy Types are designed to be used by the OOF Project support several domains including VNF placement in ONAP.
214 The OOF Platform makes a call to the Decision API to request these Policies based on the values specified in the
215 onap.policies.Optimization properties. Each of these properties are treated relative to each other as an "AND". In
216 addition, each value for each property itself is treated as an "OR".
217
218 .. csv-table::
219    :header: "Policy Type", "Action"
220
221    "onap.policies.Optimization", "optimize"
222    "onap.policies.optimization.Service", "optimize"
223    "onap.policies.optimization.Resource", "optimize"
224    "onap.policies.optimization.resource.AffinityPolicy", "optimize"
225    "onap.policies.optimization.resource.DistancePolicy", "optimize"
226    "onap.policies.optimization.resource.HpaPolicy", "optimize"
227    "onap.policies.optimization.resource.OptimizationPolicy", "optimize"
228    "onap.policies.optimization.resource.PciPolicy", "optimize"
229    "onap.policies.optimization.service.QueryPolicy", "optimize"
230    "onap.policies.optimization.service.SubscriberPolicy", "optimize"
231    "onap.policies.optimization.resource.Vim_fit", "optimize"
232    "onap.policies.optimization.resource.VnfPolicy", "optimize"
233
234 The optimization application extends the StdMatchablePolicyTranslator in that the application applies a "closest match"
235 algorithm internally after a XACML decision. This filters the results of the decision to return the one or more policies
236 that match the incoming decision request as close as possible. In addition, there is special consideration for the
237 Subscriber Policy Type. If a decision request contains subscriber context attributes, then internally the application
238 will apply an initial decision to retrieve the scope of the subscriber. The resulting scope attributes are then added
239 into a final internal decision call.
240
241 This is an example Decision API payload made to retrieve a decision for an Optimization Policy Type.
242
243 .. literalinclude:: decision.affinity.json
244   :language: JSON
245
246 Native XACML Policy Type
247 ========================
248
249 This Policy type is used by any client or ONAP component who has the need of native XACML evaluation. A native XACML policy or policy set encoded in XML can be created off this policy type and loaded into the XACML PDP engine by invoking the PAP policy deployment API. Native XACML requests encoded in either JSON or XML can be sent to the XACML PDP engine for evaluation by invoking the native decision API. Native XACML responses will be returned upon evaluating the requests against the matching XACML policies. Those native XACML policies, policy sets, requests and responses all follow the `OASIS XACML 3.0 Standard <https://www.oasis-open.org/committees/tc_home.php?wg_abbrev=xacml>`__.
250
251 .. csv-table::
252    :header: "Policy Type", "Action", "Description"
253
254    "onap.policies.native.Xacml", "native", "any client or ONAP component"
255
256 According to the XACML 3.0 specification, two content-types are supported and used to present the native requests/responses. They are formally defined as "application/xacml+json" and "application/xacml+xml".
257
258 This is an example Native Decision API payload made to retrieve a decision for whether Julius Hibbert can read http://medico.com/record/patient/BartSimpson.
259
260 .. literalinclude:: decision.native.json
261   :language: JSON
262
263 Match Policy Type
264 =================
265
266 This Policy type can be used to design your own Policy Type and utilize the :ref:`StdMatchableTranslator <xacml-matchable-label>`, and does not need to build your own custom application. You can design your Policy Type by inheriting from the Match policy type (eg. onap.policies.match.<YourPolicyType>) and adding a **matchable** metadata set to **true** for the properties that you would like to request a Decision on. All a user would need to do is then use the Policy Lifecycle API to add their Policy Type and then create policies from it. Then deploy those policies to the XACML PDP and they would be able to get Decisions without customizing their ONAP installation.
267
268 Here is an example Policy Type:
269
270 .. literalinclude:: match.policy-type.yaml
271   :language: YAML
272
273 Here are example Policies:
274
275 .. literalinclude:: match.policies.yaml
276   :language: YAML
277
278 This is an example Decision API request that can be made:
279
280 .. literalinclude:: decision.match.request.json
281   :language: JSON
282
283 Which would render the following decision response:
284
285 .. literalinclude:: decision.match.response.json
286   :language: JSON
287
288 Supporting Your Own Policy Types and Translators
289 ************************************************
290
291 In order to support your own custom Policy Type that the XACML PDP Engine can support, one needs to build a Java service application that extends the **XacmlApplicationServiceProvider** interface and implement a **ToscaPolicyTranslator** application. Your application should register itself as a Java service application and expose it in the classpath used to be loaded into the ONAP XACML PDP Engine. Ensure you define and create the TOSCA Policy Type according to these :ref:`Policy Design and Development <design-label>`. You should be able to load your custom Policy Type using the :ref:`Policy Lifecycle API <api-label>`. Once successful, you should be able to start creating policies from your custom Policy Type.
292
293 XacmlApplicationServiceProvider
294 ===============================
295
296 `Interface for XacmlApplicationServiceProvider <https://github.com/onap/policy-xacml-pdp/blob/master/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/XacmlApplicationServiceProvider.java>`_
297
298 See each of the ONAP Policy Type application implementations which re-use the **StdXacmlApplicationServiceProvider** class. This implementation can be used as a basis for your own custom applications.
299
300 `Standard Application Service Provider implementation <https://github.com/onap/policy-xacml-pdp/blob/master/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdXacmlApplicationServiceProvider.java>`_
301
302 ToscaPolicyTranslator
303 =====================
304
305 Your custom **XacmlApplicationServiceProvider** must provide an implementation of a *ToscaPolicyTranslator*.
306
307 `Interface for ToscaPolicyTranslator <https://github.com/onap/policy-xacml-pdp/blob/master/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/ToscaPolicyTranslator.java>`_
308
309 See each of the ONAP Policy type application implementations which each have their own *ToscaPolicyTranslator*. Most use or extend the **StdBaseTranslator**.
310
311 `Standard Tosca Policy Translator implementation <https://github.com/onap/policy-xacml-pdp/blob/master/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdBaseTranslator.java>`.
312
313 XACML Application and Enforcement Tutorials
314 ===========================================
315
316 The following tutorials can be helpful to get started on building your own decision application as well as building enforcement into your application.
317
318 .. toctree::
319    :maxdepth: 1
320
321    xacml-tutorial
322    xacml-tutorial-enforcement
323