Skip to content

Commit 38f3872

Browse files
committed
Config file for Context Guru that terminates TLS; logging of random ports
Signed-off-by: Ed Snible <snible@us.ibm.com>
1 parent 249de04 commit 38f3872

2 files changed

Lines changed: 91 additions & 3 deletions

File tree

authbridge/cmd/authbridge-proxy/main.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -544,9 +544,14 @@ func startHTTPServer(name string, handler http.Handler, addr string) *http.Serve
544544
Handler: handler,
545545
ReadHeaderTimeout: 10 * time.Second,
546546
}
547+
listener, err := net.Listen("tcp", addr)
548+
if err != nil {
549+
log.Fatalf("%s listen: %v", name, err)
550+
}
547551
go func() {
548-
slog.Info("HTTP server listening", "name", name, "addr", addr)
549-
if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed {
552+
actualAddr := listener.Addr().String()
553+
slog.Info("HTTP server listening", "name", name, "addr", actualAddr)
554+
if err := srv.Serve(listener); err != nil && err != http.ErrServerClosed {
550555
log.Fatalf("%s serve: %v", name, err)
551556
}
552557
}()
@@ -572,7 +577,7 @@ func startReverseProxyServer(name string, rp *reverseproxy.Server, addr string)
572577
log.Fatalf("%s listen: %v", name, err)
573578
}
574579
go func() {
575-
slog.Info("HTTP server listening", "name", name, "addr", addr, "mtls", rp.MTLSEnabled())
580+
slog.Info("Reverse server listening", "name", name, "addr", listener.Addr().String(), "mtls", rp.MTLSEnabled())
576581
if err := srv.Serve(listener); err != nil && err != http.ErrServerClosed {
577582
log.Fatalf("%s serve: %v", name, err)
578583
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# AuthBridge config for the context-guru demo — HTTPS variant.
2+
#
3+
# Use a `tls_bridge` block so
4+
# the forward proxy MITM-terminates the agent's outbound TLS. Without it, HTTPS
5+
# LLM calls arrive as an opaque CONNECT tunnel and context-guru sees no body.
6+
# With it, the decrypted HTTP request is fed through the outbound pipeline, so
7+
# inference-parser + context-guru can read and rewrite the LLM request body.
8+
#
9+
# ── PREREQUISITES (all three are required for HTTPS interception to work) ──
10+
# 1. Client trusts the bridge CA. TLS termination means the proxy presents its
11+
# OWN leaf cert for the LLM host. The agent's HTTP client rejects it unless
12+
# it trusts /tmp/tls-bridge-ca/ca.crt. For a Node agent:
13+
# NODE_EXTRA_CA_CERTS=/tmp/tls-bridge-ca/ca.crt
14+
# (Python: REQUESTS_CA_BUNDLE / SSL_CERT_FILE; Go: SSL_CERT_FILE.)
15+
# 2. Agent routes HTTPS through the forward proxy:
16+
# HTTPS_PROXY=http://127.0.0.1:8081
17+
# 3. Plugin is compiled in (it is opt-in) and the package is fully built:
18+
# LOG_LEVEL=debug go run -tags include_plugin_contextguru .
19+
#
20+
# THREE MODES via the context-guru entry's `on_error` (unchanged from the demo):
21+
# enforce (default) — compaction is applied to the outbound request.
22+
# observe — shadow: engine runs and records what it WOULD save, but
23+
# the request is forwarded unchanged. A/B the gain live.
24+
# off — kill-switch: the plugin is dropped entirely (baseline).
25+
mode: proxy-sidecar
26+
listener:
27+
# Note that commenting out the reverse proxy doesn't disable it, so give it a random port.
28+
reverse_proxy_addr: ":0"
29+
forward_proxy_addr: ":8081"
30+
reverse_proxy_backend: "http://localhost:8001" # the agent (moved off :0)
31+
32+
# TLS termination of agent egress so the outbound pipeline sees decrypted HTTPS.
33+
tls_bridge:
34+
mode: enabled # disabled | enabled (empty == disabled)
35+
ca_dir: /tmp/tls-bridge-ca # required when enabled; MUST persist across restarts
36+
generate_ca: true # demo/standalone: mint a self-signed CA into ca_dir
37+
# if absent. In-cluster this stays false (CA is a
38+
# mounted cert-manager Secret).
39+
ports: [443, 8443] # ports to intercept as TLS (this is also the default).
40+
# Only HTTP(S)-bearing ports — do NOT add non-HTTP
41+
# TLS ports (LDAPS/DB-over-TLS) or the bridge breaks them.
42+
# upstream_ca_bundle: /path/to/roots.pem # extra roots for re-origination to a
43+
# private-CA LLM endpoint; omit for system roots only.
44+
passthrough_hosts: # hosts to tunnel WITHOUT terminating (egress gate still
45+
- "keycloak.*" # runs, they just aren't decrypted). Keep control-plane
46+
- "*.keycloak.svc" # and IdP traffic out of the MITM path.
47+
48+
pipeline:
49+
# inbound:
50+
# plugins: [] # no-auth demo; add jwt-validation for the full flow
51+
outbound:
52+
plugins:
53+
- name: inference-parser
54+
- name: context-guru
55+
on_error: enforce # enforce | observe | off (see header)
56+
config:
57+
# Only inference paths are compacted; everything else passes through.
58+
paths: ["/v1/chat/completions", "/v1/completions", "/v1/messages"]
59+
# Static cheap model for the LLM-backed extract:code component. OpenAI wire
60+
# only (base_url + /v1/chat/completions). Key injected from a Secret via env.
61+
# NOTE: if CG_MODEL_BASE is now an https:// endpoint, this outbound call ALSO
62+
# goes through the forward proxy — its host must be on an intercepted port
63+
# (443/8443) or listed under passthrough_hosts, and its cert must verify.
64+
model:
65+
base_url: "${CG_MODEL_BASE}"
66+
model: "${CG_MODEL_NAME}"
67+
api_key: "${CG_MODEL_KEY}"
68+
# `engine` is context-guru's native config, passed verbatim to config.LoadBytes.
69+
engine:
70+
# 2 deterministic reducers (dedup, collapse) + extract strategy=code.
71+
pipeline: [dedup, extract, collapse]
72+
components:
73+
dedup: # drop byte-identical tool outputs
74+
min_tokens: 40
75+
extract: # LLM writes a sandboxed, deletion-only,
76+
strategy: code # containment-proven projection of each
77+
marker_mode: summary # large tool output (v1: no restoration ->
78+
model: { source: config } # summary leaves a ⟪cg⟫ breadcrumb, no stash)
79+
trigger: { min_output_tokens: 120 } # only project outputs at least this big
80+
collapse: # gentle head/tail net for anything extract left
81+
max_tokens: 300
82+
head_lines: 12
83+
tail_lines: 12

0 commit comments

Comments
 (0)