Git initial commit
This commit is contained in:
commit
5bac50269f
9
LICENSE
Executable file
9
LICENSE
Executable file
@ -0,0 +1,9 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) <year> <copyright holders>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
3
README.md
Executable file
3
README.md
Executable file
@ -0,0 +1,3 @@
|
||||
# cloud-vpn
|
||||
|
||||
Ansible role to provide an OpenVPN server; relies on easyrsa for certificates.
|
||||
31
defaults/main.yml
Executable file
31
defaults/main.yml
Executable file
@ -0,0 +1,31 @@
|
||||
---
|
||||
cloud_apps: /opt
|
||||
cloud_storage: /opt/storage
|
||||
cloud_stage: prod
|
||||
cloud_update: false
|
||||
|
||||
vpn_internal_dns: 1.1.1.1
|
||||
|
||||
vpn_allow_adjacent_client_traffic: True
|
||||
vpn_keepalive: 25
|
||||
|
||||
vpn_gateway_clientfolder: /etc/wireguard/clients
|
||||
vpn_gateway_interface: eth0
|
||||
vpn_gateway_host: my-wireguard-server.tld
|
||||
vpn_gateway_port: 51820
|
||||
vpn_gateway_net_prefix: 10.10.123
|
||||
vpn_gateway_net_cidr: 28
|
||||
vpn_gateway_public_key: your-public-key
|
||||
vpn_gateway_private_key: your-privat-key
|
||||
|
||||
vpn_gateway_forward: []
|
||||
# - server_port: 22
|
||||
# client_port: "{{ ssh_port }}"
|
||||
# client_index: 0
|
||||
|
||||
|
||||
vpn_clients: []
|
||||
# - name:
|
||||
# index: 1
|
||||
# private_key:
|
||||
# public_key:
|
||||
7
handlers/main.yml
Executable file
7
handlers/main.yml
Executable file
@ -0,0 +1,7 @@
|
||||
---
|
||||
- name: restart wireguard service
|
||||
service:
|
||||
name: wg-quick@{{ cloud_name }}
|
||||
state: restarted
|
||||
enabled: yes
|
||||
when: wireguard_installed is defined and not wireguard_installed.changed
|
||||
16
meta/main.yml
Executable file
16
meta/main.yml
Executable file
@ -0,0 +1,16 @@
|
||||
---
|
||||
galaxy_info:
|
||||
role_name: vpn
|
||||
namespace: opendevchain
|
||||
author: Lars Hahn
|
||||
company: OpenDevChain
|
||||
license: MIT
|
||||
description: Role to setup a wireguard server.
|
||||
min_ansible_version: 2.7
|
||||
platforms:
|
||||
- name: Debian
|
||||
versions:
|
||||
- 12
|
||||
galaxy_tags:
|
||||
- vpn
|
||||
dependencies: []
|
||||
53
tasks/main.yml
Executable file
53
tasks/main.yml
Executable file
@ -0,0 +1,53 @@
|
||||
---
|
||||
- name: install fail2ban service
|
||||
apt:
|
||||
update_cache: yes
|
||||
state: "{% if cloud_update | bool %}latest{% else %}present{% endif %}"
|
||||
install_recommends: yes
|
||||
pkg: wireguard
|
||||
register: wireguard_installed
|
||||
|
||||
- name: setup key files
|
||||
template:
|
||||
src: "etc/wireguard/{{ item }}.j2"
|
||||
dest: "/etc/wireguard/{{ item }}"
|
||||
owner: root
|
||||
mode: 0600
|
||||
loop:
|
||||
- private.key
|
||||
- public.key
|
||||
notify: restart wireguard service
|
||||
|
||||
- name: setup wireguard config
|
||||
template:
|
||||
src: "etc/wireguard/wireguard.conf.j2"
|
||||
dest: "/etc/wireguard/{{ cloud_name }}.conf"
|
||||
owner: root
|
||||
mode: 0600
|
||||
notify: restart wireguard service
|
||||
|
||||
- name: setup client folder
|
||||
file:
|
||||
state: directory
|
||||
mode: 0600
|
||||
owner: root
|
||||
path: "{{ vpn_gateway_clientfolder }}"
|
||||
|
||||
- name: setup client configs
|
||||
template:
|
||||
src: "etc/wireguard/clients/wireguard-client.conf.j2"
|
||||
dest: "{{ vpn_gateway_clientfolder }}/{{ vpn_client.name }}.conf"
|
||||
owner: root
|
||||
mode: 0600
|
||||
loop: "{{ vpn_clients }}"
|
||||
loop_control:
|
||||
loop_var: vpn_client
|
||||
label: "{{ vpn_client.name }}"
|
||||
|
||||
|
||||
- name: enable wireguard systemd unit
|
||||
systemd:
|
||||
name: wg-quick@{{ cloud_name }}
|
||||
enabled: yes
|
||||
daemon_reload: yes
|
||||
state: started
|
||||
11
templates/etc/wireguard/clients/wireguard-client.conf.j2
Normal file
11
templates/etc/wireguard/clients/wireguard-client.conf.j2
Normal file
@ -0,0 +1,11 @@
|
||||
[Interface]
|
||||
Address = {{ vpn_gateway_net_prefix }}.{{ vpn_client.index }}/32
|
||||
PrivateKey = {{ vpn_client.private_key }}
|
||||
DNS = {{ vpn_internal_dns }}
|
||||
|
||||
[Peer]
|
||||
PublicKey = {{ vpn_gateway_public_key }}
|
||||
Endpoint = {{ vpn_gateway_host }}:{{ vpn_gateway_port }}
|
||||
AllowedIPs = {{ vpn_gateway_net_prefix }}.1/{% if vpn_allow_adjacent_client_traffic %}{{ vpn_gateway_net_cidr }}{% else %}32{% endif %}
|
||||
|
||||
PersistentKeepalive = {{ vpn_keepalive }}
|
||||
1
templates/etc/wireguard/private.key.j2
Normal file
1
templates/etc/wireguard/private.key.j2
Normal file
@ -0,0 +1 @@
|
||||
{{ vpn_gateway_private_key }}
|
||||
1
templates/etc/wireguard/public.key.j2
Normal file
1
templates/etc/wireguard/public.key.j2
Normal file
@ -0,0 +1 @@
|
||||
{{ vpn_gateway_public_key }}
|
||||
25
templates/etc/wireguard/wireguard.conf.j2
Normal file
25
templates/etc/wireguard/wireguard.conf.j2
Normal file
@ -0,0 +1,25 @@
|
||||
[Interface]
|
||||
Address = {{ vpn_gateway_net_prefix }}.1/{{ vpn_gateway_net_cidr }}
|
||||
ListenPort = {{ vpn_gateway_port }}
|
||||
PrivateKey = {{ vpn_gateway_private_key }}
|
||||
|
||||
{% if vpn_gateway_forward is defined and vpn_gateway_forward | length > 0 %}
|
||||
PreUp = sysctl -w net.ipv4.ip_forward=1
|
||||
PreUp = sysctl -w net.ipv6.conf.all.forwarding=1
|
||||
|
||||
{% for config in vpn_gateway_forward %}
|
||||
PreUp = iptables -t nat -A PREROUTING -i {{ vpn_gateway_interface }} -p {{ config.protocol | default('tcp') }} --dport {{ config.server_port }} -j DNAT --to-destination {{ vpn_gateway_net_prefix }}.{{ config.client_index }}:{{ config.client_port }}
|
||||
PostDown = iptables -t nat -D PREROUTING -i {{ vpn_gateway_interface }} -p {{ config.protocol | default('tcp') }} --dport {{ config.server_port }} -j DNAT --to-destination {{ vpn_gateway_net_prefix }}.{{ config.client_index }}:{{ config.client_port }}
|
||||
|
||||
{% endfor %}
|
||||
PreUp = iptables -t nat -A POSTROUTING -o {{ cloud_name }} -j MASQUERADE
|
||||
PostDown = iptables -t nat -D POSTROUTING -o {{ cloud_name }} -j MASQUERADE
|
||||
{% endif %}
|
||||
|
||||
{% for vpn_client in vpn_clients %}
|
||||
## vpn {{ cloud_name }} - {{ vpn_client.name }} ##
|
||||
[Peer]
|
||||
PublicKey = {{ vpn_client.public_key }}
|
||||
AllowedIPs = {{ vpn_gateway_net_prefix }}.{{ vpn_client.index }}/32
|
||||
|
||||
{% endfor %}
|
||||
0
vars/main.yml
Executable file
0
vars/main.yml
Executable file
Loading…
Reference in New Issue
Block a user