Skip to content

Commit

Permalink
Handle Gateway in a private subnet (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
rpersee committed Mar 2, 2024
1 parent c68c954 commit e54a795
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
9 changes: 5 additions & 4 deletions src/create-link/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,22 @@ export WG_PRIVKEY
# This is the magic.
# NOTE: All traffic for `*.subdomain.domain.tld`` will be routed to the container named `subdomain-domain-tld``
# Also supports `subdomain.domain.tld` as well as apex `domain.tld`
# *.domain.tld should resolve to the Gateway's public IPv4 address
# *.domain.tld should resolve to the Gateway's access IPv4 address
CONTAINER_NAME=$(fqdn_to_container_name "$LINK_DOMAIN")
export CONTAINER_NAME

# get gateway access ipv4 address
GATEWAY_IP=$(getent ahostsv4 "$LINK_DOMAIN" | awk -v host="$LINK_DOMAIN" '$NF ~ host {print $1; exit}')

LINK_CLIENT_WG_PUBKEY=$(echo $WG_PRIVKEY|wg pubkey)
# LINK_ENV=$(ssh -o StrictHostKeyChecking=accept-new $SSH_HOST -p $SSH_PORT "bash -s" -- < ./remote.sh $CONTAINER_NAME $LINK_CLIENT_WG_PUBKEY > /dev/null 2>&1)
LINK_ENV=$(ssh -o StrictHostKeyChecking=accept-new -o LogLevel=ERROR $SSH_HOST -p $SSH_PORT "bash -s" -- < ./remote.sh $CONTAINER_NAME $LINK_CLIENT_WG_PUBKEY)


# convert to array
RESULT=($LINK_ENV)

export GATEWAY_LINK_WG_PUBKEY=${RESULT[0]}
export GATEWAY_ENDPOINT=${RESULT[1]}
export GATEWAY_LINK_WG_PUBKEY="${RESULT[0]}"
export GATEWAY_ENDPOINT="${GATEWAY_IP}:${RESULT[1]}"

cat link-compose-snippet.yml | envsubst

Expand Down
4 changes: 1 addition & 3 deletions src/create-link/remote.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ CONTAINER_ID=$(docker run --name $CONTAINER_NAME --network gateway -p $WIREGUARD
GATEWAY_LINK_WG_PUBKEY=$(docker exec $CONTAINER_NAME bash -c 'cat /etc/wireguard/link0.key |wg pubkey')
# get randomly assigned WireGuard port
#WIREGUARD_PORT=$(docker port $CONTAINER_NAME 18521/udp| head -n 1| sed "s/0\.0\.0\.0://")
# get public ipv4 address
GATEWAY_IP=$(curl -s 4.icanhazip.com)

echo "$GATEWAY_LINK_WG_PUBKEY $GATEWAY_IP:$WIREGUARD_PORT"
echo "$GATEWAY_LINK_WG_PUBKEY $WIREGUARD_PORT"

0 comments on commit e54a795

Please sign in to comment.