Debian Codegraph @

ansible_collections/community/aws/plugins/modules/networkfirewall_rule_group_info.py

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # Copyright: Ansible Project
5 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
6
7 DOCUMENTATION = r"""
8 module: networkfirewall_rule_group_info
9 short_description: describe AWS Network Firewall rule groups
10 version_added: 4.0.0
11 description:
12 - A module for describing AWS Network Firewall rule groups.
13 options:
14 arn:
15 description:
16 - The ARN of the Network Firewall rule group.
17 - At time of writing AWS does not support describing Managed Rules.
18 required: false
19 type: str
20 name:
21 description:
22 - The name of the Network Firewall rule group.
23 required: false
24 type: str
25 rule_type:
26 description:
27 - Indicates whether the rule group is stateless or stateful.
28 - Required if I(name) is provided.
29 required: false
30 aliases: ['type' ]
31 choices: ['stateful', 'stateless']
32 type: str
33 scope:
34 description:
35 - The scope of the request.
36 - When I(scope='account') returns a description of all rule groups in the account.
37 - When I(scope='managed') returns a list of available managed rule group arns.
38 - By default searches only at the account scope.
39 required: false
40 choices: ['managed', 'account']
41 type: str
42
43 author:
44 - Mark Chappell (@tremble)
45 extends_documentation_fragment:
46 - amazon.aws.common.modules
47 - amazon.aws.region.modules
48 - amazon.aws.boto3
49 """
50
51 EXAMPLES = r"""
52
53 # Describe all Rule Groups in an account (excludes managed groups)
54 - community.aws.networkfirewall_rule_group_info: {}
55
56 # List the available Managed Rule groups (AWS doesn't support describing the
57 # groups)
58 - community.aws.networkfirewall_rule_group_info:
59 scope: managed
60
61 # Describe a Rule Group by ARN
62 - community.aws.networkfirewall_rule_group_info:
63 arn: arn:aws:network-firewall:us-east-1:123456789012:stateful-rulegroup/ExampleRuleGroup
64
65 # Describe a Rule Group by name
66 - community.aws.networkfirewall_rule_group_info:
67 name: ExampleRuleGroup
68 type: stateful
69 """
70
71 RETURN = r"""
72 rule_list:
73 description: A list of ARNs of the matching rule groups.
74 type: list
75 elements: str
76 returned: When a rule name isn't specified
77
78 rule_groups:
79 description: The details of the rule groups
80 returned: success
81 type: list
82 elements: dict
83 contains:
84 rule_group:
85 description: Details of the rules in the rule group
86 type: dict
87 returned: success
88 contains:
89 rule_variables:
90 description: Settings that are available for use in the rules in the rule group.
91 returned: When rule variables are attached to the rule group.
92 type: complex
93 contains:
94 ip_sets:
95 description: A dictionary mapping variable names to IP addresses in CIDR format.
96 returned: success
97 type: dict
98 example: ['192.0.2.0/24']
99 port_sets:
100 description: A dictionary mapping variable names to ports
101 returned: success
102 type: dict
103 example: ['42']
104 stateful_rule_options:
105 description: Additional options governing how Network Firewall handles stateful rules.
106 returned: When the rule group is either "rules string" or "rules list" based.
107 type: dict
108 contains:
109 rule_order:
110 description: The order in which rules will be evaluated.
111 returned: success
112 type: str
113 example: 'DEFAULT_ACTION_ORDER'
114 rules_source:
115 description: DEFAULT_ACTION_ORDER
116 returned: success
117 type: dict
118 contains:
119 stateful_rules:
120 description: A list of dictionaries describing the rules that the rule group is comprised of.
121 returned: When the rule group is "rules list" based.
122 type: list
123 elements: dict
124 contains:
125 action:
126 description: What action to perform when a flow matches the rule criteria.
127 returned: success
128 type: str
129 example: 'PASS'
130 header:
131 description: A description of the criteria used for the rule.
132 returned: success
133 type: dict
134 contains:
135 protocol:
136 description: The protocol to inspect for.
137 returned: success
138 type: str
139 example: 'IP'
140 source:
141 description: The source address or range of addresses to inspect for.
142 returned: success
143 type: str
144 example: '203.0.113.98'
145 source_port:
146 description: The source port to inspect for.
147 returned: success
148 type: str
149 example: '42'
150 destination:
151 description: The destination address or range of addresses to inspect for.
152 returned: success
153 type: str
154 example: '198.51.100.0/24'
155 destination_port:
156 description: The destination port to inspect for.
157 returned: success
158 type: str
159 example: '6666:6667'
160 direction:
161 description: The direction of traffic flow to inspect.
162 returned: success
163 type: str
164 example: 'FORWARD'
165 rule_options:
166 description: Additional Suricata RuleOptions settings for the rule.
167 returned: success
168 type: list
169 elements: dict
170 contains:
171 keyword:
172 description: The keyword for the setting.
173 returned: success
174 type: str
175 example: 'sid:1'
176 settings:
177 description: A list of values passed to the setting.
178 returned: When values are available
179 type: list
180 elements: str
181 rules_string:
182 description: A string describing the rules that the rule group is comprised of.
183 returned: When the rule group is "rules string" based.
184 type: str
185 rules_source_list:
186 description: A description of the criteria for a domain list rule group.
187 returned: When the rule group is "domain list" based.
188 type: dict
189 contains:
190 targets:
191 description: A list of domain names to be inspected for.
192 returned: success
193 type: list
194 elements: str
195 example: ['abc.example.com', '.example.net']
196 target_types:
197 description: The protocols to be inspected by the rule group.
198 returned: success
199 type: list
200 elements: str
201 example: ['TLS_SNI', 'HTTP_HOST']
202 generated_rules_type:
203 description: Whether the rule group allows or denies access to the domains in the list.
204 returned: success
205 type: str
206 example: 'ALLOWLIST'
207 stateless_rules_and_custom_actions:
208 description: A description of the criteria for a stateless rule group.
209 returned: When the rule group is a stateless rule group.
210 type: dict
211 contains:
212 stateless_rules:
213 description: A list of stateless rules for use in a stateless rule group.
214 type: list
215 elements: dict
216 contains:
217 rule_definition:
218 description: Describes the stateless 5-tuple inspection criteria and actions for the rule.
219 returned: success
220 type: dict
221 contains:
222 match_attributes:
223 description: Describes the stateless 5-tuple inspection criteria for the rule.
224 returned: success
225 type: dict
226 contains:
227 sources:
228 description: The source IP addresses and address ranges to inspect for.
229 returned: success
230 type: list
231 elements: dict
232 contains:
233 address_definition:
234 description: An IP address or a block of IP addresses in CIDR notation.
235 returned: success
236 type: str
237 example: '192.0.2.3'
238 destinations:
239 description: The destination IP addresses and address ranges to inspect for.
240 returned: success
241 type: list
242 elements: dict
243 contains:
244 address_definition:
245 description: An IP address or a block of IP addresses in CIDR notation.
246 returned: success
247 type: str
248 example: '192.0.2.3'
249 source_ports:
250 description: The source port ranges to inspect for.
251 returned: success
252 type: list
253 elements: dict
254 contains:
255 from_port:
256 description: The lower limit of the port range.
257 returned: success
258 type: int
259 to_port:
260 description: The upper limit of the port range.
261 returned: success
262 type: int
263 destination_ports:
264 description: The destination port ranges to inspect for.
265 returned: success
266 type: list
267 elements: dict
268 contains:
269 from_port:
270 description: The lower limit of the port range.
271 returned: success
272 type: int
273 to_port:
274 description: The upper limit of the port range.
275 returned: success
276 type: int
277 protocols:
278 description: The IANA protocol numbers of the protocols to inspect for.
279 returned: success
280 type: list
281 elements: int
282 example: [6]
283 tcp_flags:
284 description: The TCP flags and masks to inspect for.
285 returned: success
286 type: list
287 elements: dict
288 contains:
289 flags:
290 description: Used with masks to define the TCP flags that flows are inspected for.
291 returned: success
292 type: list
293 elements: str
294 masks:
295 description: The set of flags considered during inspection.
296 returned: success
297 type: list
298 elements: str
299 actions:
300 description: The actions to take when a flow matches the rule.
301 returned: success
302 type: list
303 elements: str
304 example: ['aws:pass', 'CustomActionName']
305 priority:
306 description: Indicates the order in which to run this rule relative to all of the rules that are defined for a stateless rule group.
307 returned: success
308 type: int
309 custom_actions:
310 description: A list of individual custom action definitions that are available for use in stateless rules.
311 type: list
312 elements: dict
313 contains:
314 action_name:
315 description: The name for the custom action.
316 returned: success
317 type: str
318 action_definition:
319 description: The custom action associated with the action name.
320 returned: success
321 type: dict
322 contains:
323 publish_metric_action:
324 description: The description of an action which publishes to CloudWatch.
325 returned: When the action publishes to CloudWatch.
326 type: dict
327 contains:
328 dimensions:
329 description: The value to use in an Amazon CloudWatch custom metric dimension.
330 returned: success
331 type: list
332 elements: dict
333 contains:
334 value:
335 description: The value to use in the custom metric dimension.
336 returned: success
337 type: str
338 rule_group_metadata:
339 description: Details of the rules in the rule group
340 type: dict
341 returned: success
342 contains:
343 capacity:
344 description: The maximum operating resources that this rule group can use.
345 type: int
346 returned: success
347 consumed_capacity:
348 description: The number of capacity units currently consumed by the rule group rules.
349 type: int
350 returned: success
351 description:
352 description: A description of the rule group.
353 type: str
354 returned: success
355 number_of_associations:
356 description: The number of firewall policies that use this rule group.
357 type: int
358 returned: success
359 rule_group_arn:
360 description: The ARN for the rule group
361 type: int
362 returned: success
363 example: 'arn:aws:network-firewall:us-east-1:123456789012:stateful-rulegroup/ExampleGroup'
364 rule_group_id:
365 description: A unique identifier for the rule group.
366 type: int
367 returned: success
368 example: '12345678-abcd-1234-abcd-123456789abc'
369 rule_group_name:
370 description: The name of the rule group.
371 type: str
372 returned: success
373 rule_group_status:
374 description: The current status of a rule group.
375 type: str
376 returned: success
377 example: 'DELETING'
378 tags:
379 description: A dictionary representing the tags associated with the rule group.
380 type: dict
381 returned: success
382 type:
383 description: Whether the rule group is stateless or stateful.
384 type: str
385 returned: success
386 example: 'STATEFUL'
387 """
388
389 from ansible_collections.community.aws.plugins.module_utils.modules import AnsibleCommunityAWSModule as AnsibleAWSModule
390 from ansible_collections.community.aws.plugins.module_utils.networkfirewall import NetworkFirewallRuleManager
391
392
393 def main():
394 argument_spec = dict(
395 name=dict(type="str", required=False),
396 rule_type=dict(type="str", required=False, aliases=["type"], choices=["stateless", "stateful"]),
397 arn=dict(type="str", required=False),
398 scope=dict(type="str", required=False, choices=["managed", "account"]),
399 )
400
401 module = AnsibleAWSModule(
402 argument_spec=argument_spec,
403 supports_check_mode=True,
404 mutually_exclusive=[
405 ["arn", "name"],
406 ["arn", "rule_type"],
407 ],
408 required_together=[
409 ["name", "rule_type"],
410 ],
411 )
412
413 arn = module.params.get("arn")
414 name = module.params.get("name")
415 rule_type = module.params.get("rule_type")
416 scope = module.params.get("scope")
417
418 manager = NetworkFirewallRuleManager(module, name=name, rule_type=rule_type)
419
420 results = dict(changed=False)
421
422 if name or arn:
423 rule = manager.get_rule_group(name=name, rule_type=rule_type, arn=arn)
424 if rule:
425 results["rule_groups"] = [rule]
426 else:
427 results["rule_groups"] = []
428 else:
429 rule_list = manager.list(scope=scope)
430 results["rule_list"] = rule_list
431 if scope != "managed":
432 rules = [manager.get_rule_group(arn=r) for r in rule_list]
433 results["rule_groups"] = rules
434
435 module.exit_json(**results)
436
437
438 if __name__ == "__main__":
439 main()