mirror of
https://github.com/pomerium/pomerium.git
synced 2025-06-01 18:33:19 +02:00
grpc: send client traffic through envoy (#2469)
* wip * wip * handle wildcards in override name * remove wait for ready, add comment about sync, force initial sync complete in test * address comments
This commit is contained in:
parent
87c3c675d2
commit
bbec2cae9f
26 changed files with 391 additions and 480 deletions
|
@ -81,29 +81,18 @@ func (srv *Server) storeEnvoyConfigurationEvent(ctx context.Context, evt *events
|
|||
}
|
||||
|
||||
func (srv *Server) getDataBrokerClient(ctx context.Context) (databrokerpb.DataBrokerServiceClient, error) {
|
||||
options := srv.currentConfig.Load().Options
|
||||
cfg := srv.currentConfig.Load()
|
||||
|
||||
sharedKey, err := options.GetSharedKey()
|
||||
sharedKey, err := cfg.Options.GetSharedKey()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
urls, err := options.GetDataBrokerURLs()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cc, err := grpc.GetGRPCClientConn(ctx, "databroker", &grpc.Options{
|
||||
Addrs: urls,
|
||||
OverrideCertificateName: options.OverrideCertificateName,
|
||||
CA: options.CA,
|
||||
CAFile: options.CAFile,
|
||||
RequestTimeout: options.GRPCClientTimeout,
|
||||
ClientDNSRoundRobin: options.GRPCClientDNSRoundRobin,
|
||||
WithInsecure: options.GetGRPCInsecure(),
|
||||
InstallationID: options.InstallationID,
|
||||
ServiceName: options.Services,
|
||||
SignedJWTKey: sharedKey,
|
||||
cc, err := grpc.GetOutboundGRPCClientConn(context.Background(), &grpc.OutboundOptions{
|
||||
OutboundPort: cfg.OutboundPort,
|
||||
InstallationID: cfg.Options.InstallationID,
|
||||
ServiceName: cfg.Options.Services,
|
||||
SignedJWTKey: sharedKey,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("controlplane: error creating databroker connection: %w", err)
|
||||
|
|
|
@ -69,6 +69,7 @@ func TestEvents(t *testing.T) {
|
|||
li, err := net.Listen("tcp", "127.0.0.1:0")
|
||||
require.NoError(t, err)
|
||||
defer li.Close()
|
||||
_, outboundPort, _ := net.SplitHostPort(li.Addr().String())
|
||||
|
||||
var putRequest *databrokerpb.PutRequest
|
||||
var setOptionsRequest *databrokerpb.SetOptionsRequest
|
||||
|
@ -100,6 +101,7 @@ func TestEvents(t *testing.T) {
|
|||
srv := &Server{}
|
||||
srv.currentConfig.Store(versionedConfig{
|
||||
Config: &config.Config{
|
||||
OutboundPort: outboundPort,
|
||||
Options: &config.Options{
|
||||
SharedKey: cryptutil.NewBase64Key(),
|
||||
DataBrokerURLString: "http://" + li.Addr().String(),
|
||||
|
|
|
@ -68,20 +68,20 @@ type Server struct {
|
|||
}
|
||||
|
||||
// NewServer creates a new Server. Listener ports are chosen by the OS.
|
||||
func NewServer(name string, metricsMgr *config.MetricsManager) (*Server, error) {
|
||||
func NewServer(cfg *config.Config, metricsMgr *config.MetricsManager) (*Server, error) {
|
||||
srv := &Server{
|
||||
metricsMgr: metricsMgr,
|
||||
reproxy: reproxy.New(),
|
||||
envoyConfigurationEvents: make(chan *events.EnvoyConfigurationEvent, 10),
|
||||
}
|
||||
srv.currentConfig.Store(versionedConfig{
|
||||
Config: &config.Config{Options: &config.Options{}},
|
||||
Config: cfg,
|
||||
})
|
||||
|
||||
var err error
|
||||
|
||||
// setup gRPC
|
||||
srv.GRPCListener, err = net.Listen("tcp4", "127.0.0.1:0")
|
||||
srv.GRPCListener, err = net.Listen("tcp4", net.JoinHostPort("127.0.0.1", cfg.GRPCPort))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -92,7 +92,7 @@ func NewServer(name string, metricsMgr *config.MetricsManager) (*Server, error)
|
|||
),
|
||||
)
|
||||
srv.GRPCServer = grpc.NewServer(
|
||||
grpc.StatsHandler(telemetry.NewGRPCServerStatsHandler(name)),
|
||||
grpc.StatsHandler(telemetry.NewGRPCServerStatsHandler(cfg.Options.Services)),
|
||||
grpc.ChainUnaryInterceptor(requestid.UnaryServerInterceptor(), ui),
|
||||
grpc.ChainStreamInterceptor(requestid.StreamServerInterceptor(), si),
|
||||
)
|
||||
|
@ -102,7 +102,7 @@ func NewServer(name string, metricsMgr *config.MetricsManager) (*Server, error)
|
|||
grpc_health_v1.RegisterHealthServer(srv.GRPCServer, pom_grpc.NewHealthCheckServer())
|
||||
|
||||
// setup HTTP
|
||||
srv.HTTPListener, err = net.Listen("tcp4", "127.0.0.1:0")
|
||||
srv.HTTPListener, err = net.Listen("tcp4", net.JoinHostPort("127.0.0.1", cfg.HTTPPort))
|
||||
if err != nil {
|
||||
_ = srv.GRPCListener.Close()
|
||||
return nil, err
|
||||
|
@ -121,7 +121,7 @@ func NewServer(name string, metricsMgr *config.MetricsManager) (*Server, error)
|
|||
)
|
||||
|
||||
ctx := log.WithContext(context.Background(), func(c zerolog.Context) zerolog.Context {
|
||||
return c.Str("server_name", name)
|
||||
return c.Str("server_name", cfg.Options.Services)
|
||||
})
|
||||
|
||||
res, err := srv.buildDiscoveryResources(ctx)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue