salt.states.firewalld#
Management of firewalld
New in version 2015.8.0.
The following example applies changes to the public zone, blocks echo-reply and echo-request packets, does not set the zone to be the default, enables masquerading, and allows ports 22/tcp and 25/tcp. It will be applied permanently and directly before restart/reload.
public:
firewalld.present:
- name: public
- block_icmp:
- echo-reply
- echo-request
- default: False
- masquerade: True
- ports:
- 22/tcp
- 25/tcp
The following example applies changes to the public zone, enables masquerading and configures port forwarding TCP traffic from port 22 to 2222, and forwards TCP traffic from port 80 to 443 at 192.168.0.1.
my_zone:
firewalld.present:
- name: public
- masquerade: True
- port_fwd:
- 22:2222:tcp
- 80:443:tcp:192.168.0.1
The following example binds the public zone to interface eth0 and to all packets coming from the 192.168.1.0/24 subnet. It also removes the zone from all other interfaces or sources.
public:
firewalld.present:
- name: public
- interfaces:
- eth0
- sources:
- 192.168.1.0/24
Here, we define a new service that encompasses TCP ports 4505 4506:
saltmaster:
firewalld.service:
- name: saltmaster
- ports:
- 4505/tcp
- 4506/tcp
To make this new service available in a zone, the following can be used, which would allow access to the salt master from the 10.0.0.0/8 subnet:
saltzone:
firewalld.present:
- name: saltzone
- services:
- saltmaster
- sources:
- 10.0.0.0/8
Another way of implementing the same rule above using rich rules is demonstrated here:
saltzone:
firewalld.present:
- name: saltzone
- rich_rules:
- rule service name="saltmaster" accept
- sources:
- 10.0.0.0/8
The format of rich rules is the same as:
firewall-cmd --list-rich-rules
with an example output of:
rule protocol value="icmp" accept
rule protocol value="ipv6-icmp" accept
rule service name="snmp" accept
Here, we define a new ipset that include 1.1.1.1/32 and 8.8.8.8/32:
saltmaster:
firewalld.ipset_present:
- name: ipset_salt
- ipset_type: hash:net
- entries:
- 1.1.1.1/32
- 8.8.8.8/32
- class salt.states.firewalld.ForwardingMapping(srcport, destport, protocol, destaddr)#
Represents a port forwarding statement mapping a local port to a remote port for a specific protocol (TCP or UDP)
- todict()#
Returns a pretty dictionary meant for command line output.
- salt.states.firewalld.ipset_absent(name)#
Ensure the ipset is absent.
- name
The ipset to delete.
Example:
remove_old_ipset: firewalld.ipset_absent: - name: ipset_salt
- salt.states.firewalld.ipset_present(name, ipset_type, family=None, options=None, entries=None)#
Ensure the ipset exists and encompasses the specified entries.
- name
The ipset to modify.
- ipset_type
Ipset type, please see: firewall-cmd --get-ipset-types.
- family: None
Address family, can be inet or inet6.
- options: None
List of options to add to the ipset, can be timeout, maxelen or hashsize.
- entries: None
Entries the ipset must contain; others are removed. If omitted, entries are not managed. Use
[]for an empty ipset.
Example:
ipset_salt: firewalld.ipset_present: - name: ipset_salt - ipset_type: hash:net - family: inet - options: timeout: 0 - entries: - 1.1.1.1/32 - 8.8.8.8/32
- salt.states.firewalld.present(name, target=None, block_icmp=None, prune_block_icmp=False, default=None, masquerade=None, ports=None, prune_ports=False, port_fwd=None, prune_port_fwd=False, services=None, prune_services=False, interfaces=None, prune_interfaces=False, sources=None, prune_sources=False, rich_rules=None, prune_rich_rules=False)#
Ensure a zone has specific attributes. Alias to zone_present.
- name
The zone to modify.
- target: None
Set the target zone, zones target is one of: default, ACCEPT, DROP, REJECT.
- default: None
Set this zone as the default zone if
True.- masquerade: None
Enable or disable masquerade for a zone. By default it will not change it.
- block_icmp: None
List of ICMP types to block in the zone.
- prune_block_icmp: False
If
True, remove all but the specified block_icmp from the zone.- ports: None
List of ports to add to the zone.
- prune_ports: False
If
True, remove all but the specified ports from the zone.- port_fwd: None
List of port forwards to add to the zone.
- prune_port_fwd: False
If
True, remove all but the specified port_fwd from the zone.- services: None
List of services to add to the zone.
- prune_services: False
If
True, remove all but the specified services from the zone. .. note:: Currently defaults to True for compatibility, but will be changed to False in a future release.- interfaces: None
List of interfaces to add to the zone.
- prune_interfaces: False
If
True, remove all but the specified interfaces from the zone.- sources: None
List of sources to add to the zone.
- prune_sources: False
If
True, remove all but the specified sources from the zone.- rich_rules: None
List of rich rules to add to the zone.
- prune_rich_rules: False
If
True, remove all but the specified rich rules from the zone.
Example:
public: firewalld.present: - name: public - default: False - masquerade: True - ports: - 22/tcp - 25/tcp
- salt.states.firewalld.service(name, ports=None, protocols=None)#
Ensure the service exists and encompasses the specified ports and protocols. Alias to service_present.
New in version 2016.11.0.
- name
The service to modify.
- ports: None
List of ports to add to the service.
- protocols: None
List of protocols to add to the service.
Example:
saltmaster: firewalld.service: - name: saltmaster - ports: - 4505/tcp - 4506/tcp - protocols: - igmp
- salt.states.firewalld.service_absent(name)#
Ensure the service does not exists.
- name
The service to delete.
Example:
remove_old_service: firewalld.service_absent: - name: saltmaster
- salt.states.firewalld.service_present(name, ports=None, protocols=None)#
Ensure the service exists and encompasses the specified ports and protocols.
- name
The service to modify.
- ports: None
List of ports to add to the service.
- protocols: None
List of protocols to add to the service.
Example:
saltmaster: firewalld.service_present: - name: saltmaster - ports: - 4505/tcp - 4506/tcp - protocols: - igmp
- salt.states.firewalld.zone_absent(name)#
Ensure the zone does not exists.
- name
The zone to delete.
Example:
remove_old_zone: firewalld.zone_absent: - name: saltzone
- salt.states.firewalld.zone_present(name, target=None, block_icmp=None, prune_block_icmp=False, default=None, masquerade=None, ports=None, prune_ports=False, port_fwd=None, prune_port_fwd=False, services=None, prune_services=None, interfaces=None, prune_interfaces=False, sources=None, prune_sources=False, rich_rules=None, prune_rich_rules=False)#
Ensure a zone has specific attributes.
- name
The zone to modify.
- target: None
Set the target zone, zones target is one of: default, ACCEPT, DROP, REJECT.
- default: None
Set this zone as the default zone if
True.- masquerade: None
Enable or disable masquerade for a zone. By default it will not change it.
- block_icmp: None
List of ICMP types to block in the zone.
- prune_block_icmp: False
If
True, remove all but the specified block_icmp from the zone.- ports: None
List of ports to add to the zone.
- prune_ports: False
If
True, remove all but the specified ports from the zone.- port_fwd: None
List of port forwards to add to the zone.
- prune_port_fwd: False
If
True, remove all but the specified port_fwd from the zone.- services: None
List of services to add to the zone.
- prune_services: False
If
True, remove all but the specified services from the zone. .. note:: Currently defaults to True for compatibility, but will be changed to False in a future release.- interfaces: None
List of interfaces to add to the zone.
- prune_interfaces: False
If
True, remove all but the specified interfaces from the zone.- sources: None
List of sources to add to the zone.
- prune_sources: False
If
True, remove all but the specified sources from the zone.- rich_rules: None
List of rich rules to add to the zone.
- prune_rich_rules: False
If
True, remove all but the specified rich rules from the zone.
Example:
public: firewalld.zone_present: - name: public - default: False - masquerade: True - ports: - 22/tcp - 25/tcp