Gate Tetragon agents on node BTF capability
Homelab Main / validate (push) Waiting to run Details
Homelab Main / running-update (push) Blocked by required conditions Details
Homelab Main / debian-ops (push) Blocked by required conditions Details

This commit is contained in:
juvenal.diaz 2026-11-04 07:43:44 -06:00
parent 53bd363966
commit 7e485915e7
6 changed files with 127 additions and 2 deletions

View File

@ -2417,7 +2417,10 @@ resource "helm_release" "extra_tools" {
namespace = each.value.namespace
create_namespace = each.value.create_namespace
timeout = each.value.timeout
values = each.value.values_yaml != "" ? [each.value.values_yaml] : []
values = concat(each.value.values_yaml != "" ? [each.value.values_yaml] : [], each.key == "tetragon" ? [yamlencode({
tetragon = { enabled = var.tetragon_agent_enabled }
nodeSelector = { "homelab.dev/kernel-btf" = "true" }
})] : [])
depends_on = [null_resource.calico_ready]
dynamic "set" {

View File

@ -330,6 +330,12 @@ variable "prometheus_stack_node_selector" {
}
}
variable "tetragon_agent_enabled" {
description = "Enable the Tetragon agent after the pipeline finds at least one node with kernel BTF."
type = bool
default = false
}
variable "grafana_sso_enabled" {
description = "Enable Grafana Generic OAuth when the SSO stack's client-secret exists."
type = bool
@ -385,7 +391,7 @@ variable "extra_helm_releases" {
tetragon:
enableProcessCred: true
enableProcessNs: true
exportFilename: /var/run/cilium/tetragon/tetragon.log
exportFilename: tetragon.log
# Set both fields so upgrades/downgrades cannot retain an
# incompatible allowPrivilegeEscalation=false from an older pod
# template. This privileged eBPF agent requires host access.

View File

@ -1,5 +1,22 @@
# Application Operations
## Tetragon kernel capability
Platform applies probe `/sys/kernel/btf/vmlinux` over SSH on each live node
using the declared cluster credentials, then label nodes with
`homelab.dev/kernel-btf=true` or `false`. Tetragon's agent selects nodes with
the true label. If no node exposes BTF, Helm disables the agent DaemonSet and
reports that runtime tracing is unavailable. The operator remains installed.
Plans probe capability without changing labels. SSH probe failures stop the
operation rather than being interpreted as missing BTF.
This applies to every cluster profile. The Orange Pi Rockchip kernel
`5.10.160-rockchip-rk3588` was observed without host BTF, so the native profile
currently has no Tetragon agent coverage. Running the agent requires a kernel
with BTF enabled or a separately configured BTF artifact matching the exact
kernel build. The pipeline does not install or replace host kernels. BTF
presence is a prerequisite, not proof that all eBPF features are supported.
## Homelab Overview dashboard
When the selected cluster is remote, platform/apps applies and edge route setup

View File

@ -1,5 +1,22 @@
# Application Operations
## Tetragon kernel capability
Platform applies probe `/sys/kernel/btf/vmlinux` over SSH on each live node
using the declared cluster credentials, then label nodes with
`homelab.dev/kernel-btf=true` or `false`. Tetragon's agent selects nodes with
the true label. If no node exposes BTF, Helm disables the agent DaemonSet and
reports that runtime tracing is unavailable. The operator remains installed.
Plans probe capability without changing labels. SSH probe failures stop the
operation rather than being interpreted as missing BTF.
This applies to every cluster profile. The Orange Pi Rockchip kernel
`5.10.160-rockchip-rk3588` was observed without host BTF, so the native profile
currently has no Tetragon agent coverage. Running the agent requires a kernel
with BTF enabled or a separately configured BTF artifact matching the exact
kernel build. The pipeline does not install or replace host kernels. BTF
presence is a prerequisite, not proof that all eBPF features are supported.
## Homelab Overview dashboard
When the selected cluster is remote, platform/apps applies and edge route setup

View File

@ -17,6 +17,12 @@ configure_platform_grafana_sso() {
fi
}
configure_platform_tetragon_capabilities() {
local enabled
enabled="$(python3 "${REPO_ROOT}/scripts/tetragon-capabilities.py" "$@")" || return 1
export TF_VAR_tetragon_agent_enabled="${enabled}"
}
require_debian_server() {
local command_name="$1"
local os_id=""
@ -821,6 +827,7 @@ run_tofu_stack() {
if [[ "${stack}" == "bootstrap/platform" ]]; then
configure_platform_grafana_sso
ensure_platform_scheduling_labels || return 1
configure_platform_tetragon_capabilities --label-nodes || return 1
fi
tofu -chdir="${REPO_ROOT}/${stack}" init || return 1
@ -887,6 +894,7 @@ run_tofu_plan_stack() {
if [[ "${stack}" == "bootstrap/platform" ]]; then
configure_platform_grafana_sso
configure_platform_tetragon_capabilities || return 1
fi
tofu -chdir="${REPO_ROOT}/${stack}" init

View File

@ -0,0 +1,74 @@
#!/usr/bin/env python3
"""Probe host BTF and optionally label eligible Tetragon nodes."""
import argparse
import importlib.util
import json
import os
from pathlib import Path
import subprocess
import sys
import yaml
REPO = Path(__file__).resolve().parents[1]
LABEL = "homelab.dev/kernel-btf"
def run(command):
return subprocess.run(command, check=True, text=True, capture_output=True, timeout=30).stdout.strip()
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--label-nodes", action="store_true")
args = parser.parse_args()
inventory = yaml.safe_load(Path(os.environ.get("HOMELAB_INVENTORY_FILE", REPO / "homelab.yml")).read_text())
profile = os.environ.get("LAB_CLUSTER_PROFILE") or inventory["cluster"]["active_profile"]
control = inventory["cluster"]["profiles"][profile]["control_plane"]
spec = importlib.util.spec_from_file_location("tetragon_cluster_context", REPO / "scripts/cluster-context.py")
context = importlib.util.module_from_spec(spec)
spec.loader.exec_module(context)
ctx = context.Context(profile)
ctx.check()
credentials = {control["lan_ip"]: (control["user"], control["ssh_key_path"])}
for address in inventory["cluster"]["profiles"]["pimox"]["pimox"]["worker_static_ips"].split():
credentials.setdefault(address, (control["user"], control["ssh_key_path"]))
workers = REPO / ".lab/pimox-workers.tsv"
if workers.is_file() and profile != "k3s":
for line in workers.read_text().splitlines():
fields = line.split("\t")
if len(fields) == 5:
_, address, user, _, key = fields
credentials[address] = (user, key)
nodes = json.loads(run(ctx.client() + ["--request-timeout=15s", "get", "nodes", "-o", "json"]))["items"]
results = []
for node in nodes:
name = node["metadata"]["name"]
addresses = [a["address"] for a in node["status"]["addresses"] if a["type"] == "InternalIP" and a["address"] in credentials]
if len(addresses) != 1:
raise RuntimeError(f"{name}: no unique declared SSH target for kernel capability probe")
address = addresses[0]
user, key = credentials[address]
result = run(["ssh", "-T", "-i", key, "-o", "BatchMode=yes", "-o", "IdentitiesOnly=yes",
"-o", "ConnectTimeout=10", "-o", "StrictHostKeyChecking=accept-new", f"{user}@{address}",
"if test -s /sys/kernel/btf/vmlinux; then echo true; else echo false; fi"])
if result not in ("true", "false"):
raise RuntimeError(f"{name}: ambiguous BTF probe result")
results.append((node, result))
for node, result in results:
name = node["metadata"]["name"]
if args.label_nodes and node["metadata"].get("labels", {}).get(LABEL) != result:
run(ctx.client() + ["--request-timeout=15s", "label", "node", name, f"{LABEL}={result}", "--overwrite"])
print(f"Tetragon BTF capability: {name}={result}", file=sys.stderr)
enabled = any(result == "true" for _, result in results)
if not enabled:
print("Tetragon agent disabled: no cluster node exposes host kernel BTF. Runtime tracing is unavailable.", file=sys.stderr)
print("true" if enabled else "false")
if __name__ == "__main__":
try:
main()
except (OSError, RuntimeError, KeyError, ValueError, subprocess.SubprocessError) as error:
raise SystemExit(f"Tetragon capability detection refused: {error}")