Skip to content

feat(supervisor): relay agent OTLP logs and metrics - #5858

Open
ericcurtin wants to merge 4 commits into
ai-openshell:mainfrom
ericcurtin:feat/5562-relay-logs-metrics/ericcurtin
Open

ericcurtin wants to merge 4 commits into
ai-openshell:mainfrom
ericcurtin:feat/5562-relay-logs-metrics/ericcurtin

Conversation

@ericcurtin

Copy link
Copy Markdown
Contributor

Summary

The agent relay now forwards OTLP logs and metrics to the agent collector, not just traces.

Related Issue

Closes #5562

Changes

  • Forward /v1/logs and /v1/metrics with the same sandbox id attribution as traces.
  • One buffer per signal, so a chatty signal can't crowd out the others.
  • Count exported, rejected and failed batches per signal in the summary log.
  • Update docs.

Release Notes

The agent relay forwards logs and metrics as well as traces.

Testing

  • Checks appropriate to the affected code and behavior pass
  • Unit tests added/updated (if applicable)
  • E2E tests added/updated (if applicable)

cargo fmt, cargo clippy -p openshell-supervisor --all-targets and cargo test -p openshell-supervisor --lib pass.

Checklist

  • Follows Conventional Commits
  • Commits are signed off (DCO)
  • Architecture docs updated (if applicable)

Closes ai-openshell#5562

Signed-off-by: Eric Curtin <eric.curtin@docker.com>
@ericcurtin

Copy link
Copy Markdown
Contributor Author

@rhuss @TaylorMutch PTAL when you get a chance, and /ok to test 83e815e06c872751a72fbe69d98a8f33910cb20c if it looks good. Thank you!

Signed-off-by: Eric Curtin <eric.curtin@docker.com>
@ericcurtin

Copy link
Copy Markdown
Contributor Author

@rhuss @alangou PTAL when you get a chance, and /ok to test 0684adedddee955014e64aef4009a1fcd3049995 if it looks good. Thank you!

@rhuss rhuss left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

cc-review Summary

What Went Well

  • Signal (crates/openshell-supervisor/src/otlp_relay/mod.rs:41-80) owns the HTTP path, the gRPC service name and the array index in one enum, so receiver routing, buffers, counters and exporter URIs cannot drift apart, and arrays sized by Signal::ALL.len() make a new signal a compile error at every site that must handle it.
  • RelayCounters::discard_pending (mod.rs:255-264) replaces four copies of the pending-to-failure accounting in Drop and shutdown with one helper that charges each lost batch to its own signal.
  • handle_request (receiver.rs:184-193) sends logs and metrics through the same content-type, body-size, body-timeout and structural-limit checks as traces, and the old drain-and-acknowledge path is gone without leaving dead helpers or counters behind.
  • The enrichment.rs module doc (lines 6-10) and the PassthroughCodec doc (exporter.rs:264-267) explain why the bounded wire-level walk and the trace response decoder also fit logs and metrics (the shared field-1 layout), so the agent payload is still never fully decoded.
  • new_buffer (buffer.rs:77-96) gives each signal its own bounded, non-blocking queue, so a full logs or metrics queue answers 503 for that signal only and total buffered memory keeps a fixed ceiling.
  • logs_and_metrics_reach_a_grpc_collector_with_attribution (mod.rs:910-965) and logs_and_metrics_are_enriched_and_buffered (receiver.rs:671-717) spoof openshell.sandbox.id and assert the replaced value with no duplicate attribution keys, against a real tonic collector and through the typed logs and metrics request types.

Findings

Severity File Description Source
Minor crates/openshell-supervisor/README.md:135 The limits paragraph of this README section (line 137) still says 32 buffered batches and about... production
Important crates/openshell-supervisor/src/otlp_relay/buffer.rs:66 BatchReceiver::recv drains the three queues with a biased select in fixed order, so logs and... correctness
Minor crates/openshell-supervisor/src/otlp_relay/buffer.rs:128 The metrics queue capacity is never asserted: a_full_signal_does_not_block_the_others fills on... test-quality
Minor crates/openshell-supervisor/src/otlp_relay/enrichment.rs:122 The EnrichError Display impl was generalized only for Malformed; the other client-visible me... architecture
Minor crates/openshell-supervisor/src/otlp_relay/mod.rs:195 record_rejection now takes the signal, but its one-time warning still logs buffer_capacity =... correctness
Minor crates/openshell-supervisor/src/otlp_relay/mod.rs:206 No test covers a collector that rejects logs or metrics while accepting traces, so the effect of... test-quality
Important crates/openshell-supervisor/src/otlp_relay/mod.rs:212 The single last_export_failed flag is now set and cleared by exports of all three signals, so... correctness
Minor crates/openshell-supervisor/src/otlp_relay/mod.rs:277 Per-signal exported counts appear only in the 'OTLP relay summary' line, which is emitted only w... goal-alignment
Minor crates/openshell-supervisor/src/otlp_relay/mod.rs:964 Per-signal counter attribution is never asserted: every counter test records Signal::Traces, a... test-quality
Important crates/openshell-supervisor/src/otlp_relay/receiver.rs:184 Forwarding agent-authored OTLP logs (and metrics) gives the sandboxed workload a credentialed wr... security
Minor crates/openshell-supervisor/src/otlp_relay/receiver.rs:184 Logs and metrics now pass through the receiver's compression refusal, but the injected workload... correctness
Important docs/how-it-works/gateways/configuration.mdx:1110 Logs and metrics that the relay used to acknowledge and drop are now forwarded to the agent coll... goal-alignment
Notable docs/how-it-works/gateways/configuration.mdx:1120 The workload environment handling stays trace-specific: the runtime forces only the generic and... goal-alignment

Review Details

I went through these findings one by one and selected the ones posted here; cc-review's reviewer agents produced them. Failure scenarios were derived from reading the code and were not executed.

  • Findings posted: 13
  • Findings reviewed and not posted: 7
  • Gate outcome: FAIL
  • Participating reviewers: architecture, correctness, goal-alignment, production, security, test-quality, gator

Comment thread crates/openshell-supervisor/README.md Resolved
.expect("static response builds"));
}
if request.method() != Method::POST || request.uri().path() != "/v1/traces" {
let Some(signal) = (request.method() == Method::POST)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Important: Forwarding agent-authored OTLP logs (and metrics) gives the sandboxed workload a credentialed write path into the collector that by default also receives supervisor and gateway OCSF audit logs, and a forged record can match every documented marker of a genuine OCSF event except one deny-list resource attribute.

Why this matters: With [openshell.gateway.otlp] endpoint set and [otlp.ocsf] and [otlp.agent] enabled without their own endpoints, RawCollector::resolve (crates/openshell-server/src/config_file.rs:1048-1062, 1103-1118) gives both the same endpoint, headers and TLS client identity. The workload can then POST to http://192.0.0.8:4318/v1/logs a request with scope openshell.ocsf, the record attributes ocsf.class_uid, ocsf.activity_id, ocsf.metadata.uid and openshell.sandbox.id=<another sandbox>, and an OCSF JSON body (a fake network activity or detection finding); enrich_resource_spans rewrites only openshell.sandbox.id and openshell.telemetry.source on the resource (enrichment.rs:312-320) and copies scopes and records byte for byte (enrichment.rs:332-337). A SIEM pipeline built on the documented OCSF Log Export contract ingests the forgery as an audit event, possibly attributed to another sandbox, and since infrastructure resources carry no positive openshell.telemetry.source value, pipelines written before this change fail open; in backends that keep only service.name and service.instance.id, agent-sent openshell_server_* metric series can likewise collide with the gateway's.

Suggested fix: Stamp supervisor and gateway resources with a positive openshell.telemetry.source value (for example in supervisor_resource_attributes, crates/openshell-supervisor/src/main.rs:854) so consumers can allow-list it; the relay already overwrites that key, so the agent cannot forge it. In the OCSF Log Export and relay sections of docs/how-it-works/gateways/configuration.mdx, state that agent logs and metrics reach the same collector when the endpoints coincide and must be dropped from audit pipelines by that attribute, or recommend a dedicated [otlp.agent] endpoint when OCSF export is on.

Source: security agent (also flagged by: gator agent)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Docs only in a561522: agent logs share the collector, drop source=agent from audit pipelines or use a dedicated agent endpoint. Stamping infra resources would change the OCSF export contract, left out of scope.

```

While the relay is active, the sandbox runtime sets `OTEL_EXPORTER_OTLP_ENDPOINT=http://192.0.0.8:4318` and `OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf` in every workload process, and sets `OTEL_EXPORTER_OTLP_COMPRESSION` and `OTEL_EXPORTER_OTLP_TRACES_COMPRESSION` to `none`, so a standard OpenTelemetry SDK exports without configuration. These are lowest-precedence defaults. They are not set when the sandbox creation request or an environment passed to `openshell sandbox exec` names `OTEL_EXPORTER_OTLP_ENDPOINT` or `OTEL_EXPORTER_OTLP_TRACES_ENDPOINT`, or when the image `ENV` names one for the main process, since `openshell sandbox exec` sessions do not inherit the image environment, and an endpoint the workload sets itself, for example with a shell `export`, takes precedence over them. A workload that exports elsewhere does so subject to the sandbox's network policy, and its traces carry no relay attribution. Provider credentials cannot redirect traces. While the relay is off, nothing is injected. Because the generic endpoint is set, an SDK that also exports metrics or logs sends them to the relay, which answers with an empty OTLP success and discards them. To keep metrics and logs, point those exporters elsewhere with `OTEL_EXPORTER_OTLP_METRICS_ENDPOINT` and `OTEL_EXPORTER_OTLP_LOGS_ENDPOINT`. The address is a reserved label rather than a network destination: the supervisor serves it inside the sandbox boundary and forwards accepted batches to the collector over the configured `protocol`. The collector's address is never visible inside the sandbox.
While the relay is active, the sandbox runtime sets `OTEL_EXPORTER_OTLP_ENDPOINT=http://192.0.0.8:4318` and `OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf` in every workload process, and sets `OTEL_EXPORTER_OTLP_COMPRESSION` and `OTEL_EXPORTER_OTLP_TRACES_COMPRESSION` to `none`, so a standard OpenTelemetry SDK exports without configuration. These are lowest-precedence defaults. They are not set when the sandbox creation request or an environment passed to `openshell sandbox exec` names `OTEL_EXPORTER_OTLP_ENDPOINT` or `OTEL_EXPORTER_OTLP_TRACES_ENDPOINT`, or when the image `ENV` names one for the main process, since `openshell sandbox exec` sessions do not inherit the image environment, and an endpoint the workload sets itself, for example with a shell `export`, takes precedence over them. A workload that exports elsewhere does so subject to the sandbox's network policy, and its traces carry no relay attribution. Provider credentials cannot redirect traces. While the relay is off, nothing is injected. The relay forwards logs and metrics too, so an SDK that exports them, for example with `OTEL_LOGS_EXPORTER=otlp` and `OTEL_METRICS_EXPORTER=otlp`, needs no other setting. The address is a reserved label rather than a network destination: the supervisor serves it inside the sandbox boundary and forwards accepted batches to the collector over the configured `protocol`. The collector's address is never visible inside the sandbox.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Notable: The workload environment handling stays trace-specific: the runtime forces only the generic and the traces compression variable to none and strips only a provider-set traces endpoint, so logs and metrics do not get the protection traces get, although the docs now say they need no other setting.

Why this matters: (a) otlp_relay_env_vars (crates/openshell-sandbox/src/child_env.rs:66-73) overrides only OTEL_EXPORTER_OTLP_COMPRESSION and OTEL_EXPORTER_OTLP_TRACES_COMPRESSION, so a gzip setting for logs or metrics leads to 415 (receiver.rs:204-210), logged at debug level and not counted, where the same export got 200 before this PR. (b) apply_otlp_relay_env (child_env.rs:135) removes only OTEL_EXPORTER_OTLP_TRACES_ENDPOINT, so a provider-supplied OTEL_EXPORTER_OTLP_LOGS_ENDPOINT or OTEL_EXPORTER_OTLP_METRICS_ENDPOINT still sends those signals past the relay and its attribution, while this paragraph says 'Provider credentials cannot redirect traces'. This is a design note for a follow-up rather than a defect in the changed lines, since the issue asks that logs and metrics are forwarded like traces with no agent-side change.

Suggested fix: Extend the compression defaults and the provider-endpoint removal to the logs and metrics variables, or document these limits here.

Source: goal-alignment agent

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Compression fixed in a561522. Provider logs/metrics endpoint stripping is documented as a limit and left as a follow-up, since it changes when the defaults apply.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Provider logs/metrics endpoints are now stripped too, in a495c81.

Signed-off-by: Eric Curtin <eric.curtin@docker.com>
@ericcurtin

Copy link
Copy Markdown
Contributor Author

@rhuss @matthewgrossman Addressed the review in a561522. PTAL when you get a chance, and /ok to test a561522894b6514a0f6ed9332fe7707b5d0132cf if it looks good. Thank you!

@ericcurtin

Copy link
Copy Markdown
Contributor Author

@elezar @purp PTAL when you get a chance, and /ok to test a561522894b6514a0f6ed9332fe7707b5d0132cf if it looks good. Thank you!

Signed-off-by: Eric Curtin <eric.curtin@docker.com>

This branch has not been deployed

No deployments
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.

feat(observability): relay agent OTLP logs and metrics from the sandbox

2 participants