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

Extending rules template to support ORIGINAL DEST #19

Closed
apiening opened this issue May 6, 2020 · 7 comments
Closed

Extending rules template to support ORIGINAL DEST #19

apiening opened this issue May 6, 2020 · 7 comments

Comments

@apiening
Copy link

apiening commented May 6, 2020

I have the requirement to set the field ORIGINAL DEST in /etc/shorewall/rules in order to be able to match specific target IP's on a server.
This field is the seventh parameter in a rule definition, right after SOURCE PORT(S) which is also not filled by the current template.

As far as I see, there is just the line nr. 6 in templates/etc/shorewall/rules.j2 to be modified in order to achieve this:

{{ rule.action }}   {{ rule.source }}   {{ rule.dest }}   {{ rule.proto }}   {{ rule.dest_ports|join (',') }}   {{ rule.source_ports|join (',') }}   {{ rule.original_dest }}

Another idea (that has also been addressed in the pull request #18) is to add support for comments.

This could be done by adding these three lines right before the rule line inside the loop:

{% if rule.comment|length %}
#{{ rule.comment }}
{% endif %}

Of course this is not a issue, it is more a suggestion. I think it would be easy to apply and should not break something because if the variables are empty the template expands to the same rule line.
What do you think?

Btw. just want to say thank you for your ansible role. It is the most often used role in my playbooks.

@rogerniesten
Copy link

rogerniesten commented May 7, 2020 via email

@apiening
Copy link
Author

apiening commented May 7, 2020

I’ve added the comment by changing the affected in in the roles.j2 template: {{ rule.action }} {{ rule.source }} {{ rule.dest }} {{ rule.proto }} {{ rule.dest_ports|join (',') }} {% if rule.comments is defined %}# {{ rule.comments }} {% endif %} When comments field is added tot the dictionary, it will be added to the rules file.

Hi Roger,
which rules.j2 template did you update? Can't see the change in the master branch and this seems to be the only branch.

I would prefer the optional comment on top of the rule line instead at the end, especially when a lot of options are set (like the suggested ORIGINAL DEST field) the rules get pretty long which makes them harder to read with a comment at the end that would potentially be wrapped to a new line by the editor. But that's just cosmetics.

What about merging these changes into master?

@rogerniesten
Copy link

rogerniesten commented May 7, 2020 via email

@apiening
Copy link
Author

apiening commented May 7, 2020

Hi Roger,

ok I see.

If the extension to support ORIGINAL DEST is not merged, I would need to create a fork because I really need this setting to manage more complex rules on a few systems.
The best option from my perspective is to have one central repository for this role which is updated and improved over time, compared to end up with several forks with feature fragmentation.

@mrlesmithjr What do you think? Is it possible to update the rules.j2 template file, or would you prefer a pull request?

With kind regards

Andreas

@mrlesmithjr
Copy link
Owner

@apiening @rogerniesten Glad both of you are getting some use out of this role. And I'd absolutely be open to any pull requests to add additional functionality, etc.

@apiening
Copy link
Author

@mrlesmithjr Thank you. I've just committed a pull request (#20).

I have commented the change in the PR and only one file is affected (rules.j2).
I tried to make sure that the changes does not affect the content of the rule file when the new fields are unset by using defaults for the rule line. So I can't see a situation where this change might break the config with existing config-variables.
I did some tests with shorewall 5.1.12.2 on Ubuntu 18.04.4 LTS and shorewall 5.2.3.4 on Ubuntu 20.04 LTS without any issues.

I would be happy if you would accept the PR or discuss if anything is unclear or need to be changed.

@apiening
Copy link
Author

Since the PR has been merged into master, I'm closing this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants