Skip to content

enhance firewalld modules and states with ipset, zone_absent, service_absent#67790

Open
remijouannet wants to merge 4 commits into
saltstack:masterfrom
remijouannet:firewalld-ipset
Open

enhance firewalld modules and states with ipset, zone_absent, service_absent#67790
remijouannet wants to merge 4 commits into
saltstack:masterfrom
remijouannet:firewalld-ipset

Conversation

@remijouannet

@remijouannet remijouannet commented Mar 6, 2025

Copy link
Copy Markdown
Contributor

enhance firewalld modules and states with ipset, zone_absent, service_absent

What does this PR do?

  • Add service_absent and service_present, service become an alias to service_present
  • Add zone_absent and zone_present, present become an alias to zone_present
  • Add ipset_absent and ipset_present with necessary functions in firewalld module
  • add option to some functions to skip check in order to speed up executions
  • Add target option to zone_present

Merge requirements satisfied?

[NOTICE] Bug fixes or features added to Salt require tests.

Commits signed with GPG?

No

@remijouannet

Copy link
Copy Markdown
Contributor Author

states that i've used to test my changes

firewalld:
  pkg.installed

firewalld_service:
  service.running:
    - name: firewalld
    - enable: True

service_http0:
  firewalld.service_present:
    - name: http0
    - ports:
      - 8000/tcp

service_http1:
  firewalld.service_present:
    - name: http1
    - ports:
      - 8000/tcp

service_http2:
  firewalld.service:
    - name: http2
    - ports:
      - 8000/tcp

ipset_adm:
  firewalld.ipset_present:
    - name: adm
    - ipset_type: hash:net
    - entries:
      - 10.0.0.0/24

ipset_svc1:
  firewalld.ipset_present:
    - name: svc1
    - ipset_type: hash:net
    - entries:
      - 10.0.1.0/24

ipset_svc2:
  firewalld.ipset_present:
    - name: svc2
    - ipset_type: hash:net
    - entries:
      - 10.0.2.0/24

ipset_svc3:
  firewalld.ipset_present:
    - name: svc3
    - ipset_type: hash:net
    - entries:
      - 10.0.3.0/24

zone_svc1:
  firewalld.zone_present:
    - name: test1
    - target: DROP
    - interfaces:
      - eth0
    - prune_rich_rules: True
    - rich_rules:
      - rule protocol value="icmp" accept
      - rule service name="ssh" accept
      - rule family="ipv4" source ipset="adm" accept
      - rule family="ipv4" source ipset="svc1" accept
      - rule family="ipv4" source ipset="svc3" service name="http0" accept

test_ipset:
  firewalld.ipset_absent:
    - name: test1
firewalld:
  pkg.installed

firewalld_service:
  service.running:
    - name: firewalld
    - enable: True

zone_svc4:
  firewalld.zone_absent:
    - name: test2

zone_svc1:
  firewalld.zone_absent:
    - name: test1

service_http0:
  firewalld.service_absent:
    - name: http0

service_http1:
  firewalld.service_absent:
    - name: http0

service_http2:
  firewalld.service_absent:
    - name: http0

ipset_adm:
  firewalld.ipset_absent:
    - name: adm

ipset_svc1:
  firewalld.ipset_absent:
    - name: svc1

ipset_svc2:
  firewalld.ipset_absent:
    - name: svc2

ipset_svc3:
  firewalld.ipset_absent:
    - name: svc3

test_ipset:
  firewalld.ipset_absent:
    - name: test1

firewalld:
  pkg.installed

firewalld_service:
  service.running:
    - name: firewalld
    - enable: True

service_http0:
  firewalld.service_present:
    - name: http0
    - ports:
      - 8000/tcp

service_http1:
  firewalld.service_absent:
    - name: http1

service_http2:
  firewalld.service:
    - name: http2
    - ports:
      - 8001/tcp

ipset_adm:
  firewalld.ipset_present:
    - name: adm
    - ipset_type: hash:net
    - entries:
      - 10.0.0.0/24
      - 10.2.0.0/24

ipset_svc1:
  firewalld.ipset_present:
    - name: svc1
    - ipset_type: hash:net
    - entries:
      - 10.0.1.0/24

ipset_svc2:
  firewalld.ipset_absent:
    - name: svc2

ipset_svc3:
  firewalld.ipset_present:
    - name: svc3
    - ipset_type: hash:net
    - entries:
      - 10.0.3.0/24

zone_svc1:
  firewalld.zone_present:
    - name: test2
    - target: DROP
    - interfaces:
      - eth0
    - prune_rich_rules: True
    - rich_rules:
      - rule protocol value="icmp" accept
      - rule service name="ssh" accept
      - rule family="ipv4" source ipset="adm" accept
      - rule family="ipv4" source ipset="svc1" accept
      - rule family="ipv4" source ipset="svc3" service name="http0" accept

@twangboy twangboy left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will also need a changelog and some tests for the module and the state.

Comment thread salt/modules/firewalld.py

.. code-block:: bash

salt '*' firewalld.get_ipsets

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

firewalld.info_ipset

Comment thread salt/modules/firewalld.py

def get_target(zone):
"""
Get zone's target

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please document the arguments as well.

Comment thread salt/modules/firewalld.py

def set_target(zone, target, permanent=True):
"""
Set zone's target

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These arguments also need to be documented

Comment thread salt/modules/firewalld.py

def get_ipsets(permanent=True):
"""
Print predefined ipsets

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

permanent needs a docs entry

Comment thread salt/modules/firewalld.py

def info_ipset(ipset):
"""
Print ipset info

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

document the argument please

Comment thread salt/modules/firewalld.py

def new_ipset(ipset, ipset_type, family=None, options=None, restart=False):
"""
Add a new ipset

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

document these arguments

Comment thread salt/modules/firewalld.py

def delete_ipset(ipset, permanent=True, restart=True):
"""
Delete an existing ipset

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add some docs for these arguments

Comment thread salt/modules/firewalld.py

def add_ipset_entry(ipset, entry):
"""
Add an new entry to the specified ipset.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here as well

Comment thread salt/modules/firewalld.py

def remove_ipset_entry(ipset, entry):
"""
Remove an entry from the specified ipset.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and here

@twangboy twangboy added needs-testcase PR needs test cases written, or the issue is about a bug/feature that needs test cases needs-changelog test:full Run the full test suite labels Jul 2, 2025
@twangboy twangboy modified the milestones: Argon v3008.0, Argon v3008.1 Jun 5, 2026
@dwoz dwoz removed needs-testcase PR needs test cases written, or the issue is about a bug/feature that needs test cases needs-changelog labels Jun 19, 2026
@remijouannet

Copy link
Copy Markdown
Contributor Author

hello @dwoz, do you need some help for my MR ? i saw you've pushed some change

remijouannet and others added 4 commits June 28, 2026 14:44
…ent, and target

Add changelog/67790.added.md and unit tests for:
- firewalld.zone_absent state (exists, absent, test mode)
- firewalld.service_absent state (exists, absent)
- firewalld.ipset_absent state (exists, absent)
- firewalld.ipset_present state (create+entries, idempotent)
- firewalld.zone_present with target option (change, idempotent)
- firewalld module: get_target, set_target, get_ipsets, new_ipset,
  delete_ipset, add_ipset_entry, remove_ipset_entry, info_ipset
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

test:full Run the full test suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants