douweng7233 2016-09-02 00:40
浏览 62
已采纳

向Protobuf添加访问控制[关闭]

I have been thinking of adding some sort of capability-based access control to grpc services. My idea was to have a required capability for each rpc defined in the proto file, and use grpc interceptors to check that the capability provided by the user matches that which is required by the rpc. I have looked at several documents and tutorials, but I'm at a bit of a loss as to where to start. Would appreciate any guidance.

  • 写回答

1条回答 默认 最新

  • duanlou2917 2016-09-02 04:47
    关注

    One way is to achieve this is writing a generator plugin that will parse your proto file, and generates some sort of code or data file. Like grpc-gateway does. Each rpc have options can be customized, and added in proto file like this. Those options are called protobuf.MethodOptions. You can see this here. So You can have your own method options and generate your validator or modifier using this, then call the validator from the interceptor to resolve.

    Another unconventional way i could tell you is that, you could have an json or yaml file including a map. Every protobuf method has an unique name identifier formated as "/package.service/rpcMethodName". so if you have a rpc method like:

    syntax = "proto3";
    
    package yourpackage;
    
    service ServiceName {
      rpc MethodName(Request) returns (Response) {};
    }
    

    the unique identifier for this method will be like as /yourpackage.ServiceName/MethodName that you will find inside your interceptor, as grpc.UnaryServerInfo.FullMethod.

    so the way is you maintain a separate map via yaml or json, that contains your FullMethodName and required capability, then inside your interceptor read the map and find the desired capability for your method, and apply your desired operations.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测