Skip to content

gRPC: choose which metadata keys bind the request context; client-sent x-user-id/x-tenant-id are trusted and propagated #112

Closed

Description

@AlexeyShalaev

Problem

The gRPC adapter has the same trust model as the HTTP one in #110. UnitScopeInterceptor builds the unit context from get_correlation_ids (adapters/grpc/metadata.py), and that function always reads x-request-id, x-user-id, x-tenant-id and x-trace-id from the incoming metadata. The mapping is a module constant, _CORRELATION_METADATA_KEYS, and neither the interceptor nor GrpcConfig can change it.

A client that reaches the gRPC port therefore sets user_id and tenant_id. Those values end up in every log line and in the propagated metadata of outbound calls, the same way they do over HTTP.

Proposal

Mirror #110: a context_metadata: dict[str, str] | None field on GrpcConfig, also a keyword of GrpcConfig.from_settings (the settings model belongs to grpc-server-kit), passed to UnitScopeInterceptor. None keeps today's four keys and {} reads none. Document the trust model in docs/adapters/grpc.md next to the table of metadata keys.

Acceptance

  • With context_metadata={"x-request-id": "request_id"}, a call that carries x-user-id metadata binds no user_id, and propagation_metadata() inside the handler returns only x-request-id.

Activity

  1. AlexeyShalaev commented on Nov 13, 2026

    @AlexeyShalaev
    MemberAuthor

    PR is up: #118, stacked on #115. Same semantics as the HTTP side: GrpcConfig.context_metadata and a from_settings(..., context_metadata=...) keyword. None keeps the four keys and {} reads none. grpc-server-kit's settings model has no such field, so the docs show how to add one to your own subclass and get GRPC__CONTEXT_METADATA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions