| 1 |
#!/usr/bin/python |
| 2 |
|
| 3 |
# Copyright (c) 2026, Clément Cruau (@PendaGTP) <[email protected]> |
| 4 |
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 5 |
# SPDX-License-Identifier: GPL-3.0-or-later |
| 6 |
|
| 7 |
DOCUMENTATION = r""" |
| 8 |
module: proxmox_node_firewall_info |
| 9 |
short_description: Get node-level firewall options for Proxmox VE cluster |
| 10 |
version_added: "2.0.0" |
| 11 |
author: |
| 12 |
- Clément Cruau (@PendaGTP) |
| 13 |
description: |
| 14 |
- Get firewall options at the node level in Proxmox VE. |
| 15 |
attributes: |
| 16 |
check_mode: |
| 17 |
support: full |
| 18 |
diff_mode: |
| 19 |
support: none |
| 20 |
options: |
| 21 |
node_name: |
| 22 |
description: |
| 23 |
- Name of the node. |
| 24 |
type: str |
| 25 |
aliases: ["node"] |
| 26 |
required: true |
| 27 |
|
| 28 |
seealso: |
| 29 |
- name: Proxmox VE Firewall configuration |
| 30 |
description: Complete reference of Proxmox VE Firewall |
| 31 |
link: https://pve.proxmox.com/pve-docs/chapter-pve-firewall.html |
| 32 |
- name: Proxmox VE node-wide configuration |
| 33 |
description: Complete reference of Proxmox VE Firewall host configuration |
| 34 |
link: https://pve.proxmox.com/pve-docs/chapter-pve-firewall.html#pve_firewall_host_specific_configuration |
| 35 |
- module: community.proxmox.proxmox_node_firewall |
| 36 |
- module: community.proxmox.proxmox_cluster_firewall |
| 37 |
|
| 38 |
extends_documentation_fragment: |
| 39 |
- community.proxmox.proxmox.actiongroup_proxmox |
| 40 |
- community.proxmox.proxmox.documentation |
| 41 |
- community.proxmox.attributes |
| 42 |
""" |
| 43 |
|
| 44 |
EXAMPLES = r""" |
| 45 |
- name: Get node-wide firewall options |
| 46 |
community.proxmox.proxmox_node_firewall_info: |
| 47 |
node_name: pve-001 |
| 48 |
""" |
| 49 |
|
| 50 |
RETURN = r""" |
| 51 |
enabled: |
| 52 |
description: Whether the firewall is enabled node-wide. |
| 53 |
returned: on success |
| 54 |
type: bool |
| 55 |
sample: true |
| 56 |
node_name: |
| 57 |
description: The name of the node. |
| 58 |
returned: on success |
| 59 |
type: str |
| 60 |
sample: pve-001 |
| 61 |
log_level_in: |
| 62 |
description: Log level setting for incoming traffic. |
| 63 |
returned: on success |
| 64 |
type: str |
| 65 |
sample: no_log |
| 66 |
log_level_out: |
| 67 |
description: Log level setting for outgoing traffic. |
| 68 |
returned: on success |
| 69 |
type: str |
| 70 |
sample: no_log |
| 71 |
log_level_forward: |
| 72 |
description: Log level setting for fowarded traffic. |
| 73 |
returned: on success |
| 74 |
type: str |
| 75 |
sample: no_log |
| 76 |
ndp: |
| 77 |
description: Whether NDP (Neighbor Discovery Protocol) is enabled. |
| 78 |
returned: on success |
| 79 |
type: bool |
| 80 |
sample: true |
| 81 |
nftables: |
| 82 |
description: Whether nftables based firewall is enabled. |
| 83 |
returned: on success |
| 84 |
type: bool |
| 85 |
sample: false |
| 86 |
nosmurfs: |
| 87 |
description: Whether SMURFS filter is enabled. |
| 88 |
returned: on success |
| 89 |
type: bool |
| 90 |
sample: true |
| 91 |
smurf_log_level: |
| 92 |
description: Log level setting for SMURFS filter. |
| 93 |
returned: on success |
| 94 |
type: str |
| 95 |
tcp_flags_log_level: |
| 96 |
description: Log level setting for illegal TCP flags filter. |
| 97 |
returned: on success |
| 98 |
type: str |
| 99 |
tcpflags: |
| 100 |
description: Whether illegal combinations of TCP flags are filtered. |
| 101 |
returned: on success |
| 102 |
type: bool |
| 103 |
sample: false |
| 104 |
nf_conntrack_allow_invalid: |
| 105 |
description: Whether invalid packets are allowed on connection tracking. |
| 106 |
returned: on success |
| 107 |
type: bool |
| 108 |
sample: false |
| 109 |
nf_conntrack_helpers: |
| 110 |
description: Conntrack helpers for specific protocols. |
| 111 |
returned: on success |
| 112 |
type: str |
| 113 |
nf_conntrack_max: |
| 114 |
description: Maximum number of tracked connections. |
| 115 |
returned: on success |
| 116 |
type: int |
| 117 |
sample: 262144 |
| 118 |
nf_conntrack_tcp_timeout_established: |
| 119 |
description: Conntrack established timeout in seconds. |
| 120 |
returned: on success |
| 121 |
type: int |
| 122 |
sample: 432000 |
| 123 |
nf_conntrack_tcp_timeout_syn_recv: |
| 124 |
description: Conntrack syn recv timeout in seconds. |
| 125 |
returned: on success |
| 126 |
type: int |
| 127 |
sample: 60 |
| 128 |
protection_synflood: |
| 129 |
description: Whether synflood protection is enabled. |
| 130 |
returned: on success |
| 131 |
type: bool |
| 132 |
sample: false |
| 133 |
protection_synflood_burst: |
| 134 |
description: Synflood protection rate burst by IP source address. |
| 135 |
returned: on success |
| 136 |
type: int |
| 137 |
sample: 1000 |
| 138 |
protection_synflood_rate: |
| 139 |
description: Synflood protection rate syn/sec by IP source address. |
| 140 |
returned: on success |
| 141 |
type: int |
| 142 |
sample: 200 |
| 143 |
""" |
| 144 |
|
| 145 |
from ansible.module_utils.common.text.converters import to_native |
| 146 |
|
| 147 |
from ansible_collections.community.proxmox.plugins.module_utils.proxmox import ( |
| 148 |
ProxmoxAnsible, |
| 149 |
create_proxmox_module, |
| 150 |
) |
| 151 |
from ansible_collections.community.proxmox.plugins.module_utils.proxmox_node_firewall import ( |
| 152 |
node_firewall_options_to_ansible_result, |
| 153 |
) |
| 154 |
|
| 155 |
|
| 156 |
def module_args(): |
| 157 |
return dict( |
| 158 |
node_name=dict(aliases=["node"], type="str", required=True), |
| 159 |
) |
| 160 |
|
| 161 |
|
| 162 |
def module_options(): |
| 163 |
return {} |
| 164 |
|
| 165 |
|
| 166 |
class ProxmoxNodeFirewallAnsible(ProxmoxAnsible): |
| 167 |
def __init__(self, module): |
| 168 |
super().__init__(module) |
| 169 |
self.params = module.params |
| 170 |
|
| 171 |
def run(self): |
| 172 |
current_raw = self._fetch_firewall_options() |
| 173 |
current = self._format_options(current_raw) |
| 174 |
self.module.exit_json( |
| 175 |
changed=False, |
| 176 |
**current, |
| 177 |
) |
| 178 |
|
| 179 |
def _fetch_firewall_options(self): |
| 180 |
try: |
| 181 |
return self.proxmox_api.nodes(self.params["node_name"]).firewall().options.get() |
| 182 |
except Exception as e: |
| 183 |
self.module.fail_json(msg=f"Failed to retrieve node firewall options: {to_native(e)}") |
| 184 |
|
| 185 |
def _format_options(self, raw): |
| 186 |
return node_firewall_options_to_ansible_result(self.params["node_name"], raw) |
| 187 |
|
| 188 |
|
| 189 |
def main(): |
| 190 |
module = create_proxmox_module(module_args(), **module_options()) |
| 191 |
proxmox = ProxmoxNodeFirewallAnsible(module) |
| 192 |
|
| 193 |
proxmox.run() |
| 194 |
|
| 195 |
|
| 196 |
if __name__ == "__main__": |
| 197 |
main() |