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 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题