kratos
kratos copied to clipboard
middleware: middleware registry & selector config
Feature-request
Proposal
middleware registry,类似 gateway registry,可以通过名称进行注册管理; yaml 配置,并且通过 对应名称的 middleware,这个 yaml 配置将会放到 proto 相同目录,通过工具生成配置注册; selector,通过 operation 进行匹配选择对应的 middleware。
例子:
type: google.api.Service
config_version: 3
name: library-example.googleapis.com
title: Example Library API
backend:
rules:
- selector: 'google.pubsub.v1.Publisher.*'
deadline: 120.0
- selector: google.pubsub.v1.Publisher.Publish
authentication:
rules:
- selector: 'google.iam.v1.IAMPolicy.*'
oauth:
canonical_scopes: |-
https://www.googleapis.com/auth/cloud-platform,
https://www.googleapis.com/auth/pubsub
ref: https://github.com/googleapis/googleapis/blob/master/google/example/library/library_example_v1.yaml
生成插件: protoc-gen-grpc protoc-gen-http protoc-gen-kratos
pb.RegisterGreeterHTTPServer(httpServer)
pb.RegisterGreeterServer(grpcServer)
func RegisterGreeterKratosServer(srv grpc.Server) {
// build middleware config
srv.RegisterMiddleware(`yaml config`)
}
可以通过复写下注册方法,传递 kratos server 进来下
这个 Proposal 提实用的 。
可通过yaml的形式,指定不同接口所使用的中间件,如某些接口需要auth,某些不需要。
比如在 beer-shop 项目的 interface 中,现在只能通过 selector 的形式来进行配置 auth,接口数量一多时,会需要写大量的 selector whiteList 在 http 中(或者有其它办法处理这个 whiteList?),不利于模块化管理。
https://github.com/go-kratos/beer-shop/blob/f758c74c1e6704f8bc689408dc904d522a871f79/app/shop/interface/internal/server/http.go#L21-L32
To have your gRPC service managed by Endpoints, in addition to the compiled proto file, you have to specify a service configuration in one or more YAML files. A service configuration is a specification that lets you define the behavior of a gRPC service, including authentication, quotas, and more.
ref:
- https://cloud.google.com/endpoints/docs/grpc/grpc-service-config
- https://grpc-ecosystem.github.io/grpc-gateway/docs/mapping/grpc_api_configuration/#generate_unbound_methods
- https://github.com/googleapis/googleapis
- https://eng.uber.com/architecture-api-gateway
- https://github.com/grpc-ecosystem/grpc-gateway/pull/521
是的,这个可以支持 grpc service config,以及 middleware config,用户配置app.yaml 就可以了完成配置了
Hi, @tonybase! I'm Dosu, and I'm helping the kratos team manage their backlog. I wanted to let you know that we are marking this issue as stale.
From what I understand, this issue is a feature request for a middleware registry and selector configuration. You and shi-yang discussed the possibility of implementing this feature using YAML configuration and different middleware for different APIs. You confirmed that this can be achieved by configuring app.yaml.
Before we close this issue, we wanted to check if it is still relevant to the latest version of the kratos repository. If it is, please let us know by commenting on this issue. Otherwise, feel free to close the issue yourself, or it will be automatically closed in 7 days.
Thank you for your contribution and your understanding. Let us know if you have any further questions or concerns.