| 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_policy_info |
| 9 |
short_description: describe AWS Network Firewall policies |
| 10 |
version_added: 4.0.0 |
| 11 |
description: |
| 12 |
- A module for describing AWS Network Firewall policies. |
| 13 |
options: |
| 14 |
arn: |
| 15 |
description: |
| 16 |
- The ARN of the Network Firewall policy. |
| 17 |
- Mutually exclusive with I(name). |
| 18 |
required: false |
| 19 |
type: str |
| 20 |
name: |
| 21 |
description: |
| 22 |
- The name of the Network Firewall policy. |
| 23 |
- Mutually exclusive with I(arn). |
| 24 |
required: false |
| 25 |
type: str |
| 26 |
|
| 27 |
author: |
| 28 |
- Mark Chappell (@tremble) |
| 29 |
extends_documentation_fragment: |
| 30 |
- amazon.aws.common.modules |
| 31 |
- amazon.aws.region.modules |
| 32 |
- amazon.aws.boto3 |
| 33 |
""" |
| 34 |
|
| 35 |
EXAMPLES = r""" |
| 36 |
|
| 37 |
# Describe all Firewall policies in an account |
| 38 |
- community.aws.networkfirewall_policy_info: {} |
| 39 |
|
| 40 |
# Describe a Firewall policy by ARN |
| 41 |
- community.aws.networkfirewall_policy_info: |
| 42 |
arn: arn:aws:network-firewall:us-east-1:123456789012:firewall-policy/ExamplePolicy |
| 43 |
|
| 44 |
# Describe a Firewall policy by name |
| 45 |
- community.aws.networkfirewall_policy_info: |
| 46 |
name: ExamplePolicy |
| 47 |
""" |
| 48 |
|
| 49 |
RETURN = r""" |
| 50 |
policy_list: |
| 51 |
description: A list of ARNs of the matching policies. |
| 52 |
type: list |
| 53 |
elements: str |
| 54 |
returned: When a policy name isn't specified |
| 55 |
example: ['arn:aws:network-firewall:us-east-1:123456789012:firewall-policy/Example1', |
| 56 |
'arn:aws:network-firewall:us-east-1:123456789012:firewall-policy/Example2'] |
| 57 |
|
| 58 |
policies: |
| 59 |
description: The details of the policies |
| 60 |
returned: success |
| 61 |
type: list |
| 62 |
elements: dict |
| 63 |
contains: |
| 64 |
policy: |
| 65 |
description: The details of the policy |
| 66 |
type: dict |
| 67 |
returned: success |
| 68 |
contains: |
| 69 |
stateful_engine_options: |
| 70 |
description: |
| 71 |
- Extra options describing how the stateful rules should be handled. |
| 72 |
type: dict |
| 73 |
returned: success |
| 74 |
contains: |
| 75 |
rule_order: |
| 76 |
description: |
| 77 |
- How rule group evaluation will be ordered. |
| 78 |
- For more information on rule evaluation ordering see the AWS documentation |
| 79 |
U(https://docs.aws.amazon.com/network-firewall/latest/developerguide/suricata-rule-evaluation-order.html). |
| 80 |
type: str |
| 81 |
returned: success |
| 82 |
example: 'DEFAULT_ACTION_ORDER' |
| 83 |
stateful_rule_group_references: |
| 84 |
description: Information about the stateful rule groups attached to the policy. |
| 85 |
type: list |
| 86 |
elements: dict |
| 87 |
returned: success |
| 88 |
contains: |
| 89 |
resource_arn: |
| 90 |
description: The ARN of the rule group. |
| 91 |
type: str |
| 92 |
returned: success |
| 93 |
example: 'arn:aws:network-firewall:us-east-1:aws-managed:stateful-rulegroup/AbusedLegitMalwareDomainsActionOrder' |
| 94 |
priority: |
| 95 |
description: |
| 96 |
- An integer that indicates the order in which to run the stateful rule groups in a single policy. |
| 97 |
- This only applies to policies that specify the STRICT_ORDER rule order in the stateful engine options settings. |
| 98 |
type: int |
| 99 |
returned: success |
| 100 |
example: 1234 |
| 101 |
stateless_custom_actions: |
| 102 |
description: |
| 103 |
- A description of additional custom actions available for use as |
| 104 |
default rules to apply to stateless packets. |
| 105 |
type: list |
| 106 |
elements: dict |
| 107 |
returned: success |
| 108 |
contains: |
| 109 |
action_name: |
| 110 |
description: A name for the action. |
| 111 |
type: str |
| 112 |
returned: success |
| 113 |
example: 'ExampleAction' |
| 114 |
action_definition: |
| 115 |
description: The action to perform. |
| 116 |
type: dict |
| 117 |
returned: success |
| 118 |
contains: |
| 119 |
publish_metric_action: |
| 120 |
description: |
| 121 |
- Definition of a custom metric to be published to CloudWatch. |
| 122 |
- U(https://docs.aws.amazon.com/network-firewall/latest/developerguide/monitoring-cloudwatch.html) |
| 123 |
type: dict |
| 124 |
returned: success |
| 125 |
contains: |
| 126 |
dimensions: |
| 127 |
description: |
| 128 |
- The values of the CustomAction dimension to set on the metrics. |
| 129 |
- The dimensions of a metric are used to identify unique |
| 130 |
streams of data. |
| 131 |
type: list |
| 132 |
elements: dict |
| 133 |
returned: success |
| 134 |
contains: |
| 135 |
value: |
| 136 |
description: A value of the CustomAction dimension to set on the metrics. |
| 137 |
type: str |
| 138 |
returned: success |
| 139 |
example: 'ExampleRule' |
| 140 |
stateless_default_actions: |
| 141 |
description: The default actions to take on a packet that doesn't match any stateful rules. |
| 142 |
type: list |
| 143 |
elements: str |
| 144 |
returned: success |
| 145 |
example: ['aws:alert_strict'] |
| 146 |
stateless_fragment_default_actions: |
| 147 |
description: The actions to take on a packet if it doesn't match any of the stateless rules in the policy. |
| 148 |
type: list |
| 149 |
elements: str |
| 150 |
returned: success |
| 151 |
example: ['aws:pass'] |
| 152 |
stateless_rule_group_references: |
| 153 |
description: Information about the stateful rule groups attached to the policy. |
| 154 |
type: list |
| 155 |
elements: dict |
| 156 |
returned: success |
| 157 |
contains: |
| 158 |
resource_arn: |
| 159 |
description: The ARN of the rule group. |
| 160 |
type: str |
| 161 |
returned: success |
| 162 |
example: 'arn:aws:network-firewall:us-east-1:123456789012:stateless-rulegroup/ExampleGroup' |
| 163 |
priority: |
| 164 |
description: |
| 165 |
- An integer that indicates the order in which to run the stateless rule groups in a single policy. |
| 166 |
type: str |
| 167 |
returned: success |
| 168 |
example: 12345 |
| 169 |
policy_metadata: |
| 170 |
description: Metadata about the policy |
| 171 |
type: dict |
| 172 |
returned: success |
| 173 |
contains: |
| 174 |
consumed_stateful_rule_capacity: |
| 175 |
description: The total number of capacity units used by the stateful rule groups. |
| 176 |
type: int |
| 177 |
returned: success |
| 178 |
example: 165 |
| 179 |
consumed_stateless_rule_capacity: |
| 180 |
description: The total number of capacity units used by the stateless rule groups. |
| 181 |
type: int |
| 182 |
returned: success |
| 183 |
example: 2010 |
| 184 |
firewall_policy_arn: |
| 185 |
description: The ARN of the policy. |
| 186 |
type: str |
| 187 |
returned: success |
| 188 |
example: arn:aws:network-firewall:us-east-1:123456789012:firewall-policy/ExamplePolicy |
| 189 |
firewall_policy_id: |
| 190 |
description: The unique ID of the policy. |
| 191 |
type: str |
| 192 |
returned: success |
| 193 |
example: 12345678-abcd-1234-5678-123456789abc |
| 194 |
firewall_policy_name: |
| 195 |
description: The name of the policy. |
| 196 |
type: str |
| 197 |
returned: success |
| 198 |
example: ExamplePolicy |
| 199 |
firewall_policy_status: |
| 200 |
description: The current status of the policy. |
| 201 |
type: str |
| 202 |
returned: success |
| 203 |
example: ACTIVE |
| 204 |
number_of_associations: |
| 205 |
description: The number of firewalls the policy is associated to. |
| 206 |
type: int |
| 207 |
returned: success |
| 208 |
example: 1 |
| 209 |
tags: |
| 210 |
description: A dictionary representing the tags associated with the policy. |
| 211 |
type: dict |
| 212 |
returned: success |
| 213 |
example: {'tagName': 'Some Value'} |
| 214 |
""" |
| 215 |
|
| 216 |
from ansible_collections.community.aws.plugins.module_utils.modules import AnsibleCommunityAWSModule as AnsibleAWSModule |
| 217 |
from ansible_collections.community.aws.plugins.module_utils.networkfirewall import NetworkFirewallPolicyManager |
| 218 |
|
| 219 |
|
| 220 |
def main(): |
| 221 |
argument_spec = dict( |
| 222 |
name=dict(type="str", required=False), |
| 223 |
arn=dict(type="str", required=False), |
| 224 |
) |
| 225 |
|
| 226 |
module = AnsibleAWSModule( |
| 227 |
argument_spec=argument_spec, |
| 228 |
supports_check_mode=True, |
| 229 |
mutually_exclusive=[ |
| 230 |
["arn", "name"], |
| 231 |
], |
| 232 |
) |
| 233 |
|
| 234 |
arn = module.params.get("arn") |
| 235 |
name = module.params.get("name") |
| 236 |
|
| 237 |
manager = NetworkFirewallPolicyManager(module) |
| 238 |
|
| 239 |
results = dict(changed=False) |
| 240 |
|
| 241 |
if name or arn: |
| 242 |
policy = manager.get_policy(name=name, arn=arn) |
| 243 |
if policy: |
| 244 |
results["policies"] = [policy] |
| 245 |
else: |
| 246 |
results["policies"] = [] |
| 247 |
else: |
| 248 |
policy_list = manager.list() |
| 249 |
results["policy_list"] = policy_list |
| 250 |
policies = [manager.get_policy(arn=p) for p in policy_list] |
| 251 |
results["policies"] = policies |
| 252 |
|
| 253 |
module.exit_json(**results) |
| 254 |
|
| 255 |
|
| 256 |
if __name__ == "__main__": |
| 257 |
main() |