.
This commit is contained in:
parent
1a6f230702
commit
fcdda55ed9
@ -7,6 +7,7 @@ base:
|
|||||||
- docker
|
- docker
|
||||||
- remote-desktop
|
- remote-desktop
|
||||||
- ssh
|
- ssh
|
||||||
|
- wireguard
|
||||||
{% if salt['pillar.file_exists']('local.sls') %}
|
{% if salt['pillar.file_exists']('local.sls') %}
|
||||||
- local
|
- local
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
9
salt/pillars/wireguard.sls
Normal file
9
salt/pillars/wireguard.sls
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
wireguard:
|
||||||
|
iface: wg-vpn
|
||||||
|
address: 172.20.1.1/24
|
||||||
|
postup:
|
||||||
|
postdown:
|
||||||
|
port: 62666
|
||||||
|
privatekey:
|
||||||
|
publickey:
|
||||||
|
peers: []
|
@ -1,3 +1,9 @@
|
|||||||
|
Configure wireguard service:
|
||||||
|
firewalld.service:
|
||||||
|
- name: wireguard
|
||||||
|
- ports:
|
||||||
|
- {{ pillar['wireguard']['port'] }}/udp
|
||||||
|
|
||||||
Configure firewalld for external interface:
|
Configure firewalld for external interface:
|
||||||
firewalld.present:
|
firewalld.present:
|
||||||
- name: external
|
- name: external
|
||||||
@ -10,6 +16,7 @@ Configure firewalld for external interface:
|
|||||||
- {{ pillar['network']['interface']['external'] }}
|
- {{ pillar['network']['interface']['external'] }}
|
||||||
- services:
|
- services:
|
||||||
- ssh
|
- ssh
|
||||||
|
- wireguard
|
||||||
|
|
||||||
Configure firewalld for internal network:
|
Configure firewalld for internal network:
|
||||||
firewalld.present:
|
firewalld.present:
|
||||||
@ -20,6 +27,7 @@ Configure firewalld for internal network:
|
|||||||
- prune_sources: True
|
- prune_sources: True
|
||||||
- interfaces:
|
- interfaces:
|
||||||
- {{ pillar['network']['interface']['internal'] }}
|
- {{ pillar['network']['interface']['internal'] }}
|
||||||
|
- {{ pillar['wireguard']['iface'] }}
|
||||||
- sources:
|
- sources:
|
||||||
- {{ pillar['network']['netaddress'] }}/{{ pillar['network']['netmask'] }}
|
- {{ pillar['network']['netaddress'] }}/{{ pillar['network']['netmask'] }}
|
||||||
- services:
|
- services:
|
||||||
|
@ -2,6 +2,7 @@ base:
|
|||||||
'*':
|
'*':
|
||||||
- hostname
|
- hostname
|
||||||
- firewalld
|
- firewalld
|
||||||
|
- ssh
|
||||||
- chrony
|
- chrony
|
||||||
- atftp
|
- atftp
|
||||||
- dnsmasq
|
- dnsmasq
|
||||||
|
14
salt/states/wireguard/files/interface.conf.template
Normal file
14
salt/states/wireguard/files/interface.conf.template
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
[Interface]
|
||||||
|
Address = {{ pillar['wireguard']['address'] }}
|
||||||
|
PrivateKey = {{ pillar['wireguard']['privatekey'] }}
|
||||||
|
ListenPort = {{ pillar['wireguard']['port'] }}
|
||||||
|
PostUp = iptables -A FORWARD -i {{ pillar['wireguard']['iface'] }} -j ACCEPT; iptables -t nat -A POSTROUTING -o {{ pillar['network']['interface']['internal'] }} -j MASQUERADE
|
||||||
|
PostDOWN = iptables -D FORWARD -i {{ pillar['wireguard']['iface'] }} -j ACCEPT; iptables -t nat -D POSTROUTING -o {{ pillar['network']['interface']['internal'] }} -j MASQUERADE
|
||||||
|
|
||||||
|
{% for peer in pillar['wireguard']['peers'] -%}
|
||||||
|
[peer]
|
||||||
|
PublicKey = {{ peer['publickey'] }}
|
||||||
|
PresharedKey = {{ peer['presharedkey'] }}
|
||||||
|
AllowedIPs = {{ peer['allowedips'] }}
|
||||||
|
{% endfor %}
|
||||||
|
|
26
salt/states/wireguard/init.sls
Normal file
26
salt/states/wireguard/init.sls
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
Install wireguard tools:
|
||||||
|
pkg.installed:
|
||||||
|
- name: wireguard-tools
|
||||||
|
|
||||||
|
{% if pillar['wireguard']['privatekey'] %}
|
||||||
|
configure wireguard interface:
|
||||||
|
file.managed:
|
||||||
|
- name: /etc/wireguard/{{ pillar['wireguard']['iface'] }}.conf
|
||||||
|
- source: salt://wireguard/files/interface.conf.template
|
||||||
|
- template: jinja
|
||||||
|
- user: root
|
||||||
|
- group: root
|
||||||
|
- mode: "0600"
|
||||||
|
|
||||||
|
stop wireguard interface:
|
||||||
|
cmd.run:
|
||||||
|
- name: wg-quick down {{ pillar['wireguard']['iface'] }}
|
||||||
|
- onlyif: wg show {{ pillar['wireguard']['iface'] }}
|
||||||
|
- onchanges:
|
||||||
|
- file: configure wireguard interface
|
||||||
|
|
||||||
|
start wireguard interface:
|
||||||
|
cmd.run:
|
||||||
|
- name: wg-quick up {{ pillar['wireguard']['iface'] }}
|
||||||
|
- unless: wg show {{ pillar['wireguard']['iface'] }}
|
||||||
|
{% endif %}
|
Loading…
Reference in New Issue
Block a user