daklib.rpc_peer¶
Peer address handling for the DAK RPC server.
Classes
|
|
|
gRPC interceptor that records the client's peer address. |
- class daklib.rpc_peer.PeerAddress(ip: ipaddress.IPv4Address | ipaddress.IPv6Address, port: int = 0)[source]¶
- classmethod from_forwarded_header(value: str) PeerAddress | None[source]¶
Parse the client address from a header like X-Forwarded-For.
Only the last entry of a comma-separated list is used: it is the one appended by the trusted reverse proxy; earlier entries are client-controlled. Entries must be bare IP addresses; the port is not available (0).
- classmethod from_grpc_peer(peer: str) PeerAddress | None[source]¶
Parse a gRPC peer string like ipv4:1.2.3.4:5678 or ipv6:[::1]:5678.
Returns None for peers without an IP address (unix sockets).
- ip: IPv4Address | IPv6Address¶
- class daklib.rpc_peer.PeerAddressInterceptor(peer_header: str | None = None)[source]¶
gRPC interceptor that records the client’s peer address.
The address is taken from peer_header if configured, falling back to the connection’s transport address. The header must only be configured when all connections arrive via a trusted reverse proxy that sets it (e.g. via a unix socket only the proxy can reach); otherwise clients can spoof their address.
- _abc_impl = <_abc._abc_data object>¶
- intercept_service(continuation: Callable[[grpc.HandlerCallDetails], grpc.RpcMethodHandler[Any, Any] | None], handler_call_details: HandlerCallDetails) grpc.RpcMethodHandler[Any, Any] | None[source]¶
Intercepts incoming RPCs before handing them over to a handler.
- Args:
- continuation: A function that takes a HandlerCallDetails and
proceeds to invoke the next interceptor in the chain, if any, or the RPC handler lookup logic, with the call details passed as an argument, and returns an RpcMethodHandler instance if the RPC is considered serviced, or None otherwise.
handler_call_details: A HandlerCallDetails describing the RPC.
- Returns:
An RpcMethodHandler with which the RPC may be serviced if the interceptor chooses to service this RPC, or None otherwise.