Skip to content

Commit bfaa814

Browse files
committed
Configuration Refactor
This commit refactors the entire sg-base role to use the newest configuration refactor. This refactor includes exciting new features such as CARP, cleaner ways to specify multiple networks, and more! The most notable change with this commit is that the gateway now implements fairly advanced firewalling based on what services are loaded. Ideally in a future version this will be factored out to the individual roles, but right now the template logic to do so would make this commit too complex to review. This refactor includes significant work from @m-wynn.
1 parent 534c8f8 commit bfaa814

File tree

16 files changed

+247
-50
lines changed

16 files changed

+247
-50
lines changed

defaults/main.yml

Lines changed: 0 additions & 25 deletions
This file was deleted.

files/pkg.conf

Lines changed: 0 additions & 1 deletion
This file was deleted.

files/rc.local

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cp /etc/resolv.conf.final /etc/resolv.conf

files/sshd_banner

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This system is for authorized use only!

files/sysctl.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
# the many available variables.
44

55
ddb.panic=0 # 0=Do not drop into ddb on a kernel panic
6+
net.inet.carp.preempt=1 # 1=Enable carp(4) preemption
67
net.inet.ip.forwarding=1 # 1=Permit forwarding (routing) of IPv4 packets

handlers/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,6 @@
2222

2323
- name: pf
2424
command: pfctl -f /etc/pf.conf
25+
26+
- name: sshd
27+
command: /etc/rc.d/sshd restart

tasks/main.yml

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
- name: Configure interfaces
2+
- name: Configure Interfaces
33
template:
44
src: hostname.interface.j2
55
dest: /etc/hostname.{{ item.name }}
@@ -8,7 +8,7 @@
88
mode: 0640
99
notify:
1010
- netstart
11-
with_items: "{{ sg_network }}"
11+
with_items: "{{ sg_interfaces }}"
1212
loop_control:
1313
label: "{{ item.name }}"
1414

@@ -48,14 +48,65 @@
4848
group: wheel
4949
mode: 0644
5050
with_items:
51-
- pkg.conf
5251
- rc.securelevel
5352
- sysctl.conf
5453

54+
- name: Configure SSH
55+
template:
56+
src: sshd_config.j2
57+
dest: /etc/ssh/sshd_config
58+
owner: root
59+
group: wheel
60+
mode: 0644
61+
notify:
62+
- sshd
63+
64+
- name: Copy SSH banner
65+
copy:
66+
src: "{{ sshd_banner | default('sshd_banner') }}"
67+
dest: /etc/ssh/sshd_banner
68+
owner: root
69+
group: wheel
70+
mode: 0644
71+
notify:
72+
- sshd
73+
74+
- name: Configure package system
75+
template:
76+
src: pkg.conf.j2
77+
dest: /etc/pkg.conf
78+
owner: root
79+
group: wheel
80+
mode: 0644
81+
82+
- name: Template Startup Control Files
83+
template:
84+
src: "{{ item }}.j2"
85+
dest: /etc/{{ item }}
86+
owner: root
87+
group: wheel
88+
mode: 0644
89+
with_items:
90+
- hosts
91+
- myname
92+
- mygate
93+
- resolv.conf.boot
94+
- resolv.conf.final
95+
5596
- name: Create rc.conf.local.d
5697
file:
5798
path: /etc/rc.conf.local.d
5899
state: directory
59100
owner: root
60101
group: wheel
61102
mode: 0644
103+
104+
- name: Create rc.local
105+
copy:
106+
src: rc.local
107+
dest: /etc/rc.local
108+
owner: root
109+
group: wheel
110+
mode: 0644
111+
when: sg_networks|selectattr('services', 'issuperset', ['dhcp'])|list
112+

templates/hostname.interface.j2

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,24 @@
1+
{% if item.name == sg_interfaces[0].name %}
2+
{# This handles the case where we boot faster that the upstream resolver #}
3+
!cp /etc/resolv.conf.boot /etc/resolv.conf
4+
{% endif %}
5+
{% if item.syncdev is defined %}
6+
up syncdev {{ item.syncdev }}
7+
{% else %}
8+
{% if item.address is defined %}
9+
{% if item.carpdev is defined %}
10+
inet {{ item.address | ipaddr('address') }} {{ item.address | ipaddr('netmask') }} NONE vhid {{ item.vhid }} carpdev {{ item.carpdev }} advskew {{ item.advskew }}
11+
{% else %}
112
{% if item.address | ipaddr %}
2-
inet {{ item.address }} {{ item.cidr | ipaddr('netmask') }} NONE
13+
inet {{ item.address | ipaddr('address') }} {{ item.address | ipaddr('netmask') }} NONE
14+
{% if item.aliases is defined %}
15+
{% for alias in item.aliases %}
16+
inet alias {{ alias | ipaddr('address') }} {{ alias | ipaddr('netmask') }}
17+
{% endfor %}
18+
{% endif %}
319
{% elif item.address == "dhcp" %}
420
dhcp
521
{% endif %}
6-
-inet6
7-
up
22+
{% endif %}
23+
{% endif %}
24+
{% endif %}

templates/hosts.j2

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
127.0.0.1 localhost
2+
::1 localhost
3+
4+
{# This might seem like an epic kludge, but really this allows us to
5+
absolutely know that pf will come up even if the external boot
6+
resolver is absolutely dead. This list must contain all symbolic
7+
names that are used in the pf rules for hosts managed by this
8+
router. #}
9+
{% if sg_globalconf.boothosts is defined %}
10+
{% for host in sg_globalconf.boothosts %}
11+
{{ host.ip }} {{ host.name }}
12+
{% endfor %}
13+
{% endif %}

templates/mygate.j2

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{# This defaults to localhost to account for if dhcp is used for egress #}
2+
{{ sg_globalconf.default_gateway | default('127.0.0.1') }}

0 commit comments

Comments
 (0)