From 6858f17766fcd6fd0f05c43393188b79d29be5e5 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Thu, 22 Oct 2020 17:57:02 +0200 Subject: Rework Ansible to support ipv6 --- os/config/roles/network/files/rules.v6 | 12 --------- os/config/roles/network/tasks/main.yml | 7 +++-- os/config/roles/network/templates/en.network | 9 +++++++ os/config/roles/network/templates/rules.v4 | 36 +++++++++++++++++++++++++ os/config/roles/network/templates/rules.v4.j2 | 36 ------------------------- os/config/roles/network/templates/rules.v6 | 38 +++++++++++++++++++++++++++ 6 files changed, 88 insertions(+), 50 deletions(-) delete mode 100644 os/config/roles/network/files/rules.v6 create mode 100644 os/config/roles/network/templates/en.network create mode 100644 os/config/roles/network/templates/rules.v4 delete mode 100644 os/config/roles/network/templates/rules.v4.j2 create mode 100644 os/config/roles/network/templates/rules.v6 (limited to 'os/config/roles/network') diff --git a/os/config/roles/network/files/rules.v6 b/os/config/roles/network/files/rules.v6 deleted file mode 100644 index 17ff71c..0000000 --- a/os/config/roles/network/files/rules.v6 +++ /dev/null @@ -1,12 +0,0 @@ -# WARNING!! When rules.{v4,v6} are changed, the whole iptables configuration is reloaded. -# This creates issues with Docker, which injects its own configuration in iptables when it starts. -# In practice, most (all?) containers will break if rules.{v4,v6} are changed, -# and docker will have to be restared. - - -*filter -:INPUT DROP [0:0] -:FORWARD DROP [0:0] -:OUTPUT ACCEPT [0:0] -COMMIT - diff --git a/os/config/roles/network/tasks/main.yml b/os/config/roles/network/tasks/main.yml index 1443e0c..caa6bff 100644 --- a/os/config/roles/network/tasks/main.yml +++ b/os/config/roles/network/tasks/main.yml @@ -1,8 +1,11 @@ - name: "Deploy iptablesv4 configuration" - template: src=rules.v4.j2 dest=/etc/iptables/rules.v4 + template: src=rules.v4 dest=/etc/iptables/rules.v4 - name: "Deploy iptablesv6 configuration" - copy: src=rules.v6 dest=/etc/iptables/rules.v6 + template: src=rules.v6 dest=/etc/iptables/rules.v6 + +- name: "Deploy systemd-networkd configuration" + template: src=en.network dest=/etc/systemd/network/en.network - name: "Activate IP forwarding" sysctl: diff --git a/os/config/roles/network/templates/en.network b/os/config/roles/network/templates/en.network new file mode 100644 index 0000000..b9b52e9 --- /dev/null +++ b/os/config/roles/network/templates/en.network @@ -0,0 +1,9 @@ +[Match] +Name={{ interface }} + +[Network] +Address={{ ipv4 }}/24 +Address={{ ipv6 }}/64 +Gateway=192.168.1.254 +DNS={{ ipv4 }} +DNS={{ dns_server }} diff --git a/os/config/roles/network/templates/rules.v4 b/os/config/roles/network/templates/rules.v4 new file mode 100644 index 0000000..159f5f7 --- /dev/null +++ b/os/config/roles/network/templates/rules.v4 @@ -0,0 +1,36 @@ +*filter +:INPUT DROP [0:0] +:FORWARD DROP [0:0] +:OUTPUT ACCEPT [0:0] + +# Debug +-A INPUT -p icmp -j ACCEPT + +# Administration +-A INPUT -p tcp --dport 22 -j ACCEPT + +# Cluster +{% for selected_host in groups['cluster_nodes'] %} +-A INPUT -s {{ hostvars[selected_host]['ipv4'] }} -j ACCEPT +{% endfor %} + +# Local +-A INPUT -i docker0 -j ACCEPT +-A INPUT -s 127.0.0.1/8 -j ACCEPT +-A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT +COMMIT + +*nat +:PREROUTING ACCEPT [0:0] +:INPUT ACCEPT [0:0] +:OUTPUT ACCEPT [0:0] +:POSTROUTING ACCEPT [0:0] +COMMIT + +*mangle +:PREROUTING ACCEPT [0:0] +:INPUT ACCEPT [0:0] +:FORWARD ACCEPT [0:0] +:OUTPUT ACCEPT [0:0] +:POSTROUTING ACCEPT [0:0] +COMMIT diff --git a/os/config/roles/network/templates/rules.v4.j2 b/os/config/roles/network/templates/rules.v4.j2 deleted file mode 100644 index a446139..0000000 --- a/os/config/roles/network/templates/rules.v4.j2 +++ /dev/null @@ -1,36 +0,0 @@ -*filter -:INPUT DROP [0:0] -:FORWARD DROP [0:0] -:OUTPUT ACCEPT [0:0] - -# Administration --A INPUT -p tcp --dport 22 -j ACCEPT - -# Cluster --A INPUT -s 192.168.1.254 -j ACCEPT --A INPUT -s 82.253.205.190 -j ACCEPT -{% for selected_host in groups['cluster_nodes'] %} --A INPUT -s {{ hostvars[selected_host]['public_ip'] }} -j ACCEPT --A INPUT -s {{ hostvars[selected_host]['private_ip'] }} -j ACCEPT -{% endfor %} - -# Local --A INPUT -i docker0 -j ACCEPT --A INPUT -s 127.0.0.1/8 -j ACCEPT --A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT -COMMIT - -*nat -:PREROUTING ACCEPT [0:0] -:INPUT ACCEPT [0:0] -:OUTPUT ACCEPT [0:0] -:POSTROUTING ACCEPT [0:0] -COMMIT - -*mangle -:PREROUTING ACCEPT [0:0] -:INPUT ACCEPT [0:0] -:FORWARD ACCEPT [0:0] -:OUTPUT ACCEPT [0:0] -:POSTROUTING ACCEPT [0:0] -COMMIT diff --git a/os/config/roles/network/templates/rules.v6 b/os/config/roles/network/templates/rules.v6 new file mode 100644 index 0000000..7365b8a --- /dev/null +++ b/os/config/roles/network/templates/rules.v6 @@ -0,0 +1,38 @@ +*filter +:INPUT DROP [0:0] +:FORWARD DROP [0:0] +:OUTPUT ACCEPT [0:0] + +# Debug +-A INPUT -p icmp -j ACCEPT + +# Administration +-A INPUT -p tcp --dport 22 -j ACCEPT + +# Cluster +{% for selected_host in groups['cluster_nodes'] %} +-A INPUT -s {{ hostvars[selected_host]['ipv6'] }} -j ACCEPT +{% endfor %} + +# Local +-A INPUT -i docker0 -j ACCEPT +-A INPUT -s ::1/128 -j ACCEPT +-A INPUT -m conntrack --cstate ESTABLISHED,RELATED -j ACCEPT + +COMMIT + +*nat +:PREROUTING ACCEPT [0:0] +:INPUT ACCEPT [0:0] +:OUTPUT ACCEPT [0:0] +:POSTROUTING ACCEPT [0:0] +COMMIT + +*mangle +:PREROUTING ACCEPT [0:0] +:INPUT ACCEPT [0:0] +:FORWARD ACCEPT [0:0] +:OUTPUT ACCEPT [0:0] +:POSTROUTING ACCEPT [0:0] +COMMIT + -- cgit v1.2.3