New min/max Guard Policy
[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.  The Policy PDP behaves in a PERMIT overrides fashion, that is,  if any policy permits, it will override any denies.
17
18 .. note:: *Limit Functionality*: The determination to deny a request because it has exceeded the limit is based on the number of entries in the **database**.  
19
20 Creating Guard Policies
21 ^^^^^^^^^^^^^^^^^^^^^^^
22
23 There are two options for creating guard policies: (1) through the GUI and (2) through the restful API.
24
25 GUI Method
26 ----------
27
28 The GUARD policy can be created from the POLICY GUI as shown below.
29
30 .. image:: PolicyGUI_GuardPolicy.png
31
32 In a Blacklist policy, the blacklist entries can be entered either manually or imported from an excel sheet.  This import option can also be used to delete existing blacklist entries and to add new entries.
33
34 .. image:: PolicyGUI_BlacklistPolicy.png
35
36
37 API Method
38 ----------
39
40 To create the policy, use the PUT /createPolicy API. This request uses Basic Access Authentication. 
41
42 The request should be in the following form for the regular guard policy:
43
44 .. code-block:: json
45    :caption: Regular Guard Policy Creation
46    :linenos:
47
48     {
49         "policyClass": "Decision",
50         "policyName": "Test.TestingGUARDapitest",
51         "policyDescription": "Testing new YAML Guard Policy",
52         "onapName": "PDPD",
53         "ruleProvider": "GUARD_YAML",
54         "attributes": {
55             "MATCHING": {
56                 "actor": "APPC",
57                 "recipe": "restart",
58                 "targets" : "test",
59                 "clname" : "test",
60                 "limit": "5",
61                 "timeWindow": "15",
62                 "timeUnits" : "minute",
63                 "guardActiveStart": "05:00:00-05:00",
64                 "guardActiveEnd": "23:59:59-05:00"
65             }
66         }
67     }
68
69 The request should be in the following form for the Min/Max guard policy:
70
71 .. code-block:: json
72    :caption: Min/Max Guard Policy Creation
73    :linenos:
74
75     {
76         "policyClass": "Decision",
77         "policyName": "Test.TestingGUARDMinMaxtest",
78         "policyDescription": "Testing new Min/Max Guard Policy",
79         "onapName": "PDPD",
80         "ruleProvider": "GUARD_MIN_MAX",
81         "attributes": {
82             "MATCHING": {
83                 "actor": "SO",
84                 "recipe": "scaleOut",
85                 "targets" : ".*",
86                 "clname" : "test",
87                 "min": "1",
88                 "max": "5",
89                 "guardActiveStart": "05:00:00-05:00",
90                 "guardActiveEnd": "23:59:59-05:00"
91             }
92         }
93     }
94     
95 The request should be in the following form for blacklist guard policy:
96
97 .. code-block:: json
98    :caption: Blacklist Guard Policy Creation
99    :linenos:
100
101     {
102         "policyClass": "Decision",
103         "policyName": "Test.TestingBLGUARD",
104         "policyDescription": "Testing New BL YAML Guard Policy",
105         "onapName": "MSO",
106         "ruleProvider": "GUARD_BL_YAML",
107         "attributes": {
108             "MATCHING": {
109                 "actor": "APPC",
110                 "recipe": "restart",
111                 "clname": "test",
112                 "guardActiveStart": "05:00:00-05:00",
113                 "guardActiveEnd": "23:59:59-05:00",
114                 "blackList": "target1,target2,target3"
115             }
116         }
117     }
118
119 Using Guard Policies
120 ^^^^^^^^^^^^^^^^^^^^
121
122 In order to use the guard policies just make an http request. For example:
123
124 .. code-block:: bash
125
126     http
127      POST pdp:8081/pdp/api/getDecision
128      Authorization:<yourAuth> ClientAuth:<yourClientAuth>
129      Environment:<environment> Content-Type:application/json < guard_request.json
130     
131 | where:
132 |     *<yourAuth>*       is the string generated from user:pass converted to base64 encoding.
133 |     *<yourClientAuth>* is generated the same way but from the client user and pass.
134 |     *<environment>*    is the context of the request. For example: TEST
135
136 The guard_request.json should be in the form of the following:
137
138 .. code-block:: json
139    :caption: guard_request.json
140
141     {
142       "decisionAttributes": {
143             "actor": "APPC",
144             "recipe": "Restart",
145             "target": "test13",
146             "clname" : "piptest",
147             "vfCount" : "4"
148         },
149       "onapName": "PDPD"
150     }
151
152 A response containing a “PERMIT” or “DENY” in uppercase is returned as follows:
153
154 .. code-block:: json
155    :caption: Response
156
157     {
158       "decision": "PERMIT",
159       "details": "Decision Permit. OK!"
160     }
161
162
163 End of Document
164
165 .. SSNote: Wiki page ref.  https://wiki.onap.org/display/DW/Creating+and+Using+Guard+Policies
166
167