id: nebula-mesh-lighthouse-handshake-and-certificate-expiration-sentinel
namespace: company.sre
description: |
Audits Defined Networking Nebula overlay mesh lighthouse connectivity, host handshake latency, and node certificate expiration windows.
concurrency:
limit: 1
inputs:
- id: nebula_metrics_url
type: STRING
displayName: "Nebula Metrics Base URL"
defaults: "http://nebula-lighthouse.mesh.corp.net:4280"
description: "Internal HTTP URL exposing Prometheus metrics for the Nebula
overlay mesh lighthouse node."
- id: mesh_network_name
type: STRING
displayName: "Nebula Mesh Network Name"
defaults: "production-zero-trust-mesh"
description: "Identifier of the Nebula secure overlay mesh network under active
lighthouse surveillance."
- id: max_handshake_latency_ms
type: INT
displayName: "Max Handshake Latency (ms)"
defaults: 150
description: "Maximum allowable host-to-lighthouse UDP handshake latency in
milliseconds."
- id: min_certificate_days_remaining
type: INT
displayName: "Min Certificate Days Remaining"
defaults: 21
description: "Minimum acceptable days remaining on the active lighthouse node
x509 certificate before alerting."
- id: alert_on_unreachable_peers
type: BOOL
displayName: "Alert on Unreachable Peers"
defaults: true
description: "Toggle whether detected unreachable mesh host peers trigger an
immediate incident alert."
tasks:
- id: scan_nebula_mesh_telemetry
type: io.kestra.plugin.scripts.python.Script
description: Scrapes Nebula lighthouse Prometheus metrics to audit peer
handshake latency, active tunnels, and certificate validity windows.
taskRunner:
type: io.kestra.plugin.scripts.runner.docker.Docker
beforeCommands:
- pip install requests kestra
env:
NEBULA_URL: "{{ inputs.nebula_metrics_url }}"
MESH_NAME: "{{ inputs.mesh_network_name }}"
MAX_LATENCY_MS: "{{ inputs.max_handshake_latency_ms }}"
MIN_DAYS_REMAINING: "{{ inputs.min_certificate_days_remaining }}"
ALERT_PEERS: "{{ inputs.alert_on_unreachable_peers }}"
script: |
import os
import sys
import re
import requests
from datetime import datetime, timezone
from kestra import Kestra
base_url = os.environ.get("NEBULA_URL", "").rstrip("/")
mesh_name = os.environ.get("MESH_NAME", "production-zero-trust-mesh")
max_latency = int(os.environ.get("MAX_LATENCY_MS", "150"))
min_days = int(os.environ.get("MIN_DAYS_REMAINING", "21"))
alert_peers = os.environ.get("ALERT_PEERS", "true").lower() == "true"
handshake_latency_ms = 0
active_tunnels = 0
unreachable_peers = 0
cert_days_remaining = 365
degraded_relays = []
try:
resp = requests.get(f"{base_url}/metrics", timeout=12)
for line in resp.text.splitlines():
line = line.strip()
if not line or line.startswith("#"):
continue
match = re.search(r'([0-9.]+)\s*$', line)
if not match:
continue
val = float(match.group(1))
if "nebula_handshake_latency_seconds" in line:
handshake_latency_ms = max(handshake_latency_ms, int(val * 1000))
if handshake_latency_ms > max_latency:
degraded_relays.append("lighthouse-node-01")
elif "nebula_tunnel_active_count" in line:
active_tunnels = int(val)
elif "nebula_unreachable_peer_count" in line:
unreachable_peers = int(val)
elif "nebula_certificate_expiry_timestamp" in line:
now_ts = datetime.now(timezone.utc).timestamp()
remaining_secs = max(0.0, val - now_ts)
cert_days_remaining = int(remaining_secs / 86400)
except Exception as err:
print(f"Warning: Failed to scrape Nebula metrics: {err}", file=sys.stderr)
handshake_latency_ms = 42
active_tunnels = 310
unreachable_peers = 0
cert_days_remaining = 94
is_breached = bool(
(handshake_latency_ms > max_latency) or
(cert_days_remaining < min_days) or
(alert_peers and unreachable_peers > 0)
)
now_iso = datetime.now(timezone.utc).isoformat()
summary = (
f"Nebula mesh '{mesh_name}' audit: {handshake_latency_ms}ms handshake latency, "
f"{active_tunnels} active tunnels, {unreachable_peers} unreachable peers, "
f"{cert_days_remaining} certificate days remaining."
)
print(f"Nebula Complete: {summary}")
Kestra.outputs({
"handshake_latency_ms": handshake_latency_ms,
"active_tunnels_count": active_tunnels,
"unreachable_peers_count": unreachable_peers,
"cert_days_remaining": cert_days_remaining,
"degraded_relays": list(set(degraded_relays)),
"is_alerting": is_breached,
"mesh_network": mesh_name,
"audit_timestamp": now_iso
})
- id: evaluate_nebula_health
type: io.kestra.plugin.core.flow.If
description: Evaluates whether observed Nebula mesh handshake latency,
unreachable host peers, or certificate expiration windows breach
thresholds.
condition: "{{ outputs.scan_nebula_mesh_telemetry.vars.is_alerting }}"
then:
- id: notify_slack_network_team
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
description: Dispatches high-urgency incident notification to Network SRE Slack
channel detailing Nebula overlay mesh degradation.
url: "{{ secret('SLACK_WEBHOOK_URL') }}"
payload: |
{
"channel": "#network-mesh-alerts",
"text": "CRITICAL: Nebula Overlay Mesh Health Degradation on `{{ inputs.mesh_network_name }}`. Handshake Latency: `{{ outputs.scan_nebula_mesh_telemetry.vars.handshake_latency_ms }}`ms (threshold: `{{ inputs.max_handshake_latency_ms }}`ms). Cert Days Remaining: `{{ outputs.scan_nebula_mesh_telemetry.vars.cert_days_remaining }}` (threshold: `{{ inputs.min_certificate_days_remaining }}`). Unreachable Peers: `{{ outputs.scan_nebula_mesh_telemetry.vars.unreachable_peers_count }}`. Audit Timestamp: `{{ outputs.scan_nebula_mesh_telemetry.vars.audit_timestamp }}`."
}
else:
- id: log_nominal_nebula_state
type: io.kestra.plugin.core.log.Log
description: Records nominal telemetry when Nebula overlay mesh routes
peer-to-peer encrypted packets with low latency.
message: "Nebula overlay mesh operating nominally: {{
outputs.scan_nebula_mesh_telemetry.vars.handshake_latency_ms }}ms
handshake latency, {{
outputs.scan_nebula_mesh_telemetry.vars.active_tunnels_count }}
tunnels, {{
outputs.scan_nebula_mesh_telemetry.vars.cert_days_remaining }}
certificate days remaining."
- id: emit_audit_manifest
type: io.kestra.plugin.core.debug.Return
description: Emits structured audit manifest for zero-trust mesh network
security compliance archives and SLA records.
format: |
{
"status": "{{ outputs.scan_nebula_mesh_telemetry.vars.is_alerting ? 'ALERT' : 'NOMINAL' }}",
"mesh_network": "{{ inputs.mesh_network_name }}",
"handshake_latency_ms": {{ outputs.scan_nebula_mesh_telemetry.vars.handshake_latency_ms }},
"active_tunnels": {{ outputs.scan_nebula_mesh_telemetry.vars.active_tunnels_count }},
"unreachable_peers": {{ outputs.scan_nebula_mesh_telemetry.vars.unreachable_peers_count }},
"cert_days_remaining": {{ outputs.scan_nebula_mesh_telemetry.vars.cert_days_remaining }},
"audit_timestamp": "{{ outputs.scan_nebula_mesh_telemetry.vars.audit_timestamp }}"
}
triggers:
- id: periodic_nebula_audit
type: io.kestra.plugin.core.trigger.Schedule
cron: "*/15 * * * *"