The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu
Go agent-ai-cliagent-harnessesagent-securitybrowser-extensionciclaude-codecloudcodexcursordetection-engineeringjevknowledge-basememorymobile-device-managementobservabilitysecuritysecurity-information-and-event-managementsecurity-toolstelemetrytraces
Address review: sock_diag ENOENT fallback, Cowork identity, Falcon HEC
Claude90c37af92c3a
diff --git a/CLAUDE.md b/CLAUDE.mdindex b56b80ca..3084c294 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -59,7 +59,7 @@ Supported runtime surfaces today:- DeepSeek Harness (`dsh`) is installed through two user-level files: `$DSH_HOME/beacon-endpoint-hooks.json` and a row in `$DSH_HOME/cordis.patch.yml`; there is no project scope. The `@deepseek-ai/dsh-hooks-claude-code` bridge that row mounts is not shipped with the CLI (dev dependency only) and must be installed per profile with `@deepseek-ai/dsh-hook-protocol` at exactly the dsh version; a mount dsh cannot load is skipped at boot with only a warning. So `InstallDsh` first runs `hooks.InspectDshBridge` (`internal/endpoint/hooks/dsh_bridge.go`, read-only: the installation found from the `dsh` launcher on PATH, each `$DSH_HOME/profiles/*` resolved Node-style, and rows in any patch layer that mount a bridge by absolute path at Beacon's hooks file) and returns `*DshBridgeUnavailableError` without writing anything when nothing loads a matching bridge; explicit `--harness dsh` fails, `--all` and endpoint install skip with a warning. A healthy by-path mount (how Nix installs it; it must also resolve its declared dsh peers from its own location, because dsh's host-package interception applies only to profile plugins, else `peers_missing`) counts as installed and Beacon writes no row of its own (removing one it wrote earlier) so hooks never run twice. Beacon never installs the packages. `DshStatus.Active`/`Bridge`, discovery (misconfigured when inactive), doctor `dsh_hook_bridge`, and inventory (each profile's patch layer) surface it; tests build on-disk fixtures with `internal/endpoint/hooks/dshtest`. It also installs a Beacon-owned local skill at `$DSH_HOME/skills/beacon-endpoint/SKILL.md` and supports native session backfill from `$DSH_HOME/sessions` through `beacon endpoint dsh sync`, which fills assistant text/reasoning, tool failures, and token usage that the hook bridge does not expose. It rides the Claude-shaped envelope on the hook path, but `run_code` remains `tool.invoked` because nested commands fire their own hooks.- fx (vercel-labs/fx) telemetry read from the session store fx commits under `~/.fx/sessions/`, covering session start, prompts, tool calls, commands with exit codes and output, file reads/creates/edits with diffs, MCP tool calls, agent messages, history compaction, and per-turn token usage plus reported cost. fx exposes no third-party hook, plugin, or OTLP surface -- its lifecycle hooks are compiled into the binary -- so collection is a read of fx's own records, run by `beacon endpoint fx sync`. Every event carries `harness.collection_method=poll`; approvals are not synthesized (fx persists permission feedback text, not a per-call decision, matching the Cline and Pi posture) and no session-end event is invented, since fx sessions are resumable. Implementation lives in `cli/beacon/internal/fxsession` and `cli/beacon/cmd/endpoint_fx.go`.- Harness² (google-research/harness2) rollouts, read from the executor event streams Harness² records under its runs directory (`$HARNESS2_RUNS_DIR`, `~/harness2/runs`, or a `--runs-dir` an earlier sync was given and the cursor file remembers): OpenCode `run --format json` and Codex `exec --json`, recognized by their first event rather than by file name. Harness² runs Codex under its own `CODEX_HOME` with `--ephemeral` and OpenCode from a source checkout, so Beacon's Codex/OpenCode integrations do not record these sessions. Events carry `harness.name=harness2`, `harness.collection_method=poll`, the executor's own session id, and the rollout's benchmark/task/label/run/trial/attempt/harness fingerprint under `raw.harness2`. Codex `turn.completed` usage is the thread's running total and is differenced per turn; Codex exec lines carry no times, so they take the file's mtime. No prompts (an argv argument, absent from both streams) and no approvals are recorded or synthesized. `testdata/recorded` holds streams recorded from the exact OpenCode and Codex releases Harness² pins; re-record them when it bumps either. Implementation lives in `cli/beacon/internal/harness2session` and `cli/beacon/cmd/endpoint_harness2.go`.-- Attribution of OTLP events: every account on a machine exports to the same loopback collector, and the exporter's base `user` is the collector process's own account (`asymptoteobserve.NewEvent` reads `$USER`/`$USERNAME`). On Linux the collector replaces it with the account that owns the sending socket (peer attribution): `collector.ConfigYAML` renders, only where `collector.PeerAttribution` (`runtime.GOOS == "linux"`), the `beacon_otlp_http` receiver (`collector-builder/exporter/beaconjsonexporter/otlphttpreceiver`, the upstream OTLP/HTTP protocol rebuilt on confighttp so `client.Info.Addr` keeps the client port that upstream drops; it replaces `otlp.protocols.http` on the same port) and the `beacon_peer` processor (`peerprocessor`, right after `memory_limiter` and before `batch`, which loses the connection) on Beacon's own pipelines, never the OTLP forward's, plus `peer_user: true` on beaconjson. `beacon_peer` removes `beacon.peer.uid`/`beacon.peer.user` wherever a sender put them (resource, scope, record, span, span event and link, every datapoint type), then asks `internal/peercred` for the owner of the client socket of exactly this connection: the client address from `client.Info.Addr` and the collector's end from the gRPC peer's `LocalAddr` or net/http's `LocalAddrContextKey` (no server address, no lookup). `peercred` first asks the kernel with one `NETLINK_SOCK_DIAG` exact four-tuple lookup (`diag_linux.go`, constant cost per export) and only when sock_diag itself is unavailable scans `/proc/net/tcp{,6}` for the same four-tuple; inode 0 (TIME_WAIT/orphan, uid printed 0), no match, or two owners are unknown, never guessed, and an unrelated TIME_WAIT on the same port is skipped. The name comes from `internal/accountname` (shared with `beacon_ingest`). The converter reads the peer attributes from the resource only (`mergeSignalAttrs`), and `applyPeerUser` copies them into `user` only with `Options.PeerUser`, before `normalizeClaudeCoworkContext`, whose cloud identity still wins; with `PeerUser` an unidentified sender gets an empty `user`, never the collector's root, so a recorded root always means root sent it. `CheckComponentsFor` refuses a collector without both where they are rendered. macOS and Windows have no lookup and keep the collector's account (root, or `COMPUTERNAME$` under LocalSystem). Hook and plugin events carry the person's uid or SID from `os/user.Current()` (verified by the OS in restricted mode). The person is also on the session's hook and plugin events, joined by `session.id`; the Sentinel guide carries the KQL. Never describe OTLP events on macOS or Windows as carrying the person who ran the agent.+- Attribution of OTLP events: every account on a machine exports to the same loopback collector, and the exporter's base `user` is the collector process's own account (`asymptoteobserve.NewEvent` reads `$USER`/`$USERNAME`). On Linux the collector replaces it with the account that owns the sending socket (peer attribution): `collector.ConfigYAML` renders, only where `collector.PeerAttribution` (`runtime.GOOS == "linux"`), the `beacon_otlp_http` receiver (`collector-builder/exporter/beaconjsonexporter/otlphttpreceiver`, the upstream OTLP/HTTP protocol rebuilt on confighttp so `client.Info.Addr` keeps the client port that upstream drops; it replaces `otlp.protocols.http` on the same port) and the `beacon_peer` processor (`peerprocessor`, right after `memory_limiter` and before `batch`, which loses the connection) on Beacon's own pipelines, never the OTLP forward's, plus `peer_user: true` on beaconjson. `beacon_peer` removes `beacon.peer.uid`/`beacon.peer.user` wherever a sender put them (resource, scope, record, span, span event and link, every datapoint type), then asks `internal/peercred` for the owner of the client socket of exactly this connection: the client address from `client.Info.Addr` and the collector's end from the gRPC peer's `LocalAddr` or net/http's `LocalAddrContextKey` (no server address, no lookup). `peercred` first asks the kernel with one `NETLINK_SOCK_DIAG` exact four-tuple lookup (`diag_linux.go`, constant cost per export) and scans `/proc/net/tcp{,6}` for the same four-tuple when sock_diag itself is unavailable or, until sock_diag has once answered with a socket, when it says ENOENT (the kernel says that for a missing `tcp_diag` handler too; a socket `/proc` finds then marks sock_diag blind for good); inode 0 (TIME_WAIT/orphan, uid printed 0), no match, or two owners are unknown, never guessed, and an unrelated TIME_WAIT on the same port is skipped. The name comes from `internal/accountname` (shared with `beacon_ingest`). The converter reads the peer attributes from the resource only (`mergeSignalAttrs`), and `applyPeerUser` copies them into `user` only with `Options.PeerUser`, and with it `normalizeClaudeCoworkContext` leaves `user` alone (a sender can call itself Cowork, so its cloud identity stays only in raw attributes; without `PeerUser` it still replaces the collector's account); the `falcon_hec` exporter gets `peer_user: true` too, so LogScale matches the log; with `PeerUser` an unidentified sender gets an empty `user`, never the collector's root, so a recorded root always means root sent it. `CheckComponentsFor` refuses a collector without both where they are rendered. macOS and Windows have no lookup and keep the collector's account (root, or `COMPUTERNAME$` under LocalSystem). Hook and plugin events carry the person's uid or SID from `os/user.Current()` (verified by the OS in restricted mode). The person is also on the session's hook and plugin events, joined by `session.id`; the Sentinel guide carries the KQL. Never describe OTLP events on macOS or Windows as carrying the person who ran the agent.- Claude Cowork admin-configured OpenTelemetry setup guidance and local validation.- OpenClaw Gateway uses a Beacon-managed plugin directory plus OpenClaw's own diagnostics OTLP guidance (`beacon endpoint integrations openclaw`). The plugin's `before_tool_call` hook is fail-closed, so the handler dispatches synchronously and returns without awaiting. Conversation hooks, including `llm_output`, require `plugins.entries.beacon-endpoint.hooks.allowConversationAccess`; without it, token and agent-message coverage is partial. Beacon reads OpenClaw JSON/JSON5 config for advice but does not rewrite it.- GitHub Copilot CLI uses MDM/customer-managed OTLP HTTP for live spans and approval-like activity, plus `beacon endpoint copilot sync` to backfill local session records from `~/.copilot/session-state`. Poll events carry assistant text, complete tool results, command/file details, and token usage with `harness.collection_method=poll`, plus the shutdown's session-wide `totalNanoAiu` differenced into `gen_ai.usage.cost_usd` once per shutdown (10^9 nano-AIU = one AI credit = US$0.01), only for sessions started on or after the 2026-06-01 AI-credit cutover (`cli/beacon/internal/copilotsession/cost.go`); approvals still come only from the live OTLP path and are not synthesized from persisted records.diff --git a/cli/beacon/internal/endpoint/collector/collector.go b/cli/beacon/internal/endpoint/collector/collector.goindex 331984ad..d9514d4a 100644--- a/cli/beacon/internal/endpoint/collector/collector.go+++ b/cli/beacon/internal/endpoint/collector/collector.go@@ -417,6 +417,12 @@ func falconHECYAML(cfg endpointconfig.Config) string {if cfg.ClaudeCaptureModelContext {fmt.Fprintf(&b, " capture_model_context: true\n")}+ if PeerAttribution {+ // falcon_hec converts on its own, after beacon_peer in the same pipelines, so it is told to+ // trust the account beacon_peer resolved just as beaconjson is; otherwise LogScale would+ // record the collector's account for an event runtime.jsonl attributes to its sender.+ fmt.Fprintf(&b, " peer_user: true\n")+ }if falcon.Source != "" {fmt.Fprintf(&b, " source: %q\n", falcon.Source)}diff --git a/cli/beacon/internal/endpoint/collector/peer_test.go b/cli/beacon/internal/endpoint/collector/peer_test.goindex 1bc77802..3d859ed8 100644--- a/cli/beacon/internal/endpoint/collector/peer_test.go+++ b/cli/beacon/internal/endpoint/collector/peer_test.go@@ -80,6 +80,28 @@ func TestConfigYAMLRendersPeerAttribution(t *testing.T) {}}+// falcon_hec runs its own converter after beacon_peer, so it is told to trust the peer too, or+// LogScale would record the collector's account for events runtime.jsonl attributes to the sender.+func TestPeerAttributionReachesFalconHEC(t *testing.T) {+ cfg := testConfig(t)+ cfg.Destinations = &endpointconfig.Destinations{+ FalconHEC: &endpointconfig.FalconHEC{Endpoint: "https://falcon.example/api/v1/ingest/hec", Token: "test-token"},+ }+ endpointconfig.NormalizeDestinations(&cfg)+ if text := ConfigYAML(cfg); strings.Contains(text, "peer_user") {+ t.Fatalf("peer_user rendered without peer attribution:\n%s", text)+ }+ withPeerAttribution(t)+ out := render(t, cfg)+ falcon, ok := out.Exporters["falcon_hec"].(map[string]any)+ if !ok {+ t.Fatalf("no falcon_hec exporter:\n%s", ConfigYAML(cfg))+ }+ if falcon["peer_user"] != true {+ t.Fatalf("falcon_hec peer_user = %v, want true", falcon["peer_user"])+ }+}+// The OTLP forward hears HTTP exports too, but never runs beacon_peer: Beacon's attribution of// local accounts stays on this machine.func TestPeerAttributionStaysOutOfTheOTLPForward(t *testing.T) {diff --git a/collector-builder/exporter/beaconjsonexporter/falconhecexporter/config.go b/collector-builder/exporter/beaconjsonexporter/falconhecexporter/config.goindex 23819097..0cfb74d6 100644--- a/collector-builder/exporter/beaconjsonexporter/falconhecexporter/config.go+++ b/collector-builder/exporter/beaconjsonexporter/falconhecexporter/config.go@@ -27,6 +27,10 @@ type Config struct {IncludeCodexSpans bool `mapstructure:"include_codex_spans"`// CaptureModelContext is the --claude-capture-model-context opt-in; see beaconevent.Options.CaptureModelContext bool `mapstructure:"capture_model_context"`+ // PeerUser takes each event's user from the account the beacon_peer processor resolved, as+ // beaconjson's peer_user does, so LogScale and runtime.jsonl name the same sender; see+ // beaconevent.Options.PeerUser.+ PeerUser bool `mapstructure:"peer_user"`}func createDefaultConfig() *Config {diff --git a/collector-builder/exporter/beaconjsonexporter/falconhecexporter/exporter.go b/collector-builder/exporter/beaconjsonexporter/falconhecexporter/exporter.goindex b3c0d784..bb0e44c6 100644--- a/collector-builder/exporter/beaconjsonexporter/falconhecexporter/exporter.go+++ b/collector-builder/exporter/beaconjsonexporter/falconhecexporter/exporter.go@@ -72,6 +72,7 @@ func newExporter(raw component.Config, set exporter.Settings) (*falconExporter,IncludeRuntimeMetrics: cfg.IncludeRuntimeMetrics,IncludeCodexSpans: cfg.IncludeCodexSpans,CaptureModelContext: cfg.CaptureModelContext,+ PeerUser: cfg.PeerUser,CodexSurfaces: codexSurfaces,}),listings: &beaconevent.MCPListings{},diff --git a/collector-builder/exporter/beaconjsonexporter/falconhecexporter/exporter_test.go b/collector-builder/exporter/beaconjsonexporter/falconhecexporter/exporter_test.goindex 1e32eb2e..662b156d 100644--- a/collector-builder/exporter/beaconjsonexporter/falconhecexporter/exporter_test.go+++ b/collector-builder/exporter/beaconjsonexporter/falconhecexporter/exporter_test.go@@ -229,3 +229,43 @@ func configNoRetry() configretry.BackOffConfig {cfg.Enabled = falsereturn cfg}++// With peer_user, LogScale records the account beacon_peer resolved, as runtime.jsonl does.+func TestPeerUserReachesFalconPayload(t *testing.T) {+ t.Setenv("USER", "root")+ var payload hecPayload+ server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {+ if err := json.NewDecoder(r.Body).Decode(&payload); err != nil {+ t.Error(err)+ }+ w.WriteHeader(http.StatusOK)+ }))+ defer server.Close()+ cfg := createDefaultConfig()+ cfg.Endpoint, cfg.Token, cfg.PeerUser = server.URL, "test-ingest-token", true+ exp, err := newExporter(cfg, exporter.Settings{})+ if err != nil {+ t.Fatal(err)+ }+ logs := plog.NewLogs()+ rl := logs.ResourceLogs().AppendEmpty()+ rl.Resource().Attributes().PutStr("service.name", "claude-code")+ rl.Resource().Attributes().PutStr(beaconevent.PeerUIDAttribute, "1001")+ rl.Resource().Attributes().PutStr(beaconevent.PeerUserAttribute, "alice")+ rec := rl.ScopeLogs().AppendEmpty().LogRecords().AppendEmpty()+ rec.Body().SetStr("prompt submitted")+ rec.Attributes().PutStr("beacon.event.action", "prompt.submitted")+ if err := exp.consumeLogs(context.Background(), logs); err != nil {+ t.Fatal(err)+ }+ data, _ := json.Marshal(payload.Event)+ var event struct {+ User beaconevent.UserInfo `json:"user"`+ }+ if err := json.Unmarshal(data, &event); err != nil {+ t.Fatal(err)+ }+ if event.User.Name != "alice" || event.User.UID != "1001" {+ t.Fatalf("falcon user = %+v, want alice/1001: %s", event.User, data)+ }+}diff --git a/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/converter.go b/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/converter.goindex 18ff2ef0..5a49109f 100644--- a/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/converter.go+++ b/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/converter.go@@ -641,7 +641,7 @@ func (c Converter) NormalizeClaudeLogEvent(event *Event, attrs map[string]interfif event == nil || !isClaudeOTelLogHarness(event.Harness.Name) {return}- normalizeClaudeCoworkContext(event, attrs)+ normalizeClaudeCoworkContext(event, attrs, c.opts.PeerUser)originalAction := event.Event.ActionoriginalCategory := event.Event.CategorypreserveAction := statedAction(attrs, "beacon.event.action", "event.action", "gen_ai.agent.action", "ai.agent.action") != ""@@ -796,7 +796,15 @@ func NormalizeClaudeToolResult(event *Event, attrs map[string]interface{}) {}}-func normalizeClaudeCoworkContext(event *Event, attrs map[string]interface{}) {+// normalizeClaudeCoworkContext applies what Claude Cowork reports about itself: where it ran and,+// unless peerUser is set, the cloud identity it names in place of the collector's account.+//+// With peerUser (beacon_peer in the pipeline) the user field is the kernel's answer for the account+// that sent the export, and nothing a sender writes replaces it. The identity attributes are whatever+// the sender put there, and the harness is only a service name, so letting them win would let any+// local account record an event as uid 0 / root by calling itself Cowork. The cloud identity still+// reaches the log in the event's raw attributes.+func normalizeClaudeCoworkContext(event *Event, attrs map[string]interface{}, peerUser bool) {if event.Harness.Name != "claude_cowork" {return}@@ -806,6 +814,9 @@ func normalizeClaudeCoworkContext(event *Event, attrs map[string]interface{}) {case "local", "desktop":event.Origin = asymptoteobserve.OriginLocal}+ if peerUser {+ return+ }if name := FirstString(attrs, "user.email", "enduser.id", "user.account_id", "user.account_uuid", "user.id"); name != "" {event.User.Name = name// The base event carries the collector process UID. Once a cloud identity@@ -2359,8 +2370,8 @@ func EventCategory(action, explicit string) string {// is root for everyone: a prompt typed by one person on a shared machine reads as root's. The// beacon_peer processor resolves the sender from the kernel; this only copies what it found, and// changes nothing when it found nobody, so an unattributed event is the collector's account as it-// always was rather than someone's guess. Runtime-specific identities (Claude Cowork's cloud user)-// are applied after this and still win.+// always was rather than someone's guess. With it on, nothing a sender reports replaces the kernel's+// answer, including Claude Cowork's cloud user (see normalizeClaudeCoworkContext).func (c Converter) applyPeerUser(event *Event, attrs map[string]interface{}) {if !c.opts.PeerUser {returndiff --git a/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/peer_user_test.go b/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/peer_user_test.goindex 68560707..b0b3f01a 100644--- a/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/peer_user_test.go+++ b/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/peer_user_test.go@@ -59,15 +59,47 @@ func TestPeerUserWithoutANameKeepsOnlyTheID(t *testing.T) {}}-// A runtime that reports its own cloud identity (Claude Cowork) keeps it: the sender's local account-// is the desktop app's, not the person's.-func TestCoworkIdentityStillWinsOverThePeer(t *testing.T) {+// With beacon_peer in the pipeline the kernel's answer is the user, even for a sender that calls+// itself Claude Cowork: the harness is only a service name and the identity attributes are whatever+// the sender wrote, so otherwise any account could record an event as uid 0 / root. The cloud+// identity stays in the raw attributes.+func TestCoworkIdentityDoesNotReplaceThePeer(t *testing.T) {+ t.Setenv("USER", "root")+ for _, forged := range []map[string]string{+ {"user.email": "[email protected]"},+ {"user.email": "root", "user.account_id": "0"},+ } {+ resource, record := peerLog("my-cowork")+ resource["cowork.surface"] = "desktop"+ for k, v := range forged {+ record.Attributes().PutStr(k, v)+ }+ event := NewConverter(Options{PeerUser: true}).EventFromLog(resource, record)+ if event.Harness.Name != "claude_cowork" {+ t.Fatalf("fixture did not resolve to claude_cowork (%q)", event.Harness.Name)+ }+ if event.User.Name != "alice" || event.User.UID != "1001" {+ t.Fatalf("user = %+v with %v, want the kernel's alice/1001", event.User, forged)+ }+ if event.Origin != "local" {+ t.Fatalf("origin = %q, want Cowork's surface still applied", event.Origin)+ }+ attrs, _ := event.Raw["attributes"].(map[string]interface{})+ if attrs["user.email"] != forged["user.email"] {+ t.Fatalf("raw attributes lost the Cowork identity: %v", attrs)+ }+ }+}++// Without beacon_peer (macOS, Windows), Claude Cowork's cloud identity replaces the collector's own+// account, as it always has.+func TestCoworkIdentityWinsWithoutThePeer(t *testing.T) {resource, record := peerLog("claude-cowork")resource["cowork.surface"] = "desktop"record.Attributes().PutStr("user.email", "[email protected]")- event := NewConverter(Options{PeerUser: true}).EventFromLog(resource, record)+ event := NewConverter(Options{}).EventFromLog(resource, record)if event.Harness.Name != "claude_cowork" {- t.Skipf("fixture did not resolve to claude_cowork (%q)", event.Harness.Name)+ t.Fatalf("fixture did not resolve to claude_cowork (%q)", event.Harness.Name)}if event.User.Name != "[email protected]" {t.Fatalf("user = %+v, want the Cowork identity", event.User)diff --git a/collector-builder/exporter/beaconjsonexporter/internal/peercred/diag_linux.go b/collector-builder/exporter/beaconjsonexporter/internal/peercred/diag_linux.goindex 47a9f365..87d8cde1 100644--- a/collector-builder/exporter/beaconjsonexporter/internal/peercred/diag_linux.go+++ b/collector-builder/exporter/beaconjsonexporter/internal/peercred/diag_linux.go@@ -137,6 +137,8 @@ func sockDiagOne(family uint8, src net.IP, sport int, dst net.IP, dport int) (stcontinue}if syscall.Errno(errno) == syscall.ENOENT {+ // No such socket, or no TCP diag handler to ask: the kernel says ENOENT for both.+ // lookupUID tells them apart.return "", ErrNotFound}return "", fmt.Errorf("%w: %v", errDiagUnavailable, syscall.Errno(errno))@@ -146,6 +148,9 @@ func sockDiagOne(family uint8, src net.IP, sport int, dst net.IP, dport int) (streturn "", errDiagUnavailable}m = *(*inetDiagMsg)(unsafe.Pointer(&reply.Data[0]))+ // A reply with a socket in it, whichever: the TCP diag handler is there, so its ENOENT+ // means no such socket from now on (see lookupUID).+ diag.CompareAndSwap(diagUnknown, diagSeesSockets)// The kernel answered for exactly this connection, or the answer is not about it.if m.ID.SPort != req.ID.SPort || m.ID.DPort != req.ID.DPort {return "", ErrNotFounddiff --git a/collector-builder/exporter/beaconjsonexporter/internal/peercred/peercred_linux.go b/collector-builder/exporter/beaconjsonexporter/internal/peercred/peercred_linux.goindex e0e781b3..9a18ab5c 100644--- a/collector-builder/exporter/beaconjsonexporter/internal/peercred/peercred_linux.go+++ b/collector-builder/exporter/beaconjsonexporter/internal/peercred/peercred_linux.go@@ -12,6 +12,7 @@ import ("os""path/filepath""strings"+ "sync/atomic")// procNet is where the fallback reads the socket tables. A var so tests can point it at fixtures.@@ -29,18 +30,49 @@ var diagLookup = sockDiagUID// kernel offers no sock_diag (a module left out, a sandbox that refuses netlink), the socket tables// in /proc/net are read instead, matching the same four-tuple.//+// A missing diag handler is not always a refused channel: with tcp_diag absent or unloadable+// (CONFIG_INET_TCP_DIAG=m on a host with kernel.modules_disabled=1, a blacklist, a container host+// whose kernel ships no module) the kernel answers ENOENT, the same answer as for a socket that does+// not exist. Until sock_diag has answered once with a socket, which proves the handler is there, its+// "no such socket" is checked against /proc; if /proc finds the socket, sock_diag is taken to be+// unable to see it and /proc answers from then on.+//// Either way an answer is refused rather than guessed when it cannot be the sender: a socket in// TIME_WAIT or otherwise orphaned reports uid 0 and inode 0 whoever created it, which would name// root for a client that has gone; and no socket at all means the client closed before the lookup,// which a sender could do on purpose.func lookupUID(client, server *net.TCPAddr) (string, error) {+ if diag.Load() == diagBlind {+ return procLookup(client, server)+ }uid, err := diagLookup(client, server)- if err == nil || errors.Is(err, ErrNotFound) {- return uid, err+ switch {+ case err == nil:+ return uid, nil+ case !errors.Is(err, ErrNotFound):+ return procLookup(client, server)+ case diag.Load() == diagSeesSockets:+ return "", ErrNotFound+ }+ uid, err = procLookup(client, server)+ if err == nil {+ diag.CompareAndSwap(diagUnknown, diagBlind)}- return procLookup(client, server)+ return uid, err}+// What sock_diag has shown it can do on this kernel. It starts unknown; one reply carrying a socket+// proves the TCP handler is registered (diagSeesSockets), and a socket /proc found where sock_diag+// said ENOENT proves it is not (diagBlind). Neither changes afterwards: a kernel does not drop a+// registered diag handler, and the lookup it costs to re-check would run on every export.+const (+ diagUnknown int32 = iota+ diagSeesSockets+ diagBlind+)++var diag atomic.Int32+// procLookup reads /proc/net/tcp and tcp6, where each socket is one line://// sl local_address rem_address st tx_queue:rx_queue tr:tm->when retrnsmt uid timeout inodediff --git a/collector-builder/exporter/beaconjsonexporter/internal/peercred/peercred_linux_test.go b/collector-builder/exporter/beaconjsonexporter/internal/peercred/peercred_linux_test.goindex c7e5926d..219bbfa4 100644--- a/collector-builder/exporter/beaconjsonexporter/internal/peercred/peercred_linux_test.go+++ b/collector-builder/exporter/beaconjsonexporter/internal/peercred/peercred_linux_test.go@@ -109,28 +109,94 @@ func TestUIDRefusesWhatItCannotSee(t *testing.T) {func TestLookupFallsBackOnlyWhenSockDiagIsUnavailable(t *testing.T) {old := diagLookupt.Cleanup(func() { diagLookup = old })+ oldState := diag.Load()+ t.Cleanup(func() { diag.Store(oldState) })dir := t.TempDir()oldProc := procNetprocNet = dirt.Cleanup(func() { procNet = oldProc })header := " sl local_address rem_address st tx_queue rx_queue tr tm->when retrnsmt uid timeout inode\n"row := " 2: 0100007F:B5D2 0100007F:10E6 01 00000000:00000000 00:00000000 00000000 1001 0 102 1 0 20 4 30 10 -1\n"- if err := os.WriteFile(filepath.Join(dir, "tcp"), []byte(header+row), 0o644); err != nil {- t.Fatal(err)+ writeTable := func(content string) {+ t.Helper()+ if err := os.WriteFile(filepath.Join(dir, "tcp"), []byte(content), 0o644); err != nil {+ t.Fatal(err)+ }}+ writeTable(header + row)client := &net.TCPAddr{IP: net.IPv4(127, 0, 0, 1), Port: 0xB5D2}server := &net.TCPAddr{IP: net.IPv4(127, 0, 0, 1), Port: 0x10E6}if procAddr4(client.IP, client.Port) != "0100007F:B5D2" {t.Skip("fixtures are little-endian")}+ diagCalls := 0+ answer := func(err error) {+ diagCalls = 0+ diagLookup = func(_, _ *net.TCPAddr) (string, error) { diagCalls++; return "", err }+ }- diagLookup = func(_, _ *net.TCPAddr) (string, error) { return "", errDiagUnavailable }+ diag.Store(diagUnknown)+ answer(errDiagUnavailable)if uid, err := lookupUID(client, server); err != nil || uid != "1001" {t.Fatalf("with sock_diag unavailable: %q, %v; want the /proc answer", uid, err)}- diagLookup = func(_, _ *net.TCPAddr) (string, error) { return "", ErrNotFound }++ // Once sock_diag has shown it can see sockets, its ENOENT is final.+ diag.Store(diagSeesSockets)+ answer(ErrNotFound)+ if uid, err := lookupUID(client, server); !errors.Is(err, ErrNotFound) {+ t.Fatalf("with a working sock_diag saying no such socket: %q, %v; want ErrNotFound without a second guess", uid, err)+ }++ // Before that, ENOENT may mean no tcp_diag handler: /proc is asked, and a client /proc can see+ // but sock_diag cannot settles it, so later lookups go straight to /proc.+ diag.Store(diagUnknown)+ answer(ErrNotFound)+ writeTable(header)if uid, err := lookupUID(client, server); !errors.Is(err, ErrNotFound) {- t.Fatalf("with sock_diag saying no such socket: %q, %v; want ErrNotFound without a second guess", uid, err)+ t.Fatalf("with neither finding the socket: %q, %v; want ErrNotFound", uid, err)+ }+ if got := diag.Load(); got != diagUnknown {+ t.Fatalf("state after agreeing ErrNotFound = %d, want still unknown", got)+ }+ writeTable(header + row)+ if uid, err := lookupUID(client, server); err != nil || uid != "1001" {+ t.Fatalf("with sock_diag blind to a socket /proc has: %q, %v; want the /proc answer", uid, err)+ }+ if got := diag.Load(); got != diagBlind {+ t.Fatalf("state = %d, want sock_diag marked blind", got)+ }+ answer(ErrNotFound)+ if uid, err := lookupUID(client, server); err != nil || uid != "1001" || diagCalls != 0 {+ t.Fatalf("after marking sock_diag blind: %q, %v, %d sock_diag calls; want /proc alone", uid, err, diagCalls)+ }+}++// A real answer from sock_diag proves its handler is there, so a later ENOENT is final.+func TestSockDiagAnswerMarksItWorking(t *testing.T) {+ oldState := diag.Load()+ t.Cleanup(func() { diag.Store(oldState) })+ diag.Store(diagUnknown)+ ln, err := net.Listen("tcp4", "127.0.0.1:0")+ if err != nil {+ t.Fatal(err)+ }+ defer ln.Close()+ client, err := net.Dial("tcp4", ln.Addr().String())+ if err != nil {+ t.Fatal(err)+ }+ defer client.Close()+ server, err := ln.Accept()+ if err != nil {+ t.Fatal(err)+ }+ defer server.Close()+ if _, err := sockDiagUID(server.RemoteAddr().(*net.TCPAddr), server.LocalAddr().(*net.TCPAddr)); err != nil {+ t.Skipf("sock_diag cannot see this socket here: %v", err)+ }+ if got := diag.Load(); got != diagSeesSockets {+ t.Fatalf("state = %d after a sock_diag answer, want diagSeesSockets", got)}}diff --git a/docs/changelog/cli.mdx b/docs/changelog/cli.mdxindex f9ff2ced..a980f6f4 100644--- a/docs/changelog/cli.mdx+++ b/docs/changelog/cli.mdx@@ -11,7 +11,7 @@ Stay up to date with the latest changes to the Agent Beacon CLI.## Unreleased-- **OpenTelemetry events name the person who sent them on Linux** · On a system install every account exports to the same local collector, so prompts and token usage from Claude Code, Codex and the browser extension were recorded, and forwarded to SIEMs such as Microsoft Sentinel, under the collector's account, `root`, whoever typed them. The Linux collector now records each OpenTelemetry export under the account that owns the connection it arrived on, as the kernel reports it, over gRPC and HTTP alike, and ignores any account a sender names for itself, on the resource or on a record, span or datapoint. An export whose sender cannot be identified (it disconnected before the collector looked) carries no `user` at all, rather than the collector's `root`, so a recorded `root` always means root sent it. Beacon's OTLP forward to another backend is unchanged. macOS and Windows are unchanged. Run `beacon endpoint repair --system` (package upgrades do this) to render the new collector config; the collector from the same release is required.+- **OpenTelemetry events name the person who sent them on Linux** · On a system install every account exports to the same local collector, so prompts and token usage from Claude Code, Codex and the browser extension were recorded, and forwarded to SIEMs such as Microsoft Sentinel, under the collector's account, `root`, whoever typed them. The Linux collector now records each OpenTelemetry export under the account that owns the connection it arrived on, as the kernel reports it, over gRPC and HTTP alike, and ignores any account a sender names for itself, on the resource or on a record, span or datapoint. That includes an export that calls itself Claude Cowork: on Linux its cloud account stays in the event's raw attributes, and `user` is still the kernel's answer. An export whose sender cannot be identified (it disconnected before the collector looked) carries no `user` at all, rather than the collector's `root`, so a recorded `root` always means root sent it. A Falcon LogScale HEC destination records the same account as `runtime.jsonl`. Beacon's OTLP forward to another backend is unchanged. macOS and Windows are unchanged. Run `beacon endpoint repair --system` (package upgrades do this) to render the new collector config; the collector from the same release is required.- **Microsoft Sentinel forwarding with one command, on macOS, Linux and Windows** · `beacon endpoint sentinel forwarder install --system` runs the Vector bundled with Beacon as a system service that sends the runtime log to Microsoft Sentinel through the Logs Ingestion API, with a Microsoft Entra app registration (certificate or client secret). The credential is stored where only root can read it, or SYSTEM and Administrators on Windows, and is never a command-line argument. Vector checks the config before anything changes. Repair and package upgrades keep the forwarder and restart it on the new Vector; uninstall removes the service. Throttling, server errors and `401`/`403` answers are retried without a limit, and a line counts as sent only once Azure has accepted it. `status` and `remove` complete the commands. The pack's Logs Ingestion DCR template no longer needs a Data Collection Endpoint. See [Vector and the Logs Ingestion API](/log-forwarding/microsoft-sentinel#vector-and-the-logs-ingestion-api).- **The Windows MSI carries Vector** · The MSI now installs Vector 0.56.0 as `vector.exe` beside `beacon.exe` in `%ProgramFiles%\Beacon\bin`, as the macOS and Linux packages already carry it, checked against the same pinned checksums. Beacon finds it there. The package only installs it; nothing runs it until a forwarder is set up. Allow it alongside the other three programs if you run AppLocker or WDAC.- **Scheduled session sync** · `beacon endpoint install|repair --session-sync` turns on a job that runs every 15 minutes and reads new records from the agent runtimes' local session stores into the runtime log. It runs the same bounded, confined sweep install already runs once, so session-store data keeps reaching the log, and any forwarder reading it, after install. Off by default; repair and upgrades keep the setting, and `--no-session-sync` removes the job. See [Scheduled session sync](/cli/endpoint-install#scheduled-session-sync).diff --git a/docs/log-forwarding/microsoft-sentinel.mdx b/docs/log-forwarding/microsoft-sentinel.mdxindex 0812ff4d..d6eb4b3a 100644--- a/docs/log-forwarding/microsoft-sentinel.mdx+++ b/docs/log-forwarding/microsoft-sentinel.mdx@@ -232,7 +232,7 @@ One case is not retried. When Microsoft Entra ID refuses the credential itself,### Who ran each session-On a machine several people use, the person behind an event is in `RawData.user`: `uid` is the account's uid, or its SID on Windows, and `name` its name. Hook and plugin events carry it, because each hook and plugin runs as the person who ran the agent; with [restricted log access](/security/restricted-log-access) the operating system vouches for it. On Linux, events from an agent's own OpenTelemetry export, such as Claude Code's token usage and cost or the browser extension's chats, carry the account that sent them too, as the kernel reports it; one whose sender disconnected before the collector could look has no `user`. On macOS and Windows they carry the collector's own account instead (such as `root`, or the machine account `COMPUTERNAME$` on Windows), because every account sends to the same local port and nothing there identifies the sender. Claude Cowork is the exception: its events name the cloud account it reports. Both kinds share the session's id, so take the person from the hook and plugin events, and keep an event's own user where its session has none:+On a machine several people use, the person behind an event is in `RawData.user`: `uid` is the account's uid, or its SID on Windows, and `name` its name. Hook and plugin events carry it, because each hook and plugin runs as the person who ran the agent; with [restricted log access](/security/restricted-log-access) the operating system vouches for it. On Linux, events from an agent's own OpenTelemetry export, such as Claude Code's token usage and cost or the browser extension's chats, carry the account that sent them too, as the kernel reports it; one whose sender disconnected before the collector could look has no `user`. On macOS and Windows they carry the collector's own account instead (such as `root`, or the machine account `COMPUTERNAME$` on Windows), because every account sends to the same local port and nothing there identifies the sender. On macOS and Windows, Claude Cowork is the exception: its events name the cloud account it reports. On Linux, Cowork events keep the account the kernel reports, and the cloud account is in the event's raw attributes. Both kinds share the session's id, so take the person from the hook and plugin events, and keep an event's own user where its session has none:```kql title="Attribute every event to the person who ran its session"let owners = BeaconRuntime_CLdiff --git a/docs/security/restricted-log-access.mdx b/docs/security/restricted-log-access.mdxindex 981341f0..1a18e4a3 100644--- a/docs/security/restricted-log-access.mdx+++ b/docs/security/restricted-log-access.mdx@@ -177,7 +177,7 @@ Restricted mode protects the **log**: what has been recorded cannot be altered o- **A user still controls their own agent.** They can still send events of their own choosing through the socket, including ones that name another session's id, but every event is recorded under their own account, as the operating system reports it. They cannot write an event that claims to be someone else's.- **A user can still change their own agent settings.** The hooks and OpenTelemetry settings that send an agent's activity to Beacon live in each user's home (for example `~/.claude/settings.json`), and that user can edit them, which stops capture of their future sessions. Restricted mode does not change this. Run [`beacon endpoint doctor --system`](/cli/endpoint-doctor#console_user_configured) from your MDM to catch it: `console_user_configured` fails when the logged-in user's agents no longer point at the collector, and `sudo beacon endpoint user-config repair-installed --system` puts the settings back.-- **The OTLP ports are open to every account.** The collector's OTLP receivers on `127.0.0.1:4317` and `4318` still accept telemetry from any local process, as in the shared mode. Agents that export over OTLP, such as Claude Code and Codex, and the browser extension use them. On Linux the collector records each such event under the account that owns the connection it arrived on, as the kernel reports it, and ignores any account the sender names itself; an event whose sender had already disconnected when the collector looked carries no `user` at all, so it is never mistaken for root's. On macOS and Windows these events carry the collector's own account (such as `root`, or the machine account `COMPUTERNAME$` on Windows), not the person who ran the agent: every account on the machine sends to the same port, and nothing there identifies the sender. Claude Cowork's name the cloud account it reports instead, which no one checks either. The person is on the same session's hook and plugin events, which share the OTLP events' `session.id` and which restricted mode does attribute; see [Microsoft Sentinel forwarding](/log-forwarding/microsoft-sentinel#who-ran-each-session) for the join.+- **The OTLP ports are open to every account.** The collector's OTLP receivers on `127.0.0.1:4317` and `4318` still accept telemetry from any local process, as in the shared mode. Agents that export over OTLP, such as Claude Code and Codex, and the browser extension use them. On Linux the collector records each such event under the account that owns the connection it arrived on, as the kernel reports it, and ignores any account the sender names itself; an event whose sender had already disconnected when the collector looked carries no `user` at all, so it is never mistaken for root's. On macOS and Windows these events carry the collector's own account (such as `root`, or the machine account `COMPUTERNAME$` on Windows), not the person who ran the agent: every account on the machine sends to the same port, and nothing there identifies the sender. There, Claude Cowork's events name the cloud account it reports instead, which no one checks either; on Linux they keep the kernel's account and carry the cloud account only in their raw attributes. The person is on the same session's hook and plugin events, which share the OTLP events' `session.id` and which restricted mode does attribute; see [Microsoft Sentinel forwarding](/log-forwarding/microsoft-sentinel#who-ran-each-session) for the join.- **Root is trusted.** An administrator can read and change the log in either mode. On Windows that is SYSTEM and any elevated administrator.## Verify