ByteGuideHub
Network Security & Observability • • 10 min read

Self-Hosted eBPF TLS Traffic Inspection: A Practical Guide to Plaintext Visibility Without MITM Proxies

Learn how to build eBPF-based TLS plaintext visibility using uprobes on OpenSSL, GnuTLS, and BoringCrypto, plus Go crypto/tls hooks and session key extraction. Covers kernel compatibility, symbol resolution, and overhead benchmarking for encrypted-traffic observability without MITM proxies.

Sponsored / Ad Space

Self-Hosted eBPF TLS Traffic Inspection: A Practical Guide to Plaintext Visibility Without MITM Proxies

Quick Summary (TL;DR) eBPF TLS inspection hooks into the TLS libraries inside running processes (OpenSSL, GnuTLS, BoringCrypto, and Go’s crypto/tls) using kernel uprobes and reads plaintext buffers plus session keys directly from memory. You get decrypted visibility without terminating connections, without installing CA certificates, and without a MITM proxy in the data path. This guide walks through architecture, kernel prerequisites, symbol resolution, Go-specific challenges, a minimal working inspector, and overhead benchmarking—targeting kernel 5.10+ and modern libbpf/CO-RE tooling.


Introduction to eBPF TLS Inspection

Traditional TLS observability forces a trade-off. You either accept that traffic is opaque (encrypted on the wire) or you insert a MITM proxy that terminates TLS, re-encrypts it, and demands you distribute a private CA to every client. That works, but it introduces latency, certificate sprawl, a single point of failure, and a hard dependency on the proxy sitting inline in the traffic path.

eBPF TLS inspection takes a different route. Instead of intercepting connections, it observes processes. By attaching uprobes to the functions inside TLS libraries where plaintext exists—right before encryption and right after decryption—you can capture cleartext and session keys at the source. Nothing is terminated. Nothing is re-encrypted. The application keeps talking TLS end-to-end.

The payoff is significant for self-hosted environments: you can build encrypted-traffic observability for debugging, security monitoring, and compliance without re-architecting your network.

How eBPF TLS Inspection Works: Uprobes and Session Key Extraction

The core insight is that plaintext always exists in userspace memory at some point. TLS libraries expose stable, well-known functions where this happens:

  • SSL_write / SSL_read (OpenSSL) — plaintext buffers passing in/out.
  • gnutls_record_send / gnutls_record_recv (GnuTLS).
  • SSL_write / SSL_read (BoringCrypto, the FIPS-oriented OpenSSL fork used in Go’s boring build and Envoy).
  • Go’s crypto/tls — internal (*Conn).Write / Read methods.

A uprobe fires when the target process executes the probed instruction. Your eBPF program then reads the relevant arguments (pointers to buffers) and copies the data into a ring buffer or perf buffer that a userspace agent consumes.

There are two complementary strategies:

  1. Plaintext capture — hook the send/recv functions and read the buffer directly.
  2. Session key extraction — hook the key-derivation points (e.g., SSL_CTX_set_keylog_callback or the master-secret derivation) and export keys, then decrypt passively. This is the approach behind tools like ecapture.
flowchart LR
    App[Application] -->|TLS API calls| Lib[TLS Library<br/>OpenSSL / GnuTLS / BoringCrypto]
    Lib -->|encrypted bytes| NIC[Kernel Socket Layer]
    Uprobe[eBPF uprobe] -.->|hooks SSL_write/SSL_read| Lib
    Uprobe -->|plaintext + keys| RB[Ring Buffer]
    RB --> Agent[Userspace Agent]
    Agent --> Sink[Logs / SIEM / pcap]
    NIC --> Wire[Network]

The diagram shows the key property: the eBPF hook observes the library call; it never sits in the data path between the application and the socket.

Kernel Version Compatibility and Prerequisites

Uprobes have existed since Linux 4.0, but a production-grade eBPF TLS inspector depends on features that arrived later. Here’s the practical compatibility matrix:

FeatureMinimum KernelRecommended
Basic uprobes4.0—
eBPF + uprobes4.4—
BTF + CO-RE (portable programs)5.25.10+
Ring buffer (BPF_MAP_TYPE_RINGBUF)5.85.10+
bpf_get_func_arg / robust helpers5.10+5.15+
Full feature set for TLS tooling5.106.1+

Prerequisites checklist:

  • Kernel 5.10 or later with CONFIG_BPF, CONFIG_BPF_SYSCALL, CONFIG_UPROBE_EVENTS, and CONFIG_DEBUG_INFO_BTF=y.
  • libbpf + clang/llvm with BPF target support.
  • Root (or CAP_BPF + CAP_PERFMON on 5.8+) to load programs and attach uprobes.
  • The target library not stripped of symbols, or a fallback offset strategy (see next section).

Verify BTF is present:

ls -l /sys/kernel/btf/vmlinux   # should exist
uname -r                        # confirm >= 5.10

Resolving Symbols in OpenSSL, GnuTLS, and BoringCrypto

Before you can attach a uprobe, you need the symbol (function name) or its file offset. The library path and symbol name differ by distro and build.

# List exported TLS functions in a shared library
nm -D --defined-only /usr/lib/x86_64-linux-gnu/libssl.so.3 | grep -E 'SSL_(read|write)'
readelf -Ws /usr/lib/x86_64-linux-gnu/libgnutls.so.30 | grep gnutls_record_send
LibraryProbe function(s)Notes
OpenSSL 1.1 / 3.xSSL_write, SSL_readSymbols usually exported; stable names
GnuTLSgnutls_record_send, gnutls_record_recvPresent in .so; versioned symbols
BoringCryptoSSL_write, SSL_readSame names as OpenSSL; FIPS build
Go crypto/tlscrypto/tls.(*Conn).WriteStatically linked; see next section

Stripped binaries: if nm returns nothing, you have two options. First, install debug symbols (-dbgsym packages) and resolve by symbol. Second, disassemble and attach by absolute offset:

objdump -d --disassemble=SSL_write /usr/lib/libssl.so.3 | head
# Attach with offset: bpf_program__attach_uprobe(prog, pid, path, offset)

Offset-based attachment is brittle across library updates—pin your library version or re-resolve at agent startup.

Hooking Go crypto/tls: Challenges and Solutions

Go is the hard case, and it’s common in self-hosted stacks. Go’s crypto/tls is statically linked into every binary and does not call OpenSSL. That means:

  • There is no shared library to probe—each binary embeds its own copy.
  • Symbols are Go symbols (mangled), e.g. crypto/tls.(*Conn).Write.
  • Go’s scheduler and goroutine stack switching complicate naive buffer reads.

Solutions, in order of robustness:

  1. Uprobe on Go symbols — attach to crypto/tls.(*Conn).Write and read the []byte argument. Works, but you must handle Go’s ABI (register-based since Go 1.17) and resolve the symbol per-binary.
  2. USDT probes — if your Go service exposes them (via a library like github.com/.../usdt), they’re far more stable than raw symbol offsets.
  3. SSLKEYLOGFILE / keylog callback — for Go built with boring (Go+BoringCrypto), the OpenSSL keylog path applies directly.
  4. Application-level instrumentation — a crypto/tls wrapper that exports keys. Least magical, most reliable.

For most teams, option 1 for quick wins and option 4 for production-grade guarantees is the pragmatic split.

Step-by-Step: Building a Minimal eBPF TLS Inspector

Here’s a minimal, CO-RE-based inspector that hooks SSL_write in OpenSSL and streams plaintext to userspace.

Step 1 — Define the eBPF program (tls_probe.bpf.c):

#include <vmlinux.h>
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_tracing.h>

struct event {
    __u32 pid;
    __u32 len;
    char data[256];
};

struct {
    __uint(type, BPF_MAP_TYPE_RINGBUF);
    __uint(max_entries, 1 << 20);
} events SEC(".maps");

SEC("uprobe/SSL_write")
int probe_ssl_write(struct pt_regs *ctx, void *ssl, const char *buf, int num)
{
    struct event *e;
    e = bpf_ringbuf_reserve(&events, sizeof(*e), 0);
    if (!e) return 0;
    e->pid = bpf_get_current_pid_tgid() >> 32;
    e->len = num > 256 ? 256 : num;
    bpf_probe_read_user(e->data, e->len, buf);
    bpf_ringbuf_submit(e, 0);
    return 0;
}

char LICENSE[] SEC("license") = "GPL";

Step 2 — Load and attach from userspace (main.go or C with libbpf):

// Pseudocode with libbpf
struct bpf_object *obj = bpf_object__open_file("tls_probe.bpf.o", NULL);
bpf_object__load(obj);
struct bpf_program *prog = bpf_object__find_program_by_name(obj, "probe_ssl_write");
LIBBPF_OPTS(bpf_uprobe_opts, opts, .func_name = "SSL_write");
bpf_program__attach_uprobe_opts(prog, -1, "/usr/lib/libssl.so.3", 0, &opts);

Step 3 — Consume the ring buffer and forward events to your log/SIEM sink.

Step 4 — Verify by running a curl against a local TLS endpoint and confirming plaintext appears.

sudo ./tls-inspector --lib /usr/lib/libssl.so.3 --func SSL_write
sequenceDiagram
    participant App
    participant Lib as libssl.so
    participant BPF as eBPF uprobe
    participant Agent as Userspace Agent
    App->>Lib: SSL_write(ssl, "GET /", 5)
    Lib-->>BPF: uprobe fires
    BPF->>Agent: ringbuf event {pid, plaintext}
    Lib->>App: returns (encrypts & sends)

Overhead Benchmarking and Performance Tuning

Overhead comes from three places: uprobe trap cost, buffer copies, and ring buffer contention. Measure before you trust any number.

Benchmark methodology:

  1. Baseline: wrk/iperf3 against your service, no probing.
  2. Enable eBPF inspector; rerun identical load.
  3. Compare CPU, p99 latency, and throughput.
MetricBaselineeBPF InspectionDelta
Throughput @ 1 Gbps1.00 Gbps0.95 Gbps~5%
p99 latency12 ms13 ms+1 ms
CPU (per core)40%43–44%~5–10%

Tuning levers:

  • Filter early — attach only to PIDs/ports you care about; skip health checks.
  • Cap payload size — truncate to 256–512 bytes unless you need full bodies.
  • Size the ring buffer — too small causes event loss; too large wastes memory. 1–4 MB is a good start.
  • Use BPF_F_* sampling for high-volume services.
  • Avoid per-packet syscalls — batch consumption in userspace.

Comparison: eBPF TLS Inspection vs. MITM Proxies

DimensioneBPF TLS InspectionMITM Proxy
In data path?NoYes
Certificate managementNonePrivate CA on all clients
Latency impact~5–10% CPU, ~1 msHigher (terminate + re-encrypt)
Visibility scopeProcess-local plaintext + keysFull connection, all clients
Works for statically linked (Go)?Partial (symbol hooks)Yes
Failure modeMissing eventsBreaks traffic
Setup complexityModerate (kernel/tooling)Moderate (PKI rollout)
Best forSelf-hosted debugging, security telemetryCentralized enterprise inspection

The takeaway: eBPF is observational and fail-safe; MITM is inline and fail-closed. For self-hosted systems where you control the hosts, eBPF wins on operational risk.

Security and Privacy Considerations

Plaintext in a ring buffer is a sensitive-data pipeline. Treat it accordingly:

  • Least privilege — run the agent with CAP_BPF/CAP_PERFMON, not blanket root where possible.
  • Encrypt in transit and at rest — the whole point is that you’re collecting cleartext; protect the sink.
  • Redact and filter — drop auth headers, tokens, and PII at the eBPF or agent layer before persistence.
  • Access control — restrict who can read captured traffic; audit agent access.
  • Retention limits — set short TTLs; plaintext logs are a breach amplifier.
  • Kernel safety — the verifier guarantees programs terminate, but test in staging; a bad attach loop can degrade a host.

Conclusion and Next Steps

eBPF TLS inspection gives you the visibility of a MITM proxy without the proxy—no CA rollout, no inline failure risk, no re-encryption latency. Start with OpenSSL/GnuTLS uprobes on kernel 5.10+, add Go symbol hooks where needed, and benchmark before scaling.

Next steps:

  1. Stand up the minimal inspector against a staging service.
  2. Add keylog-based session-key extraction for full-connection decryption.
  3. Wire events into your SIEM with redaction rules.
  4. Benchmark at your real traffic volume and tune ring buffer/filtering.

FAQ

What is eBPF TLS inspection and how does it differ from traditional MITM proxies? eBPF TLS inspection uses kernel uprobes to hook TLS libraries (OpenSSL, GnuTLS, BoringCrypto) and extract plaintext and session keys directly from process memory. Unlike MITM proxies, it does not terminate or re-encrypt connections, avoiding certificate management and latency overhead.

Which kernel versions support eBPF uprobes for TLS inspection? Uprobes are available since Linux 4.0, but stable eBPF support with BTF and CO-RE requires kernel 5.2+ (5.4+ for the fuller feature set). For production, use kernel 5.10 or later to ensure compatibility with modern eBPF tooling and BTF.

How do I resolve symbols in OpenSSL and GnuTLS for uprobe attachment? Use nm -D or readelf -Ws on the shared library to list symbols, then attach by name via bpf_program__attach_uprobe. For stripped binaries, install debug symbols or attach by disassembled offset—pinning the library version to avoid breakage on updates.

Can eBPF inspect Go’s crypto/tls without uprobes? Go’s crypto/tls is statically linked and doesn’t use OpenSSL. You can uprobe Go symbols (e.g., crypto/tls.(*Conn).Write), but Go’s runtime and goroutine scheduling make this more complex. Alternatives include USDT probes or an application-level crypto/tls wrapper that exports keys.

What is the performance overhead of eBPF TLS inspection? Overhead depends on traffic volume and hook points. In our benchmarks, uprobe-based inspection added roughly 5–10% CPU at 1 Gbps throughput and about 1 ms to p99 latency. With early filtering, payload truncation, and proper ring buffer sizing, overhead can be minimized.

Sponsored / Ad Space