1fcbed213a7a0255ca652fe4a2ec2545afe5c68e
[policy/engine.git] / docs / platform / guardpolicy.rst
1 .. This work is licensed under a Creative Commons Attribution 4.0 International License.
2 .. http://creativecommons.org/licenses/by/4.0
3
4 *********************************
5 Creating and Using Guard Policies
6 *********************************
7
8 .. contents::
9     :depth: 3
10
11 Background
12 ^^^^^^^^^^
13
14 Guard policies are used to limit what operations shall be permitted. These policies are specified in the Policy GUI or restful API and either return "PERMIT" or "DENY" on request.
15
16 There are 2 types of policies, guard policies and blacklist guard policies. The blacklist describes what is not allowed to be permitted and guard policies describe what is allowed to be permitted. Note: as of 1802 release, Policy PDP behaves as a PERMIT overrides fashion so if any policy permits, it will override any denies.
17
18 Creating Guard Policies
19 ^^^^^^^^^^^^^^^^^^^^^^^
20
21 There are two options for creating guard policies: (1) through the GUI and (2) through the restful API.
22
23 GUI Method
24 ----------
25
26 The GUARD policy can be created from the POLICY GUI as shown below.
27
28 .. image:: PolicyGUI_GuardPolicy.png
29
30 .. note::  The Onap Name must be empty for the policy to work.  To accomplish this,  instead of creating a new policy, **clone** the provided policy first and then **edit** it.
31
32 .. warning::  The request does not get denied, even though the number of requests exceeds the limit.
33
34
35 API Method
36 ----------
37
38 Use PUT /createPolicy to create a policy.  
39 The request should be in the following form for regular guard policy:
40
41 .. code-block:: json
42    :caption: Regular Guard Policy Creation
43    :linenos:
44
45     {
46         "policyClass": "Decision",
47         "policyName": "Test.TestingGUARDapitest",
48         "policyDescription": "Testing new YAML Guard Policy",
49         "onapName": "PDPD",
50         "ruleProvider": "GUARD_YAML",
51         "attributes": {
52             "MATCHING": {
53                 "actor": "APPC",
54                 "recipe": "restart",
55                 "targets" : "test",
56                 "clname" : "test",
57                 "limit": "5",
58                 "timeWindow": "15",
59                 "timeUnits" : "minute",
60                 "guardActiveStart": "05:00:00-05:00",
61                 "guardActiveEnd": "23:59:59-05:00"
62             }
63         }
64     }
65
66 The request should be in the following form for blacklist guard policy:
67
68 .. code-block:: json
69    :caption: Blacklist Guard Policy Creation
70    :linenos:
71
72     {
73         "policyClass": "Decision",
74         "policyName": "Test.TestingBLGUARD",
75         "policyDescription": "Testing New BL YAML Guard Policy",
76         "onapName": "MSO",
77         "ruleProvider": "GUARD_BL_YAML",
78         "attributes": {
79             "MATCHING": {
80                 "actor": "APPC",
81                 "recipe": "restart",
82                 "clname": "test",
83                 "guardActiveStart": "05:00:00-05:00",
84                 "guardActiveEnd": "23:59:59-05:00",
85                 "blackList": "target1,target2,target3"
86             }
87         }
88     }
89
90 Using Guard Policies
91 ^^^^^^^^^^^^^^^^^^^^
92
93 In order to use the guard policies just make an http request. For example:
94
95 .. code-block:: bash
96
97     http
98      POST pdp:8081/pdp/api/getDecision
99      Authorization:<yourAuth> ClientAuth:<yourClientAuth>
100      Environment:<environment> Content-Type:application/json < guard_request.json
101     
102 | where:
103 |     *<yourAuth>*       is the string generated from user:pass converted to base64 encoding.
104 |     *<yourClientAuth>* is generated the same way but from the client user and pass.
105 |     *<environment>*    is the context of the request. For example: TEST
106
107 The guard_request.json should be in the form of the following:
108
109 .. code-block:: json
110    :caption: guard_request.json
111
112     {
113       "decisionAttributes": {
114             "actor": "APPC",
115             "recipe": "Restart",
116             "target": "test13",
117             "clname" : "piptest"
118         },
119       "onapName": "PDPD"
120     }
121
122 A response containing a "PERMIT" or "DENY" in uppercase is returned as follows:
123
124 .. code-block:: json
125    :caption: Response
126
127     {
128       "decision": "PERMIT",
129       "details": "Decision Permit. OK!"
130     }
131
132
133
134 End of Document
135