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

Tailscale DERP Relay Latency and Fallback Sentinel

Audits Tailscale mesh networks for nodes falling back to DERP relay servers and elevated peer latency, alerting platform engineers via Slack.

Categories
CloudInfrastructure

Enterprise zero-trust infrastructure depends on Tailscale to create encrypted, point-to-point WireGuard mesh networks between cloud servers, developer laptops, and on-premises Kubernetes clusters. When local corporate firewalls block outbound UDP traffic or restrictive Symmetric NAT configurations prevent direct hole-punching, Tailscale transparently routes traffic through public or private Designated Encrypted Relay for Packets (DERP) servers. While this fallback guarantees that connections never drop, routing packets through distant HTTP/HTTPS relays dramatically inflates round-trip latency and caps throughput. Consequently, cross-cluster database replication slows down and microservice RPC timeouts occur without explicit error logs. This sentinel audits Tailscale device connectivity every 15 minutes, detects when nodes fall back to DERP relays, and alerts network engineers on Slack with exact node hostnames and firewall remediation steps.

How it works

  1. Scheduled triggering: Executes every 15 minutes via automated cron trigger (*/15 * * * *) or runs on-demand via manual execution.
  2. Device inventory query: Invokes the Tailscale REST API v2 endpoint /api/v2/tailnet/{tailnet}/devices to retrieve device metadata and connection states.
  3. Connection path inspection: Examines clientConnectivity and endpoint arrays for each device to verify whether direct WireGuard UDP peering is active or if DERP relay tunneling is in use.
  4. Threshold evaluation: Compares the count of active relayed devices against max_relayed_nodes_threshold.
  5. Conditional alerting: An io.kestra.plugin.core.flow.If flowable checks if relayed nodes exceed the threshold and dispatches a Slack alert to #netops-alerts.
  6. Network manifest export: Logs the operational summary and exports a structured diagnostic payload detailing affected machine names and DERP region codes.

Architecture diagram

flowchart TD
  A[fifteen_minute_tailscale_audit Schedule Trigger] --> B[evaluate_tailscale_devices Python Script]
  B --> C[check_derp_relay_fallback Flowable If]
  C -- High DERP Usage --> D[notify_slack_derp_degradation Webhook]
  C -- Mesh Peering Healthy --> E[log_mesh_network_status Log]
  D --> E
  E --> F[export_tailscale_manifest Return]

What you get

  • Proactive visibility into enterprise nodes failing to establish direct peer-to-peer WireGuard tunnels.
  • Automated detection of corporate firewall changes or security groups blocking UDP port 41641.
  • Contextual Slack alerts listing affected node hostnames, operating systems, and DERP region identifiers.
  • Structured JSON manifests tracking mesh network peer health over time.

Who it's for

  • Network Engineers and SREs managing zero-trust corporate mesh connectivity.
  • Infrastructure Platform Engineers troubleshooting cross-region database replication latency.
  • Security Operations Teams ensuring compliance with direct peer encryption architecture standards.

Why orchestrate this with Kestra

Tailscale seamlessly abstracts networking complexities, but its silent fallback to DERP servers obscures performance degradation. Kestra provides the orchestration framework to periodically audit network topologies, parse device connection telemetry, and trigger incident alerts when direct peer-to-peer communication degrades. Using Kestra's containerized Python runner and secret management, network teams gain automated operational guardrails without maintaining separate monitoring scripts.

Use cases

  • Cloud-to-On-Prem Tunnel Health: Verify that hybrid cloud database connections maintain direct, low-latency UDP tunnels rather than bouncing through public relays.
  • Firewall Policy Drift Detection: Detect when newly applied enterprise firewall rules inadvertently block Tailscale WireGuard UDP traffic.
  • Developer Remote Access Quality: Ensure remote engineering teams experience low-latency SSH and internal service access without relay bottlenecks.

Inputs

Name Type Default Description
tailnet_name STRING company.org.github Tailscale organizational tailnet domain identifier or organization name.
max_relayed_nodes_threshold INT 5 Maximum allowable peer nodes falling back to DERP relays before alerting network degradation.
node_tag_filter STRING all Specific node ACL tag (e.g. tag:prod-server) to filter evaluation, or all to scan all devices.
alert_on_degraded BOOL true Whether to dispatch automated Slack alerts when excessive DERP relay fallbacks are detected.

Expected outputs

  • {{ outputs.evaluate_tailscale_devices.vars.total_devices_evaluated }}: Total number of active devices inspected in the tailnet.
  • {{ outputs.evaluate_tailscale_devices.vars.relayed_nodes_count }}: Number of nodes currently routing traffic through DERP relays.
  • {{ outputs.evaluate_tailscale_devices.vars.is_degraded }}: Boolean flag indicating whether the relayed node threshold was breached.
  • {{ outputs.export_tailscale_manifest.value }}: Structured dictionary containing the consolidated mesh health summary.

Prerequisites

  • Outbound HTTPS network access from Kestra execution workers to api.tailscale.com.
  • A Tailscale API access token or OAuth client credential with devices:read scope.
  • A Slack Incoming Webhook URL configured in Kestra secrets.

Secrets

  • TAILSCALE_API_KEY: Tailscale API access token with permissions to list devices and connectivity telemetry.
  • SLACK_WEBHOOK_URL: Slack Incoming Webhook URL used to dispatch network incident alerts.

Quick start

  1. Register TAILSCALE_API_KEY and SLACK_WEBHOOK_URL in your Kestra secret storage.
  2. Import this blueprint into your Kestra instance under the company.network namespace.
  3. Update tailnet_name with your organization tailnet domain (e.g. example.com or example.github).
  4. Execute the flow manually to inspect current device connection states and verify diagnostic output.

Common pitfalls and troubleshooting

  • Tailnet Domain Format: The tailnet parameter must match your organization domain or tailnet name exactly as shown in the Tailscale admin console.
  • API Token Expiration: Tailscale personal API keys expire after 90 days; using an OAuth client secret provides durable non-expiring service authentication.
  • Ephemeral Devices: Offline or ephemeral test nodes may register without active UDP endpoints; filtering by node_tag_filter ensures only persistent production nodes are evaluated.

How to extend

  • Automated DERP Region Failover: Trigger a configuration flow to deploy and register a custom private DERP relay node in your local AWS or GCP region.
  • Firewall Policy Remediation: Dispatch a webhook to AWS Security Group or Cloudflare Magic WAN automation to reopen UDP port 41641.
  • Prometheus Metrics Exporter: Export relayed device counts directly to Prometheus or Datadog as a custom network quality metric.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.