Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions authbridge/authlib/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ require (
github.com/open-policy-agent/opa v1.19.1
github.com/rossoctl/context-guru v0.1.0
github.com/spiffe/go-spiffe/v2 v2.8.1
go.opentelemetry.io/otel v1.44.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.44.0
go.opentelemetry.io/otel/sdk v1.44.0
go.opentelemetry.io/otel/trace v1.44.0
golang.org/x/net v0.58.0
golang.org/x/sync v0.22.0
golang.org/x/sys v0.47.0
Expand Down Expand Up @@ -45,6 +49,7 @@ require (
github.com/bytedance/gopkg v0.1.3 // indirect
github.com/bytedance/sonic v1.15.1 // indirect
github.com/bytedance/sonic/loader v0.5.1 // indirect
github.com/cenkalti/backoff/v5 v5.0.3 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/cloudwego/base64x v0.1.6 // indirect
github.com/cncf/xds/go v0.0.0-20260202195803-dba9d589def2 // indirect
Expand All @@ -56,6 +61,7 @@ require (
github.com/go-logr/stdr v1.2.2 // indirect
github.com/goccy/go-json v0.10.6 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.29.0 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
github.com/huandu/go-clone v1.7.3 // indirect
github.com/huandu/go-sqlbuilder v1.42.1 // indirect
Expand Down Expand Up @@ -109,17 +115,17 @@ require (
github.com/yashtewari/glob-intersection v0.2.0 // indirect
github.com/yosida95/uritemplate/v3 v3.0.2 // indirect
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
go.opentelemetry.io/otel v1.44.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.44.0 // indirect
go.opentelemetry.io/otel/metric v1.44.0 // indirect
go.opentelemetry.io/otel/sdk v1.44.0 // indirect
go.opentelemetry.io/otel/trace v1.44.0 // indirect
go.opentelemetry.io/proto/otlp v1.10.0 // indirect
go.starlark.net v0.0.0-20260708150628-5395d018f003 // indirect
go.yaml.in/yaml/v2 v2.4.4 // indirect
go.yaml.in/yaml/v3 v3.0.4 // indirect
golang.org/x/arch v0.23.0 // indirect
golang.org/x/crypto v0.55.0 // indirect
golang.org/x/text v0.41.0 // indirect
golang.org/x/time v0.15.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20260526163538-3dc84a4a5aaa // indirect
google.golang.org/protobuf v1.36.12-0.20260120151049-f2248ac996af // indirect
gopkg.in/ini.v1 v1.67.3 // indirect
oras.land/oras-go/v2 v2.6.2 // indirect
Expand Down
166 changes: 166 additions & 0 deletions authbridge/authlib/plugins/lineage/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
package lineage

import (
"bytes"
"encoding/json"
"fmt"
"net/url"
"strings"
)

// defaultOTelEndpoint is the OTLP gRPC target used when otel_endpoint is unset:
// an in-pod collector reached over plaintext loopback.
const defaultOTelEndpoint = "localhost:4317"

// defaultMaxPayloadBytes bounds a captured input.value / output.value as a
// deliberate producer-side cap. It is NOT a mirror of any SDK limit: the OTel
// SDK's default attribute-value length limit is unlimited (-1) and Init sets no
// SpanLimits, so an oversized value is not dropped or truncated downstream. This
// bound is our own guard against unbounded spans (and against any backend value
// limit); anything longer is cut here with an explicit marker so the loss is
// visible in the span. 4096 is a conservative default, not a hard requirement.
const defaultMaxPayloadBytes = 4096

// Config holds the per-plugin configuration decoded from the pipeline YAML.
type Config struct {
// OTelEndpoint is the OTLP gRPC endpoint (host:port, http://host:port, or
// https://host:port). An https:// scheme implies OTelTLS=true. Any other
// URL scheme is rejected at decode (see decodeConfig).
// Default: "localhost:4317"
OTelEndpoint string `json:"otel_endpoint"`

// OTelTLS selects the OTLP transport. False (the default) dials plaintext,
// which is correct for the in-pod loopback collector but sends spans —
// including lineage.principal.* on every inbound request, and full payloads
// under CaptureIO — in cleartext. Set true for any collector off-pod: it
// dials with TLS against the system root CAs. An https:// otel_endpoint
// turns this on automatically; a plaintext otel_endpoint with otel_tls:true
// is honoured (TLS to a host:port). The one rejected combination is an
// https:// endpoint with an explicit otel_tls:false (see decodeConfig): a
// contradiction that would otherwise silently downgrade to cleartext.
OTelTLS bool `json:"otel_tls"`

// CaptureIO when true attaches parsed request/response content as
// input.value (request span) and output.value (response span)
// attributes, enabling Phoenix to display message content inline.
//
// For A2A (inbound agent calls): input = user message parts, output = artifact.
// For MCP tools/call: input = tool params JSON, output = tool result JSON.
// For Inference (LLM): input = messages array JSON, output = completion text.
//
// Off by default — enable only if traces do not contain PII or the
// OTel backend enforces appropriate access controls.
CaptureIO bool `json:"capture_io"`

// MaxPayloadBytes caps the size of the input.value / output.value
// attributes attached under CaptureIO. A payload longer than this is cut on
// a UTF-8 boundary and suffixed with a truncation marker, so the loss is
// explicit in the span. This is a deliberate producer-side bound; the OTel
// SDK does not itself drop or truncate an oversized value (its default
// attribute-value limit is unlimited and Init sets no SpanLimits), so
// without this cap the whole payload would be emitted. Zero (or unset) uses
// defaultMaxPayloadBytes; a negative value disables the cap (attach whole).
// Ignored when CaptureIO is false.
// Default: 4096
MaxPayloadBytes int `json:"max_payload_bytes"`

// BypassPaths lists URL path prefixes that should not generate lineage
// hops. Useful for suppressing infrastructure polling (agent-card
// discovery, health checks) that would otherwise flood the lineage graph.
// Default: ["/.well-known/", "/healthz", "/readyz", "/health"]
BypassPaths []string `json:"bypass_paths"`

// BypassHosts lists target host substrings (matched against pctx.Host)
// that should not generate lineage hops. Useful for suppressing
// infrastructure outbound calls such as OTel trace exports.
// Default: ["otel-collector", "jaeger", "zipkin", "prometheus"]
BypassHosts []string `json:"bypass_hosts"`

// SelfID is the agent's own stable identifier, emitted as the
// lineage.self.id fact on every span. Typically the Keycloak client ID
// of this workload. If empty, SelfIDFile is consulted instead.
SelfID string `json:"self_id"`

// SelfIDFile is the path to a file containing the agent's own client ID.
// Defaults to /shared/client-id.txt (the operator-mounted credential).
// Ignored when SelfID is set.
SelfIDFile string `json:"self_id_file"`
}

func defaultConfig() Config {
return Config{
OTelEndpoint: defaultOTelEndpoint,
MaxPayloadBytes: defaultMaxPayloadBytes,
BypassPaths: []string{"/.well-known/", "/healthz", "/readyz", "/health"},
BypassHosts: []string{"otel-collector", "jaeger", "zipkin", "prometheus"},
SelfIDFile: "/shared/client-id.txt",
}
}

func decodeConfig(raw json.RawMessage) (Config, error) {
cfg := defaultConfig()
if len(raw) == 0 {
return cfg, nil
}
// Unknown keys are a boot error: a typo'd knob (capture-io, selfid_file)
// must not silently run with defaults.
dec := json.NewDecoder(bytes.NewReader(raw))
dec.DisallowUnknownFields()
if err := dec.Decode(&cfg); err != nil {
return Config{}, fmt.Errorf("lineage-telemetry config: %w", err)
}
if cfg.OTelEndpoint == "" {
cfg.OTelEndpoint = defaultOTelEndpoint
}
// Zero means "unset" → the safe default; a negative value is the explicit
// opt-out (no cap). This keeps an omitted key and an explicit 0 identical.
if cfg.MaxPayloadBytes == 0 {
cfg.MaxPayloadBytes = defaultMaxPayloadBytes
}
// gRPC NewClient expects host:port only, so reduce a URL form (e.g.
// http://collector:4317/v1/traces) to its host — TrimPrefix left any path
// behind and produced an invalid dial target. A URL scheme also carries an
// intent about transport: https:// asks for TLS. Honour it (or fail on a
// contradiction) rather than silently dropping to cleartext.
if strings.Contains(cfg.OTelEndpoint, "://") {
u, err := url.Parse(cfg.OTelEndpoint)
if err != nil || u.Host == "" {
return Config{}, fmt.Errorf("lineage-telemetry config: invalid otel_endpoint %q", cfg.OTelEndpoint)
}
// Only http/https carry a meaningful OTLP transport intent. Reject any
// other scheme (ftp://, ftps://, …) rather than strip it and dial the
// bare host:port insecurely — that would silently send principal facts
// and payloads in cleartext. Fail closed, matching this package's
// DisallowUnknownFields / https+otel_tls:false posture.
if u.Scheme != "http" && u.Scheme != "https" {
return Config{}, fmt.Errorf("lineage-telemetry config: unsupported otel_endpoint scheme %q (want http or https)", u.Scheme)
}
if u.Scheme == "https" {
Comment thread
coderabbitai[bot] marked this conversation as resolved.
// An explicit otel_tls:false alongside an https:// endpoint is a
// contradiction: one asks for encryption, the other for cleartext.
// Fail closed rather than pick one, consistent with the
// DisallowUnknownFields fail-on-ambiguity choice this package makes.
if tlsExplicitlyFalse(raw) {
return Config{}, fmt.Errorf("lineage-telemetry config: otel_endpoint %q is https but otel_tls is false", cfg.OTelEndpoint)
}
cfg.OTelTLS = true
}
cfg.OTelEndpoint = u.Host
}
return cfg, nil
}

// tlsExplicitlyFalse reports whether the raw config carries otel_tls set to a
// literal false, as opposed to being absent (whose decoded value is also false
// but carries no intent). Used only to reject the https:// + otel_tls:false
// contradiction; a decode failure here is treated as "not explicitly false"
// since the DisallowUnknownFields pass above already validated the shape.
func tlsExplicitlyFalse(raw json.RawMessage) bool {
var probe struct {
OTelTLS *bool `json:"otel_tls"`
}
if err := json.Unmarshal(raw, &probe); err != nil {
return false
}
return probe.OTelTLS != nil && !*probe.OTelTLS
}
Loading
Loading