Skip to content

Add MaxHandshakeAge to /readyz and a --healthcheck flag - #232

Open
dividedby wants to merge 4 commits into
windtf:masterfrom
dividedby:feat/healthcheck
Open

dividedby wants to merge 4 commits into
windtf:masterfrom
dividedby:feat/healthcheck

Conversation

@dividedby

Copy link
Copy Markdown

Summary

  • MaxHandshakeAge ([Interface], seconds, off by default): /readyz also returns 503 when any peer's last handshake is older than that, or a peer has never completed one. It works without CheckAlive, so a stale tunnel is detected without sending pings. Each peer's last handshake time is added to the response body. Peers with no Endpoint in the config only answer handshakes, so they are skipped (listed as handshake_skipped:<key>), even after they connect once and gain a learned endpoint.
  • -H/--healthcheck <addr:port>: requests /readyz from the --info endpoint and exits 0 if healthy, 1 otherwise. That gives distroless/scratch images a container HEALTHCHECK without curl.

README documents both, and notes that idle peers need PersistentKeepalive for the handshake age to stay fresh.

This PR may conflict with the endpoint re-resolve PR in config.go and README (adjacent [Interface] keys). Happy to rebase.

Test plan

  • go test -race ./..., go vet ./..., gofmt -l ., golangci-lint (fork CI green).
  • Tests: stale and never-handshaked peers return 503; a fresh handshake returns 200 (two real wireguard devices over loopback); peers without a configured endpoint are skipped; base64 and hex key matching; the -H client.

🤖 Generated with Claude Code

dividedby and others added 4 commits November 19, 2026 18:54
/readyz only looked at CheckAlive pings, so it always returned 200 without
CheckAlive even if the tunnel was dead. The published image is distroless,
so a container health check cannot use curl or wget either.

Add an optional [Interface] MaxHandshakeAge (seconds, disabled by default).
When set, /readyz also returns 503 if any peer's last handshake is older than
that or has never happened, and lists each peer's last handshake time in the
response body under "handshake:<public key>".

Add -H/--healthcheck <address>, which requests /readyz from the --info address
without loading a configuration and exits 0 on a 200 and 1 otherwise, so it
can be used as the HEALTHCHECK command of the image.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
A peer configured without an Endpoint only answers handshakes and has
never connected, so it never gets a last handshake time. Counting it as
"never handshook" kept /readyz at 503 forever for configs that mix
initiating and responder-only peers.

Track the endpoint line per peer in the IPC output and drop peers without
one from both the staleness check and the reported records.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The MaxHandshakeAge tests only covered stale and never-handshaked peers.
Bring up two wireguard devices over loopback and assert the initiator's
/readyz turns 200, with a non-zero handshake time, once they handshake.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
wireguard-go also reports an "endpoint=" line for endpoints learned from
incoming packets, so a responder-only peer that connected once and went
idle was counted again and kept /readyz at 503. Skip peers that have no
Endpoint in the configuration instead, matching them by public key (the
IPC uses hex, the configuration hex or base64).

Skipped peers stay in the /readyz body, with a
"handshake_skipped:<public key>": 1 entry, and are only left out of the
staleness verdict.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant