Updated guard blacklist documentation
[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 blacklist guard policy:
70
71 .. code-block:: json
72    :caption: Blacklist Guard Policy Creation
73    :linenos:
74
75     {
76         "policyClass": "Decision",
77         "policyName": "Test.TestingBLGUARD",
78         "policyDescription": "Testing New BL YAML Guard Policy",
79         "onapName": "MSO",
80         "ruleProvider": "GUARD_BL_YAML",
81         "attributes": {
82             "MATCHING": {
83                 "actor": "APPC",
84                 "recipe": "restart",
85                 "clname": "test",
86                 "guardActiveStart": "05:00:00-05:00",
87                 "guardActiveEnd": "23:59:59-05:00",
88                 "blackList": "target1,target2,target3"
89             }
90         }
91     }
92
93 Using Guard Policies
94 ^^^^^^^^^^^^^^^^^^^^
95
96 In order to use the guard policies just make an http request. For example:
97
98 .. code-block:: bash
99
100     http
101      POST pdp:8081/pdp/api/getDecision
102      Authorization:<yourAuth> ClientAuth:<yourClientAuth>
103      Environment:<environment> Content-Type:application/json < guard_request.json
104     
105 | where:
106 |     *<yourAuth>*       is the string generated from user:pass converted to base64 encoding.
107 |     *<yourClientAuth>* is generated the same way but from the client user and pass.
108 |     *<environment>*    is the context of the request. For example: TEST
109
110 The guard_request.json should be in the form of the following:
111
112 .. code-block:: json
113    :caption: guard_request.json
114
115     {
116       "decisionAttributes": {
117             "actor": "APPC",
118             "recipe": "Restart",
119             "target": "test13",
120             "clname" : "piptest"
121         },
122       "onapName": "PDPD"
123     }
124
125 A response containing a “PERMIT” or “DENY” in uppercase is returned as follows:
126
127 .. code-block:: json
128    :caption: Response
129
130     {
131       "decision": "PERMIT",
132       "details": "Decision Permit. OK!"
133     }
134
135
136 End of Document
137
138 .. SSNote: Wiki page ref.  https://wiki.onap.org/display/DW/Creating+and+Using+Guard+Policies
139
140