Skip to content

Commit

Permalink
Limit GRPC Active streams (#33936)
Browse files Browse the repository at this point in the history
Originally there was a default limit of 100 max concurrent streams, however in 2017 the GRPC team removed this default: grpc/grpc-go#1624

With the recent HTTP/2 Rapid Reset DoS, it is now being encouraged to re-introduce a limit.  The fix requires this value to be configured in fact: grpc/grpc-go#6703
  • Loading branch information
jentfoo committed Oct 27, 2023
1 parent 9b38f82 commit 70afbe9
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 2 deletions.
2 changes: 2 additions & 0 deletions lib/auth/grpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ import (
wanlib "github.com/gravitational/teleport/lib/auth/webauthn"
"github.com/gravitational/teleport/lib/authz"
"github.com/gravitational/teleport/lib/backend"
"github.com/gravitational/teleport/lib/defaults"
"github.com/gravitational/teleport/lib/events"
"github.com/gravitational/teleport/lib/httplib"
"github.com/gravitational/teleport/lib/joinserver"
Expand Down Expand Up @@ -5308,6 +5309,7 @@ func NewGRPCServer(cfg GRPCServerConfig) (*GRPCServer, error) {
PermitWithoutStream: true,
},
),
grpc.MaxConcurrentStreams(defaults.GRPCMaxConcurrentStreams),
)
if err != nil {
return nil, trace.Wrap(err)
Expand Down
4 changes: 4 additions & 0 deletions lib/defaults/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ const (
// By default all users use /bin/bash
DefaultShell = "/bin/bash"

// GRPCMaxConcurrentStreams is the max GRPC streams that can be active at a time. Once the limit is reached new
// RPC calls will queue until capacity is available.
GRPCMaxConcurrentStreams = 1000

// HTTPMaxIdleConns is the max idle connections across all hosts.
HTTPMaxIdleConns = 2000

Expand Down
2 changes: 1 addition & 1 deletion lib/observability/tracing/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func NewCollector(cfg CollectorConfig) (*Collector, error) {
c := &Collector{
grpcLn: grpcLn,
httpLn: httpLn,
grpcServer: grpc.NewServer(grpc.Creds(creds)),
grpcServer: grpc.NewServer(grpc.Creds(creds), grpc.MaxConcurrentStreams(defaults.GRPCMaxConcurrentStreams)),
tlsConfing: tlsConfig,
exportedC: make(chan struct{}, 1),
}
Expand Down
2 changes: 2 additions & 0 deletions lib/proxy/peer/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/gravitational/teleport/api/metadata"
"github.com/gravitational/teleport/api/utils/grpc/interceptors"
"github.com/gravitational/teleport/lib/auth"
"github.com/gravitational/teleport/lib/defaults"
"github.com/gravitational/teleport/lib/utils"
)

Expand Down Expand Up @@ -141,6 +142,7 @@ func NewServer(config ServerConfig) (*Server, error) {
MinTime: peerKeepAlive,
PermitWithoutStream: true,
}),
grpc.MaxConcurrentStreams(defaults.GRPCMaxConcurrentStreams),
)

proto.RegisterProxyServiceServer(server, config.service)
Expand Down
3 changes: 3 additions & 0 deletions lib/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -4268,6 +4268,7 @@ func (process *TeleportProcess) initProxyEndpoint(conn *Connector) error {
otelgrpc.StreamServerInterceptor(),
),
grpc.Creds(creds),
grpc.MaxConcurrentStreams(defaults.GRPCMaxConcurrentStreams),
)

connMonitor, err := srv.NewConnectionMonitor(srv.ConnectionMonitorConfig{
Expand Down Expand Up @@ -5930,6 +5931,7 @@ func (process *TeleportProcess) initPublicGRPCServer(
// available for some time.
MaxConnectionIdle: 10 * time.Second,
}),
grpc.MaxConcurrentStreams(defaults.GRPCMaxConcurrentStreams),
)
joinServiceServer := joinserver.NewJoinServiceGRPCServer(conn.Client)
proto.RegisterJoinServiceServer(server, joinServiceServer)
Expand Down Expand Up @@ -5989,6 +5991,7 @@ func (process *TeleportProcess) initSecureGRPCServer(cfg initSecureGRPCServerCfg
grpc.ChainUnaryInterceptor(authMiddleware.UnaryInterceptors()...),
grpc.ChainStreamInterceptor(authMiddleware.StreamInterceptors()...),
grpc.Creds(creds),
grpc.MaxConcurrentStreams(defaults.GRPCMaxConcurrentStreams),
)

kubeServer, err := kubegrpc.New(kubegrpc.Config{
Expand Down
5 changes: 4 additions & 1 deletion lib/teleterm/apiserver/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"google.golang.org/grpc"

api "github.com/gravitational/teleport/gen/proto/go/teleport/lib/teleterm/v1"
"github.com/gravitational/teleport/lib/defaults"
"github.com/gravitational/teleport/lib/teleterm/apiserver/handler"
"github.com/gravitational/teleport/lib/utils"
)
Expand All @@ -41,7 +42,9 @@ func New(cfg Config) (*APIServer, error) {
}

grpcServer := grpc.NewServer(cfg.TshdServerCreds,
grpc.ChainUnaryInterceptor(withErrorHandling(cfg.Log)))
grpc.ChainUnaryInterceptor(withErrorHandling(cfg.Log)),
grpc.MaxConcurrentStreams(defaults.GRPCMaxConcurrentStreams),
)

// Create Terminal service.

Expand Down

0 comments on commit 70afbe9

Please sign in to comment.