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

docker rules are flushed on each run #82

Open
zerr0s opened this issue Dec 9, 2020 · 11 comments
Open

docker rules are flushed on each run #82

zerr0s opened this issue Dec 9, 2020 · 11 comments
Labels

Comments

@zerr0s
Copy link

zerr0s commented Dec 9, 2020

Hello, forgive me for my bad english.

First, special thanks for your ansible roles. I use them everyday in my pipelines for all servers (dev, prod, etc.).
I'm trying this role to manage iptables rules over a ci/cd pipeline. On each run, all rules are removed on all servers and new rules are applied.

My servers have docker installed and all iptables rules added by docker are flushed and docker needs to be restarted.

Is there a way to apply new rules dynamically ?

Thanks.

@alexeychusta
Copy link

This role has an option "firewall_flush_rules_and_chains:"
But I found a bug where the rules are flushed anyway
#80

Therefore, I made a correction, and added options
firewall_flush_rules_input:
firewall_flush_rules_output:
firewall_flush_rules_forward:
And excluded "iptables -F" from the service start template

To use Docker you need to add
firewall_flush_rules_forward: false
since docker adds its rules to the forward chain

you can use this role with my fixes https://github.com/alexeychusta/ansible-firewall

@zerr0s
Copy link
Author

zerr0s commented Dec 13, 2020

Hello. Thanks, i'll try it asap.

@geerlingguy
Copy link
Owner

I will likely be revamping this role a little bit to allow something similar, as this has bitten me in the past as well with Docker and this role side-by-side.

@stale
Copy link

stale bot commented Mar 15, 2021

This issue has been marked 'stale' due to lack of recent activity. If there is no further activity, the issue will be closed in another 30 days. Thank you for your contribution!

Please read this blog post to see the reasons why I mark issues as stale.

@stale stale bot added the stale label Mar 15, 2021
@stale
Copy link

stale bot commented Apr 15, 2021

This issue has been closed due to inactivity. If you feel this is in error, please reopen the issue or file a new issue with the relevant details.

@stale stale bot closed this as completed Apr 15, 2021
@geerlingguy geerlingguy reopened this Apr 16, 2021
@stale
Copy link

stale bot commented Apr 16, 2021

This issue is no longer marked for closure.

1 similar comment
@stale
Copy link

stale bot commented Apr 16, 2021

This issue is no longer marked for closure.

@stale stale bot removed the stale label Apr 16, 2021
@renepardon
Copy link

Hey @geerlingguy

since mikegleasonjr/ansible-role-firewall is no longer maintained I will use your role and my first thing I was looking for was the same behaviour with docker since mikegleasonjr/ansible-role-firewall was also flushing existing rules.

So what's the current state? Is there something we can do to make this feature available asap?

@renepardon
Copy link

Btw. maybe it helps someone:
I restart docker/fail2ban services right after updating the iptable rules so the chains will be recreated from those daemons.

- hosts: all
  become: yes
  become_user: root
  pre_tasks:
    - include: tasks/pre/load_vars.yml
  roles:
    - role: community/firewall
  tasks:
    - name: Populate service facts
      ansible.builtin.service_facts:

    - name: Restart docker to revert iptables chains
      ansible.builtin.service:
        name: docker
        state: restarted
      when: ansible_facts.services["docker.service"] is defined

    - name: Restart fail2ban to revert iptables chains
      ansible.builtin.service:
        name: fail2ban
        state: restarted
      when: ansible_facts.services["fail2ban.service"] is defined

@vitabaks
Copy link

PR (for compatibility with docker): #106

@hth2
Copy link

hth2 commented Jun 5, 2024

thanks @renepardon for the hint.

I did the following to restart docker and fail2ban when firewall is restarted:

  • change handler restart firewall:
---
- name: restart firewall
  service: name=firewall state=restarted
  register: reg_firewall_restarted
  • playbook:
  roles:
    - role: geerlingguy.firewall

  post_tasks:
  - meta: flush_handlers

  - name: Populate service facts
    ansible.builtin.service_facts:

  - name: Restart docker to revert iptables chains
    ansible.builtin.service:
      name: docker
      state: restarted
    when: ansible_facts.services["docker.service"] is defined and reg_firewall_restarted is defined

  - name: Restart fail2ban to revert iptables chains
    ansible.builtin.service:
      name: fail2ban
      state: restarted
    when: ansible_facts.services["fail2ban.service"] is defined and reg_firewall_restarted is defined

I want to avoid making change to the handler, but don't know a better way

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

No branches or pull requests

6 participants