Skip to content

Commit

Permalink
Add preshared key for wg connection
Browse files Browse the repository at this point in the history
  • Loading branch information
Naman1997 committed Sep 10, 2024
1 parent e2b6b83 commit c4e2c0e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
10 changes: 10 additions & 0 deletions ansible/3-wireguard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
shell: "wg genkey | tee privatekey_proxy | wg pubkey > publickey_proxy"
args:
chdir: "/etc/wireguard"
- name: Generate Wireguard pre-shared key
shell: "wg genpsk > preshared_key"
args:
chdir: "/etc/wireguard"
- name: Get public key of proxy
slurp:
src: /etc/wireguard/publickey_proxy
Expand All @@ -27,6 +31,10 @@
slurp:
src: /etc/wireguard/privatekey_proxy
register: private_key_proxy
- name: Get the preshared key to be used for the connection
slurp:
src: /etc/wireguard/preshared_key
register: preshared_key_content

- hosts: gateway
become: true
Expand Down Expand Up @@ -76,6 +84,7 @@
vars:
public_key: "{{ hostvars.gateway.public_key_gateway['content'] | b64decode }}"
private_key: "{{ private_key_proxy['content'] | b64decode }}"
preshared_key: "{{ preshared_key_content['content'] | b64decode }}"
- name: Startup connection
shell: "wg-quick up wg0"
- name: Enable wg service
Expand All @@ -94,6 +103,7 @@
vars:
public_key: "{{ hostvars.proxy.public_key_proxy['content'] | b64decode }}"
private_key: "{{ private_key_gateway['content'] | b64decode }}"
preshared_key: "{{ hostvars.proxy.preshared_key_content['content'] | b64decode }}"
interface: "{{ gateway_internet_interface.stdout }}"
- name: Startup connection
shell: "wg-quick up wg0"
Expand Down
3 changes: 2 additions & 1 deletion templates/wireguard/wg0_gateway.conf.template
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ PrivateKey = {{ private_key | trim }}

[Peer]
PublicKey = {{ public_key | trim }}
AllowedIPs = 10.20.0.2/32
AllowedIPs = 10.20.0.2/32
PresharedKey = {{ preshared_key | trim }}
3 changes: 2 additions & 1 deletion templates/wireguard/wg0_proxy.conf.template
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ Address = 10.20.0.2/24
PublicKey = {{ public_key | trim }}
AllowedIPs = 10.20.0.1/32
Endpoint = {{ duckdns_domain }}:{{ wireguard_port }}
PersistentKeepalive = 25
PersistentKeepalive = 10
PresharedKey = {{ preshared_key | trim }}

0 comments on commit c4e2c0e

Please sign in to comment.