initial commit: wirecon WireGuard stack

Rootless-Docker server (wireguard-go + Caddy sharing netns) and
unprivileged-LXC client (kernel WG + systemd watchdog/monitor/MTU-probe)
with curl-pipeable bootstrap. Tuned for Telekom DSL/LTE Hybrid uplinks.
This commit is contained in:
d4nn13 committed 2026-04-19 18:20:21 +02:00
commit 49b01dfcd3
19 files changed
+770

No files matched your search

+72
View File
@@ -0,0 +1,72 @@
# Runs on the internet host under rootless Docker.
#
# Prereqs on the rootless-Docker user:
# - /dev/net/tun readable (e.g. udev rule or `sudo chmod 0666 /dev/net/tun`)
# - `sysctl net.ipv4.ip_unprivileged_port_start=80` on the host if you want
# Caddy to bind 80/443 from a rootless daemon; otherwise remap to 8080/8443.
#
# Bring up: docker compose up -d --build
# Logs: docker compose logs -f wg proxy
name: wirecon
services:
wg:
build: ./wg
container_name: wirecon-wg
restart: unless-stopped
# wireguard-go is userspace, but still needs NET_ADMIN within its own netns
# to create wg0 and program routes/iptables. In rootless Docker this
# capability is confined to the container's user namespace.
cap_add:
- NET_ADMIN
devices:
- /dev/net/tun:/dev/net/tun
sysctls:
net.ipv4.ip_forward: "1"
ports:
# WireGuard handshake/data
- "51820:51820/udp"
# Reverse-proxy ingress. Published here (not on `proxy`) because proxy
# shares wg's network namespace.
- "80:80/tcp"
- "443:443/tcp"
- "443:443/udp" # HTTP/3
volumes:
- ./wg/config:/etc/wireguard:ro
healthcheck:
test: ["CMD", "/usr/local/bin/healthcheck.sh"]
interval: 30s
timeout: 5s
retries: 3
start_period: 15s
logging:
driver: json-file
options:
max-size: "10m"
max-file: "5"
proxy:
image: caddy:2-alpine
container_name: wirecon-proxy
restart: unless-stopped
depends_on:
wg:
condition: service_healthy
# Share wg's network namespace so Caddy can reach 192.168.1.0/24 via wg0
# without host-level routing. All port publishing must live on the wg
# service above.
network_mode: "service:wg"
volumes:
- ./proxy/Caddyfile:/etc/caddy/Caddyfile:ro
- caddy_data:/data
- caddy_config:/config
logging:
driver: json-file
options:
max-size: "10m"
max-file: "5"
volumes:
caddy_data:
caddy_config:
+23
View File
@@ -0,0 +1,23 @@
# Caddy runs inside the wg container's netns, so it can dial 192.168.1.x
# directly through wg0.
#
# Example: publish an internal service at https://service.example.com.
# Replace the hostnames + upstream IPs with real ones.
{
# Uncomment and fill to use ACME for real certs.
# email you@example.com
}
service.example.com {
reverse_proxy 192.168.1.10:8080
log {
output stdout
format console
}
}
# Add more sites as needed:
# other.example.com {
# reverse_proxy 192.168.1.20:3000
# }
+20
View File
@@ -0,0 +1,20 @@
FROM alpine:3.20
RUN apk add --no-cache \
wireguard-tools \
wireguard-go \
iptables \
ip6tables \
iproute2 \
bash \
curl \
tini
ENV WG_QUICK_USERSPACE_IMPLEMENTATION=wireguard-go \
WG_SUDO=0
COPY entrypoint.sh /usr/local/bin/entrypoint.sh
COPY healthcheck.sh /usr/local/bin/healthcheck.sh
RUN chmod +x /usr/local/bin/entrypoint.sh /usr/local/bin/healthcheck.sh
ENTRYPOINT ["/sbin/tini", "--", "/usr/local/bin/entrypoint.sh"]
+32
View File
@@ -0,0 +1,32 @@
# /etc/wireguard/wg0.conf on the Docker (server) side.
# Rename to wg0.conf and fill in the marked fields.
#
# Generate keys:
# wg genkey | tee server.key | wg pubkey > server.pub
# wg genkey | tee client.key | wg pubkey > client.pub
[Interface]
# Server's tunnel address. Pick a subnet that doesn't clash with 192.168.1.0/24.
Address = 10.42.0.1/24
ListenPort = 51820
PrivateKey = REPLACE_WITH_SERVER_PRIVATE_KEY
# Match MTU on both ends. 1280 is safe default behind Telekom Hybrid.
MTU = 1280
# Enable forwarding + MASQ inside the container's own netns so traffic from
# the proxy container (sharing this netns) can flow into wg0 and back.
# No host iptables are touched.
PostUp = sysctl -w net.ipv4.ip_forward=1
PostUp = iptables -A FORWARD -i %i -j ACCEPT
PostUp = iptables -A FORWARD -o %i -j ACCEPT
PostDown = iptables -D FORWARD -i %i -j ACCEPT
PostDown = iptables -D FORWARD -o %i -j ACCEPT
[Peer]
# The LXC client.
PublicKey = REPLACE_WITH_CLIENT_PUBLIC_KEY
# Route both the client's tunnel IP and its LAN subnet back through wg0.
AllowedIPs = 10.42.0.2/32, 192.168.1.0/24
# Server should not set PersistentKeepalive — the client drives this, since
# it's the one behind NAT / hybrid uplink.
+36
View File
@@ -0,0 +1,36 @@
#!/bin/bash
set -euo pipefail
IFACE="${WG_INTERFACE:-wg0}"
CONF="/etc/wireguard/${IFACE}.conf"
log() { printf '%s wirecon-wg[%s] %s\n' "$(date -u +%FT%TZ)" "$$" "$*"; }
if [[ ! -r "$CONF" ]]; then
log "FATAL: $CONF missing or unreadable"
exit 1
fi
if [[ ! -e /dev/net/tun ]]; then
log "FATAL: /dev/net/tun not present; mount it from the host"
exit 1
fi
shutdown() {
log "shutting down ${IFACE}"
wg-quick down "$IFACE" || true
exit 0
}
trap shutdown SIGINT SIGTERM
log "bringing up ${IFACE} (userspace impl: ${WG_QUICK_USERSPACE_IMPLEMENTATION})"
wg-quick up "$IFACE"
log "interface up; endpoint info:"
wg show "$IFACE" | while IFS= read -r line; do log " $line"; done
# Park foreground on a loop so signals reach us.
while :; do
sleep 60 &
wait $!
done
+16
View File
@@ -0,0 +1,16 @@
#!/bin/bash
# Healthcheck: the interface must exist and have at least one peer.
# A stale handshake is not failed here — that's the watchdog's job on the
# LXC (client) side; the server is passive and only responds.
set -euo pipefail
IFACE="${WG_INTERFACE:-wg0}"
ip link show "$IFACE" >/dev/null 2>&1 || exit 1
wg show "$IFACE" >/dev/null 2>&1 || exit 1
# Must have at least one peer configured.
peers=$(wg show "$IFACE" peers | wc -l)
[[ "$peers" -ge 1 ]] || exit 1
exit 0