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 support for preshared key #14

Closed
wants to merge 1 commit into from
Closed
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: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ expected values are set by default, most with dummy default values.
The endpoint of the VPN provider's WireGuard server.
- `WIREGUARD_VPN_PUBLIC_KEY`:
The public key of the VPN provider's WireGuard peer.
- `WIREGUARD_VPN_PRESHARED_KEY`:
Preshared key of the VPN WireGuard peer (optional).
- `WIREGUARD_ALLOWED_IPS`:
Comma-separated list of IP addresses that may be contacted using the
WireGuard interface. For a namespaced VPN, where the goal is to force all
Expand Down Expand Up @@ -100,7 +102,7 @@ expected values are set by default, most with dummy default values.
- `TUNNEL_VPN_IP_ADDRESSES`:
Comma-separated list of static IP addresses to assign to the tunnel interface
in the VPN network namespace.

#### Tunnel

This package provides a tunnel between the init namesapce and the created VPN
Expand Down
21 changes: 15 additions & 6 deletions bin/namespaced-wireguard-vpn-interface
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,20 @@ case "$1" in
up)
ip link add "$WIREGUARD_NAME" mtu $WIREGUARD_INITIAL_MTU type wireguard || die

wg set "$WIREGUARD_NAME" \
private-key <(echo "$WIREGUARD_PRIVATE_KEY") \
peer "$WIREGUARD_VPN_PUBLIC_KEY" \
endpoint "$WIREGUARD_ENDPOINT" \
allowed-ips "$WIREGUARD_ALLOWED_IPS" || die
if [ -n "$WIREGUARD_VPN_PRESHARED_KEY" ]; then
wg set "$WIREGUARD_NAME" \
private-key <(echo "$WIREGUARD_PRIVATE_KEY") \
peer "$WIREGUARD_VPN_PUBLIC_KEY" \
preshared-key <(echo "$WIREGUARD_VPN_PRESHARED_KEY") \
endpoint "$WIREGUARD_ENDPOINT" \
allowed-ips "$WIREGUARD_ALLOWED_IPS" || die
else
wg set "$WIREGUARD_NAME" \
private-key <(echo "$WIREGUARD_PRIVATE_KEY") \
peer "$WIREGUARD_VPN_PUBLIC_KEY" \
endpoint "$WIREGUARD_ENDPOINT" \
allowed-ips "$WIREGUARD_ALLOWED_IPS" || die
fi

ip link set "$WIREGUARD_NAME" netns "$NETNS_NAME" || die

Expand All @@ -27,7 +36,7 @@ case "$1" in
# Add default routes for IPv4 and IPv6
ip -n "$NETNS_NAME" -4 route add default dev "$WIREGUARD_NAME" || die
if ip -o -6 -a | grep -q "$WIREGUARD_NAME"
then
then
ip -n "$NETNS_NAME" -6 route add default dev "$WIREGUARD_NAME" || die
fi
;;
Expand Down
3 changes: 3 additions & 0 deletions conf/namespaced-wireguard-vpn.conf
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ WIREGUARD_ENDPOINT=1.2.3.4:56789
# Public key of the VPN WireGuard peer
WIREGUARD_VPN_PUBLIC_KEY=abcdFAKEefghFAKEijklFAKEmnopFAKEqrstFAKEuvw=

# Preshared key of the VPN WireGuard peer (optional)
WIREGUARD_VPN_PRESHARED_KEY=abcdFAKEefghFAKEijklFAKEmnopFAKEqrstFAKEuvw=

# Comma-separated list of allowed IP addresses for the VPN WireGuard interface
WIREGUARD_ALLOWED_IPS=0.0.0.0/0,::0/0

Expand Down