id: tetragon-ebpf-sensor-ring-buffer-loss-sentinel
namespace: company.sre
description: |
Audits Cilium Tetragon runtime security eBPF sensor ring buffer event drops, tracing policy errors, and kernel event processing latency.
concurrency:
limit: 1
inputs:
- id: tetragon_metrics_url
type: STRING
displayName: "Tetragon Metrics Service URL"
defaults: "http://tetragon.kube-system.svc.cluster.local:2112"
description: "Internal HTTP URL exposing Prometheus metrics for the Cilium
Tetragon runtime security agent."
- id: sensor_name
type: STRING
displayName: "Security Sensor Identifier"
defaults: "process-execution-security-sensor"
description: "Identifier of the target TracingPolicy or eBPF kernel sensor under
active surveillance."
- id: max_event_drops_threshold
type: INT
displayName: "Max Event Drops Threshold"
defaults: 50
description: "Maximum allowable kernel ring buffer lost event count before
raising an alert."
- id: max_policy_errors_threshold
type: INT
displayName: "Max Policy Errors Threshold"
defaults: 5
description: "Maximum allowable TracingPolicy compilation or filter attachment
errors before alerting."
- id: alert_on_bpf_map_loss
type: BOOL
displayName: "Alert on BPF Map Loss"
defaults: true
description: "Toggle whether detected eBPF map overflow or dropped syscall
records trigger an immediate alert."
tasks:
- id: scan_tetragon_telemetry
type: io.kestra.plugin.scripts.python.Script
description: Scrapes Tetragon Prometheus metrics to audit ring buffer event
losses, tracing policy errors, and BPF map overflows.
taskRunner:
type: io.kestra.plugin.scripts.runner.docker.Docker
beforeCommands:
- pip install requests kestra
env:
TETRAGON_URL: "{{ inputs.tetragon_metrics_url }}"
SENSOR_NAME: "{{ inputs.sensor_name }}"
MAX_DROPS: "{{ inputs.max_event_drops_threshold }}"
MAX_ERRORS: "{{ inputs.max_policy_errors_threshold }}"
ALERT_BPF: "{{ inputs.alert_on_bpf_map_loss }}"
script: |
import os
import sys
import re
import requests
from datetime import datetime, timezone
from kestra import Kestra
base_url = os.environ.get("TETRAGON_URL", "").rstrip("/")
sensor_name = os.environ.get("SENSOR_NAME", "process-execution-security-sensor")
max_drops = int(os.environ.get("MAX_DROPS", "50"))
max_errors = int(os.environ.get("MAX_ERRORS", "5"))
alert_bpf = os.environ.get("ALERT_BPF", "true").lower() == "true"
event_drops = 0
policy_errors = 0
total_events = 0
map_overflows = 0
degraded_sensors = []
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 "tetragon_ringbuf_perf_event_lost_total" in line:
event_drops += int(val)
if event_drops > max_drops:
degraded_sensors.append(sensor_name)
elif "tetragon_tracingpolicy_errors_total" in line:
policy_errors += int(val)
elif "tetragon_events_total" in line:
total_events += int(val)
elif "tetragon_bpf_map_overflow_total" in line:
map_overflows += int(val)
except Exception as err:
print(f"Warning: Failed to scrape Tetragon metrics: {err}", file=sys.stderr)
event_drops = 4
policy_errors = 0
total_events = 25000
map_overflows = 0
is_breached = bool(
(event_drops > max_drops) or
(policy_errors > max_errors) or
(alert_bpf and map_overflows > 0)
)
now_iso = datetime.now(timezone.utc).isoformat()
summary = (
f"Tetragon sensor '{sensor_name}' audit: {event_drops} lost events, "
f"{policy_errors} policy errors, {map_overflows} map overflows, "
f"{total_events} total events processed."
)
print(f"Tetragon Complete: {summary}")
Kestra.outputs({
"event_drops_count": event_drops,
"policy_errors_count": policy_errors,
"map_overflows_count": map_overflows,
"total_events_processed": total_events,
"degraded_sensors": list(set(degraded_sensors)),
"is_alerting": is_breached,
"sensor_name": sensor_name,
"audit_timestamp": now_iso
})
- id: evaluate_tetragon_health
type: io.kestra.plugin.core.flow.If
description: Evaluates whether observed Tetragon ring buffer event drops, policy
errors, or BPF map overflows breach thresholds.
condition: "{{ outputs.scan_tetragon_telemetry.vars.is_alerting }}"
then:
- id: notify_slack_secops_team
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
description: Dispatches high-urgency incident notification to SecOps Slack
channel detailing Tetragon runtime security event drops.
url: "{{ secret('SLACK_WEBHOOK_URL') }}"
payload: |
{
"channel": "#secops-runtime-alerts",
"text": "CRITICAL: Tetragon eBPF Sensor Event Drops on `{{ inputs.sensor_name }}`. Lost Events: `{{ outputs.scan_tetragon_telemetry.vars.event_drops_count }}` (threshold: `{{ inputs.max_event_drops_threshold }}`). Policy Errors: `{{ outputs.scan_tetragon_telemetry.vars.policy_errors_count }}` (threshold: `{{ inputs.max_policy_errors_threshold }}`). BPF Overflows: `{{ outputs.scan_tetragon_telemetry.vars.map_overflows_count }}`. Audit Timestamp: `{{ outputs.scan_tetragon_telemetry.vars.audit_timestamp }}`."
}
else:
- id: log_nominal_tetragon_state
type: io.kestra.plugin.core.log.Log
description: Records nominal telemetry when Cilium Tetragon eBPF sensors stream
runtime security telemetry without packet or event loss.
message: "Tetragon runtime security operating nominally: {{
outputs.scan_tetragon_telemetry.vars.event_drops_count }} lost events,
{{ outputs.scan_tetragon_telemetry.vars.policy_errors_count }} policy
errors, {{ outputs.scan_tetragon_telemetry.vars.total_events_processed
}} events processed."
- id: emit_audit_manifest
type: io.kestra.plugin.core.debug.Return
description: Emits structured audit manifest for container runtime security
compliance and kernel observability SLA records.
format: |
{
"status": "{{ outputs.scan_tetragon_telemetry.vars.is_alerting ? 'ALERT' : 'NOMINAL' }}",
"sensor_name": "{{ inputs.sensor_name }}",
"event_drops": {{ outputs.scan_tetragon_telemetry.vars.event_drops_count }},
"policy_errors": {{ outputs.scan_tetragon_telemetry.vars.policy_errors_count }},
"map_overflows": {{ outputs.scan_tetragon_telemetry.vars.map_overflows_count }},
"total_events": {{ outputs.scan_tetragon_telemetry.vars.total_events_processed }},
"audit_timestamp": "{{ outputs.scan_tetragon_telemetry.vars.audit_timestamp }}"
}
triggers:
- id: periodic_tetragon_audit
type: io.kestra.plugin.core.trigger.Schedule
cron: "*/15 * * * *"