Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add WireGuard service #10

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ directly.
#### Infrastructure & security
- [Authentik](https://goauthentik.io), a self-hosted identity provider.
Acts as a central authentication system for other services.
- [Tailscale](https://tailscale.com), a VPN service.
Allows secure access to the server from anywhere.
- [WireGuard](https://wireguard.com), a modern VPN protocol.
Allows secure access to the server and home network from anywhere.
- [Bitwarden](https://bitwarden.com) password manager,
using [Vaultwarden](https://github.com/dani-garcia/vaultwarden).

Expand Down
14 changes: 7 additions & 7 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -227,17 +227,17 @@ traefik_acme_dns:
env:
CF_DNS_API_TOKEN: "{{ secret_cloudflare_dns_api_token }}"


######################
# Tailscale settings #
# WireGuard settings #
######################

tailscale_enabled: true

# Subnets to route traffic to
tailscale_routes:
- "10.0.0.0/24"
wireguard_enabled: yes
wireguard_vpn_subnet: '10.5.19.0'
wireguard_peers:
- KianPhone
- KianLaptop

tailscale_auth_key: "{{ secret_tailscale_auth_key }}"

###################
# Homarr settings #
Expand Down
13 changes: 4 additions & 9 deletions config.yml.sample
Original file line number Diff line number Diff line change
Expand Up @@ -206,17 +206,12 @@ traefik_acme_dns:


######################
# Tailscale settings #
# WireGuard settings #
######################

tailscale_enabled: false

# Subnets to route traffic to
tailscale_routes:
- "10.0.0.0/24"

# Use Ansible Vault to put your encrypted auth key here
tailscale_auth_key: "{{ undef() }}"
wireguard_enabled: yes
wireguard_peers:
- TestClient


###################
Expand Down
271 changes: 133 additions & 138 deletions group_vars/homeserver/secrets.yml

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@
tags:
- traefik

- role: tailscale
- role: wireguard
tags:
- tailscale
- wireguard

- role: homarr
tags:
Expand Down
8 changes: 0 additions & 8 deletions roles/tailscale/defaults/main.yml

This file was deleted.

40 changes: 0 additions & 40 deletions roles/tailscale/tasks/main.yml

This file was deleted.

20 changes: 20 additions & 0 deletions roles/wireguard/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
# Whether to enable the WireGuard service
wireguard_enabled: yes

# Port to use for the WireGuard service
wireguard_port: 51820

# Subnet to use for the WireGuard VPN.
# It appears the CIDR notation is not allowed here; the container is hard-coded to use /24.
wireguard_vpn_subnet: "10.13.13.0"

# List of peers to add to the WireGuard configuration.
# Supports alphanumeric names only.
wireguard_peers: []

# Tag to use for the lscr.io/linuxserver/wireguard image
wireguard_tag: latest

# Directory in which to store WireGuard data
wireguard_data_dir: "{{ storage.data_dir }}/wireguard"
52 changes: 52 additions & 0 deletions roles/wireguard/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
- name: Set up Wireguard
when: wireguard_enabled is true
block:
- name: Create data directory
ansible.builtin.file:
path: "{{ wireguard_data_dir }}/config"
state: directory
owner: "{{ users.worker }}"
group: "{{ users.worker }}"
mode: '0750'

- name: Get worker UID
ansible.builtin.command:
cmd: "id -u {{ users.worker }}"
register: worker_uid
changed_when: false

- name: Get worker GID
ansible.builtin.command:
cmd: "id -g {{ users.worker }}"
register: worker_gid
changed_when: false

- name: Start Wireguard container
community.docker.docker_container:
name: wireguard
image: lscr.io/linuxserver/wireguard:{{ wireguard_tag }}
capabilities:
- NET_ADMIN
volumes:
- "{{ wireguard_data_dir }}/config:/config"
ports:
- "{{ wireguard_port }}:{{ wireguard_port }}/udp"
env:
PUID: "{{ worker_uid.stdout }}"
PGID: "{{ worker_gid.stdout }}"
SERVERURL: "{{ general.domain }}"
SERVERPORT: "{{ wireguard_port | string }}"
INTERNAL_SUBNET: "{{ wireguard_vpn_subnet }}"
LOG_CONFS: 'false' # Don't log peer configurations on startup, since we won't be looking at the logs
PEERS: "{{ wireguard_peers | join(',') | default('0', true) }}"
sysctls:
net.ipv4.conf.all.src_valid_mark: '1'

- name: Stop Wireguard
when: wireguard_enabled is false
block:
- name: Stop Wireguard container
community.docker.docker_container:
name: wireguard
state: absent