Skip to content

feat(tls): attach Go TLS probes at exec, and log where L7 events are dropped - #355

Merged
mayankpande88 merged 3 commits into
fix/tls-capture-gapsfrom
feat/exec-attach
Oct 5, 2026
Merged

mayankpande88 merged 3 commits into
fix/tls-capture-gapsfrom
feat/exec-attach

Conversation

@mayankpande88

Copy link
Copy Markdown
Contributor

Stacked on #353. It targets that branch until #353 merges.

Problem

  • Probes attached late. A process's Go TLS probes were attached on its first connection, after that connection's event had been read. A short-lived program had often exited by then, or had already made its first requests unprobed.
  • Exec'd programs kept the wrong probes. A program started by a wrapper's exec kept the probes for the wrapper's binary until a throttled re-check noticed the change.
  • Drops couldn't be traced. node_agent_l7_events_dropped_total gave a reason, but there was no way to tell which workload the drops came from.

Change

  • Attach at exec. A sched_process_exec tracepoint reports execs. The agent attaches Go TLS probes for the new image at once, and drops those of the old image along with its offsets entry. OpenSSL is still attached on the first connection, because the dynamic loader maps libssl after the exec.
  • Faster process events. Process events are read every 10 ms, like connect events, instead of every 100 ms.
  • Fallback re-check. The periodic executable re-check stays as a fallback for lost exec events, now at a 10 s interval instead of on every new socket.
  • One log line per drop source. Every L7 event dropped before parsing is logged once per container, reason and protocol, with the pid, fd and destination.
  • New no_ip_socket reason. Events on sockets without an IP tuple, such as gRPC over a Unix socket, which the agent does not track, now get their own reason instead of unknown_connection.

Verification

  • gofmt, goimports, go vet ./..., golangci-lint and go test (CI package set, plus containers locally) pass on linux/arm64. ebpf.go is regenerated with make build.
Local end-to-end run

Local e2e: built the agent from this branch and from the head of #353, and ran each privileged in a local Linux VM (kernel 6.10, standalone mode) against the same scenario set.

scenario #353 head this branch
Short-lived Go TLS clients (391 processes): requests captured 350 390
…attach attempts where the process had already exited 40 2
Wrapper that execs a client making 2 requests (17 runs): requests captured 7 19
Wrapper that execs a client making 5 requests (8 runs, 40 requests) 27 31
…same client without the wrapper 32 32
Data races, -race build 0 0
  • First requests: a short-lived program's first request is usually still sent before its probes are attached, because attaching at exec takes 10–20 ms. Catching it would need probes attached per binary instead of per process, left as a follow-up.

Cluster run. The branch ran as a DaemonSet on a multi-node cluster.

  • Health: all pods had 0 restarts, and there were no scrape or eBPF load errors.
  • fix(tls): count TLS capture losses and fix the gaps they exposed #353's parser fix: node_agent_http2_parser_stale_reuse_total went from about 111/min to 0.
  • Drop logs:
    • The unknown_connection HTTP/2 drops came only from Docker-in-Docker containers, which speak gRPC over Unix sockets. That is the case the no_ip_socket reason now covers.
    • The remaining stale_connection drops are about 30/min across all protocols: late events of a connection whose fd was reused.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces tracking for process exec events via the sched_process_exec tracepoint, allowing Go TLS probes to be attached immediately when a process replaces its image. This ensures short-lived programs and wrappers are probed before their first connection. Additionally, it refactors L7 event drop tracking to log detailed context once per container, reason, and protocol using an LRU cache. The review feedback recommends adding a process-specific identifier (pid) to the LRU cache key when the container ID is empty to prevent untracked processes from incorrectly suppressing each other's drop logs.

Comment thread containers/l7_self_metrics.go
Comment thread containers/l7_self_metrics.go
…dropped

A process's Go TLS probes were attached on its first connection, after
its connect event had been read. That was late for short-lived programs:
many exited first, and the rest had made their first requests unprobed.
A program that a wrapper exec'd kept probes for the wrapper's binary until
a throttled re-check noticed the change.

- A sched_process_exec tracepoint reports execs. The agent attaches Go
  TLS probes for the new image at once, and drops those of the old one.
  OpenSSL is still attached on the first connection, because the loader
  maps libssl after the exec.
- Process events are read every 10 ms, like connect events, instead of
  every 100 ms.
- The periodic executable re-check stays as a fallback for lost exec
  events, at a 10 s interval.
- Every L7 event dropped before parsing is logged once per container,
  reason and protocol, with the pid, fd and destination, so the counter's
  reasons can be traced to a workload.
Events on sockets without an IP tuple, such as gRPC over a Unix socket,
were counted as unknown_connection, which reads as a capture loss. The
agent does not track those sockets, so they now get their own reason.
@mayankpande88
mayankpande88 merged commit 6fd00a5 into fix/tls-capture-gaps Oct 5, 2026
2 checks passed
@mayankpande88
mayankpande88 deleted the feat/exec-attach branch October 5, 2026 15:26
blue4209211 pushed a commit that referenced this pull request Oct 6, 2026
* fix(tls): count TLS capture losses and fix the gaps they exposed

TLS capture could fail at attach time, in the kernel, or in the agent with
nothing to show for it at default verbosity. This adds counters for each
stage and fixes the losses they revealed.

Visibility:
- node_agent_tls_attach_total{lib,result} for every attach attempt, and
  one log line per binary and outcome instead of one per process.
- node_agent_tls_plaintext_dropped_total{reason}: TLS plaintext a library
  hook saw but could not attribute to a socket.
- node_agent_l7_ringbuf_drops_total: L7 events lost to a full ring buffer.
- node_agent_l7_events_dropped_total{reason,protocol,tls}: events dropped
  in the agent before protocol parsing.

Fixes:
- Register a process on its first socket event, so its first connection
  is tracked and its TLS probes attach before its first request.
- Give a connection built from an event's socket tuple the event's
  timestamp, and let a newer event replace the closed predecessor on a
  reused fd. Both cases used to be dropped as stale.
- Key the cache of binaries that cannot be probed by file identity, not
  by path, which is only meaningful inside one container.
- Re-attach after a process execs a different binary.
- Only a write that starts with a TLS record may claim pending OpenSSL
  plaintext, and that write's ciphertext now counts toward bytes sent.
- Guard Process state shared between the instrumentation goroutine, the
  event loop and the scrape path.

* fix(containers): read Python and Node.js stats under the container lock

Collect read c.pythonStats and c.nodejsStats without c.lock while the
registry's event loop updates them under it.

* fix(containers): filter and NAT-resolve connections built from socket tuples

A connection created from an L7 event's socket tuple, because the event
arrived before the connection's open event, skipped the filters and the
NAT resolution onConnectionOpen applies. With these connections now kept
(previous commit), that tracked traffic to ignored destinations and
labelled requests with a service's virtual IP as their actual destination.

- Both paths now share connectionKey: the same port, loopback, ignored
  workload and connection filters, and the same destination key.
- The socket-tuple path takes the actual destination from the kernel's
  conntrack-derived actual_destinations map, as open events do.
- An exec is re-checked on every new socket, not only when a throttle
  shared with the periodic sweep allows it.
- The go_fd_unknown help text says it includes TLS over in-memory
  connections, which have no socket.

* feat(tls): attribute TLS losses per container and find sockets behind wrapped Go connections (#354)

* feat(tls): attribute TLS plaintext losses to the container and binary

node_agent_tls_plaintext_dropped_total says how much TLS plaintext the
kernel could not attribute to a socket, but not which process it came
from, so a loss could not be traced to a workload without a debug build.

- The TLS library uprobes also count losses per process and reason in an
  LRU map. The syscall programs are left alone.
- The agent reads and clears those counts every stats tick, and drains a
  process's entries when it exits, since a short-lived process is gone
  before the next tick.
- container_tls_plaintext_dropped_total{reason} counts them per container.
- The first loss per binary and reason is logged once as a warning, naming
  the executable and what the reason usually means.

* fix(ebpf): find the socket behind wrapped Go connections

The Go TLS probe found a connection's socket only if crypto/tls ran
directly over *net.TCPConn, or over a wrapper embedding the connection
at offset 0, one level deep. Proxies and scrapers wrap deeper. One
reverse proxy's TLS connections are three wrappers deep, each embedding
the next at offset 0. A scraper's wrapper puts an int32 counter before
the embedded net.Conn, at offset 8. All of their TLS plaintext was
dropped.

The probe now descends up to four levels, taking the embedded net.Conn
at offset 0 or 8. A level is accepted when its type is the binary's
*net.TCPConn itab. Otherwise, as in stripped binaries, or PIE binaries
whose symbol table holds the itab unrelocated, the fd it yields is
accepted only if it names an IPv4 or IPv6 socket of the process. gRPC's
syscallConn has the same shape and goes through the same walk. TLS over
in-memory connections still has no socket and is still counted as
go_fd_unknown.

* fix(tls): log drops of unknown processes once per container, not once per node

An unknown process has no executable identity, so its log key was the
zero value and the first such warning on a node silenced the rest. Also
name the per-pid drop map key type.

* fix(containers): drop an fd's HTTP/2 parser when a new connection takes it

HTTP/2 parsers are keyed by pid+fd alone. When a recycled fd got a new
connection, either from its open event or from an L7 event that arrived
first, the new connection inherited the previous one's parser and its
HPACK dynamic table. Its headers then failed to decode, or decoded wrong.

The parser is now dropped when the fd's connection is replaced. A parser
already tagged with the new connection's timestamp is kept: it was created
for this connection by an L7 event that beat the open event.

* fix(tls): confirm the socket the Go TLS connection walk finds

A level of the walk that was not a *net.TCPConn was still read as one. For a
wrapper struct the first word is an itab pointer, so the "Sysfd" read was the
itab's type hash, and when a value read that way named another live socket of
the process, the socket check accepted it: the session's plaintext went to
that connection, and it was marked TLS, every time, for that binary. On
kernels without BTF the socket check was skipped, so all four levels were
trusted unchecked.

A level found without the itab must now point to a net.netFD whose family is
AF_INET or AF_INET6 and whose sotype is SOCK_STREAM. The check reads only the
application's memory, so it holds without kernel BTF. Where the kernel's
struct offsets are known, the fd must also be a SOCK_STREAM socket of that
family. The netFD offsets come from DWARF and default to 56 and 64, which
Go 1.17 through 1.26 share. The walk no longer reads the gRPC syscallConn
itab, so its discovery is gone.

New metrics make the kernel-dependent part visible:
- node_agent_go_tls_fd_resolved_total{method,depth}: method is itab, socket
  (netFD check plus kernel check) or shape (netFD check only, no BTF)
- node_agent_ebpf_info{program_variant,btf,socket_offsets}
- node_agent_ebpf_program_instructions and
  node_agent_ebpf_program_verified_instructions, per program

TestProgramsLoad loads the variant the running kernel gets and logs each
program's size and verifier cost. TestGoTLSFdWalk runs TLS over a plain, a
wrapped and a decoy connection and checks which socket each one is
attributed to. Both need root and VM=1.

* fix(containers): drop a timestamp-less HTTP/2 parser when a tracked connection takes its fd

A parser without a connection timestamp was created by events from a socket
the kernel was not tracking, such as a connection older than the agent. A
connection opening on its fd is tracked, and the kernel stamps every event of
a tracked connection with its timestamp, so the parser cannot be the new
connection's. It was kept, and the new connection inherited its HPACK table.

* feat(tls): attach Go TLS probes at exec, and log where L7 events are dropped (#355)

* feat(tls): attach Go TLS probes at exec, and log where L7 events are dropped

A process's Go TLS probes were attached on its first connection, after
its connect event had been read. That was late for short-lived programs:
many exited first, and the rest had made their first requests unprobed.
A program that a wrapper exec'd kept probes for the wrapper's binary until
a throttled re-check noticed the change.

- A sched_process_exec tracepoint reports execs. The agent attaches Go
  TLS probes for the new image at once, and drops those of the old one.
  OpenSSL is still attached on the first connection, because the loader
  maps libssl after the exec.
- Process events are read every 10 ms, like connect events, instead of
  every 100 ms.
- The periodic executable re-check stays as a fallback for lost exec
  events, at a 10 s interval.
- Every L7 event dropped before parsing is logged once per container,
  reason and protocol, with the pid, fd and destination, so the counter's
  reasons can be traced to a workload.

* fix(containers): report L7 events on non-IP sockets as no_ip_socket

Events on sockets without an IP tuple, such as gRPC over a Unix socket,
were counted as unknown_connection, which reads as a capture loss. The
agent does not track those sockets, so they now get their own reason.

* chore(ebpf): regenerate ebpf.go after rebasing onto the review fixes
mayankpande88 added a commit that referenced this pull request Oct 6, 2026
…he map lookup (#358)

* fix(tls): count TLS capture losses and fix the gaps they exposed

TLS capture could fail at attach time, in the kernel, or in the agent with
nothing to show for it at default verbosity. This adds counters for each
stage and fixes the losses they revealed.

Visibility:
- node_agent_tls_attach_total{lib,result} for every attach attempt, and
  one log line per binary and outcome instead of one per process.
- node_agent_tls_plaintext_dropped_total{reason}: TLS plaintext a library
  hook saw but could not attribute to a socket.
- node_agent_l7_ringbuf_drops_total: L7 events lost to a full ring buffer.
- node_agent_l7_events_dropped_total{reason,protocol,tls}: events dropped
  in the agent before protocol parsing.

Fixes:
- Register a process on its first socket event, so its first connection
  is tracked and its TLS probes attach before its first request.
- Give a connection built from an event's socket tuple the event's
  timestamp, and let a newer event replace the closed predecessor on a
  reused fd. Both cases used to be dropped as stale.
- Key the cache of binaries that cannot be probed by file identity, not
  by path, which is only meaningful inside one container.
- Re-attach after a process execs a different binary.
- Only a write that starts with a TLS record may claim pending OpenSSL
  plaintext, and that write's ciphertext now counts toward bytes sent.
- Guard Process state shared between the instrumentation goroutine, the
  event loop and the scrape path.

* fix(containers): read Python and Node.js stats under the container lock

Collect read c.pythonStats and c.nodejsStats without c.lock while the
registry's event loop updates them under it.

* fix(containers): filter and NAT-resolve connections built from socket tuples

A connection created from an L7 event's socket tuple, because the event
arrived before the connection's open event, skipped the filters and the
NAT resolution onConnectionOpen applies. With these connections now kept
(previous commit), that tracked traffic to ignored destinations and
labelled requests with a service's virtual IP as their actual destination.

- Both paths now share connectionKey: the same port, loopback, ignored
  workload and connection filters, and the same destination key.
- The socket-tuple path takes the actual destination from the kernel's
  conntrack-derived actual_destinations map, as open events do.
- An exec is re-checked on every new socket, not only when a throttle
  shared with the periodic sweep allows it.
- The go_fd_unknown help text says it includes TLS over in-memory
  connections, which have no socket.

* feat(tls): attribute TLS losses per container and find sockets behind wrapped Go connections (#354)

* feat(tls): attribute TLS plaintext losses to the container and binary

node_agent_tls_plaintext_dropped_total says how much TLS plaintext the
kernel could not attribute to a socket, but not which process it came
from, so a loss could not be traced to a workload without a debug build.

- The TLS library uprobes also count losses per process and reason in an
  LRU map. The syscall programs are left alone.
- The agent reads and clears those counts every stats tick, and drains a
  process's entries when it exits, since a short-lived process is gone
  before the next tick.
- container_tls_plaintext_dropped_total{reason} counts them per container.
- The first loss per binary and reason is logged once as a warning, naming
  the executable and what the reason usually means.

* fix(ebpf): find the socket behind wrapped Go connections

The Go TLS probe found a connection's socket only if crypto/tls ran
directly over *net.TCPConn, or over a wrapper embedding the connection
at offset 0, one level deep. Proxies and scrapers wrap deeper. One
reverse proxy's TLS connections are three wrappers deep, each embedding
the next at offset 0. A scraper's wrapper puts an int32 counter before
the embedded net.Conn, at offset 8. All of their TLS plaintext was
dropped.

The probe now descends up to four levels, taking the embedded net.Conn
at offset 0 or 8. A level is accepted when its type is the binary's
*net.TCPConn itab. Otherwise, as in stripped binaries, or PIE binaries
whose symbol table holds the itab unrelocated, the fd it yields is
accepted only if it names an IPv4 or IPv6 socket of the process. gRPC's
syscallConn has the same shape and goes through the same walk. TLS over
in-memory connections still has no socket and is still counted as
go_fd_unknown.

* fix(tls): log drops of unknown processes once per container, not once per node

An unknown process has no executable identity, so its log key was the
zero value and the first such warning on a node silenced the rest. Also
name the per-pid drop map key type.

* fix(containers): drop an fd's HTTP/2 parser when a new connection takes it

HTTP/2 parsers are keyed by pid+fd alone. When a recycled fd got a new
connection, either from its open event or from an L7 event that arrived
first, the new connection inherited the previous one's parser and its
HPACK dynamic table. Its headers then failed to decode, or decoded wrong.

The parser is now dropped when the fd's connection is replaced. A parser
already tagged with the new connection's timestamp is kept: it was created
for this connection by an L7 event that beat the open event.

* fix(tls): confirm the socket the Go TLS connection walk finds

A level of the walk that was not a *net.TCPConn was still read as one. For a
wrapper struct the first word is an itab pointer, so the "Sysfd" read was the
itab's type hash, and when a value read that way named another live socket of
the process, the socket check accepted it: the session's plaintext went to
that connection, and it was marked TLS, every time, for that binary. On
kernels without BTF the socket check was skipped, so all four levels were
trusted unchecked.

A level found without the itab must now point to a net.netFD whose family is
AF_INET or AF_INET6 and whose sotype is SOCK_STREAM. The check reads only the
application's memory, so it holds without kernel BTF. Where the kernel's
struct offsets are known, the fd must also be a SOCK_STREAM socket of that
family. The netFD offsets come from DWARF and default to 56 and 64, which
Go 1.17 through 1.26 share. The walk no longer reads the gRPC syscallConn
itab, so its discovery is gone.

New metrics make the kernel-dependent part visible:
- node_agent_go_tls_fd_resolved_total{method,depth}: method is itab, socket
  (netFD check plus kernel check) or shape (netFD check only, no BTF)
- node_agent_ebpf_info{program_variant,btf,socket_offsets}
- node_agent_ebpf_program_instructions and
  node_agent_ebpf_program_verified_instructions, per program

TestProgramsLoad loads the variant the running kernel gets and logs each
program's size and verifier cost. TestGoTLSFdWalk runs TLS over a plain, a
wrapped and a decoy connection and checks which socket each one is
attributed to. Both need root and VM=1.

* fix(containers): drop a timestamp-less HTTP/2 parser when a tracked connection takes its fd

A parser without a connection timestamp was created by events from a socket
the kernel was not tracking, such as a connection older than the agent. A
connection opening on its fd is tracked, and the kernel stamps every event of
a tracked connection with its timestamp, so the parser cannot be the new
connection's. It was kept, and the new connection inherited its HPACK table.

* feat(tls): attach Go TLS probes at exec, and log where L7 events are dropped (#355)

* feat(tls): attach Go TLS probes at exec, and log where L7 events are dropped

A process's Go TLS probes were attached on its first connection, after
its connect event had been read. That was late for short-lived programs:
many exited first, and the rest had made their first requests unprobed.
A program that a wrapper exec'd kept probes for the wrapper's binary until
a throttled re-check noticed the change.

- A sched_process_exec tracepoint reports execs. The agent attaches Go
  TLS probes for the new image at once, and drops those of the old one.
  OpenSSL is still attached on the first connection, because the loader
  maps libssl after the exec.
- Process events are read every 10 ms, like connect events, instead of
  every 100 ms.
- The periodic executable re-check stays as a fallback for lost exec
  events, at a 10 s interval.
- Every L7 event dropped before parsing is logged once per container,
  reason and protocol, with the pid, fd and destination, so the counter's
  reasons can be traced to a workload.

* fix(containers): report L7 events on non-IP sockets as no_ip_socket

Events on sockets without an IP tuple, such as gRPC over a Unix socket,
were counted as unknown_connection, which reads as a capture loss. The
agent does not track those sockets, so they now get their own reason.

* chore(ebpf): regenerate ebpf.go after rebasing onto the review fixes

* fix: log each agent message once, and skip untracked sockets before the map lookup

klog.SetOutput hands every severity the same writer, and klog writes a
message to its own severity's writer and to every lower one's, so each
warning reached the log twice and each error three times. one_output
writes it once.

createConnectionFromSocketInfo parsed the socket tuple and looked up the
kernel's NAT map before applying the connection filters. A TLS server's
accepted sockets have a client's ephemeral port as their destination,
are never tracked, and came through this path on every read and write
the server made. The port filter is now checked first.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant