| 1 |
|
| 2 |
from __future__ import absolute_import, division, print_function |
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
__metaclass__ = type |
| 7 |
|
| 8 |
ANSIBLE_METADATA = {'status': ['preview'], |
| 9 |
'supported_by': 'community', |
| 10 |
'metadata_version': '1.1'} |
| 11 |
|
| 12 |
DOCUMENTATION = ''' |
| 13 |
--- |
| 14 |
module: fmgr_waf_profile_signature |
| 15 |
short_description: WAF signatures. |
| 16 |
version_added: "2.0.0" |
| 17 |
extends_documentation_fragment: |
| 18 |
- fortinet.fortimanager.general |
| 19 |
- fortinet.fortimanager.general.partial_crud |
| 20 |
options: |
| 21 |
revision_note: |
| 22 |
description: The change note that can be specified when an object is created or updated. |
| 23 |
type: str |
| 24 |
adom: |
| 25 |
description: The parameter (adom) in requested url. |
| 26 |
type: str |
| 27 |
required: true |
| 28 |
profile: |
| 29 |
description: The parameter (profile) in requested url. |
| 30 |
type: str |
| 31 |
required: true |
| 32 |
waf_profile_signature: |
| 33 |
description: The top level parameters set. |
| 34 |
required: false |
| 35 |
type: dict |
| 36 |
suboptions: |
| 37 |
credit_card_detection_threshold: |
| 38 |
aliases: ['credit-card-detection-threshold'] |
| 39 |
type: int |
| 40 |
description: The minimum number of Credit cards to detect violation. |
| 41 |
custom_signature: |
| 42 |
aliases: ['custom-signature'] |
| 43 |
type: list |
| 44 |
elements: dict |
| 45 |
description: Custom signature. |
| 46 |
suboptions: |
| 47 |
action: |
| 48 |
type: str |
| 49 |
description: Action. |
| 50 |
choices: ['allow', 'block', 'erase'] |
| 51 |
case_sensitivity: |
| 52 |
aliases: ['case-sensitivity'] |
| 53 |
type: str |
| 54 |
description: Case sensitivity in pattern. |
| 55 |
choices: ['disable', 'enable'] |
| 56 |
direction: |
| 57 |
type: str |
| 58 |
description: Traffic direction. |
| 59 |
choices: ['request', 'response'] |
| 60 |
log: |
| 61 |
type: str |
| 62 |
description: Enable/disable logging. |
| 63 |
choices: ['disable', 'enable'] |
| 64 |
name: |
| 65 |
type: str |
| 66 |
description: Signature name. |
| 67 |
pattern: |
| 68 |
type: str |
| 69 |
description: Match pattern. |
| 70 |
severity: |
| 71 |
type: str |
| 72 |
description: Severity. |
| 73 |
choices: ['low', 'medium', 'high'] |
| 74 |
status: |
| 75 |
type: str |
| 76 |
description: Status. |
| 77 |
choices: ['disable', 'enable'] |
| 78 |
target: |
| 79 |
type: list |
| 80 |
elements: str |
| 81 |
description: Match HTTP target. |
| 82 |
choices: ['arg', 'arg-name', 'req-body', 'req-cookie', 'req-cookie-name', |
| 83 |
'req-filename', 'req-header', 'req-header-name', 'req-raw-uri', |
| 84 |
'req-uri', 'resp-body', 'resp-hdr', 'resp-status'] |
| 85 |
disabled_signature: |
| 86 |
aliases: ['disabled-signature'] |
| 87 |
type: raw |
| 88 |
description: (list or str) Disabled signatures |
| 89 |
disabled_sub_class: |
| 90 |
aliases: ['disabled-sub-class'] |
| 91 |
type: raw |
| 92 |
description: (list or str) Disabled signature subclasses. |
| 93 |
main_class: |
| 94 |
aliases: ['main-class'] |
| 95 |
type: dict |
| 96 |
description: Main class. |
| 97 |
suboptions: |
| 98 |
action: |
| 99 |
type: str |
| 100 |
description: Action. |
| 101 |
choices: ['allow', 'block', 'erase'] |
| 102 |
id: |
| 103 |
type: int |
| 104 |
description: Main signature class ID. |
| 105 |
log: |
| 106 |
type: str |
| 107 |
description: Enable/disable logging. |
| 108 |
choices: ['disable', 'enable'] |
| 109 |
severity: |
| 110 |
type: str |
| 111 |
description: Severity. |
| 112 |
choices: ['low', 'medium', 'high'] |
| 113 |
status: |
| 114 |
type: str |
| 115 |
description: Status. |
| 116 |
choices: ['disable', 'enable'] |
| 117 |
''' |
| 118 |
|
| 119 |
EXAMPLES = ''' |
| 120 |
- name: Example playbook (generated based on argument schema) |
| 121 |
hosts: fortimanagers |
| 122 |
connection: httpapi |
| 123 |
gather_facts: false |
| 124 |
tasks: |
| 125 |
- name: WAF signatures. |
| 126 |
fortinet.fortimanager.fmgr_waf_profile_signature: |
| 127 |
# workspace_locking_adom: <global or your adom name> |
| 128 |
adom: <your own value> |
| 129 |
profile: <your own value> |
| 130 |
waf_profile_signature: |
| 131 |
# credit_card_detection_threshold: <integer> |
| 132 |
# custom_signature: |
| 133 |
# - action: <value in [allow, block, erase]> |
| 134 |
# case_sensitivity: <value in [disable, enable]> |
| 135 |
# direction: <value in [request, response]> |
| 136 |
# log: <value in [disable, enable]> |
| 137 |
# name: <string> |
| 138 |
# pattern: <string> |
| 139 |
# severity: <value in [low, medium, high]> |
| 140 |
# status: <value in [disable, enable]> |
| 141 |
# target: ["arg", "arg-name", "req-body", "req-cookie", "req-cookie-name", |
| 142 |
# "req-filename", "req-header", "req-header-name", "req-raw-uri", |
| 143 |
# "req-uri", "resp-body", "resp-hdr", "resp-status"] |
| 144 |
# disabled_signature: <list or string> |
| 145 |
# disabled_sub_class: <list or string> |
| 146 |
# main_class: |
| 147 |
# action: <value in [allow, block, erase]> |
| 148 |
# id: <integer> |
| 149 |
# log: <value in [disable, enable]> |
| 150 |
# severity: <value in [low, medium, high]> |
| 151 |
# status: <value in [disable, enable]> |
| 152 |
''' |
| 153 |
|
| 154 |
RETURN = ''' |
| 155 |
meta: |
| 156 |
description: The result of the request. |
| 157 |
type: dict |
| 158 |
returned: always |
| 159 |
contains: |
| 160 |
request_url: |
| 161 |
description: The full url requested. |
| 162 |
returned: always |
| 163 |
type: str |
| 164 |
sample: /sys/login/user |
| 165 |
response_code: |
| 166 |
description: The status of api request. |
| 167 |
returned: always |
| 168 |
type: int |
| 169 |
sample: 0 |
| 170 |
response_data: |
| 171 |
description: The api response. |
| 172 |
type: list |
| 173 |
returned: always |
| 174 |
response_message: |
| 175 |
description: The descriptive message of the api response. |
| 176 |
type: str |
| 177 |
returned: always |
| 178 |
sample: OK. |
| 179 |
system_information: |
| 180 |
description: The information of the target system. |
| 181 |
type: dict |
| 182 |
returned: always |
| 183 |
rc: |
| 184 |
description: The status the request. |
| 185 |
type: int |
| 186 |
returned: always |
| 187 |
sample: 0 |
| 188 |
version_check_warning: |
| 189 |
description: Warning if the parameters used in the playbook are not supported by the current FortiManager version. |
| 190 |
type: list |
| 191 |
returned: complex |
| 192 |
''' |
| 193 |
from ansible.module_utils.basic import AnsibleModule |
| 194 |
from ansible.module_utils.connection import Connection |
| 195 |
from ansible_collections.fortinet.fortimanager.plugins.module_utils.napi import NAPIManager, check_galaxy_version, check_parameter_bypass |
| 196 |
from ansible_collections.fortinet.fortimanager.plugins.module_utils.common import get_module_arg_spec |
| 197 |
|
| 198 |
|
| 199 |
def main(): |
| 200 |
urls_list = [ |
| 201 |
'/pm/config/adom/{adom}/obj/waf/profile/{profile}/signature', |
| 202 |
'/pm/config/global/obj/waf/profile/{profile}/signature' |
| 203 |
] |
| 204 |
module_arg_spec = { |
| 205 |
'adom': {'required': True, 'type': 'str'}, |
| 206 |
'profile': {'required': True, 'type': 'str'}, |
| 207 |
'revision_note': {'type': 'str'}, |
| 208 |
'waf_profile_signature': { |
| 209 |
'type': 'dict', 'v_range': [['6.0.0', '']], |
| 210 |
'options': { |
| 211 |
'credit-card-detection-threshold': {'type': 'int'}, |
| 212 |
'custom-signature': { |
| 213 |
'type': 'list', |
| 214 |
'options': { |
| 215 |
'action': {'choices': ['allow', 'block', 'erase'], 'type': 'str'}, |
| 216 |
'case-sensitivity': {'choices': ['disable', 'enable'], 'type': 'str'}, |
| 217 |
'direction': {'choices': ['request', 'response'], 'type': 'str'}, |
| 218 |
'log': {'choices': ['disable', 'enable'], 'type': 'str'}, |
| 219 |
'name': {'type': 'str'}, |
| 220 |
'pattern': {'type': 'str'}, |
| 221 |
'severity': {'choices': ['low', 'medium', 'high'], 'type': 'str'}, |
| 222 |
'status': {'choices': ['disable', 'enable'], 'type': 'str'}, |
| 223 |
'target': { |
| 224 |
'type': 'list', |
| 225 |
'choices': [ |
| 226 |
'arg', 'arg-name', 'req-body', 'req-cookie', 'req-cookie-name', 'req-filename', 'req-header', 'req-header-name', |
| 227 |
'req-raw-uri', 'req-uri', 'resp-body', 'resp-hdr', 'resp-status' |
| 228 |
], |
| 229 |
'elements': 'str' |
| 230 |
} |
| 231 |
}, |
| 232 |
'elements': 'dict' |
| 233 |
}, |
| 234 |
'disabled-signature': {'type': 'raw'}, |
| 235 |
'disabled-sub-class': {'type': 'raw'}, |
| 236 |
'main-class': { |
| 237 |
'type': 'dict', |
| 238 |
'options': { |
| 239 |
'action': {'choices': ['allow', 'block', 'erase'], 'type': 'str'}, |
| 240 |
'id': {'type': 'int'}, |
| 241 |
'log': {'choices': ['disable', 'enable'], 'type': 'str'}, |
| 242 |
'severity': {'choices': ['low', 'medium', 'high'], 'type': 'str'}, |
| 243 |
'status': {'choices': ['disable', 'enable'], 'type': 'str'} |
| 244 |
} |
| 245 |
} |
| 246 |
} |
| 247 |
} |
| 248 |
} |
| 249 |
|
| 250 |
module_option_spec = get_module_arg_spec('partial crud') |
| 251 |
module_arg_spec.update(module_option_spec) |
| 252 |
check_galaxy_version(module_arg_spec) |
| 253 |
module = AnsibleModule(argument_spec=check_parameter_bypass(module_arg_spec, 'waf_profile_signature'), |
| 254 |
supports_check_mode=True) |
| 255 |
if not module._socket_path: |
| 256 |
module.fail_json(msg='MUST RUN IN HTTPAPI MODE') |
| 257 |
connection = Connection(module._socket_path) |
| 258 |
fmgr = NAPIManager('partial crud', module_arg_spec, urls_list, |
| 259 |
None, 'data', module, connection) |
| 260 |
fmgr.process_partial_crud() |
| 261 |
module.exit_json(meta=module.params) |
| 262 |
|
| 263 |
|
| 264 |
if __name__ == '__main__': |
| 265 |
main() |