Skip to content

Commit 96c5727

Browse files
feat: define, modify, and remove ipsets (#166)
* feat: define, modify, and remove ipsets User can specify `state: present` or `state: absent` and `permanent:true` with new ipset arguments to configure ipsets for use in zones using the `source` argument - firewall_lib.py - new argument: ipset - name of ipset - new argument: ipset_type - type of ipset - new argument: ipset_entry - contents of ipset - protections against failure in check mode when enabling and disabling ipsets for zones - new file: tests/tests_ipsets.yml - tests user defined ipsets (create, modify, delete, use) - tests: unit: new test cases for triggering ipset warnings and errors - docs: README, firewall_lib DOCUMENTATION for ipset feature * Update README.md Typo "--get-icmp-types" to "--get-ipset-types" Co-authored-by: Richard Megginson <richm@stanfordalumni.org> --------- Co-authored-by: Richard Megginson <richm@stanfordalumni.org>
1 parent f5a6d46 commit 96c5727

File tree

5 files changed

+872
-33
lines changed

5 files changed

+872
-33
lines changed

README.md

Lines changed: 105 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,70 @@ defining services for runtime configuration is not supported by firewalld
354354

355355
For more information about custom services, see https://firewalld.org/documentation/man-pages/firewalld.service.html
356356

357+
### ipset
358+
359+
Name of the ipset being created, modified, or removed.
360+
Use `source` to add and remove ipsets from a zone
361+
362+
When creating an ipset, you must also specify `ipset_type`,
363+
and optionally `short`, `description`, `ipset_entries`
364+
365+
Defining an ipset with all optional fields:
366+
```yaml
367+
firewall:
368+
- ipset: customipset
369+
ipset_type: "hash:ip"
370+
short: Custom IPSet
371+
description: set of ip addresses specified in entries
372+
ipset_entries:
373+
- 1.1.1.1
374+
- 2.2.2.2
375+
- 3.3.3.3
376+
- 8.8.8.8
377+
- 127.0.0.1
378+
state: present
379+
permanent: true
380+
```
381+
382+
Adding an entry to an existing ipset
383+
```yaml
384+
firewall:
385+
- ipset: customipset
386+
ipset_entries:
387+
- 127.0.0.2
388+
state: present
389+
permanent: true
390+
```
391+
392+
Changing the short and description of an ipset
393+
```yaml
394+
firewall:
395+
- ipset: customipset
396+
short: Custom
397+
description: Set of IPv4 addresses
398+
state: present
399+
permanent: true
400+
```
401+
402+
Removing entries from an ipset
403+
```yaml
404+
firewall:
405+
- ipset: customipset
406+
ipset_entries:
407+
- 127.0.0.1
408+
- 127.0.0.2
409+
state: absent
410+
permanent: true
411+
```
412+
413+
Removing an ipset
414+
```yaml
415+
firewall:
416+
- ipset: customipset
417+
state: absent
418+
permanent: true
419+
```
420+
357421
### port
358422

359423
Port or port range or a list of them to add or remove inbound access to. It
@@ -364,6 +428,36 @@ port: '443/tcp'
364428
port: ['443/tcp','443/udp']
365429
```
366430
431+
### ipset_type
432+
433+
Type of ipset being defined.
434+
Used with `ipset`.
435+
436+
For a list of available ipset types, run `firewall-cmd --get-ipset-types`,
437+
there is no method to get supported types from this role.
438+
439+
```yaml
440+
ipset: customipset
441+
ipset_type: hash:mac
442+
```
443+
444+
See `ipset` for more usage information
445+
446+
### ipset_entries
447+
List of addresses to add or remove from an ipset
448+
Used with `ipset`
449+
450+
Entrys must be compatible with the ipset type of the `ipset`
451+
being created or modified.
452+
453+
```yaml
454+
ipset: customipset
455+
ipset_entries:
456+
- 127.0.0.1
457+
```
458+
459+
See `ipset` for more usage information
460+
367461
### source_port
368462

369463
Port or port range or a list of them to add or remove source port access to. It
@@ -427,7 +521,7 @@ rich_rule: rule service name="ftp" audit limit value="1/m" accept
427521
428522
### source
429523
430-
List of source address or address range strings. A source address or address
524+
List of source address address range strings, or ipsets. A source address or address
431525
range is either an IP address or a network IP address with a mask for IPv4 or
432526
IPv6. For IPv4, the mask can be a network mask or a plain number. For IPv6 the
433527
mask is a plain number.
@@ -436,6 +530,12 @@ mask is a plain number.
436530
source: 192.0.2.0/24
437531
```
438532
533+
Ipsets are used with this option by prefixing "ipset:" to the name of the ipset
534+
535+
```yaml
536+
source: ipset:ipsetname
537+
```
538+
439539
### interface
440540

441541
String or list of interface name strings.
@@ -525,18 +625,18 @@ target: ACCEPT
525625
```
526626
### short
527627

528-
Short description, only usable when adding or modifying a service.
529-
See `service` for more usage information.
628+
Short description, only usable when defining or modifying a service or ipset.
629+
See `service` or `ipset` for more usage information.
530630

531631
```yaml
532-
short: WWW (HTTP)
632+
short: Short Description
533633
```
534634
535635
### description
536636
537637
Description for a service, only usable when adding a new service or
538638
modifying an existing service.
539-
See `service` for more information
639+
See `service` or `ipset` for more information
540640

541641
```yaml
542642
description: Your description goes here

0 commit comments

Comments
 (0)