mirror of
https://github.com/hanzo-ml/kuberay.git
synced 2026-10-30 19:48:47 +00:00
Right now API server access is completely opened. This defines the approach to secure API server and provides a very simple implementation. Securing API server endpoint Related issue number Closes #1376
33 lines
1.0 KiB
Go
33 lines
1.0 KiB
Go
package grpcproxy
|
|
|
|
import (
|
|
"context"
|
|
|
|
"google.golang.org/grpc"
|
|
"google.golang.org/grpc/metadata"
|
|
)
|
|
|
|
// NewProxy sets up a simple proxy that forwards all requests to dst.
|
|
func NewProxy(dst *grpc.ClientConn, opts ...grpc.ServerOption) (*grpc.Server, *handler) {
|
|
option, h := DefaultProxyOpt(dst)
|
|
opts = append(opts, option)
|
|
// Set up the proxy server and then serve from it like in step one.
|
|
return grpc.NewServer(opts...), h
|
|
}
|
|
|
|
// DefaultProxyOpt returns an grpc.UnknownServiceHandler with a DefaultDirector.
|
|
func DefaultProxyOpt(cc *grpc.ClientConn) (grpc.ServerOption, *handler) {
|
|
sh, h := TransparentHandler(DefaultDirector(cc))
|
|
return grpc.UnknownServiceHandler(sh), h
|
|
}
|
|
|
|
// DefaultDirector returns a very simple forwarding StreamDirector that forwards all
|
|
// calls.
|
|
func DefaultDirector(cc *grpc.ClientConn) StreamDirector {
|
|
return func(ctx context.Context, fullMethodName string) (context.Context, *grpc.ClientConn, error) {
|
|
md, _ := metadata.FromIncomingContext(ctx)
|
|
ctx = metadata.NewOutgoingContext(ctx, md.Copy())
|
|
return ctx, cc, nil
|
|
}
|
|
}
|