feat: configurable HTTP header forwarding to ClickHouse#63
feat: configurable HTTP header forwarding to ClickHouse#63isushkov-akamai wants to merge 3 commits intoAltinity:mainfrom
Conversation
8184b6f to
f20192a
Compare
f20192a to
4efb86a
Compare
Slach
left a comment
There was a problem hiding this comment.
PR Review
Good feature, clean approach via context. A few observations:
1. cmd/altinity-mcp/main.go:240-245 — Spaces instead of tabs
The new forward-http-headers flag uses spaces for indentation while the rest of the file uses tabs. Should be consistent.
2. cmd/altinity-mcp/main.go:1003-1006 — Dead code (DefaultForwardHTTPHeaders)
if len(cfg.Server.ForwardHTTPHeaders) == 0 && !cmd.IsSet("forward-http-headers") {
cfg.Server.ForwardHTTPHeaders = altinitymcp.DefaultForwardHTTPHeaders
}DefaultForwardHTTPHeaders is declared as var DefaultForwardHTTPHeaders []string — which is nil. This block assigns nil to an already empty slice. It's a no-op, should be removed.
3. pkg/server/server.go — "sort" import not in alphabetical order
sort is placed after strconv, should go before it.
4. PR description vs code: "Pattern validation: rejects invalid patterns" — but no validation exists
The PR description states: "Pattern validation: rejects invalid patterns (*Foo, X-*Z)", but there is no pattern validation at config load time. matchesAnyPattern simply won't match such patterns, but the user gets no error on misconfiguration. Either add validation with an error at startup, or remove this claim from the description.
5. PR description vs code: "Immutable context: headers are cloned on store and retrieve" — no clone on retrieve
ForwardedHeadersFromContext returns the map directly without copying. If a caller mutates the map, it affects all subsequent calls. Either clone on retrieve or remove this claim from the description.
6. pkg/server/server.go — Pattern "*" forwards all headers including Authorization and Cookie
Pattern * matches everything (since strings.HasPrefix(anything, "") is always true). This could unintentionally leak sensitive headers to ClickHouse. Consider either adding a blocklist (Authorization, Cookie, Host) or at least emitting a log.Warn when * is configured.
7. No test for CORSAllowHeaders
The CORSAllowHeaders function has no test coverage, and it contains non-trivial wildcard → * logic.
8. No test for GetClickHouseClientWithHeaders
The core function of this PR — merging extraHeaders into chConfig.HttpHeaders — is not tested.
|
could you resolve conflicts? |
4efb86a to
453c350
Compare
done |
Slach
left a comment
There was a problem hiding this comment.
Спасибо за исправления! Большинство замечаний закрыто. Осталось два нерешённых пункта — см. комментарии к коду.
|
unit tests didn't pass |
use |
Summary
Adds configurable forwarding of incoming HTTP headers from MCP requests to ClickHouse.
This enables
getClientHTTPHeader()in ClickHouse row policies and INVOKER views formulti-tenant Row-Level Security without per-tenant ClickHouse users.
--forward-http-headersCLI flag /FORWARD_HTTP_HEADERSenv var / config file optionX-Tenant-Id) and trailing wildcards (X-*)Security