Repository navigation
Refactor: Move the relay boundary into core/attribution - #1700
Conversation
The forward proxy kept the attribution state of each client connection in its own connProc type. A later hairpin listener (rossoctl#1491) must use the same state. This change moves it to core/attribution. New in core/attribution (conn.go): - ConnKey and ConnKeyOf name a connection by its two ends. - Memo holds the process chain and the listener cache of one connection. - Chain looks up the chain once for each Memo. It gives the error only to the call that made the lookup. - Program names the client program for the TLS bridge rules. - SelfTraffic finds an agent that talks to its own local service. The forward proxy keeps its gates, loopbackDests, noteSelfTraffic and its slog lines. The Debug line for a failed lookup does not change. The moved code reads the clock of the Attributor. In production that clock is time.Now. Part of rossoctl#1498. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Hai Huang <[email protected]>
Add Encode and Decode back to core/attribution/wire.go, from 2914e34^. The hairpin listener (rossoctl#1491 W9) uses them. No listener calls them yet. Changes from the old code: - Add HeaderClientProc ("X-Cortex-Client-Proc") for ClientProc, so that Decode(Encode(a)) is equal to a for a worker below its launcher. - Decode accepts only the sources that Resolve returns. It refuses "active" and "connection". - Decode checks ClientProc as "<pid>.<start>" and refuses a control rune in Header. - The comment says that the forward proxy strips the headers. Encode strips every attribution header before it sets the new values. A test shows that a field that is empty does not keep a forged value. A test shows that Strip removes every header that Encode sets. Part of rossoctl#1498. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Hai Huang <[email protected]>
Decode had three faults: - It read only Source, Session and Proc to find an attribution. An Attribution with only Agent did not travel. Decode now reads all of the attribution headers. - It refused only C0 and DEL runes. Decode now refuses invalid UTF-8 and every rune for which unicode.IsControl is true, as session.validHeaderSessionID does. - It accepted process keys that Proc.Key does not write, such as "01.2", "+1.2" and "-1.2". Decode now accepts a key only when Proc.Key writes it again the same, and refuses a negative value. Part of rossoctl#1498. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Hai Huang <[email protected]>
Add sessionevent.Sink in core/listener/internal. It has the nine session.Store methods that a listener calls at record time. *session.Store satisfies it, and a compile-time assertion keeps the signatures the same. This is the one interface to feed the control plane (rossoctl#1497 item 2). Each of forwardproxy, reverseproxy and extproc gets sink(). It returns an untyped nil when Sessions is nil. The record calls use sink(). The Sessions field and its type do not change. Every nil check still reads the field. AddRecorder stays a call on the field, because it is start-up wiring. The one call that relied on a nil-safe *Store receiver is TakesCaptures in forwardproxy's serveOutbound. It now reads "s.Sessions != nil && s.sink().TakesCaptures()", which gives the same result. A new test checks that sink() gives an untyped nil without a store. Part of rossoctl#1497 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Hai Huang <[email protected]>
The strip test sent only 3 of the 7 attribution headers. It now sends all 7, X-Cortex-Client-Proc included, and checks that the upstream gets none of them. Without HeaderClientProc in wireHeaders, the test fails. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Hai Huang <[email protected]>
Chain takes the memo as its last parameter, and SelfTraffic took it as its second. SelfTraffic now takes it last too, before the two methods become public API. The doc comments of the two methods also say that m must not be nil. Both methods use m without a nil check. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Hai Huang <[email protected]>
The three listeners had the same 4-line sink() body. sessionevent.SinkOf now holds that body, and each sink() calls it. The call sites do not change. The nil-store test moves to sessionevent. It also checks that a store gives a non-nil Sink. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Hai Huang <[email protected]>
Encode sets each header with Set, so a trusted hop sends one value per header. Decode read only the first value of a header that had more. It now refuses the whole attribution when any wire header has more than one value. Two new refusal cases cover this. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Hai Huang <[email protected]>
One line of the comment had 108 characters. It now wraps at about 90, as the lines near it do. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Hai Huang <[email protected]>
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 49 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
clawgenti
left a comment
There was a problem hiding this comment.
Summary
This is a clean move. I checked connProc/lookupChain/bridgeProgram/selfTraffic/agentsOwnService/listenerBehind against base line by line, and they behave the same. The once-per-connection lookup still logs a failure once at DEBUG. An invalid key still looks nothing up and logs nothing. affinityClient was already AgentOf. a.now() falls back to time.Now() because the forward proxy sets no Now. The empty-chain early return still runs before the nil-Attributor read, and the new test covers it. One *Memo is still shared with the bridged tunnel (tl.conn). No tests were dropped, and there are no import cycles (attribution -> tlsbridge is a leaf). The Sink switch is safe: TakesCaptures was the only nil-receiver-tolerant method, and both of its call sites now sit behind a Sessions != nil guard. In websocket.go that guard is the enclosing if. The one behaviour change, stripping X-Cortex-Client-Proc, is documented and tested. Encode and Decode have no caller, so nothing client-controlled reaches Decode in this PR.
Verified locally at 19b7bb6: go build ./... + go vet in core; go test ./attribution/... ./listener/... ./session/... all pass; -race on ./attribution and ./listener/internal/sessionevent; gofmt -l clean. cmd/cortex (build+vet), cmd/cortex-envoy and cmd/cortex-praxis build.
Author: huang195 (MEMBER — maintainer)
Areas reviewed: Go (core/attribution, core/listener/{forwardproxy,reverseproxy,extproc,internal/sessionevent})
Agent/IDE config (.claude/.vscode): none
Commits: 9 commits, all signed-off: yes
CI status: passing (39 pass, 2 skipped)
| Header: h.Get(HeaderNamedBy), | ||
| ChainSession: h.Get(HeaderChain), | ||
| } | ||
| switch a.Source { |
There was a problem hiding this comment.
suggestion (non-blocking, since nothing calls Decode yet): the checks here are per field, not per shape. Two kinds of input still decode with ok=true:
X-Cortex-Source: headerwith noX-Cortex-Session, orX-Cortex-Session-Headerwith no session.Resolvenever returns either shape.- An
X-Cortex-Agentof any length (I probed 100 kB) or any non-canonical name.Resolveonly ever setsAgentOf's canonical names.
When the trusted hop in #1491 W9 starts calling this, consider tying Source to the fields it implies (header requires Session and Header; process/affinity require Session) and bounding Agent. That way "accepts only what Resolve returns" also holds for the combination of fields.
Fixes review: The Sink interface had one implementation and no seam to give the listeners another one, because Sessions stays *session.Store. Files: - core/listener/extproc/server.go - core/listener/forwardproxy/identity.go - core/listener/forwardproxy/record.go - core/listener/forwardproxy/server.go - core/listener/forwardproxy/transparent.go - core/listener/forwardproxy/tunnel.go - core/listener/forwardproxy/upgrade.go - core/listener/forwardproxy/websocket.go - core/listener/internal/sessionevent/sink.go - core/listener/internal/sessionevent/sink_test.go - core/listener/reverseproxy/server.go Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Hai Huang <[email protected]>
Fixes review: Encode and Decode came back with no caller. Decode is a trust boundary, and its rules must come from the hop that calls it (rossoctl#1491 W9). X-Cortex-Client-Proc stays in the strip list. Files: - core/attribution/wire.go - core/attribution/wire_test.go - core/listener/forwardproxy/process_test.go Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Hai Huang <[email protected]>
rossoctl#1699 moved the data types to core/model. Bring the branch up to date with main. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Hai Huang <[email protected]>
clawgenti
left a comment
There was a problem hiding this comment.
Summary
Since my review of 19b7bb6, the two new commits remove the code that had no caller, and nothing else changes. This settles my earlier Decode suggestion: Encode, Decode and validProc are gone, and the PR body now records the rules W9 must set (tie Source to the fields it implies, put a limit on the Agent length). The Sink/SinkOf removal is a mechanical swap back to s.Sessions.X. I checked every call site. Each one is either behind the same s.Sessions != nil guard as before, or it is TakesCaptures, which accepts a nil *Store (server.go:574 now matches main exactly). Against main, the net diff is now just conn.go/conn_test.go, the process.go move, tunnel.go's *attribution.Memo, and the X-Cortex-Client-Proc strip. The wire.go comment change from "every listener" to "the forward proxy" is also more accurate: only forwardproxy (server.go:447, tunnel.go:225) calls Strip. No references to the removed symbols are left anywhere in the repo.
Verified locally at a366e0d: go build ./..., go vet (attribution, listener) and gofmt -l are clean in core. go test passes on ./attribution/..., ./listener/{forwardproxy,extproc,reverseproxy,internal/...} and ./session/...; one session/archive run flaked and passed on rerun, and this PR does not touch that package. -race passes on ./attribution and ./listener/internal/sessionevent. A merge with current main (d41332a, after #1699) builds and vets, and cmd/cortex, cmd/cortex-envoy and cmd/cortex-praxis build.
Author: @huang195 (MEMBER — maintainer)
Areas reviewed: Go (core/attribution, core/listener/{forwardproxy,reverseproxy,extproc,internal/sessionevent})
Agent/IDE config (.claude/.vscode): none
Commits: 11 commits, all signed-off: yes
CI status: passing (38 pass, 1 skipped, CodeRabbit neutral)
clawgenti
left a comment
There was a problem hiding this comment.
Summary
Re-reviewed at 85839c9. Since my last review at 19b7bb6, 7875fee and a366e0d dropped the Sink switch and Encode/Decode. That leaves the memo move plus the X-Cortex-Client-Proc strip. My earlier suggestion on Decode's per-field checks no longer applies here, since Decode is gone. It now belongs to #1491 W9, as the description says.
I checked the moved code against base, and it behaves the same:
Chain: an invalid key still looks nothing up and logs nothing. A failed lookup is kept, and it logs once at DEBUG, because only the call that runs theoncegets the error.memoChainignoresConnKeyOf'soksafely, because a failed parse leaves the key's ends invalid, andChainchecks that.Program: matches the oldbridgeProgrambody exactly.SelfTraffic: the nil-memo check now runs before the empty-chain check. Both return false, so the order doesn't matter. When the chain is empty,s.attributor()can be nil, andSelfTrafficreturns before it reads it, which the new test covers. When the chain is non-empty,processesOn()has already guaranteedSessionsandProcesses.agentsOwnService:affinityClientwas alreadyAgentOf.listenerBehind:a.now()falls back totime.Now(), because the forward proxy sets noNow.maxHintsis the same constant, now fromlookup.go.- Bridged tunnel: the CONNECT and the requests it decrypts still share one
*Memo(tunnel.go:374->bridging.go:275).
No stray references to connProc, lookupChain or listenerBehind are left in Go code, only in older plan docs. The wire.go comment now says "the forward proxy" instead of "every listener". That matches the code: only forwardproxy (server.go:447, tunnel.go:225) calls Strip.
The behaviour change does what the description claims. With HeaderClientProc taken out of wireHeaders, TestForwardProxy_StripsCortexAttributionHeaders fails with upstream saw X-Cortex-Client-Proc: "2.2". It passes with the header put back.
Verified locally at 85839c9:
go build ./...andgo vet ./...incore, andgofmt -lis clean.go test ./attribution/... ./listener/...all pass, and-raceon./attributionpasses.cmd/cortex,cmd/cortex-envoyandcmd/cortex-praxisbuild.
Author: huang195 (MEMBER — maintainer)
Areas reviewed: Go (core/attribution, core/listener/forwardproxy)
Agent/IDE config (.claude/.vscode): none
Commits: 12 commits (incl. 1 merge from main), all signed-off: yes
CI status: passing (38 pass, 2 skipped)
Part of #1498 (closed by #1682). Phase 2 of the Praxis prep (#1437), for the hairpin gateway (#1491).
What this changes
core/attribution/conn.go. New:ConnKey,ConnKeyOf,Memo,(*Attributor).Chain,ProgramandSelfTraffic. The logic of the forward proxy'sconnProc,selfTrafficandbridgeProgrammoves line for line. The forward proxy keeps its gates, its log lines andloopbackDests. One*Memois still shared by a CONNECT and the requests that its bridged tunnel decrypts.wire.gogets the headerX-Cortex-Client-ProcforAttribution.ClientProc, in the strip list. No existing header name changes.One behaviour change
The forward proxy now also strips
X-Cortex-Client-Procfrom client requests. Before this PR, a client could send it to the upstream.TestForwardProxy_StripsCortexAttributionHeadersnow checks all 7 headers, and it fails when the new header is not in the strip list.Header names: #1491 differs from
wire.goThis PR keeps the names in
wire.go. #1491 is updated to match.wire.gox-cortex-sessionX-Cortex-Sessionx-cortex-programX-Cortex-Proc"<pid>.<start>", not a programX-Cortex-AgentX-Cortex-Source,X-Cortex-Session-Header,X-Cortex-Chain-Session,X-Cortex-Client-ProcNot in this PR
EncodeandDecodefor these headers. They land with their first caller, Spec: Hairpin gateway — run the Praxis filter pipeline on all laptop traffic, with no upstream changes #1491 W9 ("Boundary contract: strip-then-inject headers").Decodeis a trust boundary, so that caller sets its rules: tieSourceto the fields it implies, and put a limit on theAgentlength.Sinkinterface for the listeners (Feed recording, sessions and cost through one input that does not depend on the Go listeners #1497 item 2). It lands with a second implementation, or when theSessionsfield type changes.Checks run
core:go vet ./...,gofmt -l .,go mod tidy -diffandgo test ./....go test -raceon./attribution/...and./listener/....conn_test.go(one lookup per memo, a failed lookup is kept, the 30 s listener cache for a hit and a miss, every listener must qualify).cmd/cortex(full profile),cmd/cortex-envoy(envoy profile) andcmd/cortex-praxisbuild and vet.Assisted-By: Claude (Anthropic AI) [email protected]