Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for setting the default firewalld zone #296

Open
jwatt opened this issue Nov 20, 2021 · 3 comments
Open

Support for setting the default firewalld zone #296

jwatt opened this issue Nov 20, 2021 · 3 comments
Labels
feature This issue/PR relates to a feature request. verified This issue has been verified/reproduced by maintainer waiting_on_contributor Needs help. Feel free to engage to get things unblocked

Comments

@jwatt
Copy link

jwatt commented Nov 20, 2021

SUMMARY

Unless I'm missing something in the docs for the firewalld module, it is possible to create zones but not to set the default zone. I guess this can be worked around by using a command with firewall-cmd --set-default-zone=<zone> but it would be cleaner if the firewalld module supported this.

ISSUE TYPE
  • Feature Idea
COMPONENT NAME

ansible.posix.firewalld

ADDITIONAL INFORMATION

I'd like to use ansible to create a new zone and set it as the default.

@saito-hideki saito-hideki added feature This issue/PR relates to a feature request. needs_triage Needs a first human triage before being processed. verified This issue has been verified/reproduced by maintainer waiting_on_contributor Needs help. Feel free to engage to get things unblocked and removed needs_triage Needs a first human triage before being processed. labels Nov 22, 2021
@saito-hideki
Copy link
Collaborator

@jwatt indeed. thank you for the feature request! :)

@nodiscc
Copy link

nodiscc commented Dec 11, 2021

The correct solution solution to this, is probably to edit the main firewalld.conf configuration file, since the default zone is explicitly defined in this file:

$ sudo head -n6 /etc/firewalld/firewalld.conf
# firewalld config file

# default zone
# The default zone used if an empty zone string is used.
# Default: public
DefaultZone=public

I don't think this should be handled by the firewalld module. template or lineinfile are sufficient.

@gnfzdz
Copy link
Contributor

gnfzdz commented Dec 14, 2022

@jwatt @saito-hideki This should be pretty trivial to implement so I'm open to raising a pull request. Even ignoring the simple alternative mentioned by @nodiscc though, there are a few quirks that give me pause.

  1. At least with firewall-cmd, the change appears to be applied both immediate and permanent, regardless of whether the --permanent argument is actually passed. Assuming that's a fundamental limitation of the underlying firewalld python library (which I haven't confirmed yet), we could guard against misuse here by returning an error if an invalid combination of immediate/permanent is actually passed. The same pattern is currently used when adding/removing a zone.
  2. More importantly, I'm not sure there's an obvious api for this feature that feels consistent with the rest of the module. Assuming state remains a required parameter, how should the negative values be interpreted?

Options for the positive case seem pretty straightforward

- ansible.posix.firewalld:
    zone: custom
    default: True
    state: enabled

- ansible.posix.firewalld:
    default_zone: custom
    state: enabled

But if default zone is already 'custom', how should these cases behave?

One option would be to switch back to the upstream default (public)? Alternatively, the negative cases could just be ignored (and documented accordingly).

- ansible.posix.firewalld:
    zone: custom
    default: True
    state: disabled

- ansible.posix.firewalld:
    zone: custom
    default: False
    state: enabled

- ansible.posix.firewalld:
    default_zone: custom
    state: disabled

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature This issue/PR relates to a feature request. verified This issue has been verified/reproduced by maintainer waiting_on_contributor Needs help. Feel free to engage to get things unblocked
Projects
None yet
Development

No branches or pull requests

4 participants