server: trailing metadata is echoed unfiltered, and the reserved-name policy needs deciding

オープン
#263 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
30/100
issue の種類
バグ
明瞭さ
説明が足りない
活発さ
静か
技術スタック
grpc, rust

調査の方向性

まず ConnectError::with_trailers、build_grpc_trailers、add_trailers を通る trailer フローを読み、次に #262 で取り消された試みを確認します。動作を変更する前に、予約名、出所、可観測性、エスケープハッチのポリシーを解決してください。trailer に特化したテストを追加し、結果を検証するために #262 の grpc-go/connect-go 相互運用ハーネスのパターンを使用します。

索引モデルが issue の本文から書いたものです。

説明

Summary

#262 stops the server echoing an upstream error's response headers onto the wire, because an echoed content-length made hyper write zero bytes and drop a Connect/HTTP-1.1 connection. The same class exists one frame later, in trailers, and it is not fixed there: err.trailers() and the handler's context trailing metadata are both echoed with no filtering at all.

Measured against real clients — a gateway propagating an upstream failure puts content-length: 4096, connection: keep-alive, transfer-encoding: chunked and a second content-type into the HTTP/2 trailers frame, and they arrive verbatim at both grpc-go v1.81.1 and connect-go v1.19.1. On the Connect unary path the same names arrive as trailer--prefixed headers. Both Go clients tolerate it today, so this is latent rather than breaking, unlike the header case.

An attempt to fix it inside #262 was reverted, because it turned out to need a policy decision rather than a predicate. The attempt is worth reading before redoing it — what follows is what it ran into.

Why this is not just "call the same predicate on trailers"

Provenance is not derivable where the filtering happens. ConnectError::with_trailers is a plain public handler API — "Add response trailers to be included in the error response" — and this repo's own conformance server calls it at six sites. So err.trailers() may hold trailing metadata a handler authored deliberately, or metadata propagated from an upstream, and nothing at the call site distinguishes them. A flag threaded from the call sites tracks which struct field the trailers arrived in, not who wrote them; the attempt did exactly that and the flag was wrong for every error path.

That matters because the two cases want different handling. Silently dropping an upstream's content-length is right. Silently dropping a name a handler deliberately set is a bad afternoon for that handler, with no signal.

But the obvious signal is remotely drivable. Logging a warning when a reserved name is dropped from handler-set metadata sounds right until you notice that handler-set trailer names are frequently derived from request data — the conformance server sets resp.trailers verbatim from the request payload, and real gateways that echo caller-supplied metadata have the same shape. That is one log line per RPC at whatever rate a peer can sustain, unbounded and undeduplicated.

And the source-selection branch has the same bug one level up. build_grpc_trailers decides between the error's trailers and the context's by testing whether the error's are non-empty. Filter after that test and an upstream error whose trailers are entirely reserved names suppresses the handler's own context trailers and emits nothing at all.

What a fix has to decide

  1. Which names. The header-side list in #262 is hop-by-hop, body framing, provenance (date), and status-bearing (grpc-status, grpc-message, grpc-status-details-bin). Not all of it transfers: in add_trailers every name is rewritten to trailer-{name} before it reaches the wire, so a forwarded content-length becomes trailer-content-length, which cannot reach hyper's length encoder or be mistaken for framing by any client. Filtering there is cross-hop consistency, not a fix — worth deciding whether that is a reason to do it or a reason not to.
  2. Whose metadata. Forwarded only, or handler-set too? Forwarded-only is defensible and much smaller. Handler-set filtering is a behaviour change on the success path, which no bug in #202 or #262 reached.
  3. Observable how. If handler-set names are stripped, a handler needs to find out without giving a peer a log-amplification lever. A debug!, a once-per-process warning per name, or a compile-time/API-level rejection at the setter are all candidates. The setter is the one place provenance is unambiguous.
  4. What the escape hatch is. If a handler genuinely wants date as trailing metadata, is the answer "you cannot", or a namespaced form, or an explicit opt-out?

Notes

server, via and alt-svc were considered and deliberately left forwarded. The argument for leaving them: the deny-list is a correctness boundary where every entry has a mechanical failure attached, and suppressing a few well-known identity headers while forwarding arbitrary upstream metadata does not make a gateway non-leaky — it makes it look non-leaky. A gateway that must not disclose upstream identity should strip metadata wholesale in an interceptor. alt-svc is the one worth revisiting, since a forwarded one redirects the client's future connections.

Conformance says nothing about any of this: the only trailer names anywhere in the upstream testsuite are x-custom-trailer and x-custom-header, so the whole reserved-name question is unexercised. A fix needs its own tests, and the interop harness pattern from #262 (real grpc-go and connect-go clients against our server, with a per-header bisect) is the way to check it.

主要言語
Rust
スター
542
フォーク
74
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

connectrpc/connect-rust のほかの issue

connectrpc/connect-rust の issue をすべて見る

似ている issue

Rust の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。