Script icon
Docker icon
If icon
SlackIncomingWebhook icon
Log icon
Return icon
Schedule icon

WireGuard Peer Handshake Staleness and Tunnel Loss Sentinel

Audits WireGuard gateway interface peer states via telemetry, detects handshake staleness and dropped tunnels, and alerts engineers via Slack.

Categories
CloudInfrastructure

Audits WireGuard secure tunnel gateway peer connectivity via wireguard telemetry exporters or management APIs, identifying cryptographically stale handshakes and dropped site-to-site VPN tunnels before cross-datacenter connectivity degrades.

How it works

  1. Gateway Telemetry Ingestion: Retrieves latest cryptographic handshake timestamps and transfer byte counters from WireGuard Prometheus exporters or management daemons.
  2. Handshake Age Differential Calculation: Computes the elapsed duration since the last completed Noise protocol re-keying handshake for each configured peer endpoint.
  3. Tunnel Loss Threshold Evaluation: Isolates peer sessions exceeding maximum permissible handshake latency windows and evaluates against alerting tolerance rules.
  4. Network Operations Incident Dispatch: Dispatches formatted operational alerts to Slack including truncated peer public keys and handshake elapsed times for rapid routing remediation.

Architecture diagram

flowchart TD
    A[periodic_wireguard_audit Schedule Trigger] --> B[scan_wireguard_peers Python Script]
    B --> C[check_stale_wireguard_peers Flowable If]
    C -- Threshold Breached --> D[notify_slack_network_alert Webhook]
    C -- Metrics Nominal --> E[log_nominal_wireguard_state Log]
    D --> E
    E --> F[export_wireguard_manifest Return]

Architecture components

  • Trigger (periodic_wireguard_audit): Drives scheduled recurring surveillance cycles without human intervention.
  • Inspection Task (scan_wireguard_peers): Queries target APIs and structures diagnostic indicators via Kestra outputs.
  • Evaluation Gate (check_stale_wireguard_peers): Evaluates operational safety boundaries using deterministic boolean branching.
  • Notification Action (notify_slack_network_alert): Dispatches rich, actionable incident messages directly to team channels.
  • Manifest Return (export_wireguard_manifest): Emits structured compliance payloads for SIEM and analytics records.

Key capabilities

  • Automated Health Polling: Continuous scheduled surveillance executed on customizable recurring intervals without dedicated agent daemons.
  • Deterministic Threshold Evaluation: Pure boolean and numeric tolerance checks eliminating false positives and alert noise.
  • Contextual Incident Notification: Rich Slack messages populated with explicit resource identifiers, error reasons, and metrics.
  • Machine-Readable Audit Manifest: Structured execution telemetry exported for compliance archives, SIEM ingestion, or analytics dashboards.

What you get

  • Continuous automated monitoring of site-to-site and remote worker WireGuard secure network tunnels
  • Instant detection of silent NAT traversal timeouts, firewall drops, and stale dynamic IP address mappings
  • Elimination of unmonitored VPN link outages causing cross-cloud and hybrid infrastructure partitions
  • Structured compliance telemetry capturing peer counts, stale durations, and audit timestamps

Who it's for

  • Network Reliability Engineers maintaining multi-cloud mesh networks and site-to-site overlay interconnects
  • Infrastructure Security Administrators managing secure administrative bastion tunnels and remote access gateways
  • DevOps Engineers supporting hybrid on-premises to public cloud high-throughput data migration tunnels

Why orchestrate this with Kestra

  • Lightweight scheduled polling without requiring complex proprietary VPN monitoring software licenses
  • Standardized integration with cloud-native monitoring endpoints and telemetry exporters
  • Extensible alerting engine with built-in Slack webhook notifications and conditional logic gates
  • Secure environment configuration safeguarding internal network telemetry endpoints

Use cases

  • VPC Tunnel Drop Detection: Detect cloud VPC-to-on-premise gateway tunnel drops caused by ISP dynamic IP reassignment.
  • Remote Worker Connection Auditing: Audit remote worker VPN connection dropouts during network infrastructure upgrades.
  • CNI Overlay Encryption Surveillance: Monitor Kubernetes cross-node overlay encryption stability when utilizing WireGuard CNI backends.

Inputs

Name Type Default Description
wireguard_interface STRING wg0 Identifier of the target WireGuard network tunnel interface to inspect.
max_handshake_age_seconds INT 300 Maximum tolerated elapsed seconds since last successful cryptographic handshake before a peer is flagged as stale.
stale_peer_threshold INT 1 Threshold count of stale WireGuard peers required to trigger an automated incident notification.
metrics_endpoint_url STRING http://vpn-gateway.internal:9586/metrics HTTP endpoint URL exposing Prometheus or JSON wireguard telemetry from the host gateway.
alert_on_stale BOOL True Toggle whether Slack webhook notifications are dispatched when stale peer thresholds are breached.

Expected outputs

  • {{ outputs.scan_wireguard_peers.vars.total_peer_count }}: Total number of WireGuard peers configured on the audited interface.
  • {{ outputs.scan_wireguard_peers.vars.stale_peer_count }}: Count of peers exhibiting handshake staleness exceeding configured thresholds.
  • {{ outputs.scan_wireguard_peers.vars.stale_peers }}: Truncated public keys and elapsed handshake durations of identified stale peer endpoints.
  • {{ outputs.scan_wireguard_peers.vars.is_alerting }}: Boolean flag indicating whether stale peer count breached configured incident criteria.

Prerequisites

  • WireGuard gateway interface (e.g., wg0) deployed and active on Linux or BSD host systems.
  • Prometheus WireGuard exporter or JSON telemetry service accessible to the Kestra execution agent.
  • Network firewall rules permitting outbound TCP access from Kestra to the gateway metrics endpoint.
  • Configured Slack incoming webhook URL with permissions to post messages into the designated alert channel.

Secrets

  • SLACK_WEBHOOK_URL: Vault secret required for authenticated API execution and notifications.

Quick start

  1. Register the required secrets in your Kestra namespace settings.
  2. Import this blueprint into your Kestra instance under the company.cloud namespace.
  3. Review input parameters such as threshold levels and target resource identifiers.
  4. Execute the flow manually to verify connectivity, then enable the automated schedule.

Common pitfalls and troubleshooting

  • Silent UDP Protocol Behavior: WireGuard emits zero packets when idle; configure PersistentKeepalive = 25 on NAT peers to maintain regular handshake telemetry.
  • Handshake Timestamp Epoch Zero: Peers that have never successfully completed an initial handshake return epoch 0; handle zero timestamps to prevent false negatives.
  • Public Key Exposure in Notifications: Truncate peer public keys in alert payloads to preserve cryptographic confidentiality while retaining actionable operational identity.
  • Metric Exporter Scrape Timeouts: Ensure the metrics exporter has direct local access to the wg binary with CAP_NET_ADMIN capabilities to avoid scrape latency.

How to extend

  • Automated Interface Re-initialization: Trigger remote SSH or Ansible playbooks to restart wireguard interfaces upon persistent total gateway outage.
  • Dynamic DNS Sync: Invoke Route53 or Cloudflare DNS updates when mobile gateway peers report altered external endpoints.
  • BGP Route Withdraw Automation: Automatically withdraw BGP network advertisements across failed WireGuard tunnel interfaces to reroute traffic.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.