Import firewall role from network repo
Move, actually.
This commit is contained in:
parent
88061d97b2
commit
754c3da31f
21 changed files with 801 additions and 1 deletions
59
roles/firewall/tasks/config.yml
Normal file
59
roles/firewall/tasks/config.yml
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
- name: Install packages for config updates
|
||||
package:
|
||||
name: tar
|
||||
|
||||
- name: Limit SSH for config updates
|
||||
copy:
|
||||
dest: /etc/ssh/
|
||||
src: sshd_config.friwall
|
||||
notify: reload sshd.friwall
|
||||
|
||||
- name: Create SSH service for config updates
|
||||
file:
|
||||
path: /etc/init.d/sshd.friwall
|
||||
src: /etc/init.d/sshd
|
||||
state: link
|
||||
|
||||
- name: Configure SSH service for config updates
|
||||
copy:
|
||||
dest: /etc/conf.d/sshd.friwall
|
||||
content: |
|
||||
cfgfile="/etc/ssh/sshd_config.friwall"
|
||||
vrf="default"
|
||||
notify: restart sshd.friwall
|
||||
|
||||
- name: Enable SSH service for config updates
|
||||
service:
|
||||
name: sshd.friwall
|
||||
enabled: yes
|
||||
state: started
|
||||
|
||||
- name: Install config updater
|
||||
copy:
|
||||
dest: /usr/local/bin/
|
||||
src: update
|
||||
mode: 0700
|
||||
|
||||
- name: Get master SSH key
|
||||
delegate_to: '{{ master }}'
|
||||
command: "cat ~friwall/.ssh/id_ed25519.pub"
|
||||
register: master_key
|
||||
changed_when: false
|
||||
|
||||
- name: Deploy master key on node
|
||||
authorized_key: "user=root key={{ master_key.stdout }}"
|
||||
|
||||
- name: Get my host SSH key
|
||||
slurp:
|
||||
src: /etc/ssh/ssh_host_ed25519_key.pub
|
||||
register: node_key
|
||||
|
||||
- name: Introduce myself to master
|
||||
delegate_to: '{{ master }}'
|
||||
become: yes
|
||||
become_user: friwall
|
||||
become_method: su
|
||||
become_flags: "-s /bin/sh" # no login shell for user
|
||||
known_hosts:
|
||||
name: "{{ inventory_hostname }}"
|
||||
key: "{{ inventory_hostname }},{{ interfaces | selectattr('name', '==', 'lo') | map(attribute='ip_addresses') | first | selectattr('role') | selectattr('role.value', '==', 'loopback') | map(attribute='address') | ipv4 | first | ipaddr('address') }} {{ node_key.content | b64decode }}" # TODO make IP retrieval less terrifying
|
||||
36
roles/firewall/tasks/conntrackd.yml
Normal file
36
roles/firewall/tasks/conntrackd.yml
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
- name: Install conntrack-tools
|
||||
package:
|
||||
name: conntrack-tools
|
||||
|
||||
# Ensure the module is loaded before setting sysctl values.
|
||||
- name: Autoload nf_conntrack
|
||||
lineinfile:
|
||||
dest: /etc/modules-load.d/netfilter.conf
|
||||
line: nf_conntrack
|
||||
create: yes
|
||||
|
||||
# Set required sysctl values.
|
||||
- name: Set sysctl values for conntrackd
|
||||
copy:
|
||||
dest: /etc/sysctl.d/
|
||||
src: conntrackd.conf
|
||||
|
||||
- name: Set up conntrackd
|
||||
template:
|
||||
dest: /etc/conntrackd/conntrackd.conf
|
||||
src: conntrackd.conf.j2
|
||||
mode: 0644
|
||||
notify: restart conntrackd
|
||||
|
||||
- name: Run conntrackd in default VRF
|
||||
lineinfile:
|
||||
dest: /etc/conf.d/conntrackd
|
||||
line: 'vrf="default"'
|
||||
regexp: '^vrf='
|
||||
notify: restart conntrackd
|
||||
|
||||
- name: Enable conntrackd
|
||||
service:
|
||||
name: conntrackd
|
||||
enabled: yes
|
||||
state: started
|
||||
48
roles/firewall/tasks/frr.yml
Normal file
48
roles/firewall/tasks/frr.yml
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
- name: Enable sysctl service
|
||||
service:
|
||||
name: sysctl
|
||||
enabled: yes
|
||||
runlevel: boot
|
||||
state: started
|
||||
|
||||
- name: Enable community package repo
|
||||
lineinfile:
|
||||
path: /etc/apk/repositories
|
||||
regexp: '^# *(http.*/v[^/]*/community)'
|
||||
line: '\1'
|
||||
backrefs: yes
|
||||
|
||||
- name: Install FRR
|
||||
package:
|
||||
name: frr,frr-pythontools
|
||||
state: latest
|
||||
|
||||
- name: Set datacenter defaults
|
||||
lineinfile:
|
||||
path: /etc/frr/daemons
|
||||
regexp: '^frr_profile='
|
||||
line: 'frr_profile="datacenter"'
|
||||
notify: restart frr
|
||||
|
||||
- name: Enable BGP and BFD
|
||||
lineinfile:
|
||||
path: /etc/frr/daemons
|
||||
regexp: "^{{ item }}="
|
||||
line: "{{ item }}=yes"
|
||||
loop:
|
||||
- bfdd
|
||||
- bgpd
|
||||
notify: restart frr
|
||||
|
||||
- name: Enable FRR service
|
||||
service:
|
||||
name: frr
|
||||
enabled: yes
|
||||
state: started
|
||||
|
||||
- name: Copy FRR config
|
||||
template:
|
||||
dest: /etc/frr/frr.conf
|
||||
src: frr.conf.j2
|
||||
mode: 0644
|
||||
notify: reload frr
|
||||
44
roles/firewall/tasks/main.yml
Normal file
44
roles/firewall/tasks/main.yml
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
- name: Update package cache
|
||||
package:
|
||||
update_cache: yes
|
||||
|
||||
- name: Install packages
|
||||
package:
|
||||
name: bash,bonding,iproute2
|
||||
state: latest
|
||||
|
||||
- name: Set up custom interfaces
|
||||
template:
|
||||
dest: /etc/network/interfaces.d/firewall.intf
|
||||
src: firewall.intf.j2
|
||||
mode: 0644
|
||||
notify: enable interfaces
|
||||
|
||||
- name: Set up sysctls
|
||||
template:
|
||||
dest: /etc/sysctl.d/firewall.conf
|
||||
src: sysctl.conf.j2
|
||||
|
||||
- name: Run SSH in management VRF
|
||||
lineinfile:
|
||||
path: /etc/conf.d/sshd
|
||||
regexp: "#* *vrf="
|
||||
line: "vrf=\"mgmt\""
|
||||
notify: reboot
|
||||
|
||||
- name: Set up FRR
|
||||
import_tasks: frr.yml
|
||||
|
||||
- name: Set up wireguard
|
||||
import_tasks: wireguard.yml
|
||||
|
||||
- name: Set up nftables
|
||||
import_tasks: nftables.yml
|
||||
|
||||
# causes issues in normal operation
|
||||
# the conntrack tables seem to get synced incorrectly
|
||||
#- name: Set up conntrackd
|
||||
# import_tasks: conntrackd.yml
|
||||
|
||||
- name: Set up configuration channel
|
||||
import_tasks: config.yml
|
||||
26
roles/firewall/tasks/nftables.yml
Normal file
26
roles/firewall/tasks/nftables.yml
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
- name: Install nftables
|
||||
package:
|
||||
name: nftables
|
||||
|
||||
- name: Copy nftables config
|
||||
template:
|
||||
dest: /etc/nftables.nft
|
||||
src: nftables.nft.j2
|
||||
mode: 0644
|
||||
notify: reload nftables
|
||||
|
||||
- name: Copy static nftables includes
|
||||
template:
|
||||
dest: '/etc/nftables.d/{{ item }}'
|
||||
src: '{{ item }}.j2'
|
||||
mode: 0644
|
||||
loop:
|
||||
- interfaces.nft
|
||||
- networks.nft
|
||||
notify: reload nftables
|
||||
|
||||
- name: Enable nftables service
|
||||
service:
|
||||
name: nftables
|
||||
enabled: yes
|
||||
state: started
|
||||
26
roles/firewall/tasks/wireguard.yml
Normal file
26
roles/firewall/tasks/wireguard.yml
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
# All firewall nodes share one external IP for wireguard connections.
|
||||
# Private key and peer configuration is the same for all nodes. Peers
|
||||
# connected to each node are installed in the routing table and
|
||||
# distributed into fabric.
|
||||
|
||||
- name: Install wireguard tools
|
||||
package:
|
||||
name: wireguard-tools
|
||||
|
||||
- name: Create wireguard directory
|
||||
file:
|
||||
path: /etc/wireguard
|
||||
state: directory
|
||||
|
||||
- name: Touch wireguard config
|
||||
file:
|
||||
path: /etc/wireguard/wg.conf
|
||||
state: touch
|
||||
access_time: preserve
|
||||
modification_time: preserve
|
||||
|
||||
- name: Add wireguard interface
|
||||
template:
|
||||
dest: /etc/network/interfaces.d/wg.intf
|
||||
src: wg.intf.j2
|
||||
notify: enable interfaces
|
||||
Loading…
Add table
Add a link
Reference in a new issue