Module auth

Module auth 

Source
Expand description

gRPC 的 Bearer Token 鉴权

两种模式:

  • 未配置 KeyStore:完全不鉴权(保持旧行为,启动日志 warn)
  • 配置了 KeyStore:所有 RPC 必须带 authorization: Bearer <plaintext> metadata, 且按 proto_id 区间 / RPC 类型校验 scope

由于 gRPC 采用通用 Request(proto_id, body) RPC 模式,scope 检查根据 proto_id 区间 进行;SubscribePush 流式 RPC 要求 qot:read (推送混合了行情与交易,以行情 scope 为最低门槛)。

proto_id 范围所需 scope
1xxx 系统(InitConnect / GetGlobalState / KeepAlive / …)无(放行)
3xxx 行情qot:read
2001 / 2008 / 2101 / 2102 / 2111 / 2201 / 2211 / 2221 / 2222 / 2223 / 2225 / 2226 账户只读acc:read
2005 UnlockTradetrade:real
2202 / 2205 / 2237 下单 / 改单 / 确认trade:real
其他拒绝(保守)

Functions§

authenticate
提取 + 校验 Bearer token,返回命中的 KeyRecord;鉴权失败返回 Status
check_scope
检查 KeyRecord 是否持有 needed scope
scope_for_proto
按 proto_id 推断所需 scope